summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel
diff options
context:
space:
mode:
authorJędrzej Nowacki <jedrzej.nowacki@nokia.com>2011-12-13 16:12:32 +0100
committerQt by Nokia <qt-info@nokia.com>2011-12-19 10:21:16 +0100
commit31d8ecfe3b6b5ab27e4bb36aeeeae917e0aabc23 (patch)
tree171fc47b8cfe04dfd2c734e24679c99f7f97db7f /src/corelib/kernel
parente75e4421cdcaba1e0c2920251b114d0318155d3c (diff)
Make QMetaTypeInterface POD.
QMetaTypeInterface has to be POD because it is constructed in a static array. Constructors in POD types are not allowed so we will use a macro instead. Change-Id: Iab9ae776dfe4dcd7148558f02d6181c5917aa5c3 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/kernel')
-rw-r--r--src/corelib/kernel/qmetatype.cpp12
-rw-r--r--src/corelib/kernel/qmetatype_p.h45
2 files changed, 31 insertions, 26 deletions
diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp
index 76537c79cb..d5a22ef07d 100644
--- a/src/corelib/kernel/qmetatype.cpp
+++ b/src/corelib/kernel/qmetatype.cpp
@@ -297,6 +297,14 @@ public:
int alias;
};
+namespace
+{
+union CheckThatItIsPod
+{ // This should break if QMetaTypeInterface is not a POD type
+ QMetaTypeInterface iface;
+};
+}
+
Q_DECLARE_TYPEINFO(QCustomTypeInfo, Q_MOVABLE_TYPE);
Q_GLOBAL_STATIC(QVector<QCustomTypeInfo>, customTypes)
Q_GLOBAL_STATIC(QReadWriteLock, customTypesLock)
@@ -454,6 +462,10 @@ int QMetaType::registerType(const char *typeName, Deleter deleter,
inf.typeName = normalizedTypeName;
inf.creator = creator;
inf.deleter = deleter;
+#ifndef QT_NO_DATASTREAM
+ inf.loadOp = 0;
+ inf.saveOp = 0;
+#endif
inf.alias = -1;
inf.constructor = constructor;
inf.destructor = destructor;
diff --git a/src/corelib/kernel/qmetatype_p.h b/src/corelib/kernel/qmetatype_p.h
index 92311afc8e..448c6ded13 100644
--- a/src/corelib/kernel/qmetatype_p.h
+++ b/src/corelib/kernel/qmetatype_p.h
@@ -113,7 +113,7 @@ QT_FOR_EACH_STATIC_WIDGETS_CLASS(QT_DECLARE_WIDGETS_MODULE_TYPES_ITER)
class QMetaTypeInterface
{
-private:
+public:
template<typename T>
struct Impl {
static void *creator(const T *t)
@@ -140,31 +140,6 @@ private:
return new (where) T;
}
};
-public:
- template<typename T>
- explicit QMetaTypeInterface(T *)
- : creator(reinterpret_cast<QMetaType::Creator>(Impl<T>::creator))
- , deleter(reinterpret_cast<QMetaType::Deleter>(Impl<T>::deleter))
- #ifndef QT_NO_DATASTREAM
- , saveOp(reinterpret_cast<QMetaType::SaveOperator>(Impl<T>::saver))
- , loadOp(reinterpret_cast<QMetaType::LoadOperator>(Impl<T>::loader))
- #endif
- , constructor(reinterpret_cast<QMetaType::Constructor>(Impl<T>::constructor))
- , destructor(reinterpret_cast<QMetaType::Destructor>(Impl<T>::destructor))
- , size(sizeof(T))
- {}
-
- QMetaTypeInterface()
- : creator(0)
- , deleter(0)
- #ifndef QT_NO_DATASTREAM
- , saveOp(0)
- , loadOp(0)
- #endif
- , constructor(0)
- , destructor(0)
- , size(0)
- {}
QMetaType::Creator creator;
QMetaType::Deleter deleter;
@@ -177,6 +152,24 @@ public:
int size;
};
+#ifndef QT_NO_DATASTREAM
+# define QT_METATYPE_INTERFACE_INIT_DATASTREAM_IMPL(Type) \
+ /*saveOp*/(reinterpret_cast<QMetaType::SaveOperator>(QMetaTypeInterface::Impl<Type>::saver)), \
+ /*loadOp*/(reinterpret_cast<QMetaType::LoadOperator>(QMetaTypeInterface::Impl<Type>::loader)),
+#else
+# define QT_METATYPE_INTERFACE_INIT_DATASTREAM_IMPL(Type)
+#endif
+
+#define QT_METATYPE_INTERFACE_INIT(Type) \
+{ \
+ /*creator*/(reinterpret_cast<QMetaType::Creator>(QMetaTypeInterface::Impl<Type>::creator)), \
+ /*deleter*/(reinterpret_cast<QMetaType::Deleter>(QMetaTypeInterface::Impl<Type>::deleter)), \
+ QT_METATYPE_INTERFACE_INIT_DATASTREAM_IMPL(Type) \
+ /*constructor*/(reinterpret_cast<QMetaType::Constructor>(QMetaTypeInterface::Impl<Type>::constructor)), \
+ /*destructor*/(reinterpret_cast<QMetaType::Destructor>(QMetaTypeInterface::Impl<Type>::destructor)), \
+ /*size*/(sizeof(Type)) \
+}
+
QT_END_NAMESPACE
#endif // QMETATYPE_P_H