diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2020-12-28 19:23:10 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2021-01-01 18:03:00 +0100 |
commit | cbe9a0a815e4a73bf8db425a7c5c651e67b2ed65 (patch) | |
tree | 9fae89b583bbace7052636bff60625bafcdc0146 /pyuno/source/loader/pyuno_loader.cxx | |
parent | a58333410cdfb3a9e6ef82710534f2422a85aeea (diff) |
Use Unicode paths on Windows for pyuno
No need to convert to 8-byte string only to convert back to UTF-16.
No idea if this has some logic on Linux, so only changing Windows.
Change-Id: I87b7f25e5b1a2dd07ac3354f8f065485949ef229
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108480
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'pyuno/source/loader/pyuno_loader.cxx')
-rw-r--r-- | pyuno/source/loader/pyuno_loader.cxx | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/pyuno/source/loader/pyuno_loader.cxx b/pyuno/source/loader/pyuno_loader.cxx index a8722dd835bb..1337ea8c78f9 100644 --- a/pyuno/source/loader/pyuno_loader.cxx +++ b/pyuno/source/loader/pyuno_loader.cxx @@ -23,6 +23,7 @@ #include <pyuno.hxx> #include <o3tl/any.hxx> +#include <o3tl/char16_t2wchar_t.hxx> #include <osl/process.h> #include <osl/file.hxx> @@ -109,16 +110,22 @@ static void setPythonHome ( const OUString & pythonHome ) { OUString systemPythonHome; osl_getSystemPathFromFileURL( pythonHome.pData, &(systemPythonHome.pData) ); - OString o = OUStringToOString( systemPythonHome, osl_getThreadTextEncoding() ); // static because Py_SetPythonHome just copies the "wide" pointer static wchar_t wide[PATH_MAX + 1]; +#if defined _WIN32 + const size_t len = systemPythonHome.getLength(); + if (len < std::size(wide)) + wcsncpy(wide, o3tl::toW(systemPythonHome.getStr()), len + 1); +#else + OString o = OUStringToOString(systemPythonHome, osl_getThreadTextEncoding()); size_t len = mbstowcs(wide, o.pData->buffer, PATH_MAX + 1); +#endif if(len == size_t(-1)) { PyErr_SetString(PyExc_SystemError, "invalid multibyte sequence in python home path"); return; } - if(len == PATH_MAX + 1) + if(len >= PATH_MAX + 1) { PyErr_SetString(PyExc_SystemError, "python home path is too long"); return; |