From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59362) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZTMim-0007LR-80 for qemu-devel@nongnu.org; Sun, 23 Aug 2015 00:17:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZTMii-0003hL-V1 for qemu-devel@nongnu.org; Sun, 23 Aug 2015 00:17:28 -0400 Received: from resqmta-po-04v.sys.comcast.net ([2001:558:fe16:19:96:114:154:163]:37221) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZTMii-0003hD-Mu for qemu-devel@nongnu.org; Sun, 23 Aug 2015 00:17:24 -0400 References: <1438703896-12553-1-git-send-email-armbru@redhat.com> <1438703896-12553-31-git-send-email-armbru@redhat.com> From: Eric Blake Message-ID: <55D94951.3020109@redhat.com> Date: Sat, 22 Aug 2015 22:17:21 -0600 MIME-Version: 1.0 In-Reply-To: <1438703896-12553-31-git-send-email-armbru@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="ew1Btv5TgR5Wnp87D7ETXSsdqbslxTlX8" Subject: Re: [Qemu-devel] [PATCH RFC v3 30/32] qapi: New QMP command query-schema for QMP schema introspection 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) --ew1Btv5TgR5Wnp87D7ETXSsdqbslxTlX8 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 08/04/2015 09:58 AM, Markus Armbruster wrote: > Caution, rough edges. >=20 >=20 > The empty object type is used when a command takes no arguments or > produces no results. > +++ b/scripts/qapi.py > @@ -1050,6 +1054,9 @@ class QAPISchema(object): > ('bool', 'boolean', 'bool', 'false'), > ('any', 'value', 'QObject' + pointer_suffix , '= NULL')]: > self._def_builtin_type(*t) > + self.the_empty_object_type =3D QAPISchemaObjectType(':empty', = None, None, > + [], None) > + self._def_entity(self.the_empty_object_type) We mentioned moving this into its own patch. In particular, I looked at what it would take to allow anonymous structs for flat union types: { 'union': 'Flat', 'base': 'Base', 'discriminator': 'type', 'data': { 'branch1': {}, 'branch2': { 'integer': 'int' } } } but having _make_implicit_object_type() return None caused subsequent failures. Normalizing to always use the special ':empty' might be worth doing if you hoist this work earlier; here's the diff I was playing with.= And while at it, should types like 'Abort' and 'ChardevDummy' (which are both intentionally empty) normalize to the same ':empty' type during introspection, or is it okay if two separate types with the same (lack of) member contents can result in separate type numbers in the introspection? diff --git i/scripts/qapi-commands.py w/scripts/qapi-commands.py index 7ff7c31..06e6a1e 100644 --- i/scripts/qapi-commands.py +++ w/scripts/qapi-commands.py @@ -76,7 +76,7 @@ def gen_marshal_vars(arg_type, ret_type): ''', c_type=3Dret_type.c_type()) - if arg_type: + if arg_type and arg_type.members: ret +=3D mcgen(''' QmpInputVisitor *mi =3D qmp_input_visitor_new_strict(QOBJECT(args)); QapiDeallocVisitor *md; @@ -108,7 +108,7 @@ bool has_%(c_name)s =3D false; def gen_marshal_input_visit(arg_type, dealloc=3DFalse): ret =3D '' - if not arg_type: + if not arg_type or not arg_type.members: return ret push_indent() diff --git i/scripts/qapi.py w/scripts/qapi.py index 34c2884..133b859 100644 --- i/scripts/qapi.py +++ w/scripts/qapi.py @@ -1071,7 +1071,7 @@ class QAPISchema(object): def _make_implicit_object_type(self, name, role, members): if not members: - return None + return ':empty' name =3D ':obj-%s-%s' % (name, role) if not self.lookup_entity(name, QAPISchemaObjectType): self._def_entity(QAPISchemaObjectType(name, None, None, @@ -1155,17 +1155,17 @@ class QAPISchema(object): def _def_command(self, expr, info): name =3D expr['command'] - data =3D expr.get('data') + data =3D expr.get('data', {}) rets =3D expr.get('returns') gen =3D expr.get('gen', True) success_response =3D expr.get('success-response', True) - if isinstance(data, OrderedDict): + if isinstance(data, dict): data =3D self._make_implicit_object_type(name, 'arg', self._make_members(data)) if isinstance(rets, list): assert len(rets) =3D=3D 1 rets =3D self._make_array_type(rets[0]) - elif isinstance(rets, OrderedDict): + elif isinstance(rets, dict): rets =3D self._make_implicit_object_type(name, 'ret', self._make_members(rets)) self._def_entity(QAPISchemaCommand(name, info, data, rets, gen, @@ -1173,8 +1173,8 @@ class QAPISchema(object): def _def_event(self, expr, info): name =3D expr['event'] - data =3D expr.get('data') - if isinstance(data, OrderedDict): + data =3D expr.get('data', {}) + if isinstance(data, dict): data =3D self._make_implicit_object_type(name, 'arg', self._make_members(data)) self._def_entity(QAPISchemaEvent(name, info, data)) diff --git i/tests/qapi-schema/event-case.out w/tests/qapi-schema/event-case.out index cdfd264..6a84fdd 100644 --- i/tests/qapi-schema/event-case.out +++ w/tests/qapi-schema/event-case.out @@ -1,2 +1,2 @@ object :empty -event oops None +event oops :empty diff --git i/tests/qapi-schema/indented-expr.out w/tests/qapi-schema/indented-expr.out index 226d300..8999a6d 100644 --- i/tests/qapi-schema/indented-expr.out +++ w/tests/qapi-schema/indented-expr.out @@ -1,5 +1,5 @@ object :empty -command eins None -> None +command eins :empty -> None gen=3DTrue success_response=3DTrue -command zwei None -> None +command zwei :empty -> None gen=3DTrue success_response=3DTrue diff --git i/tests/qapi-schema/qapi-schema-test.out w/tests/qapi-schema/qapi-schema-test.out index 386b057..57cae76 100644 --- i/tests/qapi-schema/qapi-schema-test.out +++ w/tests/qapi-schema/qapi-schema-test.out @@ -51,8 +51,8 @@ object :obj-user_def_cmd2-arg object :obj-user_def_cmd3-arg member a: int optional=3DFalse member b: int optional=3DTrue -event EVENT_A None -event EVENT_B None +event EVENT_A :empty +event EVENT_B :empty event EVENT_C :obj-EVENT_C-arg event EVENT_D :obj-EVENT_D-arg enum EnumOne ['value1', 'value2', 'value3'] @@ -154,7 +154,7 @@ command __org.qemu_x-command :obj-__org.qemu_x-command-arg -> __org.qemu_x-Union gen=3DTrue success_response=3DTrue command guest-sync :obj-guest-sync-arg -> any gen=3DTrue success_response=3DTrue -command user_def_cmd None -> None +command user_def_cmd :empty -> None gen=3DTrue success_response=3DTrue command user_def_cmd1 :obj-user_def_cmd1-arg -> None gen=3DTrue success_response=3DTrue diff --git i/tests/qapi-schema/returns-int.out w/tests/qapi-schema/returns-int.out index a2da259..29825e8 100644 --- i/tests/qapi-schema/returns-int.out +++ w/tests/qapi-schema/returns-int.out @@ -1,3 +1,3 @@ object :empty -command guest-get-time None -> int +command guest-get-time :empty -> int gen=3DTrue success_response=3DTrue --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --ew1Btv5TgR5Wnp87D7ETXSsdqbslxTlX8 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/ iQEcBAEBCAAGBQJV2UlRAAoJEKeha0olJ0NqvR0H/RwjQOA57+Z5zzw+ZUzwfT7x rpq0deR2Z4vABLm8VWlLMPfsP+CU3sefkvDiakHQ7zAjtrIDUKlbPhFyHqrjJcVQ 8oDI64zs9MOHuDBh1rZHaVSX+yisQuldfleIHl5LJDXl8ipXO9QU92lfsxwo2q+W P3r7tTSXo/X9SiyTcMjBuX6RYcVENW+LM/sW+5GBdil4qAg6pjR8PcyE4KoBXjBk B9IJQmW8h9ZcZVWYcABqMqcRRU3YsZnsuHvplFBwCRRe71I7GsBPzSZu6vbBUeH8 OhbG/F3AUiTEUu56FGnZ1pM3FwtmXXczyjqPaWJp+IxmCeuxG8WCKZmpyo/OBAQ= =H3j7 -----END PGP SIGNATURE----- --ew1Btv5TgR5Wnp87D7ETXSsdqbslxTlX8--