diff options
author | Eric Blake <eblake@redhat.com> | 2015-09-29 16:21:15 -0600 |
---|---|---|
committer | Markus Armbruster <armbru@redhat.com> | 2015-10-12 18:46:50 +0200 |
commit | 18bdbc3ac8b477e160d56aa6ecd6942495ce44d0 (patch) | |
tree | c1d186eb113f2da856120c7880574df34efca228 | |
parent | 82ca8e469666b169ccf818a0e36136aee97d7db0 (diff) |
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>
-rw-r--r-- | scripts/qapi-commands.py | 4 | ||||
-rw-r--r-- | scripts/qapi.py | 20 |
2 files changed, 11 insertions, 13 deletions
diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py index 9d214a6609..43a893b4eb 100644 --- a/scripts/qapi-commands.py +++ b/scripts/qapi-commands.py @@ -101,19 +101,17 @@ def gen_marshal_input_visit(arg_type, dealloc=False): return ret if dealloc: - errarg = None ret += mcgen(''' qmp_input_visitor_cleanup(qiv); qdv = qapi_dealloc_visitor_new(); v = qapi_dealloc_get_visitor(qdv); ''') else: - errarg = 'err' ret += mcgen(''' 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: ret += mcgen(''' diff --git a/scripts/qapi.py b/scripts/qapi.py index ada6380db2..26cff3f05c 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -1537,23 +1537,23 @@ def gen_params(arg_type, extra): return ret -def gen_err_check(err='err', label='out'): - if not err: +def gen_err_check(label='out', skiperr=False): + if skiperr: return '' return mcgen(''' - if (%(err)s) { + if (err) { 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 = '' - if errarg: - errparg = '&' + errarg - else: + if skiperr: errparg = 'NULL' + else: + errparg = '&err' for memb in members: 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), name=memb.name, errp=errparg) - ret += gen_err_check(err=errarg) + ret += gen_err_check(skiperr=skiperr) ret += mcgen(''' 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_name=c_name(memb.name), name=memb.name, errp=errparg) - ret += gen_err_check(err=errarg) + ret += gen_err_check(skiperr=skiperr) if memb.optional: pop_indent() |