[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v6 18/26] qapi-commands: De-duplicate output marshal
From: |
Markus Armbruster |
Subject: |
[Qemu-devel] [PATCH v6 18/26] qapi-commands: De-duplicate output marshaling functions |
Date: |
Fri, 11 Sep 2015 21:18:01 +0200 |
gen_marshal_output() uses its parameter name only for name of the
generated function. Name it after the type being marshaled instead of
its caller, and drop duplicates.
Saves 7 copies of qmp_marshal_output_int() in qemu-ga, and one copy of
qmp_marshal_output_str() in qemu-system-*.
Signed-off-by: Markus Armbruster <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
---
docs/qapi-code-gen.txt | 4 ++--
scripts/qapi-commands.py | 17 ++++++++++-------
2 files changed, 12 insertions(+), 9 deletions(-)
diff --git a/docs/qapi-code-gen.txt b/docs/qapi-code-gen.txt
index 09d15dc..147638f 100644
--- a/docs/qapi-code-gen.txt
+++ b/docs/qapi-code-gen.txt
@@ -713,7 +713,7 @@ Example:
$ cat qapi-generated/example-qmp-marshal.c
[Uninteresting stuff omitted...]
- static void qmp_marshal_output_my_command(UserDefOne *ret_in, QObject
**ret_out, Error **errp)
+ static void qmp_marshal_output_UserDefOne(UserDefOne *ret_in, QObject
**ret_out, Error **errp)
{
Error *local_err = NULL;
QmpOutputVisitor *mo = qmp_output_visitor_new();
@@ -756,7 +756,7 @@ Example:
goto out;
}
- qmp_marshal_output_my_command(retval, ret, &local_err);
+ qmp_marshal_output_UserDefOne(retval, ret, &local_err);
out:
error_propagate(errp, local_err);
diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py
index 833768e..810a897 100644
--- a/scripts/qapi-commands.py
+++ b/scripts/qapi-commands.py
@@ -62,7 +62,7 @@ def gen_call(name, arg_type, ret_type):
qmp_marshal_output_%(c_name)s(retval, ret, &local_err);
''',
- c_name=c_name(name))
+ c_name=ret_type.c_name())
pop_indent()
return ret
@@ -166,10 +166,10 @@ qapi_dealloc_visitor_cleanup(md);
return ret
-def gen_marshal_output(name, ret_type):
+def gen_marshal_output(ret_type):
return mcgen('''
-static void qmp_marshal_output_%(c_cmd_name)s(%(c_type)s ret_in, QObject
**ret_out, Error **errp)
+static void qmp_marshal_output_%(c_name)s(%(c_type)s ret_in, QObject
**ret_out, Error **errp)
{
Error *local_err = NULL;
QmpOutputVisitor *mo = qmp_output_visitor_new();
@@ -192,8 +192,7 @@ out:
qapi_dealloc_visitor_cleanup(md);
}
''',
- c_type=ret_type.c_type(), c_cmd_name=c_name(name),
- c_name=ret_type.c_name())
+ c_type=ret_type.c_type(), c_name=ret_type.c_name())
def gen_marshal_proto(name):
@@ -272,24 +271,28 @@ class QAPISchemaGenCommandVisitor(QAPISchemaVisitor):
self.decl = None
self.defn = None
self._regy = None
+ self._visited_ret_types = None
def visit_begin(self, schema):
self.decl = ''
self.defn = ''
self._regy = ''
+ self._visited_ret_types = set()
def visit_end(self):
if not middle_mode:
self.defn += gen_registry(self._regy)
self._regy = None
+ self._visited_ret_types = None
def visit_command(self, name, info, arg_type, ret_type,
gen, success_response):
if not gen:
return
self.decl += gen_command_decl(name, arg_type, ret_type)
- if ret_type:
- self.defn += gen_marshal_output(name, ret_type)
+ if ret_type and ret_type not in self._visited_ret_types:
+ self._visited_ret_types.add(ret_type)
+ self.defn += gen_marshal_output(ret_type)
if middle_mode:
self.decl += gen_marshal_decl(name)
self.defn += gen_marshal(name, arg_type, ret_type)
--
2.4.3
- [Qemu-devel] [PATCH v6 09/26] qapi: De-duplicate enum code generation, (continued)
- [Qemu-devel] [PATCH v6 09/26] qapi: De-duplicate enum code generation, Markus Armbruster, 2015/09/11
- [Qemu-devel] [PATCH v6 06/26] qapi-types: Convert to QAPISchemaVisitor, fixing flat unions, Markus Armbruster, 2015/09/11
- [Qemu-devel] [PATCH v6 05/26] tests/qapi-schema: Convert test harness to QAPISchemaVisitor, Markus Armbruster, 2015/09/11
- [Qemu-devel] [PATCH v6 07/26] qapi-visit: Convert to QAPISchemaVisitor, fixing bugs, Markus Armbruster, 2015/09/11
- [Qemu-devel] [PATCH v6 11/26] qapi-event: Convert to QAPISchemaVisitor, fixing data with base, Markus Armbruster, 2015/09/11
- [Qemu-devel] [PATCH v6 17/26] qapi: De-duplicate parameter list generation, Markus Armbruster, 2015/09/11
- [Qemu-devel] [PATCH v6 13/26] qapi: Clean up after recent conversions to QAPISchemaVisitor, Markus Armbruster, 2015/09/11
- [Qemu-devel] [PATCH v6 01/26] qapi: Rename class QAPISchema to QAPISchemaParser, Markus Armbruster, 2015/09/11
- [Qemu-devel] [PATCH v6 23/26] qapi-schema: Fix up misleading specification of netdev_add, Markus Armbruster, 2015/09/11
- [Qemu-devel] [PATCH v6 19/26] qapi: Improve built-in type documentation, Markus Armbruster, 2015/09/11
- [Qemu-devel] [PATCH v6 18/26] qapi-commands: De-duplicate output marshaling functions,
Markus Armbruster <=
- [Qemu-devel] [PATCH v6 20/26] qapi: Fix output visitor to return qnull() instead of NULL, Markus Armbruster, 2015/09/11
- Re: [Qemu-devel] [PATCH v6 20/26] qapi: Fix output visitor to return qnull() instead of NULL, Eric Blake, 2015/09/11
- Re: [Qemu-devel] [PATCH v6 20/26] qapi: Fix output visitor to return qnull() instead of NULL, Eric Blake, 2015/09/11
- Re: [Qemu-devel] [PATCH v6 20/26] qapi: Fix output visitor to return qnull() instead of NULL, Markus Armbruster, 2015/09/12
- Re: [Qemu-devel] [PATCH v6 20/26] qapi: Fix output visitor to return qnull() instead of NULL, Eric Blake, 2015/09/12
- Re: [Qemu-devel] [PATCH v6 20/26] qapi: Fix output visitor to return qnull() instead of NULL, Eric Blake, 2015/09/12
- Re: [Qemu-devel] [PATCH v6 20/26] qapi: Fix output visitor to return qnull() instead of NULL, Eric Blake, 2015/09/12
- Re: [Qemu-devel] [PATCH v6 20/26] qapi: Fix output visitor to return qnull() instead of NULL, Markus Armbruster, 2015/09/12
- Re: [Qemu-devel] [PATCH v6 20/26] qapi: Fix output visitor to return qnull() instead of NULL, Eric Blake, 2015/09/12
[Qemu-devel] [PATCH v6 15/26] qapi-commands: Rearrange code, Markus Armbruster, 2015/09/11