From: Friedemann Kleint Date: Fri, 24 Jun 2022 07:22:01 +0000 (+0200) Subject: libshiboken: Fix crashes with static strings in Python 3.11 X-Git-Tag: archive/raspbian/5.15.8-2+rpi1^2^2~7 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=43ec16a5b679ef41ebac1c138043c8e85882ffaf;p=pyside2.git 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 Pick-to: 6.3 6.2 5.15 Change-Id: I6436afee351f89da5814b5d6bc76970b1b508168 Reviewed-by: Qt CI Bot Reviewed-by: Christian Tismer (cherry picked from commit a09a1db8391243e6bb290ee66bb6e3afbb114c61) Gbp-Pq: Name libshiboken-Fix-crashes-with-static-strings-in-Python-3.11.patch --- diff --git a/sources/shiboken2/libshiboken/sbkstring.cpp b/sources/shiboken2/libshiboken/sbkstring.cpp index 077fb53..a9d451c 100644 --- a/sources/shiboken2/libshiboken/sbkstring.cpp +++ b/sources/shiboken2/libshiboken/sbkstring.cpp @@ -41,8 +41,14 @@ #include "sbkstaticstrings_p.h" #include "autodecref.h" -#include -#include +#if PY_VERSION_HEX >= 0x030B0000 || defined(Py_LIMITED_API) +# define USE_INTERN_STRINGS +#endif + +#ifndef USE_INTERN_STRINGS +# include +# include +#endif namespace Shiboken { @@ -233,6 +239,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; static void finalizeStaticStrings(); // forward @@ -283,6 +296,8 @@ PyObject *createStaticString(const char *str) return result; } +#endif // !USE_INTERN_STRINGS + /////////////////////////////////////////////////////////////////////// // // PYSIDE-1019: Helper function for snake_case vs. camelCase names