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 v13 08/14] qapi: Shorter visits of optional fields
Date: Fri, 20 Nov 2015 10:24:54 -0700 [thread overview]
Message-ID: <1448040300-968-9-git-send-email-eblake@redhat.com> (raw)
In-Reply-To: <1448040300-968-1-git-send-email-eblake@redhat.com>
For less code, reflect the determined boolean value of an optional
visit back to the caller instead of making the caller read the
boolean after the fact.
The resulting generated code has the following diff:
|- visit_optional(v, &has_fdset_id, "fdset-id");
|- if (has_fdset_id) {
|+ if (visit_optional(v, &has_fdset_id, "fdset-id")) {
| visit_type_int(v, &fdset_id, "fdset-id", &err);
| if (err) {
| goto out;
| }
| }
Signed-off-by: Eric Blake <eblake@redhat.com>
---
v13: no change
v12: split error removal from 'if' compression
v11 (no v10): no change
v9: no change
v8: no change
v7: rebase to no member.c_name()
v6: rebase onto earlier testsuite and gen_err_check() improvements
---
include/qapi/visitor.h | 4 ++--
qapi/qapi-visit-core.c | 3 ++-
scripts/qapi.py | 3 +--
3 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/include/qapi/visitor.h b/include/qapi/visitor.h
index 9be60d4..a14a16d 100644
--- a/include/qapi/visitor.h
+++ b/include/qapi/visitor.h
@@ -41,9 +41,9 @@ void visit_end_list(Visitor *v, Error **errp);
* Check if an optional member @name of an object needs visiting.
* For input visitors, set *@present according to whether the
* corresponding visit_type_*() needs calling; for other visitors,
- * leave *@present unchanged.
+ * leave *@present unchanged. Return *@present for convenience.
*/
-void visit_optional(Visitor *v, bool *present, const char *name);
+bool visit_optional(Visitor *v, bool *present, const char *name);
/**
* Determine the qtype of the item @name in the current object visit.
diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c
index e07d6f9..6d63e40 100644
--- a/qapi/qapi-visit-core.c
+++ b/qapi/qapi-visit-core.c
@@ -73,11 +73,12 @@ void visit_end_union(Visitor *v, bool data_present, Error **errp)
}
}
-void visit_optional(Visitor *v, bool *present, const char *name)
+bool visit_optional(Visitor *v, bool *present, const char *name)
{
if (v->optional) {
v->optional(v, present, name);
}
+ return *present;
}
void visit_get_next_type(Visitor *v, QType *type, bool promote_int,
diff --git a/scripts/qapi.py b/scripts/qapi.py
index fe76a6e..085455b 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -1655,8 +1655,7 @@ 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");
- if (%(prefix)shas_%(c_name)s) {
+ if (visit_optional(v, &%(prefix)shas_%(c_name)s, "%(name)s")) {
''',
prefix=prefix, c_name=c_name(memb.name),
name=memb.name, errp=errparg)
--
2.4.3
next prev parent reply other threads:[~2015-11-20 17:25 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-20 17:24 [Qemu-devel] [PATCH v13 00/14] qapi member collision (post-introspection cleanups, subset D) Eric Blake
2015-11-20 17:24 ` [Qemu-devel] [PATCH v13 01/14] qobject: Simplify QObject Eric Blake
2015-11-26 14:27 ` Markus Armbruster
2015-11-26 15:06 ` Markus Armbruster
2015-11-20 17:24 ` [Qemu-devel] [PATCH v13 02/14] qobject: Rename qtype_code to QType Eric Blake
2015-11-20 17:24 ` [Qemu-devel] [PATCH v13 03/14] qapi: Convert QType into QAPI built-in enum type Eric Blake
2015-11-26 14:51 ` Markus Armbruster
2015-11-27 5:09 ` Eric Blake
2015-11-20 17:24 ` [Qemu-devel] [PATCH v13 04/14] qapi: Simplify visiting of alternate types Eric Blake
2015-11-20 17:24 ` [Qemu-devel] [PATCH v13 05/14] qapi: Inline _make_implicit_tag() Eric Blake
2015-11-20 17:24 ` [Qemu-devel] [PATCH v13 06/14] qapi: Fix alternates that accept 'number' but not 'int' Eric Blake
2015-11-20 17:24 ` [Qemu-devel] [PATCH v13 07/14] qapi: Simplify visits of optional fields Eric Blake
2015-11-20 17:24 ` Eric Blake [this message]
2015-11-20 17:24 ` [Qemu-devel] [PATCH v13 09/14] qapi: Prepare new QAPISchemaMember base class Eric Blake
2015-11-20 17:24 ` [Qemu-devel] [PATCH v13 10/14] qapi: Track enum values by QAPISchemaMember, not string Eric Blake
2015-11-26 16:29 ` Markus Armbruster
2015-11-20 17:24 ` [Qemu-devel] [PATCH v13 11/14] qapi: Populate info['name'] for each entity Eric Blake
2015-11-26 16:46 ` Markus Armbruster
2015-11-20 17:24 ` [Qemu-devel] [PATCH v13 12/14] qapi: Enforce (or whitelist) case conventions on qapi members Eric Blake
2015-11-27 9:03 ` Markus Armbruster
2015-12-01 22:35 ` Eric Blake
2015-12-02 8:20 ` Markus Armbruster
2015-12-02 15:47 ` Eric Blake
2015-11-27 9:42 ` Markus Armbruster
2015-12-01 16:12 ` Eric Blake
2015-12-02 10:55 ` Markus Armbruster
2015-11-20 17:24 ` [Qemu-devel] [PATCH v13 13/14] qapi: Move duplicate collision checks to schema check() Eric Blake
2015-11-20 17:25 ` [Qemu-devel] [PATCH v13 14/14] qapi: Detect base class loops Eric Blake
2015-11-27 9:56 ` [Qemu-devel] [PATCH v13 00/14] qapi member collision (post-introspection cleanups, subset D) Markus Armbruster
2015-12-01 16:28 ` 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=1448040300-968-9-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).