[llvm] r337567 - [llvm-objcopy, tests] Fix several llvm-objcopy tests
Stella Stamenova via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 20 09:19:36 PDT 2018
Author: stella.stamenova
Date: Fri Jul 20 09:19:36 2018
New Revision: 337567
URL: http://llvm.org/viewvc/llvm-project?rev=337567&view=rev
Log:
[llvm-objcopy, tests] Fix several llvm-objcopy tests
Summary: In Python 3, sys.stdout.write expects a string rather than bytes. In order to be able to write the bytes to stdout, we need to use the buffer directly instead. This change is borrowing the implementation for writing to stdout that cat.py uses. Note that we cannot use cat.py directly because the file we are trying to open is a gzip file.
Reviewers: asmith, bkramer, alexshap, jakehehrlich
Reviewed By: alexshap, jakehehrlich
Subscribers: jakehehrlich, llvm-commits
Differential Revision: https://reviews.llvm.org/D49515
Modified:
llvm/trunk/test/tools/llvm-objcopy/Inputs/ungzip.py
Modified: llvm/trunk/test/tools/llvm-objcopy/Inputs/ungzip.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objcopy/Inputs/ungzip.py?rev=337567&r1=337566&r2=337567&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-objcopy/Inputs/ungzip.py (original)
+++ llvm/trunk/test/tools/llvm-objcopy/Inputs/ungzip.py Fri Jul 20 09:19:36 2018
@@ -2,4 +2,12 @@ import gzip
import sys
with gzip.open(sys.argv[1], 'rb') as f:
- sys.stdout.write(f.read())
+ writer = getattr(sys.stdout, 'buffer', None)
+ if writer is None:
+ writer = sys.stdout
+ if sys.platform == "win32":
+ import os, msvcrt
+ msvcrt.setmode(sys.stdout.fileno(),os.O_BINARY)
+
+ writer.write(f.read())
+ sys.stdout.flush()
More information about the llvm-commits
mailing list