On Tue, Jun 07, 2022 at 08:53:23AM -0500, Eric Blake wrote:
 On Tue, Jun 07, 2022 at 09:00:08AM +0100, Richard W.M. Jones wrote:
 > On Mon, Jun 06, 2022 at 09:08:29PM -0500, Eric Blake wrote:
 > > +  pr ":nbd_%s\",\n" name;
 > 
 > You could put this pr (but without the \n) ...
 > 
 > > +  pr "                         ";
 > > +  pr_wrap ',' (fun () ->
 > 
 > ... inside pr_wrap here, and it would mean you wouldn't need to print
 > spaces to indent (because pr_wrap should do it for you).
 
 Will do. It rearranges a few more lines of generated code (now the
 &py_h argument can sometimes be a line earlier), but is still legible.
 
 > 
 > It all looks sensible and equivalent to the old code, and the output
 > is cleaner too, so:
 > 
 > Reviewed-by: Richard W.M. Jones <rjones(a)redhat.com>
 >
 
 I get when we have more than one statement to bundle how the OCaml
 (fun () -> ... ) construct makes sense, but do we need that for this hunk?
 
 > @@ -284,7 +285,10 @@ let
 >  (* Generate the Python binding. *)
 >  let print_python_binding name { args; optargs; ret; may_set_error } =
 >    pr "PyObject *\n";
 > -  pr "nbd_internal_py_%s (PyObject *self, PyObject *args)\n" name;
 > +  pr "nbd_internal_py_%s (" name;
 > +  pr_wrap ',' (fun () ->
 > +      pr "PyObject *self, PyObject *args");
 > +  pr ")\n";
 >    pr "{\n";
 >    pr "  PyObject *py_h;\n";
 >    pr "  struct nbd_handle *h;\n";
 
 or is there a shorter way to write that one? 
I don't think so (except to write it all on a single line).
The pr_wrap function is a bit weird in that it requires a sub-function
that generates the buffer that it then wraps, rather than just taking
a string parameter directly.  Could imagine a pr_wrap_string function
that took the string buffer directly, but that doesn't exist today.
Rich.
-- 
Richard Jones, Virtualization Group, Red Hat 
http://people.redhat.com/~rjones
Read my programming and virtualization blog: 
http://rwmj.wordpress.com
nbdkit - Flexible, fast NBD server with plugins
https://gitlab.com/nbdkit/nbdkit