@@ -1974,15 +1974,8 @@ clear_gen_frame(PyThreadState *tstate, _PyInterpreterFrame * frame)
19741974void
19751975_PyEval_FrameClearAndPop (PyThreadState * tstate , _PyInterpreterFrame * frame )
19761976{
1977- // Update last_profiled_frame for remote profiler frame caching.
19781977 // By this point, tstate->current_frame is already set to the parent frame.
1979- // Only update if we're popping the exact frame that was last profiled.
1980- // This avoids corrupting the cache when transient frames (called and returned
1981- // between profiler samples) update last_profiled_frame to addresses the
1982- // profiler never saw.
1983- if (tstate -> last_profiled_frame != NULL && tstate -> last_profiled_frame == frame ) {
1984- tstate -> last_profiled_frame = tstate -> current_frame ;
1985- }
1978+ _PyThreadState_UpdateLastProfiledFrame (tstate , frame , tstate -> current_frame );
19861979
19871980 if (frame -> owner == FRAME_OWNED_BY_THREAD ) {
19881981 clear_thread_frame (tstate , frame );
@@ -2008,6 +2001,7 @@ _PyEvalFramePushAndInit(PyThreadState *tstate, _PyStackRef func,
20082001 _PyFrame_Initialize (tstate , frame , func , locals , code , 0 , previous );
20092002 if (initialize_locals (tstate , func_obj , frame -> localsplus , args , argcount , kwnames )) {
20102003 assert (frame -> owner == FRAME_OWNED_BY_THREAD );
2004+ _PyThreadState_UpdateLastProfiledFrame (tstate , frame , tstate -> current_frame );
20112005 clear_thread_frame (tstate , frame );
20122006 return NULL ;
20132007 }
0 commit comments