On 08/04/2015 09:58 AM, Markus Armbruster wrote: > Caution, rough edges. >
> > 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 = 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=ret_type.c_type()) - if arg_type: + if arg_type and arg_type.members: ret += mcgen(''' QmpInputVisitor *mi = qmp_input_visitor_new_strict(QOBJECT(args)); QapiDeallocVisitor *md; @@ -108,7 +108,7 @@ bool has_%(c_name)s = false; def gen_marshal_input_visit(arg_type, dealloc=False): ret = '' - 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 = ':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 = expr['command'] - data = expr.get('data') + data = expr.get('data', {}) rets = expr.get('returns') gen = expr.get('gen', True) success_response = expr.get('success-response', True) - if isinstance(data, OrderedDict): + if isinstance(data, dict): data = self._make_implicit_object_type(name, 'arg', self._make_members(data)) if isinstance(rets, list): assert len(rets) == 1 rets = self._make_array_type(rets[0]) - elif isinstance(rets, OrderedDict): + elif isinstance(rets, dict): rets = 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 = expr['event'] - data = expr.get('data') - if isinstance(data, OrderedDict): + data = expr.get('data', {}) + if isinstance(data, dict): data = 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=True success_response=True -command zwei None -> None +command zwei :empty -> None gen=True success_response=True 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=False member b: int optional=True -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=True success_response=True command guest-sync :obj-guest-sync-arg -> any gen=True success_response=True -command user_def_cmd None -> None +command user_def_cmd :empty -> None gen=True success_response=True command user_def_cmd1 :obj-user_def_cmd1-arg -> None gen=True success_response=True 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=True success_response=True -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature