[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH for-4.0 v7 02/27] qapi: do not define enumeratio
From: |
Markus Armbruster |
Subject: |
Re: [Qemu-devel] [PATCH for-4.0 v7 02/27] qapi: do not define enumeration value explicitly |
Date: |
Wed, 12 Dec 2018 09:52:21 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) |
Marc-André Lureau <address@hidden> writes:
> The C standard has the initial value at 0 and the subsequent values
> incremented by 1. No need to set this explicitely.
>
> This will prevent from artificial "gaps" when compiling out some enum
> values and having unnecessarily large MAX values & enums arrays, or
> simplifying iterating over valid enum values.
Should mention that compiling out will only become possible later in
this series.
> Whenever config-host.h is changed, all the enum/types are recompiled.
This soundness argument is incomplete. Yes, our coding conventions
ensure everything gets recompiled when config-host.h changes. But
nothing stops people from using 'if' conditions that depend on more than
just config-host.h.
What about this:
qapi: Do not define enumeration value explicitly
The generated C enumeration types explicitly set the enumeration
constants to 0, 1, 2, ... That's exactly what you get when you don't
supply values.
Drop the explicit values. No change now, but it will avoid gaps in
the values when we later add support for 'if' conditions. Avoiding
such gaps will save us the trouble of changing the ENUM_lookup[]
tables to work without a sentinel.
We'll have to take care to ensure the headers required by the 'if'
conditions get always included before the generated QAPI code.
Fortunately, our convention to include "qemu/osdep.h" first in any .c
ensures that's the case for our CONFIG_FOO macros.
> Signed-off-by: Marc-André Lureau <address@hidden>
With an improved commit message:
Reviewed-by: Markus Armbruster <address@hidden>
[Qemu-devel] [PATCH for-4.0 v7 02/27] qapi: do not define enumeration value explicitly, Marc-André Lureau, 2018/12/08
- Re: [Qemu-devel] [PATCH for-4.0 v7 02/27] qapi: do not define enumeration value explicitly,
Markus Armbruster <=
[Qemu-devel] [PATCH for-4.0 v7 03/27] qapi: rename QAPISchemaEnumType.values to .members, Marc-André Lureau, 2018/12/08
[Qemu-devel] [PATCH for-4.0 v7 04/27] qapi: change enum visitor and gen_enum* to take QAPISchemaMember, Marc-André Lureau, 2018/12/08
[Qemu-devel] [PATCH for-4.0 v7 05/27] tests: print enum type members more like object type members, Marc-André Lureau, 2018/12/08
[Qemu-devel] [PATCH for-4.0 v7 06/27] qapi: factor out checking for keys, Marc-André Lureau, 2018/12/08
[Qemu-devel] [PATCH for-4.0 v7 08/27] qapi: add a dictionary form with 'name' key for enum members, Marc-André Lureau, 2018/12/08
[Qemu-devel] [PATCH for-4.0 v7 07/27] qapi: improve reporting of unknown or missing keys, Marc-André Lureau, 2018/12/08