Base: let interpreter keep track of created modules
This commit is contained in:
@@ -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 (...) {
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
#endif
|
||||
|
||||
#include <CXX/Extensions.hxx>
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include "Exception.h"
|
||||
|
||||
@@ -240,6 +241,10 @@ public:
|
||||
/// Add an additional python path
|
||||
void addPythonPath(const char* Path);
|
||||
static void addType(PyTypeObject* Type,PyObject* Module, const char * Name);
|
||||
/// Add a module and return a PyObject to it
|
||||
PyObject* addModule(Py::ExtensionModuleBase*);
|
||||
/// Clean-up registered modules
|
||||
void cleanupModules();
|
||||
//@}
|
||||
|
||||
/** @name Cleanup
|
||||
@@ -311,6 +316,7 @@ protected:
|
||||
private:
|
||||
std::string _cDebugFileName;
|
||||
PyThreadState* _global;
|
||||
std::list<Py::ExtensionModuleBase*> _modules;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user