Make sym_check python 3 compatible
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@292152 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -14,6 +14,25 @@ import subprocess
|
|||||||
import sys
|
import sys
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
def to_bytes(str):
|
||||||
|
# Encode to UTF-8 to get binary data.
|
||||||
|
if isinstance(str, bytes):
|
||||||
|
return str
|
||||||
|
return str.encode('utf-8')
|
||||||
|
|
||||||
|
def to_string(bytes):
|
||||||
|
if isinstance(bytes, str):
|
||||||
|
return bytes
|
||||||
|
return to_bytes(bytes)
|
||||||
|
|
||||||
|
def convert_string(bytes):
|
||||||
|
try:
|
||||||
|
return to_string(bytes.decode('utf-8'))
|
||||||
|
except AttributeError: # 'str' object has no attribute 'decode'.
|
||||||
|
return str(bytes)
|
||||||
|
except UnicodeError:
|
||||||
|
return str(bytes)
|
||||||
|
|
||||||
def execute_command(cmd, input_str=None):
|
def execute_command(cmd, input_str=None):
|
||||||
"""
|
"""
|
||||||
Execute a command, capture and return its output.
|
Execute a command, capture and return its output.
|
||||||
@@ -28,6 +47,8 @@ def execute_command(cmd, input_str=None):
|
|||||||
exitCode = p.wait()
|
exitCode = p.wait()
|
||||||
if exitCode == -signal.SIGINT:
|
if exitCode == -signal.SIGINT:
|
||||||
raise KeyboardInterrupt
|
raise KeyboardInterrupt
|
||||||
|
out = convert_string(out)
|
||||||
|
err = convert_string(err)
|
||||||
return out, err, exitCode
|
return out, err, exitCode
|
||||||
|
|
||||||
|
|
||||||
@@ -105,13 +126,13 @@ def demangle_symbol(symbol):
|
|||||||
|
|
||||||
|
|
||||||
def is_elf(filename):
|
def is_elf(filename):
|
||||||
with open(filename, 'r') as f:
|
with open(filename, 'rb') as f:
|
||||||
magic_bytes = f.read(4)
|
magic_bytes = f.read(4)
|
||||||
return magic_bytes == '\x7fELF'
|
return magic_bytes == b'\x7fELF'
|
||||||
|
|
||||||
|
|
||||||
def is_mach_o(filename):
|
def is_mach_o(filename):
|
||||||
with open(filename, 'r') as f:
|
with open(filename, 'rb') as f:
|
||||||
magic_bytes = f.read(4)
|
magic_bytes = f.read(4)
|
||||||
return magic_bytes in [
|
return magic_bytes in [
|
||||||
'\xfe\xed\xfa\xce', # MH_MAGIC
|
'\xfe\xed\xfa\xce', # MH_MAGIC
|
||||||
|
|||||||
Reference in New Issue
Block a user