Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2021-03-22 17:10:51 +0100
committerChristian Tismer <tismer@stackless.com>2021-03-26 16:27:52 +0100
commit773e1105251a03131cbbdf4abcb0580cb425ff60 (patch)
tree0d9185db4d3087c75476da116ce560804a0e1465 /sources/pyside6/libpyside/globalreceiverv2.cpp
parentb89b8daeeac7b2b22c3887fa83fe0b986f9baec7 (diff)
Nuitka: Allow for compiled functions and methods too
The author of this patch is Kay Hayen. He writes: * Add support for compiled methods to the bindings manager. * For slots, implement lookup of code objects for compiled methods and functions with a new function avoiding code duplication. * Look up attributes of slots, e.g. code objects that Nuitka also has as well, methods have "im_func" and "im_self". * Sometimes calling "tp_descr_get" Python object slot is the universal thing to do, covering all types. * Detect compiled methods as receiver targets too. Task-number: PYSIDE-1523 Change-Id: I0277b583840710476198ed5e1ccaaccd672e7638 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/pyside6/libpyside/globalreceiverv2.cpp')
-rw-r--r--sources/pyside6/libpyside/globalreceiverv2.cpp28
1 files changed, 21 insertions, 7 deletions
diff --git a/sources/pyside6/libpyside/globalreceiverv2.cpp b/sources/pyside6/libpyside/globalreceiverv2.cpp
index 1bbafb4ec..c8a6e9f99 100644
--- a/sources/pyside6/libpyside/globalreceiverv2.cpp
+++ b/sources/pyside6/libpyside/globalreceiverv2.cpp
@@ -40,6 +40,7 @@
#include "globalreceiverv2.h"
#include "dynamicqmetaobject_p.h"
#include "pysideweakref.h"
+#include "pysidestaticstrings.h"
#include "signalmanager.h"
#include <autodecref.h>
@@ -101,21 +102,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;
+ // 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_HasAttr(callback, PySide::PyName::im_func())
+ && PyObject_HasAttr(callback, PySide::PyName::im_self())) {
+ // PYSIDE-1523: PyMethod_Check is not accepting compiled form, we just go by attributes.
+ m_isMethod = true;
+
+ m_callback = PyObject_GetAttr(callback, PySide::PyName::im_func());
+ Py_DECREF(m_callback);
+
+ m_pythonSelf = PyObject_GetAttr(callback, PySide::PyName::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);
}
@@ -137,7 +152,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, nullptr);
else
Py_INCREF(callback);
@@ -174,8 +189,7 @@ DynamicSlotDataV2::~DynamicSlotDataV2()
Py_XDECREF(m_weakRef);
m_weakRef = nullptr;
- if (!m_isMethod)
- Py_DECREF(m_callback);
+ Py_DECREF(m_callback);
}
GlobalReceiverV2::GlobalReceiverV2(PyObject *callback, GlobalReceiverV2MapPtr map) :