| 132 | { |
| 133 | public: |
| 134 | explicit PySlaveInstance(fmu_data data) |
| 135 | : data_(std::move(data)) |
| 136 | { |
| 137 | py_safe_run([this](PyGILState_STATE gilState) { |
| 138 | // Append resources path to python sys path |
| 139 | PyObject* sys_module = PyImport_ImportModule("sys"); |
| 140 | if (sys_module == nullptr) { |
| 141 | handle_py_exception("[ctor] PyImport_ImportModule", gilState); |
| 142 | } |
| 143 | PyObject* sys_path = PyObject_GetAttrString(sys_module, "path"); |
| 144 | Py_DECREF(sys_module); |
| 145 | if (sys_path == nullptr) { |
| 146 | handle_py_exception("[ctor] PyObject_GetAttrString", gilState); |
| 147 | } |
| 148 | int success = PyList_Insert(sys_path, 0, PyUnicode_FromString(resourceLocation().c_str())); |
| 149 | |
| 150 | Py_DECREF(sys_path); |
| 151 | if (success != 0) { |
| 152 | handle_py_exception("[ctor] PyList_Insert", gilState); |
| 153 | } |
| 154 | |
| 155 | std::string moduleName = getline(resourceLocation() + "/slavemodule.txt"); |
| 156 | |
| 157 | pClass_ = findClass(resourceLocation(), moduleName); |
| 158 | if (pClass_ == nullptr) { |
| 159 | handle_py_exception("[ctor] findClass", gilState); |
| 160 | } |
| 161 | |
| 162 | initialize(gilState); |
| 163 | }); |
| 164 | } |
| 165 | |
| 166 | void clearLogBuffer() const |
| 167 | { |
nothing calls this directly
no test coverage detected