Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Include/internal/pycore_opcode_metadata.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Include/internal/pycore_uop_metadata.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions Lib/test/test_capi/test_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -4114,6 +4114,28 @@ def __init__(self, name):
PYTHON_JIT_SIDE_EXIT_INITIAL_VALUE="1")
self.assertEqual(result[0].rc, 0, result)

def test_for_iter_gen_cleared_frame_does_not_crash(self):
# See: https://github.com/python/cpython/issues/145197
result = script_helper.run_python_until_end('-c', textwrap.dedent("""
def g():
yield 1
yield 2
for _ in range(4002):
for _ in g():
pass
for i in range(4002):
it = g()
if (i & 7) == 0:
next(it)
it.close()
for _ in it:
pass
"""),
PYTHON_JIT="1", PYTHON_JIT_STRESS="1")
self.assertEqual(result[0].rc, 0, result)

def global_identity(x):
return x

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix JIT trace crash when recording function from cleared generator frame.
7 changes: 5 additions & 2 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -5730,8 +5730,11 @@ dummy_func(
tier2 op(_RECORD_NOS_GEN_FUNC, (nos, tos -- nos, tos)) {
PyObject *obj = PyStackRef_AsPyObjectBorrow(nos);
if (PyGen_Check(obj)) {
PyObject *func = (PyObject *)_PyFrame_GetFunction(&((PyGenObject *)obj)->gi_iframe);
RECORD_VALUE(func);
PyGenObject *gen = (PyGenObject *)obj;
_PyStackRef func = gen->gi_iframe.f_funcobj;
if (!PyStackRef_IsNull(func)) {
RECORD_VALUE(PyStackRef_AsPyObjectBorrow(func));
}
}
}

Expand Down
11 changes: 6 additions & 5 deletions Python/record_functions.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading