Retire the generic Q_REFCOUNT_INITIALIZER macro
authorJoão Abecasis <joao.abecasis@nokia.com>
Fri, 16 Dec 2011 15:21:29 +0000 (16:21 +0100)
committerQt by Nokia <qt-info@nokia.com>
Wed, 4 Jan 2012 22:38:06 +0000 (23:38 +0100)
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 <ogoffart@woboq.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
13 files changed:
src/corelib/tools/qarraydata.cpp
src/corelib/tools/qarraydata.h
src/corelib/tools/qbytearray.cpp
src/corelib/tools/qbytearray.h
src/corelib/tools/qhash.cpp
src/corelib/tools/qlinkedlist.cpp
src/corelib/tools/qlist.cpp
src/corelib/tools/qmap.cpp
src/corelib/tools/qrefcount.h
src/corelib/tools/qstring.cpp
src/corelib/tools/qstring.h
src/corelib/tools/qvector.cpp
tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp

index e3a6bad..1145ecb 100644 (file)
@@ -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)
index 1312fec..b7ab592 100644 (file)
@@ -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) } \
     /**/
index f959eff..09cc6d2 100644 (file)
@@ -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 } };
 
 /*!
index 3ebeb3c..932998c 100644 (file)
@@ -149,7 +149,7 @@ template<int N> struct QConstByteArrayDataPtr
 #  define QByteArrayLiteral(str) ([]() -> QConstByteArrayDataPtr<sizeof(str) - 1> { \
         enum { Size = sizeof(str) - 1 }; \
         static const QConstByteArrayData<Size> qbytearray_literal = \
-        { { Q_REFCOUNT_INITIALIZER(-1), Size, 0, 0, { 0 } }, str }; \
+        { { Q_REFCOUNT_INITIALIZE_STATIC, Size, 0, 0, { 0 } }, str }; \
         QConstByteArrayDataPtr<Size> holder = { &qbytearray_literal }; \
     return holder; }())
 
@@ -162,7 +162,7 @@ template<int N> struct QConstByteArrayDataPtr
     __extension__ ({ \
         enum { Size = sizeof(str) - 1 }; \
         static const QConstByteArrayData<Size> qbytearray_literal = \
-        { { Q_REFCOUNT_INITIALIZER(-1), Size, 0, 0, { 0 } }, str }; \
+        { { Q_REFCOUNT_INITIALIZE_STATIC, Size, 0, 0, { 0 } }, str }; \
         QConstByteArrayDataPtr<Size> holder = { &qbytearray_literal }; \
         holder; })
 #endif
index 48a446c..373b598 100644 (file)
@@ -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)
index 1610553..e591936 100644 (file)
@@ -46,7 +46,7 @@ QT_BEGIN_NAMESPACE
 const QLinkedListData QLinkedListData::shared_null = {
     const_cast<QLinkedListData *>(&QLinkedListData::shared_null),
     const_cast<QLinkedListData *>(&QLinkedListData::shared_null),
-    Q_REFCOUNT_INITIALIZER(-1), 0, true
+    Q_REFCOUNT_INITIALIZE_STATIC, 0, true
 };
 
 /*! \class QLinkedList
index 8ef5fad..2a3695b 100644 (file)
@@ -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)
 {
index 6bac127..76cb203 100644 (file)
@@ -53,7 +53,7 @@ QT_BEGIN_NAMESPACE
 const QMapData QMapData::shared_null = {
     const_cast<QMapData *>(&shared_null),
     { const_cast<QMapData *>(&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)
index 6d030cc..17be893 100644 (file)
@@ -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
index 02d6788..16bf267 100644 (file)
@@ -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)
 {
index 4e1e67b..ba3407e 100644 (file)
@@ -133,7 +133,7 @@ template<int N> struct QConstStringData
 #  define QStringLiteral(str) ([]() -> QConstStringDataPtr<sizeof(QT_UNICODE_LITERAL(str))/2 - 1> { \
         enum { Size = sizeof(QT_UNICODE_LITERAL(str))/2 - 1 }; \
         static const QConstStringData<Size> 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<Size> holder = { &qstring_literal }; \
     return holder; }())
 
@@ -146,7 +146,7 @@ template<int N> struct QConstStringData
     __extension__ ({ \
         enum { Size = sizeof(QT_UNICODE_LITERAL(str))/2 - 1 }; \
         static const QConstStringData<Size> 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<Size> holder = { &qstring_literal }; \
         holder; })
 # endif
index e1828c2..95ae76e 100644 (file)
@@ -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)
 {
index 808aa73..241ef3b 100644 (file)
@@ -68,7 +68,7 @@ void tst_QArrayData::referenceCounting()
 {
     {
         // Reference counting initialized to 1 (owned)
-        QArrayData array = { Q_REFCOUNT_INITIALIZER(1), 0, 0, 0, 0 };
+        QArrayData array = { { Q_BASIC_ATOMIC_INITIALIZER(1) }, 0, 0, 0, 0 };
 
         QCOMPARE(int(array.ref), 1);
 
@@ -92,7 +92,7 @@ void tst_QArrayData::referenceCounting()
 
     {
         // Reference counting initialized to -1 (static read-only data)
-        QArrayData array = { Q_REFCOUNT_INITIALIZER(-1), 0, 0, 0, 0 };
+        QArrayData array = { Q_REFCOUNT_INITIALIZE_STATIC, 0, 0, 0, 0 };
 
         QCOMPARE(int(array.ref), -1);
 
@@ -161,7 +161,7 @@ void tst_QArrayData::staticData()
 
 void tst_QArrayData::simpleVector()
 {
-    QArrayData data0 = { Q_REFCOUNT_INITIALIZER(-1), 0, 0, 0, 0 };
+    QArrayData data0 = { Q_REFCOUNT_INITIALIZE_STATIC, 0, 0, 0, 0 };
     QStaticArrayData<int, 7> data1 = {
             Q_STATIC_ARRAY_DATA_HEADER_INITIALIZER(int, 7),
             { 0, 1, 2, 3, 4, 5, 6 }