mirror of
https://github.com/python/cpython.git
synced 2025-10-17 12:18:23 +00:00
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.
This commit is contained in:
parent
224481a8c9
commit
3f2f4fefca
4 changed files with 19 additions and 16 deletions
|
@ -994,7 +994,7 @@ class ExceptionTests(unittest.TestCase):
|
||||||
# finalization of these locals.
|
# finalization of these locals.
|
||||||
code = """if 1:
|
code = """if 1:
|
||||||
import sys
|
import sys
|
||||||
from _testcapi import get_recursion_depth
|
from _testinternalcapi import get_recursion_depth
|
||||||
|
|
||||||
class MyException(Exception): pass
|
class MyException(Exception): pass
|
||||||
|
|
||||||
|
|
|
@ -241,7 +241,7 @@ class SysModuleTest(unittest.TestCase):
|
||||||
# mark". Otherwise, it may not be possible anymore to
|
# mark". Otherwise, it may not be possible anymore to
|
||||||
# reset the overflowed flag to 0.
|
# reset the overflowed flag to 0.
|
||||||
|
|
||||||
from _testcapi import get_recursion_depth
|
from _testinternalcapi import get_recursion_depth
|
||||||
|
|
||||||
def set_recursion_limit_at_depth(depth, limit):
|
def set_recursion_limit_at_depth(depth, limit):
|
||||||
recursion_depth = get_recursion_depth()
|
recursion_depth = get_recursion_depth()
|
||||||
|
|
|
@ -5,9 +5,11 @@
|
||||||
* standard Python regression test, via Lib/test/test_capi.py.
|
* standard Python regression test, via Lib/test/test_capi.py.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* The Visual Studio projects builds _testcapi with Py_BUILD_CORE_MODULE
|
/* This module tests the public (Include/ and Include/cpython/) C API.
|
||||||
define, but we only want to test the public C API, not the internal
|
The internal C API must not be used here: use _testinternalcapi for that.
|
||||||
C API. */
|
|
||||||
|
The Visual Studio projects builds _testcapi with Py_BUILD_CORE_MODULE
|
||||||
|
macro defined, but only the public C API must be tested here. */
|
||||||
#undef Py_BUILD_CORE_MODULE
|
#undef Py_BUILD_CORE_MODULE
|
||||||
|
|
||||||
#define PY_SSIZE_T_CLEAN
|
#define PY_SSIZE_T_CLEAN
|
||||||
|
@ -4523,15 +4525,6 @@ test_PyTime_AsMicroseconds(PyObject *self, PyObject *args)
|
||||||
return _PyTime_AsNanosecondsObject(ms);
|
return _PyTime_AsNanosecondsObject(ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
|
||||||
get_recursion_depth(PyObject *self, PyObject *args)
|
|
||||||
{
|
|
||||||
PyThreadState *tstate = PyThreadState_Get();
|
|
||||||
|
|
||||||
/* subtract one to ignore the frame of the get_recursion_depth() call */
|
|
||||||
return PyLong_FromLong(tstate->recursion_depth - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
pymem_buffer_overflow(PyObject *self, PyObject *args)
|
pymem_buffer_overflow(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
|
@ -5486,7 +5479,6 @@ static PyMethodDef TestMethods[] = {
|
||||||
#endif
|
#endif
|
||||||
{"PyTime_AsMilliseconds", test_PyTime_AsMilliseconds, METH_VARARGS},
|
{"PyTime_AsMilliseconds", test_PyTime_AsMilliseconds, METH_VARARGS},
|
||||||
{"PyTime_AsMicroseconds", test_PyTime_AsMicroseconds, METH_VARARGS},
|
{"PyTime_AsMicroseconds", test_PyTime_AsMicroseconds, METH_VARARGS},
|
||||||
{"get_recursion_depth", get_recursion_depth, METH_NOARGS},
|
|
||||||
{"pymem_buffer_overflow", pymem_buffer_overflow, METH_NOARGS},
|
{"pymem_buffer_overflow", pymem_buffer_overflow, METH_NOARGS},
|
||||||
{"pymem_api_misuse", pymem_api_misuse, METH_NOARGS},
|
{"pymem_api_misuse", pymem_api_misuse, METH_NOARGS},
|
||||||
{"pymem_malloc_without_gil", pymem_malloc_without_gil, METH_NOARGS},
|
{"pymem_malloc_without_gil", pymem_malloc_without_gil, METH_NOARGS},
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
#define PY_SSIZE_T_CLEAN
|
#define PY_SSIZE_T_CLEAN
|
||||||
|
|
||||||
#include "Python.h"
|
#include "Python.h"
|
||||||
#include "pycore_initconfig.h"
|
#include "pycore_initconfig.h" // _Py_GetConfigsAsDict()
|
||||||
|
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -19,8 +19,19 @@ get_configs(PyObject *self, PyObject *Py_UNUSED(args))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static PyObject*
|
||||||
|
get_recursion_depth(PyObject *self, PyObject *args)
|
||||||
|
{
|
||||||
|
PyThreadState *tstate = PyThreadState_Get();
|
||||||
|
|
||||||
|
/* subtract one to ignore the frame of the get_recursion_depth() call */
|
||||||
|
return PyLong_FromLong(tstate->recursion_depth - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static PyMethodDef TestMethods[] = {
|
static PyMethodDef TestMethods[] = {
|
||||||
{"get_configs", get_configs, METH_NOARGS},
|
{"get_configs", get_configs, METH_NOARGS},
|
||||||
|
{"get_recursion_depth", get_recursion_depth, METH_NOARGS},
|
||||||
{NULL, NULL} /* sentinel */
|
{NULL, NULL} /* sentinel */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue