From 1b3a74e74237d004527c3f296b7ec65365be0f25 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Thu, 16 Aug 2012 17:06:16 +0100 Subject: 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 --- src/corelib/tools/qsharedpointer_impl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/corelib/tools') diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h index 4216456c1c..95864a1cc6 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::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) { } -- cgit v1.2.3