[Libguestfs] [libnbd PATCH v2 8/8] python: Make nbd.Buffer lighter-weight

Eric Blake eblake at redhat.com
Tue Jun 7 16:37:26 UTC 2022


On Tue, Jun 07, 2022 at 02:20:35PM +0100, Richard W.M. Jones wrote:
> On Mon, Jun 06, 2022 at 09:08:33PM -0500, Eric Blake wrote:
> > Instead of storing a PyCapsule in _o and repeatedly doing lookups to
> > dereference a stored malloc'd pointer, it is easier to just directly
> > store a Python buffer-like object as _o.  Track initialization via
> > ._init: absent for nbd.Buffer(int), present for
> > nbd.Buffer.from_bytearray or after we have forced initialization due
> > to aio_pread or .to_bytearray.  At this point, we are still copying in
> > and out of .{from,to}_bytearray, but we are getting closer to reducing
> > the number of copies.  The sheer size in reduced lines of code is a
> > testament to the ease of doing things closer to Python, rather than
> > hidden behind unpacking a PyCapsule layer.
> > 

> 
> Looks like a nice simplification!
> 
> Reviewed-by: Richard W.M. Jones <rjones at redhat.com>

Series now in as 08a3804..4f15d0e.  Next up - fixing
[aio_]pread_structured to expose slices of the underlying Python
object, and teaching nbd.Buffer to reuse (rather than copy) buffers.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org


More information about the Libguestfs mailing list