Peter Xu <[email protected]> writes:
> Changes from v7:
> - patch 8: use s->dump_info.page_size not TARGET_PAGE_SIZE
> - patch 10: change DUMP_STATUS_MAX to DUMP_STATUS__MAX (this is to
> fix compile error for rebasing to latest master branch, still do
> not know why we need this change from generating "_MAX" to
> "__MAX" for enum types...)
Don't ask yourself why something was done, ask git :)
$ git-log -S__MAX
[...]
commit 7fb1cf1606c78c9d5b538f29176fd5a101726a9d
Author: Eric Blake <[email protected]>
Date: Wed Nov 18 01:52:57 2015 -0700
---> qapi: Don't let implicit enum MAX member collide
Now that we guarantee the user doesn't have any enum values
beginning with a single underscore, we can use that for our
own purposes. Renaming ENUM_MAX to ENUM__MAX makes it obvious
that the sentinel is generated.
This patch was mostly generated by applying a temporary patch:
|diff --git a/scripts/qapi.py b/scripts/qapi.py
|index e6d014b..b862ec9 100644
|--- a/scripts/qapi.py
|+++ b/scripts/qapi.py
|@@ -1570,6 +1570,7 @@ const char *const %(c_name)s_lookup[] = {
| max_index = c_enum_const(name, 'MAX', prefix)
| ret += mcgen('''
| [%(max_index)s] = NULL,
|+// %(max_index)s
| };
| ''',
| max_index=max_index)
then running:
$ cat qapi-{types,event}.c tests/test-qapi-types.c |
sed -n 's,^// \(.*\)MAX,s|\1MAX|\1_MAX|g,p' > list
$ git grep -l _MAX | xargs sed -i -f list
The only things not generated are the changes in scripts/qapi.py.
Rejecting enum members named 'MAX' is now useless, and will be dropped
in the next patch.
Signed-off-by: Eric Blake <[email protected]>
Message-Id: <[email protected]>
Reviewed-by: Juan Quintela <[email protected]>
[Rebased to current master, commit message tweaked]
Signed-off-by: Markus Armbruster <[email protected]>
I guess this isn't perfectly clear without more context, so let me add
some.
The implicit FOO_MAX could collide with the user's FOO_MAX for QAPI
enumeration values 'max', or case variations thereof. Commit cf39359
added extra code to catch that.
Renaming the implict FOO_MAX to FOO__MAX removes the need for the
special rule "you can't use 'max' as an enumeration value", because the
general rule "names starting with '_' are reserved" suffices then.
Fewer rules is better.
[...]