mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
gh-140936: Fix JIT assertion crash at finalization if some generator is alive (GH-140969)
This commit is contained in:
parent
1f381a579c
commit
35ed3e4ced
2 changed files with 26 additions and 1 deletions
|
|
@ -2660,6 +2660,25 @@ def f():
|
||||||
|
|
||||||
f()
|
f()
|
||||||
|
|
||||||
|
def test_interpreter_finalization_with_generator_alive(self):
|
||||||
|
script_helper.assert_python_ok("-c", textwrap.dedent("""
|
||||||
|
import sys
|
||||||
|
t = tuple(range(%d))
|
||||||
|
def simple_for():
|
||||||
|
for x in t:
|
||||||
|
x
|
||||||
|
|
||||||
|
def gen():
|
||||||
|
try:
|
||||||
|
yield
|
||||||
|
except:
|
||||||
|
simple_for()
|
||||||
|
|
||||||
|
sys.settrace(lambda *args: None)
|
||||||
|
simple_for()
|
||||||
|
g = gen()
|
||||||
|
next(g)
|
||||||
|
""" % _testinternalcapi.SPECIALIZATION_THRESHOLD))
|
||||||
|
|
||||||
|
|
||||||
def global_identity(x):
|
def global_identity(x):
|
||||||
|
|
|
||||||
|
|
@ -118,7 +118,13 @@ _PyOptimizer_Optimize(
|
||||||
{
|
{
|
||||||
_PyStackRef *stack_pointer = frame->stackpointer;
|
_PyStackRef *stack_pointer = frame->stackpointer;
|
||||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
PyInterpreterState *interp = _PyInterpreterState_GET();
|
||||||
assert(interp->jit);
|
if (!interp->jit) {
|
||||||
|
// gh-140936: It is possible that interp->jit will become false during
|
||||||
|
// interpreter finalization. However, the specialized JUMP_BACKWARD_JIT
|
||||||
|
// instruction may still be present. In this case, we should
|
||||||
|
// return immediately without optimization.
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
assert(!interp->compiling);
|
assert(!interp->compiling);
|
||||||
#ifndef Py_GIL_DISABLED
|
#ifndef Py_GIL_DISABLED
|
||||||
interp->compiling = true;
|
interp->compiling = true;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue