qapi: Simplify gen_visit_fields() error handling

Since we have consolidated all generated code to use 'err' as
the name of the local variable for error detection, we can
simplify the decision on whether to skip error detection (useful
for deallocation paths) to be a boolean.

Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1443565276-4535-18-git-send-email-eblake@redhat.com>
[Change to gen_visit_fields() simplified]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
This commit is contained in:
Eric Blake 2015-09-29 16:21:15 -06:00 committed by Markus Armbruster
parent 82ca8e4696
commit 18bdbc3ac8
2 changed files with 11 additions and 13 deletions

View File

@ -101,19 +101,17 @@ def gen_marshal_input_visit(arg_type, dealloc=False):
return ret return ret
if dealloc: if dealloc:
errarg = None
ret += mcgen(''' ret += mcgen('''
qmp_input_visitor_cleanup(qiv); qmp_input_visitor_cleanup(qiv);
qdv = qapi_dealloc_visitor_new(); qdv = qapi_dealloc_visitor_new();
v = qapi_dealloc_get_visitor(qdv); v = qapi_dealloc_get_visitor(qdv);
''') ''')
else: else:
errarg = 'err'
ret += mcgen(''' ret += mcgen('''
v = qmp_input_get_visitor(qiv); v = qmp_input_get_visitor(qiv);
''') ''')
ret += gen_visit_fields(arg_type.members, errarg=errarg) ret += gen_visit_fields(arg_type.members, skiperr=dealloc)
if dealloc: if dealloc:
ret += mcgen(''' ret += mcgen('''

View File

@ -1537,23 +1537,23 @@ def gen_params(arg_type, extra):
return ret return ret
def gen_err_check(err='err', label='out'): def gen_err_check(label='out', skiperr=False):
if not err: if skiperr:
return '' return ''
return mcgen(''' return mcgen('''
if (%(err)s) { if (err) {
goto %(label)s; goto %(label)s;
} }
''', ''',
err=err, label=label) label=label)
def gen_visit_fields(members, prefix='', need_cast=False, errarg='err'): def gen_visit_fields(members, prefix='', need_cast=False, skiperr=False):
ret = '' ret = ''
if errarg: if skiperr:
errparg = '&' + errarg
else:
errparg = 'NULL' errparg = 'NULL'
else:
errparg = '&err'
for memb in members: for memb in members:
if memb.optional: if memb.optional:
@ -1562,7 +1562,7 @@ def gen_visit_fields(members, prefix='', need_cast=False, errarg='err'):
''', ''',
prefix=prefix, c_name=c_name(memb.name), prefix=prefix, c_name=c_name(memb.name),
name=memb.name, errp=errparg) name=memb.name, errp=errparg)
ret += gen_err_check(err=errarg) ret += gen_err_check(skiperr=skiperr)
ret += mcgen(''' ret += mcgen('''
if (%(prefix)shas_%(c_name)s) { if (%(prefix)shas_%(c_name)s) {
''', ''',
@ -1581,7 +1581,7 @@ def gen_visit_fields(members, prefix='', need_cast=False, errarg='err'):
c_type=memb.type.c_name(), prefix=prefix, cast=cast, c_type=memb.type.c_name(), prefix=prefix, cast=cast,
c_name=c_name(memb.name), name=memb.name, c_name=c_name(memb.name), name=memb.name,
errp=errparg) errp=errparg)
ret += gen_err_check(err=errarg) ret += gen_err_check(skiperr=skiperr)
if memb.optional: if memb.optional:
pop_indent() pop_indent()