@@ -1988,15 +1988,8 @@ clear_gen_frame(PyThreadState *tstate, _PyInterpreterFrame * frame)
19881988void
19891989_PyEval_FrameClearAndPop (PyThreadState * tstate , _PyInterpreterFrame * frame )
19901990{
1991- // Update last_profiled_frame for remote profiler frame caching.
19921991 // By this point, tstate->current_frame is already set to the parent frame.
1993- // Only update if we're popping the exact frame that was last profiled.
1994- // This avoids corrupting the cache when transient frames (called and returned
1995- // between profiler samples) update last_profiled_frame to addresses the
1996- // profiler never saw.
1997- if (tstate -> last_profiled_frame != NULL && tstate -> last_profiled_frame == frame ) {
1998- tstate -> last_profiled_frame = tstate -> current_frame ;
1999- }
1992+ _PyThreadState_UpdateLastProfiledFrame (tstate , frame , tstate -> current_frame );
20001993
20011994 if (frame -> owner == FRAME_OWNED_BY_THREAD ) {
20021995 clear_thread_frame (tstate , frame );
@@ -2022,6 +2015,7 @@ _PyEvalFramePushAndInit(PyThreadState *tstate, _PyStackRef func,
20222015 _PyFrame_Initialize (tstate , frame , func , locals , code , 0 , previous );
20232016 if (initialize_locals (tstate , func_obj , frame -> localsplus , args , argcount , kwnames )) {
20242017 assert (frame -> owner == FRAME_OWNED_BY_THREAD );
2018+ _PyThreadState_UpdateLastProfiledFrame (tstate , frame , tstate -> current_frame );
20252019 clear_thread_frame (tstate , frame );
20262020 return NULL ;
20272021 }
0 commit comments