diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2022-06-24 09:22:01 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2022-08-03 22:42:37 +0200 |
commit | 1c92e34b1790111e403f265f0faaf4e4d767bd97 (patch) | |
tree | ecffa95d0374667d6382060900712def6cb2a453 | |
parent | 750eb2a956c4e2dd44d7ac457c81883da674dbba (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)
-rw-r--r-- | sources/shiboken2/libshiboken/sbkstring.cpp | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/sources/shiboken2/libshiboken/sbkstring.cpp b/sources/shiboken2/libshiboken/sbkstring.cpp index cc8d4a6ec..57fb3514b 100644 --- a/sources/shiboken2/libshiboken/sbkstring.cpp +++ b/sources/shiboken2/libshiboken/sbkstring.cpp @@ -23,8 +23,14 @@ #include "sbkstaticstrings_p.h" #include "autodecref.h" -#include <vector> -#include <unordered_set> +#if PY_VERSION_HEX >= 0x03000000 +# define USE_INTERN_STRINGS +#endif + +#ifndef USE_INTERN_STRINGS +# include <vector> +# include <unordered_set> +#endif namespace Shiboken { @@ -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 @@ -265,6 +278,8 @@ PyObject *createStaticString(const char *str) return result; } +#endif // !USE_INTERN_STRINGS + /////////////////////////////////////////////////////////////////////// // // PYSIDE-1019: Helper function for snake_case vs. camelCase names |