Skip to content

Commit 90329dc

Browse files
committed
GR-10739: fix missing closure initialization from generator locals
1 parent 91e116e commit 90329dc

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/ExpressionDefinitionNode.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
package com.oracle.graal.python.nodes.function;
2727

2828
import com.oracle.graal.python.builtins.objects.cell.PCell;
29+
import com.oracle.graal.python.builtins.objects.function.PArguments;
2930
import com.oracle.graal.python.nodes.PNode;
3031
import com.oracle.graal.python.parser.DefinitionCellSlots;
3132
import com.oracle.graal.python.parser.ExecutionCellSlots;
@@ -61,4 +62,15 @@ PCell[] getClosureFromLocals(Frame frame) {
6162

6263
return closure;
6364
}
65+
66+
PCell[] getClosureFromGeneratorOrFunctionLocals(Frame frame) {
67+
PCell[] closure;
68+
Frame generatorFrame = PArguments.getGeneratorFrame(frame);
69+
if (generatorFrame != null) {
70+
closure = getClosureFromLocals(generatorFrame);
71+
} else {
72+
closure = getClosureFromLocals(frame);
73+
}
74+
return closure;
75+
}
6476
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/FunctionDefinitionNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public FunctionDefinitionNode(String functionName, String enclosingClassName, Py
6464
public Object execute(VirtualFrame frame) {
6565
defaults.executeVoid(frame);
6666

67-
PCell[] closure = getClosureFromLocals(frame);
67+
PCell[] closure = getClosureFromGeneratorOrFunctionLocals(frame);
6868
return factory().createFunction(functionName, enclosingClassName, arity, callTarget, frameDescriptor, PArguments.getGlobals(frame), closure);
6969
}
7070

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/GeneratorExpressionNode.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import com.oracle.truffle.api.CompilerAsserts;
3434
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
3535
import com.oracle.truffle.api.RootCallTarget;
36-
import com.oracle.truffle.api.frame.Frame;
3736
import com.oracle.truffle.api.frame.FrameDescriptor;
3837
import com.oracle.truffle.api.frame.VirtualFrame;
3938
import com.oracle.truffle.api.nodes.RootNode;
@@ -130,13 +129,7 @@ public Object execute(VirtualFrame frame) {
130129
}
131130
PArguments.setGlobals(arguments, PArguments.getGlobals(frame));
132131

133-
PCell[] closure;
134-
Frame generatorFrame = PArguments.getGeneratorFrame(frame);
135-
if (generatorFrame != null) {
136-
closure = getClosureFromLocals(generatorFrame);
137-
} else {
138-
closure = getClosureFromLocals(frame);
139-
}
132+
PCell[] closure = getClosureFromGeneratorOrFunctionLocals(frame);
140133
return factory().createGenerator(name, callTarget, frameDescriptor, arguments, closure, executionCellSlots,
141134
numOfActiveFlags, numOfGeneratorBlockNode, numOfGeneratorForNode);
142135
}

0 commit comments

Comments
 (0)