diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2022-07-19 12:58:36 -0700 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2022-07-20 14:57:32 -0700 |
commit | eb9ace1cee4bb48005797b0b2d2d3d576a4cb4ce (patch) | |
tree | 5f3dcdfe77584e71360501c83232c6402fb6ada8 /src | |
parent | 48675dfa33c4b99b41af487d75f057bb7399c709 (diff) |
QVariant: add missing const to QMetaTypeInterface pointers
They're ALWAYS const objects, though they also chock full of relocations
so they are never in read-only sections of memory (except maybe in final
executables that are position-dependent).
These are methods in a private sub-class of QVariant. No one outside of
QtCore (at least qtbase) should be using them directly. QVariant doesn't
have many friends (a bit anti-social); the one that matters is
qvariant_cast and that one does access QVariant::Private. This is not a
BC problem because QVariant::Private::type()'s signature is not
changing. In any case, QVariant's Q_CORE_EXPORT does not apply to
QVariant::Private anyway (see [1]).
[1] https://msvc.godbolt.org/z/r9cer8eWh
Pick-to: 6.3 6.4
Change-Id: I3859764fed084846bcb0fffd17035355f823dc8f
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/kernel/qvariant.cpp | 11 | ||||
-rw-r--r-- | src/corelib/kernel/qvariant.h | 10 |
2 files changed, 9 insertions, 12 deletions
diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index 55fe9d3c3f..472c510358 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -215,7 +215,7 @@ static qreal qConvertToRealNumber(const QVariant::Private *d, bool *ok) // the type of d has already been set, but other field are not set static void customConstruct(QVariant::Private *d, const void *copy) { - QtPrivate::QMetaTypeInterface *iface = d->typeInterface(); + const QtPrivate::QMetaTypeInterface *iface = d->typeInterface(); if (!(iface && iface->size)) { *d = QVariant::Private(); return; @@ -494,11 +494,8 @@ QVariant::QVariant(const QVariant &p) { if (d.is_shared) { d.data.shared->ref.ref(); - return; - } - QtPrivate::QMetaTypeInterface *iface = d.typeInterface(); - auto other = p.constData(); - if (iface) { + } else if (const QtPrivate::QMetaTypeInterface *iface = d.typeInterface()) { + auto other = p.constData(); if (other) iface->copyCtr(iface, &d.data, other); else @@ -986,7 +983,7 @@ QVariant &QVariant::operator=(const QVariant &variant) d = variant.d; } else { d = variant.d; - QtPrivate::QMetaTypeInterface *iface = d.typeInterface(); + const QtPrivate::QMetaTypeInterface *iface = d.typeInterface(); const void *other = variant.constData(); if (iface) { if (other) diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h index 2a9b92f0c8..dc73f46af5 100644 --- a/src/corelib/kernel/qvariant.h +++ b/src/corelib/kernel/qvariant.h @@ -428,7 +428,7 @@ public: static constexpr size_t MaxInternalSize = 3*sizeof(void *); template<typename T> static constexpr bool CanUseInternalSpace = (QTypeInfo<T>::isRelocatable && sizeof(T) <= MaxInternalSize && alignof(T) <= alignof(double)); - static constexpr bool canUseInternalSpace(QtPrivate::QMetaTypeInterface *type) + static constexpr bool canUseInternalSpace(const QtPrivate::QMetaTypeInterface *type) { Q_ASSERT(type); return QMetaType::TypeFlags(type->flags) & QMetaType::RelocatableType && @@ -468,14 +468,14 @@ public: void set(const T &t) { *static_cast<T *>(CanUseInternalSpace<T> ? &data.data : data.shared->data()) = t; } - inline QMetaType type() const + inline const QtPrivate::QMetaTypeInterface* typeInterface() const { - return QMetaType(reinterpret_cast<QtPrivate::QMetaTypeInterface *>(packedType << 2)); + return reinterpret_cast<const QtPrivate::QMetaTypeInterface *>(packedType << 2); } - inline QtPrivate::QMetaTypeInterface * typeInterface() const + inline QMetaType type() const { - return reinterpret_cast<QtPrivate::QMetaTypeInterface *>(packedType << 2); + return QMetaType(typeInterface()); } inline int typeId() const |