@@ -5439,10 +5439,12 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
5439
5439
}
5440
5440
5441
5441
#if USE_COMPUTED_GOTOS
5442
- TARGET_DO_TRACING : {
5442
+ TARGET_DO_TRACING :
5443
5443
#else
5444
- case DO_TRACING : {
5444
+ case DO_TRACING :
5445
5445
#endif
5446
+ {
5447
+ if (tstate -> tracing == 0 ) {
5446
5448
int instr_prev = skip_backwards_over_extended_args (frame -> f_code , frame -> f_lasti );
5447
5449
frame -> f_lasti = INSTR_OFFSET ();
5448
5450
TRACING_NEXTOPARG ();
@@ -5482,11 +5484,11 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
5482
5484
frame -> stacktop = -1 ;
5483
5485
}
5484
5486
}
5485
- TRACING_NEXTOPARG ();
5486
- PRE_DISPATCH_GOTO ();
5487
- DISPATCH_GOTO ();
5488
5487
}
5489
-
5488
+ TRACING_NEXTOPARG ();
5489
+ PRE_DISPATCH_GOTO ();
5490
+ DISPATCH_GOTO ();
5491
+ }
5490
5492
5491
5493
#if USE_COMPUTED_GOTOS
5492
5494
_unknown_opcode :
@@ -6673,27 +6675,38 @@ initialize_trace_info(PyTraceInfo *trace_info, _PyInterpreterFrame *frame)
6673
6675
}
6674
6676
}
6675
6677
6678
+ void
6679
+ PyThreadState_EnterTracing (PyThreadState * tstate )
6680
+ {
6681
+ tstate -> tracing ++ ;
6682
+ }
6683
+
6684
+ void
6685
+ PyThreadState_LeaveTracing (PyThreadState * tstate )
6686
+ {
6687
+ tstate -> tracing -- ;
6688
+ }
6689
+
6676
6690
static int
6677
6691
call_trace (Py_tracefunc func , PyObject * obj ,
6678
6692
PyThreadState * tstate , _PyInterpreterFrame * frame ,
6679
6693
int what , PyObject * arg )
6680
6694
{
6681
6695
int result ;
6682
- if (tstate -> tracing )
6696
+ if (tstate -> tracing ) {
6683
6697
return 0 ;
6684
- tstate -> tracing ++ ;
6685
- _PyThreadState_PauseTracing (tstate );
6698
+ }
6686
6699
PyFrameObject * f = _PyFrame_GetFrameObject (frame );
6687
6700
if (f == NULL ) {
6688
6701
return -1 ;
6689
6702
}
6703
+ PyThreadState_EnterTracing (tstate );
6690
6704
assert (frame -> f_lasti >= 0 );
6691
6705
initialize_trace_info (& tstate -> trace_info , frame );
6692
6706
f -> f_lineno = _PyCode_CheckLineNumber (frame -> f_lasti * sizeof (_Py_CODEUNIT ), & tstate -> trace_info .bounds );
6693
6707
result = func (obj , f , what , arg );
6694
6708
f -> f_lineno = 0 ;
6695
- _PyThreadState_ResumeTracing (tstate );
6696
- tstate -> tracing -- ;
6709
+ PyThreadState_LeaveTracing (tstate );
6697
6710
return result ;
6698
6711
}
6699
6712
@@ -6706,7 +6719,6 @@ _PyEval_CallTracing(PyObject *func, PyObject *args)
6706
6719
PyObject * result ;
6707
6720
6708
6721
tstate -> tracing = 0 ;
6709
- _PyThreadState_ResumeTracing (tstate );
6710
6722
result = PyObject_Call (func , args , NULL );
6711
6723
tstate -> tracing = save_tracing ;
6712
6724
tstate -> cframe -> use_tracing = save_use_tracing ;
@@ -6773,15 +6785,15 @@ _PyEval_SetProfile(PyThreadState *tstate, Py_tracefunc func, PyObject *arg)
6773
6785
tstate -> c_profilefunc = NULL ;
6774
6786
tstate -> c_profileobj = NULL ;
6775
6787
/* Must make sure that tracing is not ignored if 'profileobj' is freed */
6776
- _PyThreadState_ResumeTracing (tstate );
6788
+ _PyThreadState_UpdateTracingState (tstate );
6777
6789
Py_XDECREF (profileobj );
6778
6790
6779
6791
Py_XINCREF (arg );
6780
6792
tstate -> c_profileobj = arg ;
6781
6793
tstate -> c_profilefunc = func ;
6782
6794
6783
6795
/* Flag that tracing or profiling is turned on */
6784
- _PyThreadState_ResumeTracing (tstate );
6796
+ _PyThreadState_UpdateTracingState (tstate );
6785
6797
return 0 ;
6786
6798
}
6787
6799
@@ -6814,15 +6826,15 @@ _PyEval_SetTrace(PyThreadState *tstate, Py_tracefunc func, PyObject *arg)
6814
6826
tstate -> c_tracefunc = NULL ;
6815
6827
tstate -> c_traceobj = NULL ;
6816
6828
/* Must make sure that profiling is not ignored if 'traceobj' is freed */
6817
- _PyThreadState_ResumeTracing (tstate );
6829
+ _PyThreadState_UpdateTracingState (tstate );
6818
6830
Py_XDECREF (traceobj );
6819
6831
6820
6832
Py_XINCREF (arg );
6821
6833
tstate -> c_traceobj = arg ;
6822
6834
tstate -> c_tracefunc = func ;
6823
6835
6824
6836
/* Flag that tracing or profiling is turned on */
6825
- _PyThreadState_ResumeTracing (tstate );
6837
+ _PyThreadState_UpdateTracingState (tstate );
6826
6838
6827
6839
return 0 ;
6828
6840
}
0 commit comments