[libnbd PATCH v2 0/2] continue wrapping generated C code harder
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516 v1: https://listman.redhat.com/archives/libguestfs/2023-April/031375.html In v2, move the declaration of the "p" helper variable next to the top of the function. Thanks! Laszlo Laszlo Ersek (2): generator/C: print_wrapper: use helper variable for permitted state check generator/C: lib/api.c: indent arg list 2 spaces relative to function name generator/C.ml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) base-commit: 2fa6198f61d4e84a228155c973cdf1a2b581b705
Use a local boolean flag for unnesting the *_in_permitted_state() function call. The one place where this change currently matters is [lib/api.c]:
@@ -4787,29 +4925,31 @@ aio_connect_systemd_socket_activation_in return true; }
int nbd_aio_connect_systemd_socket_activation (struct nbd_handle *h, char **argv) { + bool p; int ret;
nbd_internal_set_error_context ("nbd_aio_connect_systemd_socket_activation");
pthread_mutex_lock (&h->lock); if_debug (h) { char *argv_printable = nbd_internal_printable_string_list (argv); debug (h, "enter: argv=%s", argv_printable ? argv_printable : ""); free (argv_printable); }
- if (unlikely (!aio_connect_systemd_socket_activation_in_permitted_state (h))) { + p = aio_connect_systemd_socket_activation_in_permitted_state (h); + if (unlikely (!p)) { ret = -1; goto out; } if (argv == NULL) { set_error (EFAULT, "%s cannot be NULL", "argv"); ret = -1; goto out;
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516 Signed-off-by: Laszlo Ersek <lersek@redhat.com> --- Notes: v2: - declare "p" near the top of the function [Eric] generator/C.ml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/generator/C.ml b/generator/C.ml index cf44424517de..e68fd70382cf 100644 --- a/generator/C.ml +++ b/generator/C.ml @@ -569,6 +569,8 @@ let print_arg_list ~wrap:true ~handle:true args optargs; pr "\n"; pr "{\n"; + if permitted_states <> [] then + pr " bool p;\n"; pr " %s ret;\n" ret_c_type; pr "\n"; if may_set_error then ( @@ -599,7 +601,8 @@ let let value = match errcode with | Some value -> value | None -> assert false in - pr " if (unlikely (!%s_in_permitted_state (h))) {\n" name; + pr " p = %s_in_permitted_state (h);\n" name; + pr " if (unlikely (!p)) {\n"; pr " ret = %s;\n" value; pr " goto out;\n"; pr " }\n";
Do the same as commit 0744f748ed90 ("generator: indent C argument list 2 spaces relative to function designator", 2023-04-21), except this time not for the header files, but for "lib/api.c". The most impactful resultant change is [lib/api.c]:
@@ -5378,9 +5577,11 @@ aio_opt_list_meta_context_queries_in_per }
int -nbd_aio_opt_list_meta_context_queries (struct nbd_handle *h, char **queries, - nbd_context_callback context_callback, - nbd_completion_callback completion_callback) +nbd_aio_opt_list_meta_context_queries ( + struct nbd_handle *h, char **queries, + nbd_context_callback context_callback, + nbd_completion_callback completion_callback +) { bool p; int ret;
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516 Signed-off-by: Laszlo Ersek <lersek@redhat.com> --- Notes: v2: - refresh diff in commit message: the quoted context changes due to the update to the preceding patch in the series generator/C.ml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/generator/C.ml b/generator/C.ml index e68fd70382cf..f772117cd3c9 100644 --- a/generator/C.ml +++ b/generator/C.ml @@ -566,7 +566,8 @@ let let ret_c_type = type_of_ret ret and errcode = errcode_of_ret ret in pr "%s\n" ret_c_type; pr "nbd_%s " name; - print_arg_list ~wrap:true ~handle:true args optargs; + print_arg_list ~wrap:true ~handle:true ~parens:(ParensNewLineWithIndent 0) + args optargs; pr "\n"; pr "{\n"; if permitted_states <> [] then
For the series: Reviewed-by: Richard W.M. Jones <rjones@redhat.com> Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 100 libraries supported. http://fedoraproject.org/wiki/MinGW
On Tue, May 02, 2023 at 07:04:24PM +0200, Laszlo Ersek wrote:
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516 v1: https://listman.redhat.com/archives/libguestfs/2023-April/031375.html
In v2, move the declaration of the "p" helper variable next to the top of the function.
Series: Reviewed-by: Eric Blake <eblake@redhat.com>
Thanks! Laszlo
Laszlo Ersek (2): generator/C: print_wrapper: use helper variable for permitted state check generator/C: lib/api.c: indent arg list 2 spaces relative to function name
generator/C.ml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
base-commit: 2fa6198f61d4e84a228155c973cdf1a2b581b705 _______________________________________________ Libguestfs mailing list Libguestfs@redhat.com https://listman.redhat.com/mailman/listinfo/libguestfs
-- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
On 5/2/23 19:04, Laszlo Ersek wrote:
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516 v1: https://listman.redhat.com/archives/libguestfs/2023-April/031375.html
In v2, move the declaration of the "p" helper variable next to the top of the function.
Thanks! Laszlo
Laszlo Ersek (2): generator/C: print_wrapper: use helper variable for permitted state check generator/C: lib/api.c: indent arg list 2 spaces relative to function name
generator/C.ml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
base-commit: 2fa6198f61d4e84a228155c973cdf1a2b581b705
Thanks for the reviews; commit range 2fa6198f61d4..99d18799f407. Laszlo
participants (3)
-
Eric Blake -
Laszlo Ersek -
Richard W.M. Jones