Skip to content

Commit 703a013

Browse files
author
Thomas Preud'homme
committed
[LNT] Python 3 support: fix text/binary confusion in profile support
There is confusion between text and binary in the checkFile method of the various profile format implementation modules. All of them compare the first few bytes read in text mode against an expected value. However, the header of the profile v1 contains some binary data, thus causing an error in Python 3 when reading a profile v1 file and calling any of the checkFile method. This commit changes the checkFile method to read binary data and compare against binary literals. Reviewers: cmatthews, hubert.reinterpretcast, kristof.beyls Reviewed By: hubert.reinterpretcast Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D68222 llvm-svn: 373617
1 parent 398d797 commit 703a013

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

lnt/testing/profile/perf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def __init__(self):
1818

1919
@staticmethod
2020
def checkFile(fn):
21-
return open(fn).read(8) == 'PERFILE2'
21+
return open(fn, 'rb').read(8) == b'PERFILE2'
2222

2323
@staticmethod
2424
def deserialize(f, nm='nm', objdump='objdump', propagateExceptions=False):

lnt/testing/profile/profilev1impl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def upgrade(old):
4343
@staticmethod
4444
def checkFile(fn):
4545
# "zlib compressed data" - 78 9C
46-
return open(fn).read(2) == '\x78\x9c'
46+
return open(fn, 'rb').read(2) == b'\x78\x9c'
4747

4848
@staticmethod
4949
def deserialize(fobj):

lnt/testing/profile/profilev2impl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ class ProfileV2(ProfileImpl):
558558
def checkFile(fn):
559559
# The first number is the version (2); ULEB encoded this is simply
560560
# 0x02.
561-
return ord(open(fn).read(1)) == 2
561+
return open(fn, 'rb').read(1) == b'\x02'
562562

563563
@staticmethod
564564
def deserialize(fobj):

0 commit comments

Comments
 (0)