QMetaCallEvent: add ctors and create() overloads taking SlotObjUniquePtr
This makes it clear who is responsible for obtaining additional strong reference to the slot objects, because these functions no longer do. Pick-to: 6.6 6.5 Change-Id: I39187e3c441d8f82d50d907731f1cbdfb2a95b9d Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
e60aed5ed0
commit
00dbd3cd26
@ -559,6 +559,21 @@ QMetaCallEvent::QMetaCallEvent(QtPrivate::QSlotObjectBase *slotO,
|
||||
d.slotObj_->ref();
|
||||
}
|
||||
|
||||
/*!
|
||||
\internal
|
||||
|
||||
Used for blocking queued connections, just passes \a args through without
|
||||
allocating any memory.
|
||||
*/
|
||||
QMetaCallEvent::QMetaCallEvent(QtPrivate::SlotObjUniquePtr slotO,
|
||||
const QObject *sender, int signalId,
|
||||
void **args, QSemaphore *semaphore)
|
||||
: QAbstractMetaCallEvent(sender, signalId, semaphore),
|
||||
d{std::move(slotO), args, nullptr, 0, 0, ushort(-1)},
|
||||
prealloc_()
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
\internal
|
||||
|
||||
@ -594,6 +609,22 @@ QMetaCallEvent::QMetaCallEvent(QtPrivate::QSlotObjectBase *slotO,
|
||||
allocArgs();
|
||||
}
|
||||
|
||||
/*!
|
||||
\internal
|
||||
|
||||
Allocates memory for \a nargs; code creating an event needs to initialize
|
||||
the void* and int arrays by accessing \a args() and \a types(), respectively.
|
||||
*/
|
||||
QMetaCallEvent::QMetaCallEvent(QtPrivate::SlotObjUniquePtr slotO,
|
||||
const QObject *sender, int signalId,
|
||||
int nargs)
|
||||
: QAbstractMetaCallEvent(sender, signalId),
|
||||
d{std::move(slotO), nullptr, nullptr, nargs, 0, ushort(-1)},
|
||||
prealloc_()
|
||||
{
|
||||
allocArgs();
|
||||
}
|
||||
|
||||
/*!
|
||||
\internal
|
||||
*/
|
||||
@ -625,12 +656,12 @@ void QMetaCallEvent::placeMetaCall(QObject *object)
|
||||
}
|
||||
}
|
||||
|
||||
QMetaCallEvent* QMetaCallEvent::create_impl(QtPrivate::QSlotObjectBase *slotObj,
|
||||
QMetaCallEvent* QMetaCallEvent::create_impl(QtPrivate::SlotObjUniquePtr slotObj,
|
||||
const QObject *sender, int signal_index,
|
||||
size_t argc, const void* const argp[],
|
||||
const QMetaType metaTypes[])
|
||||
{
|
||||
auto metaCallEvent = std::make_unique<QMetaCallEvent>(slotObj, sender,
|
||||
auto metaCallEvent = std::make_unique<QMetaCallEvent>(std::move(slotObj), sender,
|
||||
signal_index, int(argc));
|
||||
|
||||
void **args = metaCallEvent->args();
|
||||
|
@ -375,6 +375,9 @@ public:
|
||||
QMetaCallEvent(QtPrivate::QSlotObjectBase *slotObj,
|
||||
const QObject *sender, int signalId,
|
||||
void **args, QSemaphore *semaphore);
|
||||
QMetaCallEvent(QtPrivate::SlotObjUniquePtr slotObj,
|
||||
const QObject *sender, int signalId,
|
||||
void **args, QSemaphore *semaphore);
|
||||
|
||||
// queued - args allocated by event, copied by caller
|
||||
QMetaCallEvent(ushort method_offset, ushort method_relative,
|
||||
@ -384,6 +387,9 @@ public:
|
||||
QMetaCallEvent(QtPrivate::QSlotObjectBase *slotObj,
|
||||
const QObject *sender, int signalId,
|
||||
int nargs);
|
||||
QMetaCallEvent(QtPrivate::SlotObjUniquePtr slotObj,
|
||||
const QObject *sender, int signalId,
|
||||
int nargs);
|
||||
|
||||
~QMetaCallEvent() override;
|
||||
|
||||
@ -396,6 +402,15 @@ public:
|
||||
constexpr auto argc = sizeof...(Args) + 1;
|
||||
return create_impl(slotObj, sender, signal_index, argc, argp, metaTypes);
|
||||
}
|
||||
template<typename ...Args>
|
||||
static QMetaCallEvent *create(QtPrivate::SlotObjUniquePtr slotObj, const QObject *sender,
|
||||
int signal_index, const Args &...argv)
|
||||
{
|
||||
const void* const argp[] = { nullptr, std::addressof(argv)... };
|
||||
const QMetaType metaTypes[] = { QMetaType::fromType<void>(), QMetaType::fromType<Args>()... };
|
||||
constexpr auto argc = sizeof...(Args) + 1;
|
||||
return create_impl(std::move(slotObj), sender, signal_index, argc, argp, metaTypes);
|
||||
}
|
||||
|
||||
inline int id() const { return d.method_offset_ + d.method_relative_; }
|
||||
inline const void * const* args() const { return d.args_; }
|
||||
@ -407,6 +422,15 @@ public:
|
||||
|
||||
private:
|
||||
static QMetaCallEvent *create_impl(QtPrivate::QSlotObjectBase *slotObj, const QObject *sender,
|
||||
int signal_index, size_t argc, const void * const argp[],
|
||||
const QMetaType metaTypes[])
|
||||
{
|
||||
if (slotObj)
|
||||
slotObj->ref();
|
||||
return create_impl(QtPrivate::SlotObjUniquePtr{slotObj}, sender,
|
||||
signal_index, argc, argp, metaTypes);
|
||||
}
|
||||
static QMetaCallEvent *create_impl(QtPrivate::SlotObjUniquePtr slotObj, const QObject *sender,
|
||||
int signal_index, size_t argc, const void * const argp[],
|
||||
const QMetaType metaTypes[]);
|
||||
inline void allocArgs();
|
||||
|
Loading…
Reference in New Issue
Block a user