[asan_symbolize] Workaround bug in old Python 2 versions.
authorDan Liew <dan@su-root.co.uk>
Thu, 18 Apr 2019 16:22:55 +0000 (16:22 +0000)
committerDan Liew <dan@su-root.co.uk>
Thu, 18 Apr 2019 16:22:55 +0000 (16:22 +0000)
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

compiler-rt/lib/asan/scripts/asan_symbolize.py

index d3025e3..01b816c 100755 (executable)
@@ -494,6 +494,10 @@ class AsanSymbolizerPlugInProxy(object):
     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 @@ class AsanSymbolizerPlugInProxy(object):
     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)