From a2376b1016e6aed4a76869b735179239cffd65cb Mon Sep 17 00:00:00 2001 From: Dan Liew Date: Sat, 12 Mar 2016 22:22:20 +0000 Subject: [PATCH] Try to fix #510. The breakage was caused by #498. The issue here is that in Python2 ``exec`` is a statement and ``exec`` is a function in Python3. For the ``exec`` statement to work we would need to write ``` exec line.strip(' \n') in exec_globals, None ``` We could write a wrapper function to do the right thing depending on the Python version but a better approach is to actually just use ``eval()`` rather than ``exec()`` because * ``eval()`` is less "evil" than ``exec()`` because it only evaluates a single expression. My testing so far seems to indicate that this is sufficient. * ``eval()`` is function in both Python 2 and 3 so we don't need to specialise the code based on Python version. --- scripts/mk_genfile_common.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/mk_genfile_common.py b/scripts/mk_genfile_common.py index 790ce7205..dbb09539e 100644 --- a/scripts/mk_genfile_common.py +++ b/scripts/mk_genfile_common.py @@ -246,7 +246,7 @@ def mk_install_tactic_cpp_internal(component_src_dirs, path): def ADD_PROBE(name, descr, cmd): ADD_PROBE_DATA.append((name, descr, cmd)) - exec_globals = { + eval_globals = { 'ADD_TACTIC': ADD_TACTIC, 'ADD_PROBE': ADD_PROBE, } @@ -272,7 +272,7 @@ def mk_install_tactic_cpp_internal(component_src_dirs, path): added_include = True fout.write('#include"%s"\n' % h_file) try: - exec(line.strip('\n '), exec_globals) + eval(line.strip('\n '), eval_globals, None) except Exception as e: _logger.error("Failed processing ADD_TACTIC command at '{}'\n{}".format( fullname, line)) @@ -282,7 +282,7 @@ def mk_install_tactic_cpp_internal(component_src_dirs, path): added_include = True fout.write('#include"%s"\n' % h_file) try: - exec(line.strip('\n '), exec_globals) + eval(line.strip('\n '), eval_globals, None) except Exception as e: _logger.error("Failed processing ADD_PROBE command at '{}'\n{}".format( fullname, line)) @@ -514,6 +514,6 @@ def mk_hpp_from_pyg(pyg_file, output_dir): 'def_module_params' : def_module_params, } with open(pyg_file, 'r') as fh: - exec(fh.read() + "\n", pyg_globals, None) + eval(fh.read() + "\n", pyg_globals, None) assert len(OUTPUT_HPP_FILE) == 1 return OUTPUT_HPP_FILE[0]