3939#endif
4040
4141#ifdef Py_GIL_DISABLED
42-
42+ // MODIFY_BYTECODE modifies thread local bytecode of all threads,
43+ // so it must be called with the world stopped.
4344#define MODIFY_BYTECODE (code , func , ...) \
4445 do { \
4546 ASSERT_WORLD_STOPPED(); \
@@ -671,6 +672,7 @@ de_instrument(PyCodeObject *code, _Py_CODEUNIT *bytecode, _PyCoMonitoringData *m
671672{
672673 assert (event != PY_MONITORING_EVENT_INSTRUCTION );
673674 assert (event != PY_MONITORING_EVENT_LINE );
675+ ASSERT_WORLD_STOPPED ();
674676
675677 _Py_CODEUNIT * instr = & bytecode [i ];
676678 uint8_t * opcode_ptr = & instr -> op .code ;
@@ -700,6 +702,7 @@ static void
700702de_instrument_line (PyCodeObject * code , _Py_CODEUNIT * bytecode , _PyCoMonitoringData * monitoring ,
701703 int i )
702704{
705+ ASSERT_WORLD_STOPPED ();
703706 _Py_CODEUNIT * instr = & bytecode [i ];
704707 int opcode = instr -> op .code ;
705708 if (opcode != INSTRUMENTED_LINE ) {
@@ -724,6 +727,7 @@ static void
724727de_instrument_per_instruction (PyCodeObject * code , _Py_CODEUNIT * bytecode ,
725728 _PyCoMonitoringData * monitoring , int i )
726729{
730+ ASSERT_WORLD_STOPPED ();
727731 _Py_CODEUNIT * instr = & bytecode [i ];
728732 uint8_t * opcode_ptr = & instr -> op .code ;
729733 int opcode = * opcode_ptr ;
@@ -749,6 +753,7 @@ de_instrument_per_instruction(PyCodeObject *code, _Py_CODEUNIT *bytecode,
749753static void
750754instrument (PyCodeObject * code , _Py_CODEUNIT * bytecode , _PyCoMonitoringData * monitoring , int i )
751755{
756+ ASSERT_WORLD_STOPPED ();
752757 _Py_CODEUNIT * instr = & bytecode [i ];
753758 uint8_t * opcode_ptr = & instr -> op .code ;
754759 int opcode = * opcode_ptr ;
@@ -778,6 +783,7 @@ instrument(PyCodeObject *code, _Py_CODEUNIT *bytecode, _PyCoMonitoringData *moni
778783static void
779784instrument_line (PyCodeObject * code , _Py_CODEUNIT * bytecode , _PyCoMonitoringData * monitoring , int i )
780785{
786+ ASSERT_WORLD_STOPPED ();
781787 uint8_t * opcode_ptr = & bytecode [i ].op .code ;
782788 int opcode = * opcode_ptr ;
783789 if (opcode == INSTRUMENTED_LINE ) {
@@ -792,6 +798,7 @@ static void
792798instrument_per_instruction (PyCodeObject * code , _Py_CODEUNIT * bytecode ,
793799 _PyCoMonitoringData * monitoring , int i )
794800{
801+ ASSERT_WORLD_STOPPED ();
795802 _Py_CODEUNIT * instr = & bytecode [i ];
796803 uint8_t * opcode_ptr = & instr -> op .code ;
797804 int opcode = * opcode_ptr ;
0 commit comments