From patchwork Tue Feb 16 00:20:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 8319901 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 D8659C02AA for ; Tue, 16 Feb 2016 00:21:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2E77B20375 for ; Tue, 16 Feb 2016 00:21:18 +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 445B22025A for ; Tue, 16 Feb 2016 00:21:17 +0000 (UTC) Received: from localhost ([::1]:37557 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aVTOG-0006Qh-5M for patchwork-qemu-devel@patchwork.kernel.org; Mon, 15 Feb 2016 19:21:16 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44653) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aVTO5-0006Pw-FE 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 1aVTO3-0002Nv-1k for qemu-devel@nongnu.org; Mon, 15 Feb 2016 19:21:05 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39041) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aVTO2-0002Nl-Qe for qemu-devel@nongnu.org; Mon, 15 Feb 2016 19:21:02 -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 8444AC0C2379; Tue, 16 Feb 2016 00:21:02 +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 u1G0L0sp011124; Mon, 15 Feb 2016 19:21:02 -0500 From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 15 Feb 2016 17:20:48 -0700 Message-Id: <1455582057-27565-5-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 04/13] qapi: Drop pointless gotos in 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 There's no point in emitting a goto if the very next thing emitted will be the label. A bit of cleverness in gen_visit_fields() will let us choose when to omit a final error check (basically, swap the order of emitted text within the loop, with the error check omitted on the first pass, then checking whether to emit a final check after the loop); and in turn omit unused labels. The change to generated code is a bit easier because we split out the reindentation of the remaining gotos in the previous patch. For example, in visit_type_ChardevReturn_fields(): | if (visit_optional(v, "pty", &obj->has_pty)) { | visit_type_str(v, "pty", &obj->pty, &err); | } |- if (err) { |- goto out; |- } |- |-out: | error_propagate(errp, err); Signed-off-by: Eric Blake --- v10: new patch --- scripts/qapi-event.py | 7 +++++-- scripts/qapi-visit.py | 10 ++++++---- scripts/qapi.py | 8 ++++++-- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/scripts/qapi-event.py b/scripts/qapi-event.py index 544ae12..b50ac29 100644 --- a/scripts/qapi-event.py +++ b/scripts/qapi-event.py @@ -68,9 +68,12 @@ def gen_event_send(name, arg_type): name=name) ret += gen_err_check() ret += gen_visit_fields(arg_type.members, need_cast=True, - label='out_obj') - ret += mcgen(''' + label='out_obj', skiplast=True) + if len(arg_type.members) > 1: + ret += mcgen(''' out_obj: +''') + ret += mcgen(''' visit_end_struct(v, err ? NULL : &err); if (err) { goto out; diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py index 0cc9b08..0be396b 100644 --- a/scripts/qapi-visit.py +++ b/scripts/qapi-visit.py @@ -92,12 +92,14 @@ static void visit_type_%(c_name)s_fields(Visitor *v, %(c_name)s **obj, Error **e visit_type_%(c_type)s_fields(v, (%(c_type)s **)obj, &err); ''', c_type=base.c_name()) - ret += gen_err_check() + if members: + ret += gen_err_check() - ret += gen_visit_fields(members, prefix='(*obj)->') + ret += gen_visit_fields(members, prefix='(*obj)->', skiplast=True) - # 'goto out' produced for base, and by gen_visit_fields() for each member - if base or members: + # 'goto out' produced for base, and by gen_visit_fields() for each + # member except the last + if bool(base) + len(members) > 1: ret += mcgen(''' out: diff --git a/scripts/qapi.py b/scripts/qapi.py index fab5001..4d75d75 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -1645,14 +1645,17 @@ def gen_err_check(label='out', skiperr=False): def gen_visit_fields(members, prefix='', need_cast=False, skiperr=False, - label='out'): + label='out', skiplast=False): ret = '' if skiperr: errparg = 'NULL' else: errparg = '&err' + local_skiperr = True for memb in members: + ret += gen_err_check(skiperr=local_skiperr, label=label) + local_skiperr = skiperr if memb.optional: ret += mcgen(''' if (visit_optional(v, "%(name)s", &%(prefix)shas_%(c_name)s)) { @@ -1679,8 +1682,9 @@ def gen_visit_fields(members, prefix='', need_cast=False, skiperr=False, ret += mcgen(''' } ''') + + if members and not skiplast: ret += gen_err_check(skiperr=skiperr, label=label) - return ret