From 8e2e37b811214ddea195cceff361fc181745b6da Mon Sep 17 00:00:00 2001 From: Kay Hayen Date: Sun, 21 Mar 2021 17:55:19 +0100 Subject: [PATCH 5/6] Nuitka: The binding manager didn't allow for compiled methods --- .../shiboken6/libshiboken/bindingmanager.cpp | 41 ++++++++++++++++--- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/sources/shiboken6/libshiboken/bindingmanager.cpp b/sources/shiboken6/libshiboken/bindingmanager.cpp index e4c6c2320..b870b3da5 100644 --- a/sources/shiboken6/libshiboken/bindingmanager.cpp +++ b/sources/shiboken6/libshiboken/bindingmanager.cpp @@ -317,8 +317,38 @@ PyObject *BindingManager::getOverride(const void *cptr, PyObject *method = PyObject_GetAttr(reinterpret_cast(wrapper), pyMethodName); - if (method && PyMethod_Check(method) - && PyMethod_GET_SELF(method) == reinterpret_cast(wrapper)) { + PyObject *function = nullptr; + + // PYSIDE-1523: PyMethod_Check is not accepting compiled methods, we do this rather + // crude check for them. + if (method) { + if (PyMethod_Check(method)) { + if (PyMethod_GET_SELF(method) == reinterpret_cast(wrapper)) { + function = PyMethod_GET_FUNCTION(method); + } else { + Py_DECREF(method); + method = nullptr; + } + } else if (PyObject_HasAttrString(method, "im_self") && PyObject_HasAttrString(method, "im_func")) { + PyObject *im_self = PyObject_GetAttrString(method, "im_self"); + // Not retaining a reference inline with what PyMethod_GET_SELF does. + Py_DECREF(im_self); + + if (im_self == reinterpret_cast(wrapper)) { + function = PyObject_GetAttrString(method, "im_func"); + // Not retaining a reference inline with what PyMethod_GET_FUNCTION does. + Py_DECREF(function); + } else { + Py_DECREF(method); + method = nullptr; + } + } else { + Py_DECREF(method); + method = nullptr; + } + } + + if (method != nullptr) { PyObject *defaultMethod; PyObject *mro = Py_TYPE(wrapper)->tp_mro; @@ -329,13 +359,14 @@ PyObject *BindingManager::getOverride(const void *cptr, auto *parent = reinterpret_cast(PyTuple_GET_ITEM(mro, idx)); if (parent->tp_dict) { defaultMethod = PyDict_GetItem(parent->tp_dict, pyMethodName); - if (defaultMethod && PyMethod_GET_FUNCTION(method) != defaultMethod) + if (defaultMethod && function != defaultMethod) return method; } } - } else { - Py_XDECREF(method); + + Py_DECREF(method); } + return nullptr; } -- 2.30.0.windows.2