diff options
author | Christian Tismer <tismer@stackless.com> | 2021-06-30 11:22:42 +0200 |
---|---|---|
committer | Christian Tismer <tismer@stackless.com> | 2021-06-30 13:58:45 +0200 |
commit | 8f4eacfb0f140e7b75a66279835b5eb3649ae462 (patch) | |
tree | bc4ea6bc85a74dc2596611242481ad20e3f8891c | |
parent | 2022d164eaf23051c68bd5265631500e22baf66d (diff) |
Unicode: renew implementation and remove Python 2 version
[ChangeLog][PySide6] The Python Unicode API was updated to the newest
version when not in limited API mode, too.
The unicode interface that we use in non-limited API
mode is deprecated since Python 3.3.
- Remove the Python 2 branch
- Use the more efficient direct access mode.
The annoying message became visible while working on
PyPy support, which cannot use the limited API.
Change-Id: If83921000f7fbcec79e8d572a0598d50fa6508a5
Pick-to: 6.1
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
-rw-r--r-- | sources/pyside6/PySide6/glue/qtcore.cpp | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/sources/pyside6/PySide6/glue/qtcore.cpp b/sources/pyside6/PySide6/glue/qtcore.cpp index ccabc5a6f..b037a31be 100644 --- a/sources/pyside6/PySide6/glue/qtcore.cpp +++ b/sources/pyside6/PySide6/glue/qtcore.cpp @@ -1674,21 +1674,19 @@ if (PyErr_WarnEx(PyExc_DeprecationWarning, // @snippet conversion-pyunicode #ifndef Py_LIMITED_API -Py_UNICODE *unicode = PyUnicode_AS_UNICODE(%in); -# if defined(Py_UNICODE_WIDE) -// cast as Py_UNICODE can be a different type -# if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) -%out = QString::fromUcs4(reinterpret_cast<const char32_t *>(unicode)); -# else -%out = QString::fromUcs4(reinterpret_cast<const uint *>(unicode)); -# endif // Qt 6 -# else // Py_UNICODE_WIDE -# if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) -%out = QString::fromUtf16(reinterpret_cast<const char16_t *>(unicode), PepUnicode_GetLength(%in)); -# else -%out = QString::fromUtf16(reinterpret_cast<const ushort *>(unicode), PepUnicode_GetLength(%in)); -# endif // Qt 6 -# endif +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 wchar_t *temp = PyUnicode_AsWideCharString(%in, nullptr); %out = QString::fromWCharArray(temp); |