-
Notifications
You must be signed in to change notification settings - Fork 0
/
python3.10.patch
140 lines (133 loc) · 5.54 KB
/
python3.10.patch
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
Index: pyside-setup-opensource-src-5.15.2/sources/pyside2/tests/QtCore/qenum_test.py
===================================================================
--- pyside-setup-opensource-src-5.15.2.orig/sources/pyside2/tests/QtCore/qenum_test.py
+++ pyside-setup-opensource-src-5.15.2/sources/pyside2/tests/QtCore/qenum_test.py
@@ -195,16 +195,18 @@ class SomeClass(QObject):
QEnum(SomeEnum) # works even without the decorator assignment
+ENUM_META = "EnumMeta" if sys.version_info < (3, 10) else "EnumType"
+
@unittest.skipUnless(HAVE_ENUM, "requires 'enum' module (use 'pip install enum34' for Python 2)")
class TestQEnumMacro(unittest.TestCase):
def testTopLevel(self):
self.assertEqual(type(OuterEnum).__module__, "enum")
- self.assertEqual(type(OuterEnum).__name__, "EnumMeta")
+ self.assertEqual(type(OuterEnum).__name__, ENUM_META)
self.assertEqual(len(OuterEnum.__members__), 2)
def testSomeClass(self):
self.assertEqual(type(SomeClass.SomeEnum).__module__, "enum")
- self.assertEqual(type(SomeClass.SomeEnum).__name__, "EnumMeta")
+ self.assertEqual(type(SomeClass.SomeEnum).__name__, ENUM_META)
self.assertEqual(len(SomeClass.SomeEnum.__members__), 3)
with self.assertRaises(TypeError):
int(SomeClass.SomeEnum.C) == 6
Index: pyside-setup-opensource-src-5.15.2/sources/shiboken2/libshiboken/pep384impl.cpp
===================================================================
--- pyside-setup-opensource-src-5.15.2.orig/sources/shiboken2/libshiboken/pep384impl.cpp
+++ pyside-setup-opensource-src-5.15.2/sources/shiboken2/libshiboken/pep384impl.cpp
@@ -707,6 +707,76 @@ PyObject *PepMapping_Items(PyObject *o)
*
*/
+#if PY_VERSION_HEX >= 0x03000000
+PyObject *
+_Py_Mangle(PyObject *privateobj, PyObject *ident)
+{
+ /* Name mangling: __private becomes _classname__private.
+ This is independent from how the name is used. */
+ PyObject *result;
+ size_t nlen, plen, ipriv;
+ Py_UCS4 maxchar;
+ if (privateobj == NULL || !PyUnicode_Check(privateobj) ||
+ PyUnicode_READ_CHAR(ident, 0) != '_' ||
+ PyUnicode_READ_CHAR(ident, 1) != '_') {
+ Py_INCREF(ident);
+ return ident;
+ }
+ nlen = PyUnicode_GET_LENGTH(ident);
+ plen = PyUnicode_GET_LENGTH(privateobj);
+ /* Don't mangle __id__ or names with dots.
+
+ The only time a name with a dot can occur is when
+ we are compiling an import statement that has a
+ package name.
+
+ TODO(jhylton): Decide whether we want to support
+ mangling of the module name, e.g. __M.X.
+ */
+ if ((PyUnicode_READ_CHAR(ident, nlen-1) == '_' &&
+ PyUnicode_READ_CHAR(ident, nlen-2) == '_') ||
+ PyUnicode_FindChar(ident, '.', 0, nlen, 1) != -1) {
+ Py_INCREF(ident);
+ return ident; /* Don't mangle __whatever__ */
+ }
+ /* Strip leading underscores from class name */
+ ipriv = 0;
+ while (PyUnicode_READ_CHAR(privateobj, ipriv) == '_')
+ ipriv++;
+ if (ipriv == plen) {
+ Py_INCREF(ident);
+ return ident; /* Don't mangle if class is just underscores */
+ }
+ plen -= ipriv;
+
+ if (plen + nlen >= PY_SSIZE_T_MAX - 1) {
+ PyErr_SetString(PyExc_OverflowError,
+ "private identifier too large to be mangled");
+ return NULL;
+ }
+
+ maxchar = PyUnicode_MAX_CHAR_VALUE(ident);
+ if (PyUnicode_MAX_CHAR_VALUE(privateobj) > maxchar)
+ maxchar = PyUnicode_MAX_CHAR_VALUE(privateobj);
+
+ result = PyUnicode_New(1 + nlen + plen, maxchar);
+ if (!result)
+ return 0;
+ /* ident = "_" + priv[ipriv:] + ident # i.e. 1+plen+nlen bytes */
+ PyUnicode_WRITE(PyUnicode_KIND(result), PyUnicode_DATA(result), 0, '_');
+ if (PyUnicode_CopyCharacters(result, 1, privateobj, ipriv, plen) < 0) {
+ Py_DECREF(result);
+ return NULL;
+ }
+ if (PyUnicode_CopyCharacters(result, plen+1, ident, 0, nlen) < 0) {
+ Py_DECREF(result);
+ return NULL;
+ }
+ assert(_PyUnicode_CheckConsistency(result, 1));
+ return result;
+}
+#endif
+
#ifdef Py_LIMITED_API
// We keep these definitions local, because they don't work in Python 2.
# define PyUnicode_GET_LENGTH(op) PyUnicode_GetLength((PyObject *)(op))
@@ -751,9 +821,6 @@ _Pep_PrivateMangle(PyObject *self, PyObj
#endif // IS_PY2
Shiboken::AutoDecRef privateobj(PyObject_GetAttr(
reinterpret_cast<PyObject *>(Py_TYPE(self)), Shiboken::PyMagicName::name()));
-#ifndef Py_LIMITED_API
- return _Py_Mangle(privateobj, name);
-#else
// PYSIDE-1436: _Py_Mangle is no longer exposed; implement it always.
// The rest of this function is our own implementation of _Py_Mangle.
// Please compare the original function in compile.c .
@@ -789,7 +856,6 @@ _Pep_PrivateMangle(PyObject *self, PyObj
if (amount > big_stack)
free(resbuf);
return result;
-#endif // else Py_LIMITED_API
}
/*****************************************************************************
Index: pyside-setup-opensource-src-5.15.2/sources/shiboken2/libshiboken/pep384impl.h
===================================================================
--- pyside-setup-opensource-src-5.15.2.orig/sources/shiboken2/libshiboken/pep384impl.h
+++ pyside-setup-opensource-src-5.15.2/sources/shiboken2/libshiboken/pep384impl.h
@@ -45,6 +45,11 @@
# define Py_SET_REFCNT(obj, refcnt) ((Py_REFCNT(obj) = (refcnt)), (void)0)
#endif
+// PYSIDE-1436: Adapt to Python 3.10
+#if PY_VERSION_HEX < 0x030900A4
+# define Py_SET_REFCNT(obj, refcnt) ((Py_REFCNT(obj) = (refcnt)), (void)0)
+#endif
+
extern "C"
{