aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/libpyside/pysideslot.cpp
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2021-12-08 17:29:27 +0100
committerChristian Tismer <tismer@stackless.com>2021-12-09 08:51:18 +0100
commitbd1ad4d23d18132446a936841dc82e444e8e240d (patch)
tree0ab878e96bf5ab2e9208104507753f46a6d97bd0 /sources/pyside6/libpyside/pysideslot.cpp
parent2c2d5c4566cfbf09d21a61d1495e9eefac3146a9 (diff)
PySide6: Fix a bug in Slot.__call__
While trying to improve MyPy compatibility, a test of Slot()() revealed a missing argument check. The function was also modernized a bit. Task-number: PYSIDE-1675 Change-Id: I0d06931a1dd92b9e55b5bd6e50569c77f6223a4e Pick-to: 6.2 5.15 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/pyside6/libpyside/pysideslot.cpp')
-rw-r--r--sources/pyside6/libpyside/pysideslot.cpp11
1 files changed, 6 insertions, 5 deletions
diff --git a/sources/pyside6/libpyside/pysideslot.cpp b/sources/pyside6/libpyside/pysideslot.cpp
index c20945066..e9fa02abb 100644
--- a/sources/pyside6/libpyside/pysideslot.cpp
+++ b/sources/pyside6/libpyside/pysideslot.cpp
@@ -133,11 +133,13 @@ int slotTpInit(PyObject *self, PyObject *args, PyObject *kw)
PyObject *slotCall(PyObject *self, PyObject *args, PyObject * /* kw */)
{
static PyObject *pySlotName = nullptr;
- PyObject *callback;
- callback = PyTuple_GetItem(args, 0);
+ PyObject *callback = nullptr;
+
+ if (!PyArg_UnpackTuple(args, "Slot.__call__", 1, 1, &callback))
+ return nullptr;
Py_INCREF(callback);
- if (Py_TYPE(callback)->tp_call != nullptr) {
+ if (PyCallable_Check(callback)) {
PySideSlot *data = reinterpret_cast<PySideSlot *>(self);
if (!data->slotData)
@@ -146,7 +148,7 @@ PyObject *slotCall(PyObject *self, PyObject *args, PyObject * /* kw */)
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);
+ data->slotData->name = funcName.isNull() ? "<no name>" : String::toCString(funcName);
}
const QByteArray returnType = QMetaObject::normalizedType(data->slotData->resultType);
const QByteArray signature =
@@ -171,7 +173,6 @@ PyObject *slotCall(PyObject *self, PyObject *args, PyObject * /* kw */)
//clear data
delete data->slotData;
data->slotData = nullptr;
- return callback;
}
return callback;
}