Skip to content

Commit 3e82c25

Browse files
committed
Add more gil & interpreters slots
1 parent 91d59e9 commit 3e82c25

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

Lib/test/test_capi/test_module.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import unittest
55
import types
6-
from test.support import import_helper, subTests
6+
from test.support import import_helper, subTests, requires_gil_enabled
77

88
# Skip this test if the _testcapi module isn't available.
99
_testcapi = import_helper.import_module('_testcapi')
@@ -25,6 +25,7 @@ def def_and_token(mod):
2525
)
2626

2727
class TestModFromSlotsAndSpec(unittest.TestCase):
28+
@requires_gil_enabled("empty slots re-enable GIL")
2829
def test_empty(self):
2930
mod = _testcapi.module_from_slots_empty(FakeSpec())
3031
self.assertIsInstance(mod, types.ModuleType)

Modules/_testcapi/module.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ module_from_slots_name(PyObject *self, PyObject *spec)
2727
{
2828
PyModuleDef_Slot slots[] = {
2929
{Py_mod_name, "currently ignored..."},
30+
{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
31+
{Py_mod_gil, Py_MOD_GIL_NOT_USED},
3032
{0},
3133
};
3234
return PyModule_FromSlotsAndSpec(slots, spec);
@@ -37,6 +39,8 @@ module_from_slots_doc(PyObject *self, PyObject *spec)
3739
{
3840
PyModuleDef_Slot slots[] = {
3941
{Py_mod_doc, "the docstring"},
42+
{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
43+
{Py_mod_gil, Py_MOD_GIL_NOT_USED},
4044
{0},
4145
};
4246
return PyModule_FromSlotsAndSpec(slots, spec);
@@ -47,6 +51,8 @@ module_from_slots_size(PyObject *self, PyObject *spec)
4751
{
4852
PyModuleDef_Slot slots[] = {
4953
{Py_mod_state_size, (void*)123},
54+
{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
55+
{Py_mod_gil, Py_MOD_GIL_NOT_USED},
5056
{0},
5157
};
5258
PyObject *mod = PyModule_FromSlotsAndSpec(slots, spec);
@@ -72,6 +78,8 @@ module_from_slots_methods(PyObject *self, PyObject *spec)
7278
{
7379
PyModuleDef_Slot slots[] = {
7480
{Py_mod_methods, a_methoddef_array},
81+
{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
82+
{Py_mod_gil, Py_MOD_GIL_NOT_USED},
7583
{0},
7684
};
7785
return PyModule_FromSlotsAndSpec(slots, spec);
@@ -90,6 +98,8 @@ module_from_slots_gc(PyObject *self, PyObject *spec)
9098
{Py_mod_state_traverse, noop_traverse},
9199
{Py_mod_state_clear, noop_clear},
92100
{Py_mod_state_free, noop_free},
101+
{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
102+
{Py_mod_gil, Py_MOD_GIL_NOT_USED},
93103
{0},
94104
};
95105
PyObject *mod = PyModule_FromSlotsAndSpec(slots, spec);
@@ -118,6 +128,8 @@ module_from_slots_token(PyObject *self, PyObject *spec)
118128
{
119129
PyModuleDef_Slot slots[] = {
120130
{Py_mod_token, (void*)&test_token},
131+
{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
132+
{Py_mod_gil, Py_MOD_GIL_NOT_USED},
121133
{0},
122134
};
123135
PyObject *mod = PyModule_FromSlotsAndSpec(slots, spec);
@@ -144,6 +156,8 @@ module_from_slots_exec(PyObject *self, PyObject *spec)
144156
{
145157
PyModuleDef_Slot slots[] = {
146158
{Py_mod_exec, simple_exec},
159+
{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
160+
{Py_mod_gil, Py_MOD_GIL_NOT_USED},
147161
{0},
148162
};
149163
PyObject *mod = PyModule_FromSlotsAndSpec(slots, spec);
@@ -175,6 +189,8 @@ module_from_slots_create(PyObject *self, PyObject *spec)
175189
{
176190
PyModuleDef_Slot slots[] = {
177191
{Py_mod_create, create_attr_from_spec},
192+
{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
193+
{Py_mod_gil, Py_MOD_GIL_NOT_USED},
178194
{0},
179195
};
180196
return PyModule_FromSlotsAndSpec(slots, spec);
@@ -205,6 +221,8 @@ module_from_slots_repeat_slot(PyObject *self, PyObject *spec)
205221
PyModuleDef_Slot slots[] = {
206222
{slot_id, "anything"},
207223
{slot_id, "anything else"},
224+
{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
225+
{Py_mod_gil, Py_MOD_GIL_NOT_USED},
208226
{0},
209227
};
210228
return PyModule_FromSlotsAndSpec(slots, spec);
@@ -219,6 +237,8 @@ module_from_slots_null_slot(PyObject *self, PyObject *spec)
219237
}
220238
PyModuleDef_Slot slots[] = {
221239
{slot_id, NULL},
240+
{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
241+
{Py_mod_gil, Py_MOD_GIL_NOT_USED},
222242
{0},
223243
};
224244
return PyModule_FromSlotsAndSpec(slots, spec);
@@ -233,6 +253,8 @@ module_from_def_slot(PyObject *self, PyObject *spec)
233253
}
234254
PyModuleDef_Slot slots[] = {
235255
{slot_id, "anything"},
256+
{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
257+
{Py_mod_gil, Py_MOD_GIL_NOT_USED},
236258
{0},
237259
};
238260
PyModuleDef def = {
@@ -280,6 +302,7 @@ module_from_def_multiple_exec(PyObject *self, PyObject *spec)
280302
static PyModuleDef_Slot slots[] = {
281303
{Py_mod_exec, simple_exec},
282304
{Py_mod_exec, another_exec},
305+
{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
283306
{Py_mod_gil, Py_MOD_GIL_NOT_USED},
284307
{0},
285308
};

0 commit comments

Comments
 (0)