search for: pyobject_getattrstring

Displaying 20 results from an estimated 28 matches for "pyobject_getattrstring".

2018 Apr 05
1
[nbdkit PATCH] python: Make sure callbacks are actually callable
...ns/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 = obj; -- 2.14.3
2019 Nov 22
1
Re: [PATCH nbdkit v2 03/10] python: Implement nbdkit API version 2.
...on. > > The extra glue code is (without error handling): > > PyObject *d = PyModule_GetDict(PyObject *module); > PyObject *v = PyDict_GetItemString(d, "API_VERSION"); > long api_version = PyLong_AsLong(v); Or simpler (with error handling): PyObject *v = PyObject_GetAttrString(m, "API_VERSION"); if (v == NULL) return 1; long value = PyLong_AsLong(v); Py_DECREF(m); return value; On error -1 is returned and PyErr_Occurred() will return the exception type.
2019 Aug 13
0
[PATCH libnbd 2/6] generator: Create only one Python wrapper per closure.
...PyErr_PrintEx (0); /* print exception */\n"; + pr " };\n"; + pr "\n"; + List.iter ( + function + | CBArrayAndLen (UInt32 n, _) -> + pr " Py_DECREF (py_%s);\n" n + | CBMutable (Int n) -> + pr " PyObject *py_%s_ret = PyObject_GetAttrString (py_%s, \"value\");\n" n n; + pr " *%s = PyLong_AsLong (py_%s_ret);\n" n n; + pr " Py_DECREF (py_%s_ret);\n" n; + pr " Py_DECREF (py_%s);\n" n + | CBBytesIn _ + | CBInt _ | CBInt64 _ + | CBString _ + | CBUInt _ | CB...
2018 Aug 08
2
[PATCH nbdkit] python: Try harder to print the full traceback on error.
...eback"); +#else + module_name = PyUnicode_FromString ("traceback"); +#endif + traceback_module = PyImport_Import (module_name); + Py_DECREF (module_name); + + /* couldn't 'import traceback' */ + if (traceback_module == NULL) + return -1; + + format_exception_fn = PyObject_GetAttrString (traceback_module, + "format_exception"); + if (format_exception_fn == NULL) + return -1; + if (!PyCallable_Check (format_exception_fn)) + return -1; + + rv = PyObject_CallFunctionObjArgs (format_exception_fn, +...
2018 Aug 08
0
Re: [PATCH nbdkit] python: Try harder to print the full traceback on error.
...de_FromString ("traceback"); > +#endif > + traceback_module = PyImport_Import (module_name); > + Py_DECREF (module_name); > + > + /* couldn't 'import traceback' */ > + if (traceback_module == NULL) > + return -1; > + > + format_exception_fn = PyObject_GetAttrString (traceback_module, > + "format_exception"); > + if (format_exception_fn == NULL) > + return -1; > + if (!PyCallable_Check (format_exception_fn)) > + return -1; > + > + rv = PyObject_CallFunctionObjArgs (format_ex...
2019 Nov 22
4
Re: [PATCH nbdkit v2 03/10] python: Implement nbdkit API version 2.
On 11/22/19 3:20 PM, Nir Soffer wrote: >>> +# There are several variants of the API. nbdkit will call this >>> +# function first to determine which one you want to use. This is the >>> +# latest version at the time this example was written. >>> +def api_version(): >>> + return 2 >> >> Matches the C counterpart of #define
2019 Jul 16
0
[libnbd PATCH 2/2] RFC: generator: Handle shared callbacks in Python
...PyErr_PrintEx (0); /* print exception */\n"; + pr " };\n"; + pr "\n"; + List.iter ( + function + | ArrayAndLen (UInt32 n, _) -> + pr " Py_DECREF (py_%s);\n" n + | Mutable (Int n) -> + pr " PyObject *py_%s_ret = PyObject_GetAttrString (py_%s, \"value\");\n" n n; + pr " *%s = PyLong_AsLong (py_%s_ret);\n" n n; + pr " Py_DECREF (py_%s_ret);\n" n; + pr " Py_DECREF (py_%s);\n" n + | BytesIn _ + | Int _ | Int64 _ + | String _ + | UInt64 _ -&gt...
2019 Aug 12
0
[PATCH libnbd 7/7] api: Remove the valid_flag from all callbacks.
...pr "\n"; List.iter ( function | CBArrayAndLen (UInt32 n, _) -> - pr " Py_DECREF (py_%s);\n" n + pr " Py_DECREF (py_%s);\n" n | CBMutable (Int n) -> - pr " PyObject *py_%s_ret = PyObject_GetAttrString (py_%s, \"value\");\n" n n; - pr " *%s = PyLong_AsLong (py_%s_ret);\n" n n; - pr " Py_DECREF (py_%s_ret);\n" n; - pr " Py_DECREF (py_%s);\n" n + pr " PyObject *py_%s_ret = PyObject_GetAttrString...
2019 Jul 16
3
[RFC libnbd PATCH 0/2] Start fixing python nbd.pread_structured_callback
Posting now that I got something to compile (at the expense of breaking OCaml bindings), but I'm open to ideas on how to improve it. Eric Blake (2): generator: Tweak print_c_arg_list to take alternate first arg RFC: generator: Handle shared callbacks in Python generator/generator | 556 ++++++++++++++++++++++---------------------- 1 file changed, 280 insertions(+), 276 deletions(-) --
2019 Nov 23
0
[PATCH nbdkit v3 2/7] python: Implement nbdkit API version 2.
.../* 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; /* Default to API version 1. */ + + value = PyLong_AsLong (obj); + Py_DECREF (obj); + + if (value < 1 || value > NBDKIT_API_VERSION) { + nbdkit_error ("%s: API_VERSION requested unknown version:...
2019 Aug 13
0
[PATCH libnbd 2/4] api: Add free function and remove valid_flag parameter.
...\n"; + pr " };\n"; pr "\n"; List.iter ( function | CBArrayAndLen (UInt32 n, _) -> - pr " Py_DECREF (py_%s);\n" n + pr " Py_DECREF (py_%s);\n" n | CBMutable (Int n) -> - pr " PyObject *py_%s_ret = PyObject_GetAttrString (py_%s, \"value\");\n" n n; - pr " *%s = PyLong_AsLong (py_%s_ret);\n" n n; - pr " Py_DECREF (py_%s_ret);\n" n; - pr " Py_DECREF (py_%s);\n" n + pr " PyObject *py_%s_ret = PyObject_GetAttrString (py_%s, \"value...
2019 Jul 24
0
[PATCH libnbd v2 2/5] lib: Implement closure lifetimes.
...; pr "\n"; List.iter ( function | ArrayAndLen (UInt32 n, _) -> - pr " Py_DECREF (py_%s);\n" n + pr " Py_DECREF (py_%s);\n" n | Mutable (Int n) -> - pr " PyObject *py_%s_ret = PyObject_GetAttrString (py_%s, \"value\");\n" n n; - pr " *%s = PyLong_AsLong (py_%s_ret);\n" n n; - pr " Py_DECREF (py_%s_ret);\n" n; - pr " Py_DECREF (py_%s);\n" n + pr " PyObject *py_%s_ret = PyObject_GetAttrString (py_...
2019 Jun 25
3
[PATCH libnbd] generator: Add Mutable type to the generator.
Mutable (Int n) => int *n This can currently only be used for callback arguments of type int (not for other types, nor for any ordinary function arguments), but it could be implemented more generally in future. --- generator/generator | 75 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 63 insertions(+), 12 deletions(-) diff --git a/generator/generator b/generator/generator
2019 Jul 24
0
[PATCH libnbd 1/3] generator: Change Closure so it describes single callbacks.
...pr " };\n"; - pr "\n"; - List.iter ( - function - | ArrayAndLen (UInt32 n, _) -> - pr " Py_DECREF (py_%s);\n" n - | Mutable (Int n) -> - pr " PyObject *py_%s_ret = PyObject_GetAttrString (py_%s, \"value\");\n" n n; - pr " *%s = PyLong_AsLong (py_%s_ret);\n" n n; - pr " Py_DECREF (py_%s_ret);\n" n; - pr " Py_DECREF (py_%s);\n" n - | BytesIn _ - | Int _ | Int64 _ -...
2019 Jul 24
8
[PATCH libnbd v2 0/5] lib: Implement closure lifetimes.
v1 was here: https://www.redhat.com/archives/libguestfs/2019-July/thread.html#00231 The changes address everything that Eric picked up in his review of the first two patches. I have also added two more patches (4 and 5) which respectively fix docs and change int status -> unsigned status, as discussed. Passes make, check, check-valgrind. Rich.
2019 Aug 13
12
[PATCH 0/6] Implement OClosure.
Patches 1-4 are basically uncontroversial, straightforward refactoring and IMHO we should just push them. Possibly 1-3 should be squashed together, but I posted them separately so they are easier to review. Patches 5 and 6 together implement OClosure. Patch 5 adds the feature and is simple to understand. Patch 6 changes the Closure completion callbacks into OClosure, but because it doesn't
2019 Jul 16
0
[PATCH libnbd v2] generator: Define new Closure type instead of callbacks.
...);\n"; + pr "}\n"; + pr "\n"; + ); + List.iter ( - function - | ArrayAndLen (UInt32 n, _) -> - pr " Py_DECREF (py_%s);\n" n - | Mutable (Int n) -> - pr " PyObject *py_%s_ret = PyObject_GetAttrString (py_%s, \"value\");\n" n n; - pr " *%s = PyLong_AsLong (py_%s_ret);\n" n n; - pr " Py_DECREF (py_%s_ret);\n" n; - pr " Py_DECREF (py_%s);\n" n - | BytesIn _ - | Int _ | Int64 _ - | Opaque _ -...
2020 Aug 05
5
[PATCH NOT WORKING nbdkit 0/3] python: Allow thread model to be set from Python plugins.
...'pread', obj=<module at remote 0x7fc4abbfabd0>) at /usr/src/debug/python3.9-3.9.0~b3-1.fc33.x86_64/Objects/object.c:1278 #4 module_getattro (m=0x7fc4abbfabd0, name='pread') at /usr/src/debug/python3.9-3.9.0~b3-1.fc33.x86_64/Objects/moduleobject.c:717 #5 0x00007fc4b94c2014 in PyObject_GetAttrString (v=<module at remote 0x7fc4abbfabd0>, name=<optimized out>) at /usr/src/debug/python3.9-3.9.0~b3-1.fc33.x86_64/Objects/object.c:795 #6 0x00007fc4b9f7a5e8 in callback_defined (name=0x7fc4b9f7d4b6 "pread", obj_rtn=0x7fc4aa21e940) at python.c:77 #7 0x00007fc4b9f7b7c8 in py_prea...
2019 Jul 16
2
[PATCH libnbd v2] generator: Define new Closure type
As before, but this one has working Python bindings. OCaml still TBD. Rich.
2019 Aug 10
7
[PATCH libnbd 0/5] WIP: python: Add test for doing asynch copy.
This doesn't yet work. However it does make me more convinced than ever that we really need to sort out persistent buffer lifetimes in the library (similar to what we did for closures). Rich.