[compiler-rt] r358682 - [asan_symbolize] Workaround bug in old Python 2 versions.

Dan Liew via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 18 09:22:55 PDT 2019


Author: delcypher
Date: Thu Apr 18 09:22:55 2019
New Revision: 358682

URL: http://llvm.org/viewvc/llvm-project?rev=358682&view=rev
Log:
[asan_symbolize] Workaround bug in old Python 2 versions.

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

Modified:
    compiler-rt/trunk/lib/asan/scripts/asan_symbolize.py

Modified: compiler-rt/trunk/lib/asan/scripts/asan_symbolize.py
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/scripts/asan_symbolize.py?rev=358682&r1=358681&r2=358682&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/scripts/asan_symbolize.py (original)
+++ compiler-rt/trunk/lib/asan/scripts/asan_symbolize.py Thu Apr 18 09:22:55 2019
@@ -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)




More information about the llvm-commits mailing list