From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34297) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a9U0i-0000fn-7W for qemu-devel@nongnu.org; Thu, 17 Dec 2015 03:34:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a9U0g-0001Gd-3n for qemu-devel@nongnu.org; Thu, 17 Dec 2015 03:34:04 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47101) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a9U0f-0001GF-RQ for qemu-devel@nongnu.org; Thu, 17 Dec 2015 03:34:01 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id 7AD08C00126D for ; Thu, 17 Dec 2015 08:34:01 +0000 (UTC) From: Markus Armbruster Date: Thu, 17 Dec 2015 09:33:40 +0100 Message-Id: <1450341225-2735-36-git-send-email-armbru@redhat.com> In-Reply-To: <1450341225-2735-1-git-send-email-armbru@redhat.com> References: <1450341225-2735-1-git-send-email-armbru@redhat.com> Subject: [Qemu-devel] [PULL 35/40] qapi: Shorter visits of optional fields List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org From: Eric Blake 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 Message-Id: <1449033659-25497-10-git-send-email-eblake@redhat.com> Signed-off-by: Markus Armbruster --- 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 8bf41db..58ecdf2 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -1656,8 +1656,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