Skip to content

Commit a4ffa74

Browse files
committed
Acquire GIL after StackOverflowError
1 parent e7f2217 commit a4ffa74

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/statement/ExceptionHandlingStatementNode.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ protected final PException wrapJavaExceptionIfApplicable(Throwable e) {
209209
return wrapJavaException(e, this, factory().createBaseException(SystemError, "%m", new Object[]{e}));
210210
}
211211
if (e instanceof StackOverflowError) {
212+
getContext().recoverFromSoe(e);
212213
return wrapJavaException(e, this, factory().createBaseException(RecursionError, "maximum recursion depth exceeded", new Object[]{}));
213214
}
214215
return null;

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,21 @@ public PythonNativeWrapper getSingletonNativeWrapper(PythonAbstractObject obj) {
12351235
return null;
12361236
}
12371237

1238+
public void recoverFromSoe(Throwable e) {
1239+
if (!ownsGil()) {
1240+
System.out.println("SOE thrown and we don't have GIL");
1241+
e.printStackTrace(System.out);
1242+
while (true) {
1243+
try {
1244+
acquireGil();
1245+
return;
1246+
} catch (InterruptedException ee) {
1247+
System.out.println("INTERRUPTED");
1248+
}
1249+
}
1250+
}
1251+
}
1252+
12381253
/**
12391254
* Should not be called directly.
12401255
*

0 commit comments

Comments
 (0)