On 05/05/2017 03:11 PM, Eduardo Habkost wrote: > The new parameter will be used by the string input visitor to detect > alternate types that can't be parsed unambiguously. > > Signed-off-by: Eduardo Habkost <ehabk...@redhat.com> > --- > Changes v1 -> v2: > * (new patch added to series) > ---
> +++ b/include/qapi/visitor.h > @@ -411,13 +411,21 @@ void visit_end_list(Visitor *v, void **list); > * @supported_qtypes is a bit mask indicating which QTypes are supported > * by the alternate. > * > + * @enum_table contains the enum value lookup table, in case > + * strings in the input are going to be parsed as enums. Visitors > + * aren't required to validate string input according to > + * enum_table, as visit_type_enum() will be called automatically > + * if (*obj)->type is QTYPE_QSTRING. Presumably, enum_table will be NULL if the alternate type does not include an enum? [reads ahead] yes. Should be documented. I'm less convinced we need this patch, if we can instead guarantee at QAPI-generation time that alternates are not possible if they would cause an ambiguity. > +++ b/scripts/qapi-visit.py > @@ -166,6 +166,12 @@ def gen_visit_alternate(name, variants): > supported_qtypes = ' | '.join(qtypes) > ret = '' > > + enum_table = 'NULL' > + for var in variants.variants: > + if isinstance(var.type, QAPISchemaEnumType): > + enum_table = '%s_lookup' % (var.type.c_name()) > + break > + > ret += mcgen(''' > > void visit_type_%(c_name)s(Visitor *v, const char *name, %(c_name)s **obj, > Error **errp) > @@ -174,7 +180,7 @@ void visit_type_%(c_name)s(Visitor *v, const char *name, > %(c_name)s **obj, Error > uint32_t supported_qtypes = %(supported_qtypes)s; > > visit_start_alternate(v, name, (GenericAlternate **)obj, sizeof(**obj), > - supported_qtypes, &err); > + supported_qtypes, %(enum_table)s, &err); So there's where you populate the enum through. I'll have to see where 3/3 goes before deciding if this is worth having. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
signature.asc
Description: OpenPGP digital signature