Skip to content

Commit e243651

Browse files
committed
Avoid try-with-resources in PE code
1 parent c6b6dff commit e243651

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/control/TopLevelExceptionHandler.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@
6060
import com.oracle.graal.python.nodes.util.CannotCastException;
6161
import com.oracle.graal.python.nodes.util.CastToJavaLongLossyNode;
6262
import com.oracle.graal.python.runtime.ExecutionContext.IndirectCalleeContext;
63+
import com.oracle.graal.python.runtime.GilNode;
6364
import com.oracle.graal.python.runtime.PythonContext;
6465
import com.oracle.graal.python.runtime.PythonOptions;
65-
import com.oracle.graal.python.runtime.GilNode;
6666
import com.oracle.graal.python.runtime.exception.ExceptionUtils;
6767
import com.oracle.graal.python.runtime.exception.PException;
6868
import com.oracle.graal.python.runtime.exception.PythonExitException;
@@ -88,6 +88,8 @@ public class TopLevelExceptionHandler extends RootNode {
8888
@CompilationFinal private LanguageReference<PythonLanguage> language;
8989
@CompilationFinal private ContextReference<PythonContext> context;
9090

91+
@Child GilNode gilNode = GilNode.create();
92+
9193
public TopLevelExceptionHandler(PythonLanguage language, RootNode child) {
9294
super(language);
9395
this.sourceSection = child.getSourceSection();
@@ -121,7 +123,8 @@ private PythonContext getContext() {
121123
@Override
122124
@SuppressWarnings("try")
123125
public Object execute(VirtualFrame frame) {
124-
try (GilNode.UncachedAcquire gil = GilNode.uncachedAcquire()) {
126+
boolean wasAcquired = gilNode.acquire();
127+
try {
125128
if (exception != null) {
126129
throw handlePythonException(exception.getEscapedException());
127130
} else {
@@ -140,6 +143,8 @@ public Object execute(VirtualFrame frame) {
140143
throw e;
141144
}
142145
}
146+
} finally {
147+
gilNode.release(wasAcquired);
143148
}
144149
}
145150

0 commit comments

Comments
 (0)