@@ -82,10 +82,12 @@ get_index_for_executor(PyCodeObject *code, _Py_CODEUNIT *instr)
82
82
static void
83
83
insert_executor (PyCodeObject * code , _Py_CODEUNIT * instr , int index , _PyExecutorObject * executor )
84
84
{
85
+ _PyExecutorObject * old_executor = NULL ;
85
86
Py_INCREF (executor );
86
87
if (instr -> op .code == ENTER_EXECUTOR ) {
87
88
assert (index == instr -> op .arg );
88
- _Py_ExecutorClear (code -> co_executors -> executors [index ]);
89
+ old_executor = code -> co_executors -> executors [index ];
90
+ code -> co_executors -> executors [index ] = NULL ;
89
91
}
90
92
else {
91
93
assert (code -> co_executors -> size == index );
@@ -100,6 +102,7 @@ insert_executor(PyCodeObject *code, _Py_CODEUNIT *instr, int index, _PyExecutorO
100
102
assert (index < MAX_EXECUTORS_SIZE );
101
103
instr -> op .code = ENTER_EXECUTOR ;
102
104
instr -> op .arg = index ;
105
+ Py_XDECREF (old_executor );
103
106
}
104
107
105
108
int
@@ -1591,13 +1594,14 @@ _Py_ExecutorClear(_PyExecutorObject *executor)
1591
1594
executor -> exits [i ].temperature = initial_unreachable_backoff_counter ();
1592
1595
}
1593
1596
_Py_CODEUNIT * instruction = & _PyCode_CODE (code )[executor -> vm_data .index ];
1594
- assert (instruction -> op .code == ENTER_EXECUTOR );
1595
- int index = instruction -> op .arg ;
1596
- assert (code -> co_executors -> executors [index ] == executor );
1597
- instruction -> op .code = executor -> vm_data .opcode ;
1598
- instruction -> op .arg = executor -> vm_data .oparg ;
1599
- executor -> vm_data .code = NULL ;
1600
- Py_CLEAR (code -> co_executors -> executors [index ]);
1597
+ if (instruction -> op .code == ENTER_EXECUTOR ) {
1598
+ int index = instruction -> op .arg ;
1599
+ assert (code -> co_executors -> executors [index ] == executor );
1600
+ instruction -> op .code = executor -> vm_data .opcode ;
1601
+ instruction -> op .arg = executor -> vm_data .oparg ;
1602
+ executor -> vm_data .code = NULL ;
1603
+ Py_CLEAR (code -> co_executors -> executors [index ]);
1604
+ }
1601
1605
}
1602
1606
1603
1607
void
0 commit comments