From 3fad9a846f6a89bd342b25c319d0263794bda575 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= Date: Fri, 16 Dec 2011 16:21:29 +0100 Subject: Retire the generic Q_REFCOUNT_INITIALIZER macro This was only being used to initialize static read-only RefCount instances, where the value is hard-wired to -1. Instead of allowing initialization with arbitrary values (which for a reference count can be error prone) the intent of the macro is made explicit with its replacement Q_REFCOUNT_INITIALIZE_STATIC. Change-Id: I5b0f3f1eb58c3d010e49e9259ff4d06cbab2fd35 Reviewed-by: Olivier Goffart Reviewed-by: Thiago Macieira Reviewed-by: Lars Knoll --- src/corelib/tools/qarraydata.cpp | 4 ++-- src/corelib/tools/qarraydata.h | 2 +- src/corelib/tools/qbytearray.cpp | 4 ++-- src/corelib/tools/qbytearray.h | 4 ++-- src/corelib/tools/qhash.cpp | 2 +- src/corelib/tools/qlinkedlist.cpp | 2 +- src/corelib/tools/qlist.cpp | 2 +- src/corelib/tools/qmap.cpp | 2 +- src/corelib/tools/qrefcount.h | 4 ++-- src/corelib/tools/qstring.cpp | 4 ++-- src/corelib/tools/qstring.h | 4 ++-- src/corelib/tools/qvector.cpp | 2 +- 12 files changed, 18 insertions(+), 18 deletions(-) (limited to 'src/corelib/tools') diff --git a/src/corelib/tools/qarraydata.cpp b/src/corelib/tools/qarraydata.cpp index e3a6bad7c5..1145ecb4f4 100644 --- a/src/corelib/tools/qarraydata.cpp +++ b/src/corelib/tools/qarraydata.cpp @@ -43,8 +43,8 @@ QT_BEGIN_NAMESPACE -const QArrayData QArrayData::shared_null = { Q_REFCOUNT_INITIALIZER(-1), 0, 0, 0, 0 }; -const QArrayData QArrayData::shared_empty = { Q_REFCOUNT_INITIALIZER(-1), 0, 0, 0, 0 }; +const QArrayData QArrayData::shared_null = { Q_REFCOUNT_INITIALIZE_STATIC, 0, 0, 0, 0 }; +const QArrayData QArrayData::shared_empty = { Q_REFCOUNT_INITIALIZE_STATIC, 0, 0, 0, 0 }; QArrayData *QArrayData::allocate(size_t objectSize, size_t alignment, size_t capacity, bool reserve) diff --git a/src/corelib/tools/qarraydata.h b/src/corelib/tools/qarraydata.h index 1312feccdb..b7ab59257f 100644 --- a/src/corelib/tools/qarraydata.h +++ b/src/corelib/tools/qarraydata.h @@ -132,7 +132,7 @@ struct QStaticArrayData }; #define Q_STATIC_ARRAY_DATA_HEADER_INITIALIZER(type, size) { \ - Q_REFCOUNT_INITIALIZER(-1), size, 0, 0, \ + Q_REFCOUNT_INITIALIZE_STATIC, size, 0, 0, \ (sizeof(QArrayData) + (Q_ALIGNOF(type) - 1)) \ & ~(Q_ALIGNOF(type) - 1) } \ /**/ diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp index f959effb43..09cc6d2f97 100644 --- a/src/corelib/tools/qbytearray.cpp +++ b/src/corelib/tools/qbytearray.cpp @@ -614,9 +614,9 @@ static inline char qToLower(char c) return c; } -const QConstByteArrayData<1> QByteArray::shared_null = { { Q_REFCOUNT_INITIALIZER(-1), +const QConstByteArrayData<1> QByteArray::shared_null = { { Q_REFCOUNT_INITIALIZE_STATIC, 0, 0, 0, { 0 } }, { 0 } }; -const QConstByteArrayData<1> QByteArray::shared_empty = { { Q_REFCOUNT_INITIALIZER(-1), +const QConstByteArrayData<1> QByteArray::shared_empty = { { Q_REFCOUNT_INITIALIZE_STATIC, 0, 0, 0, { 0 } }, { 0 } }; /*! diff --git a/src/corelib/tools/qbytearray.h b/src/corelib/tools/qbytearray.h index 3ebeb3c340..932998cb4c 100644 --- a/src/corelib/tools/qbytearray.h +++ b/src/corelib/tools/qbytearray.h @@ -149,7 +149,7 @@ template struct QConstByteArrayDataPtr # define QByteArrayLiteral(str) ([]() -> QConstByteArrayDataPtr { \ enum { Size = sizeof(str) - 1 }; \ static const QConstByteArrayData qbytearray_literal = \ - { { Q_REFCOUNT_INITIALIZER(-1), Size, 0, 0, { 0 } }, str }; \ + { { Q_REFCOUNT_INITIALIZE_STATIC, Size, 0, 0, { 0 } }, str }; \ QConstByteArrayDataPtr holder = { &qbytearray_literal }; \ return holder; }()) @@ -162,7 +162,7 @@ template struct QConstByteArrayDataPtr __extension__ ({ \ enum { Size = sizeof(str) - 1 }; \ static const QConstByteArrayData qbytearray_literal = \ - { { Q_REFCOUNT_INITIALIZER(-1), Size, 0, 0, { 0 } }, str }; \ + { { Q_REFCOUNT_INITIALIZE_STATIC, Size, 0, 0, { 0 } }, str }; \ QConstByteArrayDataPtr holder = { &qbytearray_literal }; \ holder; }) #endif diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp index 48a446cad6..373b59872c 100644 --- a/src/corelib/tools/qhash.cpp +++ b/src/corelib/tools/qhash.cpp @@ -166,7 +166,7 @@ static int countBits(int hint) const int MinNumBits = 4; const QHashData QHashData::shared_null = { - 0, 0, Q_REFCOUNT_INITIALIZER(-1), 0, 0, MinNumBits, 0, 0, true, false, 0 + 0, 0, Q_REFCOUNT_INITIALIZE_STATIC, 0, 0, MinNumBits, 0, 0, true, false, 0 }; void *QHashData::allocateNode(int nodeAlign) diff --git a/src/corelib/tools/qlinkedlist.cpp b/src/corelib/tools/qlinkedlist.cpp index 16105530bf..e5919363a0 100644 --- a/src/corelib/tools/qlinkedlist.cpp +++ b/src/corelib/tools/qlinkedlist.cpp @@ -46,7 +46,7 @@ QT_BEGIN_NAMESPACE const QLinkedListData QLinkedListData::shared_null = { const_cast(&QLinkedListData::shared_null), const_cast(&QLinkedListData::shared_null), - Q_REFCOUNT_INITIALIZER(-1), 0, true + Q_REFCOUNT_INITIALIZE_STATIC, 0, true }; /*! \class QLinkedList diff --git a/src/corelib/tools/qlist.cpp b/src/corelib/tools/qlist.cpp index 8ef5fadb73..2a3695bb35 100644 --- a/src/corelib/tools/qlist.cpp +++ b/src/corelib/tools/qlist.cpp @@ -57,7 +57,7 @@ QT_BEGIN_NAMESPACE the number of elements in the list. */ -const QListData::Data QListData::shared_null = { Q_REFCOUNT_INITIALIZER(-1), 0, 0, 0, true, { 0 } }; +const QListData::Data QListData::shared_null = { Q_REFCOUNT_INITIALIZE_STATIC, 0, 0, 0, true, { 0 } }; static int grow(int size) { diff --git a/src/corelib/tools/qmap.cpp b/src/corelib/tools/qmap.cpp index 6bac127a82..76cb203e10 100644 --- a/src/corelib/tools/qmap.cpp +++ b/src/corelib/tools/qmap.cpp @@ -53,7 +53,7 @@ QT_BEGIN_NAMESPACE const QMapData QMapData::shared_null = { const_cast(&shared_null), { const_cast(&shared_null), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - Q_REFCOUNT_INITIALIZER(-1), 0, 0, 0, false, true, false, 0 + Q_REFCOUNT_INITIALIZE_STATIC, 0, 0, 0, false, true, false, 0 }; QMapData *QMapData::createData(int alignment) diff --git a/src/corelib/tools/qrefcount.h b/src/corelib/tools/qrefcount.h index 6d030cc0b3..17be893744 100644 --- a/src/corelib/tools/qrefcount.h +++ b/src/corelib/tools/qrefcount.h @@ -81,10 +81,10 @@ public: QBasicAtomicInt atomic; }; -#define Q_REFCOUNT_INITIALIZER(a) { Q_BASIC_ATOMIC_INITIALIZER(a) } - } +#define Q_REFCOUNT_INITIALIZE_STATIC { Q_BASIC_ATOMIC_INITIALIZER(-1) } + QT_END_NAMESPACE QT_END_HEADER diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index 02d6788701..16bf26721e 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -798,8 +798,8 @@ const QString::Null QString::null = { }; \sa split() */ -const QConstStringData<1> QString::shared_null = { { Q_REFCOUNT_INITIALIZER(-1), 0, 0, false, { 0 } }, { 0 } }; -const QConstStringData<1> QString::shared_empty = { { Q_REFCOUNT_INITIALIZER(-1), 0, 0, false, { 0 } }, { 0 } }; +const QConstStringData<1> QString::shared_null = { { Q_REFCOUNT_INITIALIZE_STATIC, 0, 0, false, { 0 } }, { 0 } }; +const QConstStringData<1> QString::shared_empty = { { Q_REFCOUNT_INITIALIZE_STATIC, 0, 0, false, { 0 } }, { 0 } }; int QString::grow(int size) { diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h index 4e1e67bfa6..ba3407e1cc 100644 --- a/src/corelib/tools/qstring.h +++ b/src/corelib/tools/qstring.h @@ -133,7 +133,7 @@ template struct QConstStringData # define QStringLiteral(str) ([]() -> QConstStringDataPtr { \ enum { Size = sizeof(QT_UNICODE_LITERAL(str))/2 - 1 }; \ static const QConstStringData qstring_literal = \ - { { Q_REFCOUNT_INITIALIZER(-1), Size, 0, 0, { 0 } }, QT_UNICODE_LITERAL(str) }; \ + { { Q_REFCOUNT_INITIALIZE_STATIC, Size, 0, 0, { 0 } }, QT_UNICODE_LITERAL(str) }; \ QConstStringDataPtr holder = { &qstring_literal }; \ return holder; }()) @@ -146,7 +146,7 @@ template struct QConstStringData __extension__ ({ \ enum { Size = sizeof(QT_UNICODE_LITERAL(str))/2 - 1 }; \ static const QConstStringData qstring_literal = \ - { { Q_REFCOUNT_INITIALIZER(-1), Size, 0, 0, { 0 } }, QT_UNICODE_LITERAL(str) }; \ + { { Q_REFCOUNT_INITIALIZE_STATIC, Size, 0, 0, { 0 } }, QT_UNICODE_LITERAL(str) }; \ QConstStringDataPtr holder = { &qstring_literal }; \ holder; }) # endif diff --git a/src/corelib/tools/qvector.cpp b/src/corelib/tools/qvector.cpp index e1828c2b0f..95ae76eb1e 100644 --- a/src/corelib/tools/qvector.cpp +++ b/src/corelib/tools/qvector.cpp @@ -52,7 +52,7 @@ static inline int alignmentThreshold() return 2 * sizeof(void*); } -const QVectorData QVectorData::shared_null = { Q_REFCOUNT_INITIALIZER(-1), 0, 0, true, false, 0 }; +const QVectorData QVectorData::shared_null = { Q_REFCOUNT_INITIALIZE_STATIC, 0, 0, true, false, 0 }; QVectorData *QVectorData::malloc(int sizeofTypedData, int size, int sizeofT, QVectorData *init) { -- cgit v1.2.3