Skip to content

Commit 78ecc87

Browse files
committed
[GR-16578] Correctly prepare interop call to regex.
PullRequest: graalpython/551
2 parents 7b7dfc4 + 21bb680 commit 78ecc87

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SREModuleBuiltins.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@
6161
import com.oracle.graal.python.nodes.function.builtins.PythonTernaryBuiltinNode;
6262
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
6363
import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
64+
import com.oracle.graal.python.runtime.ExecutionContext.IndirectCallContext;
6465
import com.oracle.graal.python.runtime.PythonContext;
66+
import com.oracle.graal.python.runtime.exception.PException;
6567
import com.oracle.graal.python.runtime.exception.PythonErrorType;
6668
import com.oracle.truffle.api.CompilerAsserts;
6769
import com.oracle.truffle.api.CompilerDirectives;
@@ -199,10 +201,12 @@ private BytesNodes.ToBytesNode getToBytesNode() {
199201
abstract static class TRegexCallCompile extends PythonTernaryBuiltinNode {
200202

201203
@Specialization(limit = "1")
202-
Object call(Object callable, Object arg1, Object arg2,
204+
Object call(VirtualFrame frame, Object callable, Object arg1, Object arg2,
203205
@Cached("create()") BranchProfile syntaxError,
204206
@Cached("create()") BranchProfile typeError,
205-
@CachedLibrary("callable") InteropLibrary interop) {
207+
@CachedLibrary("callable") InteropLibrary interop,
208+
@CachedContext(PythonLanguage.class) PythonContext context) {
209+
PException savedExceptionState = IndirectCallContext.enter(frame, context, this);
206210
try {
207211
return interop.execute(callable, arg1, arg2);
208212
} catch (ArityException | UnsupportedTypeException | UnsupportedMessageException e) {
@@ -215,6 +219,8 @@ Object call(Object callable, Object arg1, Object arg2,
215219
}
216220
// just re-throw
217221
throw e;
222+
} finally {
223+
IndirectCallContext.exit(context, savedExceptionState);
218224
}
219225
}
220226
}
@@ -225,14 +231,18 @@ Object call(Object callable, Object arg1, Object arg2,
225231
abstract static class TRegexCallExec extends PythonTernaryBuiltinNode {
226232

227233
@Specialization(limit = "1")
228-
Object call(Object callable, Object arg1, Number arg2,
234+
Object call(VirtualFrame frame, Object callable, Object arg1, Number arg2,
229235
@Cached("create()") BranchProfile typeError,
230-
@CachedLibrary("callable") InteropLibrary interop) {
236+
@CachedLibrary("callable") InteropLibrary interop,
237+
@CachedContext(PythonLanguage.class) PythonContext context) {
238+
PException savedExceptionState = IndirectCallContext.enter(frame, context, this);
231239
try {
232240
return interop.execute(callable, arg1, arg2);
233241
} catch (ArityException | UnsupportedTypeException | UnsupportedMessageException e) {
234242
typeError.enter();
235243
throw raise(TypeError, "%s", e);
244+
} finally {
245+
IndirectCallContext.exit(context, savedExceptionState);
236246
}
237247
}
238248
}

0 commit comments

Comments
 (0)