[Libguestfs] [PATCH 2/2] python: change return type for RBufferOut with Python 3 (RHBZ#1661871)
Richard W.M. Jones
rjones at redhat.com
Tue Jan 22 13:12:52 UTC 2019
On Tue, Jan 22, 2019 at 02:00:22PM +0100, Pino Toscano wrote:
> So far RBufferOut return values are 'str' on all the versions of Python.
> Python 3 distinguishes between 'str' (unicode strings), and 'bytes',
> with 'str' no more able to hold arbitrary data.
>
> For this reason, switch the return value of RBufferOut functions to
> bytes on Python 3: while this is a potentially incompatibile change,
> this is the only way to handle safely sequences of arbitrary bytes, like
> all the ones returned by RBufferOut functions.
> ---
> generator/python.ml | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/generator/python.ml b/generator/python.ml
> index a70faec8c..c10adcb69 100644
> --- a/generator/python.ml
> +++ b/generator/python.ml
> @@ -511,7 +511,11 @@ and generate_python_actions actions () =
> pr " guestfs_int_free_string_list (r);\n";
> pr " if (py_r == NULL) goto out;\n";
> | RBufferOut _ ->
> + pr "#if PY_MAJOR_VERSION >= 3\n";
> + pr " py_r = PyBytes_FromStringAndSize (r, size);\n";
> + pr "#else\n";
> pr " py_r = guestfs_int_py_fromstringsize (r, size);\n";
> + pr "#endif\n";
> pr " free (r);\n";
> pr " if (py_r == NULL) goto out;\n";
> );
> --
ACK series.
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
libguestfs lets you edit virtual machines. Supports shell scripting,
bindings from many languages. http://libguestfs.org
More information about the Libguestfs
mailing list