return objs;
}
+#if PY_MAJOR_VERSION >= 3
+PyObject *
+#else
void
+#endif
EmbeddedPyBind::initAll()
{
std::list<EmbeddedPyBind *> pending;
}
}
}
+
+#if PY_MAJOR_VERSION >= 3
+ return m_m5.ptr();
+#endif
}
-int
-initM5Python()
+void
+registerNativeModules()
{
- EmbeddedPyBind::initAll();
- return EmbeddedPython::initAll();
+ auto result = PyImport_AppendInittab("_m5", EmbeddedPyBind::initAll);
+ if (result == -1)
+ panic("Failed to add _m5 to Python's inittab\n");
}
/*
return 0;
}
-
-PyMODINIT_FUNC
-initm5(void)
-{
- initM5Python();
- PyImport_ImportModule(PyCC("m5"));
-}
EmbeddedPyBind(const char *_name,
void (*init_func)(pybind11::module &));
+#if PY_MAJOR_VERSION >= 3
+ static PyObject *initAll();
+#else
static void initAll();
+#endif
private:
void (*initFunc)(pybind11::module &);
static std::map<std::string, EmbeddedPyBind *> &getMap();
};
-int initM5Python();
+void registerNativeModules();
+
int m5Main(int argc, char **argv);
-PyMODINIT_FUNC initm5(void);
#endif // __SIM_INIT_HH__
Py_SetProgramName(argv[0]);
#endif
+ // Register native modules with Python's init system before
+ // initializing the interpreter.
+ registerNativeModules();
+
// initialize embedded Python interpreter
Py_Initialize();
// Initialize the embedded m5 python library
- ret = initM5Python();
+ ret = EmbeddedPython::initAll();
if (ret == 0) {
// start m5