From: Stefan Berger <stefanb@linux.ibm.com>
To: "Philippe Mathieu-Daudé" <philmd@linaro.org>, qemu-devel@nongnu.org
Cc: "Pavel Dovgalyuk" <pavel.dovgaluk@ispras.ru>,
"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
"Juan Quintela" <quintela@redhat.com>,
"Gerd Hoffmann" <kraxel@redhat.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Michael Roth" <michael.roth@amd.com>,
"Markus Armbruster" <armbru@redhat.com>,
"Stefan Berger" <stefanb@linux.vnet.ibm.com>,
"Paolo Bonzini" <pbonzini@redhat.com>
Subject: Re: [PATCH v2 2/3] qapi: Do not generate empty enum
Date: Wed, 15 Mar 2023 11:19:38 -0400 [thread overview]
Message-ID: <68816687-b319-7c1a-f586-51201e12ecba@linux.ibm.com> (raw)
In-Reply-To: <20230315111304.21692-3-philmd@linaro.org>
On 3/15/23 07:13, Philippe Mathieu-Daudé wrote:
> Per the C++ standard, empty enum are ill-formed. Do not generate
> them in order to avoid:
>
> In file included from qga/qga-qapi-emit-events.c:14:
> qga/qga-qapi-emit-events.h:20:1: error: empty enum is invalid
> 20 | } qga_QAPIEvent;
> | ^
>
> Reported-by: Markus Armbruster <armbru@redhat.com>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
> docs/devel/qapi-code-gen.rst | 6 +++---
> scripts/qapi/schema.py | 5 ++++-
> 2 files changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/docs/devel/qapi-code-gen.rst b/docs/devel/qapi-code-gen.rst
> index 23e7f2fb1c..d684c7c24d 100644
> --- a/docs/devel/qapi-code-gen.rst
> +++ b/docs/devel/qapi-code-gen.rst
> @@ -206,6 +206,9 @@ Syntax::
>
> Member 'enum' names the enum type.
>
> +Empty enumeration (no member) does not generate anything (not even
> +constant PREFIX__MAX).
> +
> Each member of the 'data' array defines a value of the enumeration
> type. The form STRING is shorthand for :code:`{ 'name': STRING }`. The
> 'name' values must be be distinct.
> @@ -214,9 +217,6 @@ Example::
>
> { 'enum': 'MyEnum', 'data': [ 'value1', 'value2', 'value3' ] }
>
> -Nothing prevents an empty enumeration, although it is probably not
> -useful.
> -
> On the wire, an enumeration type's value is represented by its
> (string) name. In C, it's represented by an enumeration constant.
> These are of the form PREFIX_NAME, where PREFIX is derived from the
> diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py
> index 207e4d71f3..28045dbe93 100644
> --- a/scripts/qapi/schema.py
> +++ b/scripts/qapi/schema.py
> @@ -309,6 +309,7 @@ class QAPISchemaEnumType(QAPISchemaType):
>
> def __init__(self, name, info, doc, ifcond, features, members, prefix):
> super().__init__(name, info, doc, ifcond, features)
> + assert members
not: assert isinstance(members, list)
> for m in members:
> assert isinstance(m, QAPISchemaEnumMember)
> m.set_defined_in(name)
> @@ -1047,8 +1048,10 @@ def _make_implicit_object_type(self, name, info, ifcond, role, members):
> return name
>
> def _def_enum_type(self, expr: QAPIExpression):
> - name = expr['enum']
> data = expr['data']
> + if not data:
> + return
> + name = expr['enum']
> prefix = expr.get('prefix')
> ifcond = QAPISchemaIfCond(expr.get('if'))
> info = expr.info
Acked-by: Stefan Berger <stefanb@linux.ibm.com>
next prev parent reply other threads:[~2023-03-15 15:20 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-15 11:13 [PATCH v2 0/3] qapi: Simplify enum generation Philippe Mathieu-Daudé
2023-03-15 11:13 ` [PATCH v2 1/3] scripts/git.orderfile: Display QAPI script changes before schema ones Philippe Mathieu-Daudé
2023-03-15 11:13 ` [PATCH v2 2/3] qapi: Do not generate empty enum Philippe Mathieu-Daudé
2023-03-15 15:19 ` Stefan Berger [this message]
2023-03-15 15:25 ` Philippe Mathieu-Daudé
2023-03-15 11:13 ` [PATCH v2 3/3] qapi: Generate enum count as definition Philippe Mathieu-Daudé
2023-03-15 11:22 ` [PATCH v2 0/3] qapi: Simplify enum generation Philippe Mathieu-Daudé
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=68816687-b319-7c1a-f586-51201e12ecba@linux.ibm.com \
--to=stefanb@linux.ibm.com \
--cc=armbru@redhat.com \
--cc=dgilbert@redhat.com \
--cc=kraxel@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=michael.roth@amd.com \
--cc=pavel.dovgaluk@ispras.ru \
--cc=pbonzini@redhat.com \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
--cc=stefanb@linux.vnet.ibm.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).