From 10437e0aca08f9d761fe8863877ce0879bb3177f Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Fri, 16 Mar 2018 00:32:21 +0000 Subject: [PATCH] Allow conversion of any unicode sequence into a QString --- src/runner/pythonrunner.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/runner/pythonrunner.cpp b/src/runner/pythonrunner.cpp index 87c28b4..2978ab8 100644 --- a/src/runner/pythonrunner.cpp +++ b/src/runner/pythonrunner.cpp @@ -112,8 +112,13 @@ struct QString_from_python_str } static void construct(PyObject *objPtr, bpy::converter::rvalue_from_python_stage1_data *data) { + // Ensure the string uses 8-bit characters + PyObject *strPtr = PyUnicode_Check(objPtr) ? PyUnicode_AsUTF8String(objPtr) : objPtr; // Extract the character data from the python string - const char* value = PyString_AsString(objPtr); + const char* value = PyString_AsString(strPtr); + // Deallocate local copy if one was made + if (strPtr != objPtr) + Py_DecRef(strPtr); assert(value != nullptr); // allocate storage