Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/tools/qsharedpointer.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||
---|---|---|---|---|---|---|---|---|
1 | - | |||||||
2 | - | |||||||
3 | - | |||||||
4 | - | |||||||
5 | - | |||||||
6 | - | |||||||
7 | - | |||||||
8 | - | |||||||
9 | - | |||||||
10 | - | |||||||
11 | - | |||||||
12 | - | |||||||
13 | void QtSharedPointer::ExternalRefCountData::setQObjectShared(const QObject *, bool) | - | ||||||
14 | {} | - | ||||||
15 | void QtSharedPointer::ExternalRefCountData::checkQObjectShared(const QObject *) | - | ||||||
16 | { | - | ||||||
17 | if (strongref.load() < 0
| 2-60 | ||||||
18 | QMessageLogger(__FILE__, 1328, __PRETTY_FUNCTION__).warning("QSharedPointer: cannot create a QSharedPointer from a QObject-tracking QWeakPointer"); executed 2 times by 1 test: QMessageLogger(__FILE__, 1328, __PRETTY_FUNCTION__).warning("QSharedPointer: cannot create a QSharedPointer from a QObject-tracking QWeakPointer"); Executed by:
| 2 | ||||||
19 | } executed 62 times by 5 tests: end of block Executed by:
| 62 | ||||||
20 | - | |||||||
21 | QtSharedPointer::ExternalRefCountData *QtSharedPointer::ExternalRefCountData::getAndRef(const QObject *obj) | - | ||||||
22 | { | - | ||||||
23 | ((!(obj)) ? qt_assert("obj",__FILE__,1333) : qt_noop()); | - | ||||||
24 | QObjectPrivate *d = QObjectPrivate::get(const_cast<QObject *>(obj)); | - | ||||||
25 | ((!(!d->wasDeleted)) ? qt_assert_x("QWeakPointer", "Detected QWeakPointer creation in a QObject being deleted",__FILE__,1335) : qt_noop()); | - | ||||||
26 | - | |||||||
27 | ExternalRefCountData *that = d->sharedRefcount.load(); | - | ||||||
28 | if (that
| 68025-217414 | ||||||
29 | that->weakref.ref(); | - | ||||||
30 | return executed 217414 times by 223 tests: that;return that; Executed by:
executed 217414 times by 223 tests: return that; Executed by:
| 217414 | ||||||
31 | } | - | ||||||
32 | - | |||||||
33 | - | |||||||
34 | ExternalRefCountData *x = new ExternalRefCountData(Qt::Uninitialized); | - | ||||||
35 | x->strongref.store(-1); | - | ||||||
36 | x->weakref.store(2); | - | ||||||
37 | if (!d->sharedRefcount.testAndSetRelease(0, x)
| 0-68025 | ||||||
38 | delete x; | - | ||||||
39 | x = d->sharedRefcount.loadAcquire(); | - | ||||||
40 | x->weakref.ref(); | - | ||||||
41 | } never executed: end of block | 0 | ||||||
42 | return executed 68025 times by 243 tests: x;return x; Executed by:
executed 68025 times by 243 tests: return x; Executed by:
| 68025 | ||||||
43 | } | - | ||||||
44 | - | |||||||
45 | - | |||||||
46 | - | |||||||
47 | - | |||||||
48 | - | |||||||
49 | - | |||||||
50 | QSharedPointer<QObject> QtSharedPointer::sharedPointerFromVariant_internal(const QVariant &variant) | - | ||||||
51 | { | - | ||||||
52 | ((!(QMetaType::typeFlags(variant.userType()) & QMetaType::SharedPointerToQObject)) ? qt_assert("QMetaType::typeFlags(variant.userType()) & QMetaType::SharedPointerToQObject",__FILE__,1362) : qt_noop()); | - | ||||||
53 | return executed 8 times by 2 tests: *reinterpret_cast<const QSharedPointer<QObject>*>(variant.constData());return *reinterpret_cast<const QSharedPointer<QObject>*>(variant.constData()); Executed by:
executed 8 times by 2 tests: return *reinterpret_cast<const QSharedPointer<QObject>*>(variant.constData()); Executed by:
| 8 | ||||||
54 | } | - | ||||||
55 | - | |||||||
56 | - | |||||||
57 | - | |||||||
58 | - | |||||||
59 | - | |||||||
60 | - | |||||||
61 | QWeakPointer<QObject> QtSharedPointer::weakPointerFromVariant_internal(const QVariant &variant) | - | ||||||
62 | { | - | ||||||
63 | ((!(QMetaType::typeFlags(variant.userType()) & QMetaType::WeakPointerToQObject || QMetaType::typeFlags(variant.userType()) & QMetaType::TrackingPointerToQObject)) ? qt_assert("QMetaType::typeFlags(variant.userType()) & QMetaType::WeakPointerToQObject || QMetaType::typeFlags(variant.userType()) & QMetaType::TrackingPointerToQObject",__FILE__,1373) : qt_noop()); | - | ||||||
64 | return executed 21 times by 3 tests: *reinterpret_cast<const QWeakPointer<QObject>*>(variant.constData());return *reinterpret_cast<const QWeakPointer<QObject>*>(variant.constData()); Executed by:
executed 21 times by 3 tests: return *reinterpret_cast<const QWeakPointer<QObject>*>(variant.constData()); Executed by:
| 21 | ||||||
65 | } | - | ||||||
66 | - | |||||||
67 | - | |||||||
68 | namespace { | - | ||||||
69 | - | |||||||
70 | struct Data { | - | ||||||
71 | const volatile void *pointer; | - | ||||||
72 | - | |||||||
73 | - | |||||||
74 | - | |||||||
75 | }; | - | ||||||
76 | - | |||||||
77 | class KnownPointers | - | ||||||
78 | { | - | ||||||
79 | public: | - | ||||||
80 | QMutex mutex; | - | ||||||
81 | QHash<const void *, Data> dPointers; | - | ||||||
82 | QHash<const volatile void *, const void *> dataPointers; | - | ||||||
83 | }; | - | ||||||
84 | } | - | ||||||
85 | - | |||||||
86 | namespace { namespace Q_QGS_knownPointers { typedef KnownPointers Type; QBasicAtomicInt guard = { QtGlobalStatic::Uninitialized }; __attribute__((visibility("hidden"))) inline Type *innerFunction() { struct HolderBase { ~HolderBase() noexcept { if (guard.load() == QtGlobalStatic::Initialized
executed 2 times by 2 tests: }guard.store(QtGlobalStatic::Destroyed); Executed by:
executed 2 times by 2 tests: }; static struct Holder : public HolderBase { Type value; Holder() noexcept(noexcept(Type ())) : value () { guard.store(QtGlobalStatic::Initialized); } } holder; returnend of block Executed by:
executed 387 times by 2 tests: &holder.value;return &holder.value; Executed by:
executed 387 times by 2 tests: } } } static QGlobalStatic<KnownPointers, Q_QGS_knownPointers::innerFunction, Q_QGS_knownPointers::guard> knownPointers;return &holder.value; Executed by:
| 0-387 | ||||||
87 | - | |||||||
88 | - | |||||||
89 | - | |||||||
90 | namespace QtSharedPointer { | - | ||||||
91 | __attribute__((visibility("default"))) void internalSafetyCheckCleanCheck(); | - | ||||||
92 | } | - | ||||||
93 | - | |||||||
94 | - | |||||||
95 | - | |||||||
96 | - | |||||||
97 | void QtSharedPointer::internalSafetyCheckAdd(const void *d_ptr, const volatile void *ptr) | - | ||||||
98 | { | - | ||||||
99 | KnownPointers *const kp = knownPointers(); | - | ||||||
100 | if (!kp
| 0-133 | ||||||
101 | return; never executed: return; | 0 | ||||||
102 | - | |||||||
103 | QMutexLocker lock(&kp->mutex); | - | ||||||
104 | ((!(!kp->dPointers.contains(d_ptr))) ? qt_assert("!kp->dPointers.contains(d_ptr)",__FILE__,1502) : qt_noop()); | - | ||||||
105 | - | |||||||
106 | - | |||||||
107 | - | |||||||
108 | const void *other_d_ptr = kp->dataPointers.value(ptr, 0); | - | ||||||
109 | if (__builtin_expect(!!(other_d_ptr), false)
| 0-133 | ||||||
110 | - | |||||||
111 | - | |||||||
112 | - | |||||||
113 | QMessageLogger(__FILE__, 1511, __PRETTY_FUNCTION__).fatal("QSharedPointer: internal self-check failed: pointer %p was already tracked " | - | ||||||
114 | "by another QSharedPointer object %p", ptr, other_d_ptr); | - | ||||||
115 | } never executed: end of block | 0 | ||||||
116 | - | |||||||
117 | Data data; | - | ||||||
118 | data.pointer = ptr; | - | ||||||
119 | - | |||||||
120 | - | |||||||
121 | - | |||||||
122 | - | |||||||
123 | kp->dPointers.insert(d_ptr, data); | - | ||||||
124 | kp->dataPointers.insert(ptr, d_ptr); | - | ||||||
125 | ((!(kp->dPointers.size() == kp->dataPointers.size())) ? qt_assert("kp->dPointers.size() == kp->dataPointers.size()",__FILE__,1523) : qt_noop()); | - | ||||||
126 | } executed 133 times by 1 test: end of block Executed by:
| 133 | ||||||
127 | - | |||||||
128 | - | |||||||
129 | - | |||||||
130 | - | |||||||
131 | void QtSharedPointer::internalSafetyCheckRemove(const void *d_ptr) | - | ||||||
132 | { | - | ||||||
133 | KnownPointers *const kp = knownPointers(); | - | ||||||
134 | if (!kp
| 0-133 | ||||||
135 | return; never executed: return; | 0 | ||||||
136 | - | |||||||
137 | QMutexLocker lock(&kp->mutex); | - | ||||||
138 | - | |||||||
139 | const auto it = kp->dPointers.constFind(d_ptr); | - | ||||||
140 | if (__builtin_expect(!!(it == kp->dPointers.cend()), false)
| 0-133 | ||||||
141 | QMessageLogger(__FILE__, 1539, __PRETTY_FUNCTION__).fatal("QSharedPointer: internal self-check inconsistency: pointer %p was not tracked. " | - | ||||||
142 | "To use QT_SHAREDPOINTER_TRACK_POINTERS, you have to enable it throughout " | - | ||||||
143 | "in your code.", d_ptr); | - | ||||||
144 | } never executed: end of block | 0 | ||||||
145 | - | |||||||
146 | const auto it2 = kp->dataPointers.constFind(it->pointer); | - | ||||||
147 | ((!(it2 != kp->dataPointers.cend())) ? qt_assert("it2 != kp->dataPointers.cend()",__FILE__,1545) : qt_noop()); | - | ||||||
148 | - | |||||||
149 | - | |||||||
150 | - | |||||||
151 | - | |||||||
152 | kp->dataPointers.erase(it2); | - | ||||||
153 | kp->dPointers.erase(it); | - | ||||||
154 | ((!(kp->dPointers.size() == kp->dataPointers.size())) ? qt_assert("kp->dPointers.size() == kp->dataPointers.size()",__FILE__,1552) : qt_noop()); | - | ||||||
155 | } executed 133 times by 1 test: end of block Executed by:
| 133 | ||||||
156 | - | |||||||
157 | - | |||||||
158 | - | |||||||
159 | - | |||||||
160 | - | |||||||
161 | void QtSharedPointer::internalSafetyCheckCleanCheck() | - | ||||||
162 | { | - | ||||||
163 | - | |||||||
164 | KnownPointers *const kp = knownPointers(); | - | ||||||
165 | ((!(kp)) ? qt_assert_x("internalSafetyCheckSelfCheck()", "Called after global statics deletion!",__FILE__,1563) : qt_noop()); | - | ||||||
166 | - | |||||||
167 | if (__builtin_expect(!!(kp->dPointers.size() != kp->dataPointers.size()), false)
| 0-121 | ||||||
168 | QMessageLogger(__FILE__, 1566, __PRETTY_FUNCTION__).fatal("Internal consistency error: the number of pointers is not equal!"); never executed: QMessageLogger(__FILE__, 1566, __PRETTY_FUNCTION__).fatal("Internal consistency error: the number of pointers is not equal!"); | 0 | ||||||
169 | - | |||||||
170 | if (__builtin_expect(!!(!kp->dPointers.isEmpty()), false)
| 0-121 | ||||||
171 | QMessageLogger(__FILE__, 1569, __PRETTY_FUNCTION__).fatal("Pointer cleaning failed: %d entries remaining", kp->dPointers.size()); never executed: QMessageLogger(__FILE__, 1569, __PRETTY_FUNCTION__).fatal("Pointer cleaning failed: %d entries remaining", kp->dPointers.size()); | 0 | ||||||
172 | - | |||||||
173 | } executed 121 times by 2 tests: end of block Executed by:
| 121 | ||||||
174 | - | |||||||
175 | - | |||||||
Switch to Source code | Preprocessed file |