From f774118ab6f81d30f35f05c052fddbce2ade96a7 Mon Sep 17 00:00:00 2001 From: Kay Hayen Date: Sun, 21 Mar 2021 17:54:11 +0100 Subject: [PATCH 4/6] Nuitka: Add support for compiled methods to dynamic slot data * Not sure what this is used for. --- .../pyside6/libpyside/globalreceiverv2.cpp | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/sources/pyside6/libpyside/globalreceiverv2.cpp b/sources/pyside6/libpyside/globalreceiverv2.cpp index 8ff5d896f..0558174aa 100644 --- a/sources/pyside6/libpyside/globalreceiverv2.cpp +++ b/sources/pyside6/libpyside/globalreceiverv2.cpp @@ -99,21 +99,35 @@ class DynamicSlotDataV2 using namespace PySide; DynamicSlotDataV2::DynamicSlotDataV2(PyObject *callback, GlobalReceiverV2 *parent) : - m_isMethod(PyMethod_Check(callback)), m_parent(parent) { Shiboken::GilState gil; - if (m_isMethod) { - //Can not store calback pointe because this will be destroyed at the end of the scope - //To avoid increment intance reference keep the callback information + if (PyMethod_Check(callback)) { + m_isMethod = true; + //Can not store callback pointer because this will be destroyed at the end of the scope + //To avoid increment instance reference keep the callback information m_callback = PyMethod_GET_FUNCTION(callback); + Py_INCREF(m_callback); m_pythonSelf = PyMethod_GET_SELF(callback); //monitor class from method lifetime m_weakRef = WeakRef::create(m_pythonSelf, DynamicSlotDataV2::onCallbackDestroyed, this); + } else if (PyObject_HasAttrString(callback, "im_func") && PyObject_HasAttrString(callback, "im_self")) { + // PYSIDE-1523: PyMethod_Check is not accepting compiled form, we just go by attributes. + m_isMethod = true; + + m_callback = PyObject_GetAttrString(callback, "im_func"); + Py_DECREF(m_callback); + + PyObject *m_pythonSelf = PyObject_GetAttrString(callback, "im_self"); + Py_DECREF(m_pythonSelf); + //monitor class from method lifetime + m_weakRef = WeakRef::create(m_pythonSelf, DynamicSlotDataV2::onCallbackDestroyed, this); } else { + m_isMethod = false; + m_callback = callback; Py_INCREF(m_callback); } @@ -135,7 +149,7 @@ PyObject *DynamicSlotDataV2::callback() //create a callback based on method data if (m_isMethod) - callback = PyMethod_New(m_callback, m_pythonSelf); + callback = Py_TYPE(m_callback)->tp_descr_get(m_callback, m_pythonSelf, NULL); else Py_INCREF(callback); @@ -172,8 +186,7 @@ DynamicSlotDataV2::~DynamicSlotDataV2() Py_XDECREF(m_weakRef); m_weakRef = 0; - if (!m_isMethod) - Py_DECREF(m_callback); + Py_DECREF(m_callback); } GlobalReceiverV2::GlobalReceiverV2(PyObject *callback, GlobalReceiverV2MapPtr map) : -- 2.30.0.windows.2