cleanup containers methods and use of deprecated allocation methods

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2016-02-16 03:47:38 +02:00
parent 446bedd388
commit f9540805d1
47 changed files with 228 additions and 331 deletions

View file

@ -804,7 +804,7 @@ QTextCodec::ConverterState::~ConverterState()
if (flags & FreeFunction) if (flags & FreeFunction)
(QTextCodecUnalignedPointer::decode(state_data))(this); (QTextCodecUnalignedPointer::decode(state_data))(this);
else if (d) else if (d)
qFree(d); free(d);
} }
/*! /*!

View file

@ -3103,7 +3103,7 @@ void *qReallocAligned(void *oldptr, size_t newsize, size_t oldsize, size_t align
void *actualptr = oldptr ? static_cast<void **>(oldptr)[-1] : 0; void *actualptr = oldptr ? static_cast<void **>(oldptr)[-1] : 0;
if (alignment <= sizeof(void*)) { if (alignment <= sizeof(void*)) {
// special, fast case // special, fast case
void **newptr = static_cast<void **>(qRealloc(actualptr, newsize + sizeof(void*))); void **newptr = static_cast<void **>(realloc(actualptr, newsize + sizeof(void*)));
if (!newptr) if (!newptr)
return 0; return 0;
if (newptr == actualptr) { if (newptr == actualptr) {
@ -3123,7 +3123,7 @@ void *qReallocAligned(void *oldptr, size_t newsize, size_t oldsize, size_t align
// However, we need to store the actual pointer, so we need to allocate actually size + // However, we need to store the actual pointer, so we need to allocate actually size +
// alignment anyway. // alignment anyway.
void *real = qRealloc(actualptr, newsize + alignment); void *real = realloc(actualptr, newsize + alignment);
if (!real) if (!real)
return 0; return 0;

View file

@ -180,7 +180,7 @@ public:
SidCleanup::~SidCleanup() SidCleanup::~SidCleanup()
{ {
qFree(currentUserSID); free(currentUserSID);
currentUserSID = 0; currentUserSID = 0;
// worldSID was allocated with AllocateAndInitializeSid so it needs to be freed with FreeSid // worldSID was allocated with AllocateAndInitializeSid so it needs to be freed with FreeSid
@ -231,15 +231,15 @@ static void resolveLibs()
// doing a dummy GetTokenInformation call. // doing a dummy GetTokenInformation call.
::GetTokenInformation(token, TokenUser, 0, 0, &retsize); ::GetTokenInformation(token, TokenUser, 0, 0, &retsize);
if (retsize) { if (retsize) {
void *tokenBuffer = qMalloc(retsize); void *tokenBuffer = malloc(retsize);
if (::GetTokenInformation(token, TokenUser, tokenBuffer, retsize, &retsize)) { if (::GetTokenInformation(token, TokenUser, tokenBuffer, retsize, &retsize)) {
PSID tokenSid = reinterpret_cast<PTOKEN_USER>(tokenBuffer)->User.Sid; PSID tokenSid = reinterpret_cast<PTOKEN_USER>(tokenBuffer)->User.Sid;
DWORD sidLen = ::GetLengthSid(tokenSid); DWORD sidLen = ::GetLengthSid(tokenSid);
currentUserSID = reinterpret_cast<PSID>(qMalloc(sidLen)); currentUserSID = reinterpret_cast<PSID>(malloc(sidLen));
if (::CopySid(sidLen, currentUserSID, tokenSid)) if (::CopySid(sidLen, currentUserSID, tokenSid))
ptrBuildTrusteeWithSidW(&currentUserTrusteeW, currentUserSID); ptrBuildTrusteeWithSidW(&currentUserTrusteeW, currentUserSID);
} }
qFree(tokenBuffer); free(tokenBuffer);
} }
::CloseHandle(token); ::CloseHandle(token);
} }
@ -314,7 +314,7 @@ static QString readSymLink(const QFileSystemEntry &link)
0); 0);
if (handle != INVALID_HANDLE_VALUE) { if (handle != INVALID_HANDLE_VALUE) {
DWORD bufsize = MAXIMUM_REPARSE_DATA_BUFFER_SIZE; DWORD bufsize = MAXIMUM_REPARSE_DATA_BUFFER_SIZE;
REPARSE_DATA_BUFFER *rdb = (REPARSE_DATA_BUFFER*)qMalloc(bufsize); REPARSE_DATA_BUFFER *rdb = (REPARSE_DATA_BUFFER*)malloc(bufsize);
DWORD retsize = 0; DWORD retsize = 0;
if (::DeviceIoControl(handle, FSCTL_GET_REPARSE_POINT, 0, 0, rdb, bufsize, &retsize, 0)) { if (::DeviceIoControl(handle, FSCTL_GET_REPARSE_POINT, 0, 0, rdb, bufsize, &retsize, 0)) {
if (rdb->ReparseTag == IO_REPARSE_TAG_MOUNT_POINT) { if (rdb->ReparseTag == IO_REPARSE_TAG_MOUNT_POINT) {
@ -332,7 +332,7 @@ static QString readSymLink(const QFileSystemEntry &link)
if (result.size() > 4 && result.at(0) == QLatin1Char('\\') && result.at(2) == QLatin1Char('?') && result.at(3) == QLatin1Char('\\')) if (result.size() > 4 && result.at(0) == QLatin1Char('\\') && result.at(2) == QLatin1Char('?') && result.at(3) == QLatin1Char('\\'))
result = result.mid(4); result = result.mid(4);
} }
qFree(rdb); free(rdb);
CloseHandle(handle); CloseHandle(handle);
#if !defined(QT_NO_LIBRARY) #if !defined(QT_NO_LIBRARY)

View file

@ -1615,9 +1615,9 @@ bool QMetaMethod::invoke(QObject *object,
} }
int nargs = 1; // include return type int nargs = 1; // include return type
void **args = (void **) qMalloc(paramCount * sizeof(void *)); void **args = (void **) malloc(paramCount * sizeof(void *));
Q_CHECK_PTR(args); Q_CHECK_PTR(args);
int *types = (int *) qMalloc(paramCount * sizeof(int)); int *types = (int *) malloc(paramCount * sizeof(int));
Q_CHECK_PTR(types); Q_CHECK_PTR(types);
types[0] = 0; // return type types[0] = 0; // return type
args[0] = 0; args[0] = 0;
@ -1634,8 +1634,8 @@ bool QMetaMethod::invoke(QObject *object,
if (types[x] && args[x]) if (types[x] && args[x])
QMetaType::destroy(types[x], args[x]); QMetaType::destroy(types[x], args[x]);
} }
qFree(types); free(types);
qFree(args); free(args);
return false; return false;
} }
} }

View file

@ -464,8 +464,8 @@ QMetaCallEvent::~QMetaCallEvent()
if (types_[i] && args_[i]) if (types_[i] && args_[i])
QMetaType::destroy(types_[i], args_[i]); QMetaType::destroy(types_[i], args_[i]);
} }
qFree(types_); free(types_);
qFree(args_); free(args_);
} }
#ifndef QT_NO_THREAD #ifndef QT_NO_THREAD
if (semaphore_) if (semaphore_)
@ -3127,9 +3127,9 @@ static void queued_activate(QObject *sender, int signal, QObjectPrivate::Connect
int nargs = 1; // include return type int nargs = 1; // include return type
while (c->argumentTypes[nargs-1]) while (c->argumentTypes[nargs-1])
++nargs; ++nargs;
int *types = (int *) qMalloc(nargs*sizeof(int)); int *types = (int *) malloc(nargs*sizeof(int));
Q_CHECK_PTR(types); Q_CHECK_PTR(types);
void **args = (void **) qMalloc(nargs*sizeof(void *)); void **args = (void **) malloc(nargs*sizeof(void *));
Q_CHECK_PTR(args); Q_CHECK_PTR(args);
types[0] = 0; // return type types[0] = 0; // return type
args[0] = 0; // return value args[0] = 0; // return value

View file

@ -549,7 +549,7 @@ QByteArray qUncompress(const uchar* data, int nbytes)
qWarning("qUncompress: Input data is corrupted"); qWarning("qUncompress: Input data is corrupted");
return QByteArray(); return QByteArray();
} }
QByteArray::Data *p = static_cast<QByteArray::Data *>(qRealloc(d.data(), sizeof(QByteArray::Data) + alloc)); QByteArray::Data *p = static_cast<QByteArray::Data *>(realloc(d.data(), sizeof(QByteArray::Data) + alloc));
if (!p) { if (!p) {
// we are not allowed to crash here when compiling with QT_NO_EXCEPTIONS // we are not allowed to crash here when compiling with QT_NO_EXCEPTIONS
qWarning("qUncompress: could not allocate enough memory to uncompress data"); qWarning("qUncompress: could not allocate enough memory to uncompress data");
@ -569,7 +569,7 @@ QByteArray qUncompress(const uchar* data, int nbytes)
qWarning("qUncompress: Input data is corrupted"); qWarning("qUncompress: Input data is corrupted");
return QByteArray(); return QByteArray();
} }
QByteArray::Data *p = static_cast<QByteArray::Data *>(qRealloc(d.data(), sizeof(QByteArray::Data) + len)); QByteArray::Data *p = static_cast<QByteArray::Data *>(realloc(d.data(), sizeof(QByteArray::Data) + len));
if (!p) { if (!p) {
// we are not allowed to crash here when compiling with QT_NO_EXCEPTIONS // we are not allowed to crash here when compiling with QT_NO_EXCEPTIONS
qWarning("qUncompress: could not allocate enough memory to uncompress data"); qWarning("qUncompress: could not allocate enough memory to uncompress data");
@ -904,7 +904,7 @@ QByteArray &QByteArray::operator=(const QByteArray & other)
{ {
other.d->ref.ref(); other.d->ref.ref();
if (!d->ref.deref()) if (!d->ref.deref())
qFree(d); free(d);
d = other.d; d = other.d;
return *this; return *this;
} }
@ -926,14 +926,14 @@ QByteArray &QByteArray::operator=(const char *str)
} else { } else {
int len = qstrlen(str); int len = qstrlen(str);
if (d->ref != 1 || len > d->alloc || (len < d->size && len < d->alloc >> 1)) if (d->ref != 1 || len > d->alloc || (len < d->size && len < d->alloc >> 1))
realloc(len); reallocData(len);
x = d; x = d;
memcpy(x->data, str, len + 1); // include null terminator memcpy(x->data, str, len + 1); // include null terminator
x->size = len; x->size = len;
} }
x->ref.ref(); x->ref.ref();
if (!d->ref.deref()) if (!d->ref.deref())
qFree(d); free(d);
d = x; d = x;
return *this; return *this;
} }
@ -1323,7 +1323,7 @@ QByteArray::QByteArray(const char *str)
d = &shared_empty; d = &shared_empty;
} else { } else {
int len = qstrlen(str); int len = qstrlen(str);
d = static_cast<Data *>(qMalloc(sizeof(Data)+len)); d = static_cast<Data *>(malloc(sizeof(Data)+len));
Q_CHECK_PTR(d); Q_CHECK_PTR(d);
d->ref = 0;; d->ref = 0;;
d->alloc = d->size = len; d->alloc = d->size = len;
@ -1351,7 +1351,7 @@ QByteArray::QByteArray(const char *data, int size)
} else if (size <= 0) { } else if (size <= 0) {
d = &shared_empty; d = &shared_empty;
} else { } else {
d = static_cast<Data *>(qMalloc(sizeof(Data) + size)); d = static_cast<Data *>(malloc(sizeof(Data) + size));
Q_CHECK_PTR(d); Q_CHECK_PTR(d);
d->ref = 0; d->ref = 0;
d->alloc = d->size = size; d->alloc = d->size = size;
@ -1374,7 +1374,7 @@ QByteArray::QByteArray(int size, char ch)
if (size <= 0) { if (size <= 0) {
d = &shared_null; d = &shared_null;
} else { } else {
d = static_cast<Data *>(qMalloc(sizeof(Data)+size)); d = static_cast<Data *>(malloc(sizeof(Data)+size));
Q_CHECK_PTR(d); Q_CHECK_PTR(d);
d->ref = 0; d->ref = 0;
d->alloc = d->size = size; d->alloc = d->size = size;
@ -1396,7 +1396,7 @@ QByteArray::QByteArray(int size, Qt::Initialization)
if (size <= 0) { if (size <= 0) {
d = &shared_empty; d = &shared_empty;
} else { } else {
d = static_cast<Data *>(qMalloc(sizeof(Data)+size)); d = static_cast<Data *>(malloc(sizeof(Data)+size));
Q_CHECK_PTR(d); Q_CHECK_PTR(d);
d->ref = 0; d->ref = 0;
d->alloc = d->size = size; d->alloc = d->size = size;
@ -1425,7 +1425,7 @@ void QByteArray::resize(int size)
Data *x = &shared_empty; Data *x = &shared_empty;
x->ref.ref(); x->ref.ref();
if (!d->ref.deref()) if (!d->ref.deref())
qFree(d); free(d);
d = x; d = x;
} else if (d == &shared_null) { } else if (d == &shared_null) {
// //
@ -1436,7 +1436,7 @@ void QByteArray::resize(int size)
// which is used in place of the Qt 3 idiom: // which is used in place of the Qt 3 idiom:
// QByteArray a(sz); // QByteArray a(sz);
// //
Data *x = static_cast<Data *>(qMalloc(sizeof(Data)+size)); Data *x = static_cast<Data *>(malloc(sizeof(Data)+size));
Q_CHECK_PTR(x); Q_CHECK_PTR(x);
x->ref = 1; x->ref = 1;
x->alloc = x->size = size; x->alloc = x->size = size;
@ -1446,7 +1446,7 @@ void QByteArray::resize(int size)
d = x; d = x;
} else { } else {
if (d->ref != 1 || size > d->alloc || (size < d->size && size < d->alloc >> 1)) if (d->ref != 1 || size > d->alloc || (size < d->size && size < d->alloc >> 1))
realloc(qAllocMore(size, sizeof(Data))); reallocData(qAllocMore(size, sizeof(Data)));
if (d->alloc >= size) { if (d->alloc >= size) {
d->size = size; d->size = size;
if (d->data == d->array) { if (d->data == d->array) {
@ -1475,10 +1475,10 @@ QByteArray &QByteArray::fill(char ch, int size)
return *this; return *this;
} }
void QByteArray::realloc(int alloc) void QByteArray::reallocData(int alloc)
{ {
if (d->ref != 1 || d->data != d->array) { if (d->ref != 1 || d->data != d->array) {
Data *x = static_cast<Data *>(qMalloc(sizeof(Data) + alloc)); Data *x = static_cast<Data *>(malloc(sizeof(Data) + alloc));
Q_CHECK_PTR(x); Q_CHECK_PTR(x);
x->size = qMin(alloc, d->size); x->size = qMin(alloc, d->size);
::memcpy(x->array, d->data, x->size); ::memcpy(x->array, d->data, x->size);
@ -1487,10 +1487,10 @@ void QByteArray::realloc(int alloc)
x->alloc = alloc; x->alloc = alloc;
x->data = x->array; x->data = x->array;
if (!d->ref.deref()) if (!d->ref.deref())
qFree(d); free(d);
d = x; d = x;
} else { } else {
Data *x = static_cast<Data *>(qRealloc(d, sizeof(Data) + alloc)); Data *x = static_cast<Data *>(realloc(d, sizeof(Data) + alloc));
Q_CHECK_PTR(x); Q_CHECK_PTR(x);
x->alloc = alloc; x->alloc = alloc;
x->data = x->array; x->data = x->array;
@ -1578,7 +1578,7 @@ QByteArray &QByteArray::prepend(const char *str, int len)
{ {
if (str) { if (str) {
if (d->ref != 1 || d->size + len > d->alloc) if (d->ref != 1 || d->size + len > d->alloc)
realloc(qAllocMore(d->size + len, sizeof(Data))); reallocData(qAllocMore(d->size + len, sizeof(Data)));
memmove(d->data+len, d->data, d->size); memmove(d->data+len, d->data, d->size);
memcpy(d->data, str, len); memcpy(d->data, str, len);
d->size += len; d->size += len;
@ -1596,7 +1596,7 @@ QByteArray &QByteArray::prepend(const char *str, int len)
QByteArray &QByteArray::prepend(char ch) QByteArray &QByteArray::prepend(char ch)
{ {
if (d->ref != 1 || d->size + 1 > d->alloc) if (d->ref != 1 || d->size + 1 > d->alloc)
realloc(qAllocMore(d->size + 1, sizeof(Data))); reallocData(qAllocMore(d->size + 1, sizeof(Data)));
memmove(d->data+1, d->data, d->size); memmove(d->data+1, d->data, d->size);
d->data[0] = ch; d->data[0] = ch;
++d->size; ++d->size;
@ -1634,7 +1634,7 @@ QByteArray &QByteArray::append(const QByteArray &ba)
*this = ba; *this = ba;
} else if (ba.d != &shared_null) { } else if (ba.d != &shared_null) {
if (d->ref != 1 || d->size + ba.d->size > d->alloc) if (d->ref != 1 || d->size + ba.d->size > d->alloc)
realloc(qAllocMore(d->size + ba.d->size, sizeof(Data))); reallocData(qAllocMore(d->size + ba.d->size, sizeof(Data)));
memcpy(d->data + d->size, ba.d->data, ba.d->size); memcpy(d->data + d->size, ba.d->data, ba.d->size);
d->size += ba.d->size; d->size += ba.d->size;
d->data[d->size] = '\0'; d->data[d->size] = '\0';
@ -1668,7 +1668,7 @@ QByteArray& QByteArray::append(const char *str)
if (str) { if (str) {
int len = qstrlen(str); int len = qstrlen(str);
if (d->ref != 1 || d->size + len > d->alloc) if (d->ref != 1 || d->size + len > d->alloc)
realloc(qAllocMore(d->size + len, sizeof(Data))); reallocData(qAllocMore(d->size + len, sizeof(Data)));
memcpy(d->data + d->size, str, len + 1); // include null terminator memcpy(d->data + d->size, str, len + 1); // include null terminator
d->size += len; d->size += len;
} }
@ -1693,7 +1693,7 @@ QByteArray &QByteArray::append(const char *str, int len)
len = qstrlen(str); len = qstrlen(str);
if (str && len) { if (str && len) {
if (d->ref != 1 || d->size + len > d->alloc) if (d->ref != 1 || d->size + len > d->alloc)
realloc(qAllocMore(d->size + len, sizeof(Data))); reallocData(qAllocMore(d->size + len, sizeof(Data)));
memcpy(d->data + d->size, str, len); // include null terminator memcpy(d->data + d->size, str, len); // include null terminator
d->size += len; d->size += len;
d->data[d->size] = '\0'; d->data[d->size] = '\0';
@ -1710,7 +1710,7 @@ QByteArray &QByteArray::append(const char *str, int len)
QByteArray& QByteArray::append(char ch) QByteArray& QByteArray::append(char ch)
{ {
if (d->ref != 1 || d->size + 1 > d->alloc) if (d->ref != 1 || d->size + 1 > d->alloc)
realloc(qAllocMore(d->size + 1, sizeof(Data))); reallocData(qAllocMore(d->size + 1, sizeof(Data)));
d->data[d->size++] = ch; d->data[d->size++] = ch;
d->data[d->size] = '\0'; d->data[d->size] = '\0';
return *this; return *this;
@ -2743,7 +2743,7 @@ QByteArray QByteArray::toUpper() const
void QByteArray::clear() void QByteArray::clear()
{ {
if (!d->ref.deref()) if (!d->ref.deref())
qFree(d); free(d);
d = &shared_null; d = &shared_null;
d->ref.ref(); d->ref.ref();
} }
@ -3893,7 +3893,7 @@ QByteArray QByteArray::number(double n, char f, int prec)
QByteArray QByteArray::fromRawData(const char *data, int size) QByteArray QByteArray::fromRawData(const char *data, int size)
{ {
Data *x = static_cast<Data *>(qMalloc(sizeof(Data))); Data *x = static_cast<Data *>(malloc(sizeof(Data)));
Q_CHECK_PTR(x); Q_CHECK_PTR(x);
if (data) { if (data) {
x->data = const_cast<char *>(data); x->data = const_cast<char *>(data);

View file

@ -353,7 +353,7 @@ private:
static Data shared_empty; static Data shared_empty;
Data *d; Data *d;
QByteArray(Data *dd, int /*dummy*/, int /*dummy*/) : d(dd) {} QByteArray(Data *dd, int /*dummy*/, int /*dummy*/) : d(dd) {}
void realloc(int alloc); void reallocData(int alloc);
void expand(int i); void expand(int i);
QByteArray nulTerminated() const; QByteArray nulTerminated() const;
@ -366,7 +366,7 @@ public:
}; };
inline QByteArray::QByteArray(): d(&shared_null) { d->ref.ref(); } inline QByteArray::QByteArray(): d(&shared_null) { d->ref.ref(); }
inline QByteArray::~QByteArray() { if (!d->ref.deref()) qFree(d); } inline QByteArray::~QByteArray() { if (!d->ref.deref()) free(d); }
inline int QByteArray::size() const inline int QByteArray::size() const
{ return d->size; } { return d->size; }
@ -401,7 +401,7 @@ inline const char *QByteArray::data() const
inline const char *QByteArray::constData() const inline const char *QByteArray::constData() const
{ return d->data; } { return d->data; }
inline void QByteArray::detach() inline void QByteArray::detach()
{ if (d->ref != 1 || d->data != d->array) realloc(d->size); } { if (d->ref != 1 || d->data != d->array) reallocData(d->size); }
inline bool QByteArray::isDetached() const inline bool QByteArray::isDetached() const
{ return d->ref == 1; } { return d->ref == 1; }
inline QByteArray::QByteArray(const QByteArray &a) : d(a.d) inline QByteArray::QByteArray(const QByteArray &a) : d(a.d)
@ -411,10 +411,10 @@ inline int QByteArray::capacity() const
{ return d->alloc; } { return d->alloc; }
inline void QByteArray::reserve(int asize) inline void QByteArray::reserve(int asize)
{ if (d->ref != 1 || asize > d->alloc) realloc(asize); } { if (d->ref != 1 || asize > d->alloc) reallocData(asize); }
inline void QByteArray::squeeze() inline void QByteArray::squeeze()
{ if (d->size < d->alloc) realloc(d->size); } { if (d->size < d->alloc) reallocData(d->size); }
class Q_CORE_EXPORT QByteRef { class Q_CORE_EXPORT QByteRef {
QByteArray &a; QByteArray &a;

View file

@ -61,7 +61,7 @@ QContiguousCacheData *QContiguousCacheData::allocate(int size, int alignment)
return static_cast<QContiguousCacheData *>(qMallocAligned(size, alignment)); return static_cast<QContiguousCacheData *>(qMallocAligned(size, alignment));
} }
void QContiguousCacheData::free(QContiguousCacheData *data) void QContiguousCacheData::freeData(QContiguousCacheData *data)
{ {
qFreeAligned(data); qFreeAligned(data);
} }

View file

@ -69,7 +69,7 @@ struct Q_CORE_EXPORT QContiguousCacheData
// (such as long double on 64-bit platforms, __int128, __float128) // (such as long double on 64-bit platforms, __int128, __float128)
static QContiguousCacheData *allocate(int size, int alignment); static QContiguousCacheData *allocate(int size, int alignment);
static void free(QContiguousCacheData *data); static void freeData(QContiguousCacheData *data);
#ifdef QT_QCONTIGUOUSCACHE_DEBUG #ifdef QT_QCONTIGUOUSCACHE_DEBUG
void dump() const; void dump() const;
@ -82,7 +82,7 @@ struct QContiguousCacheTypedData: private QContiguousCacheData
// private inheritance to avoid aliasing warningss // private inheritance to avoid aliasing warningss
T array[1]; T array[1];
static inline void free(QContiguousCacheTypedData *data) { QContiguousCacheData::free(data); } static inline void free(QContiguousCacheTypedData *data) { QContiguousCacheData::freeData(data); }
}; };
template<typename T> template<typename T>

View file

@ -171,7 +171,7 @@ QHashData QHashData::shared_null = {
void *QHashData::allocateNode(int nodeAlign) 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); Q_CHECK_PTR(ptr);
return ptr; return ptr;
} }
@ -181,7 +181,7 @@ void QHashData::freeNode(void *node)
if (strictAlignment) if (strictAlignment)
qFreeAligned(node); qFreeAligned(node);
else else
qFree(node); free(node);
} }
QHashData *QHashData::detach_helper(void (*node_duplicate)(Node *, void *), QHashData *QHashData::detach_helper(void (*node_duplicate)(Node *, void *),

View file

@ -82,7 +82,7 @@ QListData::Data *QListData::detach_grow(int *idx, int num)
int l = x->end - x->begin; int l = x->end - x->begin;
int nl = l + num; int nl = l + num;
int alloc = grow(nl); 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); Q_CHECK_PTR(t);
t->ref = 1; t->ref = 1;
@ -113,64 +113,6 @@ QListData::Data *QListData::detach_grow(int *idx, int num)
return x; return x;
} }
#if QT_VERSION >= 0x050000
# error "Remove QListData::detach(), it is only required for binary compatibility for 4.0.x to 4.2.x"
#endif
QListData::Data *QListData::detach()
{
Data *x = static_cast<Data *>(qMalloc(DataHeaderSize + d->alloc * sizeof(void *)));
Q_CHECK_PTR(x);
x->ref = 1;
x->sharable = true;
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())
return x;
return 0;
}
/*!
* 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
*/
#if QT_VERSION >= 0x050000
# error "Remove QListData::detach2(), it is only required for binary compatibility for 4.3.x to 4.5.x"
#endif
QListData::Data *QListData::detach2()
{
Data *x = d;
Data* t = static_cast<Data *>(qMalloc(DataHeaderSize + x->alloc * sizeof(void *)));
Q_CHECK_PTR(t);
::memcpy(t, d, DataHeaderSize + d->alloc * sizeof(void *));
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;
return x;
}
/*! /*!
* Detaches the QListData by allocating new memory for a list which possibly * Detaches the QListData by allocating new memory for a list which possibly
* has a different size than the copied one. * has a different size than the copied one.
@ -182,7 +124,7 @@ QListData::Data *QListData::detach2()
QListData::Data *QListData::detach(int alloc) QListData::Data *QListData::detach(int alloc)
{ {
Data *x = d; 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); Q_CHECK_PTR(t);
t->ref = 1; t->ref = 1;
@ -207,18 +149,10 @@ QListData::Data *QListData::detach(int alloc)
* *
* \internal * \internal
*/ */
#if QT_VERSION >= 0x050000 void QListData::reallocData(int alloc)
# error "Remove QListData::detach3(), it is only required for binary compatibility for 4.5.x to 4.6.x"
#endif
QListData::Data *QListData::detach3()
{
return detach(d->alloc);
}
void QListData::realloc(int alloc)
{ {
Q_ASSERT(d->ref == 1); 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); Q_CHECK_PTR(x);
d = x; d = x;
@ -240,7 +174,7 @@ void **QListData::append(int n)
::memmove(d->array, d->array + b, e * sizeof(void *)); ::memmove(d->array, d->array + b, e * sizeof(void *));
d->begin = 0; d->begin = 0;
} else { } else {
realloc(grow(d->alloc + n)); reallocData(grow(d->alloc + n));
} }
} }
d->end = e + n; d->end = e + n;
@ -254,25 +188,7 @@ void **QListData::append()
} }
// ensures that enough space is available to append the list // ensures that enough space is available to append the list
#if QT_VERSION >= 0x050000
# error "Remove QListData::append(), it is only required for binary compatibility up to 4.5.x"
#endif
void **QListData::append(const QListData& l) void **QListData::append(const QListData& l)
{
Q_ASSERT(d->ref == 1);
int e = d->end;
int n = l.d->end - l.d->begin;
if (n) {
if (e + n > d->alloc)
realloc(grow(e + n));
::memcpy(d->array + d->end, l.d->array + l.d->begin, n*sizeof(void*));
d->end += n;
}
return d->array + e;
}
// ensures that enough space is available to append the list
void **QListData::append2(const QListData& l)
{ {
return append(l.d->end - l.d->begin); return append(l.d->end - l.d->begin);
} }
@ -282,7 +198,7 @@ void **QListData::prepend()
Q_ASSERT(d->ref == 1); Q_ASSERT(d->ref == 1);
if (d->begin == 0) { if (d->begin == 0) {
if (d->end >= d->alloc / 3) if (d->end >= d->alloc / 3)
realloc(grow(d->alloc + 1)); reallocData(grow(d->alloc + 1));
if (d->end < d->alloc / 3) if (d->end < d->alloc / 3)
d->begin = d->alloc - 2 * d->end; d->begin = d->alloc - 2 * d->end;
@ -309,7 +225,7 @@ void **QListData::insert(int i)
if (d->begin == 0) { if (d->begin == 0) {
if (d->end == d->alloc) { if (d->end == d->alloc) {
// If the array is full, we expand it and move some items rightward // If the array is full, we expand it and move some items rightward
realloc(grow(d->alloc + 1)); reallocData(grow(d->alloc + 1));
} else { } else {
// If there is free space at the end of the array, we move some items rightward // If there is free space at the end of the array, we move some items rightward
} }

View file

@ -78,17 +78,13 @@ struct Q_CORE_EXPORT QListData {
Data *detach(int alloc); Data *detach(int alloc);
Data *detach_grow(int *i, int n); Data *detach_grow(int *i, int n);
Data *detach(); // remove in 5.0 void reallocData(int alloc);
Data *detach2(); // remove in 5.0
Data *detach3(); // remove in 5.0
void realloc(int alloc);
static Data shared_null; static Data shared_null;
Data *d; Data *d;
void **erase(void **xi); void **erase(void **xi);
void **append(int n); void **append(int n);
void **append(); void **append();
void **append(const QListData &l); void **append(const QListData &l);
void **append2(const QListData &l); // remove in 5.0
void **prepend(); void **prepend();
void **insert(int i); void **insert(int i);
void remove(int i); void remove(int i);
@ -338,7 +334,7 @@ private:
Node *detach_helper_grow(int i, int n); Node *detach_helper_grow(int i, int n);
void detach_helper(int alloc); void detach_helper(int alloc);
void detach_helper(); void detach_helper();
void free(QListData::Data *d); void freeData(QListData::Data *d);
void node_construct(Node *n, const T &t); void node_construct(Node *n, const T &t);
void node_destruct(Node *n); void node_destruct(Node *n);
@ -485,7 +481,7 @@ Q_OUTOFLINE_TEMPLATE void QList<T>::reserve(int alloc)
if (d->ref != 1) if (d->ref != 1)
detach_helper(alloc); detach_helper(alloc);
else else
p.realloc(alloc); p.reallocData(alloc);
} }
} }
@ -667,7 +663,7 @@ Q_OUTOFLINE_TEMPLATE typename QList<T>::Node *QList<T>::detach_helper_grow(int i
node_copy(reinterpret_cast<Node *>(p.begin()), node_copy(reinterpret_cast<Node *>(p.begin()),
reinterpret_cast<Node *>(p.begin() + i), n); reinterpret_cast<Node *>(p.begin() + i), n);
} QT_CATCH(...) { } QT_CATCH(...) {
qFree(d); free(d);
d = x; d = x;
QT_RETHROW; QT_RETHROW;
} }
@ -677,7 +673,7 @@ Q_OUTOFLINE_TEMPLATE typename QList<T>::Node *QList<T>::detach_helper_grow(int i
} QT_CATCH(...) { } QT_CATCH(...) {
node_destruct(reinterpret_cast<Node *>(p.begin()), node_destruct(reinterpret_cast<Node *>(p.begin()),
reinterpret_cast<Node *>(p.begin() + i)); reinterpret_cast<Node *>(p.begin() + i));
qFree(d); free(d);
d = x; d = x;
QT_RETHROW; QT_RETHROW;
} }
@ -696,7 +692,7 @@ Q_OUTOFLINE_TEMPLATE void QList<T>::detach_helper(int alloc)
QT_TRY { QT_TRY {
node_copy(reinterpret_cast<Node *>(p.begin()), reinterpret_cast<Node *>(p.end()), n); node_copy(reinterpret_cast<Node *>(p.begin()), reinterpret_cast<Node *>(p.end()), n);
} QT_CATCH(...) { } QT_CATCH(...) {
qFree(d); free(d);
d = x; d = x;
QT_RETHROW; QT_RETHROW;
} }
@ -736,13 +732,12 @@ Q_OUTOFLINE_TEMPLATE bool QList<T>::operator==(const QList<T> &l) const
return true; return true;
} }
// ### Qt 5: rename freeData() to avoid confusion with std::free()
template <typename T> template <typename T>
Q_OUTOFLINE_TEMPLATE void QList<T>::free(QListData::Data *data) Q_OUTOFLINE_TEMPLATE void QList<T>::freeData(QListData::Data *data)
{ {
node_destruct(reinterpret_cast<Node *>(data->array + data->begin), node_destruct(reinterpret_cast<Node *>(data->array + data->begin),
reinterpret_cast<Node *>(data->array + data->end)); reinterpret_cast<Node *>(data->array + data->end));
qFree(data); free(data);
} }
@ -809,7 +804,7 @@ Q_OUTOFLINE_TEMPLATE QList<T> &QList<T>::operator+=(const QList<T> &l)
} else { } else {
Node *n = (d->ref != 1) Node *n = (d->ref != 1)
? detach_helper_grow(INT_MAX, l.size()) ? detach_helper_grow(INT_MAX, l.size())
: reinterpret_cast<Node *>(p.append2(l.p)); : reinterpret_cast<Node *>(p.append(l.p));
QT_TRY { QT_TRY {
node_copy(n, reinterpret_cast<Node *>(p.end()), node_copy(n, reinterpret_cast<Node *>(p.end()),
reinterpret_cast<Node *>(l.p.begin())); reinterpret_cast<Node *>(l.p.begin()));

View file

@ -85,7 +85,7 @@ void QMapData::continueFreeData(int offset)
if (strictAlignment) if (strictAlignment)
qFreeAligned(reinterpret_cast<char *>(prev) - offset); qFreeAligned(reinterpret_cast<char *>(prev) - offset);
else else
qFree(reinterpret_cast<char *>(prev) - offset); free(reinterpret_cast<char *>(prev) - offset);
} }
delete this; delete this;
} }
@ -127,7 +127,7 @@ QMapData::Node *QMapData::node_create(Node *update[], int offset, int alignment)
void *concreteNode = strictAlignment ? void *concreteNode = strictAlignment ?
qMallocAligned(offset + sizeof(Node) + level * sizeof(Node *), alignment) : 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); Q_CHECK_PTR(concreteNode);
Node *abstractNode = reinterpret_cast<Node *>(reinterpret_cast<char *>(concreteNode) + offset); 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) if (strictAlignment)
qFreeAligned(reinterpret_cast<char *>(node) - offset); qFreeAligned(reinterpret_cast<char *>(node) - offset);
else else
qFree(reinterpret_cast<char *>(node) - offset); free(reinterpret_cast<char *>(node) - offset);
} }
#ifdef QT_QMAP_DEBUG #ifdef QT_QMAP_DEBUG

View file

@ -79,7 +79,7 @@ struct QScopedPointerArrayDeleter
struct QScopedPointerPodDeleter struct QScopedPointerPodDeleter
{ {
static inline void cleanup(void *pointer) { if (pointer) qFree(pointer); } static inline void cleanup(void *pointer) { if (pointer) free(pointer); }
}; };
template <typename T, typename Cleanup = QScopedPointerDeleter<T> > template <typename T, typename Cleanup = QScopedPointerDeleter<T> >

View file

@ -1049,7 +1049,7 @@ QString::QString(const QChar *unicode, int size)
d = &shared_empty; d = &shared_empty;
d->ref.ref(); d->ref.ref();
} else { } else {
d = (Data*) qMalloc(sizeof(Data)+size*sizeof(QChar)); d = (Data*) malloc(sizeof(Data)+size*sizeof(QChar));
Q_CHECK_PTR(d); Q_CHECK_PTR(d);
d->ref = 1; d->ref = 1;
d->alloc = d->size = size; d->alloc = d->size = size;
@ -1082,7 +1082,7 @@ QString::QString(const QChar *unicode)
d = &shared_empty; d = &shared_empty;
d->ref.ref(); d->ref.ref();
} else { } else {
d = (Data*) qMalloc(sizeof(Data)+size*sizeof(QChar)); d = (Data*) malloc(sizeof(Data)+size*sizeof(QChar));
Q_CHECK_PTR(d); Q_CHECK_PTR(d);
d->ref = 1; d->ref = 1;
d->alloc = d->size = size; d->alloc = d->size = size;
@ -1107,7 +1107,7 @@ QString::QString(int size, QChar ch)
d = &shared_empty; d = &shared_empty;
d->ref.ref(); d->ref.ref();
} else { } else {
d = (Data*) qMalloc(sizeof(Data)+size*sizeof(QChar)); d = (Data*) malloc(sizeof(Data)+size*sizeof(QChar));
Q_CHECK_PTR(d); Q_CHECK_PTR(d);
d->ref = 1; d->ref = 1;
d->alloc = d->size = size; d->alloc = d->size = size;
@ -1130,7 +1130,7 @@ QString::QString(int size, QChar ch)
*/ */
QString::QString(int size, Qt::Initialization) QString::QString(int size, Qt::Initialization)
{ {
d = (Data*) qMalloc(sizeof(Data)+size*sizeof(QChar)); d = (Data*) malloc(sizeof(Data)+size*sizeof(QChar));
Q_CHECK_PTR(d); Q_CHECK_PTR(d);
d->ref = 1; d->ref = 1;
d->alloc = d->size = size; d->alloc = d->size = size;
@ -1151,7 +1151,7 @@ QString::QString(int size, Qt::Initialization)
*/ */
QString::QString(QChar ch) QString::QString(QChar ch)
{ {
void *buf = qMalloc(sizeof(Data) + sizeof(QChar)); void *buf = malloc(sizeof(Data) + sizeof(QChar));
Q_CHECK_PTR(buf); Q_CHECK_PTR(buf);
d = reinterpret_cast<Data *>(buf); d = reinterpret_cast<Data *>(buf);
d->ref = 1; d->ref = 1;
@ -1214,10 +1214,9 @@ QString::QString(QChar ch)
\internal \internal
*/ */
// ### Qt 5: rename freeData() to avoid confusion. See task 197625. void QString::freeData(Data *d)
void QString::free(Data *d)
{ {
qFree(d); free(d);
} }
/*! /*!
@ -1259,12 +1258,12 @@ void QString::resize(int size)
Data *x = &shared_empty; Data *x = &shared_empty;
x->ref.ref(); x->ref.ref();
if (!d->ref.deref()) if (!d->ref.deref())
QString::free(d); QString::freeData(d);
d = x; d = x;
} else { } else {
if (d->ref != 1 || size > d->alloc || if (d->ref != 1 || size > d->alloc ||
(!d->capacity && size < d->size && size < d->alloc >> 1)) (!d->capacity && size < d->size && size < d->alloc >> 1))
realloc(grow(size)); reallocData(grow(size));
if (d->alloc >= size) { if (d->alloc >= size) {
d->size = size; d->size = size;
if (d->data == d->array) { if (d->data == d->array) {
@ -1324,11 +1323,10 @@ void QString::resize(int size)
\sa reserve(), capacity() \sa reserve(), capacity()
*/ */
// ### Qt 5: rename reallocData() to avoid confusion. 197625 void QString::reallocData(int alloc)
void QString::realloc(int alloc)
{ {
if (d->ref != 1 || d->data != d->array) { if (d->ref != 1 || d->data != d->array) {
Data *x = static_cast<Data *>(qMalloc(sizeof(Data) + alloc * sizeof(QChar))); Data *x = static_cast<Data *>(malloc(sizeof(Data) + alloc * sizeof(QChar)));
Q_CHECK_PTR(x); Q_CHECK_PTR(x);
x->size = qMin(alloc, d->size); x->size = qMin(alloc, d->size);
::memcpy(x->array, d->data, x->size * sizeof(QChar)); ::memcpy(x->array, d->data, x->size * sizeof(QChar));
@ -1341,10 +1339,10 @@ void QString::realloc(int alloc)
x->capacity = d->capacity; x->capacity = d->capacity;
x->data = x->array; x->data = x->array;
if (!d->ref.deref()) if (!d->ref.deref())
QString::free(d); QString::freeData(d);
d = x; d = x;
} else { } else {
Data *p = static_cast<Data *>(qRealloc(d, sizeof(Data) + alloc * sizeof(QChar))); Data *p = static_cast<Data *>(realloc(d, sizeof(Data) + alloc * sizeof(QChar)));
Q_CHECK_PTR(p); Q_CHECK_PTR(p);
d = p; d = p;
d->alloc = alloc; d->alloc = alloc;
@ -1352,9 +1350,9 @@ void QString::realloc(int alloc)
} }
} }
void QString::realloc() void QString::reallocData()
{ {
realloc(d->size); reallocData(d->size);
} }
void QString::expand(int i) void QString::expand(int i)
@ -1386,7 +1384,7 @@ QString &QString::operator=(const QString &other)
{ {
other.d->ref.ref(); other.d->ref.ref();
if (!d->ref.deref()) if (!d->ref.deref())
QString::free(d); QString::freeData(d);
d = other.d; d = other.d;
return *this; return *this;
} }
@ -1502,11 +1500,11 @@ QString& QString::insert(int i, const QChar *unicode, int size)
const ushort *s = (const ushort *)unicode; const ushort *s = (const ushort *)unicode;
if (s >= d->data && s < d->data + d->alloc) { if (s >= d->data && s < d->data + d->alloc) {
// Part of me - take a copy // 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); Q_CHECK_PTR(tmp);
memcpy(tmp, s, size * sizeof(QChar)); memcpy(tmp, s, size * sizeof(QChar));
insert(i, reinterpret_cast<const QChar *>(tmp), size); insert(i, reinterpret_cast<const QChar *>(tmp), size);
qFree(tmp); free(tmp);
return *this; return *this;
} }
@ -1561,7 +1559,7 @@ QString &QString::append(const QString &str)
operator=(str); operator=(str);
} else { } else {
if (d->ref != 1 || d->size + str.d->size > d->alloc) if (d->ref != 1 || d->size + str.d->size > d->alloc)
realloc(grow(d->size + str.d->size)); reallocData(grow(d->size + str.d->size));
memcpy(d->data + d->size, str.d->data, str.d->size * sizeof(QChar)); memcpy(d->data + d->size, str.d->data, str.d->size * sizeof(QChar));
d->size += str.d->size; d->size += str.d->size;
d->data[d->size] = '\0'; d->data[d->size] = '\0';
@ -1581,7 +1579,7 @@ QString &QString::append(const QLatin1String &str)
if (s) { if (s) {
int len = qstrlen((char *)s); int len = qstrlen((char *)s);
if (d->ref != 1 || d->size + len > d->alloc) if (d->ref != 1 || d->size + len > d->alloc)
realloc(grow(d->size + len)); reallocData(grow(d->size + len));
ushort *i = d->data + d->size; ushort *i = d->data + d->size;
while ((*i++ = *s++)) while ((*i++ = *s++))
; ;
@ -1624,7 +1622,7 @@ QString &QString::append(const QLatin1String &str)
QString &QString::append(QChar ch) QString &QString::append(QChar ch)
{ {
if (d->ref != 1 || d->size + 1 > d->alloc) if (d->ref != 1 || d->size + 1 > d->alloc)
realloc(grow(d->size + 1)); reallocData(grow(d->size + 1));
d->data[d->size++] = ch.unicode(); d->data[d->size++] = ch.unicode();
d->data[d->size] = '\0'; d->data[d->size] = '\0';
return *this; return *this;
@ -1862,7 +1860,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.) // (which we could possibly invalidate via a realloc or corrupt via memcpy operations.)
QChar *afterBuffer = const_cast<QChar *>(after); QChar *afterBuffer = const_cast<QChar *>(after);
if (after >= reinterpret_cast<QChar *>(d->data) && after < reinterpret_cast<QChar *>(d->data) + d->size) { 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); Q_CHECK_PTR(afterBuffer);
::memcpy(afterBuffer, after, alen*sizeof(QChar)); ::memcpy(afterBuffer, after, alen*sizeof(QChar));
} }
@ -1917,11 +1915,11 @@ void QString::replace_helper(uint *indices, int nIndices, int blen, const QChar
} }
} QT_CATCH(const std::bad_alloc &) { } QT_CATCH(const std::bad_alloc &) {
if (afterBuffer != after) if (afterBuffer != after)
qFree(afterBuffer); free(afterBuffer);
QT_RETHROW; QT_RETHROW;
} }
if (afterBuffer != after) if (afterBuffer != after)
qFree(afterBuffer); free(afterBuffer);
} }
/*! /*!
@ -2824,7 +2822,7 @@ QString& QString::replace(const QRegExp &rx, const QString &after)
if (isEmpty() && rx2.indexIn(*this) == -1) if (isEmpty() && rx2.indexIn(*this) == -1)
return *this; return *this;
realloc(); reallocData();
int index = 0; int index = 0;
int numCaptures = rx2.captureCount(); int numCaptures = rx2.captureCount();
@ -3801,7 +3799,7 @@ QString::Data *QString::fromLatin1_helper(const char *str, int size)
} else { } else {
if (size < 0) if (size < 0)
size = qstrlen(str); size = qstrlen(str);
d = static_cast<Data *>(qMalloc(sizeof(Data) + size * sizeof(QChar))); d = static_cast<Data *>(malloc(sizeof(Data) + size * sizeof(QChar)));
Q_CHECK_PTR(d); Q_CHECK_PTR(d);
d->ref = 1; d->ref = 1;
d->alloc = d->size = size; d->alloc = d->size = size;
@ -4855,7 +4853,7 @@ const ushort *QString::utf16() const
{ {
if (d->data != d->array) { if (d->data != d->array) {
QString *that = const_cast<QString*>(this); QString *that = const_cast<QString*>(this);
that->realloc(); // ensure '\\0'-termination for ::fromRawData strings that->reallocData(); // ensure '\\0'-termination for ::fromRawData strings
return that->d->data; return that->d->data;
} }
return d->array; return d->array;
@ -7134,7 +7132,7 @@ bool QString::isRightToLeft() const
*/ */
QString QString::fromRawData(const QChar *unicode, int size) QString QString::fromRawData(const QChar *unicode, int size)
{ {
Data *x = static_cast<Data *>(qMalloc(sizeof(Data))); Data *x = static_cast<Data *>(malloc(sizeof(Data)));
Q_CHECK_PTR(x); Q_CHECK_PTR(x);
if (unicode) { if (unicode) {
x->data = (ushort *)unicode; x->data = (ushort *)unicode;

View file

@ -107,7 +107,7 @@ public:
int capacity() const; int capacity() const;
inline void reserve(int size); inline void reserve(int size);
inline void squeeze() { if (d->size < d->alloc || d->ref != 1) realloc(); d->capacity = 0;} inline void squeeze() { if (d->size < d->alloc || d->ref != 1) reallocData(); d->capacity = 0;}
inline const QChar *unicode() const; inline const QChar *unicode() const;
inline QChar *data(); inline QChar *data();
@ -260,7 +260,7 @@ public:
inline QString &operator+=(QChar c) { inline QString &operator+=(QChar c) {
if (d->ref != 1 || d->size + 1 > d->alloc) if (d->ref != 1 || d->size + 1 > d->alloc)
realloc(grow(d->size + 1)); reallocData(grow(d->size + 1));
d->data[d->size++] = c.unicode(); d->data[d->size++] = c.unicode();
d->data[d->size] = '\0'; d->data[d->size] = '\0';
return *this; return *this;
@ -526,9 +526,9 @@ private:
static QTextCodec *codecForCStrings; static QTextCodec *codecForCStrings;
#endif #endif
static int grow(int); static int grow(int);
static void free(Data *); static void freeData(Data *);
void realloc(); void reallocData();
void realloc(int alloc); void reallocData(int alloc);
void expand(int i); void expand(int i);
void updateProperties() const; void updateProperties() const;
QString multiArg(int numArgs, const QString **args) const; QString multiArg(int numArgs, const QString **args) const;
@ -617,7 +617,7 @@ inline QChar *QString::data()
inline const QChar *QString::constData() const inline const QChar *QString::constData() const
{ return reinterpret_cast<const QChar*>(d->data); } { return reinterpret_cast<const QChar*>(d->data); }
inline void QString::detach() inline void QString::detach()
{ if (d->ref != 1 || d->data != d->array) realloc(); } { if (d->ref != 1 || d->data != d->array) reallocData(); }
inline bool QString::isDetached() const inline bool QString::isDetached() const
{ return d->ref == 1; } { return d->ref == 1; }
inline QString &QString::operator=(const QLatin1String &s) inline QString &QString::operator=(const QLatin1String &s)
@ -770,8 +770,8 @@ inline void QCharRef::setCell(uchar acell) { QChar(*this).setCell(acell); }
inline QString::QString() : d(&shared_null) { d->ref.ref(); } inline QString::QString() : d(&shared_null) { d->ref.ref(); }
inline QString::~QString() { if (!d->ref.deref()) free(d); } inline QString::~QString() { if (!d->ref.deref()) freeData(d); }
inline void QString::reserve(int asize) { if (d->ref != 1 || asize > d->alloc) realloc(asize); d->capacity = 1;} inline void QString::reserve(int asize) { if (d->ref != 1 || asize > d->alloc) reallocData(asize); d->capacity = 1;}
inline QString &QString::setUtf16(const ushort *autf16, int asize) inline QString &QString::setUtf16(const ushort *autf16, int asize)
{ return setUnicode(reinterpret_cast<const QChar *>(autf16), asize); } { return setUnicode(reinterpret_cast<const QChar *>(autf16), asize); }
inline QCharRef QString::operator[](int i) inline QCharRef QString::operator[](int i)

View file

@ -75,7 +75,7 @@ public:
i->~T(); i->~T();
} }
if (ptr != reinterpret_cast<T *>(array)) if (ptr != reinterpret_cast<T *>(array))
qFree(ptr); free(ptr);
} }
inline QVarLengthArray<T, Prealloc> &operator=(const QVarLengthArray<T, Prealloc> &other) inline QVarLengthArray<T, Prealloc> &operator=(const QVarLengthArray<T, Prealloc> &other)
{ {
@ -181,7 +181,7 @@ template <class T, int Prealloc>
Q_INLINE_TEMPLATE QVarLengthArray<T, Prealloc>::QVarLengthArray(int asize) Q_INLINE_TEMPLATE QVarLengthArray<T, Prealloc>::QVarLengthArray(int asize)
: s(asize) { : s(asize) {
if (s > Prealloc) { if (s > Prealloc) {
ptr = reinterpret_cast<T *>(qMalloc(s * sizeof(T))); ptr = reinterpret_cast<T *>(malloc(s * sizeof(T)));
Q_CHECK_PTR(ptr); Q_CHECK_PTR(ptr);
a = s; a = s;
} else { } else {
@ -234,7 +234,7 @@ Q_OUTOFLINE_TEMPLATE void QVarLengthArray<T, Prealloc>::realloc(int asize, int a
const int copySize = qMin(asize, osize); const int copySize = qMin(asize, osize);
if (aalloc != a) { if (aalloc != a) {
ptr = reinterpret_cast<T *>(qMalloc(aalloc * sizeof(T))); ptr = reinterpret_cast<T *>(malloc(aalloc * sizeof(T)));
Q_CHECK_PTR(ptr); Q_CHECK_PTR(ptr);
if (ptr) { if (ptr) {
s = 0; s = 0;
@ -254,7 +254,7 @@ Q_OUTOFLINE_TEMPLATE void QVarLengthArray<T, Prealloc>::realloc(int asize, int a
while (sClean < osize) while (sClean < osize)
(oldPtr+(sClean++))->~T(); (oldPtr+(sClean++))->~T();
if (oldPtr != reinterpret_cast<T *>(array) && oldPtr != ptr) if (oldPtr != reinterpret_cast<T *>(array) && oldPtr != ptr)
qFree(oldPtr); free(oldPtr);
QT_RETHROW; QT_RETHROW;
} }
} else { } else {
@ -274,7 +274,7 @@ Q_OUTOFLINE_TEMPLATE void QVarLengthArray<T, Prealloc>::realloc(int asize, int a
} }
if (oldPtr != reinterpret_cast<T *>(array) && oldPtr != ptr) if (oldPtr != reinterpret_cast<T *>(array) && oldPtr != ptr)
qFree(oldPtr); free(oldPtr);
if (QTypeInfo<T>::isComplex) { if (QTypeInfo<T>::isComplex) {
// call default constructor for new objects (which can throw) // call default constructor for new objects (which can throw)

View file

@ -54,32 +54,24 @@ static inline int alignmentThreshold()
QVectorData QVectorData::shared_null = { Q_BASIC_ATOMIC_INITIALIZER(1), 0, 0, true, false, 0 }; QVectorData QVectorData::shared_null = { Q_BASIC_ATOMIC_INITIALIZER(1), 0, 0, true, false, 0 };
QVectorData *QVectorData::malloc(int sizeofTypedData, int size, int sizeofT, QVectorData *init)
{
QVectorData* p = (QVectorData *)qMalloc(sizeofTypedData + (size - 1) * sizeofT);
Q_CHECK_PTR(p);
::memcpy(p, init, sizeofTypedData + (qMin(size, init->alloc) - 1) * sizeofT);
return p;
}
QVectorData *QVectorData::allocate(int size, int alignment) 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) QVectorData *QVectorData::reallocate(QVectorData *x, int newsize, int oldsize, int alignment)
{ {
if (alignment > alignmentThreshold()) if (alignment > alignmentThreshold())
return static_cast<QVectorData *>(qReallocAligned(x, newsize, oldsize, alignment)); 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) void QVectorData::freeData(QVectorData *x, int alignment)
{ {
if (alignment > alignmentThreshold()) if (alignment > alignmentThreshold())
qFreeAligned(x); qFreeAligned(x);
else else
qFree(x); free(x);
} }
int QVectorData::grow(int sizeofTypedData, int size, int sizeofT, bool excessive) int QVectorData::grow(int sizeofTypedData, int size, int sizeofT, bool excessive)

View file

@ -69,13 +69,9 @@ struct Q_CORE_EXPORT QVectorData
#endif #endif
static QVectorData shared_null; static QVectorData shared_null;
// ### Qt 5: rename to 'allocate()'. The current name causes problems for
// some debugges when the QVector is member of a class within an unnamed namespace.
// ### Qt 5: can be removed completely. (Ralf)
static QVectorData *malloc(int sizeofTypedData, int size, int sizeofT, QVectorData *init);
static QVectorData *allocate(int size, int alignment); static QVectorData *allocate(int size, int alignment);
static QVectorData *reallocate(QVectorData *old, int newsize, int oldsize, int alignment); static QVectorData *reallocate(QVectorData *old, int newsize, int oldsize, int alignment);
static void free(QVectorData *data, int alignment); static void freeData(QVectorData *data, int alignment);
static int grow(int sizeofTypedData, int size, int sizeofT, bool excessive); static int grow(int sizeofTypedData, int size, int sizeofT, bool excessive);
}; };
@ -85,7 +81,7 @@ struct QVectorTypedData : private QVectorData
// as this would break strict aliasing rules. (in the case of shared_null) // as this would break strict aliasing rules. (in the case of shared_null)
T array[1]; T array[1];
static inline void free(QVectorTypedData<T> *x, int alignment) { QVectorData::free(static_cast<QVectorData *>(x), alignment); } static inline void free(QVectorTypedData<T> *x, int alignment) { QVectorData::freeData(static_cast<QVectorData *>(x), alignment); }
}; };
class QRegion; class QRegion;

View file

@ -891,9 +891,9 @@ void QXmlStreamReaderPrivate::parseEntity(const QString &value)
inline void QXmlStreamReaderPrivate::reallocateStack() inline void QXmlStreamReaderPrivate::reallocateStack()
{ {
stack_size <<= 1; stack_size <<= 1;
sym_stack = reinterpret_cast<Value*> (qRealloc(sym_stack, stack_size * sizeof(Value))); sym_stack = reinterpret_cast<Value*> (realloc(sym_stack, stack_size * sizeof(Value)));
Q_CHECK_PTR(sym_stack); Q_CHECK_PTR(sym_stack);
state_stack = reinterpret_cast<int*> (qRealloc(state_stack, stack_size * sizeof(int))); state_stack = reinterpret_cast<int*> (realloc(state_stack, stack_size * sizeof(int)));
Q_CHECK_PTR(sym_stack); Q_CHECK_PTR(sym_stack);
} }
@ -903,8 +903,8 @@ QXmlStreamReaderPrivate::~QXmlStreamReaderPrivate()
#ifndef QT_NO_TEXTCODEC #ifndef QT_NO_TEXTCODEC
delete decoder; delete decoder;
#endif #endif
qFree(sym_stack); free(sym_stack);
qFree(state_stack); free(state_stack);
delete entityParser; delete entityParser;
} }

View file

@ -152,12 +152,12 @@ template <typename T> class QXmlStreamSimpleStack {
int tos, cap; int tos, cap;
public: public:
inline QXmlStreamSimpleStack():data(0), tos(-1), cap(0){} inline QXmlStreamSimpleStack():data(0), tos(-1), cap(0){}
inline ~QXmlStreamSimpleStack(){ if (data) qFree(data); } inline ~QXmlStreamSimpleStack(){ if (data) free(data); }
inline void reserve(int extraCapacity) { inline void reserve(int extraCapacity) {
if (tos + extraCapacity + 1 > cap) { if (tos + extraCapacity + 1 > cap) {
cap = qMax(tos + extraCapacity + 1, cap << 1 ); cap = qMax(tos + extraCapacity + 1, cap << 1 );
data = reinterpret_cast<T *>(qRealloc(data, cap * sizeof(T))); data = reinterpret_cast<T *>(realloc(data, cap * sizeof(T)));
Q_CHECK_PTR(data); Q_CHECK_PTR(data);
} }
} }

View file

@ -646,12 +646,12 @@ template <typename T> class QXmlStreamSimpleStack {
int tos, cap; int tos, cap;
public: public:
inline QXmlStreamSimpleStack():data(0), tos(-1), cap(0){} inline QXmlStreamSimpleStack():data(0), tos(-1), cap(0){}
inline ~QXmlStreamSimpleStack(){ if (data) qFree(data); } inline ~QXmlStreamSimpleStack(){ if (data) free(data); }
inline void reserve(int extraCapacity) { inline void reserve(int extraCapacity) {
if (tos + extraCapacity + 1 > cap) { if (tos + extraCapacity + 1 > cap) {
cap = qMax(tos + extraCapacity + 1, cap << 1 ); cap = qMax(tos + extraCapacity + 1, cap << 1 );
data = reinterpret_cast<T *>(qRealloc(data, cap * sizeof(T))); data = reinterpret_cast<T *>(realloc(data, cap * sizeof(T)));
Q_CHECK_PTR(data); Q_CHECK_PTR(data);
} }
} }

View file

@ -393,9 +393,9 @@ void Parser::reallocateStack()
else else
stack_size <<= 1; stack_size <<= 1;
sym_stack = reinterpret_cast<Value*> (qRealloc(sym_stack, stack_size * sizeof(Value))); sym_stack = reinterpret_cast<Value*> (realloc(sym_stack, stack_size * sizeof(Value)));
state_stack = reinterpret_cast<int*> (qRealloc(state_stack, stack_size * sizeof(int))); state_stack = reinterpret_cast<int*> (realloc(state_stack, stack_size * sizeof(int)));
location_stack = reinterpret_cast<AST::SourceLocation*> (qRealloc(location_stack, stack_size * sizeof(AST::SourceLocation))); location_stack = reinterpret_cast<AST::SourceLocation*> (realloc(location_stack, stack_size * sizeof(AST::SourceLocation)));
} }
inline static bool automatic(Engine *driver, int token) inline static bool automatic(Engine *driver, int token)
@ -421,9 +421,9 @@ Parser::Parser(Engine *engine):
Parser::~Parser() Parser::~Parser()
{ {
if (stack_size) { if (stack_size) {
qFree(sym_stack); free(sym_stack);
qFree(state_stack); free(state_stack);
qFree(location_stack); free(location_stack);
} }
} }

View file

@ -78,9 +78,9 @@ public:
virtual ~MemoryPool() { virtual ~MemoryPool() {
for (int index = 0; index < m_blockIndex + 1; ++index) for (int index = 0; index < m_blockIndex + 1; ++index)
qFree(m_storage[index]); free(m_storage[index]);
qFree(m_storage); free(m_storage);
} }
char *allocate(int bytes) { char *allocate(int bytes) {
@ -89,8 +89,8 @@ public:
++m_blockIndex; ++m_blockIndex;
m_currentBlockSize = defaultBlockSize << m_blockIndex; m_currentBlockSize = defaultBlockSize << m_blockIndex;
m_storage = reinterpret_cast<char**>(qRealloc(m_storage, sizeof(char*) * (1 + m_blockIndex))); m_storage = reinterpret_cast<char**>(realloc(m_storage, sizeof(char*) * (1 + m_blockIndex)));
m_currentBlock = m_storage[m_blockIndex] = reinterpret_cast<char*>(qMalloc(m_currentBlockSize)); m_currentBlock = m_storage[m_blockIndex] = reinterpret_cast<char*>(malloc(m_currentBlockSize));
::memset(m_currentBlock, 0, m_currentBlockSize); ::memset(m_currentBlock, 0, m_currentBlockSize);
m_currentIndex = (8 - quintptr(m_currentBlock)) & 7; // ensure first chunk is 64-bit aligned m_currentIndex = (8 - quintptr(m_currentBlock)) & 7; // ensure first chunk is 64-bit aligned

View file

@ -70,9 +70,9 @@ void Parser::reallocateStack()
else else
stack_size <<= 1; stack_size <<= 1;
sym_stack = reinterpret_cast<Value*> (qRealloc(sym_stack, stack_size * sizeof(Value))); sym_stack = reinterpret_cast<Value*> (realloc(sym_stack, stack_size * sizeof(Value)));
state_stack = reinterpret_cast<int*> (qRealloc(state_stack, stack_size * sizeof(int))); state_stack = reinterpret_cast<int*> (realloc(state_stack, stack_size * sizeof(int)));
location_stack = reinterpret_cast<AST::SourceLocation*> (qRealloc(location_stack, stack_size * sizeof(AST::SourceLocation))); location_stack = reinterpret_cast<AST::SourceLocation*> (realloc(location_stack, stack_size * sizeof(AST::SourceLocation)));
} }
inline static bool automatic(Engine *driver, int token) inline static bool automatic(Engine *driver, int token)
@ -98,9 +98,9 @@ Parser::Parser(Engine *engine):
Parser::~Parser() Parser::~Parser()
{ {
if (stack_size) { if (stack_size) {
qFree(sym_stack); free(sym_stack);
qFree(state_stack); free(state_stack);
qFree(location_stack); free(location_stack);
} }
} }

View file

@ -286,7 +286,7 @@ QDeclarativeBoundSignalParameters::QDeclarativeBoundSignalParameters(const QMeta
QDeclarativeBoundSignalParameters::~QDeclarativeBoundSignalParameters() QDeclarativeBoundSignalParameters::~QDeclarativeBoundSignalParameters()
{ {
delete [] types; delete [] types;
qFree(myMetaObject); free(myMetaObject);
} }
void QDeclarativeBoundSignalParameters::setValues(void **v) void QDeclarativeBoundSignalParameters::setValues(void **v)

View file

@ -1378,7 +1378,7 @@ static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf,
QMetaObject *QMetaObjectBuilder::toMetaObject() const QMetaObject *QMetaObjectBuilder::toMetaObject() const
{ {
int size = buildMetaObject(d, 0, false); int size = buildMetaObject(d, 0, false);
char *buf = reinterpret_cast<char *>(qMalloc(size)); char *buf = reinterpret_cast<char *>(malloc(size));
memset(buf, 0, size); memset(buf, 0, size);
buildMetaObject(d, buf, false); buildMetaObject(d, buf, false);
return reinterpret_cast<QMetaObject *>(buf); return reinterpret_cast<QMetaObject *>(buf);

View file

@ -75,7 +75,7 @@ QDeclarativeOpenMetaObjectType::QDeclarativeOpenMetaObjectType(const QMetaObject
QDeclarativeOpenMetaObjectType::~QDeclarativeOpenMetaObjectType() QDeclarativeOpenMetaObjectType::~QDeclarativeOpenMetaObjectType()
{ {
if (d->mem) if (d->mem)
qFree(d->mem); free(d->mem);
if (d->cache) if (d->cache)
d->cache->release(); d->cache->release();
delete d; delete d;
@ -98,7 +98,7 @@ int QDeclarativeOpenMetaObjectType::createProperty(const QByteArray &name)
d->mob.addSignal("__" + QByteArray::number(id) + "()"); d->mob.addSignal("__" + QByteArray::number(id) + "()");
QMetaPropertyBuilder build = d->mob.addProperty(name, "QVariant", id); QMetaPropertyBuilder build = d->mob.addProperty(name, "QVariant", id);
propertyCreated(id, build); propertyCreated(id, build);
qFree(d->mem); free(d->mem);
d->mem = d->mob.toMetaObject(); d->mem = d->mob.toMetaObject();
d->names.insert(name, id); d->names.insert(name, id);
QSet<QDeclarativeOpenMetaObject*>::iterator it = d->referers.begin(); QSet<QDeclarativeOpenMetaObject*>::iterator it = d->referers.begin();

View file

@ -202,7 +202,7 @@ QPixmap QPixmap::fromWinHBITMAP(HBITMAP bitmap, HBitmapFormat format)
QImage result; QImage result;
// Get bitmap bits // Get bitmap bits
uchar *data = (uchar *) qMalloc(bmi.bmiHeader.biSizeImage); uchar *data = (uchar *) malloc(bmi.bmiHeader.biSizeImage);
HDC display_dc = GetDC(0); HDC display_dc = GetDC(0);
if (GetDIBits(display_dc, bitmap, 0, h, data, &bmi, DIB_RGB_COLORS)) { if (GetDIBits(display_dc, bitmap, 0, h, data, &bmi, DIB_RGB_COLORS)) {
@ -235,7 +235,7 @@ QPixmap QPixmap::fromWinHBITMAP(HBITMAP bitmap, HBitmapFormat format)
qWarning("QPixmap::fromWinHBITMAP(), failed to get bitmap bits"); qWarning("QPixmap::fromWinHBITMAP(), failed to get bitmap bits");
} }
ReleaseDC(0, display_dc); ReleaseDC(0, display_dc);
qFree(data); free(data);
return fromImage(result); return fromImage(result);
} }
@ -297,7 +297,7 @@ static QImage qt_fromWinHBITMAP(HDC hdc, HBITMAP bitmap, int w, int h)
return image; return image;
// Get bitmap bits // Get bitmap bits
uchar *data = (uchar *) qMalloc(bmi.bmiHeader.biSizeImage); uchar *data = (uchar *) malloc(bmi.bmiHeader.biSizeImage);
if (GetDIBits(hdc, bitmap, 0, h, data, &bmi, DIB_RGB_COLORS)) { if (GetDIBits(hdc, bitmap, 0, h, data, &bmi, DIB_RGB_COLORS)) {
// Create image and copy data into image. // Create image and copy data into image.
@ -309,7 +309,7 @@ static QImage qt_fromWinHBITMAP(HDC hdc, HBITMAP bitmap, int w, int h)
} else { } else {
qWarning("qt_fromWinHBITMAP(), failed to get bitmap bits"); qWarning("qt_fromWinHBITMAP(), failed to get bitmap bits");
} }
qFree(data); free(data);
return image; return image;
} }

View file

@ -503,13 +503,13 @@ bool QTiffHandler::write(const QImage &image)
} }
//// write the color table //// write the color table
// allocate the color tables // allocate the color tables
uint16 *redTable = static_cast<uint16 *>(qMalloc(256 * sizeof(uint16))); uint16 *redTable = static_cast<uint16 *>(malloc(256 * sizeof(uint16)));
uint16 *greenTable = static_cast<uint16 *>(qMalloc(256 * sizeof(uint16))); uint16 *greenTable = static_cast<uint16 *>(malloc(256 * sizeof(uint16)));
uint16 *blueTable = static_cast<uint16 *>(qMalloc(256 * sizeof(uint16))); uint16 *blueTable = static_cast<uint16 *>(malloc(256 * sizeof(uint16)));
if (!redTable || !greenTable || !blueTable) { if (!redTable || !greenTable || !blueTable) {
qFree(redTable); free(redTable);
qFree(greenTable); free(greenTable);
qFree(blueTable); free(blueTable);
TIFFClose(tiff); TIFFClose(tiff);
return false; return false;
} }
@ -526,9 +526,9 @@ bool QTiffHandler::write(const QImage &image)
const bool setColorTableSuccess = TIFFSetField(tiff, TIFFTAG_COLORMAP, redTable, greenTable, blueTable); const bool setColorTableSuccess = TIFFSetField(tiff, TIFFTAG_COLORMAP, redTable, greenTable, blueTable);
qFree(redTable); free(redTable);
qFree(greenTable); free(greenTable);
qFree(blueTable); free(blueTable);
if (!setColorTableSuccess) { if (!setColorTableSuccess) {
TIFFClose(tiff); TIFFClose(tiff);

View file

@ -64,7 +64,7 @@ public:
{ {
capacity = res; capacity = res;
if (res) if (res)
buffer = (Type*) qMalloc(capacity * sizeof(Type)); buffer = (Type*) malloc(capacity * sizeof(Type));
else else
buffer = 0; buffer = 0;
siz = 0; siz = 0;
@ -73,7 +73,7 @@ public:
~QDataBuffer() ~QDataBuffer()
{ {
if (buffer) if (buffer)
qFree(buffer); free(buffer);
} }
inline void reset() { siz = 0; } inline void reset() { siz = 0; }
@ -112,16 +112,16 @@ public:
capacity = 1; capacity = 1;
while (capacity < size) while (capacity < size)
capacity *= 2; capacity *= 2;
buffer = (Type*) qRealloc(buffer, capacity * sizeof(Type)); buffer = (Type*) realloc(buffer, capacity * sizeof(Type));
} }
} }
inline void shrink(int size) { inline void shrink(int size) {
capacity = size; capacity = size;
if (size) if (size)
buffer = (Type*) qRealloc(buffer, capacity * sizeof(Type)); buffer = (Type*) realloc(buffer, capacity * sizeof(Type));
else { else {
qFree(buffer); free(buffer);
buffer = 0; buffer = 0;
} }
} }

View file

@ -101,7 +101,7 @@ QSGGeometry::QSGGeometry(const QSGGeometry::AttributeSet &attributes,
QSGGeometry::~QSGGeometry() QSGGeometry::~QSGGeometry()
{ {
if (m_owns_data) if (m_owns_data)
qFree(m_data); free(m_data);
} }
void *QSGGeometry::indexData() void *QSGGeometry::indexData()
@ -135,7 +135,7 @@ void QSGGeometry::allocate(int vertexCount, int indexCount)
int vertexByteSize = m_attributes.stride * m_vertex_count; int vertexByteSize = m_attributes.stride * m_vertex_count;
if (m_owns_data) if (m_owns_data)
qFree(m_data); free(m_data);
if (canUsePrealloc && vertexByteSize <= (int) sizeof(m_prealloc)) { if (canUsePrealloc && vertexByteSize <= (int) sizeof(m_prealloc)) {
m_data = (void *) &m_prealloc[0]; m_data = (void *) &m_prealloc[0];
@ -144,7 +144,7 @@ void QSGGeometry::allocate(int vertexCount, int indexCount)
} else { } else {
Q_ASSERT(m_index_type == GL_UNSIGNED_INT || m_index_type == GL_UNSIGNED_SHORT); Q_ASSERT(m_index_type == GL_UNSIGNED_INT || m_index_type == GL_UNSIGNED_SHORT);
int indexByteSize = indexCount * (m_index_type == GL_UNSIGNED_SHORT ? sizeof(quint16) : sizeof(quint32)); int indexByteSize = indexCount * (m_index_type == GL_UNSIGNED_SHORT ? sizeof(quint16) : sizeof(quint32));
m_data = (void *) qMalloc(vertexByteSize + indexByteSize); m_data = (void *) malloc(vertexByteSize + indexByteSize);
m_index_data_offset = vertexByteSize; m_index_data_offset = vertexByteSize;
m_owns_data = true; m_owns_data = true;
} }

View file

@ -231,7 +231,7 @@ QList<int> QAudioDeviceInfoInternal::channelsList()
&propSize, &propSize,
0) == noErr) { 0) == noErr) {
AudioBufferList* audioBufferList = static_cast<AudioBufferList*>(qMalloc(propSize)); AudioBufferList* audioBufferList = static_cast<AudioBufferList*>(malloc(propSize));
if (audioBufferList != 0) { if (audioBufferList != 0) {
if (AudioDeviceGetProperty(deviceId, if (AudioDeviceGetProperty(deviceId,
@ -247,7 +247,7 @@ QList<int> QAudioDeviceInfoInternal::channelsList()
} }
} }
qFree(audioBufferList); free(audioBufferList);
} }
} }

View file

@ -80,7 +80,7 @@ public:
dataSize = 0; dataSize = 0;
bfs = reinterpret_cast<AudioBufferList*>(qMalloc(sizeof(AudioBufferList) + bfs = reinterpret_cast<AudioBufferList*>(malloc(sizeof(AudioBufferList) +
(sizeof(AudioBuffer) * numberOfBuffers))); (sizeof(AudioBuffer) * numberOfBuffers)));
bfs->mNumberBuffers = numberOfBuffers; bfs->mNumberBuffers = numberOfBuffers;
@ -98,7 +98,7 @@ public:
{ {
dataSize = bufferSize; dataSize = bufferSize;
bfs = reinterpret_cast<AudioBufferList*>(qMalloc(sizeof(AudioBufferList) + sizeof(AudioBuffer))); bfs = reinterpret_cast<AudioBufferList*>(malloc(sizeof(AudioBufferList) + sizeof(AudioBuffer)));
bfs->mNumberBuffers = 1; bfs->mNumberBuffers = 1;
bfs->mBuffers[0].mNumberChannels = 1; bfs->mBuffers[0].mNumberChannels = 1;
@ -116,13 +116,13 @@ public:
dataSize = framesToBuffer * sf.mBytesPerFrame; dataSize = framesToBuffer * sf.mBytesPerFrame;
bfs = reinterpret_cast<AudioBufferList*>(qMalloc(sizeof(AudioBufferList) + bfs = reinterpret_cast<AudioBufferList*>(malloc(sizeof(AudioBufferList) +
(sizeof(AudioBuffer) * numberOfBuffers))); (sizeof(AudioBuffer) * numberOfBuffers)));
bfs->mNumberBuffers = numberOfBuffers; bfs->mNumberBuffers = numberOfBuffers;
for (int i = 0; i < numberOfBuffers; ++i) { for (int i = 0; i < numberOfBuffers; ++i) {
bfs->mBuffers[i].mNumberChannels = isInterleaved ? numberOfBuffers : 1; bfs->mBuffers[i].mNumberChannels = isInterleaved ? numberOfBuffers : 1;
bfs->mBuffers[i].mDataByteSize = dataSize; bfs->mBuffers[i].mDataByteSize = dataSize;
bfs->mBuffers[i].mData = qMalloc(dataSize); bfs->mBuffers[i].mData = malloc(dataSize);
} }
} }
@ -130,10 +130,10 @@ public:
{ {
if (owner) { if (owner) {
for (UInt32 i = 0; i < bfs->mNumberBuffers; ++i) for (UInt32 i = 0; i < bfs->mNumberBuffers; ++i)
qFree(bfs->mBuffers[i].mData); free(bfs->mBuffers[i].mData);
} }
qFree(bfs); free(bfs);
} }
AudioBufferList* audioBufferList() const AudioBufferList* audioBufferList() const

View file

@ -336,7 +336,7 @@ QString QHostInfo::localDomainName()
resolveLibrary(); resolveLibrary();
if (local_res_ninit) { if (local_res_ninit) {
// using thread-safe version // using thread-safe version
res_state_ptr state = res_state_ptr(qMalloc(sizeof(*state))); res_state_ptr state = res_state_ptr(malloc(sizeof(*state)));
Q_CHECK_PTR(state); Q_CHECK_PTR(state);
memset(state, 0, sizeof(*state)); memset(state, 0, sizeof(*state));
local_res_ninit(state); local_res_ninit(state);
@ -344,7 +344,7 @@ QString QHostInfo::localDomainName()
if (domainName.isEmpty()) if (domainName.isEmpty())
domainName = QUrl::fromAce(state->dnsrch[0]); domainName = QUrl::fromAce(state->dnsrch[0]);
local_res_nclose(state); local_res_nclose(state);
qFree(state); free(state);
return domainName; return domainName;
} }

View file

@ -104,12 +104,12 @@ static QHash<QHostAddress, QHostAddress> ipv4Netmasks()
DWORD retval = ptrGetAdaptersInfo(pAdapter, &bufSize); DWORD retval = ptrGetAdaptersInfo(pAdapter, &bufSize);
if (retval == ERROR_BUFFER_OVERFLOW) { if (retval == ERROR_BUFFER_OVERFLOW) {
// need more memory // need more memory
pAdapter = (IP_ADAPTER_INFO *)qMalloc(bufSize); pAdapter = (IP_ADAPTER_INFO *)malloc(bufSize);
if (!pAdapter) if (!pAdapter)
return ipv4netmasks; return ipv4netmasks;
// try again // try again
if (ptrGetAdaptersInfo(pAdapter, &bufSize) != ERROR_SUCCESS) { if (ptrGetAdaptersInfo(pAdapter, &bufSize) != ERROR_SUCCESS) {
qFree(pAdapter); free(pAdapter);
return ipv4netmasks; return ipv4netmasks;
} }
} else if (retval != ERROR_SUCCESS) { } else if (retval != ERROR_SUCCESS) {
@ -126,7 +126,7 @@ static QHash<QHostAddress, QHostAddress> ipv4Netmasks()
} }
} }
if (pAdapter != staticBuf) if (pAdapter != staticBuf)
qFree(pAdapter); free(pAdapter);
return ipv4netmasks; return ipv4netmasks;
@ -146,12 +146,12 @@ static QList<QNetworkInterfacePrivate *> interfaceListingWinXP()
ULONG retval = ptrGetAdaptersAddresses(AF_UNSPEC, flags, NULL, pAdapter, &bufSize); ULONG retval = ptrGetAdaptersAddresses(AF_UNSPEC, flags, NULL, pAdapter, &bufSize);
if (retval == ERROR_BUFFER_OVERFLOW) { if (retval == ERROR_BUFFER_OVERFLOW) {
// need more memory // need more memory
pAdapter = (IP_ADAPTER_ADDRESSES *)qMalloc(bufSize); pAdapter = (IP_ADAPTER_ADDRESSES *)malloc(bufSize);
if (!pAdapter) if (!pAdapter)
return interfaces; return interfaces;
// try again // try again
if (ptrGetAdaptersAddresses(AF_UNSPEC, flags, NULL, pAdapter, &bufSize) != ERROR_SUCCESS) { if (ptrGetAdaptersAddresses(AF_UNSPEC, flags, NULL, pAdapter, &bufSize) != ERROR_SUCCESS) {
qFree(pAdapter); free(pAdapter);
return interfaces; return interfaces;
} }
} else if (retval != ERROR_SUCCESS) { } else if (retval != ERROR_SUCCESS) {
@ -212,7 +212,7 @@ static QList<QNetworkInterfacePrivate *> interfaceListingWinXP()
} }
if (pAdapter != staticBuf) if (pAdapter != staticBuf)
qFree(pAdapter); free(pAdapter);
return interfaces; return interfaces;
} }
@ -227,12 +227,12 @@ static QList<QNetworkInterfacePrivate *> interfaceListingWin2k()
DWORD retval = ptrGetAdaptersInfo(pAdapter, &bufSize); DWORD retval = ptrGetAdaptersInfo(pAdapter, &bufSize);
if (retval == ERROR_BUFFER_OVERFLOW) { if (retval == ERROR_BUFFER_OVERFLOW) {
// need more memory // need more memory
pAdapter = (IP_ADAPTER_INFO *)qMalloc(bufSize); pAdapter = (IP_ADAPTER_INFO *)malloc(bufSize);
if (!pAdapter) if (!pAdapter)
return interfaces; return interfaces;
// try again // try again
if (ptrGetAdaptersInfo(pAdapter, &bufSize) != ERROR_SUCCESS) { if (ptrGetAdaptersInfo(pAdapter, &bufSize) != ERROR_SUCCESS) {
qFree(pAdapter); free(pAdapter);
return interfaces; return interfaces;
} }
} else if (retval != ERROR_SUCCESS) { } else if (retval != ERROR_SUCCESS) {
@ -266,7 +266,7 @@ static QList<QNetworkInterfacePrivate *> interfaceListingWin2k()
} }
if (pAdapter != staticBuf) if (pAdapter != staticBuf)
qFree(pAdapter); free(pAdapter);
return interfaces; return interfaces;
} }
@ -298,12 +298,12 @@ QString QHostInfo::localDomainName()
ULONG bufSize = sizeof info; ULONG bufSize = sizeof info;
pinfo = &info; pinfo = &info;
if (ptrGetNetworkParams(pinfo, &bufSize) == ERROR_BUFFER_OVERFLOW) { if (ptrGetNetworkParams(pinfo, &bufSize) == ERROR_BUFFER_OVERFLOW) {
pinfo = (FIXED_INFO *)qMalloc(bufSize); pinfo = (FIXED_INFO *)malloc(bufSize);
if (!pinfo) if (!pinfo)
return QString(); return QString();
// try again // try again
if (ptrGetNetworkParams(pinfo, &bufSize) != ERROR_SUCCESS) { if (ptrGetNetworkParams(pinfo, &bufSize) != ERROR_SUCCESS) {
qFree(pinfo); free(pinfo);
return QString(); // error return QString(); // error
} }
} }
@ -311,7 +311,7 @@ QString QHostInfo::localDomainName()
QString domainName = QUrl::fromAce(pinfo->DomainName); QString domainName = QUrl::fromAce(pinfo->DomainName);
if (pinfo != &info) if (pinfo != &info)
qFree(pinfo); free(pinfo);
return domainName; return domainName;
} }

View file

@ -714,8 +714,8 @@ void QGL2PaintEngineExPrivate::cleanupVectorPath(QPaintEngineEx *engine, void *d
d->unusedIBOSToClean << c->ibo; d->unusedIBOSToClean << c->ibo;
#else #else
Q_UNUSED(engine); Q_UNUSED(engine);
qFree(c->vertices); free(c->vertices);
qFree(c->indices); free(c->indices);
#endif #endif
delete c; delete c;
} }
@ -760,7 +760,7 @@ void QGL2PaintEngineExPrivate::fill(const QVectorPath& path)
cache->vbo = 0; cache->vbo = 0;
Q_ASSERT(cache->ibo == 0); Q_ASSERT(cache->ibo == 0);
#else #else
qFree(cache->vertices); free(cache->vertices);
Q_ASSERT(cache->indices == 0); Q_ASSERT(cache->indices == 0);
#endif #endif
updateCache = true; updateCache = true;
@ -788,7 +788,7 @@ void QGL2PaintEngineExPrivate::fill(const QVectorPath& path)
glBufferData(GL_ARRAY_BUFFER, floatSizeInBytes, vertexCoordinateArray.data(), GL_STATIC_DRAW); glBufferData(GL_ARRAY_BUFFER, floatSizeInBytes, vertexCoordinateArray.data(), GL_STATIC_DRAW);
cache->ibo = 0; cache->ibo = 0;
#else #else
cache->vertices = (float *) qMalloc(floatSizeInBytes); cache->vertices = (float *) malloc(floatSizeInBytes);
memcpy(cache->vertices, vertexCoordinateArray.data(), floatSizeInBytes); memcpy(cache->vertices, vertexCoordinateArray.data(), floatSizeInBytes);
cache->indices = 0; cache->indices = 0;
#endif #endif
@ -840,8 +840,8 @@ void QGL2PaintEngineExPrivate::fill(const QVectorPath& path)
glDeleteBuffers(1, &cache->vbo); glDeleteBuffers(1, &cache->vbo);
glDeleteBuffers(1, &cache->ibo); glDeleteBuffers(1, &cache->ibo);
#else #else
qFree(cache->vertices); free(cache->vertices);
qFree(cache->indices); free(cache->indices);
#endif #endif
updateCache = true; updateCache = true;
} }
@ -875,12 +875,12 @@ void QGL2PaintEngineExPrivate::fill(const QVectorPath& path)
vertices[i] = float(inverseScale * polys.vertices.at(i)); vertices[i] = float(inverseScale * polys.vertices.at(i));
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * vertices.size(), vertices.data(), GL_STATIC_DRAW); glBufferData(GL_ARRAY_BUFFER, sizeof(float) * vertices.size(), vertices.data(), GL_STATIC_DRAW);
#else #else
cache->vertices = (float *) qMalloc(sizeof(float) * polys.vertices.size()); cache->vertices = (float *) malloc(sizeof(float) * polys.vertices.size());
if (QGLExtensions::glExtensions() & QGLExtensions::ElementIndexUint) { if (QGLExtensions::glExtensions() & QGLExtensions::ElementIndexUint) {
cache->indices = (quint32 *) qMalloc(sizeof(quint32) * polys.indices.size()); cache->indices = (quint32 *) malloc(sizeof(quint32) * polys.indices.size());
memcpy(cache->indices, polys.indices.data(), sizeof(quint32) * polys.indices.size()); memcpy(cache->indices, polys.indices.data(), sizeof(quint32) * polys.indices.size());
} else { } else {
cache->indices = (quint16 *) qMalloc(sizeof(quint16) * polys.indices.size()); cache->indices = (quint16 *) malloc(sizeof(quint16) * polys.indices.size());
memcpy(cache->indices, polys.indices.data(), sizeof(quint16) * polys.indices.size()); memcpy(cache->indices, polys.indices.data(), sizeof(quint16) * polys.indices.size());
} }
for (int i = 0; i < polys.vertices.size(); ++i) for (int i = 0; i < polys.vertices.size(); ++i)

View file

@ -1042,7 +1042,7 @@ QScriptEnginePrivate::~QScriptEnginePrivate()
while (freeScriptValues) { while (freeScriptValues) {
QScriptValuePrivate *p = freeScriptValues; QScriptValuePrivate *p = freeScriptValues;
freeScriptValues = p->next; freeScriptValues = p->next;
qFree(p); free(p);
} }
} }

View file

@ -610,7 +610,7 @@ inline QScriptValuePrivate *QScriptEnginePrivate::allocateScriptValuePrivate(siz
--freeScriptValuesCount; --freeScriptValuesCount;
return p; return p;
} }
return reinterpret_cast<QScriptValuePrivate*>(qMalloc(size)); return reinterpret_cast<QScriptValuePrivate*>(malloc(size));
} }
inline void QScriptEnginePrivate::freeScriptValuePrivate(QScriptValuePrivate *p) inline void QScriptEnginePrivate::freeScriptValuePrivate(QScriptValuePrivate *p)
@ -620,7 +620,7 @@ inline void QScriptEnginePrivate::freeScriptValuePrivate(QScriptValuePrivate *p)
freeScriptValues = p; freeScriptValues = p;
++freeScriptValuesCount; ++freeScriptValuesCount;
} else { } else {
qFree(p); free(p);
} }
} }
@ -809,7 +809,7 @@ inline void* QScriptValuePrivate::operator new(size_t size, QScriptEnginePrivate
{ {
if (engine) if (engine)
return engine->allocateScriptValuePrivate(size); return engine->allocateScriptValuePrivate(size);
return qMalloc(size); return malloc(size);
} }
inline void QScriptValuePrivate::operator delete(void *ptr) inline void QScriptValuePrivate::operator delete(void *ptr)
@ -818,7 +818,7 @@ inline void QScriptValuePrivate::operator delete(void *ptr)
if (d->engine) if (d->engine)
d->engine->freeScriptValuePrivate(d); d->engine->freeScriptValuePrivate(d);
else else
qFree(d); free(d);
} }
inline void QScriptEnginePrivate::saveException(JSC::ExecState *exec, JSC::JSValue *val) inline void QScriptEnginePrivate::saveException(JSC::ExecState *exec, JSC::JSValue *val)

View file

@ -268,9 +268,9 @@ inline void QScriptParser::reallocateStack()
else else
stack_size <<= 1; stack_size <<= 1;
sym_stack = reinterpret_cast<Value*> (qRealloc(sym_stack, stack_size * sizeof(Value))); sym_stack = reinterpret_cast<Value*> (realloc(sym_stack, stack_size * sizeof(Value)));
state_stack = reinterpret_cast<int*> (qRealloc(state_stack, stack_size * sizeof(int))); state_stack = reinterpret_cast<int*> (realloc(state_stack, stack_size * sizeof(int)));
location_stack = reinterpret_cast<Location*> (qRealloc(location_stack, stack_size * sizeof(Location))); location_stack = reinterpret_cast<Location*> (realloc(location_stack, stack_size * sizeof(Location)));
} }
:/ :/
@ -307,9 +307,9 @@ QScriptParser::QScriptParser():
QScriptParser::~QScriptParser() QScriptParser::~QScriptParser()
{ {
if (stack_size) { if (stack_size) {
qFree(sym_stack); free(sym_stack);
qFree(state_stack); free(state_stack);
qFree(location_stack); free(location_stack);
} }
} }

View file

@ -84,9 +84,9 @@ QScriptParser::QScriptParser():
QScriptParser::~QScriptParser() QScriptParser::~QScriptParser()
{ {
if (stack_size) { if (stack_size) {
qFree(sym_stack); free(sym_stack);
qFree(state_stack); free(state_stack);
qFree(location_stack); free(location_stack);
} }
} }

View file

@ -149,9 +149,9 @@ inline void QScriptParser::reallocateStack()
else else
stack_size <<= 1; stack_size <<= 1;
sym_stack = reinterpret_cast<Value*> (qRealloc(sym_stack, stack_size * sizeof(Value))); sym_stack = reinterpret_cast<Value*> (realloc(sym_stack, stack_size * sizeof(Value)));
state_stack = reinterpret_cast<int*> (qRealloc(state_stack, stack_size * sizeof(int))); state_stack = reinterpret_cast<int*> (realloc(state_stack, stack_size * sizeof(int)));
location_stack = reinterpret_cast<Location*> (qRealloc(location_stack, stack_size * sizeof(Location))); location_stack = reinterpret_cast<Location*> (realloc(location_stack, stack_size * sizeof(Location)));
} }

View file

@ -41,7 +41,7 @@ SyntaxChecker::SyntaxChecker():
SyntaxChecker::~SyntaxChecker() SyntaxChecker::~SyntaxChecker()
{ {
if (stack_size) { if (stack_size) {
qFree(state_stack); free(state_stack);
} }
} }

View file

@ -86,7 +86,7 @@ inline void SyntaxChecker::reallocateStack()
else else
stack_size <<= 1; stack_size <<= 1;
state_stack = reinterpret_cast<int*> (qRealloc(state_stack, stack_size * sizeof(int))); state_stack = reinterpret_cast<int*> (realloc(state_stack, stack_size * sizeof(int)));
} }
} // namespace QScript } // namespace QScript

View file

@ -114,7 +114,7 @@ struct QTestCharBuffer
inline ~QTestCharBuffer() inline ~QTestCharBuffer()
{ {
if (buf != staticBuf) if (buf != staticBuf)
qFree(buf); free(buf);
} }
inline char *data() inline char *data()
@ -142,10 +142,10 @@ struct QTestCharBuffer
char *newBuf = 0; char *newBuf = 0;
if (buf == staticBuf) { if (buf == staticBuf) {
// if we point to our internal buffer, we need to malloc first // if we point to our internal buffer, we need to malloc first
newBuf = reinterpret_cast<char *>(qMalloc(newSize)); newBuf = reinterpret_cast<char *>(malloc(newSize));
} else { } else {
// if we already malloc'ed, just realloc // if we already malloc'ed, just realloc
newBuf = reinterpret_cast<char *>(qRealloc(buf, newSize)); newBuf = reinterpret_cast<char *>(realloc(buf, newSize));
} }
// if the allocation went wrong (newBuf == 0), we leave the object as is // if the allocation went wrong (newBuf == 0), we leave the object as is

View file

@ -2162,8 +2162,8 @@ inline void QScriptParser::reallocateStack()
stack_size <<= 1; stack_size <<= 1;
sym_stack.resize(stack_size); sym_stack.resize(stack_size);
state_stack = reinterpret_cast<int*> (qRealloc(state_stack, stack_size * sizeof(int))); state_stack = reinterpret_cast<int*> (realloc(state_stack, stack_size * sizeof(int)));
location_stack = reinterpret_cast<Location*> (qRealloc(location_stack, stack_size * sizeof(Location))); location_stack = reinterpret_cast<Location*> (realloc(location_stack, stack_size * sizeof(Location)));
} }
inline static bool automatic(QScript::Lexer *lexer, int token) inline static bool automatic(QScript::Lexer *lexer, int token)
@ -2187,8 +2187,8 @@ QScriptParser::QScriptParser():
QScriptParser::~QScriptParser() QScriptParser::~QScriptParser()
{ {
if (stack_size) { if (stack_size) {
qFree(state_stack); free(state_stack);
qFree(location_stack); free(location_stack);
} }
} }

View file

@ -1479,8 +1479,8 @@ inline void QScriptParser::reallocateStack()
stack_size <<= 1; stack_size <<= 1;
sym_stack.resize(stack_size); sym_stack.resize(stack_size);
state_stack = reinterpret_cast<int*> (qRealloc(state_stack, stack_size * sizeof(int))); state_stack = reinterpret_cast<int*> (realloc(state_stack, stack_size * sizeof(int)));
location_stack = reinterpret_cast<Location*> (qRealloc(location_stack, stack_size * sizeof(Location))); location_stack = reinterpret_cast<Location*> (realloc(location_stack, stack_size * sizeof(Location)));
} }
inline static bool automatic(QScript::Lexer *lexer, int token) inline static bool automatic(QScript::Lexer *lexer, int token)
@ -1504,8 +1504,8 @@ QScriptParser::QScriptParser():
QScriptParser::~QScriptParser() QScriptParser::~QScriptParser()
{ {
if (stack_size) { if (stack_size) {
qFree(state_stack); free(state_stack);
qFree(location_stack); free(location_stack);
} }
} }