[OpenPower-Firmware] [RFC PATCH 4/6] sbeCompression: use floor division

Marty E. Plummer hanetzer at startmail.com
Fri May 10 19:35:07 AEST 2019


python2 returns an integer when both division operands are integers.
python3 will return a float in this situation. Use the floor division
operator (//) which returns an integer on both versions.

Without this change, building with python3.x (python3.5 tested) as
/usr/bin/python will result in the following error:

Traceback (most recent call last):
  File "sbe/src/boot/sbeCompression.py", line 198, in <module>
    main( sys.argv )
  File "sbe/src/boot/sbeCompression.py", line 181, in main
    compress(imagePath + "/" + image + ".base", imagePath + "/" + image + ".base.compressed")
  File "sbe/src/boot/sbeCompression.py", line 58, in compress
    for i in range(0, os.stat(inputFile).st_size / 4 ):
TypeError: 'float' object cannot be interpreted as an integer

Signed-off-by: Marty E. Plummer <hanetzer at startmail.com>
---
 src/boot/sbeCompression.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/boot/sbeCompression.py b/src/boot/sbeCompression.py
index f8ca6202..b6da858c 100755
--- a/src/boot/sbeCompression.py
+++ b/src/boot/sbeCompression.py
@@ -55,7 +55,7 @@ def compress(inputFile, compressedFile):
       sys.exit(1)
 
     instDict = dict()
-    for i in range(0, os.stat(inputFile).st_size / 4 ):
+    for i in range(0, os.stat(inputFile).st_size // 4 ):
 
        fourByt = f.read(4)
 
@@ -88,7 +88,7 @@ def compress(inputFile, compressedFile):
     count = 0
 
     #Create a bitmap for each four bytes of binary.
-    for i in range(0, os.stat(inputFile).st_size / 4 ):
+    for i in range(0, os.stat(inputFile).st_size // 4 ):
 
        fourByt = f.read(4)
        if fourByt in instList:
@@ -97,7 +97,7 @@ def compress(inputFile, compressedFile):
        else :
           strBits += '0'
 
-       if ((len(strBits) == 32) or (i == (os.stat(inputFile).st_size / 4) - 1)):
+       if ((len(strBits) == 32) or (i == (os.stat(inputFile).st_size // 4) - 1)):
           value = int(strBits, 2)
           fW.write(struct.pack('>I', value))
           strBits = ""
@@ -115,7 +115,7 @@ def compress(inputFile, compressedFile):
 
     f.seek(0, 0)
 
-    for i in range(0, os.stat(inputFile).st_size / 4 ):
+    for i in range(0, os.stat(inputFile).st_size // 4 ):
 
        fourByt = f.read(4)
 
-- 
2.21.0



More information about the OpenPower-Firmware mailing list