[PySide] Translating 4-bytes unicode symbols from cpp to python
Sergey A. Komissarov
sergey.komissarov at datadvance.net
Mon Nov 10 16:05:33 CET 2014
We have 64bit linux cpp application with embeded python and pyside. Recently we encountered problem with more than 2-bytes long unicode symbols:
>from PySide import QtCore
>QtCore.QUrl(u"\U0001F431").toString() # using u"\uD83D\uDC31" instead of u"\U0001F431" leads to the same result
>u'\U0001f431\u7f74' # 2 symbols string instead of one
last symbol is different each application run (it's some randomly filled memory).
our exact environment is python 2.7.7 with Py_UNICODE_SIZE = 2, pyside 1.1.2 and qt 4.8.3 where sizeof(wchar_t) = 4.
Look in the QString converter-function at PySide/QtCore/typesystem_core_common.xml:195
The source of problem is QString::toWCharArray function, which traslates 2 characters QString into single character wchar_t array and python PyUnicode_FromWideChar doesn't set proper unicode string length to resulting object when argument array have internal zeros. I attached patch which seems to fix this problem.
If patch is not appropriate could someone tell me how to fix this properly?
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 2451 bytes
Desc: not available
More information about the PySide