From patchwork Tue Jul 19 11:39:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 9236817 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 941D060574 for ; Tue, 19 Jul 2016 11:40:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8529120265 for ; Tue, 19 Jul 2016 11:40:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7A07626247; Tue, 19 Jul 2016 11:40:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 1EA0520265 for ; Tue, 19 Jul 2016 11:40:25 +0000 (UTC) Received: from localhost ([::1]:54820 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPTNw-0001e9-8K for patchwork-qemu-devel@patchwork.kernel.org; Tue, 19 Jul 2016 07:40:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50897) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPTNK-0001ZG-2s for qemu-devel@nongnu.org; Tue, 19 Jul 2016 07:39:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bPTNH-0001uy-MS for qemu-devel@nongnu.org; Tue, 19 Jul 2016 07:39:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35644) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPTNH-0001ua-EM for qemu-devel@nongnu.org; Tue, 19 Jul 2016 07:39:43 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 04FD47D0EA for ; Tue, 19 Jul 2016 11:39:43 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-35.ams2.redhat.com [10.36.116.35]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u6JBdfKW000777 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 19 Jul 2016 07:39:42 -0400 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 1696B11AD295; Tue, 19 Jul 2016 13:39:38 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Tue, 19 Jul 2016 13:39:31 +0200 Message-Id: <1468928377-20384-10-git-send-email-armbru@redhat.com> In-Reply-To: <1468928377-20384-1-git-send-email-armbru@redhat.com> References: <1468928377-20384-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 19 Jul 2016 11:39:43 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL for-2.7 09/15] qapi-event: Simplify visit of non-implicit data X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 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" X-Virus-Scanned: ClamAV using ClamSMTP From: Eric Blake Commit 7ce106a9 documented why we don't generated a visit_type_FOO() for implicit types; and therefore events with an anonymous type for 'data' have to open-code a visit. Note that the open-coded visit in qapi-event.c is slightly different from what is done in qapi-visit.c for normal types, in part because we don't have to check for *obj being NULL or free things on error. But where the type is not implicit, it is nicer to reuse the normal visit instead of open-coding a duplicate. At the moment, the only event with a non-implicit 'data' is in the testsuite, where test-qapi-event.c changes as follows: |@@ -155,6 +155,7 @@ void qapi_event_send___org_qemu_x_event( | __org_qemu_x_Struct param = { | __org_qemu_x_member1, (char *)__org_qemu_x_member2, has_q_wchar_t, q_wchar_t | }; |+ __org_qemu_x_Struct *arg = ¶m; | | emit = qmp_event_get_func_emit(); | if (!emit) { |@@ -164,16 +165,7 @@ void qapi_event_send___org_qemu_x_event( | qmp = qmp_event_build_dict("__ORG.QEMU_X-EVENT"); | | v = qmp_output_visitor_new(&obj); |- |- visit_start_struct(v, "__ORG.QEMU_X-EVENT", NULL, 0, &err); |- if (err) { |- goto out; |- } |- visit_type___org_qemu_x_Struct_members(v, ¶m, &err); |- if (!err) { |- if (!err) { |- visit_check_struct(v, &err); |- } |- visit_end_struct(v, NULL); |+ visit_type___org_qemu_x_Struct(v, "__ORG.QEMU_X-EVENT", &arg, &err); | if (err) { | goto out; | } Signed-off-by: Eric Blake Message-Id: <1468468228-27827-8-git-send-email-eblake@redhat.com> Reviewed-by: Markus Armbruster Signed-off-by: Markus Armbruster --- scripts/qapi-event.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/scripts/qapi-event.py b/scripts/qapi-event.py index 09c0a2a..b9c6b6e 100644 --- a/scripts/qapi-event.py +++ b/scripts/qapi-event.py @@ -49,6 +49,11 @@ def gen_param_var(typ): }; ''') + if not typ.is_implicit(): + ret += mcgen(''' + %(c_name)s *arg = ¶m; +''', + c_name=typ.c_name()) return ret @@ -91,6 +96,14 @@ def gen_event_send(name, arg_type): if arg_type and not arg_type.is_empty(): ret += mcgen(''' v = qmp_output_visitor_new(&obj); +''') + if not arg_type.is_implicit(): + ret += mcgen(''' + visit_type_%(c_name)s(v, "%(name)s", &arg, &err); +''', + name=name, c_name=arg_type.c_name()) + else: + ret += mcgen(''' visit_start_struct(v, "%(name)s", NULL, 0, &err); if (err) { @@ -101,14 +114,16 @@ def gen_event_send(name, arg_type): visit_check_struct(v, &err); } visit_end_struct(v, NULL); +''', + name=name, c_name=arg_type.c_name()) + ret += mcgen(''' if (err) { goto out; } visit_complete(v, &obj); qdict_put_obj(qmp, "data", obj); -''', - name=name, c_name=arg_type.c_name()) +''') ret += mcgen(''' emit(%(c_enum)s, qmp, &err);