#include"pch.h"
|
#include"pyutils.h"
|
|
|
PyObject* create_py_module(string module_name) {
|
Py_Initialize();
|
PyRun_SimpleString("import sys");
|
PyRun_SimpleString("import os");
|
PyRun_SimpleString("sdk_path = os.getenv('MDK_PKGS')");
|
string pyd_home = "sys.path.append(sdk_path)";
|
PyRun_SimpleString(pyd_home.c_str());
|
|
PyObject* pModule = PyImport_ImportModule(module_name.c_str());
|
return pModule;
|
}
|
|
int py_initialize() {
|
Py_Initialize();
|
if (!Py_IsInitialized()) {
|
return 0;
|
}
|
else {
|
PyRun_SimpleString("import sys");
|
PyRun_SimpleString("import os");
|
PyRun_SimpleString("sdk_path = os.getenv('MDK_PKGS')");
|
string pyd_home = "sys.path.append(sdk_path)";
|
PyRun_SimpleString(pyd_home.c_str());
|
//char* sdk_path = getenv("MDK_PKGS");
|
|
PyEval_InitThreads();
|
int nInit = PyEval_ThreadsInitialized();
|
if (nInit) {
|
PyEval_ReleaseThread(PyThreadState_Get());
|
}
|
else {
|
return 0;
|
}
|
}
|
}
|
|
int py_finalize() {
|
int nint = PyGILState_Check();
|
PyGILState_STATE gstate;
|
if (!nint) {
|
gstate = PyGILState_Ensure();
|
}
|
Py_Finalize();
|
return nint;
|
//PyGILThreadLock lock;
|
}
|
|
int py_isInitialized() {
|
return Py_IsInitialized();
|
}
|