5353import com .oracle .graal .python .nodes .frame .ReadFrameNode ;
5454import com .oracle .graal .python .nodes .util .ExceptionStateNodes .GetCaughtExceptionNode ;
5555import com .oracle .graal .python .runtime .IndirectCallData .BoundaryCallData ;
56+ import com .oracle .graal .python .runtime .IndirectCallData .IndirectCallDataBase ;
5657import com .oracle .graal .python .runtime .IndirectCallData .InteropCallData ;
5758import com .oracle .graal .python .runtime .PythonContext .PythonThreadState ;
5859import com .oracle .graal .python .runtime .exception .PException ;
@@ -513,7 +514,7 @@ public static Object enter(VirtualFrame frame, BoundaryCallData boundaryCallData
513514
514515 private static Object enterWithPythonFrame (VirtualFrame frame , BoundaryCallData boundaryCallData , PythonThreadState pythonThreadState ) {
515516 assert frame != null ;
516- return IndirectCallContext .enterWithPythonFrame (frame , boundaryCallData , pythonThreadState , boundaryCallData .getCallerFlags (), EMPTY_SAVED_STATE );
517+ return IndirectCallContext .enterWithPythonFrame (frame , boundaryCallData , boundaryCallData , pythonThreadState , boundaryCallData .getCallerFlags (), EMPTY_SAVED_STATE );
517518 }
518519
519520 public static void exit (VirtualFrame frame , PythonLanguage language , PythonContext context , Object savedState ) {
@@ -596,7 +597,7 @@ public static Object enter(VirtualFrame frame, Node node, InteropCallData callDa
596597
597598 private static Object enterWithPythonFrame (VirtualFrame frame , InteropCallData callData , PythonThreadState pythonThreadState ) {
598599 assert frame != null ;
599- return IndirectCallContext .enterWithPythonFrame (frame , null , pythonThreadState , callData .getCallerFlags (), null );
600+ return IndirectCallContext .enterWithPythonFrame (frame , callData , null , pythonThreadState , callData .getCallerFlags (), null );
600601 }
601602
602603 public static void exit (VirtualFrame frame , PythonLanguage language , PythonContext context , Object savedState ) {
@@ -635,8 +636,8 @@ public static void exit(VirtualFrame frame, PythonThreadState pythonThreadState,
635636
636637 // Common code shared by BoundaryCallContext and InteropCallContext
637638 public abstract static class IndirectCallContext {
638- private static Object enterWithPythonFrame (VirtualFrame frame , Node encapsulatingNodeToPush , PythonThreadState pythonThreadState ,
639- int callerFlags , Object defaultReturn ) {
639+ private static Object enterWithPythonFrame (VirtualFrame frame , IndirectCallDataBase callData , Node encapsulatingNodeToPush ,
640+ PythonThreadState pythonThreadState , int callerFlags , Object defaultReturn ) {
640641 CompilerAsserts .partialEvaluationConstant (encapsulatingNodeToPush == null );
641642 CompilerAsserts .partialEvaluationConstant (defaultReturn );
642643 if (callerFlags == 0 ) {
@@ -654,18 +655,24 @@ private static Object enterWithPythonFrame(VirtualFrame frame, Node encapsulatin
654655 }
655656 }
656657
657- return enterSlowPath (frame , encapsulatingNodeToPush , pythonThreadState , callerFlags , defaultReturn );
658+ return enterSlowPath (frame , callData , encapsulatingNodeToPush , pythonThreadState , callerFlags , defaultReturn );
658659 }
659660
660- private static Object enterSlowPath (VirtualFrame frame , Node encapsulatingNodeToPush , PythonThreadState pythonThreadState ,
661- int callerFlags , Object defaultReturn ) {
661+ private static Object enterSlowPath (VirtualFrame frame , IndirectCallDataBase callData , Node encapsulatingNodeToPush ,
662+ PythonThreadState pythonThreadState , int callerFlags , Object defaultReturn ) {
662663 PFrame .Reference info = null ;
663664 if (CallerFlags .needsFrameReference (callerFlags )) {
664665 PFrame .Reference prev = pythonThreadState .popTopFrameInfo ();
665666 assert prev == null : "trying to call from Python to a foreign function, but we didn't clear the topframeref. " +
666667 "This indicates that a call into Python code happened without a proper enter through IndirectCalleeContext" ;
667668 info = PArguments .getCurrentFrameInfo (frame );
668669 pythonThreadState .setTopFrameInfo (info );
670+ if (CallerFlags .needsPFrame (callerFlags )) {
671+ callData .getMaterializeFrameNode ().executeOnStack (false , CallerFlags .needsLocals (callerFlags ), frame );
672+ } else if (info .getPyFrame () != null ) {
673+ // Avoid passing stale locals
674+ info .getPyFrame ().setLocals (null );
675+ }
669676 }
670677 AbstractTruffleException curExc = pythonThreadState .getCaughtException ();
671678 AbstractTruffleException exceptionState = PArguments .getException (frame );
0 commit comments