From 35e985edefc98946dee7729ca29c0de292a63597 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 15 Nov 2023 20:14:41 +0100 Subject: [PATCH] gh-111798: Use lower Py_C_RECURSION_LIMIT in debug mode Reenable test_call.test_super_deep() on s390x architecture. --- Include/cpython/pystate.h | 6 +++++- Lib/test/test_call.py | 3 +-- .../2023-11-15-20-20-51.gh-issue-111798.cs-3t3.rst | 4 ++++ 3 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2023-11-15-20-20-51.gh-issue-111798.cs-3t3.rst diff --git a/Include/cpython/pystate.h b/Include/cpython/pystate.h index 7f2378ae76fe5c3..61b2fba571c0c0a 100644 --- a/Include/cpython/pystate.h +++ b/Include/cpython/pystate.h @@ -214,7 +214,11 @@ struct _ts { }; -#ifdef __wasi__ +#ifdef Py_DEBUG + // A debug build is likely built with low optimization level which implies + // higher stack memory usage than a release build. Use a lower limit. +# define Py_C_RECURSION_LIMIT 500 +#elif defined(__wasi__) // WASI has limited call stack. Python's recursion limit depends on code // layout, optimization, and WASI runtime. Wasmtime can handle about 700 // recursions, sometimes less. 500 is a more conservative limit. diff --git a/Lib/test/test_call.py b/Lib/test/test_call.py index b1c78d7136fc9ba..fddc6fad24fcd59 100644 --- a/Lib/test/test_call.py +++ b/Lib/test/test_call.py @@ -1,5 +1,5 @@ import unittest -from test.support import cpython_only, requires_limited_api, skip_on_s390x +from test.support import cpython_only, requires_limited_api try: import _testcapi except ImportError: @@ -989,7 +989,6 @@ def case_change_over_substitution(BLuch=None, Luch = None, fluch = None): @cpython_only class TestRecursion(unittest.TestCase): - @skip_on_s390x def test_super_deep(self): def recurse(n): diff --git a/Misc/NEWS.d/next/Core and Builtins/2023-11-15-20-20-51.gh-issue-111798.cs-3t3.rst b/Misc/NEWS.d/next/Core and Builtins/2023-11-15-20-20-51.gh-issue-111798.cs-3t3.rst new file mode 100644 index 000000000000000..24bb4ec096c2d11 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2023-11-15-20-20-51.gh-issue-111798.cs-3t3.rst @@ -0,0 +1,4 @@ +When Python is built in debug mode, set the C recursion limit to 500 instead +of 1500. A debug build is likely built with low optimization level which +implies higher stack memory usage than a release build. Patch by Victor +Stinner.