diff options
author | Simo Fält <simo.falt@qt.io> | 2023-06-29 15:15:57 +0300 |
---|---|---|
committer | Simo Fält <simo.falt@qt.io> | 2023-06-29 15:15:57 +0300 |
commit | 8d8e799cb7ab0bebe8f6dd4172848159eb3c8087 (patch) | |
tree | 143f0ade6f75a55fcf6824e2b5a5b8a3e48ba1fa /sources/pyside2/PySide2/glue/qtcore.cpp | |
parent | 2342e61cb53824e2dcd6324e3d108500d61ffee2 (diff) | |
parent | 927c0d3e625455a8e5fedef3ed6662c8acba1858 (diff) |
Merge tag 'v5.15.9-lts' into tqtc/lts-5.15-opensourcev5.15.9-lts-lgpl
Qt For Python Release 5.15.9
Change-Id: I6a2717036c50f27aa0eeea6cfcfbc2970c0bd04a
Diffstat (limited to 'sources/pyside2/PySide2/glue/qtcore.cpp')
-rw-r--r-- | sources/pyside2/PySide2/glue/qtcore.cpp | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/sources/pyside2/PySide2/glue/qtcore.cpp b/sources/pyside2/PySide2/glue/qtcore.cpp index 78de3d5d5..8a9aae8f7 100644 --- a/sources/pyside2/PySide2/glue/qtcore.cpp +++ b/sources/pyside2/PySide2/glue/qtcore.cpp @@ -1065,9 +1065,10 @@ if (PyIndex_Check(_key)) { if (PyLong_Check(item) || PyInt_Check(item)) { #endif int overflow; - long ival = PyLong_AsLongAndOverflow(item, &overflow); - // Not suppose to bigger than 255 because only bytes, bytearray, QByteArray were accept - temp = QByteArray(reinterpret_cast<const char *>(&ival)); + const long ival = PyLong_AsLongAndOverflow(item, &overflow); + // Not supposed to be bigger than 255 because only bytes, + // bytearray, QByteArray were accepted + temp.append(char(ival)); } else { temp = %CONVERTTOCPP[QByteArray](item); } @@ -1751,7 +1752,25 @@ Py_END_ALLOW_THREADS // @snippet conversion-pylong-quintptr // @snippet conversion-pyunicode -#ifndef Py_LIMITED_API +#if defined(Py_LIMITED_API) + wchar_t *temp = PyUnicode_AsWideCharString(%in, NULL); + %out = QString::fromWCharArray(temp); + PyMem_Free(temp); +#elif defined(IS_PY3K) + void *data = PyUnicode_DATA(%in); + Py_ssize_t len = PyUnicode_GetLength(%in); + switch (PyUnicode_KIND(%in)) { + case PyUnicode_1BYTE_KIND: + %out = QString::fromLatin1(reinterpret_cast<const char *>(data)); + break; + case PyUnicode_2BYTE_KIND: + %out = QString::fromUtf16(reinterpret_cast<const char16_t *>(data), len); + break; + case PyUnicode_4BYTE_KIND: + %out = QString::fromUcs4(reinterpret_cast<const char32_t *>(data), len); + break; + } +#else // IS_PY3K Py_UNICODE *unicode = PyUnicode_AS_UNICODE(%in); # if defined(Py_UNICODE_WIDE) // cast as Py_UNICODE can be a different type @@ -1767,11 +1786,7 @@ Py_UNICODE *unicode = PyUnicode_AS_UNICODE(%in); %out = QString::fromUtf16(reinterpret_cast<const ushort *>(unicode), PepUnicode_GetLength(%in)); # endif // Qt 6 # endif -#else -wchar_t *temp = PyUnicode_AsWideCharString(%in, NULL); -%out = QString::fromWCharArray(temp); -PyMem_Free(temp); -#endif +#endif // !IS_PY3K // @snippet conversion-pyunicode // @snippet conversion-pystring |