2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-23 17:52:17 +00:00

Set the Py_MOD_GIL_NOT_USED flag on modules.

This indicates that the free-threaded build of Python can keep the
GIL disabled when the module is loaded.  Without this module flag,
importing the module will cause the GIL to be re-enabled.  A warning
is emitted if this happens.
This commit is contained in:
Neil Schemenauer
2025-10-13 20:59:37 -07:00
parent cfbefe893c
commit fc68878e02

View File

@@ -40,8 +40,14 @@ BOOST_PYTHON_DECL void scope_setattr_doc(char const* name, object const& x, char
BOOST_PYTHON_DECL PyObject* init_module(PyModuleDef& moduledef, void(*init_function)())
{
PyObject *mod = PyModule_Create(&moduledef);
#ifdef Py_GIL_DISABLED
if (mod != NULL) {
PyUnstable_Module_SetGIL(mod, Py_MOD_GIL_NOT_USED);
}
#endif
return init_module_in_scope(
PyModule_Create(&moduledef),
mod,
init_function);
}