[Libguestfs] [libnbd PATCH 2/2] RFC: generator: Handle shared callbacks in Python

Richard W.M. Jones rjones at redhat.com
Tue Jul 16 07:46:32 UTC 2019


I have a partial patch which fixes this in a slightly different (but
overall quite similar) way.  The key observations are:

(1) OpaqueAndCallbacks is otherwise known as a list of Closures.  A
closure list in C corresponds to an opaque pointer + several function
pointers (as in your patch).

(2) But in other languages, Closures capture local state already so
don't require the opaque pointer at all.  ie. In OCaml you can already
write this to capture some local_data in the closure:

  let my_chunk_cb local_data subbuf count offset stats error =
    ...
  in

  NBD.pread_structured buf count offset (my_chunk_cb local_data) flags

Similarly in Python you can use lambda.  There's no need for the
opaque to be explicit at all in non-C languages.

(3) I don't think we actually have to name the opaque pointer.  We can
just always call it "void *user_data" in C.  (There is max one opaque
pointer per function).  This simplifies things a bit.

(4) We can also probably assume that either all non-persistent or all
persistent callbacks are required.  (Your patch does that already, but
mine uses a boolean flag instead of separate case).

Will post later.

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