Skip to content

Commit 8d48775

Browse files
committed
TST: change one test package to use PyModEXPORT_FUNC (PEP 793)
1 parent b94af9c commit 8d48775

1 file changed

Lines changed: 28 additions & 2 deletions

File tree

tests/packages/link-library-in-subproject/foo/_examplemod.c

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,21 @@ static PyMethodDef methods[] = {
2323
{NULL, NULL, 0, NULL},
2424
};
2525

26-
static struct PyModuleDef module = {
26+
#if PY_VERSION_HEX >= 0x030F0000
27+
/* Use `PyModExport_<modname>` hook, new in Python 3.15 (PEP 793) */
28+
static PyModuleDef_Slot example_slots[] = {
29+
{Py_mod_name, "_example"},
30+
{Py_mod_methods, methods},
31+
{Py_mod_gil, Py_MOD_GIL_NOT_USED},
32+
{0, NULL}
33+
};
34+
35+
PyMODEXPORT_FUNC PyModExport__example(void) {
36+
return example_slots;
37+
}
38+
#else
39+
/* Use legacy method to create a module dynamically */
40+
static struct PyModuleDef moduledef = {
2741
PyModuleDef_HEAD_INIT,
2842
"_example",
2943
NULL,
@@ -33,5 +47,17 @@ static struct PyModuleDef module = {
3347

3448
PyMODINIT_FUNC PyInit__example(void)
3549
{
36-
return PyModule_Create(&module);
50+
PyObject *module;
51+
52+
module = PyModule_Create(&moduledef);
53+
if (module == NULL) {
54+
return module;
55+
}
56+
57+
#if Py_GIL_DISABLED
58+
PyUnstable_Module_SetGIL(module, Py_MOD_GIL_NOT_USED);
59+
#endif
60+
61+
return module;
3762
}
63+
#endif

0 commit comments

Comments
 (0)