This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Remove _Py_CheckRecursionLimit variable
Type: Stage: resolved
Components: C API Versions: Python 3.10
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: vstinner
Priority: normal Keywords: patch

Created on 2020-09-22 12:39 by vstinner, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 22359 merged vstinner, 2020-09-22 12:47
Messages (2)
msg377317 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-09-22 12:39
_Py_CheckRecursionLimit variable is no longer needed and can be removed.

In Python 3.9, I added a recursion limit per interpreter.

In Python 3.8 and older, it was used by _Py_MakeRecCheck() macro to check for recursion error. 

Previously, the _Py_CheckRecursionLimit variable was kept for backward compatibility with the stable ABI, but in Python 3.8 and older, Py_EnterRecursiveCall() and Py_LeaveRecursiveCall() could not be used with the limited C API since these macros accessed PyThreadState structure member, whereas the structure is opaque in the limited C API.

Attached PR removed the variable.

---

(3) bpo-40513: Limit made per interpreter.

commit 4e30ed3af06ae655f4cb8aad8cba21f341384250
Author: Victor Stinner <vstinner@python.org>
Date:   Tue May 5 16:52:52 2020 +0200

    bpo-40513: Per-interpreter recursion_limit (GH-19929)
    
    Move recursion_limit member from _PyRuntimeState.ceval to
    PyInterpreterState.ceval.
    
    * Py_SetRecursionLimit() now only sets _Py_CheckRecursionLimit
      of ceval.c if the current Python thread is part of the main
      interpreter.
    * Inline _Py_MakeEndRecCheck() into _Py_LeaveRecursiveCall().
    * Convert _Py_RecursionLimitLowerWaterMark() macro into a static
      inline function.

---

(2) bpo-38644: The _Py_CheckRecursionLimit variable was used by Py_EnterRecursiveCall() and Py_LeaveRecursiveCall() macros. I converted these macros into function calls in Python 3.9:

commit f4b1e3d7c64985f5d5b00f6cc9a1c146bbbfd613
Author: Victor Stinner <vstinner@python.org>
Date:   Mon Nov 4 19:48:34 2019 +0100

    bpo-38644: Add Py_EnterRecursiveCall() to the limited API (GH-17046)
    
    Provide Py_EnterRecursiveCall() and Py_LeaveRecursiveCall() as
    regular functions for the limited API. Previously, there were defined
    as macros, but these macros didn't work with the limited API which
    cannot access PyThreadState.recursion_depth field.
    
    Remove _Py_CheckRecursionLimit from the stable ABI.
    
    Add Include/cpython/ceval.h header file.

In pycore_ceval.h, the function is overriden by a macro which points to an inline function which uses:

* tstate->recursion_depth
* tstate->interp->ceval.recursion_limit
* tstate->stackcheck_counter (if USE_STACKCHECK macro is defined)

---

(1) bpo-31857: Original change adding the FIXME.

commit 1896793520a49a6f97ae360c0b288967e56b005e
Author: pdox <pdox@alum.mit.edu>
Date:   Wed Oct 25 23:03:01 2017 -0700

    bpo-31857: Make the behavior of USE_STACKCHECK deterministic (#4098)

This change added the FIXME comment:

/* Due to the macros in which it's used, _Py_CheckRecursionLimit is in
   the stable ABI.  It should be removed therefrom when possible.
*/
msg377367 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-09-23 12:05
New changeset 19c3ac92bf73f1902cff846988552fd7bb8a8621 by Victor Stinner in branch 'master':
bpo-41834: Remove _Py_CheckRecursionLimit variable (GH-22359)
https://github.com/python/cpython/commit/19c3ac92bf73f1902cff846988552fd7bb8a8621
History
Date User Action Args
2022-04-11 14:59:35adminsetgithub: 86000
2020-10-01 22:45:53vstinnersetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2020-09-23 12:05:01vstinnersetmessages: + msg377367
2020-09-22 12:47:39vstinnersetkeywords: + patch
stage: patch review
pull_requests: + pull_request21397
2020-09-22 12:39:27vstinnercreate