diff options
author | Erik Verbruggen <erik.verbruggen@digia.com> | 2016-09-09 15:37:57 +0200 |
---|---|---|
committer | Erik Verbruggen <erik.verbruggen@qt.io> | 2016-10-06 11:44:08 +0000 |
commit | 3b14e2ffdd8eb4b7f7f4508768b75f2acc399370 (patch) | |
tree | 7943f293bf2d0d376d5dc620448bab1a2b58027d /src/qml/memory/qv4heap_p.h | |
parent | 1b90dc4482d001512f09a5785d4cbd8030879d82 (diff) |
QML: Make Heap::Object and all subclasses trivial
GCC6 might dead-store-eliminate out our secret write to Base::mmdata,
because it expects all memory content to be "undefined" before
constructor calls. Clang might take the same approach if the constructor
of Heap::Object is removed.
By making these structs trivial, it also makes them memcpy-able.
Change-Id: I055b2ad28311b997fbe059849ebda4d5894eaa9b
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/memory/qv4heap_p.h')
-rw-r--r-- | src/qml/memory/qv4heap_p.h | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/qml/memory/qv4heap_p.h b/src/qml/memory/qv4heap_p.h index d15d14e463..abbe85c04e 100644 --- a/src/qml/memory/qv4heap_p.h +++ b/src/qml/memory/qv4heap_p.h @@ -58,6 +58,12 @@ // parent's init all up the inheritance chain), define QML_CHECK_INIT_DESTROY_CALLS below. #undef QML_CHECK_INIT_DESTROY_CALLS +#if defined(_MSC_VER) && (_MSC_VER < 1900) // broken compilers: +# define V4_ASSERT_IS_TRIVIAL(x) +#else // working compilers: +# define V4_ASSERT_IS_TRIVIAL(x) Q_STATIC_ASSERT(std::is_trivial< x >::value); +#endif + QT_BEGIN_NAMESPACE namespace QV4 { @@ -82,6 +88,8 @@ struct VTable namespace Heap { struct Q_QML_EXPORT Base { + void *operator new(size_t) = delete; + quintptr mm_data; // vtable and markbit inline ReturnedValue asReturnedValue() const; @@ -128,13 +136,19 @@ struct Q_QML_EXPORT Base { void init() { setInitialized(); } #ifdef QML_CHECK_INIT_DESTROY_CALLS bool _isInitialized; - void _checkIsInitialized() { Q_ASSERT(_isInitialized); } + void _checkIsInitialized() { + if (!_isInitialized) + fprintf(stderr, "ERROR: use of object '%s' before call to init() !!\n", + vtable()->className); + Q_ASSERT(_isInitialized); + } void setInitialized() { Q_ASSERT(!_isInitialized); _isInitialized = true; } #else Q_ALWAYS_INLINE void _checkIsInitialized() {} Q_ALWAYS_INLINE void setInitialized() {} #endif }; +V4_ASSERT_IS_TRIVIAL(Base) template <typename T> struct Pointer { @@ -148,7 +162,7 @@ struct Pointer { T *ptr; }; -Q_STATIC_ASSERT(std::is_trivial<Pointer<void>>::value); +V4_ASSERT_IS_TRIVIAL(Pointer<void>) } @@ -204,7 +218,7 @@ private: QtSharedPointer::ExternalRefCountData *d; QObject *qObject; }; -Q_STATIC_ASSERT(std::is_trivial<QQmlQPointer<QObject>>::value); +V4_ASSERT_IS_TRIVIAL(QQmlQPointer<QObject>) #endif } |