From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50614) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZJf79-0004px-4S for qemu-devel@nongnu.org; Mon, 27 Jul 2015 05:54:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZJf75-0007BO-Ud for qemu-devel@nongnu.org; Mon, 27 Jul 2015 05:54:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38529) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZJf75-0007BK-PU for qemu-devel@nongnu.org; Mon, 27 Jul 2015 05:54:27 -0400 From: Markus Armbruster References: <1435782155-31412-1-git-send-email-armbru@redhat.com> <1435782155-31412-23-git-send-email-armbru@redhat.com> <55B0DFBE.1010403@redhat.com> Date: Mon, 27 Jul 2015 11:54:24 +0200 In-Reply-To: <55B0DFBE.1010403@redhat.com> (Eric Blake's message of "Thu, 23 Jul 2015 06:36:14 -0600") Message-ID: <87pp3eorhr.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH RFC v2 22/47] qapi: QAPISchema code generation helper methods List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: kwolf@redhat.com, berto@igalia.com, qemu-devel@nongnu.org, mdroth@linux.vnet.ibm.com Eric Blake writes: > On 07/01/2015 02:22 PM, Markus Armbruster wrote: >> New methods c_name(), c_type(), c_null(), json_type(), >> alternate_qtype(). >> >> Signed-off-by: Markus Armbruster >> --- >> scripts/qapi.py | 72 >> +++++++++++++++++++++++++++++++++++++++++++++++++++------ >> 1 file changed, 65 insertions(+), 7 deletions(-) >> > > I just noticed: > >> @@ -779,6 +811,12 @@ class QAPISchemaEnumType(QAPISchemaType): >> for v in values: >> assert isinstance(v, str) >> self.values = values >> + def c_type(self, is_param=False): >> + return c_name(self.name) >> + def c_null(self): >> + return c_enum_const(self.name, self.values[0]) > > What does this return for an empty enum, as in { 'enum':'Empty', > 'data':[] }? I suspect self.values will be [] then, and self.values[0] will bomb. Possible fixes: * Outlaw empty enums * Add the implicit MAX member to self.values[] (other code may have to skip it) * Catch the special case here, and return the implicit MAX member. > Our testsuite proves we can do that, even if our normal > .json code doesn't use it. tests/qapi-schema/enum-empty.json:{ 'enum': 'MyEnum', 'data': [ ] }