From: Eric Blake <eblake@redhat.com>
To: Anton Nefedov <anton.nefedov@virtuozzo.com>, qemu-devel@nongnu.org
Cc: armbru@redhat.com, mdroth@linux.vnet.ibm.com
Subject: Re: [Qemu-devel] [PATCH v2 1/2] qapi: allow empty branches in flat unions
Date: Tue, 29 May 2018 15:43:29 -0500 [thread overview]
Message-ID: <ed01b561-663c-bee7-0a1a-ecab8265912e@redhat.com> (raw)
In-Reply-To: <1527612092-65980-2-git-send-email-anton.nefedov@virtuozzo.com>
On 05/29/2018 11:41 AM, Anton Nefedov wrote:
> It often happens that just a few discriminator values imply extra data in
> a flat union. Existing checks did not make possible to leave other values
> uncovered. Such cases had to be worked around by either stating a dummy
> (empty) type or introducing another (subset) discriminator enumeration.
>
> Both options create redundant entities in qapi files for little profit.
>
> With this patch it is not necessary anymore to add designated union
> fields for every possible value of a discriminator enumeration.
>
> Signed-off-by: Anton Nefedov <anton.nefedov@virtuozzo.com>
> ---
> docs/devel/qapi-code-gen.txt | 7 ++++---
> scripts/qapi/common.py | 11 ++++-------
> scripts/qapi/types.py | 4 +++-
> scripts/qapi/visit.py | 17 +++++++++++++----
> tests/qapi-schema/flat-union-incomplete-branch.err | 1 -
> tests/qapi-schema/flat-union-incomplete-branch.exit | 2 +-
> tests/qapi-schema/flat-union-incomplete-branch.out | 14 ++++++++++++++
Generally, when converting a negative test to a positive test, I prefer
to instead drop the negative test and put the positive test as part of
tests/qapi-schema/qapi-schema-test.json - because that file has the
additional coverage of proving that the compiler is still happy with the
generated code (we don't compile any of the other positive tests).
> 7 files changed, 39 insertions(+), 17 deletions(-)
>
> diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt
> index b9b6eab..a3ea450 100644
> --- a/docs/devel/qapi-code-gen.txt
> +++ b/docs/devel/qapi-code-gen.txt
> @@ -496,9 +496,10 @@ Resulting in these JSON objects:
>
> Notice that in a flat union, the discriminator name is controlled by
> the user, but because it must map to a base member with enum type, the
> -code generator can ensure that branches exist for all values of the
> -enum (although the order of the keys need not match the declaration of
> -the enum). In the resulting generated C data types, a flat union is
> +code generator ensures that branches match the existing values of the
> +enum. The order of the keys need not match the declaration of the enum.
> +The keys need not cover all possible enum values.
Maybe mention that omitted enum values are still valid branches that
merely add no additional members to the data type.
> +In the resulting generated C data types, a flat union is
> represented as a struct with the base members included directly, and
> then a union of structures for each branch of the struct.
>
Otherwise seems reasonable to me.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
next prev parent reply other threads:[~2018-05-29 20:43 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-29 16:41 [Qemu-devel] [PATCH v2 0/2] qapi: allow empty branches in flat unions Anton Nefedov
2018-05-29 16:41 ` [Qemu-devel] [PATCH v2 1/2] " Anton Nefedov
2018-05-29 20:43 ` Eric Blake [this message]
2018-05-29 16:41 ` [Qemu-devel] [PATCH v2 2/2] qapi: remove empty flat union branches and types Anton Nefedov
2018-05-29 20:46 ` Eric Blake
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=ed01b561-663c-bee7-0a1a-ecab8265912e@redhat.com \
--to=eblake@redhat.com \
--cc=anton.nefedov@virtuozzo.com \
--cc=armbru@redhat.com \
--cc=mdroth@linux.vnet.ibm.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 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).