@@ -903,26 +903,34 @@ instrumentation_cross_checks(PyInterpreterState *interp, PyCodeObject *code)
903903#endif
904904
905905static inline uint8_t
906- get_tools_for_instruction (PyCodeObject * code ,int i ,int event )
906+ get_tools_for_instruction (PyCodeObject * code , PyInterpreterState * interp ,int i ,int event )
907907{
908908uint8_t tools ;
909909assert (event != PY_MONITORING_EVENT_LINE );
910910assert (event != PY_MONITORING_EVENT_INSTRUCTION );
911- assert (instrumentation_cross_checks (PyThreadState_GET ()-> interp ,code ));
912- _PyCoMonitoringData * monitoring = code -> _co_monitoring ;
913911if (event >=PY_MONITORING_UNGROUPED_EVENTS ) {
914912assert (event == PY_MONITORING_EVENT_C_RAISE ||
915913event == PY_MONITORING_EVENT_C_RETURN );
916914event = PY_MONITORING_EVENT_CALL ;
917915 }
918- if (event < PY_MONITORING_INSTRUMENTED_EVENTS && monitoring -> tools ) {
919- tools = monitoring -> tools [i ];
916+ if (event < PY_MONITORING_INSTRUMENTED_EVENTS ) {
917+ CHECK (is_version_up_to_date (code ,interp ));
918+ CHECK (instrumentation_cross_checks (interp ,code ));
919+ if (code -> _co_monitoring -> tools ) {
920+ tools = code -> _co_monitoring -> tools [i ];
921+ }
922+ else {
923+ tools = code -> _co_monitoring -> active_monitors .tools [event ];
924+ }
920925 }
921926else {
922- tools = code -> _co_monitoring -> active_monitors .tools [event ];
927+ if (code -> _co_monitoring ) {
928+ tools = code -> _co_monitoring -> active_monitors .tools [event ];
929+ }
930+ else {
931+ tools = interp -> monitors .tools [event ];
932+ }
923933 }
924- CHECK (tools_is_subset_for_event (code ,event ,tools ));
925- CHECK ((tools & code -> _co_monitoring -> active_monitors .tools [event ])== tools );
926934return tools ;
927935}
928936
@@ -937,9 +945,6 @@ call_instrumentation_vector(
937945assert (!_PyErr_Occurred (tstate ));
938946assert (args [0 ]== NULL );
939947PyCodeObject * code = _PyFrame_GetCode (frame );
940- assert (code -> _co_instrumentation_version == tstate -> interp -> monitoring_version );
941- assert (is_version_up_to_date (code ,tstate -> interp ));
942- assert (instrumentation_cross_checks (tstate -> interp ,code ));
943948assert (args [1 ]== NULL );
944949args [1 ]= (PyObject * )code ;
945950int offset = (int )(instr - _PyCode_CODE (code ));
@@ -952,11 +957,11 @@ call_instrumentation_vector(
952957 }
953958assert (args [2 ]== NULL );
954959args [2 ]= offset_obj ;
955- uint8_t tools = get_tools_for_instruction (code ,offset ,event );
960+ PyInterpreterState * interp = tstate -> interp ;
961+ uint8_t tools = get_tools_for_instruction (code ,interp ,offset ,event );
956962Py_ssize_t nargsf = nargs |PY_VECTORCALL_ARGUMENTS_OFFSET ;
957963PyObject * * callargs = & args [1 ];
958964int err = 0 ;
959- PyInterpreterState * interp = tstate -> interp ;
960965while (tools ) {
961966int tool = most_significant_bit (tools );
962967assert (tool >=0 && tool < 8 );