From patchwork Tue Mar 14 08:28:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 9622739 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 5E81960424 for ; Tue, 14 Mar 2017 08:29:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4BA462837F for ; Tue, 14 Mar 2017 08:29:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3EFDD284DC; Tue, 14 Mar 2017 08:29:16 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 D1A2E2837F for ; Tue, 14 Mar 2017 08:29:15 +0000 (UTC) Received: from localhost ([::1]:57075 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnhpS-0005Is-VA for patchwork-qemu-devel@patchwork.kernel.org; Tue, 14 Mar 2017 04:29:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45436) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnhp6-0005Ec-W6 for qemu-devel@nongnu.org; Tue, 14 Mar 2017 04:28:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cnhp5-0000x8-KC for qemu-devel@nongnu.org; Tue, 14 Mar 2017 04:28:53 -0400 Received: from mail-lf0-x241.google.com ([2a00:1450:4010:c07::241]:36374) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cnhp5-0000ww-8B for qemu-devel@nongnu.org; Tue, 14 Mar 2017 04:28:51 -0400 Received: by mail-lf0-x241.google.com with SMTP id g70so13507200lfh.3 for ; Tue, 14 Mar 2017 01:28:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=O59WFg2UkP6GGMgmbU4xKkJQU29ymNixFD6qSsyIkj8=; b=kCiPfvWWpmpW9273bCC6RonGe3DSsnMHKHe5+Za/kkFBYdr+0bbcXgbQXw84yzsyxm i+x5XN0bwIdXd/96m/NLk1ZXw68ibJ/h0eFdMegWmOu+AVP5/xteA4+oQGe2dEhTqRdh vPZL8cHoSFXYnOqco0JAxyJPWN1OuuXPX8xYdSXMpor5ehxEdfMl3NlXyKND00+xGpJ3 UN8U5LGx5BRUZVEIV7J1zvUWLbaMLRSxSfJNqpuw89SS17uODe4uzt9PYaHFIaqOLXdJ 6mR5LHGB+Zo6Yp2xWO30VJI7cVjGM0OIrdqoF6ccgJCATiMMBzUkrgnGvNHS6aqtNzq3 y30A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=O59WFg2UkP6GGMgmbU4xKkJQU29ymNixFD6qSsyIkj8=; b=DNtKj3G2TCQi0zEQ8wDZ/HkEa1GbBAdg9F3kmWRfZr31K414iRV8zp1yjDbOD6V7m3 dUCWinx5WUTRAkzlnasTkuwNgve8Hbsmdw582BR7lLxEdzrlYecfkE0mMouUcjL5zhlg 2ralnVUbfgVGEqKFGdfLcdjIo8zKy7im82pZQpa/VAuv4+jynSDaF92a/e56GnTcsT50 3bNYNCJxiCS+HGaXEQADecQhRmNaOEhDuHo9wmJmxQdj0uQiMgaI8NdUlUKWvqNo93RX AwbvFFLPH+up/Cj+Ru8rexOK+irnpDW1SCsqNV5ySmki3wG7qqxr7lpI9U++lJm9JfuV DuOA== X-Gm-Message-State: AMke39lLHGjY5e2UuBQ318wwhqTVAyG2sYqXyuh9L+SkTrBUAeqLvf+rm3K8RMt6oPOhPuvnucNX6rZj6I0hDw== X-Received: by 10.46.5.148 with SMTP id 142mr12027874ljf.46.1489480130047; Tue, 14 Mar 2017 01:28:50 -0700 (PDT) MIME-Version: 1.0 References: <1489385927-6735-1-git-send-email-armbru@redhat.com> <1489385927-6735-2-git-send-email-armbru@redhat.com> In-Reply-To: <1489385927-6735-2-git-send-email-armbru@redhat.com> From: =?UTF-8?B?TWFyYy1BbmRyw6kgTHVyZWF1?= Date: Tue, 14 Mar 2017 08:28:39 +0000 Message-ID: To: Markus Armbruster , qemu-devel@nongnu.org X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:4010:c07::241 X-Content-Filtered-By: Mailman/MimeDel 2.1.21 Subject: Re: [Qemu-devel] [PATCH for-2.9 01/47] qapi: Factor QAPISchemaParser._include() out of .__init__() 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: , Cc: mdroth@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP On Mon, Mar 13, 2017 at 10:20 AM Markus Armbruster wrote: Signed-off-by: Markus Armbruster Reviewed-by: Marc-André Lureau --- scripts/qapi.py | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) expr_elem = {'expr': expr, 'info': info} @@ -307,6 +288,26 @@ class QAPISchemaParser(object): self.exprs.append(expr_elem) + def _include(self, include, info, base_dir, previously_included): + incl_abs_fname = os.path.join(base_dir, include) + # catch inclusion cycle + inf = info + while inf: + if incl_abs_fname == os.path.abspath(inf['file']): + raise QAPISemError(info, "Inclusion loop for %s" % include) + inf = inf['parent'] + + # skip multiple include of the same file + if incl_abs_fname in previously_included: + return + try: + fobj = open(incl_abs_fname, 'r') + except IOError as e: + raise QAPISemError(info, '%s: %s' % (e.strerror, include)) + exprs_include = QAPISchemaParser(fobj, previously_included, info) + self.exprs.extend(exprs_include.exprs) + self.docs.extend(exprs_include.docs) + def accept(self, skip_comment=True): while True: self.tok = self.src[self.cursor] -- 2.7.4 diff --git a/scripts/qapi.py b/scripts/qapi.py index 53a4477..345cde1 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -268,34 +268,15 @@ class QAPISchemaParser(object): continue expr = self.get_expr(False) - if isinstance(expr, dict) and "include" in expr: + if 'include' in expr: if len(expr) != 1: raise QAPISemError(info, "Invalid 'include' directive") include = expr["include"] if not isinstance(include, str): raise QAPISemError(info, "Value of 'include' must be a string") - incl_abs_fname = os.path.join(os.path.dirname(abs_fname), - include) - # catch inclusion cycle - inf = info - while inf: - if incl_abs_fname == os.path.abspath(inf['file']): - raise QAPISemError(info, "Inclusion loop for %s" - % include) - inf = inf['parent'] - - # skip multiple include of the same file - if incl_abs_fname in previously_included: - continue - try: - fobj = open(incl_abs_fname, 'r') - except IOError as e: - raise QAPISemError(info, '%s: %s' % (e.strerror, include)) - exprs_include = QAPISchemaParser(fobj, previously_included, - info) - self.exprs.extend(exprs_include.exprs) - self.docs.extend(exprs_include.docs) + self._include(include, info, os.path.dirname(abs_fname), + previously_included) else: