]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools: Unify long and int in Expression.py
authorGary Lin <glin@suse.com>
Wed, 27 Jun 2018 10:07:56 +0000 (18:07 +0800)
committerYonghong Zhu <yonghong.zhu@intel.com>
Sun, 8 Jul 2018 07:39:57 +0000 (15:39 +0800)
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 <yonghong.zhu@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Signed-off-by: Gary Lin <glin@suse.com>
Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
BaseTools/Source/Python/Common/Expression.py

index e1a2c155b7f3d94afa62997413d8a1f6f6b43480..51e8d2174a8ff2352a342835fb2a140c6349f571 100644 (file)
@@ -20,6 +20,7 @@ from Misc import GuidStringToGuidStructureString, ParseFieldValue, IsFieldValueA
 import Common.EdkLogger as EdkLogger\r
 import copy\r
 from Common.DataType import *\r
+import sys\r
 \r
 ERR_STRING_EXPR         = 'This operator cannot be used in string expression: [%s].'\r
 ERR_SNYTAX              = 'Syntax error, the rest of expression cannot be evaluated: [%s].'\r
@@ -254,7 +255,8 @@ class ValueExpression(BaseExpression):
                 Oprand2 = IntToStr(Oprand2)\r
         TypeDict = {\r
             type(0)  : 0,\r
-            type(0L) : 0,\r
+            # For python2 long type\r
+            type(sys.maxsize + 1) : 0,\r
             type('') : 1,\r
             type(True) : 2\r
         }\r
@@ -892,7 +894,7 @@ class ValueExpressionEx(ValueExpression):
                     raise BadExpression('Type %s PCD Value Size is Larger than 8 byte' % self.PcdType)\r
             else:\r
                 try:\r
-                    TmpValue = long(PcdValue)\r
+                    TmpValue = int(PcdValue)\r
                     TmpList = []\r
                     if TmpValue.bit_length() == 0:\r
                         PcdValue = '{0x00}'\r