From nobody Mon Dec 23 04:44:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1520982710536385.6149945156833; Tue, 13 Mar 2018 16:11:50 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 66050224CCC3B; Tue, 13 Mar 2018 16:05:25 -0700 (PDT) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 68F72224CCC0B for ; Tue, 13 Mar 2018 16:05:23 -0700 (PDT) Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Mar 2018 16:11:45 -0700 Received: from jcarsey-desk1.amr.corp.intel.com ([10.7.159.144]) by orsmga005.jf.intel.com with ESMTP; 13 Mar 2018 16:11:45 -0700 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.65; helo=mga03.intel.com; envelope-from=jaben.carsey@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,466,1515484800"; d="scan'208";a="207954914" From: Jaben Carsey To: edk2-devel@lists.01.org Date: Tue, 13 Mar 2018 16:11:32 -0700 Message-Id: <17f7cfad50a29664b2d2fb8dbb6f32f964e4ebd1.1520982577.git.jaben.carsey@intel.com> X-Mailer: git-send-email 2.16.2.windows.1 In-Reply-To: References: In-Reply-To: References: Subject: [edk2] [PATCH v1 2/5] BaseTools: Expression refactor function X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The function is about C Names, not C Strings. Move the re.compile outside the function call Cc: Yonghong Zhu Cc: Liming Gao Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jaben Carsey --- BaseTools/Source/Python/Common/Expression.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/BaseTools/Source/Python/Common/Expression.py b/BaseTools/Sourc= e/Python/Common/Expression.py index bcb27ec11fd5..c7037dd0d00b 100644 --- a/BaseTools/Source/Python/Common/Expression.py +++ b/BaseTools/Source/Python/Common/Expression.py @@ -40,6 +40,8 @@ ERR_ARRAY_ELE =3D 'This must be HEX value for N= List or Array: [%s].' ERR_EMPTY_EXPR =3D 'Empty expression is not allowed.' ERR_IN_OPERAND =3D 'Macro after IN operator can only be: $(FAMILY= ), $(ARCH), $(TOOL_CHAIN_TAG) and $(TARGET).' =20 +__ValidString =3D re.compile(r'[_a-zA-Z][_0-9a-zA-Z]*$') + ## SplitString # Split string to list according double quote # For example: abc"de\"f"ghi"jkl"mn will be: ['abc', '"de\"f"', 'ghi', '"= jkl"', 'mn'] @@ -117,11 +119,8 @@ def SplitPcdValueString(String): RetList.append(Item) return RetList =20 -def IsValidCString(Str): - ValidString =3D re.compile(r'[_a-zA-Z][_0-9a-zA-Z]*$') - if not ValidString.match(Str): - return False - return True +def IsValidCName(Str): + return True if __ValidString.match(Str) else False =20 def BuildOptionValue(PcdValue, GuidDict): IsArray =3D False @@ -912,7 +911,7 @@ class ValueExpressionEx(ValueExpression): Item =3D Item.strip() if LabelList: for Label in LabelList: - if not IsValidCString(Label): + if not IsValidCName(Label): raise BadExpression('%s is not a v= alid c variable name' % Label) if Label not in LabelDict.keys(): LabelDict[Label] =3D str(LabelOffs= et) --=20 2.16.2.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel