BaseTools: no need to do int() API work for it
authorCarsey, Jaben </o=Intel/ou=Americas01/cn=Workers/cn=Carsey, Jaben>
Thu, 29 Mar 2018 00:02:17 +0000 (08:02 +0800)
committerYonghong Zhu <yonghong.zhu@intel.com>
Fri, 30 Mar 2018 01:16:01 +0000 (09:16 +0800)
int() with base=0 will already auto determine base from preceeding 0x/0X

Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
BaseTools/Source/Python/AutoGen/GenC.py
BaseTools/Source/Python/Common/Expression.py
BaseTools/Source/Python/GenFds/FdfParser.py
BaseTools/Source/Python/PatchPcdValue/PatchPcdValue.py

index cca6c8ab4fb57d77c2b157780e5888c46cf95124..4d9ea1b2a8b1a1aff786b67ccd477c4e86b31ee2 100644 (file)
@@ -1032,10 +1032,7 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
             try:\r
                 if Value.upper().endswith('L'):\r
                     Value = Value[:-1]\r
-                if Value.upper().startswith('0X'):\r
-                    ValueNumber = int (Value, 16)\r
-                else:\r
-                    ValueNumber = int (Value)\r
+                ValueNumber = int (Value, 0)\r
             except:\r
                 EdkLogger.error("build", AUTOGEN_ERROR,\r
                                 "PCD value is not valid dec or hex number for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),\r
index 9a844b0417f203fd6c26a95fe283e81a56a2f1c3..8e1a9866e1eadd3b8de664450861b0822a4f01fc 100644 (file)
@@ -845,7 +845,7 @@ class ValueExpressionEx(ValueExpression):
 \r
                         if ItemSize == 0:\r
                             try:\r
-                                tmpValue = int(Item, 16) if Item.upper().startswith('0X') else int(Item, 0)\r
+                                tmpValue = int(Item, 0)\r
                                 if tmpValue > 255:\r
                                     raise BadExpression("Byte  array number %s should less than 0xFF." % Item)\r
                             except BadExpression, Value:\r
@@ -857,7 +857,7 @@ class ValueExpressionEx(ValueExpression):
                             ItemValue = ParseFieldValue(Item)[0]\r
 \r
                         if type(ItemValue) == type(''):\r
-                            ItemValue = int(ItemValue, 16) if ItemValue.startswith('0x') else int(ItemValue)\r
+                            ItemValue = int(ItemValue, 0)\r
 \r
                         TmpValue = (ItemValue << (Size * 8)) | TmpValue\r
                         Size = Size + ItemSize\r
index 8a894f1528165c38638746fcdccc524552a0077f..346f4eeb0308fa050379d18668fad05eec119309 100644 (file)
@@ -1146,10 +1146,7 @@ class FdfParser:
         if Scope in ['UINT64', 'UINT8']:\r
             ValueNumber = 0\r
             try:\r
-                if Value.upper().startswith('0X'):\r
-                    ValueNumber = int (Value, 16)\r
-                else:\r
-                    ValueNumber = int (Value)\r
+                ValueNumber = int (Value, 0)\r
             except:\r
                 EdkLogger.error("FdfParser", FORMAT_INVALID, "The value is not valid dec or hex number for %s." % Name)\r
             if ValueNumber < 0:\r
index 0c8009cb0b44840305a50f57494da1d0963f067d..0664d6a90fa14ca9a11dadfd644698aa55816467 100644 (file)
@@ -110,10 +110,7 @@ def PatchBinaryFile(FileName, ValueOffset, TypeName, ValueString, MaxSize=0):
                 ValueNumber = 1\r
             elif ValueString == 'FALSE':\r
                 ValueNumber = 0\r
-            elif ValueString.startswith('0X'):\r
-                ValueNumber = int (ValueString, 16)\r
-            else:\r
-                ValueNumber = int (ValueString)\r
+            ValueNumber = int (ValueString, 0)\r
             if ValueNumber != 0:\r
                 ValueNumber = 1\r
         except:\r
@@ -127,10 +124,7 @@ def PatchBinaryFile(FileName, ValueOffset, TypeName, ValueString, MaxSize=0):
         # Get PCD value for UINT* data type\r
         #\r
         try:\r
-            if ValueString.startswith('0X'):\r
-                ValueNumber = int (ValueString, 16)\r
-            else:\r
-                ValueNumber = int (ValueString)\r
+            ValueNumber = int (ValueString, 0)\r
         except:\r
             return PARAMETER_INVALID, "PCD Value %s is not valid dec or hex string." % (ValueString)\r
         #\r