Skip to content

[3.13] gh-132011: Fix crash on invalid CALL_LIST_APPEND deoptimization (GH-132018) #132161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 6, 2025
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
22 changes: 22 additions & 0 deletions Lib/test/test_list.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import sys
import textwrap
from test import list_tests
from test.support import cpython_only
from test.support.script_helper import assert_python_ok
import pickle
import unittest

Expand Down Expand Up @@ -309,5 +311,25 @@ def test_tier2_invalidates_iterator(self):
a.append(4)
self.assertEqual(list(it), [])

def test_deopt_from_append_list(self):
# gh-132011: it used to crash, because
# of `CALL_LIST_APPEND` specialization failure.
code = textwrap.dedent("""
l = []
def lappend(l, x, y):
l.append((x, y))
for x in range(3):
lappend(l, None, None)
try:
lappend(list, None, None)
except TypeError:
pass
else:
raise AssertionError
""")

rc, _, _ = assert_python_ok("-c", code)
self.assertEqual(rc, 0)

if __name__ == "__main__":
unittest.main()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix crash when calling :meth:`!list.append` as an unbound method.
2 changes: 1 addition & 1 deletion Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -3631,7 +3631,7 @@ dummy_func(
assert(oparg == 1);
PyInterpreterState *interp = tstate->interp;
DEOPT_IF(callable != interp->callable_cache.list_append);
assert(self != NULL);
DEOPT_IF(self == NULL);
DEOPT_IF(!PyList_Check(self));
STAT_INC(CALL, hit);
if (_PyList_AppendTakeRef((PyListObject *)self, arg) < 0) {
Expand Down
2 changes: 1 addition & 1 deletion Python/generated_cases.c.h

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

Loading