From: Markus Armbruster <armbru@redhat.com>
To: "Marc-André Lureau" <marcandre.lureau@gmail.com>
Cc: QEMU <qemu-devel@nongnu.org>,
Michael Roth <michael.roth@amd.com>,
Kevin Wolf <kwolf@redhat.com>,
Laurent Vivier <laurent@vivier.eu>, Warner Losh <imp@bsdimp.com>,
Kyle Evans <kevans@freebsd.org>,
Hanna Reitz <hreitz@redhat.com>,
Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>,
Fam Zheng <fam@euphon.net>, Eric Blake <eblake@redhat.com>,
"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>,
"open list:Block layer core" <qemu-block@nongnu.org>
Subject: Re: [PATCH 1/9] monitor: make error_vprintf_unless_qmp() static
Date: Fri, 08 Jul 2022 15:56:06 +0200 [thread overview]
Message-ID: <87fsjb6749.fsf@pond.sub.org> (raw)
In-Reply-To: <CAJ+F1CLtkoHZWwyBDJH6ZNek=McM3k8OQhKsVfcidXvRToqY3Q@mail.gmail.com> ("Marc-André Lureau"'s message of "Thu, 7 Jul 2022 21:35:05 +0400")
Marc-André Lureau <marcandre.lureau@gmail.com> writes:
> Hi
>
> On Thu, Jul 7, 2022 at 4:25 PM Markus Armbruster <armbru@redhat.com> wrote:
>
>> marcandre.lureau@redhat.com writes:
>>
>> > From: Marc-André Lureau <marcandre.lureau@redhat.com>
>> >
>> > Not needed outside monitor.c. Remove the needless stub.
>> >
>> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>> > ---
>> > include/monitor/monitor.h | 1 -
>> > monitor/monitor.c | 3 ++-
>> > stubs/error-printf.c | 5 -----
>> > 3 files changed, 2 insertions(+), 7 deletions(-)
>> >
>> > diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h
>> > index a4b40e8391db..44653e195b45 100644
>> > --- a/include/monitor/monitor.h
>> > +++ b/include/monitor/monitor.h
>> > @@ -56,7 +56,6 @@ void monitor_register_hmp(const char *name, bool info,
>> > void monitor_register_hmp_info_hrt(const char *name,
>> > HumanReadableText *(*handler)(Error **errp));
>> >
>> > -int error_vprintf_unless_qmp(const char *fmt, va_list ap) G_GNUC_PRINTF(1, 0);
>> > int error_printf_unless_qmp(const char *fmt, ...) G_GNUC_PRINTF(1, 2);
>> >
>> > #endif /* MONITOR_H */
>> > diff --git a/monitor/monitor.c b/monitor/monitor.c
>> > index 86949024f643..ba4c1716a48a 100644
>> > --- a/monitor/monitor.c
>> > +++ b/monitor/monitor.c
>> > @@ -273,7 +273,8 @@ int error_vprintf(const char *fmt, va_list ap)
>> > return vfprintf(stderr, fmt, ap);
>> > }
>> >
>> > -int error_vprintf_unless_qmp(const char *fmt, va_list ap)
>> > +G_GNUC_PRINTF(1, 0)
>> > +static int error_vprintf_unless_qmp(const char *fmt, va_list ap)
>> > {
>> > Monitor *cur_mon = monitor_cur();
>> >
>> > diff --git a/stubs/error-printf.c b/stubs/error-printf.c
>> > index 0e326d801059..1afa0f62ca26 100644
>> > --- a/stubs/error-printf.c
>> > +++ b/stubs/error-printf.c
>> > @@ -16,8 +16,3 @@ int error_vprintf(const char *fmt, va_list ap)
>> > }
>> > return vfprintf(stderr, fmt, ap);
>> > }
>> > -
>> > -int error_vprintf_unless_qmp(const char *fmt, va_list ap)
>> > -{
>> > - return error_vprintf(fmt, ap);
>> > -}
>>
>> When I write a printf-like utility function, I habitually throw in a
>> vprintf-like function.
>>
>> Any particular reason for hiding this one? To avoid misunderstandings:
>> I'm fine with hiding it if it's causing you trouble.
>
> I don't think I had an issue with it, only that I wrote tests for the
> error-report.h API, and didn't see the need to cover a function that isn't
> used outside the unit.
I'd keep it and not worry about missing tests; the tests of
error_printf_unless_qmp() exercise it fine.
>> Except I think we'd better delete than hide then: inline into
>> error_printf_unless_qmp(). Makes sense?
>
> It can't be easily inlined because of the surrounding va_start/va_end
Easily enough, I think:
diff --git a/monitor/monitor.c b/monitor/monitor.c
index 86949024f6..201a672ac6 100644
--- a/monitor/monitor.c
+++ b/monitor/monitor.c
@@ -273,27 +273,22 @@ int error_vprintf(const char *fmt, va_list ap)
return vfprintf(stderr, fmt, ap);
}
-int error_vprintf_unless_qmp(const char *fmt, va_list ap)
-{
- Monitor *cur_mon = monitor_cur();
-
- if (!cur_mon) {
- return vfprintf(stderr, fmt, ap);
- }
- if (!monitor_cur_is_qmp()) {
- return monitor_vprintf(cur_mon, fmt, ap);
- }
- return -1;
-}
-
int error_printf_unless_qmp(const char *fmt, ...)
{
+ Monitor *cur_mon = monitor_cur();
va_list ap;
int ret;
va_start(ap, fmt);
- ret = error_vprintf_unless_qmp(fmt, ap);
+ if (!cur_mon) {
+ ret = vfprintf(stderr, fmt, ap);
+ } else if (!monitor_cur_is_qmp()) {
+ ret = monitor_vprintf(cur_mon, fmt, ap);
+ } else {
+ ret = -1;
+ }
va_end(ap);
+
return ret;
}
next prev parent reply other threads:[~2022-07-08 13:59 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-16 12:40 [PATCH 0/9] Preliminary patches for subproject split marcandre.lureau
2022-06-16 12:40 ` [PATCH 1/9] monitor: make error_vprintf_unless_qmp() static marcandre.lureau
2022-07-07 12:23 ` Markus Armbruster
2022-07-07 17:35 ` Marc-André Lureau
2022-07-08 13:56 ` Markus Armbruster [this message]
2022-07-08 14:10 ` Marc-André Lureau
2022-06-16 12:40 ` [PATCH 2/9] error-report: misc comment fix marcandre.lureau
2022-06-20 7:22 ` Markus Armbruster
2022-06-16 12:40 ` [PATCH 3/9] error-report: introduce "detailed" variable marcandre.lureau
2022-06-20 7:22 ` Markus Armbruster
2022-06-16 12:40 ` [PATCH 4/9] error-report: simplify print_loc() marcandre.lureau
2022-06-20 7:24 ` Markus Armbruster
2022-06-16 12:40 ` [PATCH 5/9] error-report: introduce ErrorReportDetailedFunc marcandre.lureau
2022-06-16 18:28 ` Warner Losh
2022-07-07 12:11 ` Markus Armbruster
2022-07-07 18:06 ` Marc-André Lureau
2022-06-16 12:40 ` [PATCH 6/9] error-report: add a callback to overwrite error_vprintf marcandre.lureau
2022-07-07 12:16 ` Markus Armbruster
2022-07-07 18:05 ` Marc-André Lureau
2022-07-12 9:32 ` Marc-André Lureau
2022-06-16 12:40 ` [PATCH 7/9] qapi: move QEMU-specific dispatch code in monitor marcandre.lureau
2022-06-16 12:40 ` [PATCH 8/9] scripts/qapi-gen: add -i option marcandre.lureau
2022-06-21 14:13 ` Markus Armbruster
2022-06-23 8:10 ` Marc-André Lureau
2022-08-02 13:27 ` Markus Armbruster
2022-08-03 7:42 ` Marc-André Lureau
2022-08-03 11:16 ` Markus Armbruster
2022-06-16 12:40 ` [PATCH 9/9] scripts/qapi: add required system includes to visitor marcandre.lureau
2022-06-23 13:43 ` Markus Armbruster
2022-07-04 14:55 ` Marc-André Lureau
2022-06-16 13:12 ` [PATCH 0/9] Preliminary patches for subproject split Paolo Bonzini
2022-06-16 13:20 ` Marc-André Lureau
2022-06-28 8:15 ` Marc-André Lureau
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87fsjb6749.fsf@pond.sub.org \
--to=armbru@redhat.com \
--cc=dgilbert@redhat.com \
--cc=eblake@redhat.com \
--cc=fam@euphon.net \
--cc=hreitz@redhat.com \
--cc=imp@bsdimp.com \
--cc=kevans@freebsd.org \
--cc=kwolf@redhat.com \
--cc=laurent@vivier.eu \
--cc=marcandre.lureau@gmail.com \
--cc=michael.roth@amd.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=vsementsov@yandex-team.ru \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.