From: Markus Armbruster <armbru@redhat.com>
To: Christian Schoenebeck <qemu_oss@crudebyte.com>
Cc: qemu-devel@nongnu.org, "Nikita Ivanov" <nivanov@cloudlinux.com>,
"Peter Maydell" <peter.maydell@linaro.org>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Greg Kurz" <groug@kaod.org>, "Jason Wang" <jasowang@redhat.com>,
"Michael Roth" <michael.roth@amd.com>,
"Konstantin Kostiuk" <kkostiuk@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>
Subject: Re: [PATCH] error handling: Use TFR() macro where applicable
Date: Mon, 08 Aug 2022 16:22:24 +0200 [thread overview]
Message-ID: <87mtcen7bz.fsf@pond.sub.org> (raw)
In-Reply-To: <7218690.D19hzYb2mh@silver> (Christian Schoenebeck's message of "Mon, 08 Aug 2022 15:11:35 +0200")
Christian Schoenebeck <qemu_oss@crudebyte.com> writes:
> On Montag, 8. August 2022 14:52:28 CEST Christian Schoenebeck wrote:
>> On Montag, 8. August 2022 10:05:56 CEST Markus Armbruster wrote:
>> > Nikita Ivanov <nivanov@cloudlinux.com> writes:
>> > > Summing up the discussion above, I suggest the following patch for TFR()
>> > > macro refactoring. (The patch is sequential to the first one I
>> > > introduced
>> > > in the start of the discussion).
>> > >
>> > >>From 6318bee052900aa93bba6620b53c7cb2290e5001 Mon Sep 17 00:00:00 2001
>> > >>
>> > > From: Nikita Ivanov <nivanov@cloudlinux.com>
>> > > Date: Mon, 8 Aug 2022 09:30:34 +0300
>> > > Subject: [PATCH] Refactoring: rename TFR() to TEMP_FAILURE_RETRY()
>> > >
>> > > glibc's unistd.h header provides the same macro with the
>> > > subtle difference in type casting. Adjust macro name to the
>> > > common standard and define conditionally.
>> > >
>> > > Signed-off-by: Nikita Ivanov <nivanov@cloudlinux.com>
[...]
>> > > diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
>> > > index b1c161c035..55f2927d8b 100644
>> > > --- a/include/qemu/osdep.h
>> > > +++ b/include/qemu/osdep.h
>> > > @@ -242,8 +242,10 @@ void QEMU_ERROR("code path is reachable")
>> > >
>> > > #if !defined(ESHUTDOWN)
>> > > #define ESHUTDOWN 4099
>> > > #endif
>> > >
>> > > -
>> > > -#define TFR(expr) do { if ((expr) != -1) break; } while (errno ==
>> > > EINTR)
>> > > +#if !defined(TEMP_FAILURE_RETRY)
>> > > +#define TEMP_FAILURE_RETRY(expr) \
>> > > + do { if ((expr) != -1) break; } while (errno == EINTR)
To avoid / reduce confusion: this macro expands into a statement, and ...
>> > > +#endif
>> >
>> > GLibc's version is
>> >
>> > # define TEMP_FAILURE_RETRY(expression) \
>> > (__extension__ \
>> > ({ long int __result; \
>> > do __result = (long int) (expression); \
>> > while (__result == -1L && errno == EINTR); \
>> > __result; }))
... this one expands into an expression. It uses GCC's "a compound
statement enclosed in parentheses may appear as an expression" extension.
>> >
>> > The difference isn't just "type casting", it's also statement
>> > vs. expression.
>> >
>> > Is it a good idea to have the macro expand into a statement on some
>> > hosts, and into an expression on others? Sure, CI should catch any uses
>> > as expression, but delaying compile errors to CI wastes developer time.
>>
>> For consistency and simplicity, I would define exactly one version (no
>> ifdefs) of the macro with a different macro name than glibc's
>> TEMP_FAILURE_RETRY(), and use that QEMU specific macro name in QEMU code
>> everywhere.
TFR()? Can't resist closing the circle...
>> As for statement vs. expression: The only advantage of the statement version
>> is if you'd need __result as an rvalue, which is not needed ATM, right? So
>> I would go for the expression version (with cast) for now.
The expression-like macro is nicer where the return value matters.
Example (stolen from "The GNU C Library Reference Manual"):
nbytes = TEMP_FAILURE_RETRY (write (desc, buffer, count));
With the statement-like macro, you have to write
TEMP_FAILURE_RETRY (nbytes = write (desc, buffer, count));
>> The glibc history does not reveal why they chose the statement version.
The expression version, actually.
>> Best regards,
>> Christian Schoenebeck
>
> Sorry: s/rvalue/lvalue/ i.e. if you need the memory address of result or if
> you need to take the result value of the last iteration in 'expression' into
> account.
next prev parent reply other threads:[~2022-08-08 14:24 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-04 7:25 [PATCH] error handling: Use TFR() macro where applicable Nikita Ivanov
2022-08-05 11:10 ` Christian Schoenebeck
2022-08-05 11:18 ` Marc-André Lureau
2022-08-05 11:40 ` Peter Maydell
2022-08-08 7:19 ` Nikita Ivanov
2022-08-08 8:05 ` Markus Armbruster
2022-08-08 8:27 ` Nikita Ivanov
2022-08-08 12:52 ` Christian Schoenebeck
2022-08-08 13:11 ` Christian Schoenebeck
2022-08-08 14:22 ` Markus Armbruster [this message]
2022-08-08 18:00 ` Nikita Ivanov
2022-08-08 18:03 ` Nikita Ivanov
2022-08-17 14:06 ` Nikita Ivanov
2022-08-17 14:16 ` Peter Maydell
2022-08-17 14:49 ` Nikita Ivanov
2022-08-17 15:55 ` Peter Maydell
2022-08-18 14:07 ` Christian Schoenebeck
2022-08-18 14:11 ` Peter Maydell
2022-10-07 11:44 ` Nikita Ivanov
2022-10-07 14:50 ` Christian Schoenebeck
2022-10-07 15:32 ` Peter Maydell
2022-10-10 8:33 ` Nikita Ivanov
2022-10-10 9:56 ` Peter Maydell
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=87mtcen7bz.fsf@pond.sub.org \
--to=armbru@redhat.com \
--cc=groug@kaod.org \
--cc=jasowang@redhat.com \
--cc=kkostiuk@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=michael.roth@amd.com \
--cc=nivanov@cloudlinux.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu_oss@crudebyte.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).