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:
Victor Stinner 2020-03-13 13:07:31 +01:00 committed by GitHub
parent 224481a8c9
commit 3f2f4fefca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 16 deletions

View file

@ -9,7 +9,7 @@
#define PY_SSIZE_T_CLEAN
#include "Python.h"
#include "pycore_initconfig.h"
#include "pycore_initconfig.h" // _Py_GetConfigsAsDict()
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[] = {
{"get_configs", get_configs, METH_NOARGS},
{"get_recursion_depth", get_recursion_depth, METH_NOARGS},
{NULL, NULL} /* sentinel */
};