summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/global/qglobal.h3
-rw-r--r--src/corelib/tools/qarraydata.cpp13
-rw-r--r--src/corelib/tools/qarraydata.h4
-rw-r--r--src/corelib/tools/qarraydatapointer.h4
-rw-r--r--src/corelib/tools/qcontiguouscache.h2
-rw-r--r--src/corelib/tools/qhash.h2
-rw-r--r--src/corelib/tools/qlinkedlist.h2
-rw-r--r--src/corelib/tools/qlist.h2
-rw-r--r--src/corelib/tools/qmap.h2
-rw-r--r--src/corelib/tools/qrefcount.h18
-rw-r--r--src/corelib/tools/qset.h2
-rw-r--r--src/corelib/tools/qvector.h14
-rw-r--r--tests/auto/corelib/tools/qarraydata/simplevector.h3
-rw-r--r--tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp44
-rw-r--r--tests/auto/corelib/tools/qhash/tst_qhash.cpp4
-rw-r--r--tests/auto/corelib/tools/qlinkedlist/tst_qlinkedlist.cpp6
-rw-r--r--tests/auto/corelib/tools/qlist/tst_qlist.cpp8
-rw-r--r--tests/auto/corelib/tools/qmap/tst_qmap.cpp8
-rw-r--r--tests/auto/corelib/tools/qvector/tst_qvector.cpp115
19 files changed, 196 insertions, 60 deletions
diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h
index fba8b019e7..391466448f 100644
--- a/src/corelib/global/qglobal.h
+++ b/src/corelib/global/qglobal.h
@@ -58,7 +58,10 @@
#if !defined(QT_BUILD_QMAKE) && !defined(QT_BUILD_CONFIGURE)
#include <QtCore/qconfig.h>
#include <QtCore/qfeatures.h>
+#endif
#define QT_SUPPORTS(FEATURE) (!defined(QT_NO_##FEATURE))
+#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
+# define QT_NO_UNSHARABLE_CONTAINERS
#endif
/* These two macros makes it possible to turn the builtin line expander into a
diff --git a/src/corelib/tools/qarraydata.cpp b/src/corelib/tools/qarraydata.cpp
index 825b3289c7..12736d5c2e 100644
--- a/src/corelib/tools/qarraydata.cpp
+++ b/src/corelib/tools/qarraydata.cpp
@@ -75,10 +75,13 @@ QArrayData *QArrayData::allocate(size_t objectSize, size_t alignment,
&& !(alignment & (alignment - 1)));
// Don't allocate empty headers
- if (!(options & RawData) && !capacity)
- return !(options & Unsharable)
- ? const_cast<QArrayData *>(&qt_array_empty)
- : const_cast<QArrayData *>(&qt_array_unsharable_empty);
+ if (!(options & RawData) && !capacity) {
+#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
+ if (options & Unsharable)
+ return const_cast<QArrayData *>(&qt_array_unsharable_empty);
+#endif
+ return const_cast<QArrayData *>(&qt_array_empty);
+ }
size_t headerSize = sizeof(QArrayData);
@@ -118,8 +121,10 @@ void QArrayData::deallocate(QArrayData *data, size_t objectSize,
&& !(alignment & (alignment - 1)));
Q_UNUSED(objectSize) Q_UNUSED(alignment)
+#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
if (data == &qt_array_unsharable_empty)
return;
+#endif
Q_ASSERT_X(!data->ref.isStatic(), "QArrayData::deallocate", "Static data can not be deleted");
::free(data);
diff --git a/src/corelib/tools/qarraydata.h b/src/corelib/tools/qarraydata.h
index ffb2b8765e..10a9e35542 100644
--- a/src/corelib/tools/qarraydata.h
+++ b/src/corelib/tools/qarraydata.h
@@ -80,7 +80,9 @@ struct Q_CORE_EXPORT QArrayData
enum AllocationOption {
CapacityReserved = 0x1,
+#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
Unsharable = 0x2,
+#endif
RawData = 0x4,
Grow = 0x8,
@@ -99,8 +101,10 @@ struct Q_CORE_EXPORT QArrayData
AllocationOptions detachFlags() const
{
AllocationOptions result;
+#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
if (!ref.isSharable())
result |= Unsharable;
+#endif
if (capacityReserved)
result |= CapacityReserved;
return result;
diff --git a/src/corelib/tools/qarraydatapointer.h b/src/corelib/tools/qarraydatapointer.h
index 533f7a306f..2245106ec0 100644
--- a/src/corelib/tools/qarraydatapointer.h
+++ b/src/corelib/tools/qarraydatapointer.h
@@ -134,6 +134,7 @@ public:
return (!d->isMutable() || d->ref.isShared());
}
+#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
void setSharable(bool sharable)
{
if (needsDetach()) {
@@ -147,6 +148,9 @@ public:
}
}
+ bool isSharable() const { return d->isSharable(); }
+#endif
+
void swap(QArrayDataPointer &other)
{
qSwap(d, other.d);
diff --git a/src/corelib/tools/qcontiguouscache.h b/src/corelib/tools/qcontiguouscache.h
index d601ddb819..e05ef33aa2 100644
--- a/src/corelib/tools/qcontiguouscache.h
+++ b/src/corelib/tools/qcontiguouscache.h
@@ -104,7 +104,9 @@ public:
inline void detach() { if (d->ref.load() != 1) detach_helper(); }
inline bool isDetached() const { return d->ref.load() == 1; }
+#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
inline void setSharable(bool sharable) { if (!sharable) detach(); d->sharable = sharable; }
+#endif
QContiguousCache<T> &operator=(const QContiguousCache<T> &other);
#ifdef Q_COMPILER_RVALUE_REFS
diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h
index 40e501355c..f68b02be2c 100644
--- a/src/corelib/tools/qhash.h
+++ b/src/corelib/tools/qhash.h
@@ -330,7 +330,9 @@ public:
inline void detach() { if (d->ref.isShared()) detach_helper(); }
inline bool isDetached() const { return !d->ref.isShared(); }
+#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
inline void setSharable(bool sharable) { if (!sharable) detach(); if (d != &QHashData::shared_null) d->sharable = sharable; }
+#endif
inline bool isSharedWith(const QHash<Key, T> &other) const { return d == other.d; }
void clear();
diff --git a/src/corelib/tools/qlinkedlist.h b/src/corelib/tools/qlinkedlist.h
index bdacdbcd26..3377d1bbc3 100644
--- a/src/corelib/tools/qlinkedlist.h
+++ b/src/corelib/tools/qlinkedlist.h
@@ -106,7 +106,9 @@ public:
inline void detach()
{ if (d->ref.isShared()) detach_helper2(this->e); }
inline bool isDetached() const { return !d->ref.isShared(); }
+#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
inline void setSharable(bool sharable) { if (!sharable) detach(); if (d != &QLinkedListData::shared_null) d->sharable = sharable; }
+#endif
inline bool isSharedWith(const QLinkedList<T> &other) const { return d == other.d; }
inline bool isEmpty() const { return d->size == 0; }
diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h
index 3a0d01aa8d..9e4ba70908 100644
--- a/src/corelib/tools/qlist.h
+++ b/src/corelib/tools/qlist.h
@@ -146,6 +146,7 @@ public:
}
inline bool isDetached() const { return !d->ref.isShared(); }
+#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
inline void setSharable(bool sharable)
{
if (sharable == d->ref.isSharable())
@@ -155,6 +156,7 @@ public:
if (d != &QListData::shared_null)
d->ref.setSharable(sharable);
}
+#endif
inline bool isSharedWith(const QList<T> &other) const { return d == other.d; }
inline bool isEmpty() const { return p.isEmpty(); }
diff --git a/src/corelib/tools/qmap.h b/src/corelib/tools/qmap.h
index 487039ccfb..76f8bd6f17 100644
--- a/src/corelib/tools/qmap.h
+++ b/src/corelib/tools/qmap.h
@@ -377,6 +377,7 @@ public:
inline void detach() { if (d->ref.isShared()) detach_helper(); }
inline bool isDetached() const { return !d->ref.isShared(); }
+#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
inline void setSharable(bool sharable)
{
if (sharable == d->ref.isSharable())
@@ -386,6 +387,7 @@ public:
// Don't call on shared_null
d->ref.setSharable(sharable);
}
+#endif
inline bool isSharedWith(const QMap<Key, T> &other) const { return d == other.d; }
void clear();
diff --git a/src/corelib/tools/qrefcount.h b/src/corelib/tools/qrefcount.h
index 84314b1fcc..3a8f0f3982 100644
--- a/src/corelib/tools/qrefcount.h
+++ b/src/corelib/tools/qrefcount.h
@@ -55,8 +55,10 @@ class RefCount
public:
inline bool ref() Q_DECL_NOTHROW {
int count = atomic.load();
+#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
if (count == 0) // !isSharable
return false;
+#endif
if (count != -1) // !isStatic
atomic.ref();
return true;
@@ -64,13 +66,16 @@ public:
inline bool deref() Q_DECL_NOTHROW {
int count = atomic.load();
+#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
if (count == 0) // !isSharable
return false;
+#endif
if (count == -1) // isStatic
return true;
return atomic.deref();
}
+#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
bool setSharable(bool sharable) Q_DECL_NOTHROW
{
Q_ASSERT(!isShared());
@@ -80,17 +85,18 @@ public:
return atomic.testAndSetRelaxed(1, 0);
}
- bool isStatic() const Q_DECL_NOTHROW
- {
- // Persistent object, never deleted
- return atomic.load() == -1;
- }
-
bool isSharable() const Q_DECL_NOTHROW
{
// Sharable === Shared ownership.
return atomic.load() != 0;
}
+#endif
+
+ bool isStatic() const Q_DECL_NOTHROW
+ {
+ // Persistent object, never deleted
+ return atomic.load() == -1;
+ }
bool isShared() const Q_DECL_NOTHROW
{
diff --git a/src/corelib/tools/qset.h b/src/corelib/tools/qset.h
index ad2f91b983..0cc704b6cf 100644
--- a/src/corelib/tools/qset.h
+++ b/src/corelib/tools/qset.h
@@ -91,7 +91,9 @@ public:
inline void detach() { q_hash.detach(); }
inline bool isDetached() const { return q_hash.isDetached(); }
+#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
inline void setSharable(bool sharable) { q_hash.setSharable(sharable); }
+#endif
inline void clear() { q_hash.clear(); }
diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h
index b0be98c296..6f7c534085 100644
--- a/src/corelib/tools/qvector.h
+++ b/src/corelib/tools/qvector.h
@@ -107,6 +107,7 @@ public:
inline void detach();
inline bool isDetached() const { return !d->ref.isShared(); }
+#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
inline void setSharable(bool sharable)
{
if (sharable == d->ref.isSharable())
@@ -122,6 +123,7 @@ public:
}
Q_ASSERT(d->ref.isSharable() == sharable);
}
+#endif
inline bool isSharedWith(const QVector<T> &other) const { return d == other.d; }
@@ -329,10 +331,12 @@ template <typename T>
void QVector<T>::detach()
{
if (!isDetached()) {
- if (d->alloc)
- reallocData(d->size, int(d->alloc));
- else
+#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
+ if (!d->alloc)
d = Data::unsharableEmpty();
+ else
+#endif
+ reallocData(d->size, int(d->alloc));
}
Q_ASSERT(isDetached());
}
@@ -484,7 +488,9 @@ void QVector<T>::reallocData(const int asize, const int aalloc, QArrayData::Allo
x = Data::allocate(aalloc, options);
Q_CHECK_PTR(x);
// aalloc is bigger then 0 so it is not [un]sharedEmpty
+#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
Q_ASSERT(x->ref.isSharable() || options.testFlag(QArrayData::Unsharable));
+#endif
Q_ASSERT(!x->ref.isStatic());
x->size = asize;
@@ -550,7 +556,9 @@ void QVector<T>::reallocData(const int asize, const int aalloc, QArrayData::Allo
Q_ASSERT(d->data());
Q_ASSERT(uint(d->size) <= d->alloc);
+#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
Q_ASSERT(d != Data::unsharableEmpty());
+#endif
Q_ASSERT(aalloc ? d != Data::sharedNull() : d == Data::sharedNull());
Q_ASSERT(d->alloc >= uint(aalloc));
Q_ASSERT(d->size == asize);
diff --git a/tests/auto/corelib/tools/qarraydata/simplevector.h b/tests/auto/corelib/tools/qarraydata/simplevector.h
index 40917c0172..af0ced130c 100644
--- a/tests/auto/corelib/tools/qarraydata/simplevector.h
+++ b/tests/auto/corelib/tools/qarraydata/simplevector.h
@@ -101,9 +101,10 @@ public:
bool isStatic() const { return d->ref.isStatic(); }
bool isShared() const { return d->ref.isShared(); }
bool isSharedWith(const SimpleVector &other) const { return d == other.d; }
+#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
bool isSharable() const { return d->ref.isSharable(); }
-
void setSharable(bool sharable) { d.setSharable(sharable); }
+#endif
size_t size() const { return d->size; }
size_t capacity() const { return d->alloc; }
diff --git a/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp b/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp
index 60b807a7bc..35ec0ef019 100644
--- a/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp
+++ b/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp
@@ -52,7 +52,9 @@ struct SharedNullVerifier
{
Q_ASSERT(QArrayData::shared_null[0].ref.isStatic());
Q_ASSERT(QArrayData::shared_null[0].ref.isShared());
+#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
Q_ASSERT(QArrayData::shared_null[0].ref.isSharable());
+#endif
}
};
@@ -107,7 +109,9 @@ void tst_QArrayData::referenceCounting()
QCOMPARE(array.ref.atomic.load(), 1);
QVERIFY(!array.ref.isStatic());
+#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
QVERIFY(array.ref.isSharable());
+#endif
QVERIFY(array.ref.ref());
QCOMPARE(array.ref.atomic.load(), 2);
@@ -127,6 +131,7 @@ void tst_QArrayData::referenceCounting()
// Now would be a good time to free/release allocated data
}
+#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
{
// Reference counting initialized to 0 (non-sharable)
QArrayData array = { { Q_BASIC_ATOMIC_INITIALIZER(0) }, 0, 0, 0, 0 };
@@ -145,6 +150,7 @@ void tst_QArrayData::referenceCounting()
// Free/release data
}
+#endif
{
// Reference counting initialized to -1 (static read-only data)
@@ -153,13 +159,16 @@ void tst_QArrayData::referenceCounting()
QCOMPARE(array.ref.atomic.load(), -1);
QVERIFY(array.ref.isStatic());
+#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
QVERIFY(array.ref.isSharable());
+#endif
QVERIFY(array.ref.ref());
QCOMPARE(array.ref.atomic.load(), -1);
QVERIFY(array.ref.deref());
QCOMPARE(array.ref.atomic.load(), -1);
+
}
}
@@ -169,16 +178,19 @@ void tst_QArrayData::sharedNullEmpty()
QArrayData *empty = QArrayData::allocate(1, Q_ALIGNOF(QArrayData), 0);
QVERIFY(null->ref.isStatic());
- QVERIFY(null->ref.isSharable());
QVERIFY(null->ref.isShared());
QVERIFY(empty->ref.isStatic());
- QVERIFY(empty->ref.isSharable());
QVERIFY(empty->ref.isShared());
QCOMPARE(null->ref.atomic.load(), -1);
QCOMPARE(empty->ref.atomic.load(), -1);
+#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
+ QVERIFY(null->ref.isSharable());
+ QVERIFY(empty->ref.isSharable());
+#endif
+
QVERIFY(null->ref.ref());
QVERIFY(empty->ref.ref());
@@ -305,6 +317,7 @@ void tst_QArrayData::simpleVector()
QVERIFY(!v7.isShared());
QVERIFY(!v8.isShared());
+#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
QVERIFY(v1.isSharable());
QVERIFY(v2.isSharable());
QVERIFY(v3.isSharable());
@@ -313,6 +326,7 @@ void tst_QArrayData::simpleVector()
QVERIFY(v6.isSharable());
QVERIFY(v7.isSharable());
QVERIFY(v8.isSharable());
+#endif
QVERIFY(v1.isSharedWith(v2));
QVERIFY(v1.isSharedWith(v3));
@@ -496,6 +510,7 @@ void tst_QArrayData::simpleVector()
for (int i = 0; i < 120; ++i)
QCOMPARE(v1[i], v8[i % 10]);
+#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
{
v7.setSharable(true);
QVERIFY(v7.isSharable());
@@ -558,6 +573,7 @@ void tst_QArrayData::simpleVector()
QVERIFY(null.isEmpty());
QVERIFY(empty.isEmpty());
}
+#endif
}
Q_DECLARE_METATYPE(SimpleVector<int>)
@@ -648,7 +664,7 @@ void tst_QArrayData::allocate_data()
QTest::addColumn<size_t>("alignment");
QTest::addColumn<QArrayData::AllocationOptions>("allocateOptions");
QTest::addColumn<bool>("isCapacityReserved");
- QTest::addColumn<bool>("isSharable");
+ QTest::addColumn<bool>("isSharable"); // ### Qt6: remove
QTest::addColumn<const QArrayData *>("commonEmpty");
struct {
@@ -662,10 +678,12 @@ void tst_QArrayData::allocate_data()
};
QArrayData *shared_empty = QArrayData::allocate(0, Q_ALIGNOF(QArrayData), 0);
- QArrayData *unsharable_empty = QArrayData::allocate(0, Q_ALIGNOF(QArrayData), 0, QArrayData::Unsharable);
-
QVERIFY(shared_empty);
+
+#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
+ QArrayData *unsharable_empty = QArrayData::allocate(0, Q_ALIGNOF(QArrayData), 0, QArrayData::Unsharable);
QVERIFY(unsharable_empty);
+#endif
struct {
char const *description;
@@ -676,10 +694,12 @@ void tst_QArrayData::allocate_data()
} options[] = {
{ "Default", QArrayData::Default, false, true, shared_empty },
{ "Reserved", QArrayData::CapacityReserved, true, true, shared_empty },
+#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
{ "Reserved | Unsharable",
QArrayData::CapacityReserved | QArrayData::Unsharable, true, false,
unsharable_empty },
{ "Unsharable", QArrayData::Unsharable, false, false, unsharable_empty },
+#endif
{ "Grow", QArrayData::Grow, false, true, shared_empty }
};
@@ -700,7 +720,6 @@ void tst_QArrayData::allocate()
QFETCH(size_t, alignment);
QFETCH(QArrayData::AllocationOptions, allocateOptions);
QFETCH(bool, isCapacityReserved);
- QFETCH(bool, isSharable);
QFETCH(const QArrayData *, commonEmpty);
// Minimum alignment that can be requested is that of QArrayData.
@@ -725,7 +744,10 @@ void tst_QArrayData::allocate()
else
QCOMPARE(data->alloc, uint(capacity));
QCOMPARE(data->capacityReserved, uint(isCapacityReserved));
+#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
+ QFETCH(bool, isSharable);
QCOMPARE(data->ref.isSharable(), isSharable);
+#endif
// Check that the allocated array can be used. Best tested with a
// memory checker, such as valgrind, running.
@@ -1302,6 +1324,7 @@ static inline bool arrayIsFilledWith(const QArrayDataPointer<int> &array,
void tst_QArrayData::setSharable_data()
{
+#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
QTest::addColumn<QArrayDataPointer<int> >("array");
QTest::addColumn<size_t>("size");
QTest::addColumn<size_t>("capacity");
@@ -1342,10 +1365,12 @@ void tst_QArrayData::setSharable_data()
QTest::newRow("non-empty-reserved") << nonEmptyReserved << size_t(7) << size_t(15) << true << 2;
QTest::newRow("static-array") << staticArray << size_t(10) << size_t(0) << false << 3;
QTest::newRow("raw-data") << rawData << size_t(10) << size_t(0) << false << 3;
+#endif
}
void tst_QArrayData::setSharable()
{
+#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
QFETCH(QArrayDataPointer<int>, array);
QFETCH(size_t, size);
QFETCH(size_t, capacity);
@@ -1424,6 +1449,7 @@ void tst_QArrayData::setSharable()
QCOMPARE(array->ref.isShared(), !(size || isCapacityReserved));
QVERIFY(array->ref.isSharable());
+#endif
}
struct ResetOnDtor
@@ -1474,6 +1500,7 @@ void fromRawData_impl()
QVERIFY((const T *)raw.constBegin() != array);
}
+#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
{
// Immutable, unsharable
SimpleVector<T> raw = SimpleVector<T>::fromRawData(array,
@@ -1502,6 +1529,7 @@ void fromRawData_impl()
QCOMPARE(raw.back(), T(11));
QVERIFY((const T *)raw.constBegin() != array);
}
+#endif
}
void tst_QArrayData::fromRawData_data()
@@ -1558,7 +1586,9 @@ void tst_QArrayData::literals()
QVERIFY(v.isStatic());
#endif
+#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
QVERIFY(v.isSharable());
+#endif
QCOMPARE((void*)(const char*)(v.constBegin() + v.size()), (void*)(const char*)v.constEnd());
for (int i = 0; i < 10; ++i)
@@ -1607,7 +1637,9 @@ void tst_QArrayData::variadicLiterals()
QVERIFY(v.isStatic());
+#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
QVERIFY(v.isSharable());
+#endif
QCOMPARE((const int *)(v.constBegin() + v.size()), (const int *)v.constEnd());
for (int i = 0; i < 7; ++i)
diff --git a/tests/auto/corelib/tools/qhash/tst_qhash.cpp b/tests/auto/corelib/tools/qhash/tst_qhash.cpp
index 73f8973245..9c96aaf78d 100644
--- a/tests/auto/corelib/tools/qhash/tst_qhash.cpp
+++ b/tests/auto/corelib/tools/qhash/tst_qhash.cpp
@@ -1217,12 +1217,14 @@ void tst_QHash::noNeedlessRehashes()
void tst_QHash::const_shared_null()
{
+ QHash<int, QString> hash2;
+#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
QHash<int, QString> hash1;
hash1.setSharable(false);
QVERIFY(hash1.isDetached());
- QHash<int, QString> hash2;
hash2.setSharable(true);
+#endif
QVERIFY(!hash2.isDetached());
}
diff --git a/tests/auto/corelib/tools/qlinkedlist/tst_qlinkedlist.cpp b/tests/auto/corelib/tools/qlinkedlist/tst_qlinkedlist.cpp
index 49b32d5534..9e47e9c6d6 100644
--- a/tests/auto/corelib/tools/qlinkedlist/tst_qlinkedlist.cpp
+++ b/tests/auto/corelib/tools/qlinkedlist/tst_qlinkedlist.cpp
@@ -1018,12 +1018,14 @@ void tst_QLinkedList::initializeList() const
template<typename T>
void tst_QLinkedList::constSharedNull() const
{
+ QLinkedList<T> list2;
+#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
QLinkedList<T> list1;
list1.setSharable(false);
QVERIFY(list1.isDetached());
- QLinkedList<T> list2;
list2.setSharable(true);
+#endif
QVERIFY(!list2.isDetached());
}
@@ -1049,6 +1051,7 @@ void tst_QLinkedList::constSharedNullComplex() const
void tst_QLinkedList::setSharableInt() const
{
+#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
QLinkedList<int> orglist;
orglist << 0 << 1 << 2 << 3 << 4 << 5;
int size = 6;
@@ -1094,6 +1097,7 @@ void tst_QLinkedList::setSharableInt() const
}
QCOMPARE(list.size(), size);
+#endif
}
QTEST_APPLESS_MAIN(tst_QLinkedList)
diff --git a/tests/auto/corelib/tools/qlist/tst_qlist.cpp b/tests/auto/corelib/tools/qlist/tst_qlist.cpp
index d77cc4a37c..b368359c62 100644
--- a/tests/auto/corelib/tools/qlist/tst_qlist.cpp
+++ b/tests/auto/corelib/tools/qlist/tst_qlist.cpp
@@ -1522,12 +1522,14 @@ void tst_QList::initializeList() const
template<typename T>
void tst_QList::constSharedNull() const
{
+ QList<T> list2;
+#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
QList<T> list1;
list1.setSharable(false);
QVERIFY(list1.isDetached());
- QList<T> list2;
list2.setSharable(true);
+#endif
QVERIFY(!list2.isDetached());
}
@@ -1553,16 +1555,19 @@ void tst_QList::constSharedNullComplex() const
template <class T>
void generateSetSharableData()
{
+#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
QTest::addColumn<QList<T> >("list");
QTest::addColumn<int>("size");
QTest::newRow("null") << QList<T>() << 0;
QTest::newRow("non-empty") << (QList<T>() << T(0) << T(1) << T(2) << T(3) << T(4)) << 5;
+#endif
}
template <class T>
void runSetSharableTest()
{
+#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
QFETCH(QList<T>, list);
QFETCH(int, size);
@@ -1602,6 +1607,7 @@ void runSetSharableTest()
QCOMPARE(int(list[i]), i);
QCOMPARE(list.size(), size);
+#endif
}
void tst_QList::setSharableInt_data() const
diff --git a/tests/auto/corelib/tools/qmap/tst_qmap.cpp b/tests/auto/corelib/tools/qmap/tst_qmap.cpp
index e812e5a337..00e669c1d8 100644
--- a/tests/auto/corelib/tools/qmap/tst_qmap.cpp
+++ b/tests/auto/corelib/tools/qmap/tst_qmap.cpp
@@ -984,12 +984,14 @@ void tst_QMap::qmultimap_specific()
void tst_QMap::const_shared_null()
{
+ QMap<int, QString> map2;
+#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
QMap<int, QString> map1;
map1.setSharable(false);
QVERIFY(map1.isDetached());
- QMap<int, QString> map2;
map2.setSharable(true);
+#endif
QVERIFY(!map2.isDetached());
}
@@ -1046,6 +1048,7 @@ const T &const_(const T &t)
void tst_QMap::setSharable()
{
+#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
QMap<int, QString> map;
map.insert(1, "um");
@@ -1095,6 +1098,7 @@ void tst_QMap::setSharable()
QVERIFY(!map.isDetached());
QVERIFY(copy.isSharedWith(map));
}
+#endif
}
void tst_QMap::insert()
@@ -1204,7 +1208,6 @@ void tst_QMap::initializerList()
void tst_QMap::testInsertWithHint()
{
QMap<int, int> map;
- map.setSharable(false);
// Check with end hint();
map.insert(map.constEnd(), 3, 1); // size == 1
@@ -1268,7 +1271,6 @@ void tst_QMap::testInsertWithHint()
void tst_QMap::testInsertMultiWithHint()
{
QMap<int, int> map;
- map.setSharable(false);
typedef QMap<int, int>::const_iterator cite; // Hack since we define QT_STRICT_ITERATORS
map.insertMulti(cite(map.end()), 64, 65);
diff --git a/tests/auto/corelib/tools/qvector/tst_qvector.cpp b/tests/auto/corelib/tools/qvector/tst_qvector.cpp
index c9545c8eb4..f1efbf0812 100644
--- a/tests/auto/corelib/tools/qvector/tst_qvector.cpp
+++ b/tests/auto/corelib/tools/qvector/tst_qvector.cpp
@@ -265,12 +265,15 @@ private slots:
void initializeListCustom();
void const_shared_null();
+#if 1
+ // ### Qt6 remove this section
void setSharableInt_data();
void setSharableInt();
void setSharableMovable_data();
void setSharableMovable();
void setSharableCustom_data();
void setSharableCustom();
+#endif
void detachInt() const;
void detachMovable() const;
@@ -395,15 +398,17 @@ void tst_QVector::copyConstructor() const
}
{
QVector<T> v1;
- v1.setSharable(false);
+ v1 << value1 << value2 << value3 << value4;
QVector<T> v2(v1);
- QVERIFY(!v1.isSharedWith(v2));
QCOMPARE(v1, v2);
}
+#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
+ // ### Qt6 remove this section
{
QVector<T> v1;
- v1 << value1 << value2 << value3 << value4;
+ v1.setSharable(false);
QVector<T> v2(v1);
+ QVERIFY(!v1.isSharedWith(v2));
QCOMPARE(v1, v2);
}
{
@@ -414,6 +419,7 @@ void tst_QVector::copyConstructor() const
QVERIFY(!v1.isSharedWith(v2));
QCOMPARE(v1, v2);
}
+#endif
}
void tst_QVector::copyConstructorInt() const
@@ -514,6 +520,8 @@ void tst_QVector::append() const
QVERIFY(v.size() == 3);
QCOMPARE(v.at(v.size() - 1), SimpleValue<T>::at(0));
}
+#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
+ // ### Qt6 remove this section
{
QVector<T> v(2);
v.reserve(12);
@@ -522,6 +530,7 @@ void tst_QVector::append() const
QVERIFY(v.size() == 3);
QCOMPARE(v.last(), SimpleValue<T>::at(0));
}
+#endif
}
void tst_QVector::appendInt() const
@@ -819,12 +828,15 @@ void tst_QVector::eraseEmpty() const
v.erase(v.begin(), v.end());
QCOMPARE(v.size(), 0);
}
+#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
+ // ### Qt6 remove this section
{
QVector<T> v;
v.setSharable(false);
v.erase(v.begin(), v.end());
QCOMPARE(v.size(), 0);
}
+#endif
}
void tst_QVector::eraseEmptyInt() const
@@ -855,6 +867,8 @@ void tst_QVector::eraseEmptyReserved() const
v.erase(v.begin(), v.end());
QCOMPARE(v.size(), 0);
}
+#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
+ // ### Qt6 remove this section
{
QVector<T> v;
v.reserve(10);
@@ -862,6 +876,7 @@ void tst_QVector::eraseEmptyReserved() const
v.erase(v.begin(), v.end());
QCOMPARE(v.size(), 0);
}
+#endif
}
void tst_QVector::eraseEmptyReservedInt() const
@@ -968,6 +983,8 @@ void tst_QVector::erase(bool shared) const
if (shared)
QCOMPARE(SimpleValue<T>::vector(12), *svc.copy);
}
+#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
+ // ### Qt6 remove this section
{
QVector<T> v = SimpleValue<T>::vector(10);
SharedVectorChecker<T> svc(v, shared);
@@ -980,6 +997,7 @@ void tst_QVector::erase(bool shared) const
if (shared)
QCOMPARE(SimpleValue<T>::vector(10), *svc.copy);
}
+#endif
}
void tst_QVector::eraseInt() const
@@ -1052,6 +1070,8 @@ template<typename T> void tst_QVector::eraseReserved() const
v.erase(v.begin() + 1, v.end() - 1);
QCOMPARE(v.size(), 2);
}
+#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
+ // ### Qt6 remove this section
{
QVector<T> v(10);
v.reserve(16);
@@ -1061,6 +1081,7 @@ template<typename T> void tst_QVector::eraseReserved() const
v.erase(v.begin(), v.end() - 1);
QCOMPARE(v.size(), 1);
}
+#endif
}
void tst_QVector::eraseReservedInt() const
@@ -1512,6 +1533,14 @@ void tst_QVector::resizePOD_data() const
QVERIFY(emptyReserved.capacity() >= 10);
QVERIFY(nonEmptyReserved.capacity() >= 15);
+ QTest::newRow("null") << null << 10;
+ QTest::newRow("empty") << empty << 10;
+ QTest::newRow("emptyReserved") << emptyReserved << 10;
+ QTest::newRow("nonEmpty") << nonEmpty << 10;
+ QTest::newRow("nonEmptyReserved") << nonEmptyReserved << 10;
+
+#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
+ // ### Qt6 remove this section
QVector<int> nullNotShared;
QVector<int> emptyNotShared(0, 5);
QVector<int> emptyReservedNotShared;
@@ -1530,16 +1559,12 @@ void tst_QVector::resizePOD_data() const
nonEmptyNotShared.setSharable(false);
nonEmptyReservedNotShared.setSharable(false);
- QTest::newRow("null") << null << 10;
- QTest::newRow("empty") << empty << 10;
- QTest::newRow("emptyReserved") << emptyReserved << 10;
- QTest::newRow("nonEmpty") << nonEmpty << 10;
- QTest::newRow("nonEmptyReserved") << nonEmptyReserved << 10;
QTest::newRow("nullNotShared") << nullNotShared << 10;
QTest::newRow("emptyNotShared") << emptyNotShared << 10;
QTest::newRow("emptyReservedNotShared") << emptyReservedNotShared << 10;
QTest::newRow("nonEmptyNotShared") << nonEmptyNotShared << 10;
QTest::newRow("nonEmptyReservedNotShared") << nonEmptyReservedNotShared << 10;
+#endif
}
void tst_QVector::resizePOD() const
@@ -1583,6 +1608,14 @@ void tst_QVector::resizeComplexMovable_data() const
QVERIFY(emptyReserved.capacity() >= 10);
QVERIFY(nonEmptyReserved.capacity() >= 15);
+ QTest::newRow("null") << null << 10;
+ QTest::newRow("empty") << empty << 10;
+ QTest::newRow("emptyReserved") << emptyReserved << 10;
+ QTest::newRow("nonEmpty") << nonEmpty << 10;
+ QTest::newRow("nonEmptyReserved") << nonEmptyReserved << 10;
+
+#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
+ // ### Qt6 remove this section
QVector<Movable> nullNotShared;
QVector<Movable> emptyNotShared(0, 'Q');
QVector<Movable> emptyReservedNotShared;
@@ -1601,16 +1634,12 @@ void tst_QVector::resizeComplexMovable_data() const
nonEmptyNotShared.setSharable(false);
nonEmptyReservedNotShared.setSharable(false);
- QTest::newRow("null") << null << 10;
- QTest::newRow("empty") << empty << 10;
- QTest::newRow("emptyReserved") << emptyReserved << 10;
- QTest::newRow("nonEmpty") << nonEmpty << 10;
- QTest::newRow("nonEmptyReserved") << nonEmptyReserved << 10;
QTest::newRow("nullNotShared") << nullNotShared << 10;
QTest::newRow("emptyNotShared") << emptyNotShared << 10;
QTest::newRow("emptyReservedNotShared") << emptyReservedNotShared << 10;
QTest::newRow("nonEmptyNotShared") << nonEmptyNotShared << 10;
QTest::newRow("nonEmptyReservedNotShared") << nonEmptyReservedNotShared << 10;
+#endif
}
void tst_QVector::resizeComplexMovable() const
@@ -1658,6 +1687,14 @@ void tst_QVector::resizeComplex_data() const
QVERIFY(emptyReserved.capacity() >= 10);
QVERIFY(nonEmptyReserved.capacity() >= 15);
+ QTest::newRow("null") << null << 10;
+ QTest::newRow("empty") << empty << 10;
+ QTest::newRow("emptyReserved") << emptyReserved << 10;
+ QTest::newRow("nonEmpty") << nonEmpty << 10;
+ QTest::newRow("nonEmptyReserved") << nonEmptyReserved << 10;
+
+#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
+ // ### Qt6 remove this section
QVector<Custom> nullNotShared;
QVector<Custom> emptyNotShared(0, '0');
QVector<Custom> emptyReservedNotShared;
@@ -1676,16 +1713,12 @@ void tst_QVector::resizeComplex_data() const
nonEmptyNotShared.setSharable(false);
nonEmptyReservedNotShared.setSharable(false);
- QTest::newRow("null") << null << 10;
- QTest::newRow("empty") << empty << 10;
- QTest::newRow("emptyReserved") << emptyReserved << 10;
- QTest::newRow("nonEmpty") << nonEmpty << 10;
- QTest::newRow("nonEmptyReserved") << nonEmptyReserved << 10;
QTest::newRow("nullNotShared") << nullNotShared << 10;
QTest::newRow("emptyNotShared") << emptyNotShared << 10;
QTest::newRow("emptyReservedNotShared") << emptyReservedNotShared << 10;
QTest::newRow("nonEmptyNotShared") << nonEmptyNotShared << 10;
QTest::newRow("nonEmptyReservedNotShared") << nonEmptyReservedNotShared << 10;
+#endif
}
void tst_QVector::resizeComplex() const
@@ -2070,15 +2103,20 @@ void tst_QVector::initializeListCustom()
void tst_QVector::const_shared_null()
{
+ QVector<int> v2;
+#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
+ // ### Qt6 remove this section
QVector<int> v1;
v1.setSharable(false);
QVERIFY(v1.isDetached());
- QVector<int> v2;
v2.setSharable(true);
+#endif
QVERIFY(!v2.isDetached());
}
+#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
+// ### Qt6 remove this section
template<typename T>
void tst_QVector::setSharable_data() const
{
@@ -2109,21 +2147,6 @@ void tst_QVector::setSharable_data() const
QTest::newRow("non-empty, Reserved") << nonEmptyReserved << 7 << 15 << true;
}
-void tst_QVector::setSharableInt_data()
-{
- setSharable_data<int>();
-}
-
-void tst_QVector::setSharableMovable_data()
-{
- setSharable_data<Movable>();
-}
-
-void tst_QVector::setSharableCustom_data()
-{
- setSharable_data<Custom>();
-}
-
template<typename T>
void tst_QVector::setSharable() const
{
@@ -2185,6 +2208,30 @@ void tst_QVector::setSharable() const
.arg(vector.capacity())
.arg(capacity)));
}
+#else
+template<typename T> void tst_QVector::setSharable_data() const
+{
+}
+
+template<typename T> void tst_QVector::setSharable() const
+{
+}
+#endif
+
+void tst_QVector::setSharableInt_data()
+{
+ setSharable_data<int>();
+}
+
+void tst_QVector::setSharableMovable_data()
+{
+ setSharable_data<Movable>();
+}
+
+void tst_QVector::setSharableCustom_data()
+{
+ setSharable_data<Custom>();
+}
void tst_QVector::setSharableInt()
{