Skip to content

Commit ed28348

Browse files
committed
Avoid NPE when reading frame in async handler when triggered in generator functions
1 parent aa401b4 commit ed28348

File tree

11 files changed

+54
-3
lines changed

11 files changed

+54
-3
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/ExternalFunctionNodes.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,11 @@ public boolean isInternal() {
10021002
return true;
10031003
}
10041004

1005+
@Override
1006+
public boolean setsUpCalleeContext() {
1007+
return true;
1008+
}
1009+
10051010
protected final Object readSelf(VirtualFrame frame) {
10061011
if (readSelfNode != null) {
10071012
return readSelfNode.execute(frame);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/HPyExternalFunctionNodes.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,11 @@ public boolean isInternal() {
552552
public boolean isPythonInternal() {
553553
return true;
554554
}
555+
556+
@Override
557+
public boolean setsUpCalleeContext() {
558+
return true;
559+
}
555560
}
556561

557562
static final class HPyMethNoargsRoot extends HPyMethodDescriptorRootNode {
@@ -1314,6 +1319,11 @@ public boolean isPythonInternal() {
13141319
public boolean isInternal() {
13151320
return true;
13161321
}
1322+
1323+
@Override
1324+
public boolean setsUpCalleeContext() {
1325+
return true;
1326+
}
13171327
}
13181328

13191329
/**

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/SortNodes.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ public boolean isInternal() {
162162
public String getName() {
163163
return "sort_comparator";
164164
}
165+
166+
@Override
167+
public boolean setsUpCalleeContext() {
168+
return true;
169+
}
165170
}
166171

167172
public abstract static class SortSequenceStorageNode extends PNodeWithContext {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/PRootNode.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,4 +189,11 @@ protected byte[] extractCode() {
189189
// no code for non-user functions
190190
return PythonUtils.EMPTY_BYTE_ARRAY;
191191
}
192+
193+
/**
194+
* True if the root calls CalleeContext.enter or an equivalent on entry.
195+
*/
196+
public boolean setsUpCalleeContext() {
197+
return false;
198+
}
192199
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeGeneratorFunctionRootNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public String getName() {
109109
@Override
110110
public String toString() {
111111
CompilerAsserts.neverPartOfCompilation();
112-
return "<generator function root" + originalName + ">";
112+
return "<generator function root " + originalName + ">";
113113
}
114114

115115
@Override

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeGeneratorRootNode.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,11 @@ public String toString() {
195195
return "<bytecode " + rootNode.getName() + " (generator resume bci=" + resumeBci + ")>";
196196
}
197197

198+
@Override
199+
public boolean setsUpCalleeContext() {
200+
return true;
201+
}
202+
198203
@Override
199204
public Signature getSignature() {
200205
return rootNode.getSignature();

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeRootNode.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5636,6 +5636,11 @@ public boolean isInternal() {
56365636
return internal;
56375637
}
56385638

5639+
@Override
5640+
public boolean setsUpCalleeContext() {
5641+
return true;
5642+
}
5643+
56395644
@Override
56405645
protected byte[] extractCode() {
56415646
/*

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/CallArithmeticRootNode.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,9 @@ public Object execute(VirtualFrame frame) {
8383
}
8484

8585
protected abstract Object doCall(VirtualFrame frame);
86+
87+
@Override
88+
public boolean setsUpCalleeContext() {
89+
return true;
90+
}
8691
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/ReadCallerFrameNode.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,7 @@ public Frame visitFrame(FrameInstance frameInstance) {
302302
RootNode rootNode = target.getRootNode();
303303
Node callNode = frameInstance.getCallNode();
304304
boolean didMark = IndirectCallNode.setEncapsulatingNeedsToPassCallerFrame(callNode != null ? callNode : requestingNode);
305-
if (rootNode instanceof PRootNode && outputFrame[0] == null) {
306-
PRootNode pRootNode = (PRootNode) rootNode;
305+
if (outputFrame[0] == null && rootNode instanceof PRootNode pRootNode && pRootNode.setsUpCalleeContext()) {
307306
pRootNode.setNeedsCallerFrame();
308307
if (i < 0 && startFrame != null) {
309308
Frame roFrame = frameInstance.getFrame(FrameInstance.FrameAccess.READ_ONLY);

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,11 @@ public boolean isInternal() {
322322
return true;
323323
}
324324

325+
@Override
326+
public boolean setsUpCalleeContext() {
327+
return true;
328+
}
329+
325330
@Override
326331
public Object execute(VirtualFrame frame) {
327332
if (body == null) {

0 commit comments

Comments
 (0)