From a71ed5cb2b4cd51f84909f77daa9fb3261968a6e Mon Sep 17 00:00:00 2001 From: Peter Bierma Date: Thu, 6 Nov 2025 11:37:52 -0500 Subject: [PATCH 1/3] gh-141004: Document `Py_GetRecursionLimit` and `Py_SetRecursionLimit` (GH-141151) (cherry picked from commit 0b260305d302eace7d59931ca582a1953d894018) Co-authored-by: Peter Bierma Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> --- 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 10cb33990c55ca..20827c42fa5fd0 100644 --- a/Doc/c-api/exceptions.rst +++ b/Doc/c-api/exceptions.rst @@ -967,6 +967,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 with + :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 new_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 3c549226dd7ac738bc236625095710b8823729f5 Mon Sep 17 00:00:00 2001 From: Peter Bierma Date: Thu, 6 Nov 2025 11:53:30 -0500 Subject: [PATCH 2/3] Update Doc/c-api/exceptions.rst --- Doc/c-api/exceptions.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/c-api/exceptions.rst b/Doc/c-api/exceptions.rst index 20827c42fa5fd0..b984c2b1916e98 100644 --- a/Doc/c-api/exceptions.rst +++ b/Doc/c-api/exceptions.rst @@ -983,8 +983,8 @@ these are the C equivalent to :func:`reprlib.recursive_repr`. Set the recursion limit for the current interpreter. - This function cannot fail, and the caller must hold an - :term:`attached thread state`. + This function cannot fail, and the caller must hold the + :term:`GIL`. .. seealso:: :py:func:`sys.setrecursionlimit` From bd7eaa657ac38ecc8f30aa894b78d92d802f2860 Mon Sep 17 00:00:00 2001 From: Peter Bierma Date: Thu, 6 Nov 2025 11:53:35 -0500 Subject: [PATCH 3/3] Update Doc/c-api/exceptions.rst --- Doc/c-api/exceptions.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/c-api/exceptions.rst b/Doc/c-api/exceptions.rst index b984c2b1916e98..cea03b24b4d61a 100644 --- a/Doc/c-api/exceptions.rst +++ b/Doc/c-api/exceptions.rst @@ -973,8 +973,8 @@ these are the C equivalent to :func:`reprlib.recursive_repr`. :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`. + This function cannot fail, and the caller must hold the + :term:`GIL`. .. seealso:: :py:func:`sys.getrecursionlimit`