Signed-off-by: Matteo Cafasso <noxdafox@gmail.com> --- generator/python.ml | 3 ++- python/handle.c | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/generator/python.ml b/generator/python.ml index 4cae24757..f7c1f80bb 100644 --- a/generator/python.ml +++ b/generator/python.ml @@ -93,6 +93,7 @@ extern PyObject *guestfs_int_py_put_string_list (char * const * const argv); extern PyObject *guestfs_int_py_put_table (char * const * const argv); extern PyObject *guestfs_int_py_fromstring (const char *str); extern PyObject *guestfs_int_py_fromstringsize (const char *str, size_t size); +extern PyObject *guestfs_int_py_bytesfromstringsize (const char *str, size_t size); extern char *guestfs_int_py_asstring (PyObject *obj); "; @@ -513,7 +514,7 @@ and generate_python_actions actions () = pr " guestfs_int_free_string_list (r);\n"; pr " if (py_r == NULL) goto out;\n"; | RBufferOut _ -> - pr " py_r = guestfs_int_py_fromstringsize (r, size);\n"; + pr " py_r = guestfs_int_py_bytesfromstringsize (r, size);\n"; pr " free (r);\n"; pr " if (py_r == NULL) goto out;\n"; ); diff --git a/python/handle.c b/python/handle.c index d93f2f021..52c36f1d2 100644 --- a/python/handle.c +++ b/python/handle.c @@ -400,6 +400,16 @@ guestfs_int_py_fromstringsize (const char *str, size_t size) #endif } +PyObject * +guestfs_int_py_bytesfromstringsize (const char *str, size_t size) +{ +#ifdef HAVE_PYSTRING_ASSTRING + return PyString_FromStringAndSize (str, size); +#else + return PyBytes_FromStringAndSize (str, size); +#endif +} + char * guestfs_int_py_asstring (PyObject *obj) { -- 2.11.0