From: Markus Armbruster <armbru@redhat.com>
To: "Marc-André Lureau" <marcandre.lureau@gmail.com>
Cc: Markus Armbruster <armbru@redhat.com>, QEMU <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH v3 15/49] qapi: do not define enumeration value explicitely
Date: Thu, 28 Jun 2018 08:34:29 +0200 [thread overview]
Message-ID: <87fu175si2.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <CAJ+F1CJAGPY6dbt-T50ERmO0=wVY2PrSPz0tZnWDZuabMiG8+A@mail.gmail.com> ("Marc-André Lureau"'s message of "Wed, 27 Jun 2018 14:13:01 +0200")
Marc-André Lureau <marcandre.lureau@gmail.com> writes:
> Hi
>
> On Fri, Jun 22, 2018 at 10:08 AM, Markus Armbruster <armbru@redhat.com> wrote:
>> Subject: explicitly
>>
>> Marc-André Lureau <marcandre.lureau@redhat.com> 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.
>>>
>>> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>>> ---
>>> scripts/qapi/common.py | 7 ++-----
>>> 1 file changed, 2 insertions(+), 5 deletions(-)
>>>
>>> diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
>>> index 60c1d0a783..68a567f53f 100644
>>> --- a/scripts/qapi/common.py
>>> +++ b/scripts/qapi/common.py
>>> @@ -2032,14 +2032,11 @@ typedef enum %(c_name)s {
>>> ''',
>>> c_name=c_name(name))
>>>
>>> - i = 0
>>> for value in enum_values:
>>> ret += mcgen('''
>>> - %(c_enum)s = %(i)d,
>>> + %(c_enum)s,
>>> ''',
>>> - c_enum=c_enum_const(name, value, prefix),
>>> - i=i)
>>> - i += 1
>>> + c_enum=c_enum_const(name, value, prefix))
>>>
>>> ret += mcgen('''
>>> } %(c_name)s;
>>
>> What excactly in your series depends on this?
>>
>> What safeguards do you propose to ensure an enumeration with
>> conditionals is compiled only with the exact same conditionals within
>> the same program?
>>
>> Example of the kind of deathtrap to guard against: compile
>>
>> typedef enum Color {
>> COLOR_WHITE,
>> #if defined(NEED_CPU_H)
>> #if defined(TARGET_S390X)
>> COLOR_BLUE,
>> #endif /* defined(TARGET_S390X) */
>> #endif /* defined(NEED_CPU_H) */
>> COLOR_BLACK,
>> } Color;
>>
>> in s390x-code (COLOR_BLACK = 2) and in target-independent code
>> (COLOR_BLACK = 1), then linking the two together.
>
> This was a trick used in previous iterations. Now that we have a
> separate target schema and generated code/headers, and since we have
> poisoned identifiers, this should never happen.
>
>> Yes, I know a similar deathtrap will be set up for struct and union
>> types. No excuse for ignoring either of the two.
>
> Having gaps in the enums makes it harder to iterate over all values,
> and we use more memory than necessary when allocating based on MAX
> value.
>
> It's not a big problem, but I consider this more important than this
> artificially made up broken build example.
Made up yes, but the making up comes from painful experience debugging
real programs :)
I'm not at all opposed to "contracting" enums. I just want to be
persuaded it's safe. I think your argument is "Now that we have a
separate target schema and generated code/headers, and since we have
poisoned identifiers, this should never happen." Can you elaborate?
If that goes as I expect it to go, the next request will be "now put
that into your commit message" :)
next prev parent reply other threads:[~2018-06-28 6:34 UTC|newest]
Thread overview: 95+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-21 11:51 [Qemu-devel] [PATCH v3 00/49] qapi: add #if pre-processor conditions to generated code Marc-André Lureau
2018-03-21 11:51 ` [Qemu-devel] [PATCH v3 01/49] qapi/visit: remove useless prefix argument Marc-André Lureau
2018-06-18 14:29 ` Markus Armbruster
2018-03-21 11:51 ` [Qemu-devel] [PATCH v3 02/49] qapi/events: generate event enum in main module Marc-André Lureau
2018-06-18 14:33 ` Markus Armbruster
2018-03-21 11:51 ` [Qemu-devel] [PATCH v3 03/49] qapi: add 'if' to top-level expressions Marc-André Lureau
2018-06-19 7:57 ` Markus Armbruster
2018-06-19 8:41 ` Marc-André Lureau
2018-06-19 11:35 ` Markus Armbruster
2018-03-21 11:51 ` [Qemu-devel] [PATCH v3 04/49] qapi: pass 'if' condition into QAPISchemaEntity objects Marc-André Lureau
2018-06-19 8:09 ` Markus Armbruster
2018-03-21 11:51 ` [Qemu-devel] [PATCH v3 05/49] qapi: leave the ifcond attribute undefined until check() Marc-André Lureau
2018-06-19 9:06 ` Markus Armbruster
2018-06-26 13:39 ` Marc-André Lureau
2018-06-27 5:26 ` Markus Armbruster
2018-06-29 10:30 ` Marc-André Lureau
2018-03-21 11:51 ` [Qemu-devel] [PATCH v3 06/49] qapi: add 'ifcond' to visitor methods Marc-André Lureau
2018-06-21 8:18 ` Markus Armbruster
2018-03-21 11:51 ` [Qemu-devel] [PATCH v3 07/49] qapi: mcgen() shouldn't indent # lines Marc-André Lureau
2018-06-20 15:14 ` Markus Armbruster
2018-03-21 11:51 ` [Qemu-devel] [PATCH v3 08/49] qapi: add #if/#endif helpers Marc-André Lureau
2018-06-20 16:01 ` Markus Armbruster
2018-06-21 7:06 ` Markus Armbruster
2018-03-21 11:51 ` [Qemu-devel] [PATCH v3 09/49] qapi-introspect: modify to_qlit() to append ', ' on level > 0 Marc-André Lureau
2018-03-21 11:51 ` [Qemu-devel] [PATCH v3 10/49] qapi-introspect: add preprocessor conditions to generated QLit Marc-André Lureau
2018-06-21 13:05 ` Markus Armbruster
2018-03-21 11:51 ` [Qemu-devel] [PATCH v3 11/49] qapi/commands: add #if conditions to commands Marc-André Lureau
2018-06-21 14:35 ` Markus Armbruster
2018-06-22 8:34 ` Markus Armbruster
2018-06-25 13:15 ` Markus Armbruster
2018-03-21 11:51 ` [Qemu-devel] [PATCH v3 12/49] qapi/events: add #if conditions to events Marc-André Lureau
2018-06-21 14:40 ` Markus Armbruster
2018-06-22 9:02 ` Markus Armbruster
2018-03-21 11:51 ` [Qemu-devel] [PATCH v3 13/49] qapi-types: refactor variants handling Marc-André Lureau
2018-06-21 15:54 ` Markus Armbruster
2018-03-21 11:51 ` [Qemu-devel] [PATCH v3 14/49] qapi-types: add #if conditions to types & visitors Marc-André Lureau
2018-06-21 16:12 ` Markus Armbruster
2018-06-27 11:59 ` Marc-André Lureau
2018-06-28 6:27 ` Markus Armbruster
2018-03-21 11:51 ` [Qemu-devel] [PATCH v3 15/49] qapi: do not define enumeration value explicitely Marc-André Lureau
2018-06-22 8:08 ` Markus Armbruster
2018-06-27 12:13 ` Marc-André Lureau
2018-06-28 6:34 ` Markus Armbruster [this message]
2018-03-21 11:51 ` [Qemu-devel] [PATCH v3 16/49] qapi: rename QAPISchemaEnumType.values to .members Marc-André Lureau
2018-06-22 12:24 ` Markus Armbruster
2018-03-21 11:51 ` [Qemu-devel] [PATCH v3 17/49] qapi: change enum visitor to take QAPISchemaMember Marc-André Lureau
2018-06-22 12:24 ` Markus Armbruster
2018-03-21 11:51 ` [Qemu-devel] [PATCH v3 18/49] tests: modify visit_enum_type() in test-qapi to print members Marc-André Lureau
2018-06-22 14:10 ` Markus Armbruster
2018-03-21 11:51 ` [Qemu-devel] [PATCH v3 19/49] qapi: factor out check_known_keys() Marc-André Lureau
2018-06-25 14:10 ` Markus Armbruster
2018-03-21 11:51 ` [Qemu-devel] [PATCH v3 20/49] qapi: add a dictionnary form with 'name' key for enum members Marc-André Lureau
2018-03-21 11:51 ` [Qemu-devel] [PATCH v3 21/49] qapi: add 'if' to " Marc-André Lureau
2018-03-21 11:51 ` [Qemu-devel] [PATCH v3 22/49] qapi-event: add 'if' condition to implicit event enum Marc-André Lureau
2018-03-21 11:51 ` [Qemu-devel] [PATCH v3 23/49] qapi: rename allow_dict to allow_implicit Marc-André Lureau
2018-03-21 11:51 ` [Qemu-devel] [PATCH v3 24/49] qapi: add a dictionary form with 'type' key for members Marc-André Lureau
2018-06-20 11:13 ` Markus Armbruster
2018-03-21 11:51 ` [Qemu-devel] [PATCH v3 25/49] qapi: add 'if' to implicit struct members Marc-André Lureau
2018-03-21 11:51 ` [Qemu-devel] [PATCH v3 26/49] qapi: add an error in case a discriminator is conditionnal Marc-André Lureau
2018-03-21 11:51 ` [Qemu-devel] [PATCH v3 27/49] qapi: add 'if' on union members Marc-André Lureau
2018-03-21 11:51 ` [Qemu-devel] [PATCH v3 28/49] qapi: add 'if' to alternate members Marc-André Lureau
2018-03-21 11:51 ` [Qemu-devel] [PATCH v3 29/49] qapi: add #if conditions to generated code members Marc-André Lureau
2018-03-21 11:51 ` [Qemu-devel] [PATCH v3 30/49] docs: document schema configuration Marc-André Lureau
2018-06-22 11:10 ` Markus Armbruster
2018-03-21 11:51 ` [Qemu-devel] [PATCH v3 31/49] qapi2texi: add 'If:' section to generated documentation Marc-André Lureau
2018-06-21 16:29 ` Markus Armbruster
2018-03-21 11:51 ` [Qemu-devel] [PATCH v3 32/49] qapi2texi: add 'If:' condition to enum values Marc-André Lureau
2018-03-21 11:51 ` [Qemu-devel] [PATCH v3 33/49] qapi2texi: add 'If:' condition to struct members Marc-André Lureau
2018-03-21 11:51 ` [Qemu-devel] [PATCH v3 34/49] qapi2texi: add condition to variants Marc-André Lureau
2018-03-21 11:51 ` [Qemu-devel] [PATCH v3 35/49] qapi: add conditions to VNC type/commands/events on the schema Marc-André Lureau
2018-03-21 11:51 ` [Qemu-devel] [PATCH v3 36/49] qapi: add conditions to SPICE " Marc-André Lureau
2018-03-21 11:51 ` [Qemu-devel] [PATCH v3 37/49] qapi: add conditions to REPLICATION type/commands " Marc-André Lureau
2018-03-21 11:52 ` [Qemu-devel] [PATCH v3 38/49] build-sys: move qmp-introspect per target Marc-André Lureau
2018-03-21 11:52 ` [Qemu-devel] [PATCH v3 39/49] qapi-commands: don't initialize command list in qmp_init_marshall() Marc-André Lureau
2018-03-21 11:52 ` [Qemu-devel] [PATCH v3 40/49] RFC: qapi: learn to split schema by 'top-unit' Marc-André Lureau
2018-03-21 11:52 ` [Qemu-devel] [PATCH v3 41/49] qapi: add a top-unit 'target' schema Marc-André Lureau
2018-03-21 11:52 ` [Qemu-devel] [PATCH v3 42/49] qapi: make rtc-reset-reinjection and SEV depend on TARGET_I386 Marc-André Lureau
2018-03-21 11:52 ` [Qemu-devel] [PATCH v3 43/49] qapi: make s390 commands depend on TARGET_S390X Marc-André Lureau
2018-03-22 5:42 ` Thomas Huth
2018-03-22 9:41 ` Marc-André Lureau
2018-03-22 16:10 ` Thomas Huth
2018-03-21 11:52 ` [Qemu-devel] [PATCH v3 44/49] target.json: add a note about query-cpu* not being s390x-specific Marc-André Lureau
2018-03-21 11:52 ` [Qemu-devel] [PATCH v3 45/49] qapi: make query-gic-capabilities depend on TARGET_ARM Marc-André Lureau
2018-03-21 11:52 ` [Qemu-devel] [PATCH v3 46/49] qapi: make query-cpu-model-expansion depend on s390 or x86 Marc-André Lureau
2018-03-21 11:52 ` [Qemu-devel] [PATCH v3 47/49] qapi: make query-cpu-definitions depend on specific targets Marc-André Lureau
2018-03-21 11:52 ` [Qemu-devel] [PATCH v3 48/49] qapi: remove qmp_unregister_command() Marc-André Lureau
2018-03-21 11:52 ` [Qemu-devel] [PATCH v3 49/49] RFC: make RTC_CHANGE per-target Marc-André Lureau
2018-03-21 12:47 ` [Qemu-devel] [PATCH v3 00/49] qapi: add #if pre-processor conditions to generated code no-reply
2018-03-21 14:20 ` no-reply
2018-03-21 22:08 ` no-reply
2018-03-22 5:11 ` no-reply
2018-06-21 16:47 ` Markus Armbruster
2018-06-21 17:18 ` Marc-André Lureau
2018-06-22 6:56 ` Markus Armbruster
2018-06-22 9:06 ` Markus Armbruster
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=87fu175si2.fsf@dusky.pond.sub.org \
--to=armbru@redhat.com \
--cc=marcandre.lureau@gmail.com \
--cc=qemu-devel@nongnu.org \
/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.