diff options
-rw-r--r-- | xbmc/interfaces/python/PythonInvoker.cpp | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/xbmc/interfaces/python/PythonInvoker.cpp b/xbmc/interfaces/python/PythonInvoker.cpp index 55c5181403..1e9d344151 100644 --- a/xbmc/interfaces/python/PythonInvoker.cpp +++ b/xbmc/interfaces/python/PythonInvoker.cpp @@ -226,29 +226,30 @@ bool CPythonInvoker::execute(const std::string& script, std::vector<std::wstring } PyObject* sysPath = PySys_GetObject("path"); - Py_ssize_t listSize = PyList_Size(sysPath); - if (listSize > 0) - CLog::Log(LOGDEBUG, "CPythonInvoker({}): default python path:", GetId()); + std::for_each(pythonPath.crbegin(), pythonPath.crend(), + [&sysPath](const auto& path) + { + PyObject* pyPath = PyUnicode_FromString(path.c_str()); + PyList_Insert(sysPath, 0, pyPath); - for (Py_ssize_t index = 0; index < listSize; index++) - { - PyObject* pyPath = PyList_GetItem(sysPath, index); + Py_DECREF(pyPath); + }); - CLog::Log(LOGDEBUG, "CPythonInvoker({}): {}", GetId(), PyUnicode_AsUTF8(pyPath)); - } + CLog::Log(LOGDEBUG, "CPythonInvoker({}): full python path:", GetId()); - if (!pythonPath.empty()) - CLog::Log(LOGDEBUG, "CPythonInvoker({}): adding path:", GetId()); + Py_ssize_t pathListSize = PyList_Size(sysPath); - for (const auto& path : pythonPath) + for (Py_ssize_t index = 0; index < pathListSize; index++) { - PyObject* pyPath = PyUnicode_FromString(path.c_str()); - PyList_Append(sysPath, pyPath); + if (index == 0 && !pythonPath.empty()) + CLog::Log(LOGDEBUG, "CPythonInvoker({}): custom python path:", GetId()); - CLog::Log(LOGDEBUG, "CPythonInvoker({}): {}", GetId(), PyUnicode_AsUTF8(pyPath)); + if (index == static_cast<ssize_t>(pythonPath.size())) + CLog::Log(LOGDEBUG, "CPythonInvoker({}): default python path:", GetId()); - Py_DECREF(pyPath); + PyObject* pyPath = PyList_GetItem(sysPath, index); + CLog::Log(LOGDEBUG, "CPythonInvoker({}): {}", GetId(), PyUnicode_AsUTF8(pyPath)); } { // set the m_threadState to this new interp |