Am 09.02.2012 15:31, schrieb Paolo Bonzini: > Most visitors will use the same code for enum parsing. Move it to > the core. > > Signed-off-by: Paolo Bonzini <pbonz...@redhat.com>
Reviewed-by: Andreas Färber <afaer...@suse.de> However... > diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c > index ddef3ed..a4e088c 100644 > --- a/qapi/qapi-visit-core.c > +++ b/qapi/qapi-visit-core.c > @@ -116,3 +117,53 @@ void visit_type_number(Visitor *v, double *obj, const > char *name, Error **errp) > v->type_number(v, obj, name, errp); > } > } > + > +void output_type_enum(Visitor *v, int *obj, const char *strings[], > + const char *kind, const char *name, > + Error **errp) > +{ > + int i = 0; > + int value = *obj; > + char *enum_str; > + > + assert(strings); > + while (strings[i++] != NULL); > + if (value < 0 || value >= i - 1) { > + error_set(errp, QERR_INVALID_PARAMETER, name ? name : "null"); > + return; > + } > + > + enum_str = (char *)strings[value]; This does not take into account non-linear enum values. Maybe name it output_type_linear_enum to allow for alternative enum lookup implementations? (e.g., hashtable or list of name,value tuples) Andreas -- SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg