Skip to content
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add mod_gil_not_used option to BOOST_PYTHON_MODULE_MULTI_PHASE_INIT
  • Loading branch information
o01eg committed Apr 4, 2026
commit 4f49c834efd036cda6772b26a9fb5e451b155539
51 changes: 47 additions & 4 deletions include/boost/python/module_init.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ BOOST_PYTHON_DECL PyObject* init_module(char const* name, void(*)());

# if PY_VERSION_HEX >= 0x03050000

# define _BOOST_PYTHON_MODULE_MULTI_PHASE_INIT(name) \
# if defined(HAS_CXX11) && (PY_VERSION_HEX >= 0x030D0000)
# define _BOOST_PYTHON_MODULE_MULTI_PHASE_INIT(name, ...) \
int BOOST_PP_CAT(exec_module_,name)(PyObject* module) \
{ \
return boost::python::detail::exec_module( \
Expand All @@ -140,6 +141,7 @@ BOOST_PYTHON_DECL PyObject* init_module(char const* name, void(*)());
\
static PyModuleDef_Slot slots[] = { \
{Py_mod_exec, reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(BOOST_PP_CAT(exec_module_, name)))}, \
{Py_mod_gil, boost::python::detail::gil_not_used_option(__VA_ARGS__) ? Py_MOD_GIL_NOT_USED : Py_MOD_GIL_USED}, \
{0, NULL} \
}; \
\
Expand All @@ -158,6 +160,43 @@ BOOST_PYTHON_DECL PyObject* init_module(char const* name, void(*)());
return PyModuleDef_Init(&moduledef); \
} \
void BOOST_PP_CAT(init_module_, name)()
# else // ! HAS_CXX11 && Python 3.13+
# define _BOOST_PYTHON_MODULE_MULTI_PHASE_INIT(name) \
int BOOST_PP_CAT(exec_module_,name)(PyObject* module) \
{ \
return boost::python::detail::exec_module( \
module, BOOST_PP_CAT(init_module_, name) ); \
} \
extern "C" BOOST_SYMBOL_EXPORT PyObject* BOOST_PP_CAT(PyInit_, name)() \
{ \
static PyModuleDef_Base initial_m_base = { \
PyObject_HEAD_INIT(NULL) \
0, /* m_init */ \
0, /* m_index */ \
0 /* m_copy */ }; \
static PyMethodDef initial_methods[] = { { 0, 0, 0, 0 } }; \
\
static PyModuleDef_Slot slots[] = { \
{Py_mod_exec, reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(BOOST_PP_CAT(exec_module_, name)))}, \
{0, NULL} \
}; \
\
static struct PyModuleDef moduledef = { \
initial_m_base, \
BOOST_PP_STRINGIZE(name), \
0, /* m_doc */ \
0, /* m_size */ \
initial_methods, \
slots, /* m_slots */ \
0, /* m_traverse */ \
0, /* m_clear */ \
0, /* m_free */ \
}; \
\
return PyModuleDef_Init(&moduledef); \
} \
void BOOST_PP_CAT(init_module_, name)()
# endif // HAS_CXX11 && Python 3.13+

# endif // PY_VERSION_HEX >= 0x03050000

Expand All @@ -184,11 +223,15 @@ extern "C" BOOST_SYMBOL_EXPORT _BOOST_PYTHON_MODULE_INIT(name)
# endif // HAS_CXX11 && Python 3

# if PY_VERSION_HEX >= 0x03050000

# define BOOST_PYTHON_MODULE_MULTI_PHASE_INIT(name) \
# if defined(HAS_CXX11) && (PY_VERSION_HEX >= 0x030D0000)
# define BOOST_PYTHON_MODULE_MULTI_PHASE_INIT(name, ...) \
void BOOST_PP_CAT(init_module_,name)(); \
extern "C" BOOST_SYMBOL_EXPORT _BOOST_PYTHON_MODULE_MULTI_PHASE_INIT(name, __VA_ARGS__)
# else
# define BOOST_PYTHON_MODULE_MULTI_PHASE_INIT(name) \
void BOOST_PP_CAT(init_module_,name)(); \
extern "C" BOOST_SYMBOL_EXPORT _BOOST_PYTHON_MODULE_MULTI_PHASE_INIT(name)

# endif // HAS_CXX11 && Python 3.13+
# endif // PY_VERSION_HEX >= 0x03050000

# endif // BOOST_PYTHON_MODULE_INIT
Expand Down