search for: pytuple_new

Displaying 20 results from an estimated 30 matches for "pytuple_new".

2018 Apr 06
0
[nbdkit PATCH 2/2] python: Simplify calling into plugin
..., const char *value) FILE *fp; PyObject *modname; PyObject *fn; - PyObject *args; PyObject *r; if (!script) { @@ -258,17 +257,8 @@ py_config (const char *key, const char *value) /* Other parameters are passed to the Python .config callback. */ PyErr_Clear (); - args = PyTuple_New (2); -#ifdef HAVE_PYSTRING_FROMSTRING - PyTuple_SetItem (args, 0, PyString_FromString (key)); - PyTuple_SetItem (args, 1, PyString_FromString (value)); -#else - PyTuple_SetItem (args, 0, PyUnicode_FromString (key)); - PyTuple_SetItem (args, 1, PyUnicode_FromString (value)); -#endif -...
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
2017 May 09
1
[PATCH] RHBZ#1406906: check return value of Python object functions
...table (char * const * const argv) { - PyObject *list, *item; + PyObject *list, *tuple, *item; size_t argc, i; for (argc = 0; argv[argc] != NULL; ++argc) ; list = PyList_New (argc >> 1); + if (list == NULL) + return NULL; for (i = 0; i < argc; i += 2) { - item = PyTuple_New (2); - PyTuple_SetItem (item, 0, guestfs_int_py_fromstring (argv[i])); - PyTuple_SetItem (item, 1, guestfs_int_py_fromstring (argv[i+1])); + tuple = PyTuple_New (2); + if (tuple == NULL) + goto err; + item = guestfs_int_py_fromstring (argv[i]); + if (item == NULL) + goto...
2014 Feb 03
1
[PATCH] hivex: python: value_value no longer generates Unicode strings
...----- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/generator/generator.ml b/generator/generator.ml index 908c5f3..02aaf12 100755 --- a/generator/generator.ml +++ b/generator/generator.ml @@ -2981,7 +2981,7 @@ put_val_type (char *val, size_t len, hive_type t) { PyObject *r = PyTuple_New (2); PyTuple_SetItem (r, 0, PyLong_FromLong ((long) t)); - PyTuple_SetItem (r, 1, PyUnicode_DecodeUTF8 (val, len, NULL)); + PyTuple_SetItem (r, 1, PyBytes_FromStringAndSize (val, len)); return r; } diff --git a/python/t/210-setvalue.py b/python/t/210-setvalue.py index 2ee7ac5..8e7ed5c 10...
2011 Dec 08
0
[hivex] [PATCH 2/8] generator: Add new return type to ABI: RLenValue
...PUSHs (sv_2mortal (newSViv (r)));\n"; + | RLenTypeVal -> pr "PREINIT:\n"; pr " char *r;\n"; @@ -2886,6 +2935,15 @@ put_len_type (size_t len, hive_type t) } static PyObject * +put_len_val (size_t len, hive_value_h value) +{ + PyObject *r = PyTuple_New (2); + PyTuple_SetItem (r, 0, PyLong_FromLongLong ((long) len)); + PyTuple_SetItem (r, 1, PyLong_FromLongLong ((long) value)); + return r; +} + +static PyObject * put_val_type (char *val, size_t len, hive_type t) { PyObject *r = PyTuple_New (2); @@ -2929,6 +2987,11 @@ put_val_type (char *va...
2019 Jun 28
3
[PATCH libnbd v3] python: Raise a custom exception containing error string and errno.
Following Eric's suggestions from v2, this adds .string, .errno and .__str__ properties. The .string property returns the error string. The .errno property returns the errno (from the errno module), or None. The __str__ property makes the exception nicely printable. Rich.
2011 Oct 19
1
[hivex][PATCH 2/8] generator: Add new return type to ABI: RLenValue
...PUSHs (sv_2mortal (newSViv (r)));\n"; + | RLenTypeVal -> pr "PREINIT:\n"; pr " char *r;\n"; @@ -2877,6 +2926,15 @@ put_len_type (size_t len, hive_type t) } static PyObject * +put_len_val (size_t len, hive_value_h value) +{ + PyObject *r = PyTuple_New (2); + PyTuple_SetItem (r, 0, PyLong_FromLongLong ((long) len)); + PyTuple_SetItem (r, 1, PyLong_FromLongLong ((long) value)); + return r; +} + +static PyObject * put_val_type (char *val, size_t len, hive_type t) { PyObject *r = PyTuple_New (2); @@ -2916,6 +2974,11 @@ put_val_type (char *va...
2017 May 11
1
[PATCH v2] RHBZ#1406906: check return value of Python object functions
...table (char * const * const argv) { - PyObject *list, *item; + PyObject *list, *tuple, *item; size_t argc, i; for (argc = 0; argv[argc] != NULL; ++argc) ; list = PyList_New (argc >> 1); + if (list == NULL) + return NULL; for (i = 0; i < argc; i += 2) { - item = PyTuple_New (2); - PyTuple_SetItem (item, 0, guestfs_int_py_fromstring (argv[i])); - PyTuple_SetItem (item, 1, guestfs_int_py_fromstring (argv[i+1])); - PyList_SetItem (list, i >> 1, item); + tuple = PyTuple_New (2); + if (tuple == NULL) + goto err; + item = guestfs_int_py_fromstri...
2018 Apr 06
1
[nbdkit PATCH] python: Let zero's may_trim parameter be optional
...("zero", &fn)) { + 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); + args = PyTuple_New (3); 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...
2019 Nov 22
0
[PATCH nbdkit v2 01/10] python: Use PyObject_CallFunction instead of constructing the tuple.
...hon/python.c @@ -557,26 +557,21 @@ py_zero (void *handle, uint32_t count, uint64_t offset, int may_trim) { PyObject *obj = handle; PyObject *fn; - PyObject *args; PyObject *r; if (callback_defined ("zero", &fn)) { 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_SetItem (args, 2, PyLong_FromUnsignedLongLong (offset)); - PyTuple_SetItem (args, 3, PyBool_FromLong (may_trim))...
2019 Nov 21
0
[PATCH nbdkit 1/8] python: Use PyObject_CallFunction instead of constructing the tuple.
...hon/python.c @@ -557,26 +557,21 @@ py_zero (void *handle, uint32_t count, uint64_t offset, int may_trim) { PyObject *obj = handle; PyObject *fn; - PyObject *args; PyObject *r; if (callback_defined ("zero", &fn)) { 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_SetItem (args, 2, PyLong_FromUnsignedLongLong (offset)); - PyTuple_SetItem (args, 3, PyBool_FromLong (may_trim))...
2014 Jan 15
0
[PATCH 3/4] hivex: python: Produce Unicode strings in get_* methods
...String (argv[i])); -#else - PyList_SetItem (list, i, PyUnicode_FromString (argv[i])); -#endif + PyList_SetItem (list, i, PyUnicode_DecodeUTF8 (argv[i], strlen (argv[i]), NULL)); } return list; @@ -2985,11 +2981,7 @@ put_val_type (char *val, size_t len, hive_type t) { PyObject *r = PyTuple_New (2); PyTuple_SetItem (r, 0, PyLong_FromLong ((long) t)); -#ifdef HAVE_PYSTRING_ASSTRING - PyTuple_SetItem (r, 1, PyString_FromStringAndSize (val, len)); -#else - PyTuple_SetItem (r, 1, PyBytes_FromStringAndSize (val, len)); -#endif + PyTuple_SetItem (r, 1, PyUnicode_DecodeUTF8 (val, len, NULL...
2019 Jun 28
3
[PATCH libnbd v2] python: Raise a custom exception containing error string and errno.
This kind of fixes the problems in v1. The exception still primarily lives in the libnbdmod and you could still refer to it using libnbdmod.Error (but don't do that). However when the exception is printed it now appears as nbd.Error, and you can catch it also using the same name. Other problems: - There is no "nice" interface to accessing the exception fields. You have to use
2017 May 09
1
[PATCH v2] python: add simple wrappers for PyObject<->string functions
...i, PyUnicode_FromString (argv[i])); -#endif + PyList_SetItem (list, i, guestfs_int_py_fromstring (argv[i])); } return list; @@ -367,15 +350,41 @@ guestfs_int_py_put_table (char * const * const argv) list = PyList_New (argc >> 1); for (i = 0; i < argc; i += 2) { item = PyTuple_New (2); -#ifdef HAVE_PYSTRING_ASSTRING - PyTuple_SetItem (item, 0, PyString_FromString (argv[i])); - PyTuple_SetItem (item, 1, PyString_FromString (argv[i+1])); -#else - PyTuple_SetItem (item, 0, PyUnicode_FromString (argv[i])); - PyTuple_SetItem (item, 1, PyUnicode_FromString (argv[i+1]))...
2017 Jan 26
0
[nbdkit PATCH v2 6/6] python: Support zero callback
...uint64_t offset) } static int +py_zero (void *handle, uint32_t count, uint64_t offset, int may_trim) +{ + PyObject *obj = handle; + PyObject *fn; + PyObject *args; + PyObject *r; + + if (callback_defined ("zero", &fn)) { + 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_SetItem (args, 2, PyLong_FromUnsignedLongLong (offset)); + PyTuple_SetItem (args, 3, PyBool_FromLong (may_trim))...
2017 Jan 27
0
[nbdkit PATCH v3 4/4] python: Support zero callback
...uint64_t offset) } static int +py_zero (void *handle, uint32_t count, uint64_t offset, int may_trim) +{ + PyObject *obj = handle; + PyObject *fn; + PyObject *args; + PyObject *r; + + if (callback_defined ("zero", &fn)) { + 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_SetItem (args, 2, PyLong_FromUnsignedLongLong (offset)); + PyTuple_SetItem (args, 3, PyBool_FromLong (may_trim))...
2019 Jun 28
0
[PATCH libnbd v2] python: Raise a custom exception containing error string and errno.
...+++ b/generator/generator @@ -3337,6 +3337,19 @@ get_handle (PyObject *obj) return (struct nbd_handle *) PyCapsule_GetPointer(obj, \"nbd_handle\"); } +/* nbd.Error exception. */ +extern PyObject *nbd_internal_py_Error; + +static inline void +raise_exception () +{ + PyObject *args = PyTuple_New (2); + + PyTuple_SetItem (args, 0, PyUnicode_FromString (nbd_get_error ())); + PyTuple_SetItem (args, 1, PyLong_FromLong (nbd_get_errno ())); + PyErr_SetObject (nbd_internal_py_Error, args); +} + "; List.iter ( @@ -3390,6 +3403,9 @@ static struct PyModuleDef moduledef = { NULL,...
2019 Jun 28
1
[PATCH libnbd] python: Raise a custom exception containing error string and errno.
I spent a good few hours this morning trying to make this work and came up with the following patch. It's not quite right though. The exception I've created exists in the libnbdmod module (ie. the underlying C module that we use for the Python bindings). Ideally we'd define and throw an exception from the normal nbd module, but I couldn't work out how to do that. Probably
2017 May 06
5
[Bug 1406906] [PATCH 0/3] Fix segmentation fault in Python bindings
This series addresses the issue where non UTF8 file names in a guest image lead to libguestfs segfault with Python 3 APIs. The core issue is the APIs are not checking the return value when constructing a new PyObject. Therefore NULL pointers are added to Python collections (lists and dictionaries) crashing the application. Few notes regarding the comments on the previous patch. - Added a
2019 Jun 28
0
[PATCH libnbd v3] python: Raise a custom exception containing error string and errno.
...+++ b/generator/generator @@ -3337,6 +3337,19 @@ get_handle (PyObject *obj) return (struct nbd_handle *) PyCapsule_GetPointer(obj, \"nbd_handle\"); } +/* nbd.Error exception. */ +extern PyObject *nbd_internal_py_Error; + +static inline void +raise_exception () +{ + PyObject *args = PyTuple_New (2); + + PyTuple_SetItem (args, 0, PyUnicode_FromString (nbd_get_error ())); + PyTuple_SetItem (args, 1, PyLong_FromLong (nbd_get_errno ())); + PyErr_SetObject (nbd_internal_py_Error, args); +} + "; List.iter ( @@ -3390,6 +3403,9 @@ static struct PyModuleDef moduledef = { NULL,...