From: Juan Quintela <quintela@redhat.com>
To: Eric Blake <eblake@redhat.com>
Cc: qemu-devel@nongnu.org, armbru@redhat.com,
qemu-trivial@nongnu.org, pbonzini@redhat.com,
Gerd Hoffmann <kraxel@redhat.com>,
Alistair Francis <alistair@alistair23.me>,
Peter Crosthwaite <crosthwaite.peter@gmail.com>,
Kevin Wolf <kwolf@redhat.com>, Max Reitz <mreitz@redhat.com>,
"Edgar E. Iglesias" <edgar.iglesias@gmail.com>,
Peter Maydell <peter.maydell@linaro.org>,
Alexander Graf <agraf@suse.de>, Jason Wang <jasowang@redhat.com>,
Subbaraya Sundeep <sundeep.lkml@gmail.com>,
Stefan Berger <stefanb@linux.vnet.ibm.com>,
"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
Christian Borntraeger <borntraeger@de.ibm.com>,
Cornelia Huck <cohuck@redhat.com>,
Richard Henderson <rth@twiddle.net>,
"Michael S. Tsirkin" <mst@redhat.com>,
Igor Mammedov <imammedo@redhat.com>,
qemu-block@nongnu.org (open list:Block layer core),
qemu-arm@nongnu.org (open list:Xilinx Zynq),
qemu-ppc@nongnu.org (open list:New World),
qemu-s390x@nongnu.org (open list:S390)
Subject: Re: [Qemu-trivial] [PATCH v2 6/7] maint: Fix macros with broken 'do/while(0); ' usage
Date: Sat, 02 Dec 2017 12:53:28 +0100 [thread overview]
Message-ID: <87wp25qrbb.fsf@secure.laptop> (raw)
In-Reply-To: <20171201232433.25193-7-eblake@redhat.com> (Eric Blake's message of "Fri, 1 Dec 2017 17:24:32 -0600")
Eric Blake <eblake@redhat.com> wrote:
> The point of writing a macro embedded in a 'do { ... } while (0)'
> loop (particularly if the macro has multiple statements or would
> otherwise end with an 'if' statement) is so that the macro can be
> used as a drop-in statement with the caller supplying the
> trailing ';'. Although our coding style frowns on brace-less 'if':
> if (cond)
> statement;
> else
> something else;
> that is the classic case where failure to use do/while(0) wrapping
> would cause the 'else' to pair with any embedded 'if' in the macro
> rather than the intended outer 'if'. But conversely, if the macro
> includes an embedded ';', then the same brace-less coding style
> would now have two statements, making the 'else' a syntax error
> rather than pairing with the outer 'if'. Thus, even though our
> coding style with required braces is not impacted, ending a macro
> with ';' makes our code harder to port to projects that use
> brace-less styles.
>
> The change should have no semantic impact. I was not able to
> fully compile-test all of the changes (as some of them are
> examples of the ugly bit-rotting debug print statements that are
> completely elided by default, and I didn't want to recompile
> with the necessary -D witnesses - cleaning those up is left as a
> bite-sized task for another day); I did, however, audit that for
> all files touched, all callers of the changed macros DID supply
> a trailing ';' at the callsite, and did not appear to be used
> as part of a brace-less conditional.
>
> Found mechanically via: $ git grep -B1 'while (0);' | grep -A1 \\\\
>
> Signed-off-by: Eric Blake <eblake@redhat.com>
> Acked-by: Cornelia Huck <cohuck@redhat.com>
> Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
> Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
WARNING: multiple messages have this Message-ID (diff)
From: Juan Quintela <quintela@redhat.com>
To: Eric Blake <eblake@redhat.com>
Cc: Peter Maydell <peter.maydell@linaro.org>,
"Michael S. Tsirkin" <mst@redhat.com>,
Jason Wang <jasowang@redhat.com>,
qemu-devel@nongnu.org, Alexander Graf <agraf@suse.de>,
Gerd Hoffmann <kraxel@redhat.com>, Max Reitz <mreitz@redhat.com>,
"open list:Block layer core" <qemu-block@nongnu.org>,
Stefan Berger <stefanb@linux.vnet.ibm.com>,
qemu-trivial@nongnu.org, armbru@redhat.com,
Christian Borntraeger <borntraeger@de.ibm.com>,
Alistair Francis <alistair@alistair23.me>,
"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
"open list:S390" <qemu-s390x@nongnu.org>,
"open list:Xilinx Zynq" <qemu-arm@nongnu.org>,
Igor Mammedov <imammedo@redhat.com>,
Richard Henderson <rth@twiddle.net>,
Kevin Wolf <kwolf@redhat.com>, Cornelia Huck <cohuck@redhat.com>,
Subbaraya Sundeep <sundeep.lkml@gmail.com>,
"open list:New World" <qemu-ppc@nongnu.org>,
pbonzini@redhat.com
Subject: Re: [Qemu-arm] [PATCH v2 6/7] maint: Fix macros with broken 'do/while(0); ' usage
Date: Sat, 02 Dec 2017 12:53:28 +0100 [thread overview]
Message-ID: <87wp25qrbb.fsf@secure.laptop> (raw)
In-Reply-To: <20171201232433.25193-7-eblake@redhat.com> (Eric Blake's message of "Fri, 1 Dec 2017 17:24:32 -0600")
Eric Blake <eblake@redhat.com> wrote:
> The point of writing a macro embedded in a 'do { ... } while (0)'
> loop (particularly if the macro has multiple statements or would
> otherwise end with an 'if' statement) is so that the macro can be
> used as a drop-in statement with the caller supplying the
> trailing ';'. Although our coding style frowns on brace-less 'if':
> if (cond)
> statement;
> else
> something else;
> that is the classic case where failure to use do/while(0) wrapping
> would cause the 'else' to pair with any embedded 'if' in the macro
> rather than the intended outer 'if'. But conversely, if the macro
> includes an embedded ';', then the same brace-less coding style
> would now have two statements, making the 'else' a syntax error
> rather than pairing with the outer 'if'. Thus, even though our
> coding style with required braces is not impacted, ending a macro
> with ';' makes our code harder to port to projects that use
> brace-less styles.
>
> The change should have no semantic impact. I was not able to
> fully compile-test all of the changes (as some of them are
> examples of the ugly bit-rotting debug print statements that are
> completely elided by default, and I didn't want to recompile
> with the necessary -D witnesses - cleaning those up is left as a
> bite-sized task for another day); I did, however, audit that for
> all files touched, all callers of the changed macros DID supply
> a trailing ';' at the callsite, and did not appear to be used
> as part of a brace-less conditional.
>
> Found mechanically via: $ git grep -B1 'while (0);' | grep -A1 \\\\
>
> Signed-off-by: Eric Blake <eblake@redhat.com>
> Acked-by: Cornelia Huck <cohuck@redhat.com>
> Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
> Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
WARNING: multiple messages have this Message-ID (diff)
From: Juan Quintela <quintela@redhat.com>
To: Eric Blake <eblake@redhat.com>
Cc: qemu-devel@nongnu.org, armbru@redhat.com,
qemu-trivial@nongnu.org, pbonzini@redhat.com,
Gerd Hoffmann <kraxel@redhat.com>,
Alistair Francis <alistair@alistair23.me>,
Peter Crosthwaite <crosthwaite.peter@gmail.com>,
Kevin Wolf <kwolf@redhat.com>, Max Reitz <mreitz@redhat.com>,
"Edgar E. Iglesias" <edgar.iglesias@gmail.com>,
Peter Maydell <peter.maydell@linaro.org>,
Alexander Graf <agraf@suse.de>, Jason Wang <jasowang@redhat.com>,
Subbaraya Sundeep <sundeep.lkml@gmail.com>,
Stefan Berger <stefanb@linux.vnet.ibm.com>,
"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
Christian Borntraeger <borntraeger@de.ibm.com>,
Cornelia Huck <cohuck@redhat.com>,
Richard Henderson <rth@twiddle.net>,
"Michael S. Tsirkin" <mst@redhat.com>,
Igor Mammedov <imammedo@redhat.com>,
"open list:Block layer core" <qemu-block@nongnu.org>,
"open list:Xilinx Zynq" <qemu-arm@nongnu.org>,
"open list:New World" <qemu-ppc@nongnu.org>,
"open list:S390" <qemu-s390x@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH v2 6/7] maint: Fix macros with broken 'do/while(0); ' usage
Date: Sat, 02 Dec 2017 12:53:28 +0100 [thread overview]
Message-ID: <87wp25qrbb.fsf@secure.laptop> (raw)
In-Reply-To: <20171201232433.25193-7-eblake@redhat.com> (Eric Blake's message of "Fri, 1 Dec 2017 17:24:32 -0600")
Eric Blake <eblake@redhat.com> wrote:
> The point of writing a macro embedded in a 'do { ... } while (0)'
> loop (particularly if the macro has multiple statements or would
> otherwise end with an 'if' statement) is so that the macro can be
> used as a drop-in statement with the caller supplying the
> trailing ';'. Although our coding style frowns on brace-less 'if':
> if (cond)
> statement;
> else
> something else;
> that is the classic case where failure to use do/while(0) wrapping
> would cause the 'else' to pair with any embedded 'if' in the macro
> rather than the intended outer 'if'. But conversely, if the macro
> includes an embedded ';', then the same brace-less coding style
> would now have two statements, making the 'else' a syntax error
> rather than pairing with the outer 'if'. Thus, even though our
> coding style with required braces is not impacted, ending a macro
> with ';' makes our code harder to port to projects that use
> brace-less styles.
>
> The change should have no semantic impact. I was not able to
> fully compile-test all of the changes (as some of them are
> examples of the ugly bit-rotting debug print statements that are
> completely elided by default, and I didn't want to recompile
> with the necessary -D witnesses - cleaning those up is left as a
> bite-sized task for another day); I did, however, audit that for
> all files touched, all callers of the changed macros DID supply
> a trailing ';' at the callsite, and did not appear to be used
> as part of a brace-less conditional.
>
> Found mechanically via: $ git grep -B1 'while (0);' | grep -A1 \\\\
>
> Signed-off-by: Eric Blake <eblake@redhat.com>
> Acked-by: Cornelia Huck <cohuck@redhat.com>
> Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
> Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
next prev parent reply other threads:[~2017-12-02 11:54 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-01 23:24 [Qemu-trivial] [PATCH v2 0/7] macro do/while (0) cleanup Eric Blake
2017-12-01 23:24 ` [Qemu-devel] " Eric Blake
2017-12-01 23:24 ` [Qemu-trivial] [PATCH v2 1/7] net: Drop unusual use of do { } while (0); Eric Blake
2017-12-01 23:24 ` [Qemu-devel] " Eric Blake
2017-12-01 23:24 ` [Qemu-trivial] [PATCH v2 2/7] mips: Tweak location of '; ' in macros Eric Blake
2017-12-01 23:24 ` [Qemu-devel] [PATCH v2 2/7] mips: Tweak location of ';' " Eric Blake
2017-12-01 23:24 ` [Qemu-trivial] [PATCH v2 3/7] chardev: Use goto/label instead of do/break/while(0) Eric Blake
2017-12-01 23:24 ` [Qemu-devel] " Eric Blake
2017-12-03 14:20 ` [Qemu-trivial] " Marc-André Lureau
2017-12-03 14:20 ` Marc-André Lureau
2017-12-01 23:24 ` [Qemu-trivial] [PATCH v2 4/7] chardev: Clean up previous patch indentation Eric Blake
2017-12-01 23:24 ` [Qemu-devel] " Eric Blake
2017-12-03 14:20 ` [Qemu-trivial] " Marc-André Lureau
2017-12-03 14:20 ` Marc-André Lureau
2017-12-01 23:24 ` [Qemu-trivial] [PATCH v2 5/7] tests: Avoid 'do/while(false); ' in vhost-user-bridge Eric Blake
2017-12-01 23:24 ` [Qemu-devel] " Eric Blake
2017-12-01 23:24 ` [Qemu-trivial] [PATCH v2 6/7] maint: Fix macros with broken 'do/while(0); ' usage Eric Blake
2017-12-01 23:24 ` [Qemu-devel] " Eric Blake
2017-12-01 23:24 ` [Qemu-arm] " Eric Blake
2017-12-02 11:53 ` Juan Quintela [this message]
2017-12-02 11:53 ` [Qemu-devel] " Juan Quintela
2017-12-02 11:53 ` [Qemu-arm] " Juan Quintela
2017-12-01 23:24 ` [Qemu-trivial] [PATCH v2 7/7] checkpatch: Enforce proper do/while (0) style Eric Blake
2017-12-01 23:24 ` [Qemu-devel] " Eric Blake
2018-01-09 20:52 ` [Qemu-trivial] [Qemu-devel] [PATCH v2 0/7] macro do/while (0) cleanup Eric Blake
2018-01-09 20:52 ` Eric Blake
2018-01-10 13:52 ` [Qemu-trivial] " Paolo Bonzini
2018-01-10 13:52 ` Paolo Bonzini
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=87wp25qrbb.fsf@secure.laptop \
--to=quintela@redhat.com \
--cc=agraf@suse.de \
--cc=alistair@alistair23.me \
--cc=armbru@redhat.com \
--cc=borntraeger@de.ibm.com \
--cc=cohuck@redhat.com \
--cc=crosthwaite.peter@gmail.com \
--cc=dgilbert@redhat.com \
--cc=eblake@redhat.com \
--cc=edgar.iglesias@gmail.com \
--cc=imammedo@redhat.com \
--cc=jasowang@redhat.com \
--cc=kraxel@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=qemu-s390x@nongnu.org \
--cc=qemu-trivial@nongnu.org \
--cc=rth@twiddle.net \
--cc=stefanb@linux.vnet.ibm.com \
--cc=sundeep.lkml@gmail.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 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.