Skip to content

Commit fa9a746

Browse files
committed
gh-141786 Fix missing parent executor during trace
1 parent 41b9ad5 commit fa9a746

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

Python/ceval.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,6 +1123,10 @@ stop_tracing_and_jit(PyThreadState *tstate, _PyInterpreterFrame *frame)
11231123
else {
11241124
// Likewise, we hold a strong reference to the executor containing this exit, so the exit is guaranteed
11251125
// to be valid to access.
1126+
if (!exit->executor->vm_data.linked || !exit->executor->vm_data.valid) {
1127+
// gh-141786 Parent executor is either unlinked or invalid - cannot optimize.
1128+
err = -1;
1129+
}
11261130
if (err <= 0) {
11271131
exit->temperature = restart_backoff_counter(exit->temperature);
11281132
}

Python/optimizer.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ _PyOptimizer_Optimize(
140140
}
141141
assert(!interp->compiling);
142142
assert(_tstate->jit_tracer_state.initial_state.stack_depth >= 0);
143+
_PyExitData *exit = _tstate->jit_tracer_state.initial_state.exit;
144+
if (exit != NULL && (!exit->executor->vm_data.linked || !exit->executor->vm_data.valid)) {
145+
// gh-141786 Parent executor is either unlinked or invalid - cannot optimize.
146+
return 0;
147+
}
143148
#ifndef Py_GIL_DISABLED
144149
assert(_tstate->jit_tracer_state.initial_state.func != NULL);
145150
interp->compiling = true;
@@ -185,7 +190,6 @@ _PyOptimizer_Optimize(
185190
else {
186191
executor->vm_data.code = NULL;
187192
}
188-
_PyExitData *exit = _tstate->jit_tracer_state.initial_state.exit;
189193
if (exit != NULL) {
190194
exit->executor = executor;
191195
}

0 commit comments

Comments
 (0)