[Libguestfs] [libnbd PATCH v2 5/8] python: Make py_aio_buffer a private struct
Richard W.M. Jones
rjones at redhat.com
Tue Jun 7 13:17:01 UTC 2022
On Mon, Jun 06, 2022 at 09:08:30PM -0500, Eric Blake wrote:
> Instead of having methods.c poking into the internals of a struct that
> we defined, have it use PyMemoryView* and Py_buffer*; this separation
> makes it easier to separate how we store the persistent data (for now,
> in a PyCapsule) from how we access the data. Eventually, the use of
> PyMemoryView* will make it easier for future patches to get rid of
> some layers of copying. nbd_internal_py_init_aio_buffer() is new; for
> now it doesn't fail, but it can in a future patch.
>
> For now, we still have to hang on to a python reference to the
> PyCapsule object holding our malloc'd C pointer, and since the
> MemoryView we just created is not backed by a Python object, we must
> ensure we don't leak it to Python code. But this will change in an
> upcoming patch.
>
[...]
> @@ -477,13 +481,8 @@ let
> (* Second pass, and call the underlying C function. *)
> List.iter (
> function
> - | BytesPersistIn (n, _) ->
> - pr " if (!%s_buf->initialized) {\n" n;
> - pr " memset (%s_buf->data, 0, %s_buf->len);\n" n n;
> - pr " %s_buf->initialized = true;\n" n;
> - pr " }\n"
> | BytesPersistOut (n, _) ->
> - pr " %s_buf->initialized = true;\n" n
> + pr " if (nbd_internal_py_init_aio_buffer (%s) < 0) goto out;\n" n
Can't fail, but that was noted in the commit message so that's OK.
Reviewed-by: Richard W.M. Jones <rjones at redhat.com>
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-builder quickly builds VMs from scratch
http://libguestfs.org/virt-builder.1.html
More information about the Libguestfs
mailing list