Skip to content

Commit 9bdb52b

Browse files
committed
fixup eval/exec code compilation
1 parent e36675b commit 9bdb52b

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -613,10 +613,14 @@ protected void assertNoFreeVars(PCode code) {
613613
Object[] freeVars = code.getFreeVars();
614614
if (freeVars.length > 0) {
615615
hasFreeVarsBranch.enter();
616-
throw raise(PythonBuiltinClassType.TypeError, "code object passed to eval/exec may not contain free variables");
616+
throw raise(PythonBuiltinClassType.TypeError, "code object passed to %s may not contain free variables", getMode());
617617
}
618618
}
619619

620+
protected String getMode() {
621+
return "eval";
622+
}
623+
620624
protected boolean isMapping(Object object) {
621625
// tfel: it seems that CPython only checks that there is __getitem__
622626
if (object instanceof PDict) {
@@ -631,7 +635,7 @@ protected boolean isAnyNone(Object object) {
631635
}
632636

633637
protected PCode createAndCheckCode(Object source) {
634-
PCode code = compileNode.execute(source, "<string>", "eval", 0, false, -1);
638+
PCode code = compileNode.execute(source, "<string>", getMode(), 0, false, -1);
635639
assertNoFreeVars(code);
636640
return code;
637641
}
@@ -736,6 +740,11 @@ PNone badLocals(@SuppressWarnings("unused") Object source, @SuppressWarnings("un
736740
abstract static class ExecNode extends EvalNode {
737741
protected abstract Object executeInternal(VirtualFrame frame);
738742

743+
@Override
744+
protected String getMode() {
745+
return "exec";
746+
}
747+
739748
@Override
740749
public final Object execute(VirtualFrame frame) {
741750
executeInternal(frame);

0 commit comments

Comments
 (0)