From patchwork Thu Mar 10 00:55:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 8552011 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 942E79F372 for ; Thu, 10 Mar 2016 00:55:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E65DD20259 for ; Thu, 10 Mar 2016 00:55:55 +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 BDEB320211 for ; Thu, 10 Mar 2016 00:55:54 +0000 (UTC) Received: from localhost ([::1]:45348 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1adotN-0000Gn-Rt for patchwork-qemu-devel@patchwork.kernel.org; Wed, 09 Mar 2016 19:55:53 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38979) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1adotE-0000G1-7l for qemu-devel@nongnu.org; Wed, 09 Mar 2016 19:55:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1adotB-00040n-UZ for qemu-devel@nongnu.org; Wed, 09 Mar 2016 19:55:44 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45278) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1adotB-00040X-On for qemu-devel@nongnu.org; Wed, 09 Mar 2016 19:55:41 -0500 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 58587C00FBA0; Thu, 10 Mar 2016 00:55:41 +0000 (UTC) Received: from red.redhat.com (ovpn-113-165.phx2.redhat.com [10.3.113.165]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u2A0tcH2010301; Wed, 9 Mar 2016 19:55:41 -0500 From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 9 Mar 2016 17:55:27 -0700 Message-Id: <1457571335-10938-7-git-send-email-eblake@redhat.com> In-Reply-To: <1457571335-10938-1-git-send-email-eblake@redhat.com> References: <1457571335-10938-1-git-send-email-eblake@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: armbru@redhat.com, Michael Roth Subject: [Qemu-devel] [PATCH v5 06/14] qapi-event: Slightly shrink generated code 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 Slightly rearrange the code in gen_event_send() for less generated output, by initializing 'emit' sooner, deferring an assertion to qdict_put_obj, and dropping a now-unused 'obj' local variable. While at it, document a FIXME related to the potential for a compiler naming collision - if the user ever creates a QAPI event whose name matches 'errp' or one of our local variables (like 'emit'), we'll have to revisit how we generate functions to avoid the problem. |@@ -25,16 +25,13 @@ void qapi_event_send_acpi_device_ost(ACP | { | QDict *qmp; | Error *err = NULL; |- QMPEventFuncEmit emit; |+ QMPEventFuncEmit emit = qmp_event_get_func_emit(); | QmpOutputVisitor *qov; | Visitor *v; |- QObject *obj; | |- emit = qmp_event_get_func_emit(); | if (!emit) { | return; | } |- | qmp = qmp_event_build_dict("ACPI_DEVICE_OST"); | | qov = qmp_output_visitor_new(); |@@ -53,11 +50,7 @@ out_obj: | if (err) { | goto out; | } |- |- obj = qmp_output_get_qobject(qov); |- g_assert(obj); |- |- qdict_put_obj(qmp, "data", obj); |+ qdict_put_obj(qmp, "data", qmp_output_get_qobject(qov)); | emit(QAPI_EVENT_ACPI_DEVICE_OST, qmp, &err); | | out: Signed-off-by: Eric Blake --- v5: new patch --- scripts/qapi-event.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/scripts/qapi-event.py b/scripts/qapi-event.py index c03cb78..02c9556 100644 --- a/scripts/qapi-event.py +++ b/scripts/qapi-event.py @@ -29,13 +29,19 @@ def gen_event_send_decl(name, arg_type): def gen_event_send(name, arg_type): + # FIXME: Our declaration of local variables (and of 'errp' in the + # parameter list) can collide with exploded members of the event's + # data type passed in as parameters. If this collision ever hits in + # practice, we can rename our local variables with a leading _ prefix, + # or split the code into a wrapper function that creates a boxed + # 'param' object then calls another to do the real work. ret = mcgen(''' %(proto)s { QDict *qmp; Error *err = NULL; - QMPEventFuncEmit emit; + QMPEventFuncEmit emit = qmp_event_get_func_emit(); ''', proto=gen_event_send_proto(name, arg_type)) @@ -43,16 +49,13 @@ def gen_event_send(name, arg_type): ret += mcgen(''' QmpOutputVisitor *qov; Visitor *v; - QObject *obj; - ''') ret += mcgen(''' - emit = qmp_event_get_func_emit(); + if (!emit) { return; } - qmp = qmp_event_build_dict("%(name)s"); ''', @@ -76,11 +79,7 @@ out_obj: if (err) { goto out; } - - obj = qmp_output_get_qobject(qov); - g_assert(obj); - - qdict_put_obj(qmp, "data", obj); + qdict_put_obj(qmp, "data", qmp_output_get_qobject(qov)); ''') ret += mcgen('''