Skip to content

Commit 72d25d5

Browse files
vstinnerencukou
andauthored
[3.15] gh-155561: Build most _testlimitedcapi files with Py_TARGET_ABI3T (#155570) (#159144)
* gh-155561: Build most _testlimitedcapi files with Py_TARGET_ABI3T (#155570) The following files are not build with Py_TARGET_ABI3T: * Modules/_testlimitedcapi.c * Modules/_testlimitedcapi/heaptype_relative.c * Modules/_testlimitedcapi/vectorcall_limited.c (cherry picked from commit 5dfa606) * gh-155561: Use multi-phase init for Modules/_testlimitedcapi.c (GH-156052) Co-authored-by: Victor Stinner <vstinner@python.org> (cherry picked from commit 112560e) --------- Co-authored-by: Petr Viktorin <encukou@gmail.com>
1 parent c777fe5 commit 72d25d5

16 files changed

Lines changed: 102 additions & 76 deletions

File tree

‎Modules/_testlimitedcapi.c‎

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,116 +2,116 @@
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

88
#include "_testlimitedcapi/parts.h"
99

10-
static PyMethodDef TestMethods[] = {
11-
{NULL, NULL} /* sentinel */
12-
};
13-
14-
static struct PyModuleDef _testlimitedcapimodule = {
15-
PyModuleDef_HEAD_INIT,
16-
.m_name = "_testlimitedcapi",
17-
.m_size = 0,
18-
.m_methods = TestMethods,
19-
};
20-
21-
PyMODINIT_FUNC
22-
PyInit__testlimitedcapi(void)
10+
static int
11+
module_exec(PyObject *mod)
2312
{
24-
PyObject *mod = PyModule_Create(&_testlimitedcapimodule);
25-
if (mod == NULL) {
26-
return NULL;
27-
}
28-
#ifdef Py_GIL_DISABLED
29-
PyUnstable_Module_SetGIL(mod, Py_MOD_GIL_NOT_USED);
30-
#endif
31-
3213
if (_PyTestLimitedCAPI_Init_Abstract(mod) < 0) {
33-
return NULL;
14+
return -1;
3415
}
3516
if (_PyTestLimitedCAPI_Init_ByteArray(mod) < 0) {
36-
return NULL;
17+
return -1;
3718
}
3819
if (_PyTestLimitedCAPI_Init_Bytes(mod) < 0) {
39-
return NULL;
20+
return -1;
4021
}
4122
if (_PyTestLimitedCAPI_Init_Capsule(mod) < 0) {
42-
return NULL;
23+
return -1;
4324
}
4425
if (_PyTestLimitedCAPI_Init_Codec(mod) < 0) {
45-
return NULL;
26+
return -1;
4627
}
4728
if (_PyTestLimitedCAPI_Init_Complex(mod) < 0) {
48-
return NULL;
29+
return -1;
4930
}
5031
if (_PyTestLimitedCAPI_Init_Dict(mod) < 0) {
51-
return NULL;
32+
return -1;
5233
}
5334
if (_PyTestLimitedCAPI_Init_Eval(mod) < 0) {
54-
return NULL;
35+
return -1;
5536
}
5637
if (_PyTestLimitedCAPI_Init_Float(mod) < 0) {
57-
return NULL;
38+
return -1;
5839
}
5940
if (_PyTestLimitedCAPI_Init_HeaptypeRelative(mod) < 0) {
60-
return NULL;
41+
return -1;
6142
}
6243
if (_PyTestLimitedCAPI_Init_Import(mod) < 0) {
63-
return NULL;
44+
return -1;
6445
}
6546
if (_PyTestLimitedCAPI_Init_List(mod) < 0) {
66-
return NULL;
47+
return -1;
6748
}
6849
if (_PyTestLimitedCAPI_Init_Long(mod) < 0) {
69-
return NULL;
50+
return -1;
7051
}
7152
if (_PyTestLimitedCAPI_Init_Object(mod) < 0) {
72-
return NULL;
53+
return -1;
7354
}
7455
if (_PyTestLimitedCAPI_Init_PyOS(mod) < 0) {
75-
return NULL;
56+
return -1;
7657
}
7758
if (_PyTestLimitedCAPI_Init_Set(mod) < 0) {
78-
return NULL;
59+
return -1;
7960
}
8061
if (_PyTestLimitedCAPI_Init_Slice(mod) < 0) {
81-
return NULL;
62+
return -1;
8263
}
8364
if (_PyTestLimitedCAPI_Init_Slots(mod) < 0) {
84-
return NULL;
65+
return -1;
8566
}
8667
if (_PyTestLimitedCAPI_Init_Sys(mod) < 0) {
87-
return NULL;
68+
return -1;
8869
}
8970
if (_PyTestLimitedCAPI_Init_ThreadState(mod) < 0) {
90-
return NULL;
71+
return -1;
9172
}
9273
if (_PyTestLimitedCAPI_Init_Tuple(mod) < 0) {
93-
return NULL;
74+
return -1;
9475
}
9576
if (_PyTestLimitedCAPI_Init_Unicode(mod) < 0) {
96-
return NULL;
77+
return -1;
9778
}
9879
if (_PyTestLimitedCAPI_Init_VectorcallLimited(mod) < 0) {
99-
return NULL;
80+
return -1;
10081
}
10182
if (_PyTestLimitedCAPI_Init_Version(mod) < 0) {
102-
return NULL;
83+
return -1;
10384
}
10485
if (_PyTestLimitedCAPI_Init_File(mod) < 0) {
105-
return NULL;
86+
return -1;
10687
}
10788
if (_PyTestLimitedCAPI_Init_Weakref(mod) < 0) {
108-
return NULL;
89+
return -1;
10990
}
11091
if (_PyTestLimitedCAPI_Init_Run(mod) < 0) {
111-
return NULL;
92+
return -1;
11293
}
11394
if (_PyTestLimitedCAPI_Init_Type(mod) < 0) {
114-
return NULL;
95+
return -1;
11596
}
116-
return mod;
97+
return 0;
98+
}
99+
100+
static struct PyModuleDef _testlimitedcapimodule_def = {
101+
PyModuleDef_HEAD_INIT,
102+
.m_name = "_testlimitedcapi",
103+
.m_size = 0,
104+
.m_slots = (PyModuleDef_Slot[]){
105+
{Py_mod_exec, module_exec},
106+
#ifdef Py_GIL_DISABLED
107+
{Py_mod_gil, Py_MOD_GIL_NOT_USED},
108+
#endif
109+
{0}
110+
}
111+
};
112+
113+
PyMODINIT_FUNC
114+
PyInit__testlimitedcapi(void)
115+
{
116+
return PyModuleDef_Init(&_testlimitedcapimodule_def);
117117
}

‎Modules/_testlimitedcapi/capsule.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#include "parts.h"
22

3+
#include <stdlib.h> // free()
4+
5+
36
static void
47
capsule_destructor(PyObject *op)
58
{

‎Modules/_testlimitedcapi/codec.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#include "pyconfig.h" // Py_GIL_DISABLED
2-
3-
// Need limited C API version 3.5 for PyCodec_NameReplaceErrors()
4-
#if !defined(Py_GIL_DISABLED) && !defined(Py_LIMITED_API)
2+
#ifdef Py_GIL_DISABLED
3+
# define Py_TARGET_ABI3T 0x030f0000
4+
#else
5+
// Need limited C API version 3.5 for PyCodec_NameReplaceErrors()
56
# define Py_LIMITED_API 0x03050000
67
#endif
78

‎Modules/_testlimitedcapi/file.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "pyconfig.h" // Py_GIL_DISABLED
2-
#ifndef Py_GIL_DISABLED
2+
#ifdef Py_GIL_DISABLED
3+
# define Py_TARGET_ABI3T 0x030f0000
4+
#else
35
// Need limited C API 3.13 for PyLong_AsInt()
46
# define Py_LIMITED_API 0x030d0000
57
#endif

‎Modules/_testlimitedcapi/heaptype_relative.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
// Need limited C API version 3.15 for _DuringGC functions
21
#include "pyconfig.h" // Py_GIL_DISABLED
3-
#if !defined(Py_GIL_DISABLED) && !defined(Py_LIMITED_API)
2+
#ifdef Py_GIL_DISABLED
3+
// Cannot test the limited C API
4+
#else
5+
// Need limited C API version 3.15 for _DuringGC functions
46
# define Py_LIMITED_API 0x030f0000
57
#endif
68

‎Modules/_testlimitedcapi/import.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
// Need limited C API version 3.13 for PyImport_AddModuleRef()
21
#include "pyconfig.h" // Py_GIL_DISABLED
3-
#if !defined(Py_GIL_DISABLED) && !defined(Py_LIMITED_API)
2+
#ifdef Py_GIL_DISABLED
3+
# define Py_TARGET_ABI3T 0x030f0000
4+
#else
5+
// Need limited C API version 3.13 for PyImport_AddModuleRef()
46
# define Py_LIMITED_API 0x030d0000
57
#endif
68

‎Modules/_testlimitedcapi/list.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
// Need limited C API version 3.13 for PyList_GetItemRef()
21
#include "pyconfig.h" // Py_GIL_DISABLED
3-
#if !defined(Py_GIL_DISABLED) && !defined(Py_LIMITED_API)
2+
#ifdef Py_GIL_DISABLED
3+
# define Py_TARGET_ABI3T 0x030f0000
4+
#else
5+
// Need limited C API version 3.13 for PyList_GetItemRef()
46
# define Py_LIMITED_API 0x030d0000
57
#endif
68

‎Modules/_testlimitedcapi/long.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "pyconfig.h" // Py_GIL_DISABLED
2-
#ifndef Py_GIL_DISABLED
2+
#ifdef Py_GIL_DISABLED
3+
# define Py_TARGET_ABI3T 0x030f0000
4+
#else
35
// Need limited C API 3.14 to test PyLong_AsInt64()
46
# define Py_LIMITED_API 0x030e0000
57
#endif

‎Modules/_testlimitedcapi/object.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
// Need limited C API version 3.13 for Py_GetConstant()
21
#include "pyconfig.h" // Py_GIL_DISABLED
3-
#if !defined(Py_GIL_DISABLED) && !defined(Py_LIMITED_API)
2+
#ifdef Py_GIL_DISABLED
3+
# define Py_TARGET_ABI3T 0x030f0000
4+
#else
5+
// Need limited C API version 3.13 for Py_GetConstant()
46
# define Py_LIMITED_API 0x030d0000
57
#endif
68

‎Modules/_testlimitedcapi/parts.h‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
#include "pyconfig.h" // Py_GIL_DISABLED
88

99
// Use the limited C API
10-
#if !defined(Py_GIL_DISABLED) && !defined(Py_LIMITED_API)
11-
// need limited C API version 3.5 for PyModule_AddFunctions()
10+
#ifdef Py_GIL_DISABLED
11+
// Cannot test the limited C API
12+
#elif !defined(Py_LIMITED_API)
13+
// Need limited C API version 3.5 for PyModule_AddFunctions()
1214
# define Py_LIMITED_API 0x03050000
1315
#endif
1416

0 commit comments

Comments
 (0)