QMetaObject: port invokeMethodImpl() from QScopeGuard to SlotObjUniquePtr

... so it can use the new QMetaCallEvent() ctors taking that type.

As a consequence, the slot object ref-count is now no longer touched
on the way into the meta-call event (was: upped in QMetaCallEvent
ctor, then downed in QScopeGuard).

Manual conflict resolutions:
 - QScopeGuard -> custom Holder struct

Change-Id: Id9bd157792458a3834809c23e94ca5f504f7abd1
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit 4015f81d31d783549bfe0bd26ab1504789e056fe)
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
Marc Mutz 2023-07-19 14:49:08 +02:00
parent 4395e1e06b
commit 5078becc41

View File

@ -1611,13 +1611,10 @@ bool QMetaObject::invokeMethodImpl(QObject *obj, const char *member, Qt::Connect
return printMethodNotFoundWarning(obj->metaObject(), name, paramCount, typeNames, metaTypes);
}
bool QMetaObject::invokeMethodImpl(QObject *object, QtPrivate::QSlotObjectBase *slot, Qt::ConnectionType type, void *ret)
bool QMetaObject::invokeMethodImpl(QObject *object, QtPrivate::QSlotObjectBase *slotObj,
Qt::ConnectionType type, void *ret)
{
struct Holder {
QtPrivate::QSlotObjectBase *obj;
~Holder() { obj->destroyIfLastRef(); }
} holder = { slot };
Q_UNUSED(holder);
auto slot = QtPrivate::SlotObjUniquePtr(slotObj);
if (! object)
return false;
@ -1642,14 +1639,14 @@ bool QMetaObject::invokeMethodImpl(QObject *object, QtPrivate::QSlotObjectBase *
return false;
}
QCoreApplication::postEvent(object, new QMetaCallEvent(slot, nullptr, -1, 1));
QCoreApplication::postEvent(object, new QMetaCallEvent(std::move(slot), nullptr, -1, 1));
} else if (type == Qt::BlockingQueuedConnection) {
#if QT_CONFIG(thread)
if (receiverInSameThread)
qWarning("QMetaObject::invokeMethod: Dead lock detected");
QSemaphore semaphore;
QCoreApplication::postEvent(object, new QMetaCallEvent(slot, nullptr, -1, argv, &semaphore));
QCoreApplication::postEvent(object, new QMetaCallEvent(std::move(slot), nullptr, -1, argv, &semaphore));
semaphore.acquire();
#endif // QT_CONFIG(thread)
} else {