mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-07-27 04:13:53 -06:00
qapi: Simplify visits of optional fields
None of the visitor callbacks would set an error when testing if an optional field was present; make this part of the interface contract by eliminating the errp argument. The resulting generated code has a nice diff: |- visit_optional(v, &has_fdset_id, "fdset-id", &err); |- if (err) { |- goto out; |- } |+ visit_optional(v, &has_fdset_id, "fdset-id"); | if (has_fdset_id) { | visit_type_int(v, &fdset_id, "fdset-id", &err); | if (err) { | goto out; | } | } Signed-off-by: Eric Blake <eblake@redhat.com> Message-Id: <1449033659-25497-9-git-send-email-eblake@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
This commit is contained in:
parent
d00341af38
commit
5cdc8831a7
7 changed files with 17 additions and 19 deletions
|
@ -1656,15 +1656,11 @@ def gen_visit_fields(members, prefix='', need_cast=False, skiperr=False):
|
|||
for memb in members:
|
||||
if memb.optional:
|
||||
ret += mcgen('''
|
||||
visit_optional(v, &%(prefix)shas_%(c_name)s, "%(name)s", %(errp)s);
|
||||
visit_optional(v, &%(prefix)shas_%(c_name)s, "%(name)s");
|
||||
if (%(prefix)shas_%(c_name)s) {
|
||||
''',
|
||||
prefix=prefix, c_name=c_name(memb.name),
|
||||
name=memb.name, errp=errparg)
|
||||
ret += gen_err_check(skiperr=skiperr)
|
||||
ret += mcgen('''
|
||||
if (%(prefix)shas_%(c_name)s) {
|
||||
''',
|
||||
prefix=prefix, c_name=c_name(memb.name))
|
||||
push_indent()
|
||||
|
||||
# Ugly: sometimes we need to cast away const
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue