]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-132011: Fix crash on invalid `CALL_LIST_APPEND` deoptimization (GH-132018...
authorsobolevn <mail@sobolevn.me>
Sun, 6 Apr 2025 17:08:48 +0000 (20:08 +0300)
committerGitHub <noreply@github.com>
Sun, 6 Apr 2025 17:08:48 +0000 (17:08 +0000)
* [3.13] gh-132011: Fix crash on invalid `CALL_LIST_APPEND` deoptimization (GH-132018)
(cherry picked from commit c0661df42ad20e488dbfa3e0fec22462833fc3d6)

Co-authored-by: sobolevn <mail@sobolevn.me>
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Lib/test/test_list.py
Misc/NEWS.d/next/Core_and_Builtins/2025-04-02-17-47-14.gh-issue-132011.dNh64H.rst [new file with mode: 0644]
Python/bytecodes.c
Python/generated_cases.c.h

index ad7accf2099f43dac2e0a2d8fb1eaf91954835cb..005374f429399f380ac31eabc30b61d37eb8edf7 100644 (file)
@@ -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
 
@@ -309,5 +311,25 @@ class ListTest(list_tests.CommonTest):
             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()
diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2025-04-02-17-47-14.gh-issue-132011.dNh64H.rst b/Misc/NEWS.d/next/Core_and_Builtins/2025-04-02-17-47-14.gh-issue-132011.dNh64H.rst
new file mode 100644 (file)
index 0000000..b2484bf
--- /dev/null
@@ -0,0 +1 @@
+Fix crash when calling :meth:`!list.append` as an unbound method.
index 1e6185d3c9e48994f3134320f0408bca943fda5a..ba8ecc7faf2dbc7c0b86b9bd1979d382563cf5c1 100644 (file)
@@ -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) {
index 1488e4215cf57962ea88cfa52b9282e166c10d8a..93d5a782b469d48bba668e9a04c8ec4dae54e0ec 100644 (file)
             assert(oparg == 1);
             PyInterpreterState *interp = tstate->interp;
             DEOPT_IF(callable != interp->callable_cache.list_append, CALL);
-            assert(self != NULL);
+            DEOPT_IF(self == NULL, CALL);
             DEOPT_IF(!PyList_Check(self), CALL);
             STAT_INC(CALL, hit);
             if (_PyList_AppendTakeRef((PyListObject *)self, arg) < 0) {