Skip to content
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Protect the JIT against recursive tracing.
6 changes: 6 additions & 0 deletions Python/optimizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ _PyOptimizer_Optimize(
// return immediately without optimization.
return 0;
}
if (_tstate->jit_tracer_state.initial_state.func == NULL) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't be able to get into this state, should we?
This seems like it should be an assert and the fix should be elsewhere.

// gh-143123: It is possible for another function to finalize the current
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by "another function"? Which other function?

// tracer's state while tracing. This might happen in a
// Python -> C -> Python call.
return 0;
}
assert(!interp->compiling);
assert(_tstate->jit_tracer_state.initial_state.stack_depth >= 0);
#ifndef Py_GIL_DISABLED
Expand Down
Loading