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:
2014-10-14 14:53:49 +02:00
parent e0cacb808c
commit 383bd34111
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;
}