From patchwork Thu Feb 18 06:48:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 8346651 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 0627E9F399 for ; Thu, 18 Feb 2016 06:52:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4A50E20386 for ; Thu, 18 Feb 2016 06:52:47 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7C23E20384 for ; Thu, 18 Feb 2016 06:52:46 +0000 (UTC) Received: from localhost ([::1]:37678 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aWISE-0004Ii-0K for patchwork-qemu-devel@patchwork.kernel.org; Thu, 18 Feb 2016 01:52:46 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40216) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aWIOF-0005Mu-Pw for qemu-devel@nongnu.org; Thu, 18 Feb 2016 01:48:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aWIOE-00020P-43 for qemu-devel@nongnu.org; Thu, 18 Feb 2016 01:48:39 -0500 Received: from mx1.redhat.com ([209.132.183.28]:37505) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aWIOD-00020L-Su for qemu-devel@nongnu.org; Thu, 18 Feb 2016 01:48:38 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 7DF6051E; Thu, 18 Feb 2016 06:48:37 +0000 (UTC) Received: from red.redhat.com (ovpn-113-75.phx2.redhat.com [10.3.113.75]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u1I6mXAd023855; Thu, 18 Feb 2016 01:48:37 -0500 From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 17 Feb 2016 23:48:22 -0700 Message-Id: <1455778109-6278-9-git-send-email-eblake@redhat.com> In-Reply-To: <1455778109-6278-1-git-send-email-eblake@redhat.com> References: <1455778109-6278-1-git-send-email-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: armbru@redhat.com, Michael Roth Subject: [Qemu-devel] [PATCH v11 08/15] qapi-visit: Less indirection in visit_type_Foo_fields() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We were passing 'Foo **obj' to the internal helper function, but all uses within the helper were via reads of '*obj'. Refactor things to pass one less level of indirection, by having the callers dereference before calling. For an example of the generated code change: |-static void visit_type_BalloonInfo_fields(Visitor *v, BalloonInfo **obj, Error **errp) |+static void visit_type_BalloonInfo_fields(Visitor *v, BalloonInfo *obj, Error **errp) | { | Error *err = NULL; | |- visit_type_int(v, "actual", &(*obj)->actual, &err); |+ visit_type_int(v, "actual", &obj->actual, &err); | error_propagate(errp, err); | } | |@@ -261,7 +261,7 @@ void visit_type_BalloonInfo(Visitor *v, | if (!*obj) { | goto out_obj; | } |- visit_type_BalloonInfo_fields(v, obj, &err); |+ visit_type_BalloonInfo_fields(v, *obj, &err); | out_obj: The refactoring will also make it easier to reuse the helpers in a future patch when implicit structs are stored directly in the parent struct rather than boxed through a pointer. Signed-off-by: Eric Blake --- v11: rebase to include variants, drop skiplast handling v10: new patch --- scripts/qapi-visit.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py index 4650c5b..231e424 100644 --- a/scripts/qapi-visit.py +++ b/scripts/qapi-visit.py @@ -39,7 +39,7 @@ def gen_visit_fields_decl(typ): if typ.name not in struct_fields_seen: ret += mcgen(''' -static void visit_type_%(c_type)s_fields(Visitor *v, %(c_type)s **obj, Error **errp); +static void visit_type_%(c_type)s_fields(Visitor *v, %(c_type)s *obj, Error **errp); ''', c_type=typ.c_name()) struct_fields_seen.add(typ.name) @@ -61,7 +61,7 @@ static void visit_type_implicit_%(c_type)s(Visitor *v, %(c_type)s **obj, Error * visit_start_implicit_struct(v, (void **)obj, sizeof(%(c_type)s), &err); if (!err) { - visit_type_%(c_type)s_fields(v, obj, errp); + visit_type_%(c_type)s_fields(v, *obj, errp); visit_end_implicit_struct(v); } error_propagate(errp, err); @@ -85,7 +85,7 @@ def gen_visit_struct_fields(name, base, members, variants=None): struct_fields_seen.add(name) ret += mcgen(''' -static void visit_type_%(c_name)s_fields(Visitor *v, %(c_name)s **obj, Error **errp) +static void visit_type_%(c_name)s_fields(Visitor *v, %(c_name)s *obj, Error **errp) { Error *err = NULL; @@ -94,19 +94,19 @@ static void visit_type_%(c_name)s_fields(Visitor *v, %(c_name)s **obj, Error **e if base: ret += mcgen(''' - visit_type_%(c_type)s_fields(v, (%(c_type)s **)obj, &err); + visit_type_%(c_type)s_fields(v, (%(c_type)s *)obj, &err); ''', c_type=base.c_name()) ret += gen_err_check() - ret += gen_visit_fields(members, prefix='(*obj)->') + ret += gen_visit_fields(members, prefix='obj->') if variants: ret += mcgen(''' - if (!visit_start_union(v, !!(*obj)->u.data, &err) || err) { + if (!visit_start_union(v, !!obj->u.data, &err) || err) { goto out; } - switch ((*obj)->%(c_name)s) { + switch (obj->%(c_name)s) { ''', c_name=c_name(variants.tag_member.name)) @@ -121,13 +121,13 @@ static void visit_type_%(c_name)s_fields(Visitor *v, %(c_name)s **obj, Error **e variants.tag_member.type.prefix)) if simple_union_type: ret += mcgen(''' - visit_type_%(c_type)s(v, "data", &(*obj)->u.%(c_name)s, &err); + visit_type_%(c_type)s(v, "data", &obj->u.%(c_name)s, &err); ''', c_type=simple_union_type.c_name(), c_name=c_name(var.name)) else: ret += mcgen(''' - visit_type_implicit_%(c_type)s(v, &(*obj)->u.%(c_name)s, &err); + visit_type_implicit_%(c_type)s(v, &obj->u.%(c_name)s, &err); ''', c_type=var.type.c_name(), c_name=c_name(var.name)) @@ -270,7 +270,7 @@ void visit_type_%(c_name)s(Visitor *v, const char *name, %(c_name)s **obj, Error if (!*obj) { goto out_obj; } - visit_type_%(c_name)s_fields(v, obj, &err); + visit_type_%(c_name)s_fields(v, *obj, &err); error_propagate(errp, err); err = NULL; out_obj: