Skip to content

Commit d6d53b2

Browse files
committed
ARROW-63: [C++] Enable ctest to work on systems with Python 3 as the default Python
Author: Wes McKinney <wesm@apache.org> Closes #42 from wesm/ARROW-63 and squashes the following commits: 9840308 [Wes McKinney] Make asan_symbolize.py work on both Python 2.7 and 3.x
1 parent d3cb6b4 commit d6d53b2

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

cpp/build-support/asan_symbolize.py

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def open_llvm_symbolizer(self):
6464
'--functions=true',
6565
'--inlining=true']
6666
if DEBUG:
67-
print ' '.join(cmd)
67+
print(' '.join(cmd))
6868
return subprocess.Popen(cmd, stdin=subprocess.PIPE,
6969
stdout=subprocess.PIPE)
7070

@@ -76,8 +76,9 @@ def symbolize(self, addr, binary, offset):
7676
try:
7777
symbolizer_input = '%s %s' % (binary, offset)
7878
if DEBUG:
79-
print symbolizer_input
80-
print >> self.pipe.stdin, symbolizer_input
79+
print(symbolizer_input)
80+
self.pipe.stdin.write(symbolizer_input)
81+
self.pipe.stdin.write('\n')
8182
while True:
8283
function_name = self.pipe.stdout.readline().rstrip()
8384
if not function_name:
@@ -113,7 +114,7 @@ def __init__(self, binary):
113114
def open_addr2line(self):
114115
cmd = ['addr2line', '-f', '-e', self.binary]
115116
if DEBUG:
116-
print ' '.join(cmd)
117+
print(' '.join(cmd))
117118
return subprocess.Popen(cmd,
118119
stdin=subprocess.PIPE, stdout=subprocess.PIPE)
119120

@@ -122,7 +123,8 @@ def symbolize(self, addr, binary, offset):
122123
if self.binary != binary:
123124
return None
124125
try:
125-
print >> self.pipe.stdin, offset
126+
self.pipe.stdin.write(offset)
127+
self.pipe.stdin.write('\n')
126128
function_name = self.pipe.stdout.readline().rstrip()
127129
file_name = self.pipe.stdout.readline().rstrip()
128130
except Exception:
@@ -145,11 +147,12 @@ def __init__(self, addr, binary):
145147
self.pipe = None
146148

147149
def write_addr_to_pipe(self, offset):
148-
print >> self.pipe.stdin, '0x%x' % int(offset, 16)
150+
self.pipe.stdin.write('0x%x' % int(offset, 16))
151+
self.pipe.stdin.write('\n')
149152

150153
def open_atos(self):
151154
if DEBUG:
152-
print 'atos -o %s -arch %s' % (self.binary, self.arch)
155+
print('atos -o %s -arch %s' % (self.binary, self.arch))
153156
cmdline = ['atos', '-o', self.binary, '-arch', self.arch]
154157
self.pipe = subprocess.Popen(cmdline,
155158
stdin=subprocess.PIPE,
@@ -168,7 +171,7 @@ def symbolize(self, addr, binary, offset):
168171
# foo(type1, type2) (in object.name) (filename.cc:80)
169172
match = re.match('^(.*) \(in (.*)\) \((.*:\d*)\)$', atos_line)
170173
if DEBUG:
171-
print 'atos_line: ', atos_line
174+
print('atos_line: {0}'.format(atos_line))
172175
if match:
173176
function_name = match.group(1)
174177
function_name = re.sub('\(.*?\)', '', function_name)
@@ -282,7 +285,7 @@ def symbolize(self, addr, binary, offset):
282285
function_name, file_name, line_no = res
283286
result = ['%s in %s %s:%d' % (
284287
addr, function_name, file_name, line_no)]
285-
print result
288+
print(result)
286289
return result
287290
else:
288291
return None
@@ -318,15 +321,20 @@ def symbolize_address(self, addr, binary, offset):
318321

319322
def print_symbolized_lines(self, symbolized_lines):
320323
if not symbolized_lines:
321-
print self.current_line
324+
print(self.current_line)
322325
else:
323326
for symbolized_frame in symbolized_lines:
324-
print ' #' + str(self.frame_no) + ' ' + symbolized_frame.rstrip()
327+
print(' #' + str(self.frame_no) + ' ' + symbolized_frame.rstrip())
325328
self.frame_no += 1
326329

327330
def process_stdin(self):
328331
self.frame_no = 0
329-
sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
332+
333+
if sys.version_info[0] == 2:
334+
sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
335+
else:
336+
# Unbuffered output is not supported in Python 3
337+
sys.stdout = os.fdopen(sys.stdout.fileno(), 'w')
330338

331339
while True:
332340
line = sys.stdin.readline()
@@ -337,10 +345,10 @@ def process_stdin(self):
337345
'^( *#([0-9]+) *)(0x[0-9a-f]+) *\((.*)\+(0x[0-9a-f]+)\)')
338346
match = re.match(stack_trace_line_format, line)
339347
if not match:
340-
print self.current_line
348+
print(self.current_line)
341349
continue
342350
if DEBUG:
343-
print line
351+
print(line)
344352
_, frameno_str, addr, binary, offset = match.groups()
345353
if frameno_str == '0':
346354
# Assume that frame #0 is the first frame of new stack trace.

0 commit comments

Comments
 (0)