[PATCH] D49515: [llvm-objcopy, tests] Fix several llvm-objcopy tests

Stella Stamenova via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 18 15:09:38 PDT 2018


stella.stamenova created this revision.
stella.stamenova added reviewers: asmith, bkramer.
Herald added subscribers: llvm-commits, jakehehrlich.
Herald added a reviewer: alexshap.

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.


Repository:
  rL LLVM

https://reviews.llvm.org/D49515

Files:
  test/tools/llvm-objcopy/Inputs/ungzip.py


Index: test/tools/llvm-objcopy/Inputs/ungzip.py
===================================================================
--- test/tools/llvm-objcopy/Inputs/ungzip.py
+++ test/tools/llvm-objcopy/Inputs/ungzip.py
@@ -2,4 +2,12 @@
 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()


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49515.156162.patch
Type: text/x-patch
Size: 566 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180718/5efab829/attachment.bin>


More information about the llvm-commits mailing list