From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35151) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZITuQ-00021z-6V for qemu-devel@nongnu.org; Thu, 23 Jul 2015 23:44:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZITuL-0005lM-Mm for qemu-devel@nongnu.org; Thu, 23 Jul 2015 23:44:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54962) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZITuL-0005jL-Ek for qemu-devel@nongnu.org; Thu, 23 Jul 2015 23:44:25 -0400 References: <1435782155-31412-1-git-send-email-armbru@redhat.com> <1435782155-31412-48-git-send-email-armbru@redhat.com> From: Eric Blake Message-ID: <55B1B490.6000402@redhat.com> Date: Thu, 23 Jul 2015 21:44:16 -0600 MIME-Version: 1.0 In-Reply-To: <1435782155-31412-48-git-send-email-armbru@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="daq4OWd2K4dQf2alB7sci8EmJ44niRKLE" Subject: Re: [Qemu-devel] [PATCH RFC v2 47/47] qapi-introspect: Hide type names List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster , qemu-devel@nongnu.org Cc: kwolf@redhat.com, berto@igalia.com, mdroth@linux.vnet.ibm.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --daq4OWd2K4dQf2alB7sci8EmJ44niRKLE Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 07/01/2015 02:22 PM, Markus Armbruster wrote: > To eliminate the temptation for clients to look up types by name > (which are not ABI), replace all type names by meaningless strings. >=20 > Reduces output of query-schema by 9 out of 80KiB. I'm not sure whether I like this or not. It does make sense from the perspective of forcing clients to stick to ABI queries, but makes it a bit harder to navigate things except by automated scripts. >=20 > Signed-off-by: Markus Armbruster > --- > scripts/qapi-introspect.py | 27 +++++++++++++++++++++++++-- > 1 file changed, 25 insertions(+), 2 deletions(-) >=20 > diff --git a/scripts/qapi-introspect.py b/scripts/qapi-introspect.py > index 961fe88..efb34ff 100644 > --- a/scripts/qapi-introspect.py > +++ b/scripts/qapi-introspect.py > @@ -9,13 +9,18 @@ > # This work is licensed under the terms of the GNU GPL, version 2. > # See the COPYING file in the top-level directory. > =20 > +import string > from qapi import * > =20 > +def _b32digit(num): > + return (string.lowercase + string.digits[2:])[num] This feels a bit too magic for me to decipher late at night. > + > class QAPISchemaGenIntrospectVisitor(QAPISchemaVisitor): > def __init__(self): > self.schema =3D None > self.jsons =3D None > self.used_types =3D None > + self.name_map =3D None > self.defn =3D None > self.decl =3D None > =20 > @@ -23,13 +28,17 @@ class QAPISchemaGenIntrospectVisitor(QAPISchemaVisi= tor): > self.schema =3D schema > self.jsons =3D [] > self.used_types =3D [] > + self.name_map =3D {} > return QAPISchemaType # don't visit types for now > =20 > def visit_end(self): > # visit the types that are actually used > + jsons =3D self.jsons > + self.jsons =3D [] > for typ in self.used_types: > typ.visit(self) > self.jsons.sort() > + jsons.extend(self.jsons) I'm not sure I follow the use of .extends() here. > name =3D prefix + 'qmp_schema_json' > self.decl =3D mcgen(''' > extern char %(c_name)s[]; > @@ -40,10 +49,19 @@ char %(c_name)s[] =3D "[" > "%(c_jsons)s]"; > ''', > c_name=3Dc_name(name), > - c_jsons=3D', "\n "'.join(self.jsons)) > + c_jsons=3D', "\n "'.join(jsons)) > self.schema =3D None > self.jsons =3D None > self.used_types =3D None > + self.name_map =3D None > + > + def _name(self, name): > + if name not in self.name_map: > + n =3D len(self.name_map) > + self.name_map[name] =3D ':' + _b32digit(n / 32 / 32) \ > + + _b32digit(n / 32 % 32) \ > + + _b32digit(n % 32) Caps our qapi to 32k types (including implicit ones); will that be an iss= ue? > + return self.name_map[name] > =20 > def _use_type(self, typ): > # Map the various integer types to plain int > @@ -55,9 +73,14 @@ char %(c_name)s[] =3D "[" > # Add type to work queue if new > if typ not in self.used_types: > self.used_types.append(typ) > - return typ.name > + # Clients should examine commands and events, not types. Hide= > + # type names to reduce the temptation. Also saves a few > + # characters. > + return self._name(typ.name) > =20 > def _gen_json(self, name, mtype, extra): > + if mtype !=3D 'command' and mtype !=3D 'event': > + name =3D self._name(name) > self.jsons.append("{ 'name': '%s', 'meta-type': '%s', %s }" > % (name, mtype, extra)) > =20 >=20 --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --daq4OWd2K4dQf2alB7sci8EmJ44niRKLE 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/ iQEcBAEBCAAGBQJVsbSQAAoJEKeha0olJ0NqFe8H/RlDM/YwW5wY7L91lemD7UMZ D+QRDru59W8bCzJCIFdO+s5nlCdChsur3przumBYii+3RA9KmfzsPENM/7+xWZrM yko9v3dSxCQB7MU5ZbL83xpbDV/xSi62lgs4PkhFPzjuIWgIda/v6M300WoxI66e e2+NBHBBJh/wHFlUw7YGv4hAz1Lxquq9AJf+n6EbVMcaso+V4WhvRYJtGVtwEbL1 KSTsVPJB0ml3AolExxDzLVWdlSH1mX3iwph16YWi5Q684Mu9q1JsOjpKYASj9Eou o6WLQ2yIiXF8TBzd9JvrUYtI8a95hhRVHUEKzEHL3+QzTUD68XzynA00VidxFAM= =pfme -----END PGP SIGNATURE----- --daq4OWd2K4dQf2alB7sci8EmJ44niRKLE--