Displaying 20 results from an estimated 47 matches for "check_python_failure".
2018 Apr 11
0
[nbdkit PATCH v2 5/5] RFC: python: Track and cache per-connection state in C struct
...");
+ 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 = handle;
PyObject *fn;
PyObject...
2018 Apr 06
0
[nbdkit PATCH 2/2] python: Simplify calling into plugin
...));
-#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)) {
@@ -316,11 +305,9 @@ py_open (int readonly)
PyErr_Clea...
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 19
1
Re: [nbdkit PATCH v2 5/5] RFC: python: Track and cache per-connection state in C struct
...; }
>
> 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 *...
2018 Apr 11
0
[nbdkit PATCH v2 4/5] python: Expose FUA support
...t);
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_fua < 0) {
+ check_python_failure ("config");
+...
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
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
2019 Nov 22
0
[PATCH nbdkit v2 05/10] python: Share common code in boolean callbacks.
...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 1. (In C modules, nbdkit would do...
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 22
0
[PATCH nbdkit v2 03/10] python: Implement nbdkit API version 2.
..."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 (check_python_failure ("PyLong_AsLong") == -1)
+ return -1;
+ if (py_api_version < 1 || py_api_version > NBDKIT_API_VERSION) {
+ n...
2018 Apr 11
0
[nbdkit PATCH v2 1/5] python: Let zero's may_trim parameter be optional
...*fn;
PyObject *args;
+ PyObject *kwargs;
PyObject *r;
if (callback_defined ("zero", &fn)) {
+ static int zero_may_trim = -1;
+
+ if (zero_may_trim < 0)
+ zero_may_trim = callback_has_parameter (fn, "may_trim");
+ if (zero_may_trim < 0) {
+ check_python_failure ("zero");
+ return -1;
+ }
+
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_S...
2020 Aug 10
2
[PATCH nbdkit] python: Allow extents to return any iterable (which includes lists).
...,
struct handle *h = handle;
PyObject *fn;
PyObject *r;
- Py_ssize_t i, size;
+ PyObject *iter, *t;
+ size_t size;
if (callback_defined ("extents", &fn)) {
PyErr_Clear ();
@@ -1045,29 +1046,25 @@ py_extents (void *handle, uint32_t count, uint64_t offset,
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). The list must not be empty.
- */
- if (!PyList_Check (r)) {
- nbdkit_error ("extents method did not return a list");
-...
2019 Nov 23
3
[PATCH nbdkit] python: Pass memoryview to pwrite()
...yObject_CallFunction (fn, "ONL", obj,
- PyByteArray_FromStringAndSize (buf, count),
- offset, NULL);
+ PyMemoryView_FromMemory ((char *)buf, count, PyBUF_READ),
+ offset, NULL);
Py_DECREF (fn);
if (check_python_failure ("pwrite") == -1)
return -1;
--
2.21.0
2020 Aug 10
5
[PATCH nbdkit] python: Implement can_extents + extents.
...RENT_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");
+ Py_DECREF (r);
+ re...
2020 Aug 10
0
Re: [PATCH nbdkit] python: Implement can_extents + extents.
...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"...
2019 Nov 23
0
[PATCH nbdkit v3 2/7] python: Implement nbdkit API version 2.
...L);
+ switch (py_api_version) {
+ case 1:
+ r = PyObject_CallFunction (fn, "OiL", obj, count, offset, NULL);
+ break;
+ case 2:
+ r = PyObject_CallFunction (fn, "OiLI", obj, count, offset, flags, NULL);
+ break;
+ default: abort ();
+ }
Py_DECREF (fn);
if (check_python_failure ("pread") == -1)
return ret;
@@ -515,8 +560,8 @@ out:
}
static int
-py_pwrite (void *handle, const void *buf,
- uint32_t count, uint64_t offset)
+py_pwrite (void *handle, const void *buf, uint32_t count, uint64_t offset,
+ uint32_t flags)
{
PyObject *obj =...
2018 Apr 05
1
Re: [PATCH nbdkit] python: Turn python exceptions into nbdkit errors properly.
...gt; +#ifdef HAVE_PYUNICODE_ASUTF8
> + if (PyUnicode_Check (str)) {
> + r = PyUnicode_AsUTF8 (str);
> + r = strdup (r);
> + return r;
Any simpler to just write:
return strdup (PyUnicode_AsUTF8 (str));
instead of using the temporary variable r?
> static int
> check_python_failure (const char *callback)
> {
> if (PyErr_Occurred ()) {
> - nbdkit_error ("%s: callback failed: %s", script, callback);
> - /* How to turn this into a string? XXX */
> - PyErr_Print ();
> + PyObject *type, *error, *traceback, *error_str;
> + char *err...
2020 Mar 19
5
[nbdkit PATCH 0/2] More caching of initial setup
When I added .can_FOO caching in 1.16, I missed the case that the sh
plugin itself was calling .can_flush twice in some situations (in
order to default .can_fua). Then right after, I regressed it to call
.can_zero twice (in order to default .can_fast_zero). I also missed
that .thread_model could use better caching, because at the time, I
did not add testsuite coverage. Fix that now.
Eric Blake
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.
2020 Sep 01
0
[nbdkit PATCH 1/2] python: Implement .list_exports and friends
...*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);
+ return -1;
+ }
+
+ while ((t = PyIter...