FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-140936: Fix JIT assertion crash at finalization if some generator is alive by efimov-mikhail · Pull Request #140969 · python/cpython · GitHub

/ cpython Public
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .py  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
19 changes: 19 additions & 0 deletions Lib/test/test_capi/test_opt.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -2660,6 +2660,25 @@ def 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)
Comment thread
efimov-mikhail marked this conversation as resolved.
simple_for()
g = gen()
next(g)
""" % _testinternalcapi.SPECIALIZATION_THRESHOLD))


def global_identity(x):
Expand Down
8 changes: 7 additions & 1 deletion Python/optimizer.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,13 @@ _PyOptimizer_Optimize(
{
_PyStackRef *stack_pointer = frame->stackpointer;
PyInterpreterState *interp = _PyInterpreterState_GET();
assert(interp->jit);
if (!interp->jit) {
Comment thread
efimov-mikhail marked this conversation as resolved.
// 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);
#ifndef Py_GIL_DISABLED
interp->compiling = true;
Expand Down
Loading

Back | FazBrowse Home | New Git URL