File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -306,6 +306,22 @@ extern "C" {
306
306
});
307
307
}
308
308
\endrst */
309
+ #if PY_MAJOR_VERSION >= 3
310
+ #define PYBIND11_MODULE (name, variable ) \
311
+ PYBIND11_MAYBE_UNUSED \
312
+ static void PYBIND11_CONCAT (pybind11_init_, name)(pybind11::module &); \
313
+ PYBIND11_PLUGIN_IMPL (name) { \
314
+ PYBIND11_CHECK_PYTHON_VERSION \
315
+ PYBIND11_ENSURE_INTERNALS_READY \
316
+ static PyModuleDef mdef; \
317
+ auto m = pybind11::module (PYBIND11_TOSTRING (name), nullptr , &mdef); \
318
+ try { \
319
+ PYBIND11_CONCAT (pybind11_init_, name)(m); \
320
+ return m.ptr (); \
321
+ } PYBIND11_CATCH_INIT_EXCEPTIONS \
322
+ } \
323
+ void PYBIND11_CONCAT (pybind11_init_, name)(pybind11::module &variable)
324
+ #else
309
325
#define PYBIND11_MODULE (name, variable ) \
310
326
PYBIND11_MAYBE_UNUSED \
311
327
static void PYBIND11_CONCAT (pybind11_init_, name)(pybind11::module &); \
@@ -319,6 +335,7 @@ extern "C" {
319
335
} PYBIND11_CATCH_INIT_EXCEPTIONS \
320
336
} \
321
337
void PYBIND11_CONCAT (pybind11_init_, name)(pybind11::module &variable)
338
+ #endif
322
339
323
340
324
341
PYBIND11_NAMESPACE_BEGIN (PYBIND11_NAMESPACE)
Original file line number Diff line number Diff line change @@ -827,10 +827,14 @@ class module : public object {
827
827
PYBIND11_OBJECT_DEFAULT (module , object, PyModule_Check)
828
828
829
829
// / Create a new top-level Python module with the given name and docstring
830
+ #if PY_MAJOR_VERSION >= 3
831
+ explicit module (const char *name, const char *doc = nullptr , PyModuleDef *def = nullptr ) {
832
+ #else
830
833
explicit module (const char *name, const char *doc = nullptr ) {
834
+ #endif
831
835
if (!options::show_user_defined_docstrings ()) doc = nullptr ;
832
836
#if PY_MAJOR_VERSION >= 3
833
- PyModuleDef * def = new PyModuleDef ();
837
+ if (!def) def = new PyModuleDef ();
834
838
std::memset (def, 0 , sizeof (PyModuleDef));
835
839
def->m_name = name;
836
840
def->m_doc = doc;
You can’t perform that action at this time.
0 commit comments