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 5ae8429Copy full SHA for 5ae8429
include/pybind11/pybind11.h
@@ -795,11 +795,17 @@ class module : public object {
795
if (!options::show_user_defined_docstrings()) doc = nullptr;
796
#if PY_MAJOR_VERSION >= 3
797
PyModuleDef *def = new PyModuleDef();
798
+ // Ensure that Python does not try to delete this.
799
+ Py_INCREF(def);
800
std::memset(def, 0, sizeof(PyModuleDef));
801
def->m_name = name;
802
def->m_doc = doc;
803
def->m_size = -1;
- Py_INCREF(def);
804
+ def->m_free = [](void* module ) {
805
+ if (module != NULL) {
806
+ delete PyModule_GetDef((PyObject*) module);
807
+ }
808
+ };
809
m_ptr = PyModule_Create(def);
810
#else
811
m_ptr = Py_InitModule3(name, nullptr, doc);
0 commit comments