Skip to content

Commit 4f49c83

Browse files
committed
Add mod_gil_not_used option to BOOST_PYTHON_MODULE_MULTI_PHASE_INIT
1 parent 2937444 commit 4f49c83

1 file changed

Lines changed: 47 additions & 4 deletions

File tree

include/boost/python/module_init.hpp

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ BOOST_PYTHON_DECL PyObject* init_module(char const* name, void(*)());
123123

124124
# if PY_VERSION_HEX >= 0x03050000
125125

126-
# define _BOOST_PYTHON_MODULE_MULTI_PHASE_INIT(name) \
126+
# if defined(HAS_CXX11) && (PY_VERSION_HEX >= 0x030D0000)
127+
# define _BOOST_PYTHON_MODULE_MULTI_PHASE_INIT(name, ...) \
127128
int BOOST_PP_CAT(exec_module_,name)(PyObject* module) \
128129
{ \
129130
return boost::python::detail::exec_module( \
@@ -140,6 +141,7 @@ BOOST_PYTHON_DECL PyObject* init_module(char const* name, void(*)());
140141
\
141142
static PyModuleDef_Slot slots[] = { \
142143
{Py_mod_exec, reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(BOOST_PP_CAT(exec_module_, name)))}, \
144+
{Py_mod_gil, boost::python::detail::gil_not_used_option(__VA_ARGS__) ? Py_MOD_GIL_NOT_USED : Py_MOD_GIL_USED}, \
143145
{0, NULL} \
144146
}; \
145147
\
@@ -158,6 +160,43 @@ BOOST_PYTHON_DECL PyObject* init_module(char const* name, void(*)());
158160
return PyModuleDef_Init(&moduledef); \
159161
} \
160162
void BOOST_PP_CAT(init_module_, name)()
163+
# else // ! HAS_CXX11 && Python 3.13+
164+
# define _BOOST_PYTHON_MODULE_MULTI_PHASE_INIT(name) \
165+
int BOOST_PP_CAT(exec_module_,name)(PyObject* module) \
166+
{ \
167+
return boost::python::detail::exec_module( \
168+
module, BOOST_PP_CAT(init_module_, name) ); \
169+
} \
170+
extern "C" BOOST_SYMBOL_EXPORT PyObject* BOOST_PP_CAT(PyInit_, name)() \
171+
{ \
172+
static PyModuleDef_Base initial_m_base = { \
173+
PyObject_HEAD_INIT(NULL) \
174+
0, /* m_init */ \
175+
0, /* m_index */ \
176+
0 /* m_copy */ }; \
177+
static PyMethodDef initial_methods[] = { { 0, 0, 0, 0 } }; \
178+
\
179+
static PyModuleDef_Slot slots[] = { \
180+
{Py_mod_exec, reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(BOOST_PP_CAT(exec_module_, name)))}, \
181+
{0, NULL} \
182+
}; \
183+
\
184+
static struct PyModuleDef moduledef = { \
185+
initial_m_base, \
186+
BOOST_PP_STRINGIZE(name), \
187+
0, /* m_doc */ \
188+
0, /* m_size */ \
189+
initial_methods, \
190+
slots, /* m_slots */ \
191+
0, /* m_traverse */ \
192+
0, /* m_clear */ \
193+
0, /* m_free */ \
194+
}; \
195+
\
196+
return PyModuleDef_Init(&moduledef); \
197+
} \
198+
void BOOST_PP_CAT(init_module_, name)()
199+
# endif // HAS_CXX11 && Python 3.13+
161200

162201
# endif // PY_VERSION_HEX >= 0x03050000
163202

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

186225
# if PY_VERSION_HEX >= 0x03050000
187-
188-
# define BOOST_PYTHON_MODULE_MULTI_PHASE_INIT(name) \
226+
# if defined(HAS_CXX11) && (PY_VERSION_HEX >= 0x030D0000)
227+
# define BOOST_PYTHON_MODULE_MULTI_PHASE_INIT(name, ...) \
228+
void BOOST_PP_CAT(init_module_,name)(); \
229+
extern "C" BOOST_SYMBOL_EXPORT _BOOST_PYTHON_MODULE_MULTI_PHASE_INIT(name, __VA_ARGS__)
230+
# else
231+
# define BOOST_PYTHON_MODULE_MULTI_PHASE_INIT(name) \
189232
void BOOST_PP_CAT(init_module_,name)(); \
190233
extern "C" BOOST_SYMBOL_EXPORT _BOOST_PYTHON_MODULE_MULTI_PHASE_INIT(name)
191-
234+
# endif // HAS_CXX11 && Python 3.13+
192235
# endif // PY_VERSION_HEX >= 0x03050000
193236

194237
# endif // BOOST_PYTHON_MODULE_INIT

0 commit comments

Comments
 (0)