[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v3 1/8] qapi: Add default-variant for flat union
From: |
Eric Blake |
Subject: |
Re: [Qemu-devel] [PATCH v3 1/8] qapi: Add default-variant for flat unions |
Date: |
Wed, 6 Feb 2019 14:13:23 -0600 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 |
On 2/6/19 1:55 PM, Max Reitz wrote:
> This patch allows specifying a discriminator that is an optional member
> of the base struct. In such a case, a default value must be provided
> that is used when no value is given.
>
> Signed-off-by: Max Reitz <address@hidden>
> ---
> qapi/introspect.json | 8 +++++
> scripts/qapi/common.py | 58 ++++++++++++++++++++++++++++------
> scripts/qapi/doc.py | 10 ++++--
> scripts/qapi/introspect.py | 10 ++++--
> scripts/qapi/visit.py | 13 ++++++++
> tests/qapi-schema/test-qapi.py | 2 ++
> 6 files changed, 86 insertions(+), 15 deletions(-)
Missing a change to docs/devel/qapi-code-gen.txt? [re-reads diffstat in
cover letter...] Oh, you got that later in the series. Maybe those two
patches are worth squashing?
> +++ b/scripts/qapi/visit.py
> @@ -77,6 +77,19 @@ void visit_type_%(c_name)s_members(Visitor *v, %(c_name)s
> *obj, Error **errp)
> ret += gen_endif(memb.ifcond)
>
> if variants:
> + if variants.default_tag_value is not None:
> + ret += mcgen('''
> + if (!obj->has_%(c_name)s) {
> + obj->has_%(c_name)s = true;
> + obj->%(c_name)s = %(enum_const)s;
> + }
> +''',
> + c_name=c_name(variants.tag_member.name),
> + enum_const=c_enum_const(
> + variants.tag_member.type.name,
> + variants.default_tag_value,
> + variants.tag_member.type.prefix))
> +
I like that you de-sugar it as early in the input parse as possible.
Markus may have comments, but it looks reasonable to me.
Reviewed-by: Eric Blake <address@hidden>
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org
signature.asc
Description: OpenPGP digital signature
- [Qemu-devel] [PATCH v3 0/8] block: Try to create well-typed json:{} filenames, Max Reitz, 2019/02/06
- [Qemu-devel] [PATCH v3 4/8] qapi: Formalize qcow2 encryption probing, Max Reitz, 2019/02/06
- [Qemu-devel] [PATCH v3 3/8] tests: Add QAPI optional discriminator tests, Max Reitz, 2019/02/06
- [Qemu-devel] [PATCH v3 5/8] qapi: Formalize qcow encryption probing, Max Reitz, 2019/02/06
- [Qemu-devel] [PATCH v3 6/8] block: Try to create well typed json:{} filenames, Max Reitz, 2019/02/06