From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49236) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZUcXW-0006PP-TW for qemu-devel@nongnu.org; Wed, 26 Aug 2015 11:23:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZUcXV-0002vn-OM for qemu-devel@nongnu.org; Wed, 26 Aug 2015 11:23:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34992) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZUcXV-0002vW-Fe for qemu-devel@nongnu.org; Wed, 26 Aug 2015 11:23:01 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 12A6C8E255 for ; Wed, 26 Aug 2015 15:23:01 +0000 (UTC) References: <1440601524-30316-1-git-send-email-berrange@redhat.com> <1440601524-30316-2-git-send-email-berrange@redhat.com> From: Eric Blake Message-ID: <55DDD9CF.3090302@redhat.com> Date: Wed, 26 Aug 2015 09:22:55 -0600 MIME-Version: 1.0 In-Reply-To: <1440601524-30316-2-git-send-email-berrange@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="LUR2gXhf42KHJ8tQeEtApRDPXOne4AenX" Subject: Re: [Qemu-devel] [PATCH v5 1/9] qapi: allow override of default enum prefix naming List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Daniel P. Berrange" , qemu-devel@nongnu.org Cc: Paolo Bonzini , Gerd Hoffmann , Markus Armbruster This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --LUR2gXhf42KHJ8tQeEtApRDPXOne4AenX Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 08/26/2015 09:05 AM, Daniel P. Berrange wrote: > The camel_to_upper() method applies some heuristics to turn > a mixed case type name into an all-uppercase name. This is > used for example, to generate enum constant name prefixes. >=20 > The heuristics don't also generate a satisfactory name > though. eg >=20 > { 'enum': 'QCryptoTLSCredsEndpoint', > 'data': ['client', 'server']} >=20 > Results in Q_CRYPTOTLS_CREDS_ENDPOINT_CLIENT. This has > an undesirable _ after the initial Q and is missing an > _ betweeen the CRYPTO & TLS strings. s/betweeen/between/ >=20 > Rather than try to add more and more heuristics to try > to cope with this, simply allow the QAPI schema to > specify the desired enum constant prefix explicitly. >=20 > eg >=20 > { 'enum': 'QCryptoTLSCredsEndpoint', > 'prefix': 'QCRYPTO_TLS_CREDS_ENDPOINT', > 'data': ['client', 'server']} >=20 > Now gives the QCRYPTO_TLS_CREDS_ENDPOINT_CLIENT name. Idea seems reasonable. >=20 > Signed-off-by: Daniel P. Berrange > --- > scripts/qapi-types.py | 14 +++++++------- > scripts/qapi.py | 9 ++++++--- > 2 files changed, 13 insertions(+), 10 deletions(-) Missing documentation (docs/qapi-code-gen.txt) and a testsuite addition. I suggest using 'prefix' on one of the existing enums in tests/qapi-schema/qapi-schema-test.json, then fixing any fallout from 'make check-unit check-qapi-schema' to ensure it still passes - probably done correctly if this also touches tests/qapi-schema/qapi-schema-test.out and tests/test-qmp-*visitor.c. Doesn't affect QMP wire ABI, so the new key shouldn't impact the output produced by Markus' pending series on introspection, although we may have some code collisions with the refactoring work going on there. >=20 > diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py > index e6eb4b6..549c2f7 100644 > --- a/scripts/qapi-types.py > +++ b/scripts/qapi-types.py > @@ -336,9 +336,9 @@ for expr in exprs: > if expr.has_key('struct'): > ret +=3D generate_fwd_struct(expr['struct']) > elif expr.has_key('enum'): > - ret +=3D generate_enum(expr['enum'], expr['data']) + "\n" > + ret +=3D generate_enum(expr['enum'], expr['data'], expr.get('p= refix')) + "\n" > ret +=3D generate_fwd_enum_struct(expr['enum']) > - fdef.write(generate_enum_lookup(expr['enum'], expr['data'])) > + fdef.write(generate_enum_lookup(expr['enum'], expr['data'], ex= pr.get('prefix'))) Long line; I'd wrap after the last ',' > +++ b/scripts/qapi.py > @@ -698,7 +698,7 @@ def check_exprs(exprs): > expr =3D expr_elem['expr'] > info =3D expr_elem['info'] > if expr.has_key('enum'): > - check_keys(expr_elem, 'enum', ['data']) > + check_keys(expr_elem, 'enum', ['data'], ['prefix']) I'd also amend check_enum() to ensure that the supplied prefix is a string (and not some other data structure); if you add a new error message that explicitly filters out an invalid prefix, then that is a further testsuite addition of a new negative test (tests/Makefile.am to add the the new tests/qapi-schema/*.json file, plus the corresponding =2E{out,exit,err} files to match expected results). > -def c_enum_const(type_name, const_name): > - return camel_to_upper(type_name + '_' + const_name) > +def c_enum_const(type_name, const_name, prefix=3DNone): > + if prefix is not None: > + return prefix + '_' + camel_to_upper(const_name) > + else: > + return camel_to_upper(type_name + '_' + const_name) Would it be any easier to read as: def c_enum_const(type_name, const_name, prefix=3DNone): if not prefix: prefix =3D camel_to_upper(type_name) return prefix + '_' + camel_to_upper(const_name) But I'm not sure if that would introduce any subtle changes to existing enums. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --LUR2gXhf42KHJ8tQeEtApRDPXOne4AenX 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/ iQEcBAEBCAAGBQJV3dnPAAoJEKeha0olJ0NqPdAH/3ONpQk9WUm8K+dVYMvsxYZC XIr6SkmSJVPGm97MT+os9xiGSHyQHjYgyPKtFVH/p292mgZzBmWkApZxODCeVZyb r7bMk2xAob+8KNlENrZf58URknN1r5v6A9gw7RoNa9U2kiUn+3sfV91BfgZrlXMe ZHtzxfL7P8XUZzhEReWvar0wKDh9lk6B/Y9IATsSUaiA8NBZHZ544IZFeH6LeBel euEyt8Q6zHtAIzlPzJhxlpiZtLLXhjV2OwXYRyU3Lgjk5skJdgRL0dNrc1jIHhno Ke5lpfF/lWgYmk8B4SQzRpMuxeUYyDXVj6tzh/TQ+DkSrrGzSVluFnongQ485z4= =UGSJ -----END PGP SIGNATURE----- --LUR2gXhf42KHJ8tQeEtApRDPXOne4AenX--