3
3
#include "opcode_ids.h"
4
4
5
5
#include "pycore_call.h"
6
+ #include "pycore_code.h" // _PyCode_Clear_Executors()
6
7
#include "pycore_frame.h"
7
8
#include "pycore_interp.h"
8
9
#include "pycore_long.h"
@@ -583,13 +584,7 @@ de_instrument(PyCodeObject *code, int i, int event)
583
584
_Py_CODEUNIT * instr = & _PyCode_CODE (code )[i ];
584
585
uint8_t * opcode_ptr = & instr -> op .code ;
585
586
int opcode = * opcode_ptr ;
586
- if (opcode == ENTER_EXECUTOR ) {
587
- int oparg = instr -> op .arg ;
588
- _PyExecutorObject * exec = code -> co_executors -> executors [oparg ];
589
- opcode_ptr = & exec -> vm_data .opcode ;
590
- opcode = * opcode_ptr ;
591
- assert (opcode != ENTER_EXECUTOR );
592
- }
587
+ assert (opcode != ENTER_EXECUTOR );
593
588
if (opcode == INSTRUMENTED_LINE ) {
594
589
opcode_ptr = & code -> _co_monitoring -> lines [i ].original_opcode ;
595
590
opcode = * opcode_ptr ;
@@ -734,22 +729,7 @@ remove_tools(PyCodeObject * code, int offset, int event, int tools)
734
729
assert (event != PY_MONITORING_EVENT_LINE );
735
730
assert (event != PY_MONITORING_EVENT_INSTRUCTION );
736
731
assert (PY_MONITORING_IS_INSTRUMENTED_EVENT (event ));
737
- #ifndef NDEBUG
738
- _Py_CODEUNIT co_instr = _PyCode_CODE (code )[offset ];
739
- uint8_t opcode = co_instr .op .code ;
740
- uint8_t oparg = co_instr .op .arg ;
741
- if (opcode == ENTER_EXECUTOR ) {
742
- _PyExecutorObject * exec = code -> co_executors -> executors [oparg ];
743
- assert (exec -> vm_data .opcode != ENTER_EXECUTOR );
744
- opcode = _PyOpcode_Deopt [exec -> vm_data .opcode ];
745
- opcode = exec -> vm_data .oparg ;
746
- }
747
- else {
748
- opcode = _Py_GetBaseOpcode (code , offset );
749
- }
750
- assert (opcode != ENTER_EXECUTOR );
751
- assert (opcode_has_event (opcode ));
752
- #endif
732
+ assert (opcode_has_event (_Py_GetBaseOpcode (code , offset )));
753
733
_PyCoMonitoringData * monitoring = code -> _co_monitoring ;
754
734
if (monitoring && monitoring -> tools ) {
755
735
monitoring -> tools [offset ] &= ~tools ;
@@ -1315,16 +1295,10 @@ initialize_tools(PyCodeObject *code)
1315
1295
for (int i = 0 ; i < code_len ; i ++ ) {
1316
1296
_Py_CODEUNIT * instr = & _PyCode_CODE (code )[i ];
1317
1297
int opcode = instr -> op .code ;
1318
- int oparg = instr -> op .arg ;
1319
- if (opcode == ENTER_EXECUTOR ) {
1320
- _PyExecutorObject * exec = code -> co_executors -> executors [oparg ];
1321
- opcode = exec -> vm_data .opcode ;
1322
- oparg = exec -> vm_data .oparg ;
1323
- }
1324
- else if (opcode == INSTRUMENTED_LINE ) {
1298
+ assert (opcode != ENTER_EXECUTOR );
1299
+ if (opcode == INSTRUMENTED_LINE ) {
1325
1300
opcode = code -> _co_monitoring -> lines [i ].original_opcode ;
1326
1301
}
1327
- assert (opcode != ENTER_EXECUTOR );
1328
1302
bool instrumented = is_instrumented (opcode );
1329
1303
if (instrumented ) {
1330
1304
opcode = DE_INSTRUMENT [opcode ];
@@ -1335,7 +1309,7 @@ initialize_tools(PyCodeObject *code)
1335
1309
if (instrumented ) {
1336
1310
int8_t event ;
1337
1311
if (opcode == RESUME ) {
1338
- event = oparg != 0 ;
1312
+ event = instr -> op . arg != 0 ;
1339
1313
}
1340
1314
else {
1341
1315
event = EVENT_FOR_OPCODE [opcode ];
@@ -1588,6 +1562,9 @@ _Py_Instrument(PyCodeObject *code, PyInterpreterState *interp)
1588
1562
);
1589
1563
return 0 ;
1590
1564
}
1565
+ if (code -> co_executors != NULL ) {
1566
+ _PyCode_Clear_Executors (code );
1567
+ }
1591
1568
int code_len = (int )Py_SIZE (code );
1592
1569
/* code->_co_firsttraceable >= code_len indicates
1593
1570
* that no instrumentation can be inserted.
@@ -1629,7 +1606,9 @@ _Py_Instrument(PyCodeObject *code, PyInterpreterState *interp)
1629
1606
for (int i = code -> _co_firsttraceable ; i < code_len ; i += _PyInstruction_GetLength (code , i )) {
1630
1607
_Py_CODEUNIT * instr = & _PyCode_CODE (code )[i ];
1631
1608
CHECK (instr -> op .code != 0 );
1609
+ assert (instr -> op .code != ENTER_EXECUTOR );
1632
1610
int base_opcode = _Py_GetBaseOpcode (code , i );
1611
+ assert (base_opcode != ENTER_EXECUTOR );
1633
1612
if (opcode_has_event (base_opcode )) {
1634
1613
int8_t event ;
1635
1614
if (base_opcode == RESUME ) {
0 commit comments