From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=195.135.221.5; helo=smtp.nue.novell.com; envelope-from=glin@suse.com; receiver=edk2-devel@lists.01.org Received: from smtp.nue.novell.com (smtp.nue.novell.com [195.135.221.5]) (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 75438202E540B for ; Wed, 27 Jun 2018 03:08:19 -0700 (PDT) Received: from localhost.localdomain (unknown.telstraglobal.net [134.159.103.118]) by smtp.nue.novell.com with ESMTP (NOT encrypted); Wed, 27 Jun 2018 12:08:16 +0200 From: Gary Lin To: edk2-devel@lists.01.org Cc: Yonghong Zhu , Liming Gao Date: Wed, 27 Jun 2018 18:07:56 +0800 Message-Id: <20180627100757.3405-3-glin@suse.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180627100757.3405-1-glin@suse.com> References: <20180627100757.3405-1-glin@suse.com> Subject: [PATCH 2/3] BaseTools: Unify long and int in Expression.py X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 27 Jun 2018 10:08:20 -0000 Per PEP237(*), 'long' is unified with 'int' and removed from python3. * To make the script compatible with both python2 and python3, 'type(0L)' is replaced with 'type(sys.maxsize + 1)'. In python2, the number is 'long', while it's 'int' in python3. We can remove the workaround after moving to python3 completely. * long() is replaced with int() since int() returns a long when need. (*) https://www.python.org/dev/peps/pep-0237/ Contributed-under: TianoCore Contribution Agreement 1.1 Cc: Yonghong Zhu Cc: Liming Gao Signed-off-by: Gary Lin --- 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 e1a2c155b7f3..51e8d2174a8f 100644 --- a/BaseTools/Source/Python/Common/Expression.py +++ b/BaseTools/Source/Python/Common/Expression.py @@ -20,6 +20,7 @@ from Misc import GuidStringToGuidStructureString, ParseFieldValue, IsFieldValueA import Common.EdkLogger as EdkLogger import copy from Common.DataType import * +import sys ERR_STRING_EXPR = 'This operator cannot be used in string expression: [%s].' ERR_SNYTAX = 'Syntax error, the rest of expression cannot be evaluated: [%s].' @@ -254,7 +255,8 @@ class ValueExpression(BaseExpression): Oprand2 = IntToStr(Oprand2) TypeDict = { type(0) : 0, - type(0L) : 0, + # For python2 long type + type(sys.maxsize + 1) : 0, type('') : 1, type(True) : 2 } @@ -892,7 +894,7 @@ class ValueExpressionEx(ValueExpression): raise BadExpression('Type %s PCD Value Size is Larger than 8 byte' % self.PcdType) else: try: - TmpValue = long(PcdValue) + TmpValue = int(PcdValue) TmpList = [] if TmpValue.bit_length() == 0: PcdValue = '{0x00}' -- 2.17.1