blob: 394b870e9078001ca1d594cf3756321af3da712c [file] [log] [blame]
Victor Stinner23bace22019-04-18 11:37:26 +02001/*
2 * C Extension module to test Python internal C APIs (Include/internal).
3 */
4
5#if !defined(Py_BUILD_CORE_BUILTIN) && !defined(Py_BUILD_CORE_MODULE)
6# error "Py_BUILD_CORE_BUILTIN or Py_BUILD_CORE_MODULE must be defined"
7#endif
8
9#define PY_SSIZE_T_CLEAN
10
11#include "Python.h"
Victor Stinner3f2f4fe2020-03-13 13:07:31 +010012#include "pycore_initconfig.h" // _Py_GetConfigsAsDict()
Victor Stinner23bace22019-04-18 11:37:26 +020013
14
15static PyObject *
16get_configs(PyObject *self, PyObject *Py_UNUSED(args))
17{
18 return _Py_GetConfigsAsDict();
19}
20
21
Victor Stinner3f2f4fe2020-03-13 13:07:31 +010022static PyObject*
23get_recursion_depth(PyObject *self, PyObject *args)
24{
25 PyThreadState *tstate = PyThreadState_Get();
26
27 /* subtract one to ignore the frame of the get_recursion_depth() call */
28 return PyLong_FromLong(tstate->recursion_depth - 1);
29}
30
31
Victor Stinner23bace22019-04-18 11:37:26 +020032static PyMethodDef TestMethods[] = {
33 {"get_configs", get_configs, METH_NOARGS},
Victor Stinner3f2f4fe2020-03-13 13:07:31 +010034 {"get_recursion_depth", get_recursion_depth, METH_NOARGS},
Victor Stinner23bace22019-04-18 11:37:26 +020035 {NULL, NULL} /* sentinel */
36};
37
38
39static struct PyModuleDef _testcapimodule = {
40 PyModuleDef_HEAD_INIT,
41 "_testinternalcapi",
42 NULL,
43 -1,
44 TestMethods,
45 NULL,
46 NULL,
47 NULL,
48 NULL
49};
50
51
52PyMODINIT_FUNC
53PyInit__testinternalcapi(void)
54{
55 return PyModule_Create(&_testcapimodule);
56}