aboutsummaryrefslogtreecommitdiffstats
path: root/sources
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2021-06-30 11:22:42 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-06-30 14:05:00 +0000
commit7a51dec5423e46dcdb3dc537329eb9778731581d (patch)
tree12896b5783659949228ae34d4b8d91d0b12b99c6 /sources
parentab5397ab3ff37e96f64d6776be426465c6da5875 (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 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> (cherry picked from commit 8f4eacfb0f140e7b75a66279835b5eb3649ae462) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'sources')
-rw-r--r--sources/pyside6/PySide6/glue/qtcore.cpp28
1 files changed, 13 insertions, 15 deletions
diff --git a/sources/pyside6/PySide6/glue/qtcore.cpp b/sources/pyside6/PySide6/glue/qtcore.cpp
index cf38fbc94..a30c6635b 100644
--- a/sources/pyside6/PySide6/glue/qtcore.cpp
+++ b/sources/pyside6/PySide6/glue/qtcore.cpp
@@ -1652,21 +1652,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);