Skip to content

Commit f8134e4

Browse files
sobolevnvstinnerZeroIntensity
committed
[3.13] pythongh-132011: Fix crash on invalid CALL_LIST_APPEND deoptimization (pythonGH-132018)
(cherry picked from commit c0661df) Co-authored-by: sobolevn <[email protected]> Co-authored-by: Victor Stinner <[email protected]> Co-authored-by: Peter Bierma <[email protected]>
1 parent f7ab4eb commit f8134e4

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

Lib/test/test_list.py

+21
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import sys
22
from test import list_tests
33
from test.support import cpython_only
4+
from test.support.script_helper import assert_python_ok
45
import pickle
56
import unittest
67

@@ -309,5 +310,25 @@ def test_tier2_invalidates_iterator(self):
309310
a.append(4)
310311
self.assertEqual(list(it), [])
311312

313+
def test_deopt_from_append_list(self):
314+
# gh-132011: it used to crash, because
315+
# of `CALL_LIST_APPEND` specialization failure.
316+
code = textwrap.dedent("""
317+
l = []
318+
def lappend(l, x, y):
319+
l.append((x, y))
320+
for x in range(3):
321+
lappend(l, None, None)
322+
try:
323+
lappend(list, None, None)
324+
except TypeError:
325+
pass
326+
else:
327+
raise AssertionError
328+
""")
329+
330+
rc, _, _ = assert_python_ok("-c", code)
331+
self.assertEqual(rc, 0)
332+
312333
if __name__ == "__main__":
313334
unittest.main()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix crash when calling :meth:`!list.append` as an unbound method.

Python/bytecodes.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -3631,7 +3631,7 @@ dummy_func(
36313631
assert(oparg == 1);
36323632
PyInterpreterState *interp = tstate->interp;
36333633
DEOPT_IF(callable != interp->callable_cache.list_append);
3634-
assert(self != NULL);
3634+
DEOPT_IF(self == NULL);
36353635
DEOPT_IF(!PyList_Check(self));
36363636
STAT_INC(CALL, hit);
36373637
if (_PyList_AppendTakeRef((PyListObject *)self, arg) < 0) {

Python/generated_cases.c.h

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)