From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:59193) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S06fL-00012X-GF for qemu-devel@nongnu.org; Wed, 22 Feb 2012 02:31:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S06fE-00011M-SC for qemu-devel@nongnu.org; Wed, 22 Feb 2012 02:31:07 -0500 Received: from mail-ee0-f45.google.com ([74.125.83.45]:61188) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S06fE-00011A-IA for qemu-devel@nongnu.org; Wed, 22 Feb 2012 02:31:00 -0500 Received: by eekd17 with SMTP id d17so3228367eek.4 for ; Tue, 21 Feb 2012 23:30:59 -0800 (PST) Sender: Paolo Bonzini Message-ID: <4F4499B0.7080508@redhat.com> Date: Wed, 22 Feb 2012 08:30:56 +0100 From: Paolo Bonzini MIME-Version: 1.0 References: <1328797918-1316-1-git-send-email-pbonzini@redhat.com> <1328797918-1316-2-git-send-email-pbonzini@redhat.com> <4F43FF06.5070306@suse.de> In-Reply-To: <4F43FF06.5070306@suse.de> Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 8bit 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: =?ISO-8859-15?Q?Andreas_F=E4rber?= Cc: aliguori@us.ibm.com, qemu-devel@nongnu.org On 02/21/2012 09:31 PM, Andreas Färber wrote: >> > +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) I would say that this is the common case and the other one should be named output_type_sparse_enum or something like that, if the need arises... Paolo