From patchwork Tue Aug 4 09:17:52 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 503430 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 2B30E14028E for ; Tue, 4 Aug 2015 19:21:22 +1000 (AEST) Received: from localhost ([::1]:34174 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZMYPQ-0000bf-2i for incoming@patchwork.ozlabs.org; Tue, 04 Aug 2015 05:21:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59465) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZMYMc-00041b-Bm for qemu-devel@nongnu.org; Tue, 04 Aug 2015 05:18:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZMYMV-00071y-Jx for qemu-devel@nongnu.org; Tue, 04 Aug 2015 05:18:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57547) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZMYMV-0006vu-5x for qemu-devel@nongnu.org; Tue, 04 Aug 2015 05:18:19 -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 D6587461D2; Tue, 4 Aug 2015 09:18:18 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-31.ams2.redhat.com [10.36.116.31]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t749IGFd031125 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 4 Aug 2015 05:18:18 -0400 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 6BE3F3001877; Tue, 4 Aug 2015 11:18:16 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Tue, 4 Aug 2015 11:17:52 +0200 Message-Id: <1438679896-5077-3-git-send-email-armbru@redhat.com> In-Reply-To: <1438679896-5077-1-git-send-email-armbru@redhat.com> References: <1438679896-5077-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 02/26] qapi: Clean up cgen() and mcgen() 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 Commit 05dfb26 added eatspace stripping to mcgen(). Move it to cgen(), just in case somebody gets tempted to use cgen() directly instead of via mcgen(). cgen() indents blank lines. No such lines get generated right now, but fix it anyway. We use triple-quoted strings for program text, like this: ''' Program text any number of lines ''' Keeps the program text relatively readable, but puts an extra newline at either end. mcgen() "fixes" that by dropping the first and last line outright. Drop only the newlines. This unmasks a bug in qapi-commands.py: four quotes instead of three. Fix it up. Output doesn't change Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- scripts/qapi-commands.py | 2 +- scripts/qapi.py | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py index ca22acc..ce51408 100644 --- a/scripts/qapi-commands.py +++ b/scripts/qapi-commands.py @@ -56,7 +56,7 @@ def gen_sync_call(name, args, ret_type, indent=0): name=c_name(name), args=arglist, retval=retval).rstrip() if ret_type: ret += "\n" + gen_err_check('local_err') - ret += "\n" + mcgen('''' + ret += "\n" + mcgen(''' %(marshal_output_call)s ''', marshal_output_call=gen_marshal_output_call(name, ret_type)).rstrip() diff --git a/scripts/qapi.py b/scripts/qapi.py index 06d7fc2..20383ef 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -943,16 +943,21 @@ def pop_indent(indent_amount=4): global indent_level indent_level -= indent_amount +# Generate @code with @kwds interpolated. +# Obey indent_level, and strip eatspace. def cgen(code, **kwds): - indent = genindent(indent_level) - lines = code.split('\n') - lines = map(lambda x: indent + x, lines) - return '\n'.join(lines) % kwds + '\n' - -def mcgen(code, **kwds): - raw = cgen('\n'.join(code.split('\n')[1:-1]), **kwds) + raw = code % kwds + if indent_level: + indent = genindent(indent_level) + raw = re.subn("^.", indent + '\g<0>', raw, 0, re.MULTILINE) + raw = raw[0] return re.sub(re.escape(eatspace) + ' *', '', raw) +def mcgen(code, **kwds): + if code[0] == '\n': + code = code[1:] + return cgen(code, **kwds) + def basename(filename): return filename.split("/")[-1]