Laszlo Ersek
2023-Apr-25 07:10 UTC
[Libguestfs] [libnbd PATCH 11/23] generator/C: print_trace_enter: break "enter" to a common new line
Going forward, we'd like to wrap long string literals. The recently introduced "pr_wrap_cstr" function may only be called right after the opening quote of the string literal has been produced. In the "print_trace_enter" function, we start a long string literal with "enter:"; however, because we either pass the literal to debug() or debug_direct(), this "enter:" is spelled out twice. Factor "enter:" out to a common line, also ensuring that we'll have as much room for wrapping as possible. Example effect [lib/api.c]:> @@ -6220,7 +6360,8 @@ nbd_supports_uri (struct nbd_handle *h) > > /* This function must not call set_error. */ > if_debug (h) { > - debug_direct (h, "nbd_supports_uri", "enter:"); > + debug_direct (h, "nbd_supports_uri", > + "enter:"); > } > > ret = nbd_unlocked_supports_uri (h); > @@ -6260,7 +6401,8 @@ nbd_get_uri (struct nbd_handle *h) > > pthread_mutex_lock (&h->lock); > if_debug (h) { > - debug (h, "enter:"); > + debug (h, > + "enter:"); > } > > if (unlikely (!get_uri_in_permitted_state (h))) {Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516 Signed-off-by: Laszlo Ersek <lersek at redhat.com> --- generator/C.ml | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/generator/C.ml b/generator/C.ml index b65d3de2e82d..0ccf6970d43c 100644 --- a/generator/C.ml +++ b/generator/C.ml @@ -734,11 +734,17 @@ let | Int64 _ | SizeT _ | SockAddrAndLen _ | UInt _ | UInt32 _ | UInt64 _ | UIntPtr _ -> () ) args; - if may_set_error then - pr " debug (h, \"enter:" - else ( - pr " debug_direct (h, \"nbd_%s\", \"enter:" name - ); + let indent + if may_set_error then ( + pr " debug (h,\n"; + spaces 11 + ) + else ( + pr " debug_direct (h, \"nbd_%s\",\n" name; + spaces 18 + ) in + pr "%s\"" indent; + pr "enter:"; List.iter ( function | Bool n -> pr " %s=%%s" n
Eric Blake
2023-Apr-25 21:52 UTC
[Libguestfs] [libnbd PATCH 11/23] generator/C: print_trace_enter: break "enter" to a common new line
On Tue, Apr 25, 2023 at 09:10:55AM +0200, Laszlo Ersek wrote:> Going forward, we'd like to wrap long string literals. The recently > introduced "pr_wrap_cstr" function may only be called right after the > opening quote of the string literal has been produced. In the > "print_trace_enter" function, we start a long string literal with > "enter:"; however, because we either pass the literal to debug() or > debug_direct(), this "enter:" is spelled out twice. Factor "enter:" out to > a common line, also ensuring that we'll have as much room for wrapping as > possible. > > Example effect [lib/api.c]: > > > @@ -6220,7 +6360,8 @@ nbd_supports_uri (struct nbd_handle *h) > > > > /* This function must not call set_error. */ > > if_debug (h) { > > - debug_direct (h, "nbd_supports_uri", "enter:"); > > + debug_direct (h, "nbd_supports_uri", > > + "enter:"); > > } > > > > ret = nbd_unlocked_supports_uri (h); > > @@ -6260,7 +6401,8 @@ nbd_get_uri (struct nbd_handle *h) > > > > pthread_mutex_lock (&h->lock); > > if_debug (h) { > > - debug (h, "enter:"); > > + debug (h, > > + "enter:");Looks a little funny to not wrap here; but it's generated code, and the context above makes it obvious why it is easier to wrap in both places (when the debug_direct call above has an obvious reason for wrapping). So far, I have no objections to this series, but I've hit the end of my reviewing day. For 1-11: Reviewed-by: Eric Blake <eblake at redhat.com> -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org