From 438a4e4071be895d6c838f6a2c5ac905a628d4fb Mon Sep 17 00:00:00 2001 From: Peter Bierma Date: Thu, 6 Nov 2025 10:15:19 -0500 Subject: [PATCH 1/3] Document Py_GetRecursionLimit() and Py_SetRecursionLimit() --- Doc/c-api/exceptions.rst | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Doc/c-api/exceptions.rst b/Doc/c-api/exceptions.rst index 3ff4631a8e53c4..97134b6d500761 100644 --- a/Doc/c-api/exceptions.rst +++ b/Doc/c-api/exceptions.rst @@ -979,6 +979,27 @@ these are the C equivalent to :func:`reprlib.recursive_repr`. Ends a :c:func:`Py_ReprEnter`. Must be called once for each invocation of :c:func:`Py_ReprEnter` that returns zero. +.. c:function:: int Py_GetRecursionLimit(void) + + Get the recursion limit for the current interpreter. It can be set by + :c:func:`Py_SetRecursionLimit`. The recursion limit prevents the + Python interpreter stack from growing infinitely. + + This function cannot fail, and the caller must hold an + :term:`attached thread state`. + + .. seealso:: + :py:func:`sys.getrecursionlimit` + +.. c:function:: void Py_SetRecursionLimit(int limit) + + Set the recursion limit for the current interpreter. + + This function cannot fail, and the caller must hold an + :term:`attached thread state`. + + .. seealso:: + :py:func:`sys.setrecursionlimit` .. _standardexceptions: From e116b4aee6b907468fcb3d6f830e9c0d2235cee2 Mon Sep 17 00:00:00 2001 From: Peter Bierma Date: Thu, 6 Nov 2025 11:19:44 -0500 Subject: [PATCH 2/3] Update Doc/c-api/exceptions.rst Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> --- 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 97134b6d500761..477f62cfe938d5 100644 --- a/Doc/c-api/exceptions.rst +++ b/Doc/c-api/exceptions.rst @@ -991,7 +991,7 @@ these are the C equivalent to :func:`reprlib.recursive_repr`. .. seealso:: :py:func:`sys.getrecursionlimit` -.. c:function:: void Py_SetRecursionLimit(int limit) +.. c:function:: void Py_SetRecursionLimit(int new_limit) Set the recursion limit for the current interpreter. From 3dc4a4009bc41c462cfab7d31fc11d5b0978f4a7 Mon Sep 17 00:00:00 2001 From: Peter Bierma Date: Thu, 6 Nov 2025 11:19:51 -0500 Subject: [PATCH 3/3] Update Doc/c-api/exceptions.rst Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> --- 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 477f62cfe938d5..9c75f66f683195 100644 --- a/Doc/c-api/exceptions.rst +++ b/Doc/c-api/exceptions.rst @@ -981,7 +981,7 @@ these are the C equivalent to :func:`reprlib.recursive_repr`. .. c:function:: int Py_GetRecursionLimit(void) - Get the recursion limit for the current interpreter. It can be set by + Get the recursion limit for the current interpreter. It can be set with :c:func:`Py_SetRecursionLimit`. The recursion limit prevents the Python interpreter stack from growing infinitely.