diff --git a/dpctl/tests/_c_ext.c b/dpctl/tests/_c_ext.c index f254a58c60..f847f5ef40 100644 --- a/dpctl/tests/_c_ext.c +++ b/dpctl/tests/_c_ext.c @@ -88,24 +88,28 @@ static PyMethodDef CExtMethods[] = { {NULL, NULL, 0, NULL} /* Sentinel */ }; +static int c_ext_module_exec(PyObject *m) +{ + (void)(m); // avoid unused arguments warning + return import_dpctl(); +} + +static PyModuleDef_Slot c_ext_module_slots[] = { + {Py_mod_exec, c_ext_module_exec}, +#if PY_VERSION_HEX >= 0x030D0000 + {Py_mod_gil, Py_MOD_GIL_NOT_USED}, +#endif + {0, NULL}}; + static struct PyModuleDef c_ext_module = { PyModuleDef_HEAD_INIT, "_c_ext", /* name of module */ "", /* module documentation, may be NULL */ - -1, /* size of per-interpreter state of the module, - or -1 if the module keeps state in global variables. */ + 0, /* size of per-interpreter state of the module */ CExtMethods, - NULL, + c_ext_module_slots, NULL, NULL, NULL}; -PyMODINIT_FUNC PyInit__c_ext(void) -{ - PyObject *m = NULL; - - import_dpctl(); - - m = PyModule_Create(&c_ext_module); - return m; -} +PyMODINIT_FUNC PyInit__c_ext(void) { return PyModuleDef_Init(&c_ext_module); } diff --git a/dpctl/tests/test_headers.py b/dpctl/tests/test_headers.py index 7040e538f6..bf75c73665 100644 --- a/dpctl/tests/test_headers.py +++ b/dpctl/tests/test_headers.py @@ -11,6 +11,7 @@ def dpctl_c_extension(tmp_path_factory): import subprocess import sys import sysconfig + import warnings curr_dir = os.path.dirname(__file__) dr = tmp_path_factory.mktemp("_c_ext") @@ -34,8 +35,11 @@ def dpctl_c_extension(tmp_path_factory): if not pth: pytest.fail("C extension was not built") spec = spec_from_file_location("_c_ext", pth[0]) - builder_module = module_from_spec(spec) - spec.loader.exec_module(builder_module) + # fails if the module re-enables the GIL on a free-threaded build + with warnings.catch_warnings(): + warnings.simplefilter("error", RuntimeWarning) + builder_module = module_from_spec(spec) + spec.loader.exec_module(builder_module) return builder_module else: pytest.fail("C extension could not be built")