[Libguestfs] [libnbd PATCH 20/23] generator/C: print_trace_leave: wrap "leave" debug() / debug_direct() call
Laszlo Ersek
lersek at redhat.com
Tue Apr 25 07:11:04 UTC 2023
Similarly to the "print_trace_enter" patch earlier, extract the arg list
printing logic to a named function, and pass that one to "pr_wrap".
Here we need much less work than in "print_trace_enter": no format string
(or other C string literal) can be longer than a line, so we can just wrap
all arguments in one go.
The effect of this patch is [lib/api.c]:
> @@ -247,7 +247,8 @@ nbd_stats_chunks_received (struct nbd_ha
> ret = nbd_unlocked_stats_chunks_received (h);
>
> if_debug (h) {
> - debug_direct (h, "nbd_stats_chunks_received", "leave: ret=%" PRIu64, ret);
> + debug_direct (h, "nbd_stats_chunks_received", "leave: ret=%" PRIu64,
> + ret);
> }
>
> if (h->public_state != get_next_state (h))
> @@ -1211,7 +1212,8 @@ nbd_get_request_structured_replies (stru
> ret = nbd_unlocked_get_request_structured_replies (h);
>
> if_debug (h) {
> - debug_direct (h, "nbd_get_request_structured_replies", "leave: ret=%d", ret);
> + debug_direct (h, "nbd_get_request_structured_replies", "leave: ret=%d",
> + ret);
> }
>
> if (h->public_state != get_next_state (h))
The command "git show -b" is useful with this patch.
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516
Signed-off-by: Laszlo Ersek <lersek at redhat.com>
---
generator/C.ml | 31 +++++++++++---------
1 file changed, 17 insertions(+), 14 deletions(-)
diff --git a/generator/C.ml b/generator/C.ml
index 7c8fffd89435..cff8f854f1d1 100644
--- a/generator/C.ml
+++ b/generator/C.ml
@@ -858,20 +858,23 @@ let
)
else
pr " debug_direct (";
- if may_set_error then
- pr "h, \"leave: ret="
- else
- pr "h, \"nbd_%s\", \"leave: ret=" name;
- (match ret with
- | RBool | RErr | RFd | RInt | REnum _ -> pr "%%d\", ret"
- | RInt64 | RCookie -> pr "%%\" PRIi64, ret"
- | RSizeT -> pr "%%zd\", ret"
- | RString -> pr "%%s\", ret_printable ? ret_printable : \"\""
- | RStaticString -> pr "%%s\", ret"
- | RUInt | RFlags _ -> pr "%%u\", ret"
- | RUIntPtr -> pr "%%\" PRIuPTR, ret"
- | RUInt64 -> pr "%%\" PRIu64, ret"
- );
+ let print_args () =
+ if may_set_error then
+ pr "h, \"leave: ret="
+ else
+ pr "h, \"nbd_%s\", \"leave: ret=" name;
+ (match ret with
+ | RBool | RErr | RFd | RInt | REnum _ -> pr "%%d\", ret"
+ | RInt64 | RCookie -> pr "%%\" PRIi64, ret"
+ | RSizeT -> pr "%%zd\", ret"
+ | RString -> pr "%%s\", ret_printable ? ret_printable : \"\""
+ | RStaticString -> pr "%%s\", ret"
+ | RUInt | RFlags _ -> pr "%%u\", ret"
+ | RUIntPtr -> pr "%%\" PRIuPTR, ret"
+ | RUInt64 -> pr "%%\" PRIu64, ret"
+ )
+ in
+ pr_wrap ',' print_args;
pr ");\n";
if may_set_error then (
(match ret with
More information about the Libguestfs
mailing list