summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2012-05-23 16:10:56 +0200
committerQt by Nokia <qt-info@nokia.com>2012-06-12 20:09:09 +0200
commit55c6f09b3af5900d9734817b5c4d7ea1920a2644 (patch)
treebee65d7acd27b9afbbd2346cff03a365f412af38 /src/corelib
parent6929fad9d9f98b43330c6d5a0d6b13b34fa90dc2 (diff)
Remove "delete value" from QSharedPointer
This allows a QSharedPointer to be used in contexts where the class in question is still forward-declared. This produced a warning in Qt 4 due to the expansion of the template, even if there was no chance of the pointer being deleted there (because the reference count could not drop to zero). Now, not only is the warning removed, but you can actually have the reference count drop to zero in a forward-declared class and it will do the right thing. That's because the deleter function is always recorded from the point of construction and we're sure that it wasn't forward-declared. The unit test for forward-declarations had to be rewritten. The previous version was passing only because the QSharedPointer object was created under the "tracking pointers" mode, which causes a custom deleter to be used in all cases. Task-number: QTBUG-25819 Change-Id: Ife37a4cea4551d94084b49ee03504dd39b8802c1 Reviewed-by: Lars Knoll <lars.knoll@nokia.com> Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/tools/qsharedpointer_impl.h34
1 files changed, 8 insertions, 26 deletions
diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h
index d1d660dfc7..289473514e 100644
--- a/src/corelib/tools/qsharedpointer_impl.h
+++ b/src/corelib/tools/qsharedpointer_impl.h
@@ -185,9 +185,7 @@ namespace QtSharedPointer {
virtual inline ~ExternalRefCountData() { Q_ASSERT(!weakref.load()); Q_ASSERT(strongref.load() <= 0); }
// overridden by derived classes
- // returns false to indicate caller should delete the pointer
- // returns true in case it has already done so
- virtual inline bool destroy() { return false; }
+ virtual inline void destroy() { }
#ifndef QT_NO_QOBJECT
Q_CORE_EXPORT static ExternalRefCountData *getAndRef(const QObject *);
@@ -210,7 +208,7 @@ namespace QtSharedPointer {
: destroyer(d)
{ }
- inline bool destroy() { destroyer(this); return true; }
+ inline void destroy() { destroyer(this); }
inline void operator delete(void *ptr) { ::operator delete(ptr); }
inline void operator delete(void *, void *) { }
};
@@ -327,31 +325,17 @@ namespace QtSharedPointer {
typedef ExternalRefCountData Data;
inline void deref()
- { deref(d, this->value); }
- static inline void deref(Data *d, T *value)
+ { deref(d); }
+ static inline void deref(Data *d)
{
if (!d) return;
if (!d->strongref.deref()) {
- if (!d->destroy())
- delete value;
+ d->destroy();
}
if (!d->weakref.deref())
delete d;
}
- inline void internalConstruct(T *ptr)
- {
-#ifdef QT_SHAREDPOINTER_TRACK_POINTERS
- internalConstruct<void (*)(T *)>(ptr, normalDeleter);
-#else
- if (ptr)
- d = new Data;
- else
- d = 0;
- internalFinishConstruction(ptr);
-#endif
- }
-
template <typename Deleter>
inline void internalConstruct(T *ptr, Deleter deleter)
{
@@ -381,8 +365,6 @@ namespace QtSharedPointer {
inline ExternalRefCount() : d(0) { }
inline ExternalRefCount(Qt::Initialization i) : Basic<T>(i) { }
- inline ExternalRefCount(T *ptr) : Basic<T>(Qt::Uninitialized) // throws
- { internalConstruct(ptr); }
template <typename Deleter>
inline ExternalRefCount(T *ptr, Deleter deleter) : Basic<T>(Qt::Uninitialized) // throws
{ internalConstruct(ptr, deleter); }
@@ -403,7 +385,7 @@ namespace QtSharedPointer {
other.ref();
qSwap(d, o);
qSwap(this->value, actual);
- deref(o, actual);
+ deref(o);
}
inline void internalSwap(ExternalRefCount &other)
@@ -448,7 +430,7 @@ namespace QtSharedPointer {
this->value = 0;
// dereference saved data
- deref(o, actual);
+ deref(o);
}
Data *d;
@@ -463,7 +445,7 @@ public:
inline QSharedPointer() { }
// inline ~QSharedPointer() { }
- inline explicit QSharedPointer(T *ptr) : BaseClass(ptr) // throws
+ inline explicit QSharedPointer(T *ptr) : BaseClass(ptr, &QtSharedPointer::normalDeleter<T>) // throws
{ }
template <typename Deleter>