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 internalSafetyCheckAdd call. This is actually a noop change in 5.0, as setQObjectShared does nothing. However it prevents a bug in case the Qt 4 behaviour is brought back in some later version. Change-Id: I71340d0f878828354537762d01c46d441efc918c Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
0680627d7f
commit
20993adffd
@ -387,10 +387,10 @@ public:
|
|||||||
|
|
||||||
// now initialize the data
|
// now initialize the data
|
||||||
new (result.data()) T();
|
new (result.data()) T();
|
||||||
result.d->setQObjectShared(result.value, true);
|
|
||||||
# ifdef QT_SHAREDPOINTER_TRACK_POINTERS
|
# ifdef QT_SHAREDPOINTER_TRACK_POINTERS
|
||||||
internalSafetyCheckAdd(result.d, result.value);
|
internalSafetyCheckAdd(result.d, result.value);
|
||||||
# endif
|
# endif
|
||||||
|
result.d->setQObjectShared(result.value, true);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -425,10 +425,10 @@ private:
|
|||||||
# endif
|
# endif
|
||||||
d = Private::create(ptr, deleter, actualDeleter);
|
d = Private::create(ptr, deleter, actualDeleter);
|
||||||
|
|
||||||
d->setQObjectShared(ptr, true);
|
|
||||||
#ifdef QT_SHAREDPOINTER_TRACK_POINTERS
|
#ifdef QT_SHAREDPOINTER_TRACK_POINTERS
|
||||||
internalSafetyCheckAdd(d, ptr);
|
internalSafetyCheckAdd(d, ptr);
|
||||||
#endif
|
#endif
|
||||||
|
d->setQObjectShared(ptr, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class X>
|
template <class X>
|
||||||
|
@ -1760,6 +1760,13 @@ void tst_QSharedPointer::invalidConstructs_data()
|
|||||||
"QSharedPointer<Data> ptr1 = QSharedPointer<Data>(aData);\n"
|
"QSharedPointer<Data> ptr1 = QSharedPointer<Data>(aData);\n"
|
||||||
"QSharedPointer<Data> ptr2 = 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:
|
// re-creation:
|
||||||
QTest::newRow("re-creation")
|
QTest::newRow("re-creation")
|
||||||
<< &QTest::QExternalTest::tryRunFail
|
<< &QTest::QExternalTest::tryRunFail
|
||||||
|
Loading…
x
Reference in New Issue
Block a user