Victor Stinner | 23bace2 | 2019-04-18 11:37:26 +0200 | [diff] [blame] | 1 | /* |
| 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 Stinner | 3f2f4fe | 2020-03-13 13:07:31 +0100 | [diff] [blame^] | 12 | #include "pycore_initconfig.h" // _Py_GetConfigsAsDict() |
Victor Stinner | 23bace2 | 2019-04-18 11:37:26 +0200 | [diff] [blame] | 13 | |
| 14 | |
| 15 | static PyObject * |
| 16 | get_configs(PyObject *self, PyObject *Py_UNUSED(args)) |
| 17 | { |
| 18 | return _Py_GetConfigsAsDict(); |
| 19 | } |
| 20 | |
| 21 | |
Victor Stinner | 3f2f4fe | 2020-03-13 13:07:31 +0100 | [diff] [blame^] | 22 | static PyObject* |
| 23 | get_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 Stinner | 23bace2 | 2019-04-18 11:37:26 +0200 | [diff] [blame] | 32 | static PyMethodDef TestMethods[] = { |
| 33 | {"get_configs", get_configs, METH_NOARGS}, |
Victor Stinner | 3f2f4fe | 2020-03-13 13:07:31 +0100 | [diff] [blame^] | 34 | {"get_recursion_depth", get_recursion_depth, METH_NOARGS}, |
Victor Stinner | 23bace2 | 2019-04-18 11:37:26 +0200 | [diff] [blame] | 35 | {NULL, NULL} /* sentinel */ |
| 36 | }; |
| 37 | |
| 38 | |
| 39 | static 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 | |
| 52 | PyMODINIT_FUNC |
| 53 | PyInit__testinternalcapi(void) |
| 54 | { |
| 55 | return PyModule_Create(&_testcapimodule); |
| 56 | } |