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>
---
BaseTools/Source/Python/AutoGen/GenC.py | 5 +----
BaseTools/Source/Python/Common/Expression.py | 4 ++--
BaseTools/Source/Python/GenFds/FdfParser.py | 5 +----
BaseTools/Source/Python/PatchPcdValue/PatchPcdValue.py | 10 ++--------
4 files changed, 6 insertions(+), 18 deletions(-)
diff --git a/BaseTools/Source/Python/AutoGen/GenC.py b/BaseTools/Source/Python/AutoGen/GenC.py
index 481c4dda1447..211b27e6997c 100644
--- a/BaseTools/Source/Python/AutoGen/GenC.py
+++ b/BaseTools/Source/Python/AutoGen/GenC.py
@@ -1032,10 +1032,7 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
try:
if Value.upper().endswith('L'):
Value = Value[:-1]
- if Value.upper().startswith('0X'):
- ValueNumber = int (Value, 16)
- else:
- ValueNumber = int (Value)
+ ValueNumber = int (Value, 0)
except:
EdkLogger.error("build", AUTOGEN_ERROR,
"PCD value is not valid dec or hex number for datum type [%s] of PCD %s.%s" % (Pcd.DatumType, Pcd.TokenSpaceGuidCName, TokenCName),
diff --git a/BaseTools/Source/Python/Common/Expression.py b/BaseTools/Source/Python/Common/Expression.py
index 4f0f377f3788..4a3dea1190b2 100644
--- a/BaseTools/Source/Python/Common/Expression.py
+++ b/BaseTools/Source/Python/Common/Expression.py
@@ -845,7 +845,7 @@ class ValueExpressionEx(ValueExpression):
if ItemSize == 0:
try:
- tmpValue = int(Item, 16) if Item.upper().startswith('0X') else int(Item, 0)
+ tmpValue = int(Item, 0)
if tmpValue > 255:
raise BadExpression("Byte array number %s should less than 0xFF." % Item)
except BadExpression, Value:
@@ -857,7 +857,7 @@ class ValueExpressionEx(ValueExpression):
ItemValue = ParseFieldValue(Item)[0]
if type(ItemValue) == type(''):
- ItemValue = int(ItemValue, 16) if ItemValue.startswith('0x') else int(ItemValue)
+ ItemValue = int(ItemValue, 0)
TmpValue = (ItemValue << (Size * 8)) | TmpValue
Size = Size + ItemSize
diff --git a/BaseTools/Source/Python/GenFds/FdfParser.py b/BaseTools/Source/Python/GenFds/FdfParser.py
index e35057931f03..bf78baac2185 100644
--- a/BaseTools/Source/Python/GenFds/FdfParser.py
+++ b/BaseTools/Source/Python/GenFds/FdfParser.py
@@ -1145,10 +1145,7 @@ class FdfParser:
if Scope in ['UINT64', 'UINT8']:
ValueNumber = 0
try:
- if Value.upper().startswith('0X'):
- ValueNumber = int (Value, 16)
- else:
- ValueNumber = int (Value)
+ ValueNumber = int (Value, 0)
except:
EdkLogger.error("FdfParser", FORMAT_INVALID, "The value is not valid dec or hex number for %s." % Name)
if ValueNumber < 0:
diff --git a/BaseTools/Source/Python/PatchPcdValue/PatchPcdValue.py b/BaseTools/Source/Python/PatchPcdValue/PatchPcdValue.py
index 942ba88d200f..3db480d0cdc6 100644
--- a/BaseTools/Source/Python/PatchPcdValue/PatchPcdValue.py
+++ b/BaseTools/Source/Python/PatchPcdValue/PatchPcdValue.py
@@ -110,10 +110,7 @@ def PatchBinaryFile(FileName, ValueOffset, TypeName, ValueString, MaxSize=0):
ValueNumber = 1
elif ValueString == 'FALSE':
ValueNumber = 0
- elif ValueString.startswith('0X'):
- ValueNumber = int (ValueString, 16)
- else:
- ValueNumber = int (ValueString)
+ ValueNumber = int (ValueString, 0)
if ValueNumber != 0:
ValueNumber = 1
except:
@@ -127,10 +124,7 @@ def PatchBinaryFile(FileName, ValueOffset, TypeName, ValueString, MaxSize=0):
# Get PCD value for UINT* data type
#
try:
- if ValueString.startswith('0X'):
- ValueNumber = int (ValueString, 16)
- else:
- ValueNumber = int (ValueString)
+ ValueNumber = int (ValueString, 0)
except:
return PARAMETER_INVALID, "PCD Value %s is not valid dec or hex string." % (ValueString)
#
--
2.16.2.windows.1
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
© 2016 - 2025 Red Hat, Inc.