m->md_name = NULL;
m->md_token_is_def = false;
#ifdef Py_GIL_DISABLED
- m->md_gil = Py_MOD_GIL_USED;
+ m->md_requires_gil = true;
#endif
m->md_state_size = 0;
m->md_state_traverse = NULL;
m->md_token_is_def = true;
module_copy_members_from_deflike(m, module);
#ifdef Py_GIL_DISABLED
- m->md_gil = Py_MOD_GIL_USED;
+ m->md_requires_gil = true;
#endif
return (PyObject*)m;
}
int has_multiple_interpreters_slot = 0;
void *multiple_interpreters = (void *)0;
int has_gil_slot = 0;
- void *gil_slot = Py_MOD_GIL_USED;
+ bool requires_gil = true;
int has_execution_slots = 0;
const char *name;
int ret;
name);
goto error;
}
- gil_slot = cur_slot->value;
+ requires_gil = (cur_slot->value != Py_MOD_GIL_NOT_USED);
has_gil_slot = 1;
break;
case Py_mod_abi:
mod->md_token = token;
}
#ifdef Py_GIL_DISABLED
- mod->md_gil = gil_slot;
+ mod->md_requires_gil = requires_gil;
#else
- (void)gil_slot;
+ (void)requires_gil;
#endif
mod->md_exec = m_exec;
} else {
int
PyUnstable_Module_SetGIL(PyObject *module, void *gil)
{
+ bool requires_gil = (gil != Py_MOD_GIL_NOT_USED);
if (!PyModule_Check(module)) {
PyErr_BadInternalCall();
return -1;
}
- ((PyModuleObject *)module)->md_gil = gil;
+ ((PyModuleObject *)module)->md_requires_gil = requires_gil;
return 0;
}
#endif
_Py_ext_module_origin origin;
#ifdef Py_GIL_DISABLED
- /* The module's md_gil slot, for legacy modules that are reinitialized from
- m_dict rather than calling their initialization function again. */
- void *md_gil;
+ /* The module's md_requires_gil member, for legacy modules that are
+ * reinitialized from m_dict rather than calling their initialization
+ * function again. */
+ bool md_requires_gil;
#endif
};
_extensions_cache_set(PyObject *path, PyObject *name,
PyModuleDef *def, PyModInitFunction m_init,
Py_ssize_t m_index, PyObject *m_dict,
- _Py_ext_module_origin origin, void *md_gil)
+ _Py_ext_module_origin origin, bool requires_gil)
{
struct extensions_cache_value *value = NULL;
void *key = NULL;
/* m_dict is set by set_cached_m_dict(). */
.origin=origin,
#ifdef Py_GIL_DISABLED
- .md_gil=md_gil,
+ .md_requires_gil=requires_gil,
#endif
};
#ifndef Py_GIL_DISABLED
- (void)md_gil;
+ (void)requires_gil;
#endif
if (init_cached_m_dict(newvalue, m_dict) < 0) {
goto finally;
}
if (!PyModule_Check(module) ||
- ((PyModuleObject *)module)->md_gil == Py_MOD_GIL_USED) {
+ ((PyModuleObject *)module)->md_requires_gil)
+ {
if (_PyEval_EnableGILPermanent(tstate)) {
int warn_result = PyErr_WarnFormat(
PyExc_RuntimeWarning,
Py_ssize_t m_index;
PyObject *m_dict;
_Py_ext_module_origin origin;
- void *md_gil;
+ bool md_requires_gil;
};
static struct extensions_cache_value *
#endif
cached = _extensions_cache_set(
path, name, def, m_init, singlephase->m_index, m_dict,
- singlephase->origin, singlephase->md_gil);
+ singlephase->origin, singlephase->md_requires_gil);
if (cached == NULL) {
// XXX Ignore this error? Doing so would effectively
// mark the module as not loadable.
if (def->m_base.m_copy != NULL) {
// For non-core modules, fetch the GIL slot that was stored by
// import_run_extension().
- ((PyModuleObject *)mod)->md_gil = cached->md_gil;
+ ((PyModuleObject *)mod)->md_requires_gil = cached->md_requires_gil;
}
#endif
/* We can't set mod->md_def if it's missing,
.m_index=def->m_base.m_index,
.origin=info->origin,
#ifdef Py_GIL_DISABLED
- .md_gil=((PyModuleObject *)mod)->md_gil,
+ .md_requires_gil=((PyModuleObject *)mod)->md_requires_gil,
#endif
};
// gh-88216: Extensions and def->m_base.m_copy can be updated
.origin=_Py_ext_module_origin_CORE,
#ifdef Py_GIL_DISABLED
/* Unused when m_dict == NULL. */
- .md_gil=NULL,
+ .md_requires_gil=false,
#endif
};
cached = update_global_state_for_extension(