aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/qapi-visit.py23
-rw-r--r--scripts/qapi.py46
2 files changed, 22 insertions, 47 deletions
diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
index 4923b2e9dd..5220badf28 100644
--- a/scripts/qapi-visit.py
+++ b/scripts/qapi-visit.py
@@ -51,7 +51,24 @@ void visit_type_%(c_name)s_members(Visitor *v, %(c_name)s *obj, Error **errp)
c_type=base.c_name())
ret += gen_err_check()
- ret += gen_visit_members(members, prefix='obj->')
+ for memb in members:
+ if memb.optional:
+ ret += mcgen('''
+ if (visit_optional(v, "%(name)s", &obj->has_%(c_name)s)) {
+''',
+ name=memb.name, c_name=c_name(memb.name))
+ push_indent()
+ ret += mcgen('''
+ visit_type_%(c_type)s(v, "%(name)s", &obj->%(c_name)s, &err);
+''',
+ c_type=memb.type.c_name(), name=memb.name,
+ c_name=c_name(memb.name))
+ ret += gen_err_check()
+ if memb.optional:
+ pop_indent()
+ ret += mcgen('''
+ }
+''')
if variants:
ret += mcgen('''
@@ -90,8 +107,8 @@ void visit_type_%(c_name)s_members(Visitor *v, %(c_name)s *obj, Error **errp)
}
''')
- # 'goto out' produced for base, by gen_visit_members() for each member,
- # and if variants were present
+ # 'goto out' produced for base, for each member, and if variants were
+ # present
if base or members or variants:
ret += mcgen('''
diff --git a/scripts/qapi.py b/scripts/qapi.py
index 96fb216ce2..3b50e4da79 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -1657,54 +1657,12 @@ def gen_params(arg_type, extra):
return ret
-def gen_err_check(label='out', skiperr=False):
- if skiperr:
- return ''
+def gen_err_check():
return mcgen('''
if (err) {
- goto %(label)s;
- }
-''',
- label=label)
-
-
-def gen_visit_members(members, prefix='', need_cast=False, skiperr=False,
- label='out'):
- ret = ''
- if skiperr:
- errparg = 'NULL'
- else:
- errparg = '&err'
-
- for memb in members:
- if memb.optional:
- ret += mcgen('''
- if (visit_optional(v, "%(name)s", &%(prefix)shas_%(c_name)s)) {
-''',
- prefix=prefix, c_name=c_name(memb.name),
- name=memb.name)
- push_indent()
-
- # Ugly: sometimes we need to cast away const
- if need_cast and memb.type.name == 'str':
- cast = '(char **)'
- else:
- cast = ''
-
- ret += mcgen('''
- visit_type_%(c_type)s(v, "%(name)s", %(cast)s&%(prefix)s%(c_name)s, %(errp)s);
-''',
- c_type=memb.type.c_name(), prefix=prefix, cast=cast,
- c_name=c_name(memb.name), name=memb.name,
- errp=errparg)
- ret += gen_err_check(skiperr=skiperr, label=label)
-
- if memb.optional:
- pop_indent()
- ret += mcgen('''
+ goto out;
}
''')
- return ret
#