File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -88,24 +88,28 @@ static PyMethodDef CExtMethods[] = {
8888 {NULL , NULL , 0 , NULL } /* Sentinel */
8989};
9090
91+ static int c_ext_module_exec (PyObject * m )
92+ {
93+ (void )(m ); // avoid unused arguments warning
94+ return import_dpctl ();
95+ }
96+
97+ static PyModuleDef_Slot c_ext_module_slots [] = {
98+ {Py_mod_exec , c_ext_module_exec },
99+ #if PY_VERSION_HEX >= 0x030D0000
100+ {Py_mod_gil , Py_MOD_GIL_NOT_USED },
101+ #endif
102+ {0 , NULL }};
103+
91104static struct PyModuleDef c_ext_module = {
92105 PyModuleDef_HEAD_INIT ,
93106 "_c_ext" , /* name of module */
94107 "" , /* module documentation, may be NULL */
95- -1 , /* size of per-interpreter state of the module,
96- or -1 if the module keeps state in global variables. */
108+ 0 , /* size of per-interpreter state of the module */
97109 CExtMethods ,
98- NULL ,
110+ c_ext_module_slots ,
99111 NULL ,
100112 NULL ,
101113 NULL };
102114
103- PyMODINIT_FUNC PyInit__c_ext (void )
104- {
105- PyObject * m = NULL ;
106-
107- import_dpctl ();
108-
109- m = PyModule_Create (& c_ext_module );
110- return m ;
111- }
115+ PyMODINIT_FUNC PyInit__c_ext (void ) { return PyModuleDef_Init (& c_ext_module ); }
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ def dpctl_c_extension(tmp_path_factory):
1111 import subprocess
1212 import sys
1313 import sysconfig
14+ import warnings
1415
1516 curr_dir = os .path .dirname (__file__ )
1617 dr = tmp_path_factory .mktemp ("_c_ext" )
@@ -34,8 +35,11 @@ def dpctl_c_extension(tmp_path_factory):
3435 if not pth :
3536 pytest .fail ("C extension was not built" )
3637 spec = spec_from_file_location ("_c_ext" , pth [0 ])
37- builder_module = module_from_spec (spec )
38- spec .loader .exec_module (builder_module )
38+ # fails if the module re-enables the GIL on a free-threaded build
39+ with warnings .catch_warnings ():
40+ warnings .simplefilter ("error" , RuntimeWarning )
41+ builder_module = module_from_spec (spec )
42+ spec .loader .exec_module (builder_module )
3943 return builder_module
4044 else :
4145 pytest .fail ("C extension could not be built" )
You can’t perform that action at this time.
0 commit comments