aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/qapi/commands.py60
-rw-r--r--scripts/qapi/visit.py8
2 files changed, 31 insertions, 37 deletions
diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py
index bc30876..6809b0f 100644
--- a/scripts/qapi/commands.py
+++ b/scripts/qapi/commands.py
@@ -104,6 +104,7 @@ def gen_marshal(name, arg_type, boxed, ret_type):
%(proto)s
{
Error *err = NULL;
+ Visitor *v;
''',
proto=build_marshal_proto(name))
@@ -114,44 +115,38 @@ 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('''
- Visitor *v;
%(c_name)s arg = {0};
-
''',
c_name=arg_type.c_name())
- else:
- visit_members = ''
- ret += mcgen('''
- Visitor *v = NULL;
-
- if (args) {
-''')
- push_indent()
ret += mcgen('''
+
v = qobject_input_visitor_new(QOBJECT(args));
visit_start_struct(v, NULL, NULL, 0, &err);
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)
-
- if not have_args:
- pop_indent()
- ret += mcgen('''
- }
''')
ret += gen_call(name, arg_type, boxed, ret_type)
@@ -163,29 +158,20 @@ out:
visit_free(v);
''')
+ ret += mcgen('''
+ v = qapi_dealloc_visitor_new();
+ visit_start_struct(v, NULL, NULL, 0, NULL);
+''')
+
if have_args:
- visit_members = ('visit_type_%s_members(v, &arg, NULL);'
- % arg_type.c_name())
- else:
- visit_members = ''
ret += mcgen('''
- if (args) {
-''')
- push_indent()
+ visit_type_%(c_arg_type)s_members(v, &arg, NULL);
+''',
+ c_arg_type=arg_type.c_name())
ret += mcgen('''
- v = qapi_dealloc_visitor_new();
- visit_start_struct(v, NULL, NULL, 0, NULL);
- %(visit_members)s
visit_end_struct(v, NULL);
visit_free(v);
-''',
- visit_members=visit_members)
-
- if not have_args:
- pop_indent()
- ret += mcgen('''
- }
''')
ret += mcgen('''
diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py
index 23d9194..d5d7a10 100644
--- a/scripts/qapi/visit.py
+++ b/scripts/qapi/visit.py
@@ -189,6 +189,8 @@ void visit_type_%(c_name)s(Visitor *v, const char *name, %(c_name)s **obj, Error
goto out;
}
if (!*obj) {
+ /* incomplete */
+ assert(visit_is_dealloc(v));
goto out_obj;
}
switch ((*obj)->type) {
@@ -230,8 +232,12 @@ void visit_type_%(c_name)s(Visitor *v, const char *name, %(c_name)s **obj, Error
case QTYPE_NONE:
abort();
default:
+ assert(visit_is_input(v));
error_setg(&err, QERR_INVALID_PARAMETER_TYPE, name ? name : "null",
"%(name)s");
+ /* Avoid passing invalid *obj to qapi_free_%(c_name)s() */
+ g_free(*obj);
+ *obj = NULL;
}
out_obj:
visit_end_alternate(v, (void **)obj);
@@ -260,6 +266,8 @@ void visit_type_%(c_name)s(Visitor *v, const char *name, %(c_name)s **obj, Error
goto out;
}
if (!*obj) {
+ /* incomplete */
+ assert(visit_is_dealloc(v));
goto out_obj;
}
visit_type_%(c_name)s_members(v, *obj, &err);