bpo-39947: Move get_recursion_depth() to _testinternalcapi (GH-18974) · python/cpython@3f2f4fe · GitHub
Skip to content

Commit 3f2f4fe

Browse files
authored
bpo-39947: Move get_recursion_depth() to _testinternalcapi (GH-18974)
Move get_recursion_depth() function from _testcapi to _testinternalcapi to avoid accessing PyThreadState attributes directly in _testcapi.
1 parent 224481a commit 3f2f4fe

4 files changed

Lines changed: 19 additions & 16 deletions

File tree

Lib/test/test_exceptions.py

Lines changed: 1 addition & 1 deletion

Lib/test/test_sys.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ def test_setrecursionlimit_recursion_depth(self):
241241
# mark". Otherwise, it may not be possible anymore to
242242
# reset the overflowed flag to 0.
243243

244-
from _testcapi import get_recursion_depth
244+
from _testinternalcapi import get_recursion_depth
245245

246246
def set_recursion_limit_at_depth(depth, limit):
247247
recursion_depth = get_recursion_depth()

Modules/_testcapimodule.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
* standard Python regression test, via Lib/test/test_capi.py.
66
*/
77

8-
/* The Visual Studio projects builds _testcapi with Py_BUILD_CORE_MODULE
9-
define, but we only want to test the public C API, not the internal
10-
C API. */
8+
/* This module tests the public (Include/ and Include/cpython/) C API.
9+
The internal C API must not be used here: use _testinternalcapi for that.
10+
11+
The Visual Studio projects builds _testcapi with Py_BUILD_CORE_MODULE
12+
macro defined, but only the public C API must be tested here. */
1113
#undef Py_BUILD_CORE_MODULE
1214

1315
#define PY_SSIZE_T_CLEAN
@@ -4523,15 +4525,6 @@ test_PyTime_AsMicroseconds(PyObject *self, PyObject *args)
45234525
return _PyTime_AsNanosecondsObject(ms);
45244526
}
45254527

4526-
static PyObject*
4527-
get_recursion_depth(PyObject *self, PyObject *args)
4528-
{
4529-
PyThreadState *tstate = PyThreadState_Get();
4530-
4531-
/* subtract one to ignore the frame of the get_recursion_depth() call */
4532-
return PyLong_FromLong(tstate->recursion_depth - 1);
4533-
}
4534-
45354528
static PyObject*
45364529
pymem_buffer_overflow(PyObject *self, PyObject *args)
45374530
{
@@ -5486,7 +5479,6 @@ static PyMethodDef TestMethods[] = {
54865479
#endif
54875480
{"PyTime_AsMilliseconds", test_PyTime_AsMilliseconds, METH_VARARGS},
54885481
{"PyTime_AsMicroseconds", test_PyTime_AsMicroseconds, METH_VARARGS},
5489-
{"get_recursion_depth", get_recursion_depth, METH_NOARGS},
54905482
{"pymem_buffer_overflow", pymem_buffer_overflow, METH_NOARGS},
54915483
{"pymem_api_misuse", pymem_api_misuse, METH_NOARGS},
54925484
{"pymem_malloc_without_gil", pymem_malloc_without_gil, METH_NOARGS},

Modules/_testinternalcapi.c

Lines changed: 12 additions & 1 deletion

0 commit comments

Comments
 (0)