From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.20; helo=mga02.intel.com; envelope-from=yonghong.zhu@intel.com; receiver=edk2-devel@lists.01.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) (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 BA5502116DA3B for ; Mon, 15 Oct 2018 05:45:06 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Oct 2018 05:45:06 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,384,1534834800"; d="scan'208";a="95335774" Received: from shwdeopenpsi168.ccr.corp.intel.com ([10.239.158.127]) by fmsmga002.fm.intel.com with ESMTP; 15 Oct 2018 05:45:05 -0700 From: Yonghong Zhu To: edk2-devel@lists.01.org Cc: zhijufan , Liming Gao Date: Mon, 15 Oct 2018 20:45:03 +0800 Message-Id: <1539607503-8048-1-git-send-email-yonghong.zhu@intel.com> X-Mailer: git-send-email 2.6.1.windows.1 Subject: [Patch] BaseTools: Add check for the string type whether is same X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 15 Oct 2018 12:45:06 -0000 From: zhijufan Relational and equality operators require both operands to be of the same type. Treat the string 'A' and "A" as same type, but for "A" and L"A" are not same type since one is general string, another is unicode string. True:'A'<'B', "A"<"B" 'A'<"B", L'A' Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Zhiju.Fan --- BaseTools/Source/Python/Common/Expression.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/BaseTools/Source/Python/Common/Expression.py b/BaseTools/Source/Python/Common/Expression.py index 78c69fa..84898f7 100644 --- a/BaseTools/Source/Python/Common/Expression.py +++ b/BaseTools/Source/Python/Common/Expression.py @@ -295,12 +295,12 @@ class ValueExpression(BaseExpression): # bitwise and logical operation between number and boolean is allowed pass else: raise BadExpression(ERR_EXPR_TYPE) if isinstance(Oprand1, type('')) and isinstance(Oprand2, type('')): - if (Oprand1.startswith('L"') and not Oprand2.startswith('L"')) or \ - (not Oprand1.startswith('L"') and Oprand2.startswith('L"')): + if ((Oprand1.startswith('L"') or Oprand1.startswith('L')) and (not Oprand2.startswith('L"')) and (not Oprand2.startswith("L'"))) or \ + (((not Oprand1.startswith('L"')) and (not Oprand1.startswith("L'"))) and (Oprand2.startswith('L"') or Oprand2.startswith('L'))): raise BadExpression(ERR_STRING_CMP % (Oprand1, Operator, Oprand2)) if 'in' in Operator and isinstance(Oprand2, type('')): Oprand2 = Oprand2.split() EvalStr = 'Oprand1 ' + Operator + ' Oprand2' @@ -825,10 +825,12 @@ class ValueExpressionEx(ValueExpression): except BadExpression as Value: if self.PcdType in TAB_PCD_NUMERIC_TYPES: PcdValue = PcdValue.strip() if PcdValue.startswith('{') and PcdValue.endswith('}'): PcdValue = SplitPcdValueString(PcdValue[1:-1]) + if ERR_STRING_CMP.split(':')[0] in Value.message: + raise BadExpression("Type: %s, Value: %s, %s" % (self.PcdType, PcdValue, Value)) if isinstance(PcdValue, type([])): TmpValue = 0 Size = 0 ValueType = '' for Item in PcdValue: -- 2.6.1.windows.1