aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2022-06-24 09:22:01 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-06-24 17:10:09 +0000
commit9683149520c0f8159ca907f8614421971d9fc248 (patch)
tree50e9bc6a40a31c2b9f93d7174e047edf64c80702
parent782ae86b89f58121d3ebb4fb02639a186be4f61c (diff)
libshiboken: Fix crashes with static strings in Python 3.11
In Python 3.11, some strings come with a refcount above decimal 1000000000, apparently indicating that they are interned. Replace the mechanism by PyUnicode_InternFromString(). Task-number: PYSIDE-1960 Change-Id: I6436afee351f89da5814b5d6bc76970b1b508168 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Christian Tismer <tismer@stackless.com> (cherry picked from commit a09a1db8391243e6bb290ee66bb6e3afbb114c61) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--sources/shiboken6/libshiboken/sbkstring.cpp19
1 files changed, 17 insertions, 2 deletions
diff --git a/sources/shiboken6/libshiboken/sbkstring.cpp b/sources/shiboken6/libshiboken/sbkstring.cpp
index 0a2cd5c60..3c888f7c6 100644
--- a/sources/shiboken6/libshiboken/sbkstring.cpp
+++ b/sources/shiboken6/libshiboken/sbkstring.cpp
@@ -41,8 +41,14 @@
#include "sbkstaticstrings_p.h"
#include "autodecref.h"
-#include <vector>
-#include <unordered_set>
+#if PY_VERSION_HEX >= 0x030B0000 || defined(Py_LIMITED_API)
+# define USE_INTERN_STRINGS
+#endif
+
+#ifndef USE_INTERN_STRINGS
+# include <vector>
+# include <unordered_set>
+#endif
namespace Shiboken::String
{
@@ -215,6 +221,13 @@ Py_ssize_t len(PyObject *str)
// PyObject *attr = PyObject_GetAttr(obj, name());
//
+#ifdef USE_INTERN_STRINGS
+PyObject *createStaticString(const char *str)
+{
+ return PyUnicode_InternFromString(str);
+}
+#else
+
using StaticStrings = std::unordered_set<PyObject *>;
static void finalizeStaticStrings(); // forward
@@ -261,6 +274,8 @@ PyObject *createStaticString(const char *str)
return result;
}
+#endif // !USE_INTERN_STRINGS
+
///////////////////////////////////////////////////////////////////////
//
// PYSIDE-1019: Helper function for snake_case vs. camelCase names