From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59088) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zpd7N-0001IG-BU for qemu-devel@nongnu.org; Fri, 23 Oct 2015 10:14:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zpd7I-0007MB-FS for qemu-devel@nongnu.org; Fri, 23 Oct 2015 10:14:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55881) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zpd7I-0007M6-7A for qemu-devel@nongnu.org; Fri, 23 Oct 2015 10:14:48 -0400 References: <1445576998-2921-1-git-send-email-eblake@redhat.com> <1445576998-2921-6-git-send-email-eblake@redhat.com> <87d1w5hh1e.fsf@blackfin.pond.sub.org> From: Eric Blake Message-ID: <562A40D1.30600@redhat.com> Date: Fri, 23 Oct 2015 08:14:41 -0600 MIME-Version: 1.0 In-Reply-To: <87d1w5hh1e.fsf@blackfin.pond.sub.org> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="2Q01Fmi3HD9S8dQ5q1tQoM5vDhIx2gB1w" Subject: Re: [Qemu-devel] [PATCH v10 05/25] qapi: Reserve 'q_*' and 'has_*' member names List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster Cc: qemu-devel@nongnu.org, Michael Roth This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --2Q01Fmi3HD9S8dQ5q1tQoM5vDhIx2gB1w Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 10/23/2015 07:05 AM, Markus Armbruster wrote: > Eric Blake writes: >=20 >> c_name() produces names starting with 'q_' when protecting >> a QMP member name that would fail to directly compile, but >> in doing so can cause clashes with any QMP name already >> beginning with 'q-' or 'q_'. Likewise, we create a C name >> 'has_' for any optional member, that can clash with any QMP >> name beginning with 'has-' or 'has_'. >> >> Technically, rather than blindly reserving the namespace, >> we could try to complain about user names only when an actual >> collision occurs, or even teach c_name() how to munge names >> to avoid collisions. But it is not trivial, especially when >> collisions can occur across multiple types (such as via >> inheritance or flat unions). Besides, no existing .json >> files are trying to use these names. So it's easier to just >> outright forbid the potential for collision. We can always >> relax things in the future if a real need arises for QMP to >> express member names that have been forbidden here. >> >> 'has_' only has to be reserved for struct/union member names, >> while 'q_' is reserved everywhere (matching the fact that >> we only have optional members, but use c_name() everywhere). >> >> Update and add tests to cover the new error messages. >> >> Signed-off-by: Eric Blake >> >> +++ b/scripts/qapi.py >> @@ -376,7 +376,9 @@ def check_name(expr_info, source, name, allow_opti= onal=3DFalse, >> # code always prefixes it with the enum name >> if enum_member: >> membername =3D '_' + membername >> - if not valid_name.match(membername): >> + # Reserve the entire 'q_' namespace for c_name() >> + if not valid_name.match(membername) or \ >> + membername.replace('-', '_').startswith('q_'): >=20 > Why not c_name(membername).startswith('q_')? Recursion. c_name('unix') is 'q_unix', which would be rejected, even though we want to accept it. (And yes, that was my first try, before the approach you see here) >> +++ b/tests/qapi-schema/args-has-clash.json >> @@ -1,6 +1,6 @@ >> # C member name collision >> -# FIXME - This parses, but fails to compile, because the C struct is = given >> -# two 'has_a' members, one from the flag for optional 'a', and the ot= her >> -# from member 'has-a'. Either reject this at parse time, or munge th= e C >> -# names to avoid the collision. >> +# This would attempt to create two 'has_a' members of the C struct, o= ne >> +# from the flag for optional 'a', and the other from member 'has-a'; = so >> +# instead we reject any member with a name that would collide with 'h= as_'. >=20 > Suggest something like: >=20 > # We reject names like 'has-a', because they can collide with the flag > # for an optional 'a' in generated C. Sure, your wording changes are fine. >=20 > Remind me, why do we need both reserved-command.json and > reserved-member.json? Because they are different namespaces. Your comment in 1/25 pointed out that we could change the command munging to allow qmp_q_unix() independently from qmp_unix(), even when we can't do the same for members= =2E --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --2Q01Fmi3HD9S8dQ5q1tQoM5vDhIx2gB1w 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/ iQEcBAEBCAAGBQJWKkDRAAoJEKeha0olJ0NqoCwH/jEf4hf4YmglZx8fneOpfUa6 6RHcL6iTPYvxK4OCDRYxPIyb1+IiSObq+3/97VWx7izMrKFhy2S2gotXfuR7cx9N nKYfA+vHZOEStmX+dNsdfLWpsOwBgtzzNOIH08gJWyGdBtVGW5TlAlWuJHFXRr0i hbDwiXqOZoZRqA5abyvmSPnmGfRsg8pTefSxCH2vBUr4f6rnTmdKsyLPiuyDknBT lR3qZXlmrrDKZwNzqMkCwoDzEvUCjbKmubKV5cNvH+JPsGeMlybNcrF9aUexzMwo 3/tZgmltZ1ras8kalF+ziPwG1lCzFutioNnzmqUITiVzi6kmsvmNz1BlgwzFbrs= =V2/z -----END PGP SIGNATURE----- --2Q01Fmi3HD9S8dQ5q1tQoM5vDhIx2gB1w--