From patchwork Fri Oct 18 07:43:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 11197691 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9299A5703 for ; Fri, 18 Oct 2019 07:57:38 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 72EB721897 for ; Fri, 18 Oct 2019 07:57:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 72EB721897 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36126 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iLN8j-0007V1-3E for patchwork-qemu-devel@patchwork.kernel.org; Fri, 18 Oct 2019 03:57:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59512) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iLMvQ-0000SQ-8Y for qemu-devel@nongnu.org; Fri, 18 Oct 2019 03:43:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iLMvO-0007fX-Un for qemu-devel@nongnu.org; Fri, 18 Oct 2019 03:43:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36442) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iLMvO-0007f1-MY for qemu-devel@nongnu.org; Fri, 18 Oct 2019 03:43:50 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E95033E2AF; Fri, 18 Oct 2019 07:43:49 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.36.118.123]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 12D1919C77; Fri, 18 Oct 2019 07:43:47 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 8565F1133034; Fri, 18 Oct 2019 09:43:45 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v2 2/7] qapi: Store pragma state in QAPISourceInfo, not global state Date: Fri, 18 Oct 2019 09:43:40 +0200 Message-Id: <20191018074345.24034-3-armbru@redhat.com> In-Reply-To: <20191018074345.24034-1-armbru@redhat.com> References: <20191018074345.24034-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 18 Oct 2019 07:43:49 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, marcandre.lureau@redhat.com, mdroth@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" The frontend can't be run more than once due to its global state. A future commit will want to do that. Recent commit "qapi: Move context-sensitive checking to the proper place" got rid of many global variables already, but pragma state is still stored in global variables (that's why a pragma directive's scope is the complete schema). Move the pragma state to QAPISourceInfo. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- scripts/qapi/common.py | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index d6e00c80ea..5abab44302 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -21,25 +21,28 @@ import string import sys from collections import OrderedDict -# Are documentation comments required? -doc_required = False - -# Whitelist of commands allowed to return a non-dictionary -returns_whitelist = [] - -# Whitelist of entities allowed to violate case conventions -name_case_whitelist = [] - # # Parsing the schema into expressions # + +class QAPISchemaPragma(object): + def __init__(self): + # Are documentation comments required? + self.doc_required = False + # Whitelist of commands allowed to return a non-dictionary + self.returns_whitelist = [] + # Whitelist of entities allowed to violate case conventions + self.name_case_whitelist = [] + + class QAPISourceInfo(object): def __init__(self, fname, line, parent): self.fname = fname self.line = line self.parent = parent + self.pragma = parent.pragma if parent else QAPISchemaPragma() self.defn_meta = None self.defn_name = None @@ -486,26 +489,25 @@ class QAPISchemaParser(object): return QAPISchemaParser(incl_fname, previously_included, info) def _pragma(self, name, value, info): - global doc_required, returns_whitelist, name_case_whitelist if name == 'doc-required': if not isinstance(value, bool): raise QAPISemError(info, "pragma 'doc-required' must be boolean") - doc_required = value + info.pragma.doc_required = value elif name == 'returns-whitelist': if (not isinstance(value, list) or any([not isinstance(elt, str) for elt in value])): raise QAPISemError( info, "pragma returns-whitelist must be a list of strings") - returns_whitelist = value + info.pragma.returns_whitelist = value elif name == 'name-case-whitelist': if (not isinstance(value, list) or any([not isinstance(elt, str) for elt in value])): raise QAPISemError( info, "pragma name-case-whitelist must be a list of strings") - name_case_whitelist = value + info.pragma.name_case_whitelist = value else: raise QAPISemError(info, "unknown pragma '%s'" % name) @@ -757,7 +759,7 @@ def check_type(value, info, source, raise QAPISemError(info, "%s should be an object or type name" % source) - permit_upper = allow_dict in name_case_whitelist + permit_upper = allow_dict in info.pragma.name_case_whitelist # value is a dictionary, check that each member is okay for (key, arg) in value.items(): @@ -840,7 +842,7 @@ def check_enum(expr, info): if prefix is not None and not isinstance(prefix, str): raise QAPISemError(info, "'prefix' must be a string") - permit_upper = name in name_case_whitelist + permit_upper = name in info.pragma.name_case_whitelist for member in members: source = "'data' member" @@ -968,7 +970,7 @@ def check_exprs(exprs): raise QAPISemError( info, "documentation comment is for '%s'" % doc.symbol) doc.check_expr(expr) - elif doc_required: + elif info.pragma.doc_required: raise QAPISemError(info, "documentation comment required") @@ -1690,7 +1692,7 @@ class QAPISchemaCommand(QAPISchemaEntity): if self._ret_type_name: self.ret_type = schema.resolve_type( self._ret_type_name, self.info, "command's 'returns'") - if self.name not in returns_whitelist: + if self.name not in self.info.pragma.returns_whitelist: if not (isinstance(self.ret_type, QAPISchemaObjectType) or (isinstance(self.ret_type, QAPISchemaArrayType) and isinstance(self.ret_type.element_type,