diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/corelib/kernel/qobject.cpp | 93 | ||||
| -rw-r--r-- | src/corelib/kernel/qobject_p.h | 38 |
2 files changed, 21 insertions, 110 deletions
diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index 47d07970866..7276c438448 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -484,7 +484,7 @@ QAbstractMetaCallEvent::~QAbstractMetaCallEvent() /*! \internal */ -inline void QMetaCallEvent::allocArgs() +inline void QQueuedMetaCallEvent::allocArgs() { if (!d.nargs_) return; @@ -508,8 +508,7 @@ QMetaCallEvent::QMetaCallEvent(ushort method_offset, ushort method_relative, const QObject *sender, int signalId, void **args, QLatch *latch) : QAbstractMetaCallEvent(sender, signalId, latch), - d({nullptr, args, callFunction, 0, method_offset, method_relative}), - prealloc_() + d{nullptr, args, callFunction, 0, method_offset, method_relative} { } @@ -523,8 +522,7 @@ QMetaCallEvent::QMetaCallEvent(QtPrivate::QSlotObjectBase *slotO, const QObject *sender, int signalId, void **args, QLatch *latch) : QAbstractMetaCallEvent(sender, signalId, latch), - d({QtPrivate::SlotObjUniquePtr{slotO}, args, nullptr, 0, 0, ushort(-1)}), - prealloc_() + d{QtPrivate::SlotObjUniquePtr{slotO}, args, nullptr, 0, 0, ushort(-1)} { if (d.slotObj_) d.slotObj_->ref(); @@ -540,60 +538,8 @@ QMetaCallEvent::QMetaCallEvent(QtPrivate::SlotObjUniquePtr slotO, const QObject *sender, int signalId, void **args, QLatch *latch) : QAbstractMetaCallEvent(sender, signalId, latch), - d{std::move(slotO), args, nullptr, 0, 0, ushort(-1)}, - prealloc_() -{ -} - -/*! - \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(ushort method_offset, ushort method_relative, - QObjectPrivate::StaticMetaCallFunction callFunction, - const QObject *sender, int signalId, - int nargs) - : QAbstractMetaCallEvent(sender, signalId), - d({nullptr, nullptr, callFunction, nargs, method_offset, method_relative}), - prealloc_() -{ - 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::QSlotObjectBase *slotO, - const QObject *sender, int signalId, - int nargs) - : QAbstractMetaCallEvent(sender, signalId), - d({QtPrivate::SlotObjUniquePtr(slotO), nullptr, nullptr, nargs, 0, ushort(-1)}), - prealloc_() -{ - if (d.slotObj_) - d.slotObj_->ref(); - 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_() + d{std::move(slotO), args, nullptr, 0, 0, ushort(-1)} { - allocArgs(); } /*! @@ -601,20 +547,8 @@ QMetaCallEvent::QMetaCallEvent(QtPrivate::SlotObjUniquePtr slotO, */ QMetaCallEvent::QMetaCallEvent(const QObject *sender, int signalId, Data &&data) : QAbstractMetaCallEvent(sender, signalId), - d(std::move(data)), - prealloc_() -{ -} - -/*! - \internal - */ -QMetaCallEvent::~QMetaCallEvent() + d(std::move(data)) { - if (d.nargs_) { - if (reinterpret_cast<void *>(d.args_) != reinterpret_cast<void *>(prealloc_)) - free(d.args_); - } } /*! @@ -643,7 +577,8 @@ QQueuedMetaCallEvent::QQueuedMetaCallEvent(ushort method_offset, ushort method_r const QtPrivate::QMetaTypeInterface * const *argTypes, const void * const *argValues) : QMetaCallEvent(sender, signalId, {nullptr, nullptr, callFunction, argCount, - method_offset, method_relative}) + method_offset, method_relative}), + prealloc_() { allocArgs(); copyArgValues(argCount, argTypes, argValues); @@ -659,7 +594,8 @@ QQueuedMetaCallEvent::QQueuedMetaCallEvent(QtPrivate::QSlotObjectBase *slotObj, const QtPrivate::QMetaTypeInterface * const *argTypes, const void * const *argValues) : QMetaCallEvent(sender, signalId, {QtPrivate::SlotObjUniquePtr(slotObj), nullptr, nullptr, argCount, - 0, ushort(-1)}) + 0, ushort(-1)}), + prealloc_() { if (d.slotObj_) d.slotObj_->ref(); @@ -677,7 +613,8 @@ QQueuedMetaCallEvent::QQueuedMetaCallEvent(QtPrivate::SlotObjUniquePtr slotObj, const QtPrivate::QMetaTypeInterface * const *argTypes, const void * const *argValues) : QMetaCallEvent(sender, signalId, {std::move(slotObj), nullptr, nullptr, argCount, - 0, ushort(-1)}) + 0, ushort(-1)}), + prealloc_() { allocArgs(); copyArgValues(argCount, argTypes, argValues); @@ -688,7 +625,7 @@ QQueuedMetaCallEvent::QQueuedMetaCallEvent(QtPrivate::SlotObjUniquePtr slotObj, */ QQueuedMetaCallEvent::~QQueuedMetaCallEvent() { - const QMetaType *t = types(); + const QMetaType *t = reinterpret_cast<QMetaType *>(d.args_ + d.nargs_); int inplaceIndex = 0; for (int i = 0; i < d.nargs_; ++i) { if (t[i].isValid() && d.args_[i]) { @@ -702,6 +639,10 @@ QQueuedMetaCallEvent::~QQueuedMetaCallEvent() } } } + if (d.nargs_) { + if (reinterpret_cast<void *>(d.args_) != reinterpret_cast<void *>(prealloc_)) + free(d.args_); + } } /*! @@ -711,7 +652,7 @@ inline void QQueuedMetaCallEvent::copyArgValues(int argCount, const QtPrivate::Q const void * const *argValues) { void **args = d.args_; - QMetaType *types = this->types(); + QMetaType *types = reinterpret_cast<QMetaType *>(d.args_ + d.nargs_); int inplaceIndex = 0; types[0] = QMetaType(); // return type diff --git a/src/corelib/kernel/qobject_p.h b/src/corelib/kernel/qobject_p.h index 75aeba73583..be3e8f58f09 100644 --- a/src/corelib/kernel/qobject_p.h +++ b/src/corelib/kernel/qobject_p.h @@ -363,36 +363,9 @@ public: const QObject *sender, int signalId, void **args, QLatch *latch); - // OLD - queued - args allocated by event, copied by caller - Q_DECL_DEPRECATED_X("Remove this constructor once the qtdeclarative patch is merged. Arguments are now copied by the QQueuedMetaCallEvent constructor and not the caller.") - QMetaCallEvent(ushort method_offset, ushort method_relative, - QObjectPrivate::StaticMetaCallFunction callFunction, - const QObject *sender, int signalId, - int nargs); - Q_DECL_DEPRECATED_X("Remove this constructor once the qtdeclarative patch is merged. Arguments are now copied by the QQueuedMetaCallEvent constructor and not the caller.") - QMetaCallEvent(QtPrivate::QSlotObjectBase *slotObj, - const QObject *sender, int signalId, - int nargs); - Q_DECL_DEPRECATED_X("Remove this constructor once the qtdeclarative patch is merged. Arguments are now copied by the QQueuedMetaCallEvent constructor and not the caller.") - QMetaCallEvent(QtPrivate::SlotObjUniquePtr slotObj, - const QObject *sender, int signalId, - int nargs); - - ~QMetaCallEvent() override; - - inline int id() const { return d.method_offset_ + d.method_relative_; } - Q_DECL_DEPRECATED_X("Remove this function once the qtdeclarative patch is merged. Arguments are now copied by the QQueuedMetaCallEvent constructor and not the caller.") - inline void ** args() { return d.args_; } - Q_DECL_DEPRECATED_X("Remove this function once the qtdeclarative patch is merged. Arguments are now copied by the QQueuedMetaCallEvent constructor and not the caller.") - inline QMetaType *types() { return reinterpret_cast<QMetaType *>(d.args_ + d.nargs_); } - virtual void placeMetaCall(QObject *object) override; protected: - // Move to QQueuedMetaCallEvent once the qtdeclarative patch is merged. - // QMetaCallEvent should not alloc anything anymore. - inline void allocArgs(); - struct Data { QtPrivate::SlotObjUniquePtr slotObj_; void **args_; @@ -403,13 +376,6 @@ protected: } d; inline QMetaCallEvent(const QObject *sender, int signalId, Data &&data); - inline void * const *args() const { return d.args_; } - inline QMetaType const *types() const { return reinterpret_cast<QMetaType *>(d.args_ + d.nargs_); } - - // Space for 5 argument pointers and types (including 1 return arg). - // Contiguous so that we can make one calloc() for both the pointers and the types when necessary. - // Move to QQueuedMetaCallEvent once the qtdeclarative patch is merged. - alignas(void *) char prealloc_[5 * sizeof(void *) + 5 * sizeof(QMetaType)]; }; class Q_CORE_EXPORT QQueuedMetaCallEvent : public QMetaCallEvent @@ -433,10 +399,14 @@ public: ~QQueuedMetaCallEvent() override; private: + inline void allocArgs(); inline void copyArgValues(int argCount, const QtPrivate::QMetaTypeInterface * const *argTypes, const void * const *argValues); static inline bool typeFitsInPlace(const QMetaType type); + // Space for 5 argument pointers and types (including 1 return arg). + // Contiguous so that we can make one calloc() for both the pointers and the types when necessary. + alignas(void *) char prealloc_[5 * sizeof(void *) + 5 * sizeof(QMetaType)]; struct ArgValueStorage { // size and alignment matching QString, QList, etc static constexpr size_t MaxSize = 3 * sizeof(void *); alignas(void *) char storage[MaxSize]; |
