Skip to content

Commit 73210d4

Browse files
committed
Convert limited API examples to multi-phase init (PEP 489)
1 parent bbdebae commit 73210d4

File tree

2 files changed

+50
-10
lines changed

2 files changed

+50
-10
lines changed

numpy/_core/tests/examples/limited_api/limited_api1.c

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,34 @@
44
#include <numpy/arrayobject.h>
55
#include <numpy/ufuncobject.h>
66

7-
static PyModuleDef moduledef = {
7+
static int
8+
_limited_api1_exec(void)
9+
{
10+
import_array1(-1);
11+
import_umath1(-1);
12+
return 0;
13+
}
14+
15+
static struct PyModuleDef_Slot limited_api1_slots[] = {
16+
{Py_mod_exec, _limited_api1_exec},
17+
#if PY_VERSION_HEX >= 0x030c00f0 // Python 3.12+
18+
{Py_mod_multiple_interpreters, Py_MOD_MULTIPLE_INTERPRETERS_NOT_SUPPORTED},
19+
#endif
20+
#if PY_VERSION_HEX >= 0x030d00f0 // Python 3.13+
21+
// signal that this module supports running without an active GIL
22+
{Py_mod_gil, Py_MOD_GIL_NOT_USED},
23+
#endif
24+
{0, NULL},
25+
};
26+
27+
static struct PyModuleDef moduledef = {
828
.m_base = PyModuleDef_HEAD_INIT,
9-
.m_name = "limited_api1"
29+
.m_name = "limited_api1",
30+
.m_size = 0,
31+
.m_slots = limited_api1_slots,
1032
};
1133

1234
PyMODINIT_FUNC PyInit_limited_api1(void)
1335
{
14-
import_array();
15-
import_umath();
16-
return PyModule_Create(&moduledef);
36+
return PyModuleDef_Init(&moduledef);
1737
}

numpy/_core/tests/examples/limited_api/limited_api_latest.c

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,34 @@
66
#include <numpy/arrayobject.h>
77
#include <numpy/ufuncobject.h>
88

9-
static PyModuleDef moduledef = {
9+
static int
10+
_limited_api_latest_exec(void)
11+
{
12+
import_array1(-1);
13+
import_umath1(-1);
14+
return 0;
15+
}
16+
17+
static struct PyModuleDef_Slot limited_api_latest_slots[] = {
18+
{Py_mod_exec, _limited_api_latest_exec},
19+
#if PY_VERSION_HEX >= 0x030c00f0 // Python 3.12+
20+
{Py_mod_multiple_interpreters, Py_MOD_MULTIPLE_INTERPRETERS_NOT_SUPPORTED},
21+
#endif
22+
#if PY_VERSION_HEX >= 0x030d00f0 // Python 3.13+
23+
// signal that this module supports running without an active GIL
24+
{Py_mod_gil, Py_MOD_GIL_NOT_USED},
25+
#endif
26+
{0, NULL},
27+
};
28+
29+
static struct PyModuleDef moduledef = {
1030
.m_base = PyModuleDef_HEAD_INIT,
11-
.m_name = "limited_api_latest"
31+
.m_name = "limited_api_latest",
32+
.m_size = 0,
33+
.m_slots = limited_api_latest_slots,
1234
};
1335

1436
PyMODINIT_FUNC PyInit_limited_api_latest(void)
1537
{
16-
import_array();
17-
import_umath();
18-
return PyModule_Create(&moduledef);
38+
return PyModuleDef_Init(&moduledef);
1939
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy