From 0acd368c8049989715ed55c83d62d8e3b8cb365f Mon Sep 17 00:00:00 2001 From: Bhuvansh Kataria Date: Sat, 3 Oct 2026 09:59:49 +0000 Subject: [PATCH 1/2] Doc: document that Py_EnterRecursiveCall uses C stack, not a counter --- Doc/c-api/exceptions.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Doc/c-api/exceptions.rst b/Doc/c-api/exceptions.rst index 40522f8c7b13756..82b1aa0e38fe055 100644 --- a/Doc/c-api/exceptions.rst +++ b/Doc/c-api/exceptions.rst @@ -1034,6 +1034,10 @@ because the :ref:`call protocol ` takes care of recursion handling. case, a :exc:`RecursionError` is set and a nonzero value is returned. Otherwise, zero is returned. + The limit is based on how much C stack the current thread has consumed, + not on a count of calls, so it is unaffected by + :c:func:`Py_SetRecursionLimit` and :func:`sys.setrecursionlimit`. + *where* should be a UTF-8 encoded string such as ``" in instance check"`` to be concatenated to the :exc:`RecursionError` message caused by the recursion depth limit. @@ -1044,6 +1048,10 @@ because the :ref:`call protocol ` takes care of recursion handling. .. versionchanged:: 3.9 This function is now also available in the :ref:`limited API `. + .. versionchanged:: 3.14 + The check is based on the remaining C stack space. Previously, a + separate counter of C-level calls was used. + .. c:function:: void Py_LeaveRecursiveCall(void) Ends a :c:func:`Py_EnterRecursiveCall`. Must be called once for each From 60dc145853ebb836b312d71d01aa92f030e64be9 Mon Sep 17 00:00:00 2001 From: Bhuvansh Date: Sat, 3 Oct 2026 16:29:58 +0530 Subject: [PATCH 2/2] Update Doc/c-api/exceptions.rst Co-authored-by: An Long --- Doc/c-api/exceptions.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/c-api/exceptions.rst b/Doc/c-api/exceptions.rst index 82b1aa0e38fe055..0c8d14dc134ebc1 100644 --- a/Doc/c-api/exceptions.rst +++ b/Doc/c-api/exceptions.rst @@ -1034,7 +1034,7 @@ because the :ref:`call protocol ` takes care of recursion handling. case, a :exc:`RecursionError` is set and a nonzero value is returned. Otherwise, zero is returned. - The limit is based on how much C stack the current thread has consumed, + The check is based on the remaining C stack space of the current thread, not on a count of calls, so it is unaffected by :c:func:`Py_SetRecursionLimit` and :func:`sys.setrecursionlimit`.