Displaying 8 results from an estimated 8 matches for "pyunicode_check".
2018 Apr 05
1
Re: [PATCH nbdkit] python: Turn python exceptions into nbdkit errors properly.
...++++
> 5 files changed, 144 insertions(+), 3 deletions(-)
>
> +/* Convert bytes/str/unicode into a string. Caller must free. */
> +static char *
> +python_to_string (PyObject *str)
> +{
> + char *r;
> +
> + if (str) {
> +#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...
2014 Aug 08
2
[PATCH 1/2] Add type checking, support integers as value
...n -1;
+ }
obj = PyDict_GetItemString (v, \"key\");
if (!obj) {
- PyErr_SetString (PyExc_RuntimeError, \"no 'key' element in dictionary\");
+ PyErr_SetString (PyExc_KeyError, \"no 'key' element in dictionary\");
+ return -1;
+ }
+ if (PyUnicode_Check (obj)) {
+ bytes = PyUnicode_AsUTF8String (obj);
+ if (bytes == NULL) {
+ return -1;
+ }
+ } else if (PyBytes_Check (obj)) {
+ bytes = obj;
+ } else {
+ PyErr_SetString (PyExc_TypeError, \"expected bytes or str type for 'key'\");
return -1;
}
-#ifdef...
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.
2019 Sep 11
0
[PATCH nbdkit] python: Drop support for Python 2.
...UBST([PYTHON_CFLAGS])
diff --git a/plugins/python/python.c b/plugins/python/python.c
index 20232f4..2e1a53f 100644
--- a/plugins/python/python.c
+++ b/plugins/python/python.c
@@ -117,17 +117,9 @@ static char *
python_to_string (PyObject *str)
{
if (str) {
-#ifdef HAVE_PYUNICODE_ASUTF8
if (PyUnicode_Check (str))
return strdup (PyUnicode_AsUTF8 (str));
- else
-#endif
-#ifdef HAVE_PYSTRING_ASSTRING
- if (PyString_Check (str))
- return strdup (PyString_AsString (str));
- else
-#endif
- if (PyBytes_Check (str))
+ else if (PyBytes_Check (str))
return strdup (PyBytes_AS_S...
2018 Apr 05
0
[PATCH nbdkit] python: Turn python exceptions into nbdkit errors properly.
...s/python/python.c
@@ -103,13 +103,58 @@ callback_defined (const char *name, PyObject **obj_rtn)
return 1;
}
+/* Convert bytes/str/unicode into a string. Caller must free. */
+static char *
+python_to_string (PyObject *str)
+{
+ char *r;
+
+ if (str) {
+#ifdef HAVE_PYUNICODE_ASUTF8
+ if (PyUnicode_Check (str)) {
+ r = PyUnicode_AsUTF8 (str);
+ r = strdup (r);
+ return r;
+ }
+ else
+#endif
+#ifdef HAVE_PYSTRING_ASSTRING
+ if (PyString_Check (str)) {
+ r = PyString_AsString (str); /* Internal pointer in PyObject. */
+ r = strdup (r);
+ return r;
+ }
+ el...
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 Sep 11
3
[PATCH nbdkit] python: Drop support for Python 2.
This patch proposes to drop support for Python 2 in nbdkit.
Rather than abruptly drop it everywhere, my proposal is that we point
people to nbdkit 1.14 (the current stable version) if they want to
continue with Python 2 plugins, while gently reminding them of the
upcoming Python 2.7 end of life announcement.
Libnbd never supported Python 2. Libguestfs in theory supports
Python 2 but I dropped
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