Skip to content

Commit 56d7bb4

Browse files
committed
gh-141786 Fix missing parent executor during trace
1 parent 53ec7c8 commit 56d7bb4

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
@@ -1407,6 +1407,10 @@ stop_tracing_and_jit(PyThreadState *tstate, _PyInterpreterFrame *frame)
14071407
else {
14081408
// Likewise, we hold a strong reference to the executor containing this exit, so the exit is guaranteed
14091409
// to be valid to access.
1410+
if (!exit->executor->vm_data.linked || !exit->executor->vm_data.valid) {
1411+
// gh-141786 Parent executor is either unlinked or invalid - cannot optimize.
1412+
err = -1;
1413+
}
14101414
if (err <= 0) {
14111415
exit->temperature = restart_backoff_counter(exit->temperature);
14121416
}

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)