From f8134e4191d2ef43e12279f168d0aa0f54ff09bf Mon Sep 17 00:00:00 2001 From: sobolevn Date: Sun, 6 Apr 2025 19:10:39 +0300 Subject: [PATCH 1/2] [3.13] gh-132011: Fix crash on invalid `CALL_LIST_APPEND` deoptimization (GH-132018) (cherry picked from commit c0661df42ad20e488dbfa3e0fec22462833fc3d6) Co-authored-by: sobolevn Co-authored-by: Victor Stinner Co-authored-by: Peter Bierma --- Lib/test/test_list.py | 21 +++++++++++++++++++ ...-04-02-17-47-14.gh-issue-132011.dNh64H.rst | 1 + Python/bytecodes.c | 2 +- Python/generated_cases.c.h | 2 +- 4 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2025-04-02-17-47-14.gh-issue-132011.dNh64H.rst diff --git a/Lib/test/test_list.py b/Lib/test/test_list.py index ad7accf2099f43..5447b42a55bad3 100644 --- a/Lib/test/test_list.py +++ b/Lib/test/test_list.py @@ -1,6 +1,7 @@ import sys 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 +310,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() 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 index 00000000000000..b2484bf7c01a72 --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2025-04-02-17-47-14.gh-issue-132011.dNh64H.rst @@ -0,0 +1 @@ +Fix crash when calling :meth:`!list.append` as an unbound method. diff --git a/Python/bytecodes.c b/Python/bytecodes.c index 1e6185d3c9e489..ba8ecc7faf2dbc 100644 --- a/Python/bytecodes.c +++ b/Python/bytecodes.c @@ -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) { diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h index 1488e4215cf579..93d5a782b469d4 100644 --- a/Python/generated_cases.c.h +++ b/Python/generated_cases.c.h @@ -1590,7 +1590,7 @@ 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) { From f4170ffe8f62f872ebd86cd4c15ffb536ce6d2a4 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Sun, 6 Apr 2025 19:27:07 +0300 Subject: [PATCH 2/2] Update test_list.py --- Lib/test/test_list.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/test/test_list.py b/Lib/test/test_list.py index 5447b42a55bad3..005374f429399f 100644 --- a/Lib/test/test_list.py +++ b/Lib/test/test_list.py @@ -1,4 +1,5 @@ import sys +import textwrap from test import list_tests from test.support import cpython_only from test.support.script_helper import assert_python_ok 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