aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2023-06-01 20:14:45 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-06-06 14:33:56 +0000
commit95857c8ca68720431a9af3969d2509dc6c367e1b (patch)
tree1169c2ffece81b3a81b219fff14e0bf6960537be
parentf21ed0581fa0fb352480833186cf8f43d1c22fa0 (diff)
Shiboken: Remove an old patch that is no longer necessary
An old refcounting problem from 2019 was fixed by a crude patch to class creation in basewrapper.cpp . This patch now creates an assertion error in debug mode when running the test for issue PYSIDE-2354. The problem was actually a CPython bug and does only exist in Python 3.8 until Python 3.9.12, for all other versions it works fine. See https://github.com/python/cpython/issues/92112 [ChangeLog][shiboken6] An old patch for a Python 3.8-3.9.13 error was timed out and removed from current versions. Task-number: PYSIDE-939 Task-number: PYSIDE-2354 Change-Id: I6c077294dc61491b47b6e75e95fd669144fa0471 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Adrian Herrmann <adrian.herrmann@qt.io> (cherry picked from commit 30a684904419922d7bd9857d889addc6ac444efd) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--sources/shiboken6/libshiboken/basewrapper.cpp24
-rw-r--r--sources/shiboken6/libshiboken/pep384_issue33738.cpp7
-rw-r--r--sources/shiboken6/libshiboken/pep384impl.cpp10
-rw-r--r--sources/shiboken6/libshiboken/pep384impl.h2
4 files changed, 28 insertions, 15 deletions
diff --git a/sources/shiboken6/libshiboken/basewrapper.cpp b/sources/shiboken6/libshiboken/basewrapper.cpp
index 4a5b54d23..b01d01685 100644
--- a/sources/shiboken6/libshiboken/basewrapper.cpp
+++ b/sources/shiboken6/libshiboken/basewrapper.cpp
@@ -490,16 +490,20 @@ static PyTypeObject *SbkObjectType_tp_new(PyTypeObject *metatype, PyObject *args
}
}
- // PYSIDE-939: This is a temporary patch that circumvents the problem
- // with Py_TPFLAGS_METHOD_DESCRIPTOR until this is finally solved.
- // PyType_Ready uses mro(). We need to temporarily remove the flag from it's type.
- // We cannot use PyMethodDescr_Type since it is not exported by Python 2.7 .
- static PyTypeObject *PyMethodDescr_TypePtr = Py_TYPE(
- PyObject_GetAttr(reinterpret_cast<PyObject *>(&PyType_Type), Shiboken::PyName::mro()));
- auto hold = PyMethodDescr_TypePtr->tp_flags;
- PyMethodDescr_TypePtr->tp_flags &= ~Py_TPFLAGS_METHOD_DESCRIPTOR;
- auto *newType = PepType_Type_tp_new(metatype, args, kwds);
- PyMethodDescr_TypePtr->tp_flags = hold;
+ // PYSIDE-939: This is still a temporary patch that circumvents the problem
+ // with Py_TPFLAGS_METHOD_DESCRIPTOR. The problem exists in Python 3.8
+ // until 3.9.12, only. We check the runtime and hope for this version valishing.
+ // https://github.com/python/cpython/issues/92112 will not be fixed for 3.8 :/
+ PyTypeObject *newType{};
+ static auto triplet = _PepRuntimeVersion();
+ if (triplet >= (3 << 16 | 8 << 8 | 0) && triplet < (3 << 16 | 9 << 8 | 13)) {
+ auto hold = PyMethodDescr_Type.tp_flags;
+ PyMethodDescr_Type.tp_flags &= ~Py_TPFLAGS_METHOD_DESCRIPTOR;
+ newType = PepType_Type_tp_new(metatype, args, kwds);
+ PyMethodDescr_Type.tp_flags = hold;
+ } else {
+ newType = PepType_Type_tp_new(metatype, args, kwds);
+ }
if (!newType)
return nullptr;
diff --git a/sources/shiboken6/libshiboken/pep384_issue33738.cpp b/sources/shiboken6/libshiboken/pep384_issue33738.cpp
index d91b595e8..a8fea47b8 100644
--- a/sources/shiboken6/libshiboken/pep384_issue33738.cpp
+++ b/sources/shiboken6/libshiboken/pep384_issue33738.cpp
@@ -79,11 +79,8 @@ typedef struct _oldtypeobject {
static bool is_compatible_version()
{
- auto *version = PySys_GetObject("version_info");
- auto *major = PyTuple_GetItem(version, 0);
- auto *minor = PyTuple_GetItem(version, 1);
- auto number = PyLong_AsLong(major) * 1000 + PyLong_AsLong(minor);
- return number < 3010;
+ auto number = _PepRuntimeVersion();
+ return number < (3 << 16 | 10 << 8 | 0);
}
///////////////////////////////////////////////////////////////////////
diff --git a/sources/shiboken6/libshiboken/pep384impl.cpp b/sources/shiboken6/libshiboken/pep384impl.cpp
index 8d996a706..e3b8904a5 100644
--- a/sources/shiboken6/libshiboken/pep384impl.cpp
+++ b/sources/shiboken6/libshiboken/pep384impl.cpp
@@ -898,6 +898,16 @@ init_PepRuntime()
PepRuntime_38_flag = 1;
}
+long _PepRuntimeVersion()
+{
+ static auto *version = PySys_GetObject("version_info");
+ static auto major = PyLong_AsLong(PyTuple_GetItem(version, 0));
+ static auto minor = PyLong_AsLong(PyTuple_GetItem(version, 1));
+ static auto micro = PyLong_AsLong(PyTuple_GetItem(version, 2));
+ static auto number = major << 16 | minor << 8 | micro;
+ return number;
+}
+
/*****************************************************************************
*
* PYSIDE-535: Support for PyPy
diff --git a/sources/shiboken6/libshiboken/pep384impl.h b/sources/shiboken6/libshiboken/pep384impl.h
index 05c9afab3..d57b191a2 100644
--- a/sources/shiboken6/libshiboken/pep384impl.h
+++ b/sources/shiboken6/libshiboken/pep384impl.h
@@ -121,6 +121,8 @@ LIBSHIBOKEN_API PyObject *_PepType_Lookup(PyTypeObject *type, PyObject *name);
#endif // Py_LIMITED_API
+/// PYSIDE-939: We need the runtime version, given major << 16 + minor << 8 + micro
+LIBSHIBOKEN_API long _PepRuntimeVersion();
/*****************************************************************************
*
* PYSIDE-535: Implement a clean type extension for PyPy