summaryrefslogtreecommitdiff
path: root/dev-python/shiboken2/files/shiboken2-5.15.2-python311.patch
blob: 063861a1cb1aa90527835815420c69ef04c865f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
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 <Friedemann.Kleint@qt.io>
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 <tismer@stackless.com>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
--- 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<PyTypeObject *>(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<void *>(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<SbkObjectType *>(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<PyTypeObject *>(SbkType_FromSpec(&newspec));
-    Py_TYPE(type) = SbkEnumType_TypeF();
+    Py_SET_TYPE(type, SbkEnumType_TypeF());
 
     auto *enumType = reinterpret_cast<SbkEnumType *>(type);
     PepType_SETP(enumType)->cppName = cppName;
From a09a1db8391243e6bb290ee66bb6e3afbb114c61 Mon Sep 17 00:00:00 2001
From: Friedemann Kleint <Friedemann.Kleint@qt.io>
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 <qt_ci_bot@qt-project.org>
Reviewed-by: Christian Tismer <tismer@stackless.com>
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 <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
 {
@@ -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<PyObject *>;
 
 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