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.
This commit is contained in:
Sergey Sharybin 2014-10-14 14:53:49 +02:00
parent e0cacb808c
commit 383bd34111
Notes: blender-bot 2024-03-25 12:30:38 +01:00
Referenced by issue #42021, Cycles OSL renders a black image
2 changed files with 26 additions and 20 deletions

View File

@ -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;
}

View File

@ -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<string>& except)