https://src.fedoraproject.org/fork/pviktori/rpms/python-pyside2/raw/5da9902bd8732b49eb722d71f306d4ab197c84b8/f/python3.11.patch https://code.qt.io/cgit/pyside/pyside-setup.git/patch/?id=52df3b8f64 https://code.qt.io/cgit/pyside/pyside-setup.git/patch/?id=73adefe22f https://code.qt.io/cgit/pyside/pyside-setup.git/patch/?id=a09a1db839 From b64ad27d8dfeeecaaa8a98051252a32c9d998df4 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 9 Jun 2022 16:50:41 +0200 Subject: [PATCH] libshiboken: Fix a crash in Shiboken::Object::isValid() for Python 3.11 The function is passed type objects for class methods, which caused it to crash. The first clause did not catch this, and so it was cast to SbkObject below. Add a type check to prevent this. Pick-to: 6.3 6.2 5.15 Task-number: PYSIDE-1960 Change-Id: Icfdd6fefb7156ac5961444bd5395109849a1d66e Reviewed-by: Christian Tismer Reviewed-by: Qt CI Bot --- a/libshiboken/basewrapper.cpp +++ b/libshiboken/basewrapper.cpp @@ -1468,6 +1468,7 @@ bool setCppPointer(SbkObject *sbkObj, PyTypeObject *desiredType, void *cptr) bool isValid(PyObject *pyObj) { if (!pyObj || pyObj == Py_None + || PyType_Check(pyObj) != 0 || Py_TYPE(Py_TYPE(pyObj)) != SbkObjectType_TypeF()) { return true; } --- a/libshiboken/basewrapper.cpp +++ b/libshiboken/basewrapper.cpp @@ -366,7 +366,7 @@ SbkObjectType *SbkObject_TypeF(void) static PyTypeObject *type = nullptr; if (!type) { type = reinterpret_cast(SbkType_FromSpec(&SbkObject_Type_spec)); - Py_TYPE(type) = SbkObjectType_TypeF(); + Py_SET_TYPE(type, SbkObjectType_TypeF()); Py_INCREF(Py_TYPE(type)); type->tp_weaklistoffset = offsetof(SbkObject, weakreflist); type->tp_dictoffset = offsetof(SbkObject, ob_dict); @@ -1110,7 +1110,7 @@ introduceWrapperType(PyObject *enclosingObject, typeSpec->slots[0].pfunc = reinterpret_cast(baseType ? baseType : SbkObject_TypeF()); PyObject *heaptype = SbkType_FromSpecWithBases(typeSpec, baseTypes); - Py_TYPE(heaptype) = SbkObjectType_TypeF(); + Py_SET_TYPE(heaptype, SbkObjectType_TypeF()); Py_INCREF(Py_TYPE(heaptype)); auto *type = reinterpret_cast(heaptype); #if PY_VERSION_HEX < 0x03000000 --- a/libshiboken/sbkenum.cpp +++ b/libshiboken/sbkenum.cpp @@ -741,7 +741,7 @@ newTypeWithName(const char *name, copyNumberMethods(numbers_fromFlag, newslots, &idx); newspec.slots = newslots; auto *type = reinterpret_cast(SbkType_FromSpec(&newspec)); - Py_TYPE(type) = SbkEnumType_TypeF(); + Py_SET_TYPE(type, SbkEnumType_TypeF()); auto *enumType = reinterpret_cast(type); PepType_SETP(enumType)->cppName = cppName; From a09a1db8391243e6bb290ee66bb6e3afbb114c61 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 24 Jun 2022 09:22:01 +0200 Subject: 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 Upstream: https://code.qt.io/cgit/pyside/pyside-setup.git/commit/?id=a09a1db8391243e6bb290ee66bb6e3afbb114c61 --- a/libshiboken/sbkstring.cpp +++ b/libshiboken/sbkstring.cpp @@ -5,8 +5,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 { @@ -179,6 +185,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 @@ -225,6 +238,8 @@ PyObject *createStaticString(const char *str) return result; } +#endif // !USE_INTERN_STRINGS + /////////////////////////////////////////////////////////////////////// // // PYSIDE-1019: Helper function for snake_case vs. camelCase names cgit v1.2.1