Skip to content

Commit 155df21

Browse files
committed
set localsDict to the globals for Exec with globals argument
1 parent d129a07 commit 155df21

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,7 @@ PNone execDefault(Object source, PDict globals, @SuppressWarnings("unused") PNon
627627
PCode code = compileNode.execute(source, "exec", "exec", 0, false, -1);
628628
Object[] args = PArguments.create();
629629
PArguments.setGlobals(args, globals);
630+
PArguments.setPFrame(args, factory().createPFrame(globals));
630631
// If locals are not given, they default to the globals, so we don't need the caller
631632
// frame's closure at all
632633
indirectCallNode.call(code.getRootCallTarget(), args);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/frame/PFrame.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ public PFrame(LazyPythonClass cls, Frame frame) {
7676
this.inClassScope = PArguments.getSpecialArgument(frame) instanceof ClassBodyRootNode;
7777
}
7878

79+
public PFrame(LazyPythonClass cls, PDict locals) {
80+
super(cls);
81+
this.exception = null;
82+
this.index = -1;
83+
this.frame = null;
84+
this.location = null;
85+
this.inClassScope = false;
86+
this.localsDict = locals;
87+
}
88+
7989
public PFrame(LazyPythonClass cls, PBaseException exception, int index) {
8090
super(cls);
8191
this.exception = exception;
@@ -151,8 +161,11 @@ public PDict getLocals(PythonObjectFactory factory) {
151161
}
152162
}
153163
return localsDict;
164+
} else if (localsDict != null) {
165+
return localsDict;
166+
} else {
167+
return factory.createDict();
154168
}
155-
return factory.createDict();
156169
}
157170

158171
/**

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/PArguments.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,11 @@ public static PythonObject getGlobalsSafe(Frame frame) {
148148
}
149149

150150
public static void setPFrame(Frame frame, PFrame pFrame) {
151-
((PFrame[]) frame.getArguments()[INDEX_PFRAME_ARGUMENT])[0] = pFrame;
151+
setPFrame(frame.getArguments(), pFrame);
152+
}
153+
154+
public static void setPFrame(Object[] args, PFrame pFrame) {
155+
((PFrame[]) args[INDEX_PFRAME_ARGUMENT])[0] = pFrame;
152156
}
153157

154158
public static PFrame getPFrame(Frame frame) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/object/PythonObjectFactory.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,10 @@ public PReferenceType createReferenceType(PythonObject object, PFunction callbac
560560
* Frames, traces and exceptions
561561
*/
562562

563+
public PFrame createPFrame(PDict locals) {
564+
return trace(new PFrame(PythonBuiltinClassType.PFrame, locals));
565+
}
566+
563567
public PFrame createPFrame(Frame frame) {
564568
return trace(new PFrame(PythonBuiltinClassType.PFrame, frame));
565569
}

0 commit comments

Comments
 (0)