[llvm] 42f90a2 - [extract_symbols.py] Fix line-splitting of tool output.

Simon Tatham via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 12 01:08:02 PST 2022


Author: Simon Tatham
Date: 2022-01-12T09:06:56Z
New Revision: 42f90a28a32dd97734fe3f502831a82bd9706795

URL: https://github.com/llvm/llvm-project/commit/42f90a28a32dd97734fe3f502831a82bd9706795
DIFF: https://github.com/llvm/llvm-project/commit/42f90a28a32dd97734fe3f502831a82bd9706795.diff

LOG: [extract_symbols.py] Fix line-splitting of tool output.

Two functions in the `is_32bit_windows` family were retrieving the
output of a tool via `subprocess.check_output`, and then iterating
over it using `for line in output`. But in Python, that gets you the
output one //character// at a time, not a line at a time. So the
regexes that looked for a platform name were never matching.

(This is a mistake that Python makes uniquely easy, because iterating
over a file and over a string have different default behaviour, and
because the element type of a string is still a string so you don't
even get a type mismatch error to warn you about it!)

Reviewed By: michaelplatings

Differential Revision: https://reviews.llvm.org/D117030

Added: 
    

Modified: 
    llvm/utils/extract_symbols.py

Removed: 
    


################################################################################
diff  --git a/llvm/utils/extract_symbols.py b/llvm/utils/extract_symbols.py
index 21c9768143427..0f8e8ba64c80a 100755
--- a/llvm/utils/extract_symbols.py
+++ b/llvm/utils/extract_symbols.py
@@ -111,7 +111,7 @@ def dumpbin_is_32bit_windows(lib):
 def objdump_is_32bit_windows(lib):
     output = subprocess.check_output(['objdump','-f',lib],
                                      universal_newlines=True)
-    for line in output:
+    for line in output.splitlines():
         match = re.match('.+file format (\S+)', line)
         if match:
             return (match.group(1) == 'pe-i386')
@@ -120,7 +120,7 @@ def objdump_is_32bit_windows(lib):
 def readobj_is_32bit_windows(lib):
     output = subprocess.check_output(['llvm-readobj','--file-header',lib],
                                      universal_newlines=True)
-    for line in output:
+    for line in output.splitlines():
         match = re.match('Format: (\S+)', line)
         if match:
             return (match.group(1) == 'COFF-i386')


        


More information about the llvm-commits mailing list