search for: py_array

Displaying 12 results from an estimated 12 matches for "py_array".

Did you mean: my_array
2023 Feb 17
1
[PATCH] python: Avoid leaking py_array along error paths
...changed, 1 insertion(+) > > diff --git a/python/handle.c b/python/handle.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"...
2023 Feb 17
1
[PATCH 1/2] python: Avoid crash if callback parameters cannot be built
...t; > +++ b/python/handle.c > > @@ -134,18 +134,21 @@ guestfs_int_py_event_callback_wrapper (guestfs_h *g, > > args = Py_BuildValue ("(Kis#O)", > > (unsigned PY_LONG_LONG) event, event_handle, > > buf, buf_len, py_array); According to https://docs.python.org/3/c-api/arg.html#building-values, "O" increments the count of py_array. So before the Py_BuildValue call, py_array has a refcount of 1. I think (although the docs are unclear) that if Py_BuildValue fails, it rolls back any refcount changes it mak...
2023 Feb 20
2
[PATCH 1/2] python: Avoid crash if callback parameters cannot be built
...he "O" format specifier transfers the new list's >> *sole* reference (= ownership) to the just-built higher-level object "args" > > Reference transfer is done with "N", not "O". That would be an > alternative to decreasing the refcount of py_array on success, but not > eliminate the need to decrease the refcount on Py_BuildValue failure. > >> >> - when "args" is killed (decref'd), it takes care of "py_array". >> >> Consequently, if Py_BuildValue fails, "py_array" continues owni...
2023 Feb 20
2
[PATCH 1/2] python: Avoid crash if callback parameters cannot be built
...rmat specifier transfers the new list's > >> *sole* reference (= ownership) to the just-built higher-level object "args" > > > > Reference transfer is done with "N", not "O". That would be an > > alternative to decreasing the refcount of py_array on success, but not > > eliminate the need to decrease the refcount on Py_BuildValue failure. > > > >> > >> - when "args" is killed (decref'd), it takes care of "py_array". > >> > >> Consequently, if Py_BuildValue fails, "...
2023 Feb 17
3
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 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). However the other part of Eric's suggestion is wrong as it ends up calling Py_DECREF (args) when args == NULL along the error path. This lead me to look more closely at this patch: https://listman.redhat.com/a...
2023 Feb 17
2
[PATCH v3 0/2] python: Avoid leaking py_array and py_args in event callbacks
...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). However the other part of Eric's suggestion is wrong as it ends up calling Py_DECREF (args) when args == NULL along the error path. This lead me to look more closely at this patch: https://listman.redhat.com/a...
2023 Feb 16
1
[PATCH] python: Avoid leaking py_array along error paths
Tested by reverting bbf396fc5562b4f so that the error path is used, and re-running the reproducer supplied by Google. Rich.
2023 Feb 14
2
[PATCH 1/2] python: Avoid crash if callback parameters cannot be built
...2baf47..f37e939e03 100644 --- a/python/handle.c +++ b/python/handle.c @@ -134,18 +134,21 @@ guestfs_int_py_event_callback_wrapper (guestfs_h *g, args = Py_BuildValue ("(Kis#O)", (unsigned PY_LONG_LONG) event, event_handle, buf, buf_len, py_array); + if (args == NULL) { + PyErr_PrintEx (0); + goto out; + } + Py_INCREF (args); - py_r = PyObject_CallObject (py_callback, args); - Py_DECREF (args); - if (py_r != NULL) Py_DECREF (py_r); else /* Callback threw an exception: print it. */ PyErr_PrintEx (0); +...
2019 Nov 18
0
[PATCH] Python: Fix GIL usage in guestfs_int_py_event_callback_wrapper (RHBZ#1773520)
...apper (guestfs_h *g, const char *buf, size_t buf_len, const uint64_t *array, size_t array_len) { - PyGILState_STATE py_save = PyGILState_UNLOCKED; + PyGILState_STATE py_save; PyObject *py_callback = callback; PyObject *py_array; PyObject *args; PyObject *a; size_t i; PyObject *py_r; + int threads_initialized = PyEval_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 @@ gues...
2023 Feb 14
2
[PATCH 2/2] python: Use bytes instead of str for event callback buffer
...apper (guestfs_h *g, } /* XXX As with Perl we don't pass the guestfs_h handle here. */ - args = Py_BuildValue ("(Kis#O)", + args = Py_BuildValue ("(Kiy#O)", (unsigned PY_LONG_LONG) event, event_handle, buf, buf_len, py_array); if (args == NULL) { -- 2.39.0
2019 Jan 22
3
[PATCH v2 0/2] python: fixes for Python 3
A couple of fixes for Python 3 to the Python binding. Unfortunately a behaviour change is needed, although it fixes broken types used. Changes from v1: - handle also FBuffer in structs Pino Toscano (2): python: fix call of Python handlers of events python: change types for RBufferOut/FBuffer with Python 3 (RHBZ#1661871) generator/python.ml | 9 +++++++++ python/handle.c | 3 ++- 2
2019 Jan 22
3
[PATCH 0/2] python: fixes for Python 3
A couple of fixes for Python 3 to the Python binding. Unfortunately a behaviour change is needed, although it fixes broken types used. Pino Toscano (2): python: fix call of Python handlers of events python: change return type for RBufferOut with Python 3 (RHBZ#1661871) generator/python.ml | 4 ++++ python/handle.c | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) -- 2.20.1