Skip to content

Commit 62bfaf8

Browse files
committed
moving static PyModuleDef declaration to global scope, as requested by @wjakob
1 parent 68524f5 commit 62bfaf8

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

include/pybind11/detail/common.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,14 +308,19 @@ extern "C" {
308308
}
309309
\endrst */
310310
#if PY_MAJOR_VERSION >= 3
311+
#define PYBIND11_MODULE_DETAIL_STATIC_DEF(name) \
312+
static PyModuleDef PYBIND11_CONCAT(pybind11_module_def_, name);
311313
#define PYBIND11_MODULE_DETAIL_CREATE(name) \
312-
static PyModuleDef mdef; \
313-
auto m = pybind11::module(PYBIND11_TOSTRING(name), nullptr, &mdef);
314+
auto m = pybind11::module( \
315+
PYBIND11_TOSTRING(name), nullptr, \
316+
&PYBIND11_CONCAT(pybind11_module_def_, name));
314317
#else
318+
#define PYBIND11_MODULE_DETAIL_STATIC_DEF(name)
315319
#define PYBIND11_MODULE_DETAIL_CREATE(name) \
316320
auto m = pybind11::module(PYBIND11_TOSTRING(name));
317321
#endif
318322
#define PYBIND11_MODULE(name, variable) \
323+
PYBIND11_MODULE_DETAIL_STATIC_DEF(name) \
319324
PYBIND11_MAYBE_UNUSED \
320325
static void PYBIND11_CONCAT(pybind11_init_, name)(pybind11::module &); \
321326
PYBIND11_PLUGIN_IMPL(name) { \

0 commit comments

Comments
 (0)