|
2 | 2 | * Test the limited C API. |
3 | 3 | * |
4 | 4 | * The 'test_*' functions exported by this module are run as part of the |
5 | | - * standard Python regression test, via Lib/test/test_capi.py. |
| 5 | + * standard Python regression test, via Lib/test/test_capi/test_misc.py. |
6 | 6 | */ |
7 | 7 |
|
8 | | -#include "pyconfig.h" // Py_GIL_DISABLED |
9 | | - |
10 | | -#ifdef Py_GIL_DISABLED |
11 | | - // Cannot test the limited C API |
12 | | -#else |
13 | | - // Use the oldest limited C API version |
14 | | -# define Py_LIMITED_API 0x03020000 |
15 | | -#endif |
| 8 | +// Need limited C API version 3.15 for PySlot |
| 9 | +#define Py_LIMITED_API 0x030f0000 |
16 | 10 |
|
17 | 11 | #include "_testlimitedcapi/parts.h" |
18 | 12 |
|
19 | | -static PyMethodDef TestMethods[] = { |
20 | | - {NULL, NULL} /* sentinel */ |
21 | | -}; |
22 | | - |
23 | | -static struct PyModuleDef _testlimitedcapimodule = { |
24 | | - PyModuleDef_HEAD_INIT, |
25 | | - .m_name = "_testlimitedcapi", |
26 | | - .m_size = 0, |
27 | | - .m_methods = TestMethods, |
28 | | -}; |
29 | | - |
30 | | -PyMODINIT_FUNC |
31 | | -PyInit__testlimitedcapi(void) |
| 13 | +static int |
| 14 | +module_exec(PyObject *mod) |
32 | 15 | { |
33 | | - PyObject *mod = PyModule_Create(&_testlimitedcapimodule); |
34 | | - if (mod == NULL) { |
35 | | - return NULL; |
36 | | - } |
37 | | -#ifdef Py_GIL_DISABLED |
38 | | - PyUnstable_Module_SetGIL(mod, Py_MOD_GIL_NOT_USED); |
39 | | -#endif |
40 | | - |
41 | 16 | if (_PyTestLimitedCAPI_Init_Abstract(mod) < 0) { |
42 | | - return NULL; |
| 17 | + return -1; |
43 | 18 | } |
44 | 19 | if (_PyTestLimitedCAPI_Init_ByteArray(mod) < 0) { |
45 | | - return NULL; |
| 20 | + return -1; |
46 | 21 | } |
47 | 22 | if (_PyTestLimitedCAPI_Init_Bytes(mod) < 0) { |
48 | | - return NULL; |
| 23 | + return -1; |
49 | 24 | } |
50 | 25 | if (_PyTestLimitedCAPI_Init_Capsule(mod) < 0) { |
51 | | - return NULL; |
| 26 | + return -1; |
52 | 27 | } |
53 | 28 | if (_PyTestLimitedCAPI_Init_Codec(mod) < 0) { |
54 | | - return NULL; |
| 29 | + return -1; |
55 | 30 | } |
56 | 31 | if (_PyTestLimitedCAPI_Init_Complex(mod) < 0) { |
57 | | - return NULL; |
| 32 | + return -1; |
58 | 33 | } |
59 | 34 | if (_PyTestLimitedCAPI_Init_Dict(mod) < 0) { |
60 | | - return NULL; |
| 35 | + return -1; |
61 | 36 | } |
62 | 37 | if (_PyTestLimitedCAPI_Init_Eval(mod) < 0) { |
63 | | - return NULL; |
| 38 | + return -1; |
64 | 39 | } |
65 | 40 | if (_PyTestLimitedCAPI_Init_Float(mod) < 0) { |
66 | | - return NULL; |
| 41 | + return -1; |
67 | 42 | } |
68 | 43 | if (_PyTestLimitedCAPI_Init_HeaptypeRelative(mod) < 0) { |
69 | | - return NULL; |
| 44 | + return -1; |
70 | 45 | } |
71 | 46 | if (_PyTestLimitedCAPI_Init_Import(mod) < 0) { |
72 | | - return NULL; |
| 47 | + return -1; |
73 | 48 | } |
74 | 49 | if (_PyTestLimitedCAPI_Init_List(mod) < 0) { |
75 | | - return NULL; |
| 50 | + return -1; |
76 | 51 | } |
77 | 52 | if (_PyTestLimitedCAPI_Init_Long(mod) < 0) { |
78 | | - return NULL; |
| 53 | + return -1; |
79 | 54 | } |
80 | 55 | if (_PyTestLimitedCAPI_Init_Object(mod) < 0) { |
81 | | - return NULL; |
| 56 | + return -1; |
82 | 57 | } |
83 | 58 | if (_PyTestLimitedCAPI_Init_PyOS(mod) < 0) { |
84 | | - return NULL; |
| 59 | + return -1; |
85 | 60 | } |
86 | 61 | if (_PyTestLimitedCAPI_Init_Set(mod) < 0) { |
87 | | - return NULL; |
| 62 | + return -1; |
88 | 63 | } |
89 | 64 | if (_PyTestLimitedCAPI_Init_Slots(mod) < 0) { |
90 | | - return NULL; |
| 65 | + return -1; |
91 | 66 | } |
92 | 67 | if (_PyTestLimitedCAPI_Init_Sys(mod) < 0) { |
93 | | - return NULL; |
| 68 | + return -1; |
94 | 69 | } |
95 | 70 | if (_PyTestLimitedCAPI_Init_ThreadState(mod) < 0) { |
96 | | - return NULL; |
| 71 | + return -1; |
97 | 72 | } |
98 | 73 | if (_PyTestLimitedCAPI_Init_Tuple(mod) < 0) { |
99 | | - return NULL; |
| 74 | + return -1; |
100 | 75 | } |
101 | 76 | if (_PyTestLimitedCAPI_Init_Unicode(mod) < 0) { |
102 | | - return NULL; |
| 77 | + return -1; |
103 | 78 | } |
104 | 79 | if (_PyTestLimitedCAPI_Init_VectorcallLimited(mod) < 0) { |
105 | | - return NULL; |
| 80 | + return -1; |
106 | 81 | } |
107 | 82 | if (_PyTestLimitedCAPI_Init_Version(mod) < 0) { |
108 | | - return NULL; |
| 83 | + return -1; |
109 | 84 | } |
110 | 85 | if (_PyTestLimitedCAPI_Init_File(mod) < 0) { |
111 | | - return NULL; |
| 86 | + return -1; |
112 | 87 | } |
113 | 88 | if (_PyTestLimitedCAPI_Init_Weakref(mod) < 0) { |
114 | | - return NULL; |
| 89 | + return -1; |
115 | 90 | } |
116 | 91 | if (_PyTestLimitedCAPI_Init_Run(mod) < 0) { |
117 | | - return NULL; |
| 92 | + return -1; |
118 | 93 | } |
119 | | - if (_PyTestLimitedCAPI_Init_Type(mod) < 0) { |
120 | | - return NULL; |
121 | | - } |
122 | | - return mod; |
| 94 | + return 0; |
| 95 | +} |
| 96 | + |
| 97 | +PyABIInfo_VAR(abi_info); |
| 98 | + |
| 99 | +static PySlot _testlimitedcapimodule_slots[] = { |
| 100 | + PySlot_DATA(Py_mod_abi, &abi_info), |
| 101 | + PySlot_STATIC_DATA(Py_mod_name, "_testlimitedcapi"), |
| 102 | + PySlot_SIZE(Py_mod_state_size, 0), |
| 103 | + PySlot_FUNC(Py_mod_exec, module_exec), |
| 104 | + PySlot_SIZE(Py_mod_gil, Py_MOD_GIL_NOT_USED), |
| 105 | + PySlot_END |
| 106 | +}; |
| 107 | + |
| 108 | +PyMODEXPORT_FUNC |
| 109 | +PyModExport__testlimitedcapi(void) |
| 110 | +{ |
| 111 | + return _testlimitedcapimodule_slots; |
123 | 112 | } |
0 commit comments