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 <ogoffart@woboq.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
This commit is contained in:
parent
7fadc3ce32
commit
3fad9a846f
@ -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)
|
||||
|
@ -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) } \
|
||||
/**/
|
||||
|
@ -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 } };
|
||||
|
||||
/*!
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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 }
|
||||
|
Loading…
Reference in New Issue
Block a user