diff --git a/src/cpyrt/API.cxx b/src/cpyrt/API.cxx index c0f4651..b0da815 100644 --- a/src/cpyrt/API.cxx +++ b/src/cpyrt/API.cxx @@ -59,9 +59,15 @@ static bool Initialize() { << std::endl; return false; } + } - // force loading of the cppjit module - PyRun_SimpleString(const_cast("import cppjit")); + // Importing the extension module is what runs the cpyrt initialization + // that sets gThisModule. + if (!cpyrt::gThisModule) { + PyObject* cppjitmod = PyImport_ImportModule("cppjit"); + if (!cppjitmod) + return false; + Py_DECREF(cppjitmod); } if (!gMainDict) {