diff --git a/Modules/_testlimitedcapi.c b/Modules/_testlimitedcapi.c index 4c6b7c0cb2b618f..1165f5317e7e279 100644 --- a/Modules/_testlimitedcapi.c +++ b/Modules/_testlimitedcapi.c @@ -2,116 +2,116 @@ * Test the limited C API. * * The 'test_*' functions exported by this module are run as part of the - * standard Python regression test, via Lib/test/test_capi.py. + * standard Python regression test, via Lib/test/test_capi/test_misc.py. */ #include "_testlimitedcapi/parts.h" -static PyMethodDef TestMethods[] = { - {NULL, NULL} /* sentinel */ -}; - -static struct PyModuleDef _testlimitedcapimodule = { - PyModuleDef_HEAD_INIT, - .m_name = "_testlimitedcapi", - .m_size = 0, - .m_methods = TestMethods, -}; - -PyMODINIT_FUNC -PyInit__testlimitedcapi(void) +static int +module_exec(PyObject *mod) { - PyObject *mod = PyModule_Create(&_testlimitedcapimodule); - if (mod == NULL) { - return NULL; - } -#ifdef Py_GIL_DISABLED - PyUnstable_Module_SetGIL(mod, Py_MOD_GIL_NOT_USED); -#endif - if (_PyTestLimitedCAPI_Init_Abstract(mod) < 0) { - return NULL; + return -1; } if (_PyTestLimitedCAPI_Init_ByteArray(mod) < 0) { - return NULL; + return -1; } if (_PyTestLimitedCAPI_Init_Bytes(mod) < 0) { - return NULL; + return -1; } if (_PyTestLimitedCAPI_Init_Capsule(mod) < 0) { - return NULL; + return -1; } if (_PyTestLimitedCAPI_Init_Codec(mod) < 0) { - return NULL; + return -1; } if (_PyTestLimitedCAPI_Init_Complex(mod) < 0) { - return NULL; + return -1; } if (_PyTestLimitedCAPI_Init_Dict(mod) < 0) { - return NULL; + return -1; } if (_PyTestLimitedCAPI_Init_Eval(mod) < 0) { - return NULL; + return -1; } if (_PyTestLimitedCAPI_Init_Float(mod) < 0) { - return NULL; + return -1; } if (_PyTestLimitedCAPI_Init_HeaptypeRelative(mod) < 0) { - return NULL; + return -1; } if (_PyTestLimitedCAPI_Init_Import(mod) < 0) { - return NULL; + return -1; } if (_PyTestLimitedCAPI_Init_List(mod) < 0) { - return NULL; + return -1; } if (_PyTestLimitedCAPI_Init_Long(mod) < 0) { - return NULL; + return -1; } if (_PyTestLimitedCAPI_Init_Object(mod) < 0) { - return NULL; + return -1; } if (_PyTestLimitedCAPI_Init_PyOS(mod) < 0) { - return NULL; + return -1; } if (_PyTestLimitedCAPI_Init_Set(mod) < 0) { - return NULL; + return -1; } if (_PyTestLimitedCAPI_Init_Slice(mod) < 0) { - return NULL; + return -1; } if (_PyTestLimitedCAPI_Init_Slots(mod) < 0) { - return NULL; + return -1; } if (_PyTestLimitedCAPI_Init_Sys(mod) < 0) { - return NULL; + return -1; } if (_PyTestLimitedCAPI_Init_ThreadState(mod) < 0) { - return NULL; + return -1; } if (_PyTestLimitedCAPI_Init_Tuple(mod) < 0) { - return NULL; + return -1; } if (_PyTestLimitedCAPI_Init_Unicode(mod) < 0) { - return NULL; + return -1; } if (_PyTestLimitedCAPI_Init_VectorcallLimited(mod) < 0) { - return NULL; + return -1; } if (_PyTestLimitedCAPI_Init_Version(mod) < 0) { - return NULL; + return -1; } if (_PyTestLimitedCAPI_Init_File(mod) < 0) { - return NULL; + return -1; } if (_PyTestLimitedCAPI_Init_Weakref(mod) < 0) { - return NULL; + return -1; } if (_PyTestLimitedCAPI_Init_Run(mod) < 0) { - return NULL; + return -1; } if (_PyTestLimitedCAPI_Init_Type(mod) < 0) { - return NULL; + return -1; } - return mod; + return 0; +} + +static struct PyModuleDef _testlimitedcapimodule_def = { + PyModuleDef_HEAD_INIT, + .m_name = "_testlimitedcapi", + .m_size = 0, + .m_slots = (PyModuleDef_Slot[]){ + {Py_mod_exec, module_exec}, +#ifdef Py_GIL_DISABLED + {Py_mod_gil, Py_MOD_GIL_NOT_USED}, +#endif + {0} + } +}; + +PyMODINIT_FUNC +PyInit__testlimitedcapi(void) +{ + return PyModuleDef_Init(&_testlimitedcapimodule_def); } diff --git a/Modules/_testlimitedcapi/capsule.c b/Modules/_testlimitedcapi/capsule.c index 07b85823f399ba3..8dd870034023a35 100644 --- a/Modules/_testlimitedcapi/capsule.c +++ b/Modules/_testlimitedcapi/capsule.c @@ -1,5 +1,8 @@ #include "parts.h" +#include // free() + + static void capsule_destructor(PyObject *op) { diff --git a/Modules/_testlimitedcapi/codec.c b/Modules/_testlimitedcapi/codec.c index fdc18eedc2d2886..44eecf99f678bb8 100644 --- a/Modules/_testlimitedcapi/codec.c +++ b/Modules/_testlimitedcapi/codec.c @@ -1,7 +1,8 @@ #include "pyconfig.h" // Py_GIL_DISABLED - -// Need limited C API version 3.5 for PyCodec_NameReplaceErrors() -#if !defined(Py_GIL_DISABLED) && !defined(Py_LIMITED_API) +#ifdef Py_GIL_DISABLED +# define Py_TARGET_ABI3T 0x030f0000 +#else + // Need limited C API version 3.5 for PyCodec_NameReplaceErrors() # define Py_LIMITED_API 0x03050000 #endif diff --git a/Modules/_testlimitedcapi/file.c b/Modules/_testlimitedcapi/file.c index e082e3c6700ee71..c627c6ceaa201ef 100644 --- a/Modules/_testlimitedcapi/file.c +++ b/Modules/_testlimitedcapi/file.c @@ -1,5 +1,7 @@ #include "pyconfig.h" // Py_GIL_DISABLED -#ifndef Py_GIL_DISABLED +#ifdef Py_GIL_DISABLED +# define Py_TARGET_ABI3T 0x030f0000 +#else // Need limited C API 3.13 for PyLong_AsInt() # define Py_LIMITED_API 0x030d0000 #endif diff --git a/Modules/_testlimitedcapi/heaptype_relative.c b/Modules/_testlimitedcapi/heaptype_relative.c index c02a52368b5324c..a5e15026f028ca7 100644 --- a/Modules/_testlimitedcapi/heaptype_relative.c +++ b/Modules/_testlimitedcapi/heaptype_relative.c @@ -1,6 +1,8 @@ -// Need limited C API version 3.15 for _DuringGC functions #include "pyconfig.h" // Py_GIL_DISABLED -#if !defined(Py_GIL_DISABLED) && !defined(Py_LIMITED_API) +#ifdef Py_GIL_DISABLED + // Cannot test the limited C API +#else + // Need limited C API version 3.15 for _DuringGC functions # define Py_LIMITED_API 0x030f0000 #endif diff --git a/Modules/_testlimitedcapi/import.c b/Modules/_testlimitedcapi/import.c index f572212ba88b76e..48c477bf3ccc489 100644 --- a/Modules/_testlimitedcapi/import.c +++ b/Modules/_testlimitedcapi/import.c @@ -1,6 +1,8 @@ -// Need limited C API version 3.13 for PyImport_AddModuleRef() #include "pyconfig.h" // Py_GIL_DISABLED -#if !defined(Py_GIL_DISABLED) && !defined(Py_LIMITED_API) +#ifdef Py_GIL_DISABLED +# define Py_TARGET_ABI3T 0x030f0000 +#else + // Need limited C API version 3.13 for PyImport_AddModuleRef() # define Py_LIMITED_API 0x030d0000 #endif diff --git a/Modules/_testlimitedcapi/list.c b/Modules/_testlimitedcapi/list.c index ed492c3e719727a..91c8ad60e3b990d 100644 --- a/Modules/_testlimitedcapi/list.c +++ b/Modules/_testlimitedcapi/list.c @@ -1,6 +1,8 @@ -// Need limited C API version 3.13 for PyList_GetItemRef() #include "pyconfig.h" // Py_GIL_DISABLED -#if !defined(Py_GIL_DISABLED) && !defined(Py_LIMITED_API) +#ifdef Py_GIL_DISABLED +# define Py_TARGET_ABI3T 0x030f0000 +#else + // Need limited C API version 3.13 for PyList_GetItemRef() # define Py_LIMITED_API 0x030d0000 #endif diff --git a/Modules/_testlimitedcapi/long.c b/Modules/_testlimitedcapi/long.c index 01d762165867421..1654f9210e1d0ba 100644 --- a/Modules/_testlimitedcapi/long.c +++ b/Modules/_testlimitedcapi/long.c @@ -1,5 +1,7 @@ #include "pyconfig.h" // Py_GIL_DISABLED -#ifndef Py_GIL_DISABLED +#ifdef Py_GIL_DISABLED +# define Py_TARGET_ABI3T 0x030f0000 +#else // Need limited C API 3.14 to test PyLong_AsInt64() # define Py_LIMITED_API 0x030e0000 #endif diff --git a/Modules/_testlimitedcapi/object.c b/Modules/_testlimitedcapi/object.c index da6fe3e4efa34c2..594ba60f9abf204 100644 --- a/Modules/_testlimitedcapi/object.c +++ b/Modules/_testlimitedcapi/object.c @@ -1,6 +1,8 @@ -// Need limited C API version 3.13 for Py_GetConstant() #include "pyconfig.h" // Py_GIL_DISABLED -#if !defined(Py_GIL_DISABLED) && !defined(Py_LIMITED_API) +#ifdef Py_GIL_DISABLED +# define Py_TARGET_ABI3T 0x030f0000 +#else + // Need limited C API version 3.13 for Py_GetConstant() # define Py_LIMITED_API 0x030d0000 #endif diff --git a/Modules/_testlimitedcapi/parts.h b/Modules/_testlimitedcapi/parts.h index 03bfb74b4ce1adc..95bfbc7e1ff6cbd 100644 --- a/Modules/_testlimitedcapi/parts.h +++ b/Modules/_testlimitedcapi/parts.h @@ -7,8 +7,10 @@ #include "pyconfig.h" // Py_GIL_DISABLED // Use the limited C API -#if !defined(Py_GIL_DISABLED) && !defined(Py_LIMITED_API) - // need limited C API version 3.5 for PyModule_AddFunctions() +#ifdef Py_GIL_DISABLED + // Cannot test the limited C API +#elif !defined(Py_LIMITED_API) + // Need limited C API version 3.5 for PyModule_AddFunctions() # define Py_LIMITED_API 0x03050000 #endif diff --git a/Modules/_testlimitedcapi/slots.c b/Modules/_testlimitedcapi/slots.c index 9abe53d21154645..2a887cd49f4c4b7 100644 --- a/Modules/_testlimitedcapi/slots.c +++ b/Modules/_testlimitedcapi/slots.c @@ -1,3 +1,4 @@ +// Need limited C API version 3.15 for PyType_FromSlots() #define Py_LIMITED_API 0x030f0000 #include "parts.h" diff --git a/Modules/_testlimitedcapi/sys.c b/Modules/_testlimitedcapi/sys.c index cec7f8ab6120198..618f4847c7ac6e5 100644 --- a/Modules/_testlimitedcapi/sys.c +++ b/Modules/_testlimitedcapi/sys.c @@ -1,8 +1,6 @@ -#include "pyconfig.h" // Py_GIL_DISABLED // Need limited C API version 3.15 for PySys_GetAttr() etc -#if !defined(Py_GIL_DISABLED) && !defined(Py_LIMITED_API) -# define Py_LIMITED_API 0x030f0000 -#endif +#define Py_LIMITED_API 0x030f0000 + #include "parts.h" #include "util.h" diff --git a/Modules/_testlimitedcapi/unicode.c b/Modules/_testlimitedcapi/unicode.c index c7a23d5d1cbd71a..980b192fdc3cbb6 100644 --- a/Modules/_testlimitedcapi/unicode.c +++ b/Modules/_testlimitedcapi/unicode.c @@ -1,5 +1,7 @@ #include "pyconfig.h" // Py_GIL_DISABLED -#ifndef Py_GIL_DISABLED +#ifdef Py_GIL_DISABLED +# define Py_TARGET_ABI3T 0x030f0000 +#else // Need limited C API 3.14 to test PyUnicode_Equal() # define Py_LIMITED_API 0x030e0000 #endif diff --git a/Modules/_testlimitedcapi/vectorcall_limited.c b/Modules/_testlimitedcapi/vectorcall_limited.c index 84362d523f49633..443c4aca28e3ae7 100644 --- a/Modules/_testlimitedcapi/vectorcall_limited.c +++ b/Modules/_testlimitedcapi/vectorcall_limited.c @@ -1,8 +1,10 @@ /* Test Vectorcall in the limited API */ -// Need limited C API version 3.12 for PyObject_Vectorcall() #include "pyconfig.h" // Py_GIL_DISABLED -#if !defined(Py_GIL_DISABLED) && !defined(Py_LIMITED_API) +#ifdef Py_GIL_DISABLED + // Cannot test the limited C API +#else + // Need limited C API version 3.12 for PyObject_Vectorcall() # define Py_LIMITED_API 0x030c0000 #endif diff --git a/Modules/_testlimitedcapi/version.c b/Modules/_testlimitedcapi/version.c index 57cd6e4e928ea3f..d2a4551159165c0 100644 --- a/Modules/_testlimitedcapi/version.c +++ b/Modules/_testlimitedcapi/version.c @@ -1,8 +1,11 @@ /* Test version macros in the limited API */ #include "pyconfig.h" // Py_GIL_DISABLED -#ifndef Py_GIL_DISABLED -# define Py_LIMITED_API 0x030e0000 // Added in 3.14 +#ifdef Py_GIL_DISABLED +# define Py_TARGET_ABI3T 0x030f0000 +#else + // Need limited C API version 3.14 for Py_PACK_VERSION() +# define Py_LIMITED_API 0x030e0000 #endif #include "parts.h" diff --git a/Modules/_testlimitedcapi/weakref.c b/Modules/_testlimitedcapi/weakref.c index e7f9d54d1a0d59e..a25e39e21af3748 100644 --- a/Modules/_testlimitedcapi/weakref.c +++ b/Modules/_testlimitedcapi/weakref.c @@ -1,5 +1,7 @@ #include "pyconfig.h" // Py_GIL_DISABLED -#ifndef Py_GIL_DISABLED +#ifdef Py_GIL_DISABLED +# define Py_TARGET_ABI3T 0x030f0000 +#else // Need limited C API 3.5 for PyModule_AddFunctions() # define Py_LIMITED_API 0x03050000 #endif