[PATCH 2/3] Optimize the Python 3.8 refcount fix a tiny bit
authorChristian Tismer <tismer@stackless.com>
Thu, 5 Dec 2019 10:08:50 +0000 (11:08 +0100)
committerKurt Kremitzki <kurt@kwk.systems>
Mon, 18 May 2020 01:27:01 +0000 (02:27 +0100)
This change uses the fact that our workaround to temporarily remove
the Py_TPFLAGS_METHOD_DESCRIPTOR flag uses the "mro" function
of PyType_Type, which never will change.
Therefore, the static keyword makes sure that this function lookup
happens only once.

Change-Id: I44b74556da1fac2596c81339af30cb66218276e2
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Gbp-Pq: Name 0003-Optimize-the-Python-3.8-refcount-fix-a-tiny-bit.patch

sources/shiboken2/libshiboken/basewrapper.cpp

index e9bef07f90e2395a1d5a39e9be67ef341e4e5b07..1e3b7406d56e74d7848792152717060ca6d7c7c6 100644 (file)
@@ -506,7 +506,7 @@ 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);
-    PyObject *mro = PyObject_GetAttr(ob_PyType_Type, Shiboken::PyName::mro());
+    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;
     auto *newType = reinterpret_cast<SbkObjectType *>(type_new(metatype, args, kwds));