qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v3 2/3] qapi: Do not generate empty enum


From: Philippe Mathieu-Daudé
Subject: Re: [PATCH v3 2/3] qapi: Do not generate empty enum
Date: Tue, 21 Mar 2023 15:31:56 +0100
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.9.0

On 16/3/23 15:57, Markus Armbruster wrote:
Daniel P. Berrangé <berrange@redhat.com> writes:

On Thu, Mar 16, 2023 at 01:31:04PM +0100, Markus Armbruster wrote:
Philippe Mathieu-Daudé <philmd@linaro.org> writes:

Per the C++ standard, empty enum are ill-formed. Do not generate

The C standard.  The C++ standard doesn't apply here :)

I can't find how empty enums are considered by the C standard...

But all of this falls apart with conditional members!

Example 1 (taken from qapi/block-core.json):

     { 'enum': 'BlockdevAioOptions',
       'data': [ 'threads', 'native',
                 { 'name': 'io_uring', 'if': 'CONFIG_LINUX_IO_URING' } ] }

Generates now:

     typedef enum BlockdevAioOptions {
         BLOCKDEV_AIO_OPTIONS_THREADS,
         BLOCKDEV_AIO_OPTIONS_NATIVE,
     #if defined(CONFIG_LINUX_IO_URING)
         BLOCKDEV_AIO_OPTIONS_IO_URING,
     #endif /* defined(CONFIG_LINUX_IO_URING) */
         BLOCKDEV_AIO_OPTIONS__MAX,
     } BlockdevAioOptions;

BLOCKDEV_AIO_OPTIONS__MAX is 3 if defined(CONFIG_LINUX_IO_URING), else
2.

After the next patch:

     typedef enum BlockdevAioOptions {
         BLOCKDEV_AIO_OPTIONS_THREADS,
         BLOCKDEV_AIO_OPTIONS_NATIVE,
     #if defined(CONFIG_LINUX_IO_URING)
         BLOCKDEV_AIO_OPTIONS_IO_URING,
     #endif /* defined(CONFIG_LINUX_IO_URING) */
     #define BLOCKDEV_AIO_OPTIONS__MAX 3
     } BlockdevAioOptions;

Now it's always 3.

Good catch... Using:

-- >8 --
diff --git a/scripts/qapi/types.py b/scripts/qapi/types.py
@@ -110,8 +110,11 @@ def gen_enum(name: str,

     ret += mcgen('''
 } %(c_name)s;
+_Static_assert(%(c_last_enum)s == %(c_length)s - 1, "%(c_name)s");
 ''',
-                 c_name=c_name(name))
+                 c_name=c_name(name),
+                 c_last_enum=c_enum_const(name, members[-1].name, prefix),
+                 c_length=len(members))

     ret += mcgen('''
---

I get:

./qapi/qapi-types-block-core.h:355:1: error: static_assert failed due to requirement 'BLOCKDEV_AIO_OPTIONS_NATIVE == 3 - 1' "BlockdevAioOptions" _Static_assert(BLOCKDEV_AIO_OPTIONS_IO_URING == 3 - 1, "BlockdevAioOptions");
^              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./qapi/qapi-types-block-core.h:430:1: error: static_assert failed due to requirement 'BLOCKDEV_DRIVER_VVFAT == 47 - 1' "BlockdevDriver"
_Static_assert(BLOCKDEV_DRIVER_VVFAT == 47 - 1, "BlockdevDriver");
^              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./qapi/qapi-types-char.h:110:1: error: static_assert failed due to requirement 'CHARDEV_BACKEND_KIND_MEMORY == 22 - 1' "ChardevBackendKind"
_Static_assert(CHARDEV_BACKEND_KIND_MEMORY == 22 - 1, "ChardevBackendKind");
^              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...



reply via email to

[Prev in Thread] Current Thread [Next in Thread]