qemu-trivial
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-trivial] [PATCH 3/3] maint: Fix macros with broken 'do/while(0


From: Eric Blake
Subject: Re: [Qemu-trivial] [PATCH 3/3] maint: Fix macros with broken 'do/while(0); ' usage
Date: Thu, 30 Nov 2017 08:55:02 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0

On 11/30/2017 08:43 AM, Michael S. Tsirkin wrote:
On Thu, Nov 30, 2017 at 07:41:59AM -0600, Eric Blake wrote:
The point of writing a macro embedded in a 'do { ... } while (0)'
loop 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;
the use of do/while (0) in a macro is absolutely essential for the
purpose of avoiding a syntax error on the 'else' - but it only works
if there is no trailing ';' in the macro (as the ';' in the code
calling the macro would then be a second statement and cause the
'else' to not pair to the 'if').

Shouldn't matter if everyone puts the statements in {}, right?

Correct - where we follow our style, spurious ';' don't make a difference (other than they might trigger a warning in a very particular compiler). But it also makes our code harder to copy-and-paste into other projects with a different style.


Many of the places touched in this code are examples of the ugly
bit-rotting debug print statements; cleaning those up is left as
a bite-sized task for another day.

Found mechanically via: $ git grep -B1 'while (0);' | grep -A1 \\\\

Signed-off-by: Eric Blake <address@hidden>

We can't really rely on code still building for this to do the right
thing, can we?

Some of the uses that were changed are in dead #ifdefs for debugging purposes - the only way to still compile is to turn on the debugging, but that may fail to compile for other reasons (if the format strings have bit-rotted, for example).

The only sure way to know that this did not break anything is to audit that for every macro where I eliminated the ';', all callers of that macro call 'foo();'. I did not perform that audit (the patch was mechanical) - but am willing to do so and reply back with results if you need the extra confidence.

 I did my best to look for uses and I think it's OK, so

Reviewed-by: Michael S. Tsirkin <address@hidden>

but I'm not merging this.

What tree should it go through instead? Does it need to be split along maintainer boundaries?

--
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org



reply via email to

[Prev in Thread] Current Thread [Next in Thread]