diff options
author | Erik Verbruggen <erik.verbruggen@digia.com> | 2016-09-08 11:07:26 +0200 |
---|---|---|
committer | Erik Verbruggen <erik.verbruggen@qt.io> | 2016-09-30 14:14:31 +0000 |
commit | b80fa8e7d59c2824de067ab4d488d865a6e69d94 (patch) | |
tree | dfbab030756f9c5a0f76aba8a558f429311724a2 /src/qml/memory | |
parent | c2e28350a6ea866b9e68059f232aaeccd47f743b (diff) |
QML: Make all context objects trivial
This change also adds a check to the d() calls for Managed, verifies
that the object has been initialized. This is only done for debug
builds.
To prevent other code from tripping the check, a number of other classes
are either marked as trivial, or do initialization in the constructors.
Because of template function changes in them memory manager (those now
call init() instead of in-place new), String has an extra parameter
to force it to temporarily use an old/unmodified template function.
Change-Id: I8c35161ce7680835d830638b6d21498c5129b02b
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/memory')
-rw-r--r-- | src/qml/memory/qv4heap_p.h | 14 | ||||
-rw-r--r-- | src/qml/memory/qv4mm_p.h | 4 |
2 files changed, 16 insertions, 2 deletions
diff --git a/src/qml/memory/qv4heap_p.h b/src/qml/memory/qv4heap_p.h index f38898b2ea..d15d14e463 100644 --- a/src/qml/memory/qv4heap_p.h +++ b/src/qml/memory/qv4heap_p.h @@ -54,6 +54,10 @@ #include <private/qv4global_p.h> #include <QSharedPointer> +// To check if Heap::Base::init is called (meaning, all subclasses did their init and called their +// parent's init all up the inheritance chain), define QML_CHECK_INIT_DESTROY_CALLS below. +#undef QML_CHECK_INIT_DESTROY_CALLS + QT_BEGIN_NAMESPACE namespace QV4 { @@ -120,6 +124,16 @@ struct Q_QML_EXPORT Base { void *operator new(size_t, Managed *m) { return m; } void *operator new(size_t, Heap::Base *m) { return m; } void operator delete(void *, Heap::Base *) {} + + void init() { setInitialized(); } +#ifdef QML_CHECK_INIT_DESTROY_CALLS + bool _isInitialized; + void _checkIsInitialized() { Q_ASSERT(_isInitialized); } + void setInitialized() { Q_ASSERT(!_isInitialized); _isInitialized = true; } +#else + Q_ALWAYS_INLINE void _checkIsInitialized() {} + Q_ALWAYS_INLINE void setInitialized() {} +#endif }; template <typename T> diff --git a/src/qml/memory/qv4mm_p.h b/src/qml/memory/qv4mm_p.h index 026cbd8c6b..6db5b54760 100644 --- a/src/qml/memory/qv4mm_p.h +++ b/src/qml/memory/qv4mm_p.h @@ -276,7 +276,7 @@ public: { Scope scope(engine); Scoped<ManagedType> t(scope, allocManaged<ManagedType>(sizeof(typename ManagedType::Data))); - (void)new (t->d()) typename ManagedType::Data(arg1, arg2); + t->d_unchecked()->init(arg1, arg2); return t->d(); } @@ -285,7 +285,7 @@ public: { Scope scope(engine); Scoped<ManagedType> t(scope, allocManaged<ManagedType>(sizeof(typename ManagedType::Data))); - (void)new (t->d()) typename ManagedType::Data(arg1, arg2, arg3); + t->d_unchecked()->init(arg1, arg2, arg3); return t->d(); } |