6161import com .oracle .graal .python .nodes .function .builtins .PythonTernaryBuiltinNode ;
6262import com .oracle .graal .python .nodes .function .builtins .PythonUnaryBuiltinNode ;
6363import com .oracle .graal .python .nodes .truffle .PythonArithmeticTypes ;
64+ import com .oracle .graal .python .runtime .ExecutionContext .IndirectCallContext ;
6465import com .oracle .graal .python .runtime .PythonContext ;
66+ import com .oracle .graal .python .runtime .exception .PException ;
6567import com .oracle .graal .python .runtime .exception .PythonErrorType ;
6668import com .oracle .truffle .api .CompilerAsserts ;
6769import 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