Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions dpctl/tests/_c_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
8 changes: 6 additions & 2 deletions dpctl/tests/test_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand Down
Loading