[PyQt] Problem with conversion of QString to str for Python 3.3 and higher (PEP 393)
Phil Thompson
phil at riverbankcomputing.com
Mon Feb 3 19:05:04 GMT 2014
On 01-02-2014 9:15 pm, Mathias.Born at gmx.de wrote:
> Hi,
>
> Since upgrading to Python 3.3/3.4 I have a new problem.
>
> Run this small program in a debug version of Python 3.3 or higher on
> Windows:
>
> from PyQt5.QtCore import *
> o = QObject()
> o.setObjectName('abc')
> b = o.objectName()
> print("test %s" % b)
>
> The last line will make Python abort with the message:
>
> Assertion failed: maxchar >= 128, file ..\Objects\unicodeobject.c,
> line 403
>
> This doesn't apply to the release version.
>
> The assert comes from function _PyUnicode_CheckConsistency in
> unicodeobject.c,
> which only exists in the debug version.
> It is the "assert(maxchar >= 128);" line in that function:
>
> if (kind == PyUnicode_1BYTE_KIND) {
> if (ascii->state.ascii == 0) {
> assert(maxchar >= 128);
> assert(maxchar <= 255);
> }
>
> which fails.
>
> I believe this may be caused by PyQt not constructing the Python
> string
> correctly in the "o.objectName()" part of the above script.
>
> In PyQt-file qpy\QtCore\qpycore_qstring.cpp, in function
> qpycore_PyObject_FromQString, I see that the Python string is created
> by
>
> obj = PyUnicode_New(py_len, 0x00ff)
>
> The 0x00ff is the maximum character code occuring in the string.
> However, the string in the failing example is pure ASCII.
> I'm not familiar with Python's unicode internals, but to me it looks
> like the code expects this fact to be represented by
> "ascii->state.ascii == 1",
> not "ascii->state.ascii == 0", which as it seems must be taken care
> of
> during creation.
Fixed in tonight's snapshots.
Thanks,
Phil
More information about the PyQt
mailing list