We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent fb910ae commit c84c362Copy full SHA for c84c362
include/pybind11/pybind11.h
@@ -794,12 +794,14 @@ class module : public object {
794
explicit module(const char *name, const char *doc = nullptr) {
795
if (!options::show_user_defined_docstrings()) doc = nullptr;
796
#if PY_MAJOR_VERSION >= 3
797
- PyModuleDef *def = new PyModuleDef();
+ static std::vector<PyModuleDef> m_defs;
798
+ m_defs.emplace_back();
799
+ PyModuleDef *def = &m_defs.back();
800
std::memset(def, 0, sizeof(PyModuleDef));
801
+ def->m_base = PyModuleDef_HEAD_INIT;
802
def->m_name = name;
803
def->m_doc = doc;
804
def->m_size = -1;
- Py_INCREF(def);
805
m_ptr = PyModule_Create(def);
806
#else
807
m_ptr = Py_InitModule3(name, nullptr, doc);
0 commit comments