From patchwork Tue Feb 16 00:20:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 8319971 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 6F5E59F399 for ; Tue, 16 Feb 2016 00:25:01 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B8CCC2039C for ; Tue, 16 Feb 2016 00:25:00 +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 E5D4720392 for ; Tue, 16 Feb 2016 00:24:59 +0000 (UTC) Received: from localhost ([::1]:37599 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aVTRr-0004x7-92 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 15 Feb 2016 19:24:59 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44667) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aVTO5-0006Q1-RZ for qemu-devel@nongnu.org; Mon, 15 Feb 2016 19:21:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aVTO4-0002OS-C8 for qemu-devel@nongnu.org; Mon, 15 Feb 2016 19:21:05 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41203) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aVTO4-0002OO-4N for qemu-devel@nongnu.org; Mon, 15 Feb 2016 19:21:04 -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 CC3618F279; Tue, 16 Feb 2016 00:21:03 +0000 (UTC) Received: from red.redhat.com (ovpn-113-167.phx2.redhat.com [10.3.113.167]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u1G0L0ss011124; Mon, 15 Feb 2016 19:21:03 -0500 From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 15 Feb 2016 17:20:51 -0700 Message-Id: <1455582057-27565-8-git-send-email-eblake@redhat.com> In-Reply-To: <1455582057-27565-1-git-send-email-eblake@redhat.com> References: <1455582057-27565-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 v10 07/13] 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 --- v10: new patch --- scripts/qapi-visit.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py index 786fe57..177dfc4 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); @@ -80,7 +80,7 @@ def gen_visit_struct_fields(name, base, members): 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; @@ -89,13 +89,13 @@ 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()) if members: ret += gen_err_check() - ret += gen_visit_fields(members, prefix='(*obj)->', skiplast=True) + ret += gen_visit_fields(members, prefix='obj->', skiplast=True) # 'goto out' produced for base, and by gen_visit_fields() for each # member except the last @@ -232,7 +232,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); ''', c_name=c_name(name)) if variants: