diff options
author | Robin Burchell <robin.burchell@collabora.com> | 2011-12-20 21:39:12 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-01-06 14:11:14 +0100 |
commit | b08daaedd45457b775cb90d2c2650510daff1c8d (patch) | |
tree | d68ea8016a15ee851813133a51897a7a81aedc16 /src/corelib/tools | |
parent | 514ef34d1f838be119961003c0411a88352ba535 (diff) |
Remove all non-inline of qMalloc/qFree/qRealloc.
We're trying to deprecate these, so don't use them anymore.
The inline uses of these have been left intact, for the moment. Inline code will
need to create their own non-inline allocation methods (for future-proofing to
allow alterations in how e.g. individual containers allocate)
Change-Id: I1071a487c25e95b7bb81a3327b20c5481fb5ed22
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com>
Diffstat (limited to 'src/corelib/tools')
-rw-r--r-- | src/corelib/tools/qbytearray.cpp | 30 | ||||
-rw-r--r-- | src/corelib/tools/qhash.cpp | 4 | ||||
-rw-r--r-- | src/corelib/tools/qlist.cpp | 8 | ||||
-rw-r--r-- | src/corelib/tools/qmap.cpp | 6 | ||||
-rw-r--r-- | src/corelib/tools/qstring.cpp | 30 | ||||
-rw-r--r-- | src/corelib/tools/qvector.cpp | 10 |
6 files changed, 46 insertions, 42 deletions
diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp index d8c0668a39..8c625c2868 100644 --- a/src/corelib/tools/qbytearray.cpp +++ b/src/corelib/tools/qbytearray.cpp @@ -546,7 +546,7 @@ QByteArray qUncompress(const uchar* data, int nbytes) qWarning("qUncompress: Input data is corrupted"); return QByteArray(); } - QByteArray::Data *p = static_cast<QByteArray::Data *>(qRealloc(d.data(), sizeof(QByteArray::Data) + alloc + 1)); + QByteArray::Data *p = static_cast<QByteArray::Data *>(::realloc(d.data(), sizeof(QByteArray::Data) + alloc + 1)); if (!p) { // we are not allowed to crash here when compiling with QT_NO_EXCEPTIONS qWarning("qUncompress: could not allocate enough memory to uncompress data"); @@ -567,7 +567,7 @@ QByteArray qUncompress(const uchar* data, int nbytes) qWarning("qUncompress: Input data is corrupted"); return QByteArray(); } - QByteArray::Data *p = static_cast<QByteArray::Data *>(qRealloc(d.data(), sizeof(QByteArray::Data) + len + 1)); + QByteArray::Data *p = static_cast<QByteArray::Data *>(::realloc(d.data(), sizeof(QByteArray::Data) + len + 1)); if (!p) { // we are not allowed to crash here when compiling with QT_NO_EXCEPTIONS qWarning("qUncompress: could not allocate enough memory to uncompress data"); @@ -883,7 +883,7 @@ QByteArray &QByteArray::operator=(const QByteArray & other) { other.d->ref.ref(); if (!d->ref.deref()) - qFree(d); + free(d); d = other.d; return *this; } @@ -912,7 +912,7 @@ QByteArray &QByteArray::operator=(const char *str) } x->ref.ref(); if (!d->ref.deref()) - qFree(d); + free(d); d = x; return *this; } @@ -1302,7 +1302,7 @@ QByteArray::QByteArray(const char *str) d = const_cast<Data *>(&shared_empty.ba); } else { int len = qstrlen(str); - d = static_cast<Data *>(qMalloc(sizeof(Data) + len + 1)); + d = static_cast<Data *>(malloc(sizeof(Data) + len + 1)); Q_CHECK_PTR(d); d->ref = 1; d->size = len; @@ -1331,7 +1331,7 @@ QByteArray::QByteArray(const char *data, int size) } else if (size <= 0) { d = const_cast<Data *>(&shared_empty.ba); } else { - d = static_cast<Data *>(qMalloc(sizeof(Data) + size + 1)); + d = static_cast<Data *>(malloc(sizeof(Data) + size + 1)); Q_CHECK_PTR(d); d->ref = 1; d->size = size; @@ -1355,7 +1355,7 @@ QByteArray::QByteArray(int size, char ch) if (size <= 0) { d = const_cast<Data *>(&shared_null.ba); } else { - d = static_cast<Data *>(qMalloc(sizeof(Data) + size + 1)); + d = static_cast<Data *>(malloc(sizeof(Data) + size + 1)); Q_CHECK_PTR(d); d->ref = 1; d->size = size; @@ -1375,7 +1375,7 @@ QByteArray::QByteArray(int size, char ch) QByteArray::QByteArray(int size, Qt::Initialization) { - d = static_cast<Data *>(qMalloc(sizeof(Data) + size + 1)); + d = static_cast<Data *>(malloc(sizeof(Data) + size + 1)); Q_CHECK_PTR(d); d->ref = 1; d->size = size; @@ -1411,7 +1411,7 @@ void QByteArray::resize(int size) if (size == 0 && !d->capacityReserved) { Data *x = const_cast<Data *>(&shared_empty.ba); if (!d->ref.deref()) - qFree(d); + free(d); d = x; } else if (d == &shared_null.ba || d == &shared_empty.ba) { // @@ -1422,7 +1422,7 @@ void QByteArray::resize(int size) // which is used in place of the Qt 3 idiom: // QByteArray a(sz); // - Data *x = static_cast<Data *>(qMalloc(sizeof(Data) + size + 1)); + Data *x = static_cast<Data *>(malloc(sizeof(Data) + size + 1)); Q_CHECK_PTR(x); x->ref = 1; x->size = size; @@ -1464,7 +1464,7 @@ QByteArray &QByteArray::fill(char ch, int size) void QByteArray::realloc(int alloc) { if (d->ref != 1 || d->offset) { - Data *x = static_cast<Data *>(qMalloc(sizeof(Data) + alloc + 1)); + Data *x = static_cast<Data *>(malloc(sizeof(Data) + alloc + 1)); Q_CHECK_PTR(x); x->ref = 1; x->size = qMin(alloc, d->size); @@ -1474,10 +1474,10 @@ void QByteArray::realloc(int alloc) ::memcpy(x->data(), d->data(), x->size); x->data()[x->size] = '\0'; if (!d->ref.deref()) - qFree(d); + free(d); d = x; } else { - Data *x = static_cast<Data *>(qRealloc(d, sizeof(Data) + alloc + 1)); + Data *x = static_cast<Data *>(::realloc(d, sizeof(Data) + alloc + 1)); Q_CHECK_PTR(x); x->alloc = alloc; x->offset = 0; @@ -2730,7 +2730,7 @@ QByteArray QByteArray::toUpper() const void QByteArray::clear() { if (!d->ref.deref()) - qFree(d); + free(d); d = const_cast<Data *>(&shared_null.ba); d->ref.ref(); } @@ -3885,7 +3885,7 @@ QByteArray QByteArray::fromRawData(const char *data, int size) } else if (!size) { x = const_cast<Data *>(&shared_empty.ba); } else { - x = static_cast<Data *>(qMalloc(sizeof(Data) + 1)); + x = static_cast<Data *>(malloc(sizeof(Data) + 1)); Q_CHECK_PTR(x); x->ref = 1; x->size = size; diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp index f4ec4ebd56..fac8c2f8ac 100644 --- a/src/corelib/tools/qhash.cpp +++ b/src/corelib/tools/qhash.cpp @@ -171,7 +171,7 @@ const QHashData QHashData::shared_null = { void *QHashData::allocateNode(int nodeAlign) { - void *ptr = strictAlignment ? qMallocAligned(nodeSize, nodeAlign) : qMalloc(nodeSize); + void *ptr = strictAlignment ? qMallocAligned(nodeSize, nodeAlign) : malloc(nodeSize); Q_CHECK_PTR(ptr); return ptr; } @@ -181,7 +181,7 @@ void QHashData::freeNode(void *node) if (strictAlignment) qFreeAligned(node); else - qFree(node); + free(node); } QHashData *QHashData::detach_helper(void (*node_duplicate)(Node *, void *), diff --git a/src/corelib/tools/qlist.cpp b/src/corelib/tools/qlist.cpp index 9ac46365a2..adc6ee7a4b 100644 --- a/src/corelib/tools/qlist.cpp +++ b/src/corelib/tools/qlist.cpp @@ -42,7 +42,9 @@ #include <new> #include "qlist.h" #include "qtools_p.h" + #include <string.h> +#include <stdlib.h> QT_BEGIN_NAMESPACE @@ -82,7 +84,7 @@ QListData::Data *QListData::detach_grow(int *idx, int num) int l = x->end - x->begin; int nl = l + num; int alloc = grow(nl); - Data* t = static_cast<Data *>(qMalloc(DataHeaderSize + alloc * sizeof(void *))); + Data* t = static_cast<Data *>(::malloc(DataHeaderSize + alloc * sizeof(void *))); Q_CHECK_PTR(t); t->ref = 1; @@ -124,7 +126,7 @@ QListData::Data *QListData::detach_grow(int *idx, int num) QListData::Data *QListData::detach(int alloc) { Data *x = d; - Data* t = static_cast<Data *>(qMalloc(DataHeaderSize + alloc * sizeof(void *))); + Data* t = static_cast<Data *>(::malloc(DataHeaderSize + alloc * sizeof(void *))); Q_CHECK_PTR(t); t->ref = 1; @@ -145,7 +147,7 @@ QListData::Data *QListData::detach(int alloc) void QListData::realloc(int alloc) { Q_ASSERT(d->ref == 1); - Data *x = static_cast<Data *>(qRealloc(d, DataHeaderSize + alloc * sizeof(void *))); + Data *x = static_cast<Data *>(::realloc(d, DataHeaderSize + alloc * sizeof(void *))); Q_CHECK_PTR(x); d = x; diff --git a/src/corelib/tools/qmap.cpp b/src/corelib/tools/qmap.cpp index 280409fde8..a688ae1c1a 100644 --- a/src/corelib/tools/qmap.cpp +++ b/src/corelib/tools/qmap.cpp @@ -85,7 +85,7 @@ void QMapData::continueFreeData(int offset) if (strictAlignment) qFreeAligned(reinterpret_cast<char *>(prev) - offset); else - qFree(reinterpret_cast<char *>(prev) - offset); + free(reinterpret_cast<char *>(prev) - offset); } delete this; } @@ -127,7 +127,7 @@ QMapData::Node *QMapData::node_create(Node *update[], int offset, int alignment) void *concreteNode = strictAlignment ? qMallocAligned(offset + sizeof(Node) + level * sizeof(Node *), alignment) : - qMalloc(offset + sizeof(Node) + level * sizeof(Node *)); + malloc(offset + sizeof(Node) + level * sizeof(Node *)); Q_CHECK_PTR(concreteNode); Node *abstractNode = reinterpret_cast<Node *>(reinterpret_cast<char *>(concreteNode) + offset); @@ -157,7 +157,7 @@ void QMapData::node_delete(Node *update[], int offset, Node *node) if (strictAlignment) qFreeAligned(reinterpret_cast<char *>(node) - offset); else - qFree(reinterpret_cast<char *>(node) - offset); + free(reinterpret_cast<char *>(node) - offset); } #ifdef QT_QMAP_DEBUG diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index 38e19d1c98..eea41ea3d7 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -1030,7 +1030,7 @@ QString::QString(const QChar *unicode, int size) } else if (size <= 0) { d = const_cast<Data *>(&shared_empty.str); } else { - d = (Data*) qMalloc(sizeof(Data)+(size+1)*sizeof(QChar)); + d = (Data*) ::malloc(sizeof(Data)+(size+1)*sizeof(QChar)); Q_CHECK_PTR(d); d->ref = 1; d->size = size; @@ -1062,7 +1062,7 @@ QString::QString(const QChar *unicode) if (!size) { d = const_cast<Data *>(&shared_empty.str); } else { - d = (Data*) qMalloc(sizeof(Data)+(size+1)*sizeof(QChar)); + d = (Data*) ::malloc(sizeof(Data)+(size+1)*sizeof(QChar)); Q_CHECK_PTR(d); d->ref = 1; d->size = size; @@ -1087,7 +1087,7 @@ QString::QString(int size, QChar ch) if (size <= 0) { d = const_cast<Data *>(&shared_empty.str); } else { - d = (Data*) qMalloc(sizeof(Data)+(size+1)*sizeof(QChar)); + d = (Data*) ::malloc(sizeof(Data)+(size+1)*sizeof(QChar)); Q_CHECK_PTR(d); d->ref = 1; d->size = size; @@ -1111,7 +1111,7 @@ QString::QString(int size, QChar ch) */ QString::QString(int size, Qt::Initialization) { - d = (Data*) qMalloc(sizeof(Data)+(size+1)*sizeof(QChar)); + d = (Data*) ::malloc(sizeof(Data)+(size+1)*sizeof(QChar)); Q_CHECK_PTR(d); d->ref = 1; d->size = size; @@ -1133,7 +1133,7 @@ QString::QString(int size, Qt::Initialization) */ QString::QString(QChar ch) { - d = (Data *) qMalloc(sizeof(Data) + 2*sizeof(QChar)); + d = (Data *) ::malloc(sizeof(Data) + 2*sizeof(QChar)); Q_CHECK_PTR(d); d->ref = 1; d->size = 1; @@ -1199,7 +1199,7 @@ QString::QString(QChar ch) // ### Qt 5: rename freeData() to avoid confusion. See task 197625. void QString::free(Data *d) { - qFree(d); + ::free(d); } /*! @@ -1312,7 +1312,7 @@ void QString::resize(int size) void QString::realloc(int alloc) { if (d->ref != 1 || d->offset) { - Data *x = static_cast<Data *>(qMalloc(sizeof(Data) + (alloc+1) * sizeof(QChar))); + Data *x = static_cast<Data *>(::malloc(sizeof(Data) + (alloc+1) * sizeof(QChar))); Q_CHECK_PTR(x); x->ref = 1; x->size = qMin(alloc, d->size); @@ -1325,7 +1325,7 @@ void QString::realloc(int alloc) QString::free(d); d = x; } else { - Data *p = static_cast<Data *>(qRealloc(d, sizeof(Data) + (alloc+1) * sizeof(QChar))); + Data *p = static_cast<Data *>(::realloc(d, sizeof(Data) + (alloc+1) * sizeof(QChar))); Q_CHECK_PTR(p); d = p; d->alloc = alloc; @@ -1483,11 +1483,11 @@ QString& QString::insert(int i, const QChar *unicode, int size) const ushort *s = (const ushort *)unicode; if (s >= d->data() && s < d->data() + d->alloc) { // Part of me - take a copy - ushort *tmp = static_cast<ushort *>(qMalloc(size * sizeof(QChar))); + ushort *tmp = static_cast<ushort *>(::malloc(size * sizeof(QChar))); Q_CHECK_PTR(tmp); memcpy(tmp, s, size * sizeof(QChar)); insert(i, reinterpret_cast<const QChar *>(tmp), size); - qFree(tmp); + ::free(tmp); return *this; } @@ -1843,7 +1843,7 @@ void QString::replace_helper(uint *indices, int nIndices, int blen, const QChar // (which we could possibly invalidate via a realloc or corrupt via memcpy operations.) QChar *afterBuffer = const_cast<QChar *>(after); if (after >= reinterpret_cast<QChar *>(d->data()) && after < reinterpret_cast<QChar *>(d->data()) + d->size) { - afterBuffer = static_cast<QChar *>(qMalloc(alen*sizeof(QChar))); + afterBuffer = static_cast<QChar *>(::malloc(alen*sizeof(QChar))); Q_CHECK_PTR(afterBuffer); ::memcpy(afterBuffer, after, alen*sizeof(QChar)); } @@ -1898,11 +1898,11 @@ void QString::replace_helper(uint *indices, int nIndices, int blen, const QChar } } QT_CATCH(const std::bad_alloc &) { if (afterBuffer != after) - qFree(afterBuffer); + ::free(afterBuffer); QT_RETHROW; } if (afterBuffer != after) - qFree(afterBuffer); + ::free(afterBuffer); } /*! @@ -3756,7 +3756,7 @@ QString::Data *QString::fromLatin1_helper(const char *str, int size) } else { if (size < 0) size = qstrlen(str); - d = static_cast<Data *>(qMalloc(sizeof(Data) + (size+1) * sizeof(QChar))); + d = static_cast<Data *>(::malloc(sizeof(Data) + (size+1) * sizeof(QChar))); Q_CHECK_PTR(d); d->ref = 1; d->size = size; @@ -7063,7 +7063,7 @@ QString QString::fromRawData(const QChar *unicode, int size) } else if (!size) { x = const_cast<Data *>(&shared_empty.str); } else { - x = static_cast<Data *>(qMalloc(sizeof(Data) + sizeof(ushort))); + x = static_cast<Data *>(::malloc(sizeof(Data) + sizeof(ushort))); Q_CHECK_PTR(x); x->ref = 1; x->size = size; diff --git a/src/corelib/tools/qvector.cpp b/src/corelib/tools/qvector.cpp index c58c846aa8..95775d4bd8 100644 --- a/src/corelib/tools/qvector.cpp +++ b/src/corelib/tools/qvector.cpp @@ -41,7 +41,9 @@ #include "qvector.h" #include "qtools_p.h" + #include <string.h> +#include <stdlib.h> QT_BEGIN_NAMESPACE @@ -56,7 +58,7 @@ const QVectorData QVectorData::shared_null = { Q_REFCOUNT_INITIALIZER(-1), 0, 0, QVectorData *QVectorData::malloc(int sizeofTypedData, int size, int sizeofT, QVectorData *init) { - QVectorData* p = (QVectorData *)qMalloc(sizeofTypedData + (size - 1) * sizeofT); + QVectorData* p = (QVectorData *)::malloc(sizeofTypedData + (size - 1) * sizeofT); Q_CHECK_PTR(p); ::memcpy(p, init, sizeofTypedData + (qMin(size, init->alloc) - 1) * sizeofT); return p; @@ -64,14 +66,14 @@ QVectorData *QVectorData::malloc(int sizeofTypedData, int size, int sizeofT, QVe QVectorData *QVectorData::allocate(int size, int alignment) { - return static_cast<QVectorData *>(alignment > alignmentThreshold() ? qMallocAligned(size, alignment) : qMalloc(size)); + return static_cast<QVectorData *>(alignment > alignmentThreshold() ? qMallocAligned(size, alignment) : ::malloc(size)); } QVectorData *QVectorData::reallocate(QVectorData *x, int newsize, int oldsize, int alignment) { if (alignment > alignmentThreshold()) return static_cast<QVectorData *>(qReallocAligned(x, newsize, oldsize, alignment)); - return static_cast<QVectorData *>(qRealloc(x, newsize)); + return static_cast<QVectorData *>(realloc(x, newsize)); } void QVectorData::free(QVectorData *x, int alignment) @@ -79,7 +81,7 @@ void QVectorData::free(QVectorData *x, int alignment) if (alignment > alignmentThreshold()) qFreeAligned(x); else - qFree(x); + ::free(x); } int QVectorData::grow(int sizeofTypedData, int size, int sizeofT, bool excessive) |