summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2012-08-16 16:06:16 (GMT)
committerQt by Nokia <qt-info@nokia.com>2012-08-27 10:14:39 (GMT)
commit1b3a74e74237d004527c3f296b7ec65365be0f25 (patch)
treeac3e60c021c8cdf838f8d0abe52c1bcf46fb0174
parent7982f6ad2703e13edbf80d55e537871bf1cd548d (diff)
downloadQt-1b3a74e74237d004527c3f296b7ec65365be0f25.zip
Qt-1b3a74e74237d004527c3f296b7ec65365be0f25.tar.gz
Qt-1b3a74e74237d004527c3f296b7ec65365be0f25.tar.bz2
QSharedPointer: make QT_SHAREDPOINTER_TRACK_POINTERS work with QObjects
If setQObjectShared crashes because a QObject is tracked by two different QSharedPointers, we lose the debug feature offered by #defining QT_SHAREDPOINTER_TRACK_POINTERS, as the check done by this define happens after the setQObjectShared call. Therefore, move setQObjectShared after the internalSafetyCheckAdd2 call. This way, the error raised by QSharedPointer created changes from f.i. QSharedPointer: pointer 0xa10010 already has reference counting to the more "debuggable" (and consistent with non-QObjects) QSharedPointer: internal self-check failed: pointer 0x1dd90e0 was already tracked by another QSharedPointer object 0x1dd9330 "Backport" of change-id I71340d0f878828354537762d01c46d441efc918c from qtbase (although, as of commit 609b0a9c2e69180ceff5d89c42e0d9468491d7e3, this issue is not present there, as setQObjectShared does nothing). Change-Id: I4cea83d705795eae0e05da128a3f189aea36f5ce Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r--src/corelib/tools/qsharedpointer_impl.h2
-rw-r--r--tests/auto/qsharedpointer/tst_qsharedpointer.cpp7
2 files changed, 8 insertions, 1 deletions
diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h
index 4216456..95864a1 100644
--- a/src/corelib/tools/qsharedpointer_impl.h
+++ b/src/corelib/tools/qsharedpointer_impl.h
@@ -378,10 +378,10 @@ namespace QtSharedPointer {
inline void internalFinishConstruction(T *ptr)
{
Basic<T>::internalConstruct(ptr);
- if (ptr) d->setQObjectShared(ptr, true);
#ifdef QT_SHAREDPOINTER_TRACK_POINTERS
if (ptr) internalSafetyCheckAdd2(d, ptr);
#endif
+ if (ptr) d->setQObjectShared(ptr, true);
}
inline ExternalRefCount() : d(0) { }
diff --git a/tests/auto/qsharedpointer/tst_qsharedpointer.cpp b/tests/auto/qsharedpointer/tst_qsharedpointer.cpp
index 452e658..54fe65e 100644
--- a/tests/auto/qsharedpointer/tst_qsharedpointer.cpp
+++ b/tests/auto/qsharedpointer/tst_qsharedpointer.cpp
@@ -1755,6 +1755,13 @@ void tst_QSharedPointer::invalidConstructs_data()
"QSharedPointer<Data> ptr1 = QSharedPointer<Data>(aData);\n"
"QSharedPointer<Data> ptr2 = QSharedPointer<Data>(aData);\n";
+ // two QObjects with the same pointer
+ QTest::newRow("same-pointer-to-qobject")
+ << &QTest::QExternalTest::tryRunFail
+ << "QObject *anObj = new QObject;\n"
+ "QSharedPointer<QObject> ptr1 = QSharedPointer<QObject>(anObj);\n"
+ "QSharedPointer<QObject> ptr2 = QSharedPointer<QObject>(anObj);\n";
+
// re-creation:
QTest::newRow("re-creation")
<< &QTest::QExternalTest::tryRunFail