From 56f66f128566bd08f027fee46bb42a6c4f57a26e Mon Sep 17 00:00:00 2001 From: Shyamnath Premnadh Date: Mon, 10 Jan 2022 10:22:09 +0100 Subject: Safe distinction of Nuitka compiled methods Adds an extra check to see if __code__ is present. As mentioned in PYSIDE-1755, Mocks are callable objects without __code__ attribute, unlike Python Method or Functions. However, a Mock also has im_func__ and im__self attributes. We made the assumption __code__ would be present if im_func and im_self are present, and this makes it fall under the category of a compiled method. This patch makes an extra check to see if __code__ is present. If it is not, then the Slot (here Mock) is considered as a callable method. Task-number: PYSIDE-1755 Pick-to: 6.2 Change-Id: If7e8f52dfb2409cd856eec0d0b41891d751d8a69 Reviewed-by: Friedemann Kleint --- sources/pyside6/libpyside/globalreceiverv2.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'sources/pyside6/libpyside/globalreceiverv2.cpp') diff --git a/sources/pyside6/libpyside/globalreceiverv2.cpp b/sources/pyside6/libpyside/globalreceiverv2.cpp index ef6097764..cf2508a97 100644 --- a/sources/pyside6/libpyside/globalreceiverv2.cpp +++ b/sources/pyside6/libpyside/globalreceiverv2.cpp @@ -114,8 +114,7 @@ DynamicSlotDataV2::DynamicSlotDataV2(PyObject *callback, GlobalReceiverV2 *paren //monitor class from method lifetime m_weakRef = WeakRef::create(m_pythonSelf, DynamicSlotDataV2::onCallbackDestroyed, this); - } else if (PyObject_HasAttr(callback, PySide::PyName::im_func()) - && PyObject_HasAttr(callback, PySide::PyName::im_self())) { + } else if (PySide::isCompiledMethod(callback)) { // PYSIDE-1523: PyMethod_Check is not accepting compiled form, we just go by attributes. m_isMethod = true; @@ -141,8 +140,7 @@ GlobalReceiverKey DynamicSlotDataV2::key(PyObject *callback) if (PyMethod_Check(callback)) { // PYSIDE-1422: Avoid hash on self which might be unhashable. return {PyMethod_GET_SELF(callback), PyMethod_GET_FUNCTION(callback)}; - } else if (PyObject_HasAttr(callback, PySide::PyName::im_func()) - && PyObject_HasAttr(callback, PySide::PyName::im_self())) { + } else if (PySide::isCompiledMethod(callback)) { // PYSIDE-1589: Fix for slots in compiled functions Shiboken::AutoDecRef self(PyObject_GetAttr(callback, PySide::PyName::im_self())); Shiboken::AutoDecRef func(PyObject_GetAttr(callback, PySide::PyName::im_func())); -- cgit v1.2.3