search for: pyerr_setstr

Displaying 20 results from an estimated 53 matches for "pyerr_setstr".

2014 Aug 08
2
[PATCH 1/2] Add type checking, support integers as value
...37,45 +2837,90 @@ put_handle (hive_h *h) * not be freed. */ static int -get_value (PyObject *v, hive_set_value *ret) +get_value (PyObject *v, hive_set_value *ret, uint64_t *word) { PyObject *obj; -#ifndef HAVE_PYSTRING_ASSTRING PyObject *bytes; -#endif + + if (!PyDict_Check (v)) { + PyErr_SetString (PyExc_TypeError, \"expected dictionary type for value\"); + return -1; + } obj = PyDict_GetItemString (v, \"key\"); if (!obj) { - PyErr_SetString (PyExc_RuntimeError, \"no 'key' element in dictionary\"); + PyErr_SetString (PyExc_KeyError,...
2017 May 11
1
[PATCH] python: improve few exceptions thrown on error
...ns(+), 4 deletions(-) diff --git a/python/handle.c b/python/handle.c index 88024e1..9746dca 100644 --- a/python/handle.c +++ b/python/handle.c @@ -237,7 +237,7 @@ guestfs_int_py_event_to_string (PyObject *self, PyObject *args) str = guestfs_event_to_string (events); if (str == NULL) { - PyErr_SetString (PyExc_RuntimeError, strerror (errno)); + PyErr_SetFromErrno (PyExc_RuntimeError); return NULL; } @@ -271,7 +271,7 @@ get_all_event_callbacks (guestfs_h *g, size_t *len_rtn) /* Copy them into the return array. */ r = malloc (sizeof (PyObject *) * (*len_rtn)); if (r == NULL)...
2017 Mar 18
0
[PATCH] python: check return value of Python APIs
...ot;; pr " list = PyList_New (%ss->len);\n" typ; - pr " for (i = 0; i < %ss->len; ++i)\n" typ; - pr " PyList_SetItem (list, i, guestfs_int_py_put_%s (&%ss->val[i]));\n" typ typ; + pr " if (list == NULL)\n"; + pr " PyErr_SetString (PyExc_RuntimeError, \"PyList_New\");\n"; + pr " return NULL;\n"; + pr " }\n"; + pr " for (i = 0; i < %ss->len; ++i) {\n" typ; + pr " element = guestfs_int_py_put_%s (&%ss->val[i]);\n" typ typ; + pr "...
2017 Apr 25
1
[Bug #1406906] [PATCH] python: fix segmentation fault when setting non UTF-8 strings
...;; pr " list = PyList_New (%ss->len);\n" typ; - pr " for (i = 0; i < %ss->len; ++i)\n" typ; - pr " PyList_SetItem (list, i, guestfs_int_py_put_%s (&%ss->val[i]));\n" typ typ; + pr " if (list == NULL) {\n"; + pr " PyErr_SetString (PyExc_RuntimeError, \"PyList_New\");\n"; + pr " return NULL;\n"; + pr " }\n"; + pr " for (i = 0; i < %ss->len; ++i) {\n" typ; + pr " element = guestfs_int_py_put_%s (&%ss->val[i]);\n" typ typ; + pr "...
2014 Aug 16
7
[hivex] [PATCH 0/6] Python fixes for node_set_value
Hi, This patch series is based on a prior patch[1], splitting off changes as requested and incorporating feedback from Richard Jones. It introduces type validation to avoid segmentation faults (instead, it reports an exception) and fixes handling of the bytes type in Python 3. Major changes since that series: - Drop newly introduced support for integer types for DWORD/QWORDS - Reject Unicode
2014 Aug 04
6
[hivex] Segfault for an integer value to node_set_value
Hi, When an integer argument is passed as value, node_set_value segfaults. Reproducer is at the end of this message The backtrace points at hivex-py.c, function get_value. While obj is non-NULL, `bytes = PyUnicode_AsUTF8String (obj);` returns NULL. Kind regards, Peter https://lekensteyn.nl #!/usr/bin/env python3 import hivex, sys h = hivex.Hivex(sys.argv[1]) print(h) val = {
2010 Sep 09
2
[PATCH]: add libxl python binding
...ude "libxl.h" /* gah */ +#include "%s" + +int genwrap__string_set(PyObject *v, char **str) +{ + char *tmp; + if ( NULL == v ) { + free(*str); + *str = NULL; + return 0; + } + tmp = strdup(PyString_AsString(v)); + if ( NULL == tmp ) { + PyErr_SetString(PyExc_MemoryError, "Allocating device_net2.bridge attribute"); + return -1; + } + free(*str); + *str = tmp; + return 0; +} + +PyObject *genwrap__string_get(char **str) +{ + if ( NULL == *str ) + return Py_None; + return PyString_FromString(*str); +} + +P...
2020 Sep 08
2
[libnbd PATCH] python: Plug some memory leaks on error paths
...; n n | Closure { cbname } -> pr " /* Increment refcount since pointer may be saved by libnbd. */\n"; - pr " Py_INCREF (%s_user_data->fn);\n" cbname; pr " if (!PyCallable_Check (%s_user_data->fn)) {\n" cbname; pr " PyErr_SetString (PyExc_TypeError,\n"; pr " \"callback parameter %s is not callable\");\n" cbname; - pr " return NULL;\n"; - pr " }\n" + pr " %s_user_data->fn = NULL;\n" cbname; + pr " got...
2019 Aug 13
1
Re: [PATCH libnbd v2 1/3] generator: Implement OClosure.
...None) {\n" cbname; > + pr " /* Increment refcount since pointer may be saved by libnbd. */\n"; > + pr " Py_INCREF (%s_user_data);\n" cbname; > + pr " if (!PyCallable_Check (%s_user_data)) {\n" cbname; > + pr " PyErr_SetString (PyExc_TypeError,\n"; > + pr " \"callback parameter %s is not callable\");\n" cbname; > + pr " return NULL;\n"; Leaks %s_user_data, because we fail to do a matching Py_DECREF on failure paths. It would be easier to...
2020 Sep 10
1
[libnbd PATCH] python: Fix more memory leaks
....user_data = %s_user_data = alloc_user_data ();\n" cbname cbname; + pr " if (%s_user_data == NULL) goto out;\n" cbname; + pr " if (py_%s_fn != Py_None) {\n" cbname; + pr " if (!PyCallable_Check (py_%s_fn)) {\n" cbname; + pr " PyErr_SetString (PyExc_TypeError,\n"; + pr " \"callback parameter %s is not callable\");\n" cbname; + pr " goto out;\n"; + pr " }\n"; + pr " /* Increment refcount since pointer may be saved by libnbd. */\n...
2019 Jul 16
1
Re: [PATCH libnbd v2] generator: Define new Closure type instead of callbacks.
...| BytesPersistIn (n, _) | BytesPersistOut (n, _) -> > pr " %s_buf = nbd_internal_py_get_aio_buffer (%s);\n" n n > - | Callback (n, _) | CallbackPersist (n, _) -> > - pr " if (!PyCallable_Check (%s_data->fn)) {\n" n; > - pr " PyErr_SetString (PyExc_TypeError,\n"; > - pr " \"callback parameter %s is not callable\");\n" > - n; > - pr " return NULL;\n"; > - pr " }\n" > + | Closure (_, cls) -> > + List.iter ( &gt...
2020 Jan 30
2
[PATCH libnbd] python: Add AIO buffer is_zero method.
...&obj, &offset, &size)) + return NULL; + + if (size == 0) + Py_RETURN_TRUE; + + buf = nbd_internal_py_get_aio_buffer (obj); + if (buf == NULL) + return NULL; + + /* Check the bounds of the offset. */ + if (offset < 0 || offset > buf->len) { + PyErr_SetString (PyExc_IndexError, "offset out of range"); + return NULL; + } + + /* Compute or check the length. */ + if (size == -1) + size = buf->len - offset; + else if (size < 0) { + PyErr_SetString (PyExc_IndexError, + "size cannot be negative, "...
2008 Aug 30
3
Updated version of patch
Attached is a patch against shout-python-0.2 which does two trivial but very useful things (1) The function "get_connected" is exported so that shout-python becomes usable in nonblocking mode. In the current version of shout-python "open" raises an exception in nonblocking mode. (2) The global interpreter lock is released in the potentially blocking functions
2019 Aug 12
0
[PATCH libnbd 6/7] python: Use free callback to free closure root.
...- pr " Py_DECREF ((PyObject *)user_data);\n"; - pr "\n"; pr " return ret;\n"; pr "}\n"; pr "\n" @@ -4454,6 +4451,11 @@ let print_python_binding name { args; optargs; ret; may_set_error } = pr " PyErr_SetString (PyExc_TypeError,\n"; pr " \"callback parameter %s is not callable\");\n" cbname; pr " return NULL;\n"; + pr " }\n"; + pr " if (nbd_add_free_callback (h, %s_user_data,\n" cbname; + p...
2019 Jun 28
3
[PATCH libnbd v2] python: Raise a custom exception containing error string and errno.
This kind of fixes the problems in v1. The exception still primarily lives in the libnbdmod and you could still refer to it using libnbdmod.Error (but don't do that). However when the exception is printed it now appears as nbd.Error, and you can catch it also using the same name. Other problems: - There is no "nice" interface to accessing the exception fields. You have to use
2019 Aug 14
5
[PATCH libnbd 0/3] Use free callback to hold ref to AIO buffer.
Basically the same as this patch series, but for Python: https://www.redhat.com/archives/libguestfs/2019-August/msg00235.html plus adding the 590 asynch test at the end. Rich.
2019 Jun 28
0
[PATCH libnbd v2] python: Raise a custom exception containing error string and errno.
...nbd_internal_py_Error); + return mod; } " @@ -3796,7 +3825,7 @@ let print_python_binding name { args; ret } = | RBool | RErr | RFd | RInt | RInt64 -> pr " if (ret == -1) {\n"; | RConstString | RString -> pr " if (ret == NULL) {\n"; ); - pr " PyErr_SetString (PyExc_RuntimeError, nbd_get_error ());\n"; + pr " raise_exception ();\n"; pr " py_ret = NULL;\n"; pr " goto out;\n"; pr " }\n"; @@ -3917,6 +3946,9 @@ Read the libnbd(3) man page to find out how to use the API. import libnbdmod...
2019 Jul 24
2
Re: [PATCH libnbd 2/3] lib: Implement closure lifetimes.
...) | BytesPersistOut (n, _) -> > pr " %s_buf = nbd_internal_py_get_aio_buffer (%s);\n" n n > - | Closure (_, { cbname }) -> > + | Closure { cbname } -> > pr " if (!PyCallable_Check (%s_user_data)) {\n" cbname; > pr " PyErr_SetString (PyExc_TypeError,\n"; > pr " \"callback parameter %s is not callable\");\n" cbname; ...and this match are identical, should we group the code? > +++ b/generator/states-reply-simple.c I got this far in my review; I'll resume later...
2019 Aug 13
0
[PATCH libnbd 5/6] generator: Implement OClosure.
..." if (%s_user_data) {\n" cbname; + pr " /* Increment refcount since pointer may be saved by libnbd. */\n"; + pr " Py_INCREF (%s_user_data);\n" cbname; + pr " if (!PyCallable_Check (%s_user_data)) {\n" cbname; + pr " PyErr_SetString (PyExc_TypeError,\n"; + pr " \"callback parameter %s is not callable\");\n" cbname; + pr " return NULL;\n"; + pr " }\n"; + pr " }\n" | OFlags (n, _) -> pr " %s_u32 = %s;\n&...
2019 Jun 28
1
[PATCH libnbd] python: Raise a custom exception containing error string and errno.
I spent a good few hours this morning trying to make this work and came up with the following patch. It's not quite right though. The exception I've created exists in the libnbdmod module (ie. the underlying C module that we use for the Python bindings). Ideally we'd define and throw an exception from the normal nbd module, but I couldn't work out how to do that. Probably