summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/sim/init.cc24
-rw-r--r--src/sim/init.hh8
-rw-r--r--src/sim/main.cc6
3 files changed, 24 insertions, 14 deletions
diff --git a/src/sim/init.cc b/src/sim/init.cc
index 66ec40895..5a49f360a 100644
--- a/src/sim/init.cc
+++ b/src/sim/init.cc
@@ -191,7 +191,11 @@ EmbeddedPyBind::getMap()
return objs;
}
+#if PY_MAJOR_VERSION >= 3
+PyObject *
+#else
void
+#endif
EmbeddedPyBind::initAll()
{
std::list<EmbeddedPyBind *> pending;
@@ -226,13 +230,18 @@ EmbeddedPyBind::initAll()
}
}
}
+
+#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");
}
/*
@@ -307,10 +316,3 @@ m5Main(int argc, char **_argv)
return 0;
}
-
-PyMODINIT_FUNC
-initm5(void)
-{
- initM5Python();
- PyImport_ImportModule(PyCC("m5"));
-}
diff --git a/src/sim/init.hh b/src/sim/init.hh
index de6b44de4..40ff9aea0 100644
--- a/src/sim/init.hh
+++ b/src/sim/init.hh
@@ -90,7 +90,11 @@ class EmbeddedPyBind
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 &);
@@ -105,8 +109,8 @@ class EmbeddedPyBind
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__
diff --git a/src/sim/main.cc b/src/sim/main.cc
index a77c5f578..168e4390f 100644
--- a/src/sim/main.cc
+++ b/src/sim/main.cc
@@ -54,11 +54,15 @@ main(int argc, char **argv)
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