aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/memory/qv4heap_p.h
diff options
context:
space:
mode:
authorErik Verbruggen <erik.verbruggen@digia.com>2016-09-08 11:07:26 +0200
committerErik Verbruggen <erik.verbruggen@qt.io>2016-09-30 14:14:31 +0000
commitb80fa8e7d59c2824de067ab4d488d865a6e69d94 (patch)
treedfbab030756f9c5a0f76aba8a558f429311724a2 /src/qml/memory/qv4heap_p.h
parentc2e28350a6ea866b9e68059f232aaeccd47f743b (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/qv4heap_p.h')
-rw-r--r--src/qml/memory/qv4heap_p.h14
1 files changed, 14 insertions, 0 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>