search for: py_decref

Displaying 20 results from an estimated 116 matches for "py_decref".

2018 Apr 06
0
[nbdkit PATCH 2/2] python: Simplify calling into plugin
...ple_SetItem (args, 1, PyString_FromString (value)); -#else - PyTuple_SetItem (args, 0, PyUnicode_FromString (key)); - PyTuple_SetItem (args, 1, PyUnicode_FromString (value)); -#endif - r = PyObject_CallObject (fn, args); + r = PyObject_CallFunction (fn, "ss", key, value); Py_DECREF (fn); - Py_DECREF (args); if (check_python_failure ("config") == -1) return -1; Py_DECREF (r); @@ -306,7 +296,6 @@ static void * py_open (int readonly) { PyObject *fn; - PyObject *args; PyObject *handle; if (!callback_defined ("open", &fn)) {...
2018 Apr 06
6
[nbdkit PATCH 0/2] Python cleanups
I noticed these while working on adding fua support into python, these are independent enough to push now (and I'll have to rebase my 'optional may_trim' patch on top of this). Eric Blake (2): python: Use Py_XDEFREF() python: Simplify calling into plugin plugins/python/python.c | 106 ++++++++---------------------------------------- 1 file changed, 18 insertions(+), 88
2020 Aug 10
2
[PATCH nbdkit] python: Allow extents to return any iterable (which includes lists).
...ot;extents") == -1) return -1; - /* We expect a list of extents to be returned. Each extent is a - * tuple (offset, length, type). The list must not be empty. - */ - if (!PyList_Check (r)) { - nbdkit_error ("extents method did not return a list"); - Py_DECREF (r); - return -1; - } - size = PyList_Size (r); - if (size < 1) { - nbdkit_error ("extents method cannot return an empty list"); + iter = PyObject_GetIter (r); + if (iter == NULL) { + nbdkit_error ("extents method did not return " +...
2018 Apr 11
0
[nbdkit PATCH v2 4/5] python: Expose FUA support
...Python script. nbdkit requires these callbacks.", script); return -1; } + + /* One-time setup to learn which callbacks have a fua parameter */ + if (callback_defined ("pwrite", &fn)) { + pwrite_has_fua = callback_has_parameter (fn, "fua"); + Py_DECREF (fn); + if (pwrite_has_fua < 0) { + check_python_failure ("config"); + return -1; + } + } + if (callback_defined ("zero", &fn)) { + zero_has_fua = callback_has_parameter (fn, "fua"); + Py_DECREF (fn); + if (zero_has_f...
2018 Apr 11
10
[nbdkit PATCH v2 0/5] FUA support in Python scripts
First out of our four language bindings to add FUA support (for reference, I added 'zero' support for python, perl, and ruby back in 1.1.13, then Rich had to add it for ocaml in 1.1.20). I tested this heavily under python 2, but for now only compile tested under python 3; I plan to do further testing there and make any tweaks if necessary. I wrote patch 5 early on, but then realized I
2019 Nov 25
6
[nbdkit PATCH 0/5] Counterproposal for python v2 interfaces
As mentioned in my reviews, I wonder if we should make our python callbacks look a bit more Pythonic by having kwargs added for each new flag that we want to expose. The idea was first floated here: https://www.redhat.com/archives/libguestfs/2018-April/msg00108.html Note that with my proposal, there is no need for a python script to expose a global API_VERSION variable; new flags are added
2018 Apr 11
0
[nbdkit PATCH v2 5/5] RFC: python: Track and cache per-connection state in C struct
...ot;, script, "open"); + free (h); return NULL; } PyErr_Clear (); - handle = PyObject_CallFunctionObjArgs (fn, readonly ? Py_True : Py_False, + h->obj = PyObject_CallFunctionObjArgs (fn, readonly ? Py_True : Py_False, NULL); Py_DECREF (fn); - if (check_python_failure ("open") == -1) + if (check_python_failure ("open") == -1) { + free (h); return NULL; + } - return handle; + h->fua = -1; + return h; } static void py_close (void *handle) { - PyObject *obj = handle; + ConnHandle *h = han...
2019 Aug 13
0
[PATCH libnbd 2/6] generator: Create only one Python wrapper per closure.
...+ pr " PyObject *py_%s_modname = PyUnicode_FromString (\"ctypes\");\n" n; + pr " if (!py_%s_modname) { PyErr_PrintEx (0); return -1; }\n" n; + pr " PyObject *py_%s_mod = PyImport_Import (py_%s_modname);\n" n n; + pr " Py_DECREF (py_%s_modname);\n" n; + pr " if (!py_%s_mod) { PyErr_PrintEx (0); return -1; }\n" n; + pr " PyObject *py_%s = PyObject_CallMethod (py_%s_mod, \"c_int\", \"i\", *%s);\n" n n n; + pr " if (!py_%s) { PyErr_PrintEx (0); retur...
2018 Apr 11
0
[nbdkit PATCH v2 1/5] python: Let zero's may_trim parameter be optional
...ec, *args; + + assert (script != NULL); + assert (module != NULL); + +#ifdef HAVE_PYSTRING_FROMSTRING + pname = PyString_FromString ("inspect"); +#else + pname = PyUnicode_FromString ("inspect"); +#endif + if (!pname) + return -1; + inspect = PyImport_Import (pname); + Py_DECREF (pname); + + if (!inspect) + return -1; + +#if PY_MAJOR_VERSION >= 3 + pname = PyUnicode_FromString ("getfullargspec"); +#else + pname = PyString_FromString ("getargspec"); +#endif + spec = PyObject_CallMethodObjArgs (inspect, pname, fn, NULL); + Py_DECREF (pname); +...
2018 Apr 19
1
Re: [nbdkit PATCH v2 5/5] RFC: python: Track and cache per-connection state in C struct
...; > return NULL; > } > > PyErr_Clear (); > > - handle = PyObject_CallFunctionObjArgs (fn, readonly ? Py_True : Py_False, > + h->obj = PyObject_CallFunctionObjArgs (fn, readonly ? Py_True : Py_False, > NULL); > Py_DECREF (fn); > - if (check_python_failure ("open") == -1) > + if (check_python_failure ("open") == -1) { > + free (h); > return NULL; > + } > > - return handle; > + h->fua = -1; > + return h; > } > > static void > py_close (v...
2020 Sep 01
0
[nbdkit PATCH 1/2] python: Implement .list_exports and friends
...bject *fn; + PyObject *r; + PyObject *iter, *t; + + if (!callback_defined ("list_exports", &fn)) + /* Do the same as the core server */ + return nbdkit_add_default_export (exports); + + PyErr_Clear (); + + r = PyObject_CallFunction (fn, "ii", readonly, is_tls); + Py_DECREF (fn); + if (check_python_failure ("list_exports") == -1) + return -1; + + iter = PyObject_GetIter (r); + if (iter == NULL) { + nbdkit_error ("list_exports method did not return " + "something which is iterable"); + Py_DECREF (r); + retur...
2019 Nov 22
0
[PATCH nbdkit v2 05/10] python: Share common code in boolean callbacks.
...har *can_fn, const char *plain_fn) { PyObject *obj = handle; PyObject *fn; PyObject *r; int ret; - if (callback_defined ("can_write", &fn)) { + if (callback_defined (can_fn, &fn)) { PyErr_Clear (); r = PyObject_CallFunctionObjArgs (fn, obj, NULL); Py_DECREF (fn); - if (check_python_failure ("can_write") == -1) + if (check_python_failure (can_fn) == -1) return -1; ret = r == Py_True; Py_DECREF (r); return ret; } - /* No Python can_write callback, but there's a Python pwrite callback - * defined, so return...
2020 Aug 10
5
[PATCH nbdkit] python: Implement can_extents + extents.
...CQUIRE_PYTHON_GIL_FOR_CURRENT_SCOPE; + struct handle *h = handle; + PyObject *fn; + PyObject *r; + Py_ssize_t i, size; + + if (callback_defined ("extents", &fn)) { + PyErr_Clear (); + + r = PyObject_CallFunction (fn, "OiLI", h->py_h, count, offset, flags); + Py_DECREF (fn); + if (check_python_failure ("extents") == -1) + return -1; + + /* We expect a list of extents to be returned. Each extent is a + * tuple (offset, length, type). + */ + if (!PyList_Check (r)) { + nbdkit_error ("extents method did not return a list&quo...
2018 Apr 06
0
[nbdkit PATCH 1/2] python: Use Py_XDEFREF()
...+------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/plugins/python/python.c b/plugins/python/python.c index 35e8df2..c5cc4bd 100644 --- a/plugins/python/python.c +++ b/plugins/python/python.c @@ -183,8 +183,7 @@ py_load (void) static void py_unload (void) { - if (module) - Py_DECREF (module); + Py_XDECREF (module); Py_Finalize (); } @@ -346,8 +345,7 @@ py_close (void *handle) Py_DECREF (fn); Py_DECREF (args); check_python_failure ("close"); - if (r) - Py_DECREF (r); + Py_XDECREF (r); } Py_DECREF (obj); @@ -550,8 +548,7 @@ py_zer...
2023 Feb 17
1
[PATCH] python: Avoid leaking py_array along error paths
...le.c > index bf639b5789..717eee83ed 100644 > --- a/python/handle.c > +++ b/python/handle.c > @@ -136,6 +136,7 @@ guestfs_int_py_event_callback_wrapper (guestfs_h *g, > buf, buf_len, py_array); > if (args == NULL) { > PyErr_PrintEx (0); > + Py_DECREF (py_array); > goto out; > } See my response in the other thread. You are also leaking args, which is not fixed here. I think the correct sequence is: py_array = ... args = Py_BuildValue("...O", py_array); Py_DECREF (py_array); if (args == NULL) { PyErr_PrintEx (0); g...
2020 Aug 10
0
Re: [PATCH nbdkit] python: Implement can_extents + extents.
...t handle *h = handle; > + PyObject *fn; > + PyObject *r; > + Py_ssize_t i, size; > + > + if (callback_defined ("extents", &fn)) { > + PyErr_Clear (); > + > + r = PyObject_CallFunction (fn, "OiLI", h->py_h, count, offset, flags); > + Py_DECREF (fn); > + if (check_python_failure ("extents") == -1) > + return -1; > + > + /* We expect a list of extents to be returned. Each extent is a > + * tuple (offset, length, type). > + */ > + if (!PyList_Check (r)) { > + nbdkit_error ("...
2019 Aug 10
1
Re: [PATCH libnbd 2/5] python: Allow Python callbacks to auto-retire by returning an integer.
...e code is correct: > diff --git a/generator/generator b/generator/generator > index 0107724..0523f0a 100755 > --- a/generator/generator > +++ b/generator/generator > @@ -4135,7 +4135,8 @@ let print_python_binding name { args; optargs; ret; may_set_error } = > pr " Py_DECREF (py_args);\n"; > pr "\n"; > pr " if (py_ret != NULL) {\n"; > - pr " Py_DECREF (py_ret); /* return value is discarded */\n"; > + pr " ret = PyLong_AsLong (py_ret);\n"; > + pr " Py_DEC...
2018 Apr 06
1
[nbdkit PATCH] python: Let zero's may_trim parameter be optional
...lback_has_parameter (PyObject *fn, const char *name) +{ + int r = 0; + PyObject *inspect, *pname, *spec, *args; + + assert (script != NULL); + assert (module != NULL); + + pname = PyString_FromString ("inspect"); + if (!pname) + return -1; + inspect = PyImport_Import (pname); + Py_DECREF (pname); + + if (!inspect) + return -1; + +#if PY_MAJOR_VERSION >= 3 + pname = PyString_FromString ("getfullargspec"); +#else + pname = PyString_FromString ("getargspec"); +#endif + spec = PyObject_CallMethodObjArgs (inspect, pname, fn, NULL); + Py_DECREF (pname); +...
2019 Nov 21
10
[PATCH nbdkit 0/8] Implement nbdkit API v2 for Python plugins.
And fill out most of the missing bits of the API. Rich.
2018 Aug 08
2
[PATCH nbdkit] python: Try harder to print the full traceback on error.
...+{ + PyObject *error_str; + char *error_cstr = NULL; + + error_str = PyObject_Str (error); + error_cstr = python_to_string (error_str); + nbdkit_error ("%s: %s: error: %s", + script, callback, + error_cstr ? error_cstr : "<unknown>"); + Py_DECREF (error_str); + free (error_cstr); +} + +/* Convert the Python traceback to a string and call nbdkit_error. + * https://stackoverflow.com/a/15907460/7126113 + */ +static int +print_python_traceback (const char *callback, + PyObject *type, PyObject *error, PyObject *traceback)...