Skip to content

Commit 0678505

Browse files
Fix a bug
1 parent cdbbbe3 commit 0678505

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

Include/internal/pycore_optimizer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ typedef struct _PyExitData {
4747
typedef struct _PyExecutorObject {
4848
PyObject_VAR_HEAD
4949
const _PyUOpInstruction *trace;
50+
// The interpreter this executor belongs to.
51+
PyInterpreterState *interp;
5052
_PyVMData vm_data; /* Used by the VM, but opaque to the optimizer */
5153
uint32_t exit_count;
5254
uint32_t code_size;

Python/optimizer.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,8 +1647,11 @@ unlink_executor(_PyExecutorObject *executor)
16471647
prev->vm_data.links.next = next;
16481648
}
16491649
else {
1650-
// prev == NULL implies that executor is the list head
1651-
PyInterpreterState *interp = PyInterpreterState_Get();
1650+
// prev == NULL often implies that executor is the list head
1651+
// Note that we should *not* get the current interpreter, as
1652+
// that may not always correspond to the interpreter this executor
1653+
// belongs to.
1654+
PyInterpreterState *interp = executor->interp;
16521655
assert(interp->executor_list_head == executor);
16531656
interp->executor_list_head = next;
16541657
}
@@ -1663,6 +1666,7 @@ _Py_ExecutorInit(_PyExecutorObject *executor, const _PyBloomFilter *dependency_s
16631666
for (int i = 0; i < _Py_BLOOM_FILTER_WORDS; i++) {
16641667
executor->vm_data.bloom.bits[i] = dependency_set->bits[i];
16651668
}
1669+
executor->interp = _PyInterpreterState_GET();
16661670
link_executor(executor);
16671671
}
16681672

0 commit comments

Comments
 (0)