mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
gh-128717: Stop-the-world when setting the recursion limit (#128741)
This commit is contained in:
parent
ff39e3ff7b
commit
f6c61bf2d7
3 changed files with 19 additions and 0 deletions
|
@ -270,6 +270,21 @@ class TestRaces(TestBase):
|
||||||
|
|
||||||
do_race(set_value, mutate)
|
do_race(set_value, mutate)
|
||||||
|
|
||||||
|
def test_racing_recursion_limit(self):
|
||||||
|
def something_recursive():
|
||||||
|
def count(n):
|
||||||
|
if n > 0:
|
||||||
|
return count(n - 1) + 1
|
||||||
|
return 0
|
||||||
|
|
||||||
|
count(50)
|
||||||
|
|
||||||
|
def set_recursion_limit():
|
||||||
|
for limit in range(100, 200):
|
||||||
|
sys.setrecursionlimit(limit)
|
||||||
|
|
||||||
|
do_race(something_recursive, set_recursion_limit)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Fix a crash when setting the recursion limit while other threads are active
|
||||||
|
on the :term:`free threaded <free threading>` build.
|
|
@ -294,6 +294,7 @@ void
|
||||||
Py_SetRecursionLimit(int new_limit)
|
Py_SetRecursionLimit(int new_limit)
|
||||||
{
|
{
|
||||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
PyInterpreterState *interp = _PyInterpreterState_GET();
|
||||||
|
_PyEval_StopTheWorld(interp);
|
||||||
interp->ceval.recursion_limit = new_limit;
|
interp->ceval.recursion_limit = new_limit;
|
||||||
_Py_FOR_EACH_TSTATE_BEGIN(interp, p) {
|
_Py_FOR_EACH_TSTATE_BEGIN(interp, p) {
|
||||||
int depth = p->py_recursion_limit - p->py_recursion_remaining;
|
int depth = p->py_recursion_limit - p->py_recursion_remaining;
|
||||||
|
@ -301,6 +302,7 @@ Py_SetRecursionLimit(int new_limit)
|
||||||
p->py_recursion_remaining = new_limit - depth;
|
p->py_recursion_remaining = new_limit - depth;
|
||||||
}
|
}
|
||||||
_Py_FOR_EACH_TSTATE_END(interp);
|
_Py_FOR_EACH_TSTATE_END(interp);
|
||||||
|
_PyEval_StartTheWorld(interp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The function _Py_EnterRecursiveCallTstate() only calls _Py_CheckRecursiveCall()
|
/* The function _Py_EnterRecursiveCallTstate() only calls _Py_CheckRecursiveCall()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue