summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools
diff options
context:
space:
mode:
authorHarald Fernengel <harald@trolltech.com>2009-08-03 13:12:46 (GMT)
committerHarald Fernengel <harald@trolltech.com>2009-08-03 13:12:46 (GMT)
commit41a83e1ff19ad1396e6001e6b0ac003c701ba55a (patch)
tree609e40eda10418bbf925002c36552074796b96b6 /src/corelib/tools
parentd1f3b9df2bc5c57d414da73a7d4f9ed7b25df3db (diff)
downloadQt-41a83e1ff19ad1396e6001e6b0ac003c701ba55a.zip
Qt-41a83e1ff19ad1396e6001e6b0ac003c701ba55a.tar.gz
Qt-41a83e1ff19ad1396e6001e6b0ac003c701ba55a.tar.bz2
Squashed commit of the topic/exceptions branch.
Contains some smaller fixes and renaming of macros. Looks big, but isn't scary at all ;)
Diffstat (limited to 'src/corelib/tools')
-rw-r--r--src/corelib/tools/qbytearray.cpp1
-rw-r--r--src/corelib/tools/qhash.h13
-rw-r--r--src/corelib/tools/qlist.h23
-rw-r--r--src/corelib/tools/qlistdata.cpp40
-rw-r--r--src/corelib/tools/qlocale.cpp17
-rw-r--r--src/corelib/tools/qlocale_symbian.cpp16
-rw-r--r--src/corelib/tools/qregexp.cpp10
-rw-r--r--src/corelib/tools/qringbuffer_p.h7
-rw-r--r--src/corelib/tools/qscopedpointer.cpp38
-rw-r--r--src/corelib/tools/qscopedpointer.h118
-rw-r--r--src/corelib/tools/qstring.cpp9
-rw-r--r--src/corelib/tools/qtimeline.h2
12 files changed, 207 insertions, 87 deletions
diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp
index 22cee0e..97f437f 100644
--- a/src/corelib/tools/qbytearray.cpp
+++ b/src/corelib/tools/qbytearray.cpp
@@ -1307,6 +1307,7 @@ QByteArray::QByteArray(int size, char ch)
QByteArray::QByteArray(int size, Qt::Initialization)
{
d = static_cast<Data *>(qMalloc(sizeof(Data)+size));
+ Q_CHECK_PTR(d);
d->ref = 1;
d->alloc = d->size = size;
d->data = d->array;
diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h
index d1a3386..fc6a1e3a 100644
--- a/src/corelib/tools/qhash.h
+++ b/src/corelib/tools/qhash.h
@@ -167,8 +167,13 @@ inline bool QHashData::willGrow()
inline void QHashData::hasShrunk()
{
- if (size <= (numBuckets >> 3) && numBits > userNumBits)
- rehash(qMax(int(numBits) - 2, int(userNumBits)));
+ if (size <= (numBuckets >> 3) && numBits > userNumBits) {
+ QT_TRY {
+ rehash(qMax(int(numBits) - 2, int(userNumBits)));
+ } QT_CATCH(const std::bad_alloc &) {
+ // ignore bad allocs - shrinking shouldn't throw. rehash is exception safe.
+ }
+ }
}
inline QHashData::Node *QHashData::firstNode()
@@ -761,6 +766,8 @@ Q_INLINE_TEMPLATE typename QHash<Key, T>::iterator QHash<Key, T>::insertMulti(co
template <class Key, class T>
Q_OUTOFLINE_TEMPLATE int QHash<Key, T>::remove(const Key &akey)
{
+ if (isEmpty()) // prevents detaching shared null
+ return 0;
detach();
int oldSize = d->size;
@@ -782,6 +789,8 @@ Q_OUTOFLINE_TEMPLATE int QHash<Key, T>::remove(const Key &akey)
template <class Key, class T>
Q_OUTOFLINE_TEMPLATE T QHash<Key, T>::take(const Key &akey)
{
+ if (isEmpty()) // prevents detaching shared null
+ return T();
detach();
Node **node = findNode(akey);
diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h
index a56518b..c6c898d 100644
--- a/src/corelib/tools/qlist.h
+++ b/src/corelib/tools/qlist.h
@@ -363,15 +363,16 @@ Q_INLINE_TEMPLATE void QList<T>::node_copy(Node *from, Node *to, Node *src)
Node *current = from;
if (QTypeInfo<T>::isLarge || QTypeInfo<T>::isStatic) {
QT_TRY {
- while(current != to)
+ while(current != to) {
(current++)->v = new T(*reinterpret_cast<T*>((src++)->v));
+ }
} QT_CATCH(...) {
while (current != from)
delete reinterpret_cast<T*>(current--);
QT_RETHROW;
}
- }
- else if (QTypeInfo<T>::isComplex) {
+
+ } else if (QTypeInfo<T>::isComplex) {
QT_TRY {
while(current != to)
new (current++) T(*reinterpret_cast<T*>(src++));
@@ -380,6 +381,9 @@ Q_INLINE_TEMPLATE void QList<T>::node_copy(Node *from, Node *to, Node *src)
(reinterpret_cast<T*>(current--))->~T();
QT_RETHROW;
}
+ } else {
+ if (src != from && to - from > 0)
+ memcpy(from, src, (to - from) * sizeof(Node *));
}
}
@@ -408,11 +412,12 @@ Q_INLINE_TEMPLATE QList<T> &QList<T>::operator=(const QList<T> &l)
template <typename T>
inline typename QList<T>::iterator QList<T>::insert(iterator before, const T &t)
{
- Node *n = reinterpret_cast<Node *>(p.insert(before.i - reinterpret_cast<Node *>(p.begin())));
+ int iBefore = before.i - reinterpret_cast<Node *>(p.begin());
+ Node *n = reinterpret_cast<Node *>(p.insert(iBefore));
QT_TRY {
node_construct(n, t);
} QT_CATCH(...) {
- p.remove(before.i - reinterpret_cast<Node *>(p.begin()));
+ p.remove(iBefore);
QT_RETHROW;
}
return n;
@@ -689,7 +694,13 @@ Q_OUTOFLINE_TEMPLATE QList<T> &QList<T>::operator+=(const QList<T> &l)
{
detach();
Node *n = reinterpret_cast<Node *>(p.append(l.p));
- node_copy(n, reinterpret_cast<Node *>(p.end()), reinterpret_cast<Node *>(l.p.begin()));
+ QT_TRY{
+ node_copy(n, reinterpret_cast<Node *>(p.end()), reinterpret_cast<Node *>(l.p.begin()));
+ } QT_CATCH(...) {
+ // restore the old end
+ d->end -= (reinterpret_cast<Node *>(p.end()) - n);
+ QT_RETHROW;
+ }
return *this;
}
diff --git a/src/corelib/tools/qlistdata.cpp b/src/corelib/tools/qlistdata.cpp
index 3c45bed..c67af7a 100644
--- a/src/corelib/tools/qlistdata.cpp
+++ b/src/corelib/tools/qlistdata.cpp
@@ -74,12 +74,16 @@ QListData::Data *QListData::detach()
Data *x = static_cast<Data *>(qMalloc(DataHeaderSize + d->alloc * sizeof(void *)));
Q_CHECK_PTR(x);
- ::memcpy(x, d, DataHeaderSize + d->alloc * sizeof(void *));
- x->alloc = d->alloc;
x->ref = 1;
x->sharable = true;
- if (!x->alloc)
- x->begin = x->end = 0;
+ x->alloc = d->alloc;
+ if (!x->alloc) {
+ x->begin = 0;
+ x->end = 0;
+ } else {
+ x->begin = d->begin;
+ x->end = d->end;
+ }
qSwap(d, x);
if (!x->ref.deref())
@@ -87,20 +91,30 @@ QListData::Data *QListData::detach()
return 0;
}
-// Returns the old (shared) data, it is up to the caller to deref() and free()
+/*!
+ * Detaches the QListData by reallocating new memory.
+ * Returns the old (shared) data, it is up to the caller to deref() and free()
+ * For the new data node_copy needs to be called.
+ *
+ * \internal
+ */
QListData::Data *QListData::detach2()
{
Data *x = d;
Data* t = static_cast<Data *>(qMalloc(DataHeaderSize + x->alloc * sizeof(void *)));
Q_CHECK_PTR(t);
+ t->ref = 1;
+ t->sharable = true;
+ t->alloc = x->alloc;
+ if (!t->alloc) {
+ t->begin = 0;
+ t->end = 0;
+ } else {
+ t->begin = x->begin;
+ t->end = x->end;
+ }
d = t;
- ::memcpy(d, x, DataHeaderSize + x->alloc * sizeof(void *));
- d->alloc = x->alloc;
- d->ref = 1;
- d->sharable = true;
- if (!d->alloc)
- d->begin = d->end = 0;
return x;
}
@@ -117,12 +131,14 @@ void QListData::realloc(int alloc)
d->begin = d->end = 0;
}
+// ensures that enough space is available to append one element
void **QListData::append()
{
Q_ASSERT(d->ref == 1);
if (d->end == d->alloc) {
int n = d->end - d->begin;
if (d->begin > 2 * d->alloc / 3) {
+ // we have enough space. Just not at the end -> move it.
::memcpy(d->array + n, d->array + d->begin, n * sizeof(void *));
d->begin = n;
d->end = n * 2;
@@ -133,6 +149,7 @@ void **QListData::append()
return d->array + d->end++;
}
+// ensures that enough space is available to append the list
void **QListData::append(const QListData& l)
{
Q_ASSERT(d->ref == 1);
@@ -141,7 +158,6 @@ void **QListData::append(const QListData& l)
if (n) {
if (e + n > d->alloc)
realloc(grow(e + l.d->end - l.d->begin));
- ::memcpy(d->array + d->end, l.d->array + l.d->begin, n * sizeof(void*));
d->end += n;
}
return d->array + e;
diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp
index 17634c1..a8fac2d 100644
--- a/src/corelib/tools/qlocale.cpp
+++ b/src/corelib/tools/qlocale.cpp
@@ -3943,7 +3943,13 @@ QString QLocalePrivate::doubleToString(double d,
char *rve = 0;
char *buff = 0;
- digits = QLatin1String(qdtoa(d, mode, pr, &decpt, &sign, &rve, &buff));
+ QT_TRY {
+ digits = QLatin1String(qdtoa(d, mode, pr, &decpt, &sign, &rve, &buff));
+ } QT_CATCH(...) {
+ if (buff != 0)
+ free(buff);
+ QT_RETHROW;
+ }
if (buff != 0)
free(buff);
#endif // QT_QLOCALE_USES_FCVT
@@ -6786,8 +6792,13 @@ static char *_qdtoa( NEEDS_VOLATILE double d, int mode, int ndigits, int *decpt,
if (i <= 0)
i = 1;
}
- *resultp = static_cast<char *>(malloc(i + 1));
- Q_CHECK_PTR(resultp);
+ QT_TRY {
+ *resultp = static_cast<char *>(malloc(i + 1));
+ Q_CHECK_PTR(*resultp);
+ } QT_CATCH(...) {
+ Bfree(b);
+ QT_RETHROW;
+ }
s = s0 = *resultp;
if (ilim >= 0 && ilim <= Quick_max && try_quick) {
diff --git a/src/corelib/tools/qlocale_symbian.cpp b/src/corelib/tools/qlocale_symbian.cpp
index 976227d..95d4edf 100644
--- a/src/corelib/tools/qlocale_symbian.cpp
+++ b/src/corelib/tools/qlocale_symbian.cpp
@@ -637,9 +637,9 @@ static QString symbianDayName(int day, bool short_format)
return QString();
if (short_format) {
- return qt_TDes2QStringL(TDayNameAbb(TDay(day)));
+ return qt_TDes2QString(TDayNameAbb(TDay(day)));
} else {
- return qt_TDes2QStringL(TDayName(TDay(day)));
+ return qt_TDes2QString(TDayName(TDay(day)));
}
}
@@ -655,9 +655,9 @@ static QString symbianMonthName(int month, bool short_format)
return QString();
if (short_format) {
- return qt_TDes2QStringL(TMonthNameAbb(TMonth(month)));
+ return qt_TDes2QString(TMonthNameAbb(TMonth(month)));
} else {
- return qt_TDes2QStringL(TMonthName(TMonth(month)));
+ return qt_TDes2QString(TMonthName(TMonth(month)));
}
}
@@ -678,7 +678,7 @@ static QString symbianDateFormat(bool short_format)
dateFormat.Set(ptrGetLongDateFormatSpec(_s60Locale));
}
- return s60ToQtFormat(qt_TDesC2QStringL(dateFormat));
+ return s60ToQtFormat(qt_TDesC2QString(dateFormat));
}
/*!
@@ -687,7 +687,7 @@ static QString symbianDateFormat(bool short_format)
*/
static QString symbianTimeFormat()
{
- return s60ToQtFormat(qt_TDesC2QStringL(ptrGetTimeFormatSpec(_s60Locale)));
+ return s60ToQtFormat(qt_TDesC2QString(ptrGetTimeFormatSpec(_s60Locale)));
}
/*!
@@ -719,7 +719,7 @@ static QString symbianDateToString(const QDate &date, bool short_format)
TRAPD(err, ptrTimeFormatL(timeStr, buffer, dateFormat, *_s60Locale.GetLocale());)
if (err == KErrNone)
- return qt_TDes2QStringL(buffer);
+ return qt_TDes2QString(buffer);
else
return QString();
}
@@ -749,7 +749,7 @@ static QString symbianTimeToString(const QTime &time)
)
if (err == KErrNone)
- return qt_TDes2QStringL(buffer);
+ return qt_TDes2QString(buffer);
else
return QString();
}
diff --git a/src/corelib/tools/qregexp.cpp b/src/corelib/tools/qregexp.cpp
index d7d347f..d980a9b 100644
--- a/src/corelib/tools/qregexp.cpp
+++ b/src/corelib/tools/qregexp.cpp
@@ -1216,7 +1216,7 @@ private:
int yyPos; // the position of the next character to read
int yyLen; // the length of yyIn
int yyCh; // the last character read
- QRegExpCharClass *yyCharClass; // attribute for Tok_CharClass tokens
+ QScopedPointer<QRegExpCharClass> yyCharClass; // attribute for Tok_CharClass tokens
int yyMinRep; // attribute for Tok_Quantifier
int yyMaxRep; // ditto
QString yyError; // syntax error or overflow during parsing?
@@ -1303,8 +1303,7 @@ void QRegExpMatchState::prepareForMatch(QRegExpEngine *eng)
#endif
int numCaptures = eng->numCaptures();
int newCapturedSize = 2 + 2 * numCaptures;
- bigArray = (int *)realloc(bigArray, ((3 + 4 * ncap) * ns + 4 * ncap + newSlideTabSize + newCapturedSize)*sizeof(int));
- Q_CHECK_PTR(bigArray);
+ bigArray = q_check_ptr((int *)realloc(bigArray, ((3 + 4 * ncap) * ns + 4 * ncap + newSlideTabSize + newCapturedSize)*sizeof(int)));
// set all internal variables only _after_ bigArray is realloc'ed
// to prevent a broken regexp in oom case
@@ -2795,7 +2794,7 @@ void QRegExpEngine::startTokenizer(const QChar *rx, int len)
yyPos = 0;
yyLen = len;
yyCh = getChar();
- yyCharClass = new QRegExpCharClass;
+ yyCharClass.reset(new QRegExpCharClass);
yyMinRep = 0;
yyMaxRep = 0;
yyError = QString();
@@ -2989,8 +2988,7 @@ int QRegExpEngine::parse(const QChar *pattern, int len)
#endif
box.cat(middleBox);
box.cat(rightBox);
- delete yyCharClass;
- yyCharClass = 0;
+ yyCharClass.reset(0);
#ifndef QT_NO_REGEXP_CAPTURE
for (int i = 0; i < nf; ++i) {
diff --git a/src/corelib/tools/qringbuffer_p.h b/src/corelib/tools/qringbuffer_p.h
index d8ca658..16368e9 100644
--- a/src/corelib/tools/qringbuffer_p.h
+++ b/src/corelib/tools/qringbuffer_p.h
@@ -245,12 +245,7 @@ public:
inline void clear() {
if(!buffers.isEmpty()) {
- QByteArray tmp = buffers[0];
- buffers.clear();
- buffers << tmp;
- //TODO merge this optimization ?
- //buffers.erase(buffers.begin() + 1, buffers.end());
- //>>>>>>> 08ae7ee1fb930e7d4b4039e2294cba69f9380964:src/corelib/tools/qringbuffer_p.h
+ buffers.erase(buffers.begin() + 1, buffers.end());
if (buffers.at(0).size() != basicBlockSize)
buffers[0].resize(basicBlockSize);
}
diff --git a/src/corelib/tools/qscopedpointer.cpp b/src/corelib/tools/qscopedpointer.cpp
index 912edb6..cf24381 100644
--- a/src/corelib/tools/qscopedpointer.cpp
+++ b/src/corelib/tools/qscopedpointer.cpp
@@ -39,6 +39,10 @@
**
****************************************************************************/
+#include "qscopedpointer.h"
+
+QT_BEGIN_NAMESPACE
+
/*!
\class QScopedPointer
\brief The QScopedPointer class stores a pointer to a dynamically allocated object, and deletes it upon destruction.
@@ -53,9 +57,7 @@
called resource acquisition is initialization(RAII).
QScopedPointer guarantees that the object pointed to will get deleted when
- the current scope dissapears, and it also has no way of releasing
- ownership, hence clearly communicating the lifetime and ownership of the
- object. These guarantees are convenient when reading the code.
+ the current scope dissapears.
Consider this function which does heap allocations, and have various exit points:
@@ -68,7 +70,7 @@
The code the compiler generates for QScopedPointer is the same as when
writing it manually. Code that makes use of \a delete are candidates for
- QScopedPointer usage(and if not, possibly another type of smart pointer
+ QScopedPointer usage (and if not, possibly another type of smart pointer
such as QSharedPointer). QScopedPointer intentionally has no copy
constructor or assignment operator, such that ownership and lifetime is
clearly communicated.
@@ -78,7 +80,26 @@
\snippet doc/src/snippets/code/src_corelib_tools_qscopedpointer.cpp 2
- \note QScopedPointer does not work with arrays.
+ \section1 Custom cleanup handlers
+
+ Arrays as well as pointers that have been allocated with \c malloc must
+ not be deleted using \c delete. QScopedPointer's second template parameter
+ can be used for custom cleanup handlers.
+
+ The following custom cleanup handlers exist:
+
+ \list
+ \i QScopedPointerDeleter - the default, deletes the pointer using \c delete
+ \i QScopedPointerArrayDeleter - deletes the pointer using \c{delete []}. Use
+ this handler for pointers that were allocated with \c{new []}.
+ \i QScopedPointerPodDeleter - deletes the pointer using \c{free()}. Use this
+ handler for pointers that were allocated with \c{malloc()}.
+ \endlist
+
+ You can pass your own classes as handlers, provided that they have a public
+ static function \c{void cleanup(T *pointer)}.
+
+ \snippet doc/src/snippets/code/src_corelib_tools_qscopedpointer.cpp 5
\section1 Forward Declared Pointers
@@ -175,9 +196,6 @@
Deletes the existing object it is pointing to if any, and sets its pointer to
\a other. QScopedPointer now owns \a other and will delete it in its
destructor.
-
- If \a other is equal to the value returned by data(), behavior is
- undefined.
*/
/*!
@@ -185,8 +203,8 @@
Returns the value of the pointer referenced by this object. The pointer of this
QScopedPointer object will be reset to \c null.
+
+ Callers of this function take ownership of the pointer.
*/
QT_END_NAMESPACE
-
-#endif
diff --git a/src/corelib/tools/qscopedpointer.h b/src/corelib/tools/qscopedpointer.h
index fc8f9e2..62daacb 100644
--- a/src/corelib/tools/qscopedpointer.h
+++ b/src/corelib/tools/qscopedpointer.h
@@ -49,8 +49,46 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Core)
template <typename T>
+struct QScopedPointerDeleter
+{
+ static inline void cleanup(T *pointer)
+ {
+ // Enforce a complete type.
+ // If you get a compile error here, read the secion on forward declared
+ // classes in the QScopedPointer documentation.
+ typedef char IsIncompleteType[ sizeof(T) ? 1 : -1 ];
+ (void) sizeof(IsIncompleteType);
+
+ delete pointer;
+ }
+};
+
+template <typename T>
+struct QScopedPointerArrayDeleter
+{
+ static inline void cleanup(T *pointer)
+ {
+ // Enforce a complete type.
+ // If you get a compile error here, read the secion on forward declared
+ // classes in the QScopedPointer documentation.
+ typedef char IsIncompleteType[ sizeof(T) ? 1 : -1 ];
+ (void) sizeof(IsIncompleteType);
+
+ delete [] pointer;
+ }
+};
+
+struct QScopedPointerPodDeleter
+{
+ static inline void cleanup(void *pointer) { if (pointer) qFree(pointer); }
+};
+
+template <typename T, typename Cleanup = QScopedPointerDeleter<T> >
class QScopedPointer
{
+#ifndef Q_CC_NOKIAX86
+ typedef T *QScopedPointer:: *RestrictedBool;
+#endif
public:
explicit inline QScopedPointer(T *p = 0) : d(p)
{
@@ -58,16 +96,20 @@ public:
inline ~QScopedPointer()
{
- delete d;
+ T *oldD = this->d;
+ Cleanup::cleanup(oldD);
+ this->d = 0;
}
inline T &operator*() const
{
+ Q_ASSERT(d);
return *d;
}
inline T *operator->() const
{
+ Q_ASSERT(d);
return d;
}
@@ -81,10 +123,17 @@ public:
return d != other.d;
}
+#if defined(Q_CC_NOKIAX86) || defined(Q_QDOC)
inline operator bool() const
{
- return d;
+ return isNull() ? 0 : &QScopedPointer::d;
+ }
+#else
+ inline operator RestrictedBool() const
+ {
+ return isNull() ? 0 : &QScopedPointer::d;
}
+#endif
inline T *data() const
{
@@ -98,9 +147,11 @@ public:
inline void reset(T *other = 0)
{
+ if (d == other)
+ return;
T *oldD = d;
d = other;
- delete oldD;
+ Cleanup::cleanup(oldD);
}
inline T *take()
@@ -117,37 +168,52 @@ private:
Q_DISABLE_COPY(QScopedPointer)
};
-/* internal class - allows special handling for resetting and cleaning the pointer */
-template <typename T, typename CustomHandler>
-class QScopedCustomPointer : public QScopedPointer<T>
+template <typename T, typename Cleanup = QScopedPointerArrayDeleter<T> >
+class QScopedArrayPointer : public QScopedPointer<T, Cleanup>
{
public:
- inline QScopedCustomPointer(T *p = 0)
- : QScopedPointer<T>(p)
+ explicit inline QScopedArrayPointer(T *p = 0)
+ : QScopedPointer<T, Cleanup>(p)
{
}
- inline ~QScopedCustomPointer()
+ inline T &operator[](int i)
{
- T *oldD = this->d;
- this->d = 0;
- CustomHandler::cleanup(oldD);
+ return this->d[i];
}
- inline void reset(T *other = 0)
+ inline const T &operator[](int i) const
+ {
+ return this->d[i];
+ }
+
+private:
+ Q_DISABLE_COPY(QScopedArrayPointer)
+};
+
+/* Internal helper class - exposes the data through data_ptr (legacy from QShared).
+ Required for some internal Qt classes, do not use otherwise. */
+template <typename T, typename Cleanup = QScopedPointerDeleter<T> >
+class QCustomScopedPointer : public QScopedPointer<T, Cleanup>
+{
+public:
+ explicit inline QCustomScopedPointer(T *p = 0)
+ : QScopedPointer<T, Cleanup>(p)
{
- CustomHandler::reset(this->d, other);
}
inline T *&data_ptr()
{
return this->d;
}
+
+private:
+ Q_DISABLE_COPY(QCustomScopedPointer)
};
-/* Internal helper class - a handler for QShared* classes, to be used in QScopedCustomPointer */
+/* Internal helper class - a handler for QShared* classes, to be used in QCustomScopedPointer */
template <typename T>
-class QScopedSharedPointerHandler
+class QScopedPointerSharedDeleter
{
public:
static inline void cleanup(T *d)
@@ -155,24 +221,17 @@ public:
if (d && !d->ref.deref())
delete d;
}
-
- static inline void reset(T *&d, T *other)
- {
- T *oldD = d;
- d = other;
- cleanup(oldD);
- }
};
-/* Internal. This should really have been a typedef, but you can't have a templated typedef :)
+/* Internal.
This class is basically a scoped pointer pointing to a ref-counted object
*/
template <typename T>
-class QScopedSharedPointer : public QScopedCustomPointer<T, QScopedSharedPointerHandler<T> >
+class QScopedSharedPointer : public QCustomScopedPointer<T, QScopedPointerSharedDeleter<T> >
{
public:
- inline QScopedSharedPointer(T *p = 0)
- : QScopedCustomPointer<T, QScopedSharedPointerHandler<T> >(p)
+ explicit inline QScopedSharedPointer(T *p = 0)
+ : QCustomScopedPointer<T, QScopedPointerSharedDeleter<T> >(p)
{
}
@@ -189,8 +248,11 @@ public:
other->ref.ref();
T *oldD = this->d;
this->d = other;
- QScopedSharedPointerHandler<T>::cleanup(oldD);
+ QScopedPointerSharedDeleter<T>::cleanup(oldD);
}
+
+private:
+ Q_DISABLE_COPY(QScopedSharedPointer)
};
QT_END_NAMESPACE
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp
index 38b6f58..ca2fd1a 100644
--- a/src/corelib/tools/qstring.cpp
+++ b/src/corelib/tools/qstring.cpp
@@ -1023,6 +1023,7 @@ QString::QString(int size, QChar ch)
QString::QString(int size, Qt::Initialization)
{
d = (Data*) qMalloc(sizeof(Data)+size*sizeof(QChar));
+ Q_CHECK_PTR(d);
d->ref = 1;
d->alloc = d->size = size;
d->clean = d->asciiCache = d->simpletext = d->righttoleft = d->capacity = 0;
@@ -1236,11 +1237,9 @@ void QString::realloc(int alloc)
asciiCache->remove(d);
}
#endif
- Data *x = static_cast<Data *>(qRealloc(d, sizeof(Data) + alloc * sizeof(QChar)));
- Q_CHECK_PTR(x);
- x->alloc = alloc;
- x->data = x->array;
- d = x;
+ d = static_cast<Data *>(q_check_ptr(qRealloc(d, sizeof(Data) + alloc * sizeof(QChar))));
+ d->alloc = alloc;
+ d->data = d->array;
}
}
diff --git a/src/corelib/tools/qtimeline.h b/src/corelib/tools/qtimeline.h
index 2d1ad42..2a1c2c2 100644
--- a/src/corelib/tools/qtimeline.h
+++ b/src/corelib/tools/qtimeline.h
@@ -136,7 +136,7 @@ protected:
private:
Q_DISABLE_COPY(QTimeLine)
- Q_DECLARE_PRIVATE(QTimeLine)
+ Q_DECLARE_SCOPED_PRIVATE(QTimeLine)
};
QT_END_NAMESPACE