QProperty: Use RefCounted as intended
You're not supposed to mess with the refcount directly. That's what the addRef() and deref() methods are for. Change-Id: I5cae946cef7ac72dd99b247ade95590d142c269e Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
parent
7071010880
commit
476e503cfb
@ -27,9 +27,9 @@ void QPropertyBindingPrivatePtr::reset(QtPrivate::RefCounted *ptr) noexcept
|
|||||||
{
|
{
|
||||||
if (ptr != d) {
|
if (ptr != d) {
|
||||||
if (ptr)
|
if (ptr)
|
||||||
ptr->ref++;
|
ptr->addRef();
|
||||||
auto *old = std::exchange(d, ptr);
|
auto *old = std::exchange(d, ptr);
|
||||||
if (old && (--old->ref == 0))
|
if (old && !old->deref())
|
||||||
QPropertyBindingPrivate::destroyAndFreeMemory(static_cast<QPropertyBindingPrivate *>(d));
|
QPropertyBindingPrivate::destroyAndFreeMemory(static_cast<QPropertyBindingPrivate *>(d));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -310,7 +310,7 @@ void QPropertyBindingPrivate::unlinkAndDeref()
|
|||||||
{
|
{
|
||||||
clearDependencyObservers();
|
clearDependencyObservers();
|
||||||
propertyDataPtr = nullptr;
|
propertyDataPtr = nullptr;
|
||||||
if (--ref == 0)
|
if (!deref())
|
||||||
destroyAndFreeMemory(this);
|
destroyAndFreeMemory(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,9 +36,13 @@ namespace QtPrivate {
|
|||||||
// QPropertyBindingPrivatePtr operates on a RefCountingMixin solely so that we can inline
|
// QPropertyBindingPrivatePtr operates on a RefCountingMixin solely so that we can inline
|
||||||
// the constructor and copy constructor
|
// the constructor and copy constructor
|
||||||
struct RefCounted {
|
struct RefCounted {
|
||||||
|
|
||||||
|
int refCount() const { return ref; }
|
||||||
|
void addRef() { ++ref; }
|
||||||
|
bool deref() { return --ref != 0; }
|
||||||
|
|
||||||
|
private:
|
||||||
int ref = 0;
|
int ref = 0;
|
||||||
void addRef() {++ref;}
|
|
||||||
bool deref() {--ref; return ref;}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,7 +65,7 @@ public:
|
|||||||
QPropertyBindingPrivatePtr() noexcept : d(nullptr) { }
|
QPropertyBindingPrivatePtr() noexcept : d(nullptr) { }
|
||||||
~QPropertyBindingPrivatePtr()
|
~QPropertyBindingPrivatePtr()
|
||||||
{
|
{
|
||||||
if (d && (--d->ref == 0))
|
if (d && !d->deref())
|
||||||
destroyAndFreeMemory();
|
destroyAndFreeMemory();
|
||||||
}
|
}
|
||||||
Q_CORE_EXPORT void destroyAndFreeMemory();
|
Q_CORE_EXPORT void destroyAndFreeMemory();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user