@@ -1978,28 +1978,30 @@ do_monitor_exc(PyThreadState *tstate, _PyInterpreterFrame *frame,
19781978 return err ;
19791979}
19801980
1981- static inline int
1982- no_tools_for_event (PyThreadState * tstate , _PyInterpreterFrame * frame , int event )
1981+ static inline bool
1982+ no_tools_for_global_event (PyThreadState * tstate , int event )
19831983{
1984+ return tstate -> interp -> monitors .tools [event ] == 0 ;
1985+ }
1986+
1987+ static inline bool
1988+ no_tools_for_local_event (PyThreadState * tstate , _PyInterpreterFrame * frame , int event )
1989+ {
1990+ assert (event < _PY_MONITORING_LOCAL_EVENTS );
19841991 _PyCoMonitoringData * data = _PyFrame_GetCode (frame )-> _co_monitoring ;
19851992 if (data ) {
1986- if (data -> active_monitors .tools [event ] == 0 ) {
1987- return 1 ;
1988- }
1993+ return data -> active_monitors .tools [event ] == 0 ;
19891994 }
19901995 else {
1991- if (tstate -> interp -> monitors .tools [event ] == 0 ) {
1992- return 1 ;
1993- }
1996+ return no_tools_for_global_event (tstate , event );
19941997 }
1995- return 0 ;
19961998}
19971999
19982000static void
19992001monitor_raise (PyThreadState * tstate , _PyInterpreterFrame * frame ,
20002002 _Py_CODEUNIT * instr )
20012003{
2002- if (no_tools_for_event (tstate , frame , PY_MONITORING_EVENT_RAISE )) {
2004+ if (no_tools_for_global_event (tstate , PY_MONITORING_EVENT_RAISE )) {
20032005 return ;
20042006 }
20052007 do_monitor_exc (tstate , frame , instr , PY_MONITORING_EVENT_RAISE );
@@ -2009,7 +2011,7 @@ static void
20092011monitor_reraise (PyThreadState * tstate , _PyInterpreterFrame * frame ,
20102012 _Py_CODEUNIT * instr )
20112013{
2012- if (no_tools_for_event (tstate , frame , PY_MONITORING_EVENT_RERAISE )) {
2014+ if (no_tools_for_global_event (tstate , PY_MONITORING_EVENT_RERAISE )) {
20132015 return ;
20142016 }
20152017 do_monitor_exc (tstate , frame , instr , PY_MONITORING_EVENT_RERAISE );
@@ -2019,7 +2021,7 @@ static int
20192021monitor_stop_iteration (PyThreadState * tstate , _PyInterpreterFrame * frame ,
20202022 _Py_CODEUNIT * instr )
20212023{
2022- if (no_tools_for_event (tstate , frame , PY_MONITORING_EVENT_STOP_ITERATION )) {
2024+ if (no_tools_for_local_event (tstate , frame , PY_MONITORING_EVENT_STOP_ITERATION )) {
20232025 return 0 ;
20242026 }
20252027 return do_monitor_exc (tstate , frame , instr , PY_MONITORING_EVENT_STOP_ITERATION );
@@ -2030,7 +2032,7 @@ monitor_unwind(PyThreadState *tstate,
20302032 _PyInterpreterFrame * frame ,
20312033 _Py_CODEUNIT * instr )
20322034{
2033- if (no_tools_for_event (tstate , frame , PY_MONITORING_EVENT_PY_UNWIND )) {
2035+ if (no_tools_for_global_event (tstate , PY_MONITORING_EVENT_PY_UNWIND )) {
20342036 return ;
20352037 }
20362038 do_monitor_exc (tstate , frame , instr , PY_MONITORING_EVENT_PY_UNWIND );
@@ -2042,7 +2044,7 @@ monitor_handled(PyThreadState *tstate,
20422044 _PyInterpreterFrame * frame ,
20432045 _Py_CODEUNIT * instr , PyObject * exc )
20442046{
2045- if (no_tools_for_event (tstate , frame , PY_MONITORING_EVENT_EXCEPTION_HANDLED )) {
2047+ if (no_tools_for_global_event (tstate , PY_MONITORING_EVENT_EXCEPTION_HANDLED )) {
20462048 return 0 ;
20472049 }
20482050 return _Py_call_instrumentation_arg (tstate , PY_MONITORING_EVENT_EXCEPTION_HANDLED , frame , instr , exc );
@@ -2053,7 +2055,7 @@ monitor_throw(PyThreadState *tstate,
20532055 _PyInterpreterFrame * frame ,
20542056 _Py_CODEUNIT * instr )
20552057{
2056- if (no_tools_for_event (tstate , frame , PY_MONITORING_EVENT_PY_THROW )) {
2058+ if (no_tools_for_global_event (tstate , PY_MONITORING_EVENT_PY_THROW )) {
20572059 return ;
20582060 }
20592061 do_monitor_exc (tstate , frame , instr , PY_MONITORING_EVENT_PY_THROW );
0 commit comments