From 383bd34111b8d915ac4e646f26b3170b7705b023 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Tue, 14 Oct 2014 14:53:49 +0200 Subject: [PATCH] Fix T42021: OSL doesn't work when there are non-ascii chars in the path Quite annoying, the same thing we do from the blender side, But as a positive side we can get rid of some utf8/utf16 conversions. Hopefully it all work fine now, at leats works on mu russki windoze laptop. --- intern/cycles/blender/blender_python.cpp | 30 ++++++++++++++++++++---- intern/cycles/util/util_path.cpp | 16 ------------- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/intern/cycles/blender/blender_python.cpp b/intern/cycles/blender/blender_python.cpp index b756d6acdb2..8e5a6c13f44 100644 --- a/intern/cycles/blender/blender_python.cpp +++ b/intern/cycles/blender/blender_python.cpp @@ -53,14 +53,36 @@ void python_thread_state_restore(void **python_thread_state) *python_thread_state = NULL; } +static const char *PyC_UnicodeAsByte(PyObject *py_str, PyObject **coerce) +{ +#ifdef WIN32 + /* bug [#31856] oddly enough, Python3.2 --> 3.3 on Windows will throw an + * exception here this needs to be fixed in python: + * see: bugs.python.org/issue15859 */ + if(!PyUnicode_Check(py_str)) { + PyErr_BadArgument(); + return ""; + } +#endif + if((*coerce = PyUnicode_EncodeFSDefault(py_str))) { + return PyBytes_AS_STRING(*coerce); + } + return ""; +} + static PyObject *init_func(PyObject *self, PyObject *args) { - const char *path, *user_path; + PyObject *path, *user_path; - if(!PyArg_ParseTuple(args, "ss", &path, &user_path)) + if(!PyArg_ParseTuple(args, "OO", &path, &user_path)) { return NULL; - - path_init(path, user_path); + } + + PyObject *path_coerce = NULL, *user_path_coerce = NULL; + path_init(PyC_UnicodeAsByte(path, &path_coerce), + PyC_UnicodeAsByte(user_path, &user_path_coerce)); + Py_XDECREF(path_coerce); + Py_XDECREF(user_path_coerce); Py_RETURN_NONE; } diff --git a/intern/cycles/util/util_path.cpp b/intern/cycles/util/util_path.cpp index 85d19b6a325..aa424045ece 100644 --- a/intern/cycles/util/util_path.cpp +++ b/intern/cycles/util/util_path.cpp @@ -41,21 +41,12 @@ static string cached_user_path = ""; static boost::filesystem::path to_boost(const string& path) { -#ifdef _MSC_VER - std::wstring path_utf16 = Strutil::utf8_to_utf16(path.c_str()); - return boost::filesystem::path(path_utf16.c_str()); -#else return boost::filesystem::path(path.c_str()); -#endif } static string from_boost(const boost::filesystem::path& path) { -#ifdef _MSC_VER - return Strutil::utf16_to_utf8(path.wstring().c_str()); -#else return path.string().c_str(); -#endif } void path_init(const string& path, const string& user_path) @@ -259,14 +250,7 @@ string path_source_replace_includes(const string& source_, const string& path) FILE *path_fopen(const string& path, const string& mode) { -#ifdef _WIN32 - std::wstring path_utf16 = Strutil::utf8_to_utf16(path); - std::wstring mode_utf16 = Strutil::utf8_to_utf16(mode); - - return _wfopen(path_utf16.c_str(), mode_utf16.c_str()); -#else return fopen(path.c_str(), mode.c_str()); -#endif } void path_cache_clear_except(const string& name, const set& except)