diff options
author | Christian Tismer <tismer@stackless.com> | 2019-12-12 13:01:12 +0100 |
---|---|---|
committer | Christian Tismer <tismer@stackless.com> | 2019-12-12 16:17:24 +0100 |
commit | fb628016895e59cd5adf617281b2b75b26bf3378 (patch) | |
tree | 89534a72be2e82ea55b84fdf2fb33ef0747e930d | |
parent | 2cfa859283355f7710b5fcd56b948a149d12032a (diff) |
Finalize the Python 3.8 refcount fix
This is a final optimization to the Py_TPFLAGS_METHOD_DESCRIPTOR
fix. Instead of keeping the mro method alive, we are caching it's type only,
because that is what we need to patch.
Another effort to solve this problem completely has failed, again.
This solution is good enough and has no time penalty.
Task-number: PYSIDE-939
Change-Id: I98c165f9cd704b0f6ce55750189d6bda9a811f70
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
-rw-r--r-- | sources/shiboken2/libshiboken/basewrapper.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/sources/shiboken2/libshiboken/basewrapper.cpp b/sources/shiboken2/libshiboken/basewrapper.cpp index dd5dc43e9..3c861c761 100644 --- a/sources/shiboken2/libshiboken/basewrapper.cpp +++ b/sources/shiboken2/libshiboken/basewrapper.cpp @@ -505,12 +505,14 @@ PyObject *SbkObjectTypeTpNew(PyTypeObject *metatype, PyObject *args, PyObject *k // PYSIDE-939: This is a temporary patch that circumvents the problem // with Py_TPFLAGS_METHOD_DESCRIPTOR until this is finally solved. - PyObject *ob_PyType_Type = reinterpret_cast<PyObject *>(&PyType_Type); - static PyObject *mro = PyObject_GetAttr(ob_PyType_Type, Shiboken::PyName::mro()); - auto hold = Py_TYPE(mro)->tp_flags; - Py_TYPE(mro)->tp_flags &= ~Py_TPFLAGS_METHOD_DESCRIPTOR; + // 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 = reinterpret_cast<SbkObjectType *>(type_new(metatype, args, kwds)); - Py_TYPE(mro)->tp_flags = hold; + PyMethodDescr_TypePtr->tp_flags = hold; if (!newType) return nullptr; |