aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2021-09-22 14:50:50 +0200
committerChristian Tismer <tismer@stackless.com>2021-09-23 15:28:53 +0200
commita4c432bc007d515b843b30765dfa0b82851255b9 (patch)
treefeb79ba09fb67c25d699a725d7b1a116268d9243
parent8878f9980d873cccc8f67cc6aed60929396872f2 (diff)
shiboken6: Fix an impossible reference to type_new
[ChangeLog][shiboken6] It is now possible to derive classes from enum types like `QtCore.Key` in earlier Python versions. In SbkEnumTypeTpNew the reference to `PyType_Type.tp_new` was made through `PyType_GetSlot` in a Limited API compatible way. Unfortunately, `PyType_GetSlot` works for non-heaptypes in Python 3.10, only, and `PyType_Type is not a heaptype. This was found while creating a minimum example to prove that the PyPy implementation of type_new is not correct. Task-number: PYSIDE-535 Change-Id: Ibe300f4670d9db6d29fbdeb1d147e1a074ec23c6 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
-rw-r--r--sources/pyside6/tests/QtCore/qenum_test.py6
-rw-r--r--sources/shiboken6/libshiboken/sbkenum.cpp2
2 files changed, 7 insertions, 1 deletions
diff --git a/sources/pyside6/tests/QtCore/qenum_test.py b/sources/pyside6/tests/QtCore/qenum_test.py
index 0d524505a..76caa9a37 100644
--- a/sources/pyside6/tests/QtCore/qenum_test.py
+++ b/sources/pyside6/tests/QtCore/qenum_test.py
@@ -77,6 +77,12 @@ class TestEnum(unittest.TestCase):
with self.assertRaises(TypeError):
a = k * 2.0
+ def testInherit(self):
+ class A(Qt.Key):
+ pass
+
+ self.assertEqual(A.Key_1, Qt.Key.Key_1)
+
@unittest.skipUnless(getattr(sys, "getobjects", None), "requires --with-trace-refs")
@unittest.skipUnless(getattr(sys, "gettotalrefcount", None), "requires --with-pydebug")
def testEnumNew_NoLeak(self):
diff --git a/sources/shiboken6/libshiboken/sbkenum.cpp b/sources/shiboken6/libshiboken/sbkenum.cpp
index a6f65c7ab..b97cff209 100644
--- a/sources/shiboken6/libshiboken/sbkenum.cpp
+++ b/sources/shiboken6/libshiboken/sbkenum.cpp
@@ -310,7 +310,7 @@ void SbkEnumTypeDealloc(PyObject *pyObj)
PyObject *SbkEnumTypeTpNew(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
{
- auto type_new = reinterpret_cast<newfunc>(PyType_GetSlot(&PyType_Type, Py_tp_new));
+ auto type_new = reinterpret_cast<newfunc>(PyType_Type.tp_new);
auto newType = reinterpret_cast<SbkEnumType *>(type_new(metatype, args, kwds));
if (!newType)
return nullptr;