From patchwork Thu Sep 3 14:30:15 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 514115 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 ozlabs.org (Postfix) with ESMTPS id 00CB1140285 for ; Fri, 4 Sep 2015 00:44:29 +1000 (AEST) Received: from localhost ([::1]:48640 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZXVkZ-0005Vn-7b for incoming@patchwork.ozlabs.org; Thu, 03 Sep 2015 10:44:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33119) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZXVXH-0004UQ-SX for qemu-devel@nongnu.org; Thu, 03 Sep 2015 10:30:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZXVXC-0005hu-Cy for qemu-devel@nongnu.org; Thu, 03 Sep 2015 10:30:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49818) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZXVXB-0005hO-NB for qemu-devel@nongnu.org; Thu, 03 Sep 2015 10:30:38 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id 3A848A444A; Thu, 3 Sep 2015 14:30:37 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-45.ams2.redhat.com [10.36.116.45]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t83EUVO7001711 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 3 Sep 2015 10:30:34 -0400 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 915223011F9B; Thu, 3 Sep 2015 16:30:25 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 3 Sep 2015 16:30:15 +0200 Message-Id: <1441290623-13631-25-git-send-email-armbru@redhat.com> In-Reply-To: <1441290623-13631-1-git-send-email-armbru@redhat.com> References: <1441290623-13631-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: mdroth@linux.vnet.ibm.com Subject: [Qemu-devel] [PATCH RFC v4 24/32] qapi-commands: De-duplicate output marshaling functions 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org gen_marshal_output() uses its parameter name only for name of the generated function. Name it after the type being marshaled instead of its caller, and drop duplicates. Saves 7 copies of qmp_marshal_output_int() in qemu-ga, and one copy of qmp_marshal_output_str() in qemu-system-*. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- docs/qapi-code-gen.txt | 4 ++-- scripts/qapi-commands.py | 17 ++++++++++------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/docs/qapi-code-gen.txt b/docs/qapi-code-gen.txt index 09d15dc..147638f 100644 --- a/docs/qapi-code-gen.txt +++ b/docs/qapi-code-gen.txt @@ -713,7 +713,7 @@ Example: $ cat qapi-generated/example-qmp-marshal.c [Uninteresting stuff omitted...] - static void qmp_marshal_output_my_command(UserDefOne *ret_in, QObject **ret_out, Error **errp) + static void qmp_marshal_output_UserDefOne(UserDefOne *ret_in, QObject **ret_out, Error **errp) { Error *local_err = NULL; QmpOutputVisitor *mo = qmp_output_visitor_new(); @@ -756,7 +756,7 @@ Example: goto out; } - qmp_marshal_output_my_command(retval, ret, &local_err); + qmp_marshal_output_UserDefOne(retval, ret, &local_err); out: error_propagate(errp, local_err); diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py index 5a63db0..7ff7c31 100644 --- a/scripts/qapi-commands.py +++ b/scripts/qapi-commands.py @@ -59,7 +59,7 @@ def gen_call(name, arg_type, ret_type): qmp_marshal_output_%(c_name)s(retval, ret, &local_err); ''', - c_name=c_name(name)) + c_name=ret_type.c_name()) pop_indent() return ret @@ -160,10 +160,10 @@ qapi_dealloc_visitor_cleanup(md); pop_indent() return ret -def gen_marshal_output(name, ret_type): +def gen_marshal_output(ret_type): return mcgen(''' -static void qmp_marshal_output_%(c_cmd_name)s(%(c_type)s ret_in, QObject **ret_out, Error **errp) +static void qmp_marshal_output_%(c_name)s(%(c_type)s ret_in, QObject **ret_out, Error **errp) { Error *local_err = NULL; QmpOutputVisitor *mo = qmp_output_visitor_new(); @@ -186,8 +186,7 @@ out: qapi_dealloc_visitor_cleanup(md); } ''', - c_type=ret_type.c_type(), c_cmd_name=c_name(name), - c_name=ret_type.c_name()) + c_type=ret_type.c_type(), c_name=ret_type.c_name()) def gen_marshal_proto(name): ret = 'void qmp_marshal_%s(QDict *args, QObject **ret, Error **errp)' % c_name(name) @@ -260,21 +259,25 @@ class QAPISchemaGenCommandVisitor(QAPISchemaVisitor): self.decl = None self.defn = None self.regy = None + self.visited_ret_types = None def visit_begin(self, schema): self.decl = '' self.defn = '' self.regy = '' + self.visited_ret_types = set() def visit_end(self): if not middle_mode: self.defn += gen_registry(self.regy) self.regy = None + self.visited_ret_types = None def visit_command(self, name, info, arg_type, ret_type, gen, success_response): if not gen: return self.decl += gen_command_decl(name, arg_type, ret_type) - if ret_type: - self.defn += gen_marshal_output(name, ret_type) + if ret_type and ret_type not in self.visited_ret_types: + self.visited_ret_types.add(ret_type) + self.defn += gen_marshal_output(ret_type) if middle_mode: self.decl += gen_marshal_decl(name) self.defn += gen_marshal(name, arg_type, ret_type)