From: Luiz Capitulino <lcapitulino@redhat.com>
To: peter.maydell@linaro.org
Cc: qemu-devel@nongnu.org, anthony@codemonkey.ws
Subject: [Qemu-devel] [PULL 02/20] qapi: Normalize marshalling's visitor initialization and cleanup
Date: Fri, 16 May 2014 11:30:17 -0400 [thread overview]
Message-ID: <1400254235-9435-3-git-send-email-lcapitulino@redhat.com> (raw)
In-Reply-To: <1400254235-9435-1-git-send-email-lcapitulino@redhat.com>
From: Markus Armbruster <armbru@redhat.com>
Input and output marshalling functions do it differently. Change them
to work the same: initialize the I/O visitor, use it, clean it up,
initialize the dealloc visitor, use it, clean it up.
This delays dealloc visitor initialization in output marshalling
functions, and input visitor cleanup in input marshalling functions.
No functional change, but the latter will be convenient when I change
the error handling.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
docs/qapi-code-gen.txt | 8 ++++----
scripts/qapi-commands.py | 27 ++++++++++++---------------
2 files changed, 16 insertions(+), 19 deletions(-)
diff --git a/docs/qapi-code-gen.txt b/docs/qapi-code-gen.txt
index b915c4d..1a635e2 100644
--- a/docs/qapi-code-gen.txt
+++ b/docs/qapi-code-gen.txt
@@ -434,8 +434,8 @@ Example:
static void qmp_marshal_output_my_command(UserDefOne * ret_in, QObject **ret_out, Error **errp)
{
- QapiDeallocVisitor *md = qapi_dealloc_visitor_new();
QmpOutputVisitor *mo = qmp_output_visitor_new();
+ QapiDeallocVisitor *md;
Visitor *v;
v = qmp_output_get_visitor(mo);
@@ -444,6 +444,7 @@ Example:
*ret_out = qmp_output_get_qobject(mo);
}
qmp_output_visitor_cleanup(mo);
+ md = qapi_dealloc_visitor_new();
v = qapi_dealloc_get_visitor(md);
visit_type_UserDefOne(v, &ret_in, "unused", NULL);
qapi_dealloc_visitor_cleanup(md);
@@ -452,15 +453,13 @@ Example:
static void qmp_marshal_input_my_command(QDict *args, QObject **ret, Error **errp)
{
UserDefOne * retval = NULL;
- QmpInputVisitor *mi;
+ QmpInputVisitor *mi = qmp_input_visitor_new_strict(QOBJECT(args));
QapiDeallocVisitor *md;
Visitor *v;
UserDefOne * arg1 = NULL;
- mi = qmp_input_visitor_new_strict(QOBJECT(args));
v = qmp_input_get_visitor(mi);
visit_type_UserDefOne(v, &arg1, "arg1", errp);
- qmp_input_visitor_cleanup(mi);
if (error_is_set(errp)) {
goto out;
@@ -471,6 +470,7 @@ Example:
}
out:
+ qmp_input_visitor_cleanup(mi);
md = qapi_dealloc_visitor_new();
v = qapi_dealloc_get_visitor(md);
visit_type_UserDefOne(v, &arg1, "arg1", NULL);
diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py
index 8d9096f..1399826 100644
--- a/scripts/qapi-commands.py
+++ b/scripts/qapi-commands.py
@@ -69,16 +69,17 @@ def gen_marshal_output_call(name, ret_type):
return ""
return "qmp_marshal_output_%s(retval, ret, errp);" % c_fun(name)
-def gen_visitor_input_containers_decl(args):
+def gen_visitor_input_containers_decl(args, obj):
ret = ""
push_indent()
if len(args) > 0:
ret += mcgen('''
-QmpInputVisitor *mi;
+QmpInputVisitor *mi = qmp_input_visitor_new_strict(%(obj)s);
QapiDeallocVisitor *md;
Visitor *v;
-''')
+''',
+ obj=obj)
pop_indent()
return ret.rstrip()
@@ -106,7 +107,7 @@ bool has_%(argname)s = false;
pop_indent()
return ret.rstrip()
-def gen_visitor_input_block(args, obj, dealloc=False):
+def gen_visitor_input_block(args, dealloc=False):
ret = ""
errparg = 'errp'
@@ -118,15 +119,14 @@ def gen_visitor_input_block(args, obj, dealloc=False):
if dealloc:
errparg = 'NULL'
ret += mcgen('''
+qmp_input_visitor_cleanup(mi);
md = qapi_dealloc_visitor_new();
v = qapi_dealloc_get_visitor(md);
''')
else:
ret += mcgen('''
-mi = qmp_input_visitor_new_strict(%(obj)s);
v = qmp_input_get_visitor(mi);
-''',
- obj=obj)
+''')
for argname, argtype, optional, structured in parse_args(args):
if optional:
@@ -152,10 +152,6 @@ visit_end_optional(v, %(errp)s);
ret += mcgen('''
qapi_dealloc_visitor_cleanup(md);
''')
- else:
- ret += mcgen('''
-qmp_input_visitor_cleanup(mi);
-''')
pop_indent()
return ret.rstrip()
@@ -166,8 +162,8 @@ def gen_marshal_output(name, args, ret_type, middle_mode):
ret = mcgen('''
static void qmp_marshal_output_%(c_name)s(%(c_ret_type)s ret_in, QObject **ret_out, Error **errp)
{
- QapiDeallocVisitor *md = qapi_dealloc_visitor_new();
QmpOutputVisitor *mo = qmp_output_visitor_new();
+ QapiDeallocVisitor *md;
Visitor *v;
v = qmp_output_get_visitor(mo);
@@ -176,6 +172,7 @@ static void qmp_marshal_output_%(c_name)s(%(c_ret_type)s ret_in, QObject **ret_o
*ret_out = qmp_output_get_qobject(mo);
}
qmp_output_visitor_cleanup(mo);
+ md = qapi_dealloc_visitor_new();
v = qapi_dealloc_get_visitor(md);
%(visitor)s(v, &ret_in, "unused", NULL);
qapi_dealloc_visitor_cleanup(md);
@@ -228,9 +225,9 @@ def gen_marshal_input(name, args, ret_type, middle_mode):
%(visitor_input_block)s
''',
- visitor_input_containers_decl=gen_visitor_input_containers_decl(args),
+ visitor_input_containers_decl=gen_visitor_input_containers_decl(args, "QOBJECT(args)"),
visitor_input_vars_decl=gen_visitor_input_vars_decl(args),
- visitor_input_block=gen_visitor_input_block(args, "QOBJECT(args)"))
+ visitor_input_block=gen_visitor_input_block(args))
else:
ret += mcgen('''
(void)args;
@@ -250,7 +247,7 @@ out:
ret += mcgen('''
%(visitor_input_block_cleanup)s
''',
- visitor_input_block_cleanup=gen_visitor_input_block(args, None,
+ visitor_input_block_cleanup=gen_visitor_input_block(args,
dealloc=True))
if middle_mode:
--
1.9.0
next prev parent reply other threads:[~2014-05-16 16:23 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-16 15:30 [Qemu-devel] [PULL 00/20] QMP queue Luiz Capitulino
2014-05-16 15:30 ` [Qemu-devel] [PULL 01/20] qapi: Update qapi-code-gen.txt example to match current code Luiz Capitulino
2014-05-16 15:30 ` Luiz Capitulino [this message]
2014-05-16 15:30 ` [Qemu-devel] [PULL 03/20] qapi: Remove unused Visitor callbacks start_handle(), end_handle() Luiz Capitulino
2014-05-16 15:30 ` [Qemu-devel] [PULL 04/20] qapi: Replace start_optional()/end_optional() by optional() Luiz Capitulino
2014-05-16 15:30 ` [Qemu-devel] [PULL 05/20] qapi-visit.py: Clean up confusing push_indent() / pop_indent() use Luiz Capitulino
2014-05-16 15:30 ` [Qemu-devel] [PULL 06/20] qapi: Clean up shadowing of parameters and locals in inner scopes Luiz Capitulino
2014-05-16 15:30 ` [Qemu-devel] [PULL 07/20] qapi-visit.py: Clean up a sloppy use of field prefix Luiz Capitulino
2014-05-16 15:30 ` [Qemu-devel] [PULL 08/20] qapi: Un-inline visit of implicit struct Luiz Capitulino
2014-05-16 15:30 ` [Qemu-devel] [PULL 09/20] hmp: Call visit_end_struct() after visit_start_struct() succeeds Luiz Capitulino
2014-05-16 15:30 ` [Qemu-devel] [PULL 10/20] hw: Don't call visit_end_struct() after visit_start_struct() fails Luiz Capitulino
2014-05-16 15:30 ` [Qemu-devel] [PULL 11/20] tests: " Luiz Capitulino
2014-05-16 15:30 ` [Qemu-devel] [PULL 12/20] qapi: Replace uncommon use of the error API by the common one Luiz Capitulino
2014-05-16 15:30 ` [Qemu-devel] [PULL 13/20] qapi: Show qapi-commands.py invocation in qapi-code-gen.txt Luiz Capitulino
2014-05-16 15:30 ` [Qemu-devel] [PULL 14/20] monitor: Convert sendkey to use command_completion Luiz Capitulino
2014-05-16 15:30 ` [Qemu-devel] [PULL 15/20] monitor: Add chardev-remove command completion Luiz Capitulino
2014-05-16 15:30 ` [Qemu-devel] [PULL 16/20] monitor: Add chardev-add backend argument completion Luiz Capitulino
2014-05-16 15:30 ` [Qemu-devel] [PULL 17/20] monitor: Add set_link arguments completion Luiz Capitulino
2014-05-16 15:30 ` [Qemu-devel] [PULL 18/20] monitor: Add netdev_add type argument completion Luiz Capitulino
2014-05-16 15:30 ` [Qemu-devel] [PULL 19/20] monitor: Add netdev_del id " Luiz Capitulino
2014-05-16 15:30 ` [Qemu-devel] [PULL 20/20] qapi: skip redundant includes Luiz Capitulino
2014-05-19 15:09 ` [Qemu-devel] [PULL 00/20] QMP queue Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1400254235-9435-3-git-send-email-lcapitulino@redhat.com \
--to=lcapitulino@redhat.com \
--cc=anthony@codemonkey.ws \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).