From dafa3618d232a611108dcd511e9e7af1aabd361e Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 17 Jul 2015 20:30:14 -0700 Subject: Add QTypeInfo::isRelocatable It's the same as movable (i.e., the opposite of QTypeInfo::isStatic), except that it won't trigger the QList change in memory layout. For Qt 6, we should merge the two. Change-Id: Ib306f8f647014b399b87ffff13f1ece29e4b6e5c Reviewed-by: Olivier Goffart (Woboq GmbH) --- src/corelib/global/qtypeinfo.h | 61 +++++++++++++++++++++++++++++++++--------- 1 file changed, 49 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/corelib/global/qtypeinfo.h b/src/corelib/global/qtypeinfo.h index 7fee613f89..b42e5998fc 100644 --- a/src/corelib/global/qtypeinfo.h +++ b/src/corelib/global/qtypeinfo.h @@ -32,6 +32,7 @@ ****************************************************************************/ #include +#include #ifndef QTYPEINFO_H #define QTYPEINFO_H @@ -55,6 +56,7 @@ public: isIntegral = QtPrivate::is_integral::value, isComplex = true, isStatic = true, + isRelocatable = Q_IS_ENUM(T), isLarge = (sizeof(T)>sizeof(void*)), isDummy = false, //### Qt6: remove sizeOf = sizeof(T) @@ -70,6 +72,7 @@ public: isIntegral = false, isComplex = false, isStatic = false, + isRelocatable = false, isLarge = false, isDummy = false, sizeOf = 0 @@ -85,12 +88,39 @@ public: isIntegral = false, isComplex = false, isStatic = false, + isRelocatable = true, isLarge = false, isDummy = false, sizeOf = sizeof(T*) }; }; +/*! + \class QTypeInfoQuery + \inmodule QtCore + \internal + \brief QTypeInfoQuery is used to query the values of a given QTypeInfo + + We use it because there may be some QTypeInfo specializations in user + code that don't provide certain flags that we added after Qt 5.0. They are: + \list + \li isRelocatable: defaults to !isStatic + \endlist + + DO NOT specialize this class elsewhere. +*/ +// apply defaults for a generic QTypeInfo that didn't provide the new values +template +struct QTypeInfoQuery : QTypeInfo +{ + enum { isRelocatable = !QTypeInfo::isStatic }; +}; + +// if QTypeInfo::isRelocatable exists, use it +template +struct QTypeInfoQuery::isRelocatable || true>::Type> : QTypeInfo +{}; + /*! \class QTypeInfoMerger \inmodule QtCore @@ -116,8 +146,12 @@ class QTypeInfoMerger { public: enum { - isComplex = QTypeInfo::isComplex || QTypeInfo::isComplex || QTypeInfo::isComplex || QTypeInfo::isComplex, - isStatic = QTypeInfo::isStatic || QTypeInfo::isStatic || QTypeInfo::isStatic || QTypeInfo::isStatic, + isComplex = QTypeInfoQuery::isComplex || QTypeInfoQuery::isComplex + || QTypeInfoQuery::isComplex || QTypeInfoQuery::isComplex, + isStatic = QTypeInfoQuery::isStatic || QTypeInfoQuery::isStatic + || QTypeInfoQuery::isStatic || QTypeInfoQuery::isStatic, + isRelocatable = QTypeInfoQuery::isRelocatable && QTypeInfoQuery::isRelocatable + && QTypeInfoQuery::isRelocatable && QTypeInfoQuery::isRelocatable, isLarge = sizeof(T) > sizeof(void*), isPointer = false, isIntegral = false, @@ -136,19 +170,20 @@ public: \ isPointer = false, \ isIntegral = false, \ isComplex = true, \ + isRelocatable = true, \ isStatic = false, \ isLarge = (sizeof(CONTAINER) > sizeof(void*)), \ isDummy = false, \ sizeOf = sizeof(CONTAINER) \ }; \ -}; +} -Q_DECLARE_MOVABLE_CONTAINER(QList) -Q_DECLARE_MOVABLE_CONTAINER(QVector) -Q_DECLARE_MOVABLE_CONTAINER(QQueue) -Q_DECLARE_MOVABLE_CONTAINER(QStack) -Q_DECLARE_MOVABLE_CONTAINER(QLinkedList) -Q_DECLARE_MOVABLE_CONTAINER(QSet) +Q_DECLARE_MOVABLE_CONTAINER(QList); +Q_DECLARE_MOVABLE_CONTAINER(QVector); +Q_DECLARE_MOVABLE_CONTAINER(QQueue); +Q_DECLARE_MOVABLE_CONTAINER(QStack); +Q_DECLARE_MOVABLE_CONTAINER(QLinkedList); +Q_DECLARE_MOVABLE_CONTAINER(QSet); #undef Q_DECLARE_MOVABLE_CONTAINER @@ -164,8 +199,9 @@ enum { /* TYPEINFO flags */ Q_COMPLEX_TYPE = 0, Q_PRIMITIVE_TYPE = 0x1, Q_STATIC_TYPE = 0, - Q_MOVABLE_TYPE = 0x2, - Q_DUMMY_TYPE = 0x4 + Q_MOVABLE_TYPE = 0x2, // ### Qt6: merge movable and relocatable once QList no longer depends on it + Q_DUMMY_TYPE = 0x4, + Q_RELOCATABLE_TYPE = 0x8 }; #define Q_DECLARE_TYPEINFO_BODY(TYPE, FLAGS) \ @@ -175,6 +211,7 @@ public: \ enum { \ isComplex = (((FLAGS) & Q_PRIMITIVE_TYPE) == 0), \ isStatic = (((FLAGS) & (Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE)) == 0), \ + isRelocatable = !isStatic || ((FLAGS) & Q_RELOCATABLE_TYPE), \ isLarge = (sizeof(TYPE)>sizeof(void*)), \ isPointer = false, \ isIntegral = QtPrivate::is_integral< TYPE >::value, \ @@ -216,7 +253,7 @@ inline void swap(TYPE &value1, TYPE &value2) \ { value1.swap(value2); } #define Q_DECLARE_SHARED(TYPE) Q_DECLARE_SHARED_IMPL(TYPE, Q_MOVABLE_TYPE) #define Q_DECLARE_SHARED_NOT_MOVABLE_UNTIL_QT6(TYPE) \ - Q_DECLARE_SHARED_IMPL(TYPE, QT_VERSION >= QT_VERSION_CHECK(6,0,0) ? Q_MOVABLE_TYPE : Q_COMPLEX_TYPE) + Q_DECLARE_SHARED_IMPL(TYPE, QT_VERSION >= QT_VERSION_CHECK(6,0,0) ? Q_MOVABLE_TYPE : Q_RELOCATABLE_TYPE) /* QTypeInfo primitive specializations -- cgit v1.2.3