From ca0547c83cdc8300c2b9f11416a1a302885558e2 Mon Sep 17 00:00:00 2001 From: Stella Stamenova Date: Fri, 20 Jul 2018 16:19:36 +0000 Subject: [PATCH] [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 llvm-svn: 337567 --- llvm/test/tools/llvm-objcopy/Inputs/ungzip.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/llvm/test/tools/llvm-objcopy/Inputs/ungzip.py b/llvm/test/tools/llvm-objcopy/Inputs/ungzip.py index 41f858e..c7b1de9 100644 --- a/llvm/test/tools/llvm-objcopy/Inputs/ungzip.py +++ b/llvm/test/tools/llvm-objcopy/Inputs/ungzip.py @@ -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() -- 2.7.4