Base: let interpreter keep track of created modules

This commit is contained in:
wmayer
2022-03-13 22:34:01 +01:00
parent 2908150282
commit a22608b7b5
2 changed files with 20 additions and 0 deletions

View File

@@ -487,6 +487,19 @@ bool InterpreterSingleton::loadModule(const char* psModName)
return true;
}
PyObject* InterpreterSingleton::addModule(Py::ExtensionModuleBase* mod)
{
_modules.push_back(mod);
return mod->module().ptr();
}
void InterpreterSingleton::cleanupModules()
{
for (auto it : _modules)
delete it;
_modules.clear();
}
void InterpreterSingleton::addType(PyTypeObject* Type,PyObject* Module, const char * Name)
{
// NOTE: To finish the initialization of our own type objects we must
@@ -564,6 +577,7 @@ void InterpreterSingleton::finalize()
{
try {
PyEval_RestoreThread(this->_global);
cleanupModules();
Py_Finalize();
}
catch (...) {