Skip to content

Commit

Permalink
[asan_symbolize] Workaround bug in old Python 2 versions.
Browse files Browse the repository at this point in the history
The change landed in r358657 broke some of the buildbots because they
use an older version of Python 2 that raises this error.

```
File "/Volumes/data/dev/llvm/upstream/master/src/projects/compiler-rt/lib/asan/scripts/asan_symbolize.py", line 509
  exec(f.read(), globals_space, None)
SyntaxError: unqualified exec is not allowed in function 'load_plugin_from_file' it contains a nested function with free variables
```

I can reproduce this problem when using Python 2.7.6.

To workaround this some indirection has been added to prevent the broken
(the line at fault would never be executed) SyntaxError error in old
Python versions from being raised.

rdar://problem/49476995

llvm-svn: 358682
  • Loading branch information
delcypher committed Apr 18, 2019
1 parent 523f90a commit 16c3883
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions compiler-rt/lib/asan/scripts/asan_symbolize.py
Original file line number Diff line number Diff line change
@@ -494,6 +494,10 @@ def __init__(self):
self._plugins = [ ]
self._plugin_names = set()

def _load_plugin_from_file_impl_py_gt_2(self, file_path, globals_space):
with open(file_path, 'r') as f:
exec(f.read(), globals_space, None)

def load_plugin_from_file(self, file_path):
logging.info('Loading plugins from "{}"'.format(file_path))
globals_space = dict(globals())
@@ -505,8 +509,9 @@ def register_plugin(plugin):
if sys.version_info.major < 3:
execfile(file_path, globals_space, None)
else:
with open(file_path, 'r') as f:
exec(f.read(), globals_space, None)
# Indirection here is to avoid a bug in older Python 2 versions:
# `SyntaxError: unqualified exec is not allowed in function ...`
self._load_plugin_from_file_impl_py_gt_2(file_path, globals_space)

def add_plugin(self, plugin):
assert isinstance(plugin, AsanSymbolizerPlugIn)

0 comments on commit 16c3883

Please sign in to comment.