diff mbox

i440fx-test: guard ARRAY_SIZE definition with #ifndef

Message ID 1430421390-2787-1-git-send-email-cota@braap.org
State New
Headers show

Commit Message

Emilio Cota April 30, 2015, 7:16 p.m. UTC
ARRAY_SIZE is defined in osdep.h so having an unconditional
definition here is fragile.

Signed-off-by: Emilio G. Cota <cota@braap.org>
---
 tests/i440fx-test.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Stefan Weil April 30, 2015, 7:28 p.m. UTC | #1
Am 30.04.2015 um 21:16 schrieb Emilio G. Cota:
> ARRAY_SIZE is defined in osdep.h so having an unconditional
> definition here is fragile.
>
> Signed-off-by: Emilio G. Cota <cota@braap.org>
> ---
>   tests/i440fx-test.c | 2 ++
>   1 file changed, 2 insertions(+)
>
> diff --git a/tests/i440fx-test.c b/tests/i440fx-test.c
> index d0bc8de..d610e66 100644
> --- a/tests/i440fx-test.c
> +++ b/tests/i440fx-test.c
> @@ -27,7 +27,9 @@
>   
>   #define BROKEN 1
>   
> +#ifndef ARRAY_SIZE
>   #define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
> +#endif
>   
>   typedef struct TestData
>   {

Why not include osdep.h via qemu-common.h and remove all other include 
statements which then are no longer needed? I'd prefer that variant.

Cheers
Stefan
Peter Maydell April 30, 2015, 8:02 p.m. UTC | #2
On 30 April 2015 at 20:28, Stefan Weil <sw@weilnetz.de> wrote:
> Am 30.04.2015 um 21:16 schrieb Emilio G. Cota:
>>
>> ARRAY_SIZE is defined in osdep.h so having an unconditional
>> definition here is fragile.

FWIW, the original patch of this failed to build on x86 too,
so I don't think we currently include osdep.h from this file in
any circumstances... Where do you get the ARRAY_SIZE definition
from that presumably lets you build without this one?

> Why not include osdep.h via qemu-common.h and remove all other include
> statements which then are no longer needed? I'd prefer that variant.

Can we include qemu-common.h in these libqos standalone test
executables? I forget... The rtl8139 test seems to though, so
I guess it's OK.

-- PMM
Michael Tokarev April 30, 2015, 8:14 p.m. UTC | #3
30.04.2015 22:16, Emilio G. Cota wrote:
> ARRAY_SIZE is defined in osdep.h so having an unconditional
> definition here is fragile.

Fragile in what sense?  Nothing in that file includes osdep.h.
At the maximum, compiler will issue a warning about redefinition
(it should really be redefinition, not the same definition),
which might be treated as error, and we'll just fix that
warning.. I'd say just be done with this, it doesn't deserve
that much attention ;)

Somehow initially I thought this patch actually FIXES a warning
of this sort.  But it looks lile it is only fixes a potential
warning. Oh well...  :)

Thanks,

/mjt
diff mbox

Patch

diff --git a/tests/i440fx-test.c b/tests/i440fx-test.c
index d0bc8de..d610e66 100644
--- a/tests/i440fx-test.c
+++ b/tests/i440fx-test.c
@@ -27,7 +27,9 @@ 
 
 #define BROKEN 1
 
+#ifndef ARRAY_SIZE
 #define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
+#endif
 
 typedef struct TestData
 {