Skip to content

Commit a11419e

Browse files
committed
gh-155561: Use PySlot API in Modules/_testlimitedcapi.c
1 parent 76f2903 commit a11419e

1 file changed

Lines changed: 49 additions & 60 deletions

File tree

Modules/_testlimitedcapi.c

Lines changed: 49 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -2,122 +2,111 @@
22
* Test the limited C API.
33
*
44
* 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.
66
*/
77

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
1610

1711
#include "_testlimitedcapi/parts.h"
1812

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)
3215
{
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-
4116
if (_PyTestLimitedCAPI_Init_Abstract(mod) < 0) {
42-
return NULL;
17+
return -1;
4318
}
4419
if (_PyTestLimitedCAPI_Init_ByteArray(mod) < 0) {
45-
return NULL;
20+
return -1;
4621
}
4722
if (_PyTestLimitedCAPI_Init_Bytes(mod) < 0) {
48-
return NULL;
23+
return -1;
4924
}
5025
if (_PyTestLimitedCAPI_Init_Capsule(mod) < 0) {
51-
return NULL;
26+
return -1;
5227
}
5328
if (_PyTestLimitedCAPI_Init_Codec(mod) < 0) {
54-
return NULL;
29+
return -1;
5530
}
5631
if (_PyTestLimitedCAPI_Init_Complex(mod) < 0) {
57-
return NULL;
32+
return -1;
5833
}
5934
if (_PyTestLimitedCAPI_Init_Dict(mod) < 0) {
60-
return NULL;
35+
return -1;
6136
}
6237
if (_PyTestLimitedCAPI_Init_Eval(mod) < 0) {
63-
return NULL;
38+
return -1;
6439
}
6540
if (_PyTestLimitedCAPI_Init_Float(mod) < 0) {
66-
return NULL;
41+
return -1;
6742
}
6843
if (_PyTestLimitedCAPI_Init_HeaptypeRelative(mod) < 0) {
69-
return NULL;
44+
return -1;
7045
}
7146
if (_PyTestLimitedCAPI_Init_Import(mod) < 0) {
72-
return NULL;
47+
return -1;
7348
}
7449
if (_PyTestLimitedCAPI_Init_List(mod) < 0) {
75-
return NULL;
50+
return -1;
7651
}
7752
if (_PyTestLimitedCAPI_Init_Long(mod) < 0) {
78-
return NULL;
53+
return -1;
7954
}
8055
if (_PyTestLimitedCAPI_Init_Object(mod) < 0) {
81-
return NULL;
56+
return -1;
8257
}
8358
if (_PyTestLimitedCAPI_Init_PyOS(mod) < 0) {
84-
return NULL;
59+
return -1;
8560
}
8661
if (_PyTestLimitedCAPI_Init_Set(mod) < 0) {
87-
return NULL;
62+
return -1;
8863
}
8964
if (_PyTestLimitedCAPI_Init_Slots(mod) < 0) {
90-
return NULL;
65+
return -1;
9166
}
9267
if (_PyTestLimitedCAPI_Init_Sys(mod) < 0) {
93-
return NULL;
68+
return -1;
9469
}
9570
if (_PyTestLimitedCAPI_Init_ThreadState(mod) < 0) {
96-
return NULL;
71+
return -1;
9772
}
9873
if (_PyTestLimitedCAPI_Init_Tuple(mod) < 0) {
99-
return NULL;
74+
return -1;
10075
}
10176
if (_PyTestLimitedCAPI_Init_Unicode(mod) < 0) {
102-
return NULL;
77+
return -1;
10378
}
10479
if (_PyTestLimitedCAPI_Init_VectorcallLimited(mod) < 0) {
105-
return NULL;
80+
return -1;
10681
}
10782
if (_PyTestLimitedCAPI_Init_Version(mod) < 0) {
108-
return NULL;
83+
return -1;
10984
}
11085
if (_PyTestLimitedCAPI_Init_File(mod) < 0) {
111-
return NULL;
86+
return -1;
11287
}
11388
if (_PyTestLimitedCAPI_Init_Weakref(mod) < 0) {
114-
return NULL;
89+
return -1;
11590
}
11691
if (_PyTestLimitedCAPI_Init_Run(mod) < 0) {
117-
return NULL;
92+
return -1;
11893
}
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;
123112
}

0 commit comments

Comments
 (0)