Skip to content

Commit 5fb9fe0

Browse files
sobolevnvstinnerZeroIntensity
authored
[3.13] gh-132011: Fix crash on invalid CALL_LIST_APPEND deoptimization (GH-132018) (#132161)
* [3.13] gh-132011: Fix crash on invalid `CALL_LIST_APPEND` deoptimization (GH-132018) (cherry picked from commit c0661df) Co-authored-by: sobolevn <mail@sobolevn.me> Co-authored-by: Victor Stinner <vstinner@python.org> Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
1 parent 83070aa commit 5fb9fe0

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

Lib/test/test_list.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import sys
2+
import textwrap
23
from test import list_tests
34
from test.support import cpython_only
5+
from test.support.script_helper import assert_python_ok
46
import pickle
57
import unittest
68

@@ -309,5 +311,25 @@ def test_tier2_invalidates_iterator(self):
309311
a.append(4)
310312
self.assertEqual(list(it), [])
311313

314+
def test_deopt_from_append_list(self):
315+
# gh-132011: it used to crash, because
316+
# of `CALL_LIST_APPEND` specialization failure.
317+
code = textwrap.dedent("""
318+
l = []
319+
def lappend(l, x, y):
320+
l.append((x, y))
321+
for x in range(3):
322+
lappend(l, None, None)
323+
try:
324+
lappend(list, None, None)
325+
except TypeError:
326+
pass
327+
else:
328+
raise AssertionError
329+
""")
330+
331+
rc, _, _ = assert_python_ok("-c", code)
332+
self.assertEqual(rc, 0)
333+
312334
if __name__ == "__main__":
313335
unittest.main()
Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy