diff options
author | Volker Krause <volker.krause@kdab.com> | 2014-04-15 13:11:40 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-04-15 17:50:20 +0200 |
commit | d953d9a4c3bdc5ed3b8d380c4b893b51b523bc50 (patch) | |
tree | b67db3a09a37be745f060de11a4c110eb7e9aee1 /src/corelib/kernel/qobject.cpp | |
parent | 78a1c46a86e205e599d641ffb3eae721705e0d1e (diff) |
Add a more reliable replacement for qt_add/removeObject().
These hooks only worked reliably with LD_PRELOAD on Linux/GCC, on other
platforms they depended on what exactly the compiler optimizer is doing
as well as some nasty assembler rewriting to actually access them. The
new system uses a simple array of function pointers that can be set to
custom hooks by tools that need this (based on ideas from Andre Poenitz).
This also covers qt_startup_hook (similar problem), and the Qt version
number that Andre had asked for.
Change-Id: I2c3e7950fd49b1b1d04176be34c2fff3293981b0
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Diffstat (limited to 'src/corelib/kernel/qobject.cpp')
-rw-r--r-- | src/corelib/kernel/qobject.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index 01bedb4a3a..0184e9a9e7 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -63,6 +63,7 @@ #include <qsharedpointer.h> #include <private/qorderedmutexlocker_p.h> +#include <private/qhooks_p.h> #include <new> @@ -138,6 +139,7 @@ static inline QMutex *signalSlotLock(const QObject *o) uint(quintptr(o)) % sizeof(_q_ObjectMutexPool)/sizeof(QBasicMutex)]); } +// ### Qt >= 5.6, remove qt_add/removeObject extern "C" Q_CORE_EXPORT void qt_addObject(QObject *) {} @@ -820,6 +822,8 @@ QObject::QObject(QObject *parent) } } qt_addObject(this); + if (Q_UNLIKELY(qtHookData[QHooks::AddQObject])) + reinterpret_cast<QHooks::AddQObjectCallback>(qtHookData[QHooks::AddQObject])(this); } /*! @@ -851,6 +855,8 @@ QObject::QObject(QObjectPrivate &dd, QObject *parent) } } qt_addObject(this); + if (Q_UNLIKELY(qtHookData[QHooks::AddQObject])) + reinterpret_cast<QHooks::AddQObjectCallback>(qtHookData[QHooks::AddQObject])(this); } /*! @@ -1028,6 +1034,8 @@ QObject::~QObject() d->deleteChildren(); qt_removeObject(this); + if (Q_UNLIKELY(qtHookData[QHooks::RemoveQObject])) + reinterpret_cast<QHooks::RemoveQObjectCallback>(qtHookData[QHooks::RemoveQObject])(this); if (d->parent) // remove it from parent object d->setParent_helper(0); |