From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34828) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZxIQc-0001cn-GW for qemu-devel@nongnu.org; Fri, 13 Nov 2015 12:46:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZxIQb-000723-HC for qemu-devel@nongnu.org; Fri, 13 Nov 2015 12:46:26 -0500 References: <1447224690-9743-1-git-send-email-eblake@redhat.com> <1447224690-9743-20-git-send-email-eblake@redhat.com> From: Eric Blake Message-ID: <564621E7.9040103@redhat.com> Date: Fri, 13 Nov 2015 10:46:15 -0700 MIME-Version: 1.0 In-Reply-To: <1447224690-9743-20-git-send-email-eblake@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="loWWQAA0T86MMX5FkU0jO3FW0hVFuUPFP" Subject: Re: [Qemu-devel] [PATCH v11 19/28] qapi: Change munging of CamelCase enum values List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Peter Maydell , "open list:Block layer core" , "Michael S. Tsirkin" , Jason Wang , Michael Roth , armbru@redhat.com, Gerd Hoffmann , Amit Shah , Luiz Capitulino , =?UTF-8?Q?Andreas_F=c3=a4rber?= This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --loWWQAA0T86MMX5FkU0jO3FW0hVFuUPFP Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 11/10/2015 11:51 PM, Eric Blake wrote: > When munging enum values, the fact that we were passing the entire > prefix + value through camel_to_upper() meant that enum values > spelled with CamelCase could be turned into CAMEL_CASE. However, > this provides a potential collision (both OneTwo and One-Two would > munge into ONE_TWO). By changing the generation of enum constants > to always be prefix + '_' + c_name(value).upper(), we can avoid > any risk of collisions (if we can also ensure no case collisions, > in the next patch) without having to think about what the > heuristics in camel_to_upper() will actually do to the value. >=20 > +++ b/scripts/qapi.py > @@ -1439,7 +1439,7 @@ def camel_to_upper(value): > def c_enum_const(type_name, const_name, prefix=3DNone): > if prefix is not None: > type_name =3D prefix > - return camel_to_upper(type_name + '_' + const_name) > + return camel_to_upper(type_name) + '_' + c_name(const_name, False)= =2Eupper() Doesn't match the commit message, because it used c_name(,False), while c_name(name) is short for c_name(name, True). What's more, looking at it exposed a bug: c_name('_Thread-local') returns '_Thread_local', but this collides with a C11 keyword (and was supposed to be munged to q__Thread_local); add '_Thread-local':'int' to a struct to see the resulting hilarity: CC tests/test-qmp-output-visitor.o In file included from tests/test-qmp-output-visitor.c:17:0: tests/test-qapi-types.h:781:13: error: expected identifier or =E2=80=98(=E2= =80=99 before =E2=80=98_Thread_local=E2=80=99 int64_t _Thread_local; ^ But it also made me realize that c_name('Q-int') happily returns 'Q_int' (we only reserved the leading 'q_' namespace, not 'Q_'). Alas, that means c_name('Q-int', False).upper() and c_name('int', False).upper() both produce 'Q_INT', and we have a collision. So I think enum names have to be munged by c_name(name, True). --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --loWWQAA0T86MMX5FkU0jO3FW0hVFuUPFP 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/ iQEcBAEBCAAGBQJWRiHnAAoJEKeha0olJ0NqZbIIAJEkP+m/7cDjd35rFrY1dZ4h bgds4cXHva7mZrTHiq7w3J/nPgwmgWNARnngctaHa1uLlBY03oFQnTi/slQ0evb+ gMOcAtPPNV+cosafx6T7OP2pc2GBn8QciCHYNF3Vo9YySnitLUR99XZoPaxxGlYW 9AWKwXW07CEeLrqVnhARHuNiXHVlDn7w2VpbFSqREjlCEPsQy+nHq3hhTC/kADmB 5oRry75B4/mDAP6B72ZkFF5Kyye4evWRhRW3zIhn7avShTQeg3+zNdgxKsviUK80 d70qXW/L0IqJ8fWMnabrE01+gJDsXxoh5lmz9Ts6BnLCv2Md/cMawhar7oLLtjQ= =3Wfc -----END PGP SIGNATURE----- --loWWQAA0T86MMX5FkU0jO3FW0hVFuUPFP--