search for: pyerr_occurred

Displaying 16 results from an estimated 16 matches for "pyerr_occurred".

2014 Aug 08
2
[PATCH 1/2] Add type checking, support integers as value
...etItemString (v, \"t\"); if (!obj) { - PyErr_SetString (PyExc_RuntimeError, \"no 't' element in dictionary\"); + PyErr_SetString (PyExc_KeyError, \"no 't' element in dictionary\"); return -1; } ret->t = PyLong_AsLong (obj); + if (PyErr_Occurred ()) { + PyErr_SetString (PyExc_TypeError, \"expected int type for 't'\"); + return -1; + } obj = PyDict_GetItemString (v, \"value\"); if (!obj) { - PyErr_SetString (PyExc_RuntimeError, \"no 'value' element in dictionary\"); + PyErr_...
2018 Apr 05
1
Re: [PATCH nbdkit] python: Turn python exceptions into nbdkit errors properly.
...(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 *error_cstr; > + > + /* Convert the Python exception...
2019 Aug 10
1
Re: [PATCH libnbd 2/5] python: Allow Python callbacks to auto-retire by returning an integer.
...quot;; This doesn't detect if the user returned a non-integer type (in which case ret will be -1) - are we okay blindly returning -1 regardless of whether the user returned actual -1 vs. if they returned some other non-integer Python object that has no __int__ conversion? Or do we need to use PyErr_Occurred() to distinguish between the two cases? This is particularly interesting since we document that the C callback must return -1 before any update to *err will take effect; do we want Python to have to return -1 for that effect, or is it okay if python raises an exception and we safely catch that as...
2019 Nov 22
1
Re: [PATCH nbdkit v2 03/10] python: Implement nbdkit API version 2.
..."); > 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.
2018 Apr 05
4
[PATCH nbdkit] python: Turn python exceptions into nbdkit errors
Much more annoying that it needs to be, but I have tested it and it works on Python 2 & 3. Note this will not work on Python 3.0 - 3.2, but I guess we don't care about those versions. Rich.
2012 Sep 20
0
[PATCH] python: PyInt_* no longer exists in python3, replace with PyLong_*
...s_BITMASK;\n" c_optarg_prefix uc_n; (match optarg with | OBool _ | OInt _ -> - pr " optargs_s.%s = PyInt_AsLong (py_%s);\n" n n; + pr " optargs_s.%s = PyLong_AsLong (py_%s);\n" n n; pr " if (PyErr_Occurred ()) return NULL;\n" | OInt64 _ -> pr " optargs_s.%s = PyLong_AsLongLong (py_%s);\n" n n; -- 1.7.10.4
2018 Aug 08
2
[PATCH nbdkit] python: Try harder to print the full traceback on error.
...it_error ("%s: %s: error: %s", + script, callback, + traceback_cstr); + Py_DECREF (rv); + free (traceback_cstr); + + /* This means we succeeded in calling nbdkit_error. */ + return 0; +} + static int check_python_failure (const char *callback) { if (PyErr_Occurred ()) { - PyObject *type, *error, *traceback, *error_str; - char *error_cstr; + PyObject *type, *error, *traceback; - /* Convert the Python exception to a string. - * https://stackoverflow.com/a/1418703 - * But forget about the traceback, it's very hard to print. - * htt...
2017 May 09
1
[PATCH v2] python: add simple wrappers for PyObject<->string functions
...s, 1));\n" + typ name ) cols; pr " return dict;\n"; pr "};\n"; @@ -419,13 +401,7 @@ and generate_python_actions actions () = pr " optargs_s.%s = PyLong_AsLongLong (py_%s);\n" n n; pr " if (PyErr_Occurred ()) goto out;\n" | OString _ -> - pr "#ifdef HAVE_PYSTRING_ASSTRING\n"; - pr " optargs_s.%s = PyString_AsString (py_%s);\n" n n; - pr "#else\n"; - pr " PyObject *bytes;\n"; -...
2018 Aug 08
0
Re: [PATCH nbdkit] python: Try harder to print the full traceback on error.
...we don't to fallback to the simple error print. > + Py_DECREF (rv); > + free (traceback_cstr); > + > + /* This means we succeeded in calling nbdkit_error. */ > + return 0; > +} > + > static int > check_python_failure (const char *callback) > { > if (PyErr_Occurred ()) { > - PyObject *type, *error, *traceback, *error_str; > - char *error_cstr; > + PyObject *type, *error, *traceback; > > - /* Convert the Python exception to a string. > - * https://stackoverflow.com/a/1418703 > - * But forget about the traceback, it'...
2017 May 09
0
[PATCH] python: add simple wrappers for PyObject<->string functions
...s, 1));\n" + typ name ) cols; pr " return dict;\n"; pr "};\n"; @@ -419,13 +401,7 @@ and generate_python_actions actions () = pr " optargs_s.%s = PyLong_AsLongLong (py_%s);\n" n n; pr " if (PyErr_Occurred ()) goto out;\n" | OString _ -> - pr "#ifdef HAVE_PYSTRING_ASSTRING\n"; - pr " optargs_s.%s = PyString_AsString (py_%s);\n" n n; - pr "#else\n"; - pr " PyObject *bytes;\n"; -...
2018 Apr 05
0
[PATCH nbdkit] python: Turn python exceptions into nbdkit errors properly.
...al pointer in PyObject. */ + r = strdup (r); + return r; + } + else +#endif + if (PyBytes_Check (str)) { + r = PyBytes_AS_STRING (str); + r = strdup (r); + return r; + } + } + return NULL; +} + 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 *error_cstr; + + /* Convert the Python exception to a string. + * https://stacko...
2014 Aug 04
6
[hivex] Segfault for an integer value to node_set_value
Hi, When an integer argument is passed as value, node_set_value segfaults. Reproducer is at the end of this message The backtrace points at hivex-py.c, function get_value. While obj is non-NULL, `bytes = PyUnicode_AsUTF8String (obj);` returns NULL. Kind regards, Peter https://lekensteyn.nl #!/usr/bin/env python3 import hivex, sys h = hivex.Hivex(sys.argv[1]) print(h) val = {
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
2020 Aug 05
5
[PATCH NOT WORKING nbdkit 0/3] python: Allow thread model to be set from Python plugins.
...t-python-thread-model.pid -U /tmp/'. Program terminated with signal SIGSEGV, Segmentation fault. #0 0x00007fc4b943e97c in find_name_in_mro (type=<optimized out>, name=0x7fc4aba406b0, error=0x7fc4aa21e7d4) at /usr/src/debug/python3.9-3.9.0~b3-1.fc33.x86_64/Python/errors.c:221 221 PyErr_Occurred(void) [Current thread is 1 (Thread 0x7fc4aa21f640 (LWP 109870))] glibc-2.31.9000-21.fc33.x86_64 gmp-6.1.2-12.fc32.x86_64 libidn2-2.3.0-1.fc32.x86_64 libselinux-3.1-1.fc33.x86_64 libtasn1-4.15.0-1.fc32.x86_64 p11-kit-0.23.18.1-1.fc32.x86_64 pcre2-10.34-4.fc32.x86_64 (gdb) t a a bt Thread 9 (Thread...
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.
2014 Aug 16
7
[hivex] [PATCH 0/6] Python fixes for node_set_value
Hi, This patch series is based on a prior patch[1], splitting off changes as requested and incorporating feedback from Richard Jones. It introduces type validation to avoid segmentation faults (instead, it reports an exception) and fixes handling of the bytes type in Python 3. Major changes since that series: - Drop newly introduced support for integer types for DWORD/QWORDS - Reject Unicode