public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Gary Lin <glin@suse.com>
To: edk2-devel@lists.01.org
Cc: Yonghong Zhu <yonghong.zhu@intel.com>, Liming Gao <liming.gao@intel.com>
Subject: [PATCH 2/3] BaseTools: Unify long and int in Expression.py
Date: Wed, 27 Jun 2018 18:07:56 +0800	[thread overview]
Message-ID: <20180627100757.3405-3-glin@suse.com> (raw)
In-Reply-To: <20180627100757.3405-1-glin@suse.com>

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>
---
 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



  parent reply	other threads:[~2018-06-27 10:08 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-27 10:07 [PATCH 0/3] python3 follow-up patches for BaseTools Gary Lin
2018-06-27 10:07 ` [PATCH 1/3] BaseTools: Remove the old python "not-equal" in DscBuildData.py Gary Lin
2018-06-27 10:07 ` Gary Lin [this message]
2018-06-27 10:07 ` [PATCH 3/3] BaseTools: Read the env variable PYTHON_DEFAULT Gary Lin
2018-07-06  0:46   ` Zhu, Yonghong
2018-07-06  1:49     ` Gary Lin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180627100757.3405-3-glin@suse.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox