diff options
author | Victor Stinner <vstinner@redhat.com> | 2019-04-18 09:37:26 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-18 09:37:26 (GMT) |
commit | 23bace26ec265557697cf3b578b361c178070cd5 (patch) | |
tree | 41d99b73d99a1f8295ed6177113ed7796c8ed784 /Modules | |
parent | 11efd79076559cc6e4034bb36db73e5e4293f02d (diff) | |
download | cpython-23bace26ec265557697cf3b578b361c178070cd5.zip cpython-23bace26ec265557697cf3b578b361c178070cd5.tar.gz cpython-23bace26ec265557697cf3b578b361c178070cd5.tar.bz2 |
bpo-36635: Add _testinternalcapi module (GH-12841)
Add a new _testinternalcapi module to test the internal C API.
Move _Py_GetConfigsAsDict() function to the internal C API:
_testembed now uses _testinternalcapi to access the function.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/Setup | 1 | ||||
-rw-r--r-- | Modules/_testcapimodule.c | 8 | ||||
-rw-r--r-- | Modules/_testinternalcapi.c | 45 |
3 files changed, 46 insertions, 8 deletions
diff --git a/Modules/Setup b/Modules/Setup index 03aa0f1..e729ab8 100644 --- a/Modules/Setup +++ b/Modules/Setup @@ -173,6 +173,7 @@ _symtable symtablemodule.c #_struct _struct.c # binary structure packing/unpacking #_weakref _weakref.c # basic weak reference support #_testcapi _testcapimodule.c # Python C API test module +#_testinternalcapi _testinternalcapi.c -I$(srcdir)/Include/internal -DPy_BUILD_CORE_MODULE # Python internal C API test module #_random _randommodule.c # Random number generator #_elementtree -I$(srcdir)/Modules/expat -DHAVE_EXPAT_CONFIG_H -DUSE_PYEXPAT_CAPI _elementtree.c # elementtree accelerator #_pickle _pickle.c # pickle accelerator diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index ae960de..6f4eb53 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -4736,13 +4736,6 @@ decode_locale_ex(PyObject *self, PyObject *args) } -static PyObject * -get_configs(PyObject *self, PyObject *Py_UNUSED(args)) -{ - return _Py_GetConfigsAsDict(); -} - - #ifdef Py_REF_DEBUG static PyObject * negative_refcount(PyObject *self, PyObject *Py_UNUSED(args)) @@ -4990,7 +4983,6 @@ static PyMethodDef TestMethods[] = { {"bad_get", (PyCFunction)(void(*)(void))bad_get, METH_FASTCALL}, {"EncodeLocaleEx", encode_locale_ex, METH_VARARGS}, {"DecodeLocaleEx", decode_locale_ex, METH_VARARGS}, - {"get_configs", get_configs, METH_NOARGS}, #ifdef Py_REF_DEBUG {"negative_refcount", negative_refcount, METH_NOARGS}, #endif diff --git a/Modules/_testinternalcapi.c b/Modules/_testinternalcapi.c new file mode 100644 index 0000000..3a43ec1 --- /dev/null +++ b/Modules/_testinternalcapi.c @@ -0,0 +1,45 @@ +/* + * C Extension module to test Python internal C APIs (Include/internal). + */ + +#if !defined(Py_BUILD_CORE_BUILTIN) && !defined(Py_BUILD_CORE_MODULE) +# error "Py_BUILD_CORE_BUILTIN or Py_BUILD_CORE_MODULE must be defined" +#endif + +#define PY_SSIZE_T_CLEAN + +#include "Python.h" +#include "pycore_coreconfig.h" + + +static PyObject * +get_configs(PyObject *self, PyObject *Py_UNUSED(args)) +{ + return _Py_GetConfigsAsDict(); +} + + +static PyMethodDef TestMethods[] = { + {"get_configs", get_configs, METH_NOARGS}, + {NULL, NULL} /* sentinel */ +}; + + +static struct PyModuleDef _testcapimodule = { + PyModuleDef_HEAD_INIT, + "_testinternalcapi", + NULL, + -1, + TestMethods, + NULL, + NULL, + NULL, + NULL +}; + + +PyMODINIT_FUNC +PyInit__testinternalcapi(void) +{ + return PyModule_Create(&_testcapimodule); +} |