From 2bd69b9877f7b240512f03b4df042adf9acea744 Mon Sep 17 00:00:00 2001 From: Christian Tismer Date: Thu, 3 Sep 2020 11:49:22 +0200 Subject: Add compatibility with Nuitka This patch is based upon the old PYSIDE-198 proposal. It worked with a few changes on Python 3 with limited API disabled. When enabling the Limited API, there were a lot of crashes. This was due to the way we need to get around access to certain implementations. This showed that the original patch was wrong in the expression of bindingmanager.cpp bool isCompiled = !isMethod && Py_TYPE(method)->tp_call != nullptr; After fixing this expression with bool isCompiled = !isMethod && Py_TYPE(method) != &PyCFunction_Type && Py_TYPE(method)->tp_call != nullptr; everything worked fine with the Limited API, too. Fixes: PYSIDE-198 Task-number: PYSIDE-829 Change-Id: I4f887c639628041682052e90ba4c72aa98284e9e Reviewed-by: Friedemann Kleint --- sources/pyside2/libpyside/pysideslot.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'sources/pyside2/libpyside/pysideslot.cpp') diff --git a/sources/pyside2/libpyside/pysideslot.cpp b/sources/pyside2/libpyside/pysideslot.cpp index e60115450..7bfd1719a 100644 --- a/sources/pyside2/libpyside/pysideslot.cpp +++ b/sources/pyside2/libpyside/pysideslot.cpp @@ -47,6 +47,8 @@ #include #include +using namespace Shiboken; + struct SlotData { QByteArray name; @@ -136,23 +138,25 @@ PyObject *slotCall(PyObject *self, PyObject *args, PyObject * /* kw */) callback = PyTuple_GetItem(args, 0); Py_INCREF(callback); - if (PyFunction_Check(callback)) { + if (Py_TYPE(callback)->tp_call != nullptr) { PySideSlot *data = reinterpret_cast(self); if (!data->slotData) data->slotData = new SlotData; - if (data->slotData->name.isEmpty()) - data->slotData->name = Shiboken::String::toCString(PepFunction_GetName(callback)); - + if (data->slotData->name.isEmpty()) { + // PYSIDE-198: Use PyObject_GetAttr instead of PepFunction_GetName to support Nuitka. + AutoDecRef funcName(PyObject_GetAttr(callback, PyMagicName::name())); + data->slotData->name = String::toCString(funcName); + } const QByteArray returnType = QMetaObject::normalizedType(data->slotData->resultType); const QByteArray signature = returnType + ' ' + data->slotData->name + '(' + data->slotData->args + ')'; if (!pySlotName) - pySlotName = Shiboken::String::fromCString(PYSIDE_SLOT_LIST_ATTR); + pySlotName = String::fromCString(PYSIDE_SLOT_LIST_ATTR); - PyObject *pySignature = Shiboken::String::fromCString(signature); + PyObject *pySignature = String::fromCString(signature); PyObject *signatureList = 0; if (PyObject_HasAttr(callback, pySlotName)) { signatureList = PyObject_GetAttr(callback, pySlotName); -- cgit v1.2.3