search for: py_incref

Displaying 20 results from an estimated 78 matches for "py_incref".

2018 Apr 06
0
[nbdkit PATCH 2/2] python: Simplify calling into plugin
...ython_failure ("open") == -1) return NULL; @@ -332,18 +319,13 @@ py_close (void *handle) { PyObject *obj = handle; PyObject *fn; - PyObject *args; PyObject *r; if (callback_defined ("close", &fn)) { PyErr_Clear (); - args = PyTuple_New (1); - Py_INCREF (obj); /* decremented by Py_DECREF (args) */ - PyTuple_SetItem (args, 0, obj); - r = PyObject_CallObject (fn, args); + r = PyObject_CallFunctionObjArgs (fn, obj, NULL); Py_DECREF (fn); - Py_DECREF (args); check_python_failure ("close"); Py_XDECREF (r); } @@ -...
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 Sep 08
2
[libnbd PATCH] python: Plug some memory leaks on error paths
...+396,13 @@ let print_python_binding name { args; optargs; ret; may_set_error } = pr " %s_buf = nbd_internal_py_get_aio_buffer (%s);\n" 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; -...
2019 Aug 13
1
Re: [PATCH libnbd v2 1/3] generator: Implement OClosure.
...t_error } = > ) args; > List.iter ( > function > + | OClosure { cbname } -> > + pr " if (%s_user_data != Py_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;...
2023 Feb 14
2
[PATCH 1/2] python: Avoid crash if callback parameters cannot be built
In the case that building the parameters to the Python event callback fails, args was returned as NULL. We immediately tried to call Py_INCREF on this which crashed. Returning NULL means the Python function threw an exception, so print the exception and return (there is no way to return an error here - the event is lost). Reported-by: Yonatan Shtarkman See: https://listman.redhat.com/archives/libguestfs/2023-February/030653.html --- py...
2020 Sep 10
1
[libnbd PATCH] python: Fix more memory leaks
...; + 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"; + pr " Py_INCREF (py_%s_fn);\n" cbname; + pr " %s_user_data->fn = py_%s_fn;\n" cbname cbname; + pr " }\n"; + pr " else\n"; + pr " %s.callback = NULL; /* we're not going to call it */\n" cbname + | OFlags (n, _) -> pr " %...
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 Aug 13
2
Re: [PATCH libnbd 5/6] generator: Implement OClosure.
...ret; may_set_error } = > ) args; > List.iter ( > function > + | OClosure { cbname } -> > + pr " 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; I don't think PyNone is callable; this probably needs to gain a special case for when the user omitted the optional argument and we thus... > + pr " PyErr_SetSt...
2023 Feb 17
1
[PATCH 1/2] python: Avoid crash if callback parameters cannot be built
On Thu, Feb 16, 2023 at 03:09:02PM +0100, Laszlo Ersek wrote: > On 2/14/23 19:51, Richard W.M. Jones wrote: > > In the case that building the parameters to the Python event callback > > fails, args was returned as NULL. We immediately tried to call > > Py_INCREF on this which crashed. Returning NULL means the Python > > function threw an exception, so print the exception and return (there > > is no way to return an error here - the event is lost). > > > > Reported-by: Yonatan Shtarkman > > See: https://listman.redhat.com/arc...
2019 Aug 13
0
[PATCH libnbd 2/6] generator: Create only one Python wrapper per closure.
...", %s, (int) %s" n len + | CBMutable (Int n) -> pr ", py_%s" n + | CBInt n | CBInt64 n + | CBString n + | CBUInt n | CBUInt64 n -> pr ", %s" n + | CBArrayAndLen _ | CBMutable _ -> assert false + ) cbargs; + pr ");\n"; + pr " Py_INCREF (py_args);\n"; + pr "\n"; + pr " if (PyEval_ThreadsInitialized ())\n"; + pr " py_save = PyGILState_Ensure ();\n"; + pr "\n"; + pr " py_ret = PyObject_CallObject ((PyObject *)user_data, py_args);\n"; + pr "\n"; + pr &...
2019 Jul 16
1
Re: [PATCH libnbd v2] generator: Define new Closure type instead of callbacks.
...ent closures then we need to > + * make sure the ref count remains positive. > + *) > + List.iter ( > + function > + | Closure (false, _) -> () > + | Closure (true, cls) -> > + List.iter ( > + fun { cbname } -> > + pr " Py_INCREF (user_data->%s);\n" cbname > + ) cls > + | _ -> () > + ) args; > + Any reason this loop is a separate pass, rather than... > pr " h = get_handle (py_h);\n"; > List.iter ( > function > @@ -4044,19 +4058,20 @@ let print_python_bindi...
2019 Aug 11
4
[PATCH libnbd v2 0/3] python: Add test for doing asynch copy.
v1 was here: https://www.redhat.com/archives/libguestfs/2019-August/msg00103.html In v2 I've made several changes: - Fix Python callbacks so if they don't return something which is int-like, we assume they mean to return 0. - Add nbd.Buffer free() method. Read commit message in patch 2 to see what this is about. - Fixed the asynch copy test to deal with the unbelievably
2019 Aug 13
7
[PATCH libnbd v2 0/3] Implement OClosures.
v1 was here: https://www.redhat.com/archives/libguestfs/2019-August/msg00168.html I pushed uncontroversial patches 1-4 v2: - The implementation of OClosure (new patch 1) in Python is fixed. - Patch 2 (old patch 5) is unchanged. - I added a new API for removing debug callbacks. I think this approach has some advantages over using OClosure. - I didn't yet do any work on changing the
2019 Aug 13
0
Re: [PATCH libnbd 5/6] generator: Implement OClosure.
...) args; > > List.iter ( > > function > > + | OClosure { cbname } -> > > + pr " 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; > > I don't think PyNone is callable; this probably needs to gain a special > case for when the user omitted the optional argument and we thus... Yeah I'm not su...
2019 Aug 14
0
[PATCH libnbd 2/3] python: Hold a refcount to persistent AIO buffer until command completion.
...* completion_callback.user_data so we can decrement the + * refcount on command completion. + *) + List.iter ( + function + | BytesPersistIn (n, _) | BytesPersistOut (n, _) -> + pr " /* Increment refcount since buffer may be saved by libnbd. */\n"; + pr " Py_INCREF (%s);\n" n; + pr " completion_user_data->buf = %s;\n" n; + | _ -> () + ) args; + (* Call the underlying C function. *) pr " ret = nbd_%s (h" name; List.iter ( @@ -4384,7 +4405,8 @@ let generate_python_methods_c () = pr " * and freed in the...
2019 Nov 18
0
[PATCH] Python: Fix GIL usage in guestfs_int_py_event_callback_wrapper (RHBZ#1773520)
...al_ThreadsInitialized (); + + if (threads_initialized) + py_save = PyGILState_Ensure (); py_array = PyList_New (array_len); for (i = 0; i < array_len; ++i) { @@ -132,14 +136,8 @@ guestfs_int_py_event_callback_wrapper (guestfs_h *g, buf, buf_len, py_array); Py_INCREF (args); - if (PyEval_ThreadsInitialized ()) - py_save = PyGILState_Ensure (); - py_r = PyObject_CallObject (py_callback, args); - if (PyEval_ThreadsInitialized ()) - PyGILState_Release (py_save); - Py_DECREF (args); if (py_r != NULL) @@ -147,6 +145,9 @@ guestfs_int_py_event_c...
2019 Nov 22
0
[PATCH nbdkit v2 01/10] python: Use PyObject_CallFunction instead of constructing the tuple.
...6 +557,21 @@ py_zero (void *handle, uint32_t count, uint64_t offset, int may_trim) { PyObject *obj = handle; PyObject *fn; - PyObject *args; PyObject *r; if (callback_defined ("zero", &fn)) { PyErr_Clear (); last_error = 0; - args = PyTuple_New (4); - Py_INCREF (obj); /* decremented by Py_DECREF (args) */ - PyTuple_SetItem (args, 0, obj); - PyTuple_SetItem (args, 1, PyLong_FromUnsignedLongLong (count)); - PyTuple_SetItem (args, 2, PyLong_FromUnsignedLongLong (offset)); - PyTuple_SetItem (args, 3, PyBool_FromLong (may_trim)); - r = PyObject_...
2019 Nov 21
0
[PATCH nbdkit 1/8] python: Use PyObject_CallFunction instead of constructing the tuple.
...6 +557,21 @@ py_zero (void *handle, uint32_t count, uint64_t offset, int may_trim) { PyObject *obj = handle; PyObject *fn; - PyObject *args; PyObject *r; if (callback_defined ("zero", &fn)) { PyErr_Clear (); last_error = 0; - args = PyTuple_New (4); - Py_INCREF (obj); /* decremented by Py_DECREF (args) */ - PyTuple_SetItem (args, 0, obj); - PyTuple_SetItem (args, 1, PyLong_FromUnsignedLongLong (count)); - PyTuple_SetItem (args, 2, PyLong_FromUnsignedLongLong (offset)); - PyTuple_SetItem (args, 3, PyBool_FromLong (may_trim)); - r = PyObject_...
2023 Feb 17
2
[PATCH v3 0/2] python: Avoid leaking py_array and py_args in event callbacks
Version 1 was here: https://listman.redhat.com/archives/libguestfs/2023-February/030732.html (Ignore version 2 which had a mistake, this is version 3) Following Eric's suggestion here: https://listman.redhat.com/archives/libguestfs/2023-February/030746.html let's decrement the reference of py_array right after adding it to the args. (This works even if args fails to be built).
2009 Feb 24
0
any help with pyogg and pyvorbis?
...9;t keep a page between calls to flush or pageout!! */ static PyObject * py_ogg_stream_pageout(PyObject *self, PyObject *args) { ogg_page op; int res; if (!PyArg_ParseTuple(args, "")) return NULL; res = ogg_stream_pageout(PY_OGG_STREAM(self), &op); if (res == 0) { Py_INCREF(Py_None); return Py_None; } return py_ogg_page_from_page(&op); } And ogg_stream_pageout always returns 0, so, insufficent data has been accumulated to write a page. Can anyone help me and guess, where the fault may be. After all I've read this seems to be the right encoding proce...