Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'extern/mantaflow/helper/pwrapper/registry.cpp')
-rw-r--r--extern/mantaflow/helper/pwrapper/registry.cpp31
1 files changed, 23 insertions, 8 deletions
diff --git a/extern/mantaflow/helper/pwrapper/registry.cpp b/extern/mantaflow/helper/pwrapper/registry.cpp
index 5196c0409f8..b4206a41dea 100644
--- a/extern/mantaflow/helper/pwrapper/registry.cpp
+++ b/extern/mantaflow/helper/pwrapper/registry.cpp
@@ -115,7 +115,7 @@ class WrapperRegistry {
void construct(const std::string &scriptname, const vector<string> &args);
void cleanup();
void renameObjects();
- void runPreInit();
+ void runPreInit(PyObject *name_space);
PyObject *initModule();
ClassData *lookup(const std::string &name);
bool canConvert(ClassData *from, ClassData *to);
@@ -505,7 +505,7 @@ void WrapperRegistry::addConstants(PyObject *module)
}
}
-void WrapperRegistry::runPreInit()
+void WrapperRegistry::runPreInit(PyObject *name_space)
{
// add python directories to path
PyObject *sys_path = PySys_GetObject((char *)"path");
@@ -518,7 +518,15 @@ void WrapperRegistry::runPreInit()
}
if (!mCode.empty()) {
mCode = "from manta import *\n" + mCode;
- PyRun_SimpleString(mCode.c_str());
+ PyObject *return_value = PyRun_String(mCode.c_str(), Py_file_input, name_space, name_space);
+ if (return_value == nullptr) {
+ if (PyErr_Occurred()) {
+ PyErr_Print();
+ }
+ }
+ else {
+ Py_DECREF(return_value);
+ }
}
}
@@ -698,16 +706,23 @@ PyObject *WrapperRegistry::initModule()
//******************************************************
// Register members and exposed functions
-void setup(const std::string &filename, const std::vector<std::string> &args)
+void setup(const bool python_lifecycle,
+ const std::string &filename,
+ const std::vector<std::string> &args,
+ PyObject *name_space)
{
WrapperRegistry::instance().construct(filename, args);
- Py_Initialize();
- WrapperRegistry::instance().runPreInit();
+ if (python_lifecycle) {
+ Py_Initialize();
+ }
+ WrapperRegistry::instance().runPreInit(name_space);
}
-void finalize()
+void finalize(const bool python_lifecycle)
{
- Py_Finalize();
+ if (python_lifecycle) {
+ Py_Finalize();
+ }
WrapperRegistry::instance().cleanup();
}