search for: callback_defined

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

2019 Nov 22
0
[PATCH nbdkit v2 05/10] python: Share common code in boolean callbacks.
...@@ -684,110 +684,56 @@ py_zero (void *handle, uint32_t count, uint64_t offset, uint32_t flags) } static int -py_can_write (void *handle) +boolean_callback (void *handle, const char *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) retur...
2018 Apr 11
0
[nbdkit PATCH v2 2/5] python: Expose can_zero callback
...python/python.c +++ b/plugins/python/python.c @@ -629,13 +629,8 @@ py_can_write (void *handle) Py_DECREF (r); return ret; } - /* No Python can_write callback, but there's a Python pwrite callback - * defined, so return 1. (In C modules, nbdkit would do this). - */ - else if (callback_defined ("pwrite", NULL)) - return 1; - else - return 0; + /* No Python can_write callback, so check for Python pwrite callback. */ + return callback_defined ("pwrite", NULL); } static int @@ -657,13 +652,8 @@ py_can_flush (void *handle) Py_DECREF (r); return ret;...
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
2018 Apr 11
0
[nbdkit PATCH v2 5/5] RFC: python: Track and cache per-connection state in C struct
...on state */ +typedef struct ConnHandle { + PyObject *obj; + int fua; +} ConnHandle; + static void * py_open (int readonly) { PyObject *fn; - PyObject *handle; + ConnHandle *h = malloc (sizeof *h); + if (!h) { + nbdkit_error ("%s: %m", script); + return NULL; + } if (!callback_defined ("open", &fn)) { nbdkit_error ("%s: missing callback: %s", script, "open"); + free (h); return NULL; } PyErr_Clear (); - handle = PyObject_CallFunctionObjArgs (fn, readonly ? Py_True : Py_False, + h->obj = PyObject_CallFunctionObjArgs (fn,...
2018 Apr 06
0
[nbdkit PATCH 2/2] python: Simplify calling into plugin
...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)) { @@ -316,11 +305,9 @@ py_open (int readonly) PyErr_Clear (); - args = PyTuple_New (1); - PyTuple_SetItem (args, 0, PyBool_FromLong (readonly)); - handle = PyObject_CallObject (fn, args); + handle = PyObject_CallFunctionObjArgs (fn, readonly ? Py_True : Py_Fals...
2018 Apr 19
1
Re: [nbdkit PATCH v2 5/5] RFC: python: Track and cache per-connection state in C struct
...> +} ConnHandle; > + > static void * > py_open (int readonly) > { > PyObject *fn; > - PyObject *handle; > + ConnHandle *h = malloc (sizeof *h); > > + if (!h) { > + nbdkit_error ("%s: %m", script); > + return NULL; > + } > if (!callback_defined ("open", &fn)) { > nbdkit_error ("%s: missing callback: %s", script, "open"); > + free (h); > return NULL; > } > > PyErr_Clear (); > > - handle = PyObject_CallFunctionObjArgs (fn, readonly ? Py_True : Py_False, > +...
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
2018 Apr 11
0
[nbdkit PATCH v2 3/5] python: Update internals to plugin API level 2
...see: @@ -430,12 +431,13 @@ py_get_size (void *handle) static int py_pread (void *handle, void *buf, - uint32_t count, uint64_t offset) + uint32_t count, uint64_t offset, uint32_t flags) { PyObject *obj = handle; PyObject *fn; PyObject *r; + assert (!flags); if (!callback_defined ("pread", &fn)) { nbdkit_error ("%s: missing callback: %s", script, "pread"); return -1; @@ -469,12 +471,13 @@ py_pread (void *handle, void *buf, static int py_pwrite (void *handle, const void *buf, - uint32_t count, uint64_t offset) +...
2018 Apr 11
0
[nbdkit PATCH v2 4/5] python: Expose FUA support
...it_error ("%s: one of the required callbacks 'open', 'get_size' or 'pread' is not defined by this 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", &amp...
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 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 Mar 06
1
[PATCH nbdkit] Fix --dump-plugin on perl, python and ruby plugins.
...thon.c | 2 +- plugins/ruby/ruby.c | 4 +--- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/plugins/perl/perl.c b/plugins/perl/perl.c index 80e5695..8d35b85 100644 --- a/plugins/perl/perl.c +++ b/plugins/perl/perl.c @@ -169,7 +169,7 @@ perl_dump_plugin (void) { dSP; - if (callback_defined ("dump_plugin")) { + if (script && callback_defined ("dump_plugin")) { ENTER; SAVETMPS; PUSHMARK (SP); diff --git a/plugins/python/python.c b/plugins/python/python.c index b105e53..83a32ea 100644 --- a/plugins/python/python.c +++ b/plugins/python/python.c...
2016 Sep 26
0
[PATCH] nbdkit: Talk about Python in the Python plugin
...0 @@ -437,7 +437,7 @@ Py_DECREF (r); return ret; } - /* No Perl can_write callback, but there's a Perl pwrite callback + /* No Python can_write callback, but there's a Python pwrite callback * defined, so return 1. (In C modules, nbdkit would do this). */ else if (callback_defined ("pwrite", NULL)) @@ -470,7 +470,7 @@ Py_DECREF (r); return ret; } - /* No Perl can_flush callback, but there's a Perl flush callback + /* No Python can_flush callback, but there's a Python flush callback * defined, so return 1. (In C modules, nbdkit would do t...
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.
2019 Nov 22
0
[PATCH nbdkit v2 03/10] python: Implement nbdkit API version 2.
...; static PyObject *module; +static int py_api_version = 1; static int last_error; @@ -356,6 +359,26 @@ py_config (const char *key, const char *value) "nbdkit requires these callbacks.", script); return -1; } + + /* Get the API version. */ + if (callback_defined ("api_version", &fn)) { + PyErr_Clear (); + + r = PyObject_CallObject (fn, NULL); + Py_DECREF (fn); + if (check_python_failure ("api_version") == -1) + return -1; + py_api_version = (int) PyLong_AsLong (r); + Py_DECREF (r); + if (che...
2019 Nov 23
0
[PATCH nbdkit v3 2/7] python: Implement nbdkit API version 2.
...); printf ("python_pep_384_abi_version=%d\n", PYTHON_ABI_VERSION); + /* Maximum nbdkit API version supported. */ + printf ("nbdkit_python_maximum_api_version=%d\n", NBDKIT_API_VERSION); + + /* If the script has a dump_plugin function, call it. */ if (script && callback_defined ("dump_plugin", &fn)) { PyErr_Clear (); @@ -297,6 +305,30 @@ py_dump_plugin (void) } } +static int +get_py_api_version (void) +{ + PyObject *obj; + long value; + + obj = PyObject_GetAttrString (module, "API_VERSION"); + if (obj == NULL) + return 1;...
2018 Apr 05
1
[nbdkit PATCH] python: Make sure callbacks are actually callable
...on functions from C recommend doing this filtering check. plugins/python/python.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugins/python/python.c b/plugins/python/python.c index 0206b80..35e8df2 100644 --- a/plugins/python/python.c +++ b/plugins/python/python.c @@ -94,6 +94,11 @@ callback_defined (const char *name, PyObject **obj_rtn) obj = PyObject_GetAttrString (module, name); if (!obj) return 0; + if (!PyCallable_Check (obj)) { + nbdkit_debug ("object %s isn't callable", name); + Py_DECREF (obj); + return 0; + } if (obj_rtn != NULL) *obj_rtn =...
2019 Nov 25
7
[PATCH nbdkit v2 0/7] Implement nbdkit API v2 for Python plugins.
v3 was here: https://www.redhat.com/archives/libguestfs/2019-November/msg00209.html In v4: - Rebase on top of current master. Includes various fixes and updates required because of Nir's patches that went into master. - Fix api_version() -> API_VERSION in patch 2 noted previously on the mailing list. Rich.
2019 Nov 23
8
[PATCH nbdkit v3 0/7] Implement nbdkit API v2 for Python plugins.
v2 was here: https://www.redhat.com/archives/libguestfs/2019-November/msg00163.html I pushed patch 1 (with spelling fix), patch 4 and patch 5 since those were previously ACKed on the list. Differences in v3: - Add error checking to PyModule_AddIntConstant. - Use API_VERSION constant instead of function. - Add max API version supported to --dump-plugin output. - Print API_VERSION selected by
2019 Nov 22
0
Re: [PATCH nbdkit v2 03/10] python: Implement nbdkit API version 2.
...s are assumed to want API version 1). > > Could we also permit the python code to declare a global variable > instead of a function? But a function is just fine (and easier to > integrate the way we do all our other callbacks). I couldn't work out how to do this, plus we have the callback_defined function which makes this easy, so yes, I did the easy thing :-) > >@@ -54,20 +61,20 @@ def get_size(h): > > return len(disk) > >-def pread(h, count, offset): > >+def pread(h, count, offset, flags): > > global disk > > return disk[offset:offset+co...