@@ -36,17 +36,25 @@ void CInstrumenter::enable_instrumenter()
3636 adopt_object);
3737 }
3838 if (interface == InstrumenterInterface::Trace)
39+ {
3940 PyEval_SetTrace (callback, to_PyObject ());
41+ }
4042 else
43+ {
4144 PyEval_SetProfile (callback, to_PyObject ());
45+ }
4246}
4347
4448void CInstrumenter::disable_instrumenter ()
4549{
4650 if (interface == InstrumenterInterface::Trace)
51+ {
4752 PyEval_SetTrace (nullptr , nullptr );
53+ }
4854 else
55+ {
4956 PyEval_SetProfile (nullptr , nullptr );
57+ }
5058 if (threading_set_instrumenter)
5159 {
5260 PyRefObject result (PyObject_CallFunction (threading_set_instrumenter, " O" , Py_None),
@@ -65,9 +73,13 @@ int index_of(TCollection&& col, const TElement& element)
6573{
6674 const auto it = std::find (col.cbegin (), col.cend (), element);
6775 if (it == col.end ())
76+ {
6877 return -1 ;
78+ }
6979 else
80+ {
7081 return std::distance (col.begin (), it);
82+ }
7183}
7284
7385// Required because: `sys.getprofile()` returns the user object (2nd arg to PyEval_SetTrace)
@@ -81,14 +93,18 @@ PyObject* CInstrumenter::operator()(PyFrameObject& frame, const char* what_strin
8193 // But we might be inside a `sys.settrace` call where the user wanted to set another function
8294 // which would then be overwritten here. Hence use the CALL event which avoids the problem
8395 if (what == PyTrace_CALL)
96+ {
8497 enable_instrumenter ();
98+ }
8599 if (on_event (frame, what, arg))
86100 {
87101 Py_INCREF (to_PyObject ());
88102 return to_PyObject ();
89103 }
90104 else
105+ {
91106 return nullptr ;
107+ }
92108}
93109
94110bool CInstrumenter::on_event (PyFrameObject& frame, int what, PyObject*)
0 commit comments