From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43045) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z51Gi-0001Km-8s for qemu-devel@nongnu.org; Tue, 16 Jun 2015 20:31:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z51Ge-0001PX-3G for qemu-devel@nongnu.org; Tue, 16 Jun 2015 20:31:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57926) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z51Gd-0001PK-Uo for qemu-devel@nongnu.org; Tue, 16 Jun 2015 20:31:48 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id 74EB8359990 for ; Wed, 17 Jun 2015 00:31:47 +0000 (UTC) From: Juan Quintela In-Reply-To: <5559FD48.9070405@redhat.com> (Eric Blake's message of "Mon, 18 May 2015 08:55:04 -0600") References: <1431620920-19710-1-git-send-email-quintela@redhat.com> <1431620920-19710-5-git-send-email-quintela@redhat.com> <20150518095834.GC2201@work-vm> <5559FD48.9070405@redhat.com> Date: Wed, 17 Jun 2015 02:31:45 +0200 Message-ID: <87si9rgopa.fsf@neno.neno> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH 4/9] runstate: create runstate_index function Reply-To: quintela@redhat.com List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: "Dr. David Alan Gilbert" , qemu-devel@nongnu.org Eric Blake wrote: D> On 05/18/2015 03:58 AM, Dr. David Alan Gilbert wrote: >> * Juan Quintela (quintela@redhat.com) wrote: >>> Given a string state, we need a way to get the RunState for that string. >>> >>> Signed-off-by: Juan Quintela >>> --- >>> include/sysemu/sysemu.h | 1 + >>> vl.c | 13 +++++++++++++ >>> 2 files changed, 14 insertions(+) >>> > >>> >>> +RunState runstate_index(char *str) >>> +{ >>> + RunState i = 0; >>> + >>> + while (i != RUN_STATE_MAX) { >>> + if (strcmp(str, RunState_lookup[i]) == 0) { >>> + return i; >>> + } >>> + i++; >>> + } >>> + return -1; >> >> It doesn't seem right to return -1 for the value of an enum >> (which is otherwise used as an index into an array of strings). >> >> Make it return a bool and pass the RunState* as a parameter ? > > Why open-code this, when we already have qapi_enum_parse() in > qapi/qapi-util.c? Didn't knew about this function. Thanks, Juan.