@@ -1972,15 +1972,8 @@ clear_gen_frame(PyThreadState *tstate, _PyInterpreterFrame * frame)
19721972void
19731973_PyEval_FrameClearAndPop (PyThreadState * tstate , _PyInterpreterFrame * frame )
19741974{
1975- // Update last_profiled_frame for remote profiler frame caching.
19761975 // By this point, tstate->current_frame is already set to the parent frame.
1977- // Only update if we're popping the exact frame that was last profiled.
1978- // This avoids corrupting the cache when transient frames (called and returned
1979- // between profiler samples) update last_profiled_frame to addresses the
1980- // profiler never saw.
1981- if (tstate -> last_profiled_frame != NULL && tstate -> last_profiled_frame == frame ) {
1982- tstate -> last_profiled_frame = tstate -> current_frame ;
1983- }
1976+ _PyThreadState_UpdateLastProfiledFrame (tstate , frame , tstate -> current_frame );
19841977
19851978 if (frame -> owner == FRAME_OWNED_BY_THREAD ) {
19861979 clear_thread_frame (tstate , frame );
@@ -2006,9 +1999,7 @@ _PyEvalFramePushAndInit(PyThreadState *tstate, _PyStackRef func,
20061999 _PyFrame_Initialize (tstate , frame , func , locals , code , 0 , previous );
20072000 if (initialize_locals (tstate , func_obj , frame -> localsplus , args , argcount , kwnames )) {
20082001 assert (frame -> owner == FRAME_OWNED_BY_THREAD );
2009- if (tstate -> last_profiled_frame == frame ) {
2010- tstate -> last_profiled_frame = tstate -> current_frame ;
2011- }
2002+ _PyThreadState_UpdateLastProfiledFrame (tstate , frame , tstate -> current_frame );
20122003 clear_thread_frame (tstate , frame );
20132004 return NULL ;
20142005 }
0 commit comments