From nobody Sun Jul 13 09:45:45 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 152228175696788.27377215032448; Wed, 28 Mar 2018 17:02:36 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id CBE60224DD141; Wed, 28 Mar 2018 16:55:47 -0700 (PDT) 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 56BF5224DD131 for ; Wed, 28 Mar 2018 16:55:44 -0700 (PDT) Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Mar 2018 17:02:22 -0700 Received: from jcarsey-desk1.amr.corp.intel.com ([10.7.159.144]) by orsmga007.jf.intel.com with ESMTP; 28 Mar 2018 17:02:22 -0700 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.20; helo=mga02.intel.com; envelope-from=jaben.carsey@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,374,1517904000"; d="scan'208";a="28916589" From: Jaben Carsey To: edk2-devel@lists.01.org Date: Wed, 28 Mar 2018 17:02:17 -0700 Message-Id: <7ccb2126413f14091a86381bcdecc8b1938c5b68.1522281624.git.jaben.carsey@intel.com> X-Mailer: git-send-email 2.16.2.windows.1 In-Reply-To: References: In-Reply-To: References: Subject: [edk2] [PATCH v1 1/4] BaseTools: no need to do int() API work for it 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: , Cc: Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" int() with base=3D0 will already auto determine base from preceeding 0x/0X Cc: Yonghong Zhu Cc: Liming Gao Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jaben Carsey --- 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/Pyt= hon/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, Pc= d): try: if Value.upper().endswith('L'): Value =3D Value[:-1] - if Value.upper().startswith('0X'): - ValueNumber =3D int (Value, 16) - else: - ValueNumber =3D int (Value) + ValueNumber =3D 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/Sourc= e/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): =20 if ItemSize =3D=3D 0: try: - tmpValue =3D int(Item, 16) if Item.upper()= .startswith('0X') else int(Item, 0) + tmpValue =3D int(Item, 0) if tmpValue > 255: raise BadExpression("Byte array numbe= r %s should less than 0xFF." % Item) except BadExpression, Value: @@ -857,7 +857,7 @@ class ValueExpressionEx(ValueExpression): ItemValue =3D ParseFieldValue(Item)[0] =20 if type(ItemValue) =3D=3D type(''): - ItemValue =3D int(ItemValue, 16) if ItemValue.= startswith('0x') else int(ItemValue) + ItemValue =3D int(ItemValue, 0) =20 TmpValue =3D (ItemValue << (Size * 8)) | TmpValue Size =3D 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 =3D 0 try: - if Value.upper().startswith('0X'): - ValueNumber =3D int (Value, 16) - else: - ValueNumber =3D int (Value) + ValueNumber =3D 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/BaseT= ools/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, V= alueString, MaxSize=3D0): ValueNumber =3D 1 elif ValueString =3D=3D 'FALSE': ValueNumber =3D 0 - elif ValueString.startswith('0X'): - ValueNumber =3D int (ValueString, 16) - else: - ValueNumber =3D int (ValueString) + ValueNumber =3D int (ValueString, 0) if ValueNumber !=3D 0: ValueNumber =3D 1 except: @@ -127,10 +124,7 @@ def PatchBinaryFile(FileName, ValueOffset, TypeName, V= alueString, MaxSize=3D0): # Get PCD value for UINT* data type # try: - if ValueString.startswith('0X'): - ValueNumber =3D int (ValueString, 16) - else: - ValueNumber =3D int (ValueString) + ValueNumber =3D int (ValueString, 0) except: return PARAMETER_INVALID, "PCD Value %s is not valid dec or he= x string." % (ValueString) # --=20 2.16.2.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel