From: Eric Blake <eblake@redhat.com>
To: qemu-devel@nongnu.org
Cc: armbru@redhat.com, Michael Roth <mdroth@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PATCH v10 04/13] qapi: Drop pointless gotos in generated code
Date: Mon, 15 Feb 2016 17:20:48 -0700 [thread overview]
Message-ID: <1455582057-27565-5-git-send-email-eblake@redhat.com> (raw)
In-Reply-To: <1455582057-27565-1-git-send-email-eblake@redhat.com>
There's no point in emitting a goto if the very next thing
emitted will be the label. A bit of cleverness in gen_visit_fields()
will let us choose when to omit a final error check (basically,
swap the order of emitted text within the loop, with the error
check omitted on the first pass, then checking whether to emit a
final check after the loop); and in turn omit unused labels.
The change to generated code is a bit easier because we split out
the reindentation of the remaining gotos in the previous patch.
For example, in visit_type_ChardevReturn_fields():
| if (visit_optional(v, "pty", &obj->has_pty)) {
| visit_type_str(v, "pty", &obj->pty, &err);
| }
|- if (err) {
|- goto out;
|- }
|-
|-out:
| error_propagate(errp, err);
Signed-off-by: Eric Blake <eblake@redhat.com>
---
v10: new patch
---
scripts/qapi-event.py | 7 +++++--
scripts/qapi-visit.py | 10 ++++++----
scripts/qapi.py | 8 ++++++--
3 files changed, 17 insertions(+), 8 deletions(-)
diff --git a/scripts/qapi-event.py b/scripts/qapi-event.py
index 544ae12..b50ac29 100644
--- a/scripts/qapi-event.py
+++ b/scripts/qapi-event.py
@@ -68,9 +68,12 @@ def gen_event_send(name, arg_type):
name=name)
ret += gen_err_check()
ret += gen_visit_fields(arg_type.members, need_cast=True,
- label='out_obj')
- ret += mcgen('''
+ label='out_obj', skiplast=True)
+ if len(arg_type.members) > 1:
+ ret += mcgen('''
out_obj:
+''')
+ ret += mcgen('''
visit_end_struct(v, err ? NULL : &err);
if (err) {
goto out;
diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
index 0cc9b08..0be396b 100644
--- a/scripts/qapi-visit.py
+++ b/scripts/qapi-visit.py
@@ -92,12 +92,14 @@ static void visit_type_%(c_name)s_fields(Visitor *v, %(c_name)s **obj, Error **e
visit_type_%(c_type)s_fields(v, (%(c_type)s **)obj, &err);
''',
c_type=base.c_name())
- ret += gen_err_check()
+ if members:
+ ret += gen_err_check()
- ret += gen_visit_fields(members, prefix='(*obj)->')
+ ret += gen_visit_fields(members, prefix='(*obj)->', skiplast=True)
- # 'goto out' produced for base, and by gen_visit_fields() for each member
- if base or members:
+ # 'goto out' produced for base, and by gen_visit_fields() for each
+ # member except the last
+ if bool(base) + len(members) > 1:
ret += mcgen('''
out:
diff --git a/scripts/qapi.py b/scripts/qapi.py
index fab5001..4d75d75 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -1645,14 +1645,17 @@ def gen_err_check(label='out', skiperr=False):
def gen_visit_fields(members, prefix='', need_cast=False, skiperr=False,
- label='out'):
+ label='out', skiplast=False):
ret = ''
if skiperr:
errparg = 'NULL'
else:
errparg = '&err'
+ local_skiperr = True
for memb in members:
+ ret += gen_err_check(skiperr=local_skiperr, label=label)
+ local_skiperr = skiperr
if memb.optional:
ret += mcgen('''
if (visit_optional(v, "%(name)s", &%(prefix)shas_%(c_name)s)) {
@@ -1679,8 +1682,9 @@ def gen_visit_fields(members, prefix='', need_cast=False, skiperr=False,
ret += mcgen('''
}
''')
+
+ if members and not skiplast:
ret += gen_err_check(skiperr=skiperr, label=label)
-
return ret
--
2.5.0
next prev parent reply other threads:[~2016-02-16 0:21 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-16 0:20 [Qemu-devel] [PATCH v10 00/13] prune some QAPI visitor cruft (was qapi cleanups subset E) Eric Blake
2016-02-16 0:20 ` [Qemu-devel] [PATCH v10 01/13] qapi: Simplify excess input reporting in input visitors Eric Blake
2016-02-16 0:20 ` [Qemu-devel] [PATCH v10 02/13] qapi: Forbid empty unions and useless alternates Eric Blake
2016-02-16 16:08 ` Markus Armbruster
2016-02-16 23:18 ` Eric Blake
2016-02-16 0:20 ` [Qemu-devel] [PATCH v10 03/13] qapi: Reposition error checks in gen_visit_fields() Eric Blake
2016-02-16 0:20 ` Eric Blake [this message]
2016-02-16 16:27 ` [Qemu-devel] [PATCH v10 04/13] qapi: Drop pointless gotos in generated code Markus Armbruster
2016-02-16 17:14 ` Eric Blake
2016-02-16 0:20 ` [Qemu-devel] [PATCH v10 05/13] qapi-visit: Simplify how we visit common union members Eric Blake
2016-02-16 16:31 ` Markus Armbruster
2016-02-16 17:17 ` Eric Blake
2016-02-16 0:20 ` [Qemu-devel] [PATCH v10 06/13] qapi-visit: Unify struct and union visit Eric Blake
2016-02-16 0:20 ` [Qemu-devel] [PATCH v10 07/13] qapi-visit: Less indirection in visit_type_Foo_fields() Eric Blake
2016-02-16 0:20 ` [Qemu-devel] [PATCH v10 08/13] qapi: Adjust layout of FooList types Eric Blake
2016-02-16 16:55 ` Markus Armbruster
2016-02-16 0:20 ` [Qemu-devel] [PATCH v10 09/13] qapi: Emit structs used as variants in topological order Eric Blake
2016-02-16 17:03 ` Markus Armbruster
2016-02-16 17:32 ` Eric Blake
2016-02-16 21:00 ` Markus Armbruster
2016-02-16 0:20 ` [Qemu-devel] [PATCH v10 10/13] qapi: Don't box struct branch of alternate Eric Blake
2016-02-16 19:07 ` Markus Armbruster
2016-02-16 19:53 ` Eric Blake
2016-02-17 14:40 ` Markus Armbruster
2016-02-17 20:34 ` Eric Blake
2016-02-18 8:21 ` Markus Armbruster
2016-02-16 0:20 ` [Qemu-devel] [PATCH v10 11/13] qapi: Don't box branches of flat unions Eric Blake
2016-02-17 17:44 ` Markus Armbruster
2016-02-17 20:53 ` Eric Blake
2016-02-18 8:51 ` Markus Armbruster
2016-02-18 16:51 ` Eric Blake
2016-02-18 17:11 ` Markus Armbruster
2016-02-16 0:20 ` [Qemu-devel] [PATCH v10 12/13] qapi: Delete unused visit_start_union() Eric Blake
2016-02-17 18:08 ` Markus Armbruster
2016-02-17 21:19 ` Eric Blake
2016-02-18 8:24 ` Markus Armbruster
2016-02-18 16:47 ` Eric Blake
2016-02-16 0:20 ` [Qemu-devel] [PATCH v10 13/13] qapi: Change visit_start_implicit_struct to visit_start_alternate Eric Blake
2016-02-17 18:13 ` Markus Armbruster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1455582057-27565-5-git-send-email-eblake@redhat.com \
--to=eblake@redhat.com \
--cc=armbru@redhat.com \
--cc=mdroth@linux.vnet.ibm.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).