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 RFC v3 09/20] qapi: Use consistent generated code patterns
Date: Tue, 18 Aug 2015 07:19:51 -0700 [thread overview]
Message-ID: <1439907602-11414-10-git-send-email-eblake@redhat.com> (raw)
In-Reply-To: <1439907602-11414-1-git-send-email-eblake@redhat.com>
We had a pointless difference in label names, and on whether
the generated code used:
if (*obj) {
stuff;
...
}
vs.
if (!*obj) {
goto out_obj;
}
stuff;
...
Pick a single style, as it will make it easier for later patches
to uniformly apply any updates to generated code.
No change in semantics to the generated code.
Signed-off-by: Eric Blake <eblake@redhat.com>
---
scripts/qapi-visit.py | 53 ++++++++++++++++++++++++++-------------------------
1 file changed, 27 insertions(+), 26 deletions(-)
diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
index cea0414..58afb2d 100644
--- a/scripts/qapi-visit.py
+++ b/scripts/qapi-visit.py
@@ -208,7 +208,7 @@ void visit_type_%(c_name)s(Visitor *m, %(c_name)s **obj, const char *name, Error
}
visit_get_next_type(m, &(*obj)->type, %(promote_int)s, name, &err);
if (err) {
- goto out_end;
+ goto out_obj;
}
switch ((*obj)->type) {
''',
@@ -229,7 +229,7 @@ void visit_type_%(c_name)s(Visitor *m, %(c_name)s **obj, const char *name, Error
error_setg(&err, QERR_INVALID_PARAMETER_TYPE, name ? name : "null",
"%(name)s");
}
-out_end:
+out_obj:
visit_end_implicit_struct(m, err ? NULL : &err);
out:
error_propagate(errp, err);
@@ -261,33 +261,35 @@ void visit_type_%(c_name)s(Visitor *m, %(c_name)s **obj, const char *name, Error
if (err) {
goto out;
}
- if (*obj) {
+ if (!*obj) {
+ goto out_obj;
+ }
''',
c_name=c_name(name), name=name)
tag_key = variants.tag_member.name
if base:
ret += mcgen('''
- visit_type_%(c_name)s_fields(m, (%(c_name)s **)obj, &err);
- if (err) {
- goto out_obj;
- }
+ visit_type_%(c_name)s_fields(m, (%(c_name)s **)obj, &err);
+ if (err) {
+ goto out_obj;
+ }
''',
c_name=c_name(base.name))
else:
ret += mcgen('''
- visit_type_%(c_type)s(m, &(*obj)->%(c_name)s, "%(name)s", &err);
- if (err) {
- goto out_obj;
- }
+ visit_type_%(c_type)s(m, &(*obj)->%(c_name)s, "%(name)s", &err);
+ if (err) {
+ goto out_obj;
+ }
''',
c_type=variants.tag_member.type.c_name(),
c_name=c_name(tag_key), name=tag_key)
ret += mcgen('''
- if (!visit_start_union(m, !!(*obj)->data, &err) || err) {
- goto out_obj;
- }
- switch ((*obj)->%(c_name)s) {
+ if (!visit_start_union(m, !!(*obj)->data, &err) || err) {
+ goto out_obj;
+ }
+ switch ((*obj)->%(c_name)s) {
''',
c_name=c_name(tag_key))
@@ -295,34 +297,33 @@ void visit_type_%(c_name)s(Visitor *m, %(c_name)s **obj, const char *name, Error
# TODO ugly special case for simple union
simple_union_type = var.simple_union_type()
ret += mcgen('''
- case %(case)s:
+ case %(case)s:
''',
case=c_enum_const(variants.tag_member.type.name, var.name))
if simple_union_type:
ret += mcgen('''
- visit_type_%(c_type)s(m, &(*obj)->%(c_name)s, "data", &err);
+ visit_type_%(c_type)s(m, &(*obj)->%(c_name)s, "data", &err);
''',
c_type=simple_union_type.c_name(),
c_name=c_name(var.name))
else:
ret += mcgen('''
- visit_type_implicit_%(c_type)s(m, &(*obj)->%(c_name)s, &err);
+ visit_type_implicit_%(c_type)s(m, &(*obj)->%(c_name)s, &err);
''',
c_type=var.type.c_name(),
c_name=c_name(var.name))
ret += mcgen('''
- break;
+ break;
''')
ret += mcgen('''
- default:
- abort();
- }
-out_obj:
- error_propagate(errp, err);
- err = NULL;
- visit_end_union(m, !!(*obj)->data, &err);
+ default:
+ abort();
}
+out_obj:
+ error_propagate(errp, err);
+ err = NULL;
+ visit_end_union(m, !!(*obj)->data, &err);
visit_end_struct(m, err ? NULL : &err);
out:
error_propagate(errp, err);
--
2.4.3
next prev parent reply other threads:[~2015-08-18 14:21 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-18 14:19 [Qemu-devel] [PATCH RFC v3 00/20] post-introspection qapi cleanups Eric Blake
2015-08-18 14:19 ` [Qemu-devel] [PATCH RFC v3 01/20] qapi: use 'type' in generated C code to match QMP union wire form Eric Blake
2015-08-18 14:19 ` [Qemu-devel] [PATCH RFC v3 02/20] vnc: hoist allocation of VncBasicInfo to callers Eric Blake
2015-08-18 14:19 ` [Qemu-devel] [PATCH RFC v3 03/20] qapi: Unbox base members Eric Blake
2015-08-18 14:19 ` [Qemu-devel] [PATCH RFC v3 04/20] qapi-visit: Remove redundant functions for flat union base Eric Blake
2015-08-18 14:19 ` [Qemu-devel] [PATCH RFC v3 05/20] qapi: Test use of 'number' within alternates Eric Blake
2015-08-18 14:19 ` [Qemu-devel] [PATCH RFC v3 06/20] qapi: Simplify visiting of alternate types Eric Blake
2015-08-18 14:19 ` [Qemu-devel] [PATCH RFC v3 07/20] qapi: Fix alternates that accept 'number' but not 'int' Eric Blake
2015-08-18 14:19 ` [Qemu-devel] [PATCH RFC v3 08/20] qapi: Don't pass pre-existing error to later call Eric Blake
2015-08-18 14:19 ` Eric Blake [this message]
2015-08-18 14:19 ` [Qemu-devel] [PATCH RFC v3 10/20] qapi: Add tests for empty unions Eric Blake
2015-08-18 14:19 ` [Qemu-devel] [PATCH RFC v3 11/20] qapi: Rework deallocation of partial struct Eric Blake
2015-08-18 16:05 ` [Qemu-devel] [PATCH RFC v3 12/20] qapi: Avoid use of 'data' member of qapi unions Eric Blake
2015-08-18 16:05 ` [Qemu-devel] [PATCH RFC v3 13/20] qapi: Forbid empty unions and useless alternates Eric Blake
2015-08-18 16:05 ` [Qemu-devel] [PATCH RFC v3 14/20] qapi: Drop useless 'data' member of unions Eric Blake
2015-08-18 16:05 ` [Qemu-devel] [PATCH RFC v3 15/20] qapi: Remove dead visitor code Eric Blake
2015-08-18 16:05 ` [Qemu-devel] [PATCH RFC v3 16/20] qapi: Document visitor interfaces Eric Blake
2015-08-18 16:05 ` [Qemu-devel] [PATCH RFC v3 17/20] qapi: Change visit_type_XXX() to no longer return partial objects Eric Blake
2015-08-18 16:05 ` [Qemu-devel] [PATCH RFC v3 18/20] qapi: Plumb in 'box' to qapi generator lower levels Eric Blake
2015-08-18 16:05 ` [Qemu-devel] [PATCH RFC v3 19/20] qapi: Implement boxed structs for commands/events Eric Blake
2015-08-18 16:05 ` [Qemu-devel] [PATCH RFC v3 20/20] qapi: Support boxed unions Eric Blake
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=1439907602-11414-10-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).