From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39296) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZJj2D-0001vW-Jc for qemu-devel@nongnu.org; Mon, 27 Jul 2015 10:05:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZJj2A-0003LN-9N for qemu-devel@nongnu.org; Mon, 27 Jul 2015 10:05:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41489) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZJj2A-0003Kx-1y for qemu-devel@nongnu.org; Mon, 27 Jul 2015 10:05:38 -0400 References: <1435782155-31412-1-git-send-email-armbru@redhat.com> <1435782155-31412-23-git-send-email-armbru@redhat.com> <55B0DFBE.1010403@redhat.com> <87pp3eorhr.fsf@blackfin.pond.sub.org> From: Eric Blake Message-ID: <55B63AB0.7000002@redhat.com> Date: Mon, 27 Jul 2015 08:05:36 -0600 MIME-Version: 1.0 In-Reply-To: <87pp3eorhr.fsf@blackfin.pond.sub.org> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="NpqT2UooCGVUOOUO2vtjLVgUhoxPPVPHl" 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: Markus Armbruster Cc: kwolf@redhat.com, berto@igalia.com, qemu-devel@nongnu.org, mdroth@linux.vnet.ibm.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --NpqT2UooCGVUOOUO2vtjLVgUhoxPPVPHl Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 07/27/2015 03:54 AM, Markus Armbruster wrote: > Eric Blake writes: >=20 >> 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 =3D values >>> + def c_type(self, is_param=3DFalse): >>> + 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':[] }? >=20 > I suspect self.values will be [] then, and self.values[0] will bomb. >=20 > Possible fixes: >=20 > * Outlaw empty enums >=20 > * Add the implicit MAX member to self.values[] (other code may have to > skip it) >=20 > * Catch the special case here, and return the implicit MAX member. I'm leaning toward the third option here. >=20 >> Our testsuite proves we can do that, even if our normal >> .json code doesn't use it. >=20 > tests/qapi-schema/enum-empty.json:{ 'enum': 'MyEnum', 'data': [ ] } As I've mentioned elsewhere, most of our tests/qapi-schema/*.json merely cover whether the parser is okay with the input, while tests/qapi-schema/qapi-schema-test.json is the one that also tests that the generated C code works; so sounds like that test should be enhanced to cover some of these corner cases we have been considering in this series (empty enum, command with no arguments and no returns, and so fort= h). --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --NpqT2UooCGVUOOUO2vtjLVgUhoxPPVPHl Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJVtjqwAAoJEKeha0olJ0Nq0/AH/iQg2kPsPuMxmogM6RXIxbYs r9FQ/15Oc8MEa95InXk3GkFMYevw0+XEasDi4M3i3QXg0Z4SMshgoFu4JwGCPw7r tfDbzedrrRSBggN3DyJyeN2GlCzQAMrbA/lbRGMWsI5tf5iabSXL6Ys7seOjY6zc mHDVLXCEWfy4XEQQw4filmMTCPPznndW1b/gNFB+hTDQxDr3vGgtuYobDr2AvJd2 aZ33R9+hlT/cdspBXnZjmCijXW6K7T3R35k7f0v2w8p2DOkox2d1tTGrQB+5piaE /CY1pKrzgh7JNSRgamky2Me8KZGA2wUQFzZ8sKaLRfZpN+dad+AbJxKIFq0nOpY= =xLvL -----END PGP SIGNATURE----- --NpqT2UooCGVUOOUO2vtjLVgUhoxPPVPHl--