Move Q_CHECK_PTR to inline code

The behavior of Q_CHECK_PTR is user-configurable. It may throw and
exception, output a warning or be a no-op. As such, its best used in
inline code that gets compiled into the user application.

Moving it out of the QArrayData API also enables this to be used in code
that must handle out-of-memory errors without crashing or otherwise
issuing warnings.

Putting in QArrayDataPointer gives good convenience coverage for those
who are implementing containers on top of the QArrayData stack, and
covers its use in the SimpleVector test case. It intentionally leaves
out the use of allocate to access the (hidden) shared-empties which
don't really allocate, anyway (in QArrayDataPointer::clear and
setSharable).

The autotest is not updated and will have to make do without the
Q_CHECK_PTR "protection". I think that is ok.

Change-Id: Idcad909903a9807866bf23ace89f1bf1edc53c3b
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
João Abecasis 2012-01-13 16:51:07 +01:00 committed by Qt by Nokia
parent e465a8c58c
commit 66f192e294
2 changed files with 1 additions and 1 deletions

View File

@ -73,7 +73,6 @@ QArrayData *QArrayData::allocate(size_t objectSize, size_t alignment,
allocSize += (alignment - Q_ALIGNOF(QArrayData)); allocSize += (alignment - Q_ALIGNOF(QArrayData));
QArrayData *header = static_cast<QArrayData *>(::malloc(allocSize)); QArrayData *header = static_cast<QArrayData *>(::malloc(allocSize));
Q_CHECK_PTR(header);
if (header) { if (header) {
quintptr data = (quintptr(header) + sizeof(QArrayData) + alignment - 1) quintptr data = (quintptr(header) + sizeof(QArrayData) + alignment - 1)
& ~(alignment - 1); & ~(alignment - 1);

View File

@ -73,6 +73,7 @@ public:
explicit QArrayDataPointer(QTypedArrayData<T> *ptr) explicit QArrayDataPointer(QTypedArrayData<T> *ptr)
: d(ptr) : d(ptr)
{ {
Q_CHECK_PTR(ptr);
} }
QArrayDataPointer &operator=(const QArrayDataPointer &other) QArrayDataPointer &operator=(const QArrayDataPointer &other)