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 <mre...@redhat.com> > --- > 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 <ebl...@redhat.com> -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
signature.asc
Description: OpenPGP digital signature