summaryrefslogtreecommitdiffstats
path: root/scripts/qapi
diff options
context:
space:
mode:
authorMarkus Armbruster2020-04-24 10:43:38 +0200
committerMarkus Armbruster2020-04-30 07:26:41 +0200
commit89bf68f933393a1bc0de4d07b59ffa8920da130f (patch)
tree16990310cada8c9e2f6015c37769cf7223a1a01e /scripts/qapi
parentqapi: Disallow qmp_marshal_FOO(NULL, ...) (diff)
downloadqemu-89bf68f933393a1bc0de4d07b59ffa8920da130f.tar.gz
qemu-89bf68f933393a1bc0de4d07b59ffa8920da130f.tar.xz
qemu-89bf68f933393a1bc0de4d07b59ffa8920da130f.zip
qapi: Generate simpler marshalling code when no arguments
When command FOO has no arguments, its generated qmp_marshal_FOO() is a bit confusing. Make it simpler: visit_start_struct(v, NULL, NULL, 0, &err); if (err) { goto out; } - - if (!err) { - visit_check_struct(v, &err); - } + visit_check_struct(v, &err); visit_end_struct(v, NULL); if (err) { goto out; } Signed-off-by: Markus Armbruster <armbru@redhat.com> Message-Id: <20200424084338.26803-16-armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com>
Diffstat (limited to 'scripts/qapi')
-rw-r--r--scripts/qapi/commands.py40
1 files changed, 24 insertions, 16 deletions
diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py
index f545903567..6809b0fb6e 100644
--- a/scripts/qapi/commands.py
+++ b/scripts/qapi/commands.py
@@ -115,14 +115,10 @@ def gen_marshal(name, arg_type, boxed, ret_type):
c_type=ret_type.c_type())
if have_args:
- visit_members = ('visit_type_%s_members(v, &arg, &err);'
- % arg_type.c_name())
ret += mcgen('''
%(c_name)s arg = {0};
''',
c_name=arg_type.c_name())
- else:
- visit_members = ''
ret += mcgen('''
@@ -131,16 +127,27 @@ def gen_marshal(name, arg_type, boxed, ret_type):
if (err) {
goto out;
}
- %(visit_members)s
+''')
+
+ if have_args:
+ ret += mcgen('''
+ visit_type_%(c_arg_type)s_members(v, &arg, &err);
if (!err) {
visit_check_struct(v, &err);
}
+''',
+ c_arg_type=arg_type.c_name())
+ else:
+ ret += mcgen('''
+ visit_check_struct(v, &err);
+''')
+
+ ret += mcgen('''
visit_end_struct(v, NULL);
if (err) {
goto out;
}
-''',
- visit_members=visit_members)
+''')
ret += gen_call(name, arg_type, boxed, ret_type)
@@ -151,20 +158,21 @@ out:
visit_free(v);
''')
- if have_args:
- visit_members = ('visit_type_%s_members(v, &arg, NULL);'
- % arg_type.c_name())
- else:
- visit_members = ''
-
ret += mcgen('''
v = qapi_dealloc_visitor_new();
visit_start_struct(v, NULL, NULL, 0, NULL);
- %(visit_members)s
+''')
+
+ if have_args:
+ ret += mcgen('''
+ visit_type_%(c_arg_type)s_members(v, &arg, NULL);
+''',
+ c_arg_type=arg_type.c_name())
+
+ ret += mcgen('''
visit_end_struct(v, NULL);
visit_free(v);
-''',
- visit_members=visit_members)
+''')
ret += mcgen('''
}