From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:41060) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RzwMp-0001Of-T3 for qemu-devel@nongnu.org; Tue, 21 Feb 2012 15:31:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RzwMm-0000ef-1w for qemu-devel@nongnu.org; Tue, 21 Feb 2012 15:31:19 -0500 Received: from cantor2.suse.de ([195.135.220.15]:34685 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RzwMl-0000ck-TU for qemu-devel@nongnu.org; Tue, 21 Feb 2012 15:31:16 -0500 Message-ID: <4F43FF06.5070306@suse.de> Date: Tue, 21 Feb 2012 21:31:02 +0100 From: =?ISO-8859-15?Q?Andreas_F=E4rber?= MIME-Version: 1.0 References: <1328797918-1316-1-git-send-email-pbonzini@redhat.com> <1328797918-1316-2-git-send-email-pbonzini@redhat.com> In-Reply-To: <1328797918-1316-2-git-send-email-pbonzini@redhat.com> Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 1/9] qapi: allow sharing enum implementation across visitors List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: aliguori@us.ibm.com, qemu-devel@nongnu.org Am 09.02.2012 15:31, schrieb Paolo Bonzini: > Most visitors will use the same code for enum parsing. Move it to > the core. >=20 > Signed-off-by: Paolo Bonzini Reviewed-by: Andreas F=E4rber 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, co= nst 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 =3D 0; > + int value =3D *obj; > + char *enum_str; > + > + assert(strings); > + while (strings[i++] !=3D NULL); > + if (value < 0 || value >=3D i - 1) { > + error_set(errp, QERR_INVALID_PARAMETER, name ? name : "null"); > + return; > + } > + > + enum_str =3D (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 --=20 SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 N=FCrnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imend=F6rffer; HRB 16746 AG N=FCrnbe= rg