mirror of
https://github.com/Z3Prover/z3
synced 2025-04-06 17:44:08 +00:00
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.
This commit is contained in:
parent
b5f1c50c1b
commit
a2376b1016
|
@ -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]
|
||||
|
|
Loading…
Reference in a new issue