File tree 2 files changed +16
-1
lines changed 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -1841,6 +1841,21 @@ def f(a=1, b=2):
1841
1841
self .assertEqual (call_data [0 ], (f , 1 ))
1842
1842
self .assertEqual (call_data [1 ], (f , sys .monitoring .MISSING ))
1843
1843
1844
+ def test_instruction_explicit_callback (self ):
1845
+ # gh-122247
1846
+ # Calling the instruction event callback explicitly should not
1847
+ # crash CPython
1848
+ def callback (code , instruction_offset ):
1849
+ pass
1850
+
1851
+ sys .monitoring .use_tool_id (0 , "test" )
1852
+ self .addCleanup (sys .monitoring .free_tool_id , 0 )
1853
+ sys .monitoring .register_callback (0 , sys .monitoring .events .INSTRUCTION , callback )
1854
+ sys .monitoring .set_events (0 , sys .monitoring .events .INSTRUCTION )
1855
+ callback (None , 0 ) # call the *same* handler while it is registered
1856
+ sys .monitoring .restart_events ()
1857
+ sys .monitoring .set_events (0 , 0 )
1858
+
1844
1859
1845
1860
class TestOptimizer (MonitoringTestBase , unittest .TestCase ):
1846
1861
Original file line number Diff line number Diff line change @@ -1344,14 +1344,14 @@ int
1344
1344
_Py_call_instrumentation_instruction (PyThreadState * tstate , _PyInterpreterFrame * frame , _Py_CODEUNIT * instr )
1345
1345
{
1346
1346
PyCodeObject * code = _PyFrame_GetCode (frame );
1347
- assert (debug_check_sanity (tstate -> interp , code ));
1348
1347
int offset = (int )(instr - _PyCode_CODE (code ));
1349
1348
_PyCoMonitoringData * instrumentation_data = code -> _co_monitoring ;
1350
1349
assert (instrumentation_data -> per_instruction_opcodes );
1351
1350
int next_opcode = instrumentation_data -> per_instruction_opcodes [offset ];
1352
1351
if (tstate -> tracing ) {
1353
1352
return next_opcode ;
1354
1353
}
1354
+ assert (debug_check_sanity (tstate -> interp , code ));
1355
1355
PyInterpreterState * interp = tstate -> interp ;
1356
1356
uint8_t tools = instrumentation_data -> per_instruction_tools != NULL ?
1357
1357
instrumentation_data -> per_instruction_tools [offset ] :
You can’t perform that action at this time.
0 commit comments