}
/*
- * Load and initialize all of the python parts of M5, including Swig
- * and the embedded module importer.
+ * Load and initialize all of the python parts of M5.
*/
int
EmbeddedPython::initAll()
return 0;
}
-EmbeddedSwig::EmbeddedSwig(void (*init_func)(), const string& _context)
- : initFunc(init_func), context(_context)
-{
- getList().push_back(this);
-}
-
-list<EmbeddedSwig *> &
-EmbeddedSwig::getList()
-{
- static list<EmbeddedSwig *> the_list;
- return the_list;
-}
-
-void
-EmbeddedSwig::initAll()
-{
- char* old_context = _Py_PackageContext;
- // initialize SWIG modules. initFunc() is autogenerated and calls
- // all of the individual swig initialization functions.
- for (auto i : getList()) {
- // to ensure that the loaded modules are placed in the right
- // package we have to be a bit unorthodox and directly
- // manipulate the package context since swig simply calls
- // Py_InitModule with nothing but the module name of the
- // wrapper
- char* cstr = new char[i->context.size() + 1];
- strcpy(cstr, i->context.c_str());
- _Py_PackageContext = cstr;
- i->initFunc();
- delete[] cstr;
- }
- _Py_PackageContext = old_context;
-}
-
EmbeddedPyBind::EmbeddedPyBind(const char *_name,
void (*init_func)(py::module &),
const char *_base)
int
initM5Python()
{
- EmbeddedSwig::initAll();
EmbeddedPyBind::initAll();
return EmbeddedPython::initAll();
}