From patchwork Fri Mar 18 10:04:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 8617831 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 35E75C0553 for ; Fri, 18 Mar 2016 10:09:09 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7D0392034B for ; Fri, 18 Mar 2016 10:09:08 +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 AA78C2024D for ; Fri, 18 Mar 2016 10:09:07 +0000 (UTC) Received: from localhost ([::1]:42636 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agrL7-0007nL-Nm for patchwork-qemu-devel@patchwork.kernel.org; Fri, 18 Mar 2016 06:09:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53050) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agrGs-0008EM-09 for qemu-devel@nongnu.org; Fri, 18 Mar 2016 06:04:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1agrGl-0001UC-H7 for qemu-devel@nongnu.org; Fri, 18 Mar 2016 06:04:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35478) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agrGl-0001Tz-9B for qemu-devel@nongnu.org; Fri, 18 Mar 2016 06:04:35 -0400 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 EA7EB2191 for ; Fri, 18 Mar 2016 10:04:34 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-34.ams2.redhat.com [10.36.116.34]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u2IA4W5Y027862 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 18 Mar 2016 06:04:33 -0400 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id BAA0B3004F8A; Fri, 18 Mar 2016 11:04:29 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 18 Mar 2016 11:04:23 +0100 Message-Id: <1458295469-22215-10-git-send-email-armbru@redhat.com> In-Reply-To: <1458295469-22215-1-git-send-email-armbru@redhat.com> References: <1458295469-22215-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 09/15] qapi-commands: Inline single-use helpers of gen_marshal() 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 From: Eric Blake Originally, gen_marshal_input_visit() (or gen_visitor_input_block() before commit f1538019) was factored out to make it easy to do two passes of a visit to each member of a (possibly-implicit) object, without duplicating lots of code. But after recent changes, those visits now occupy a single line of emitted code, and the helper method has become a series of conditionals both before and after the one important line, making it rather awkward to see at a glance what gets emitted on the first (parsing) or second (deallocation) pass. It's a lot easier to read the generator code if we just inline both uses directly into gen_marshal(), without all the conditionals. Once we've done that, it's easy to notice that gen_marshal_vars() is used only once, and inlining it too lets us consolidate some mcgen() calls that used to be split across helpers. gen_call() remains a single-use helper function, but it has enough indentation and complexity that inlining it would hamper legibility. No change to generated output. The fact that the diffstat shows a net reduction in lines is an argument in favor of this cleanup. Signed-off-by: Eric Blake Message-Id: <1458254921-17042-10-git-send-email-eblake@redhat.com> Signed-off-by: Markus Armbruster --- scripts/qapi-commands.py | 106 +++++++++++++++++------------------------------ 1 file changed, 39 insertions(+), 67 deletions(-) diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py index 28b9cbe..b570069 100644 --- a/scripts/qapi-commands.py +++ b/scripts/qapi-commands.py @@ -55,68 +55,6 @@ def gen_call(name, arg_type, ret_type): return ret -def gen_marshal_vars(arg_type, ret_type): - ret = mcgen(''' - Error *err = NULL; -''') - - if ret_type: - ret += mcgen(''' - %(c_type)s retval; -''', - c_type=ret_type.c_type()) - - if arg_type and arg_type.members: - ret += mcgen(''' - QmpInputVisitor *qiv = qmp_input_visitor_new_strict(QOBJECT(args)); - QapiDeallocVisitor *qdv; - Visitor *v; - %(c_name)s arg = {0}; - -''', - c_name=arg_type.c_name()) - else: - ret += mcgen(''' - - (void)args; -''') - - return ret - - -def gen_marshal_input_visit(arg_type, dealloc=False): - ret = '' - - if not arg_type or not arg_type.members: - return ret - - if dealloc: - ret += mcgen(''' - qmp_input_visitor_cleanup(qiv); - qdv = qapi_dealloc_visitor_new(); - v = qapi_dealloc_get_visitor(qdv); -''') - errp = 'NULL' - else: - ret += mcgen(''' - v = qmp_input_get_visitor(qiv); -''') - errp = '&err' - - ret += mcgen(''' - visit_type_%(c_name)s_members(v, &arg, %(errp)s); -''', - c_name=arg_type.c_name(), errp=errp) - - if dealloc: - ret += mcgen(''' - qapi_dealloc_visitor_cleanup(qdv); -''') - else: - ret += gen_err_check() - return ret - - def gen_marshal_output(ret_type): return mcgen(''' @@ -165,15 +103,40 @@ def gen_marshal(name, arg_type, ret_type): %(proto)s { + Error *err = NULL; ''', proto=gen_marshal_proto(name)) - ret += gen_marshal_vars(arg_type, ret_type) - ret += gen_marshal_input_visit(arg_type) + if ret_type: + ret += mcgen(''' + %(c_type)s retval; +''', + c_type=ret_type.c_type()) + + if arg_type and arg_type.members: + ret += mcgen(''' + QmpInputVisitor *qiv = qmp_input_visitor_new_strict(QOBJECT(args)); + QapiDeallocVisitor *qdv; + Visitor *v; + %(c_name)s arg = {0}; + + v = qmp_input_get_visitor(qiv); + visit_type_%(c_name)s_members(v, &arg, &err); + if (err) { + goto out; + } +''', + c_name=arg_type.c_name()) + + else: + ret += mcgen(''' + + (void)args; +''') + ret += gen_call(name, arg_type, ret_type) - # 'goto out' produced by gen_marshal_input_visit->gen_visit_members() - # for each arg_type member, and by gen_call() for ret_type + # 'goto out' produced above for arg_type, and by gen_call() for ret_type if (arg_type and arg_type.members) or ret_type: ret += mcgen(''' @@ -182,7 +145,16 @@ out: ret += mcgen(''' error_propagate(errp, err); ''') - ret += gen_marshal_input_visit(arg_type, dealloc=True) + if arg_type and arg_type.members: + ret += mcgen(''' + qmp_input_visitor_cleanup(qiv); + qdv = qapi_dealloc_visitor_new(); + v = qapi_dealloc_get_visitor(qdv); + visit_type_%(c_name)s_members(v, &arg, NULL); + qapi_dealloc_visitor_cleanup(qdv); +''', + c_name=arg_type.c_name()) + ret += mcgen(''' } ''')