Eric Blake
2022-Jun-03 22:26 UTC
[Libguestfs] [libnbd PATCH 5/5] python: Accept all buffer-like objects in aio_p{read, write}
After the work in the previous patch, this one is a trivial feature addition ;) Now you can do h.aio_pwrite(b'123', 0). --- python/handle.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/python/handle.c b/python/handle.c index 7f67159..8575097 100644 --- a/python/handle.c +++ b/python/handle.c @@ -104,6 +104,11 @@ nbd_internal_py_get_aio_buffer (PyObject *buffer) if (PyObject_IsInstance (buffer, nbd_internal_py_get_nbd_buffer_type ())) return PyObject_GetAttrString(buffer, "_o"); + if (PyObject_CheckBuffer (buffer)) { + Py_INCREF (buffer); + return buffer; + } + PyErr_SetString (PyExc_TypeError, "aio_buffer: expecting nbd.Buffer instance"); return NULL; -- 2.36.1
Richard W.M. Jones
2022-Jun-04 10:15 UTC
[Libguestfs] [libnbd PATCH 5/5] python: Accept all buffer-like objects in aio_p{read, write}
On Fri, Jun 03, 2022 at 05:26:35PM -0500, Eric Blake wrote:> After the work in the previous patch, this one is a trivial feature > addition ;) Now you can do h.aio_pwrite(b'123', 0). > --- > python/handle.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/python/handle.c b/python/handle.c > index 7f67159..8575097 100644 > --- a/python/handle.c > +++ b/python/handle.c > @@ -104,6 +104,11 @@ nbd_internal_py_get_aio_buffer (PyObject *buffer) > if (PyObject_IsInstance (buffer, nbd_internal_py_get_nbd_buffer_type ())) > return PyObject_GetAttrString(buffer, "_o"); > > + if (PyObject_CheckBuffer (buffer)) { > + Py_INCREF (buffer); > + return buffer; > + } > + > PyErr_SetString (PyExc_TypeError, > "aio_buffer: expecting nbd.Buffer instance"); > return NULL;Reviewed-by: Richard W.M. Jones <rjones at redhat.com> Looks like a good series, thanks. 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
Richard W.M. Jones
2022-Jun-04 10:16 UTC
[Libguestfs] [libnbd PATCH 5/5] python: Accept all buffer-like objects in aio_p{read, write}
On Fri, Jun 03, 2022 at 05:26:35PM -0500, Eric Blake wrote:> After the work in the previous patch, this one is a trivial feature > addition ;) Now you can do h.aio_pwrite(b'123', 0). > --- > python/handle.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/python/handle.c b/python/handle.c > index 7f67159..8575097 100644 > --- a/python/handle.c > +++ b/python/handle.c > @@ -104,6 +104,11 @@ nbd_internal_py_get_aio_buffer (PyObject *buffer) > if (PyObject_IsInstance (buffer, nbd_internal_py_get_nbd_buffer_type ())) > return PyObject_GetAttrString(buffer, "_o"); > > + if (PyObject_CheckBuffer (buffer)) { > + Py_INCREF (buffer); > + return buffer; > + } > + > PyErr_SetString (PyExc_TypeError, > "aio_buffer: expecting nbd.Buffer instance"); > return NULL;Sorry, a late comment on this one. Should we add a test for this, since it's plausibly something that could regress in future? 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