Skip to content

Commit c0661df

Browse files
sobolevnvstinnerZeroIntensity
authored
gh-132011: Fix crash on invalid CALL_LIST_APPEND deoptimization (#132018)
Co-authored-by: Victor Stinner <[email protected]> Co-authored-by: Peter Bierma <[email protected]>
1 parent 42e3a84 commit c0661df

File tree

5 files changed

+32
-4
lines changed

5 files changed

+32
-4
lines changed

Lib/test/test_list.py

+21-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from test import list_tests, support
55
from test.support import cpython_only
66
from test.support.import_helper import import_module
7-
from test.support.script_helper import assert_python_failure
7+
from test.support.script_helper import assert_python_failure, assert_python_ok
88
import pickle
99
import unittest
1010

@@ -332,5 +332,25 @@ def test_no_memory(self):
332332
else:
333333
self.assertNotEqual(rc, -int(signal.SIGSEGV))
334334

335+
def test_deopt_from_append_list(self):
336+
# gh-132011: it used to crash, because
337+
# of `CALL_LIST_APPEND` specialization failure.
338+
code = textwrap.dedent("""
339+
l = []
340+
def lappend(l, x, y):
341+
l.append((x, y))
342+
for x in range(3):
343+
lappend(l, None, None)
344+
try:
345+
lappend(list, None, None)
346+
except TypeError:
347+
pass
348+
else:
349+
raise AssertionError
350+
""")
351+
352+
rc, _, _ = assert_python_ok("-c", code)
353+
self.assertEqual(rc, 0)
354+
335355
if __name__ == "__main__":
336356
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
@@ -4235,7 +4235,7 @@ dummy_func(
42354235

42364236
PyInterpreterState *interp = tstate->interp;
42374237
DEOPT_IF(callable_o != interp->callable_cache.list_append);
4238-
assert(self_o != NULL);
4238+
DEOPT_IF(self_o == NULL);
42394239
DEOPT_IF(!PyList_Check(self_o));
42404240
DEOPT_IF(!LOCK_OBJECT(self_o));
42414241
STAT_INC(CALL, hit);

Python/executor_cases.c.h

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

Python/generated_cases.c.h

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

0 commit comments

Comments
 (0)