Skip to content

Commit 1e63389

Browse files
committed
be strict on restoration of thread state after leaving an indirect call
1 parent cd3c471 commit 1e63389

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/ExecutionContext.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,9 @@ private static IndirectCallState enter(VirtualFrame frame, PythonThreadState pyt
409409
public static void exit(VirtualFrame frame, PythonLanguage language, PythonContext context, Object savedState) {
410410
if (savedState != null && frame != null && context != null) {
411411
exit(frame, context.getThreadState(language), savedState);
412+
return;
412413
}
414+
assert savedState == null : "tried to exit an indirect call with state, but without frame/context";
413415
}
414416

415417
public static void exit(VirtualFrame frame, PNodeWithRaiseAndIndirectCall indirectCallNode, Object savedState) {
@@ -418,24 +420,28 @@ public static void exit(VirtualFrame frame, PNodeWithRaiseAndIndirectCall indire
418420
if (context != null) {
419421
PythonLanguage language = indirectCallNode.getLanguage();
420422
exit(frame, context.getThreadState(language), savedState);
423+
return;
421424
}
422425
}
426+
assert savedState == null : "tried to exit an indirect call with state, but without frame/context";
423427
}
424428

425429
/**
426430
* @see #exit(VirtualFrame, PythonLanguage, PythonContext, Object)
427431
*/
428432
public static void exit(VirtualFrame frame, PythonThreadState pythonThreadState, Object savedState) {
429-
if (frame == null || savedState == null) {
433+
if (frame == null) {
434+
assert savedState == null : "tried to exit an indirect call with state, but without frame";
435+
return;
436+
}
437+
if (savedState == null) {
430438
return;
431439
}
432440
IndirectCallState state = (IndirectCallState) savedState;
433441
if (state.info != null) {
434442
pythonThreadState.popTopFrameInfo();
435443
}
436-
if (state.curExc != null) {
437-
pythonThreadState.setCaughtException(state.curExc);
438-
}
444+
pythonThreadState.setCaughtException(state.curExc);
439445
}
440446
}
441447

0 commit comments

Comments
 (0)