Displaying 20 results from an estimated 44 matches for "pyobject_callobject".
2018 Apr 06
0
[nbdkit PATCH 2/2] python: Simplify calling into plugin
PyObject_CallObject is powerful, but awkward - we have to wrap
all arguments into a temporary tuple before using it.
Let python do more of the work by using PyObject_CallFunction
anywhere that all arguments can be described by a Py_BuildValue()
format string, instead of creating one-shot arguments ourselves.
In fact,...
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
2023 Feb 17
2
[PATCH v3 0/2] python: Avoid leaking py_array and py_args in event callbacks
...ore closely at this patch:
https://listman.redhat.com/archives/libguestfs/2019-January/020346.html
which I believe is wrong (at least, the part that fiddles with the
reference to args). I cannot reproduce the original problem, nor can
I find any justification by looking at the documentation of
PyObject_CallObject.
So we start by reverting that commit.
This means we are only decrementing args once, and not allow the error
path.
I tested this with:
- with the reproducer
- with the reproducer and bbf396fc5 reverted
- normal Python test suite
Rich.
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
2023 Feb 14
2
[PATCH 1/2] python: Avoid crash if callback parameters cannot be built
...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);
+ out:
PyGILState_Release (py_save);
}
--
2.39.0
2023 Feb 17
1
[PATCH 1/2] python: Avoid crash if callback parameters cannot be built
...ing the reference count here on the error path makes sense.
However, on success, it means py_array now has a refcount of 2, and
args has a refcount of 1 (where cleaning up args will reduce only 1 of
the refs to py_array)...
> > +
> > Py_INCREF (args);
> > -
> > py_r = PyObject_CallObject (py_callback, args);
> > -
> > Py_DECREF (args);
This temporary increment/decrement of args around PyObject_CallObject
is a safety factor to ensure that the call itself doesn't try to
reclaim args while still in use. I'm not sure if it is strictly
required, but it doesn'...
2019 Aug 13
0
[PATCH libnbd 2/6] generator: Create only one Python wrapper per closure.
...BMutable _ -> 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 " if (PyEval_ThreadsInitialized ())\n";
+ pr " PyGILState_Release (py_save);\n";
+ pr "\n";
+ pr " Py_DECREF (py_args);\n";
+ pr "\n";
+ pr " if (py_ret !...
2018 Apr 06
1
[nbdkit PATCH] python: Let zero's may_trim parameter be optional
...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_CallObject (fn, args);
+ if (zero_may_trim)
+ kwargs = Py_BuildValue("{s:i}", "may_trim", may_trim);
+ r = PyObject_Call (fn, args, kwargs);
Py_DECREF (fn);
Py_DECREF (args);
+ Py_XDECREF (kwargs);
if (last_error == EOPNOTSUPP) {
/* When user requests th...
2018 Mar 06
1
[PATCH nbdkit] Fix --dump-plugin on perl, python and ruby plugins.
...ns/python/python.c
+++ b/plugins/python/python.c
@@ -155,7 +155,7 @@ py_dump_plugin (void)
PyObject *fn;
PyObject *r;
- if (callback_defined ("dump_plugin", &fn)) {
+ if (script && callback_defined ("dump_plugin", &fn)) {
PyErr_Clear ();
r = PyObject_CallObject (fn, NULL);
diff --git a/plugins/ruby/ruby.c b/plugins/ruby/ruby.c
index 6b0285f..aa57f65 100644
--- a/plugins/ruby/ruby.c
+++ b/plugins/ruby/ruby.c
@@ -168,10 +168,8 @@ plugin_rb_unload (void)
static void
plugin_rb_dump_plugin (void)
{
- if (!script) {
- nbdkit_error ("the first parame...
2019 Nov 18
0
[PATCH] Python: Fix GIL usage in guestfs_int_py_event_callback_wrapper (RHBZ#1773520)
...= 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_callback_wrapper (guestfs_h *g,
else
/* Callback threw an exception: print it. */
PyErr_PrintEx (0);
+
+...
2019 Nov 22
0
[PATCH nbdkit v2 01/10] python: Use PyObject_CallFunction instead of constructing the tuple.
...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_CallObject (fn, args);
+ r = PyObject_CallFunction (fn, "OiLO",
+ obj, count, offset,
+ may_trim ? Py_True : Py_False, NULL);
Py_DECREF (fn);
- Py_DECREF (args);
if (last_error == EOPNOTSUPP || last_error == ENOTSUP) {...
2019 Nov 21
0
[PATCH nbdkit 1/8] python: Use PyObject_CallFunction instead of constructing the tuple.
...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_CallObject (fn, args);
+ r = PyObject_CallFunction (fn, "OiLO",
+ obj, count, offset,
+ may_trim ? Py_True : Py_False, NULL);
Py_DECREF (fn);
- Py_DECREF (args);
if (last_error == EOPNOTSUPP || last_error == ENOTSUP) {...
2023 Feb 17
3
python: Avoid leaking py_array and py_args in event callbacks
...ore closely at this patch:
https://listman.redhat.com/archives/libguestfs/2019-January/020346.html
which I believe is wrong (at least, the part that fiddles with the
reference to args). I cannot reproduce the original problem, nor can
I find any justification by looking at the documentation of
PyObject_CallObject.
So we start by reverting that commit.
Rich.
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.
2017 Jan 26
0
[nbdkit PATCH v2 6/6] python: Support zero callback
...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_CallObject (fn, args);
+ Py_DECREF (fn);
+ Py_DECREF (args);
+ if (last_error == EOPNOTSUPP) {
+ /* When user requests this particular error, we want to
+ gracefully fall back, and to accomodate both a normal return
+ and an exception. */
+ nbdkit_debug ("zero requested...
2017 Jan 27
0
[nbdkit PATCH v3 4/4] python: Support zero callback
...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_CallObject (fn, args);
+ Py_DECREF (fn);
+ Py_DECREF (args);
+ if (last_error == EOPNOTSUPP) {
+ /* When user requests this particular error, we want to
+ gracefully fall back, and to accomodate both a normal return
+ and an exception. */
+ nbdkit_debug ("zero requested...
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.
2019 Aug 13
0
[nbdkit PATCH 2/2] plugins: Permit ENOTSUP as synonym for EOPNOTSUPP
...normal return
and an exception. */
diff --git a/plugins/python/python.c b/plugins/python/python.c
index 71a982a3..20232f4f 100644
--- a/plugins/python/python.c
+++ b/plugins/python/python.c
@@ -603,7 +603,7 @@ py_zero (void *handle, uint32_t count, uint64_t offset, int may_trim)
r = PyObject_CallObject (fn, args);
Py_DECREF (fn);
Py_DECREF (args);
- if (last_error == EOPNOTSUPP) {
+ if (last_error == EOPNOTSUPP || last_error == ENOTSUP) {
/* When user requests this particular error, we want to
gracefully fall back, and to accomodate both a normal return...
2019 Nov 22
18
[PATCH nbdkit v2 00/10] Implement nbdkit API v2 for Python plugins.
v1:
https://www.redhat.com/archives/libguestfs/2019-November/msg00153.html
v2:
- Fix implementation of can_cache.
- Add implementation of can_fua.
- Add a very thorough test suite which tests every command + flag
combination.