Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brecht@blender.org>2020-05-04 21:02:08 +0300
committerBrecht Van Lommel <brecht@blender.org>2020-05-05 00:07:01 +0300
commitac6be6759ecc6c6503e8785ee405c003e0ca2fe5 (patch)
treefe8cff653626e1a7ef526a546b694605c1e437ea /intern/cycles/blender/blender_python.cpp
parent8b5868cc15dac0a967bb7cd03e0ed2a15026fb35 (diff)
Fix Cycles Python error when device name is not a valid UTF-8 string
This may fix or help diagnose T76378.
Diffstat (limited to 'intern/cycles/blender/blender_python.cpp')
-rw-r--r--intern/cycles/blender/blender_python.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/intern/cycles/blender/blender_python.cpp b/intern/cycles/blender/blender_python.cpp
index 89bcebda193..8c7c0bc1daa 100644
--- a/intern/cycles/blender/blender_python.cpp
+++ b/intern/cycles/blender/blender_python.cpp
@@ -60,6 +60,12 @@ void *pylong_as_voidptr_typesafe(PyObject *object)
return PyLong_AsVoidPtr(object);
}
+PyObject *pyunicode_from_string(const char *str)
+{
+ /* Ignore errors if device API returns invalid UTF-8 strings. */
+ return PyUnicode_DecodeUTF8(str, strlen(str), "ignore");
+}
+
/* Synchronize debug flags from a given Blender scene.
* Return truth when device list needs invalidation.
*/
@@ -429,9 +435,9 @@ static PyObject *available_devices_func(PyObject * /*self*/, PyObject *args)
DeviceInfo &device = devices[i];
string type_name = Device::string_from_type(device.type);
PyObject *device_tuple = PyTuple_New(3);
- PyTuple_SET_ITEM(device_tuple, 0, PyUnicode_FromString(device.description.c_str()));
- PyTuple_SET_ITEM(device_tuple, 1, PyUnicode_FromString(type_name.c_str()));
- PyTuple_SET_ITEM(device_tuple, 2, PyUnicode_FromString(device.id.c_str()));
+ PyTuple_SET_ITEM(device_tuple, 0, pyunicode_from_string(device.description.c_str()));
+ PyTuple_SET_ITEM(device_tuple, 1, pyunicode_from_string(type_name.c_str()));
+ PyTuple_SET_ITEM(device_tuple, 2, pyunicode_from_string(device.id.c_str()));
PyTuple_SET_ITEM(ret, i, device_tuple);
}
@@ -642,7 +648,7 @@ static PyObject *osl_compile_func(PyObject * /*self*/, PyObject *args)
static PyObject *system_info_func(PyObject * /*self*/, PyObject * /*value*/)
{
string system_info = Device::device_capabilities();
- return PyUnicode_FromString(system_info.c_str());
+ return pyunicode_from_string(system_info.c_str());
}
#ifdef WITH_OPENCL