From 5d5ab9fd6f2f5487600fa12b18423cda5f913e1d Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Tue, 2 Jan 2024 16:18:33 -0500 Subject: [PATCH 1/2] gh-113655: Reduce recursion limit to a safe number for Windows --- Include/cpython/pystate.h | 2 +- Lib/test/support/__init__.py | 2 +- Lib/test/test_functools.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Include/cpython/pystate.h b/Include/cpython/pystate.h index ed7dd829d4b6f0..d5500b1751e096 100644 --- a/Include/cpython/pystate.h +++ b/Include/cpython/pystate.h @@ -227,7 +227,7 @@ struct _ts { # define Py_C_RECURSION_LIMIT 1200 #else // This value is duplicated in Lib/test/support/__init__.py -# define Py_C_RECURSION_LIMIT 8000 +# define Py_C_RECURSION_LIMIT 4000 #endif diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index e5fb725a30b5b8..ded30cea1cc08f 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -2377,7 +2377,7 @@ def _get_c_recursion_limit(): return _testcapi.Py_C_RECURSION_LIMIT except (ImportError, AttributeError): # Originally taken from Include/cpython/pystate.h . - return 8000 + return 4000 # The default C recursion limit. Py_C_RECURSION_LIMIT = _get_c_recursion_limit() diff --git a/Lib/test/test_functools.py b/Lib/test/test_functools.py index 0ef45d3c670e85..98b5cd8448dc3c 100644 --- a/Lib/test/test_functools.py +++ b/Lib/test/test_functools.py @@ -1876,7 +1876,7 @@ def fib(n): if not support.Py_DEBUG: with support.infinite_recursion(): - fib(2500) + fib(1250) @py_functools.lru_cache() From 67f60b5108a07b63926d2d89d8973b754e6fc586 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Wed, 3 Jan 2024 08:25:10 -0500 Subject: [PATCH 2/2] Make sure recursion always maxes out --- Lib/test/test_functools.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Lib/test/test_functools.py b/Lib/test/test_functools.py index 98b5cd8448dc3c..6e45c0babc2de4 100644 --- a/Lib/test/test_functools.py +++ b/Lib/test/test_functools.py @@ -1876,8 +1876,7 @@ def fib(n): if not support.Py_DEBUG: with support.infinite_recursion(): - fib(1250) - + self.assertRaises(RecursionError, fib, 2000) @py_functools.lru_cache() def py_cached_func(x, y):