diff options
-rw-r--r-- | src/declarative/qml/qdeclarativecompileddata.cpp | 12 | ||||
-rw-r--r-- | src/declarative/qml/qdeclarativedeclarativedata_p.h | 3 | ||||
-rw-r--r-- | src/declarative/qml/qdeclarativeengine.cpp | 5 | ||||
-rw-r--r-- | src/declarative/qml/qdeclarativemetatype.cpp | 14 | ||||
-rw-r--r-- | src/declarative/qml/qdeclarativemetatype_p.h | 1 |
5 files changed, 30 insertions, 5 deletions
diff --git a/src/declarative/qml/qdeclarativecompileddata.cpp b/src/declarative/qml/qdeclarativecompileddata.cpp index bdf16a3..30f9510 100644 --- a/src/declarative/qml/qdeclarativecompileddata.cpp +++ b/src/declarative/qml/qdeclarativecompileddata.cpp @@ -203,9 +203,15 @@ void QDeclarativeCompiledData::clear() QObject *QDeclarativeCompiledData::TypeReference::createInstance(QDeclarativeContext *ctxt, const QBitField &bindings) const { if (type) { - QObject *rv = type->create(); - if (rv) - QDeclarativeEngine::setContextForObject(rv, ctxt); + QObject *rv = 0; + void *memory = 0; + + type->create(&rv, &memory, sizeof(QDeclarativeDeclarativeData)); + QDeclarativeDeclarativeData *ddata = new (memory) QDeclarativeDeclarativeData; + ddata->ownMemory = false; + QObjectPrivate::get(rv)->declarativeData = ddata; + QDeclarativeEngine::setContextForObject(rv, ctxt); + return rv; } else { Q_ASSERT(component); diff --git a/src/declarative/qml/qdeclarativedeclarativedata_p.h b/src/declarative/qml/qdeclarativedeclarativedata_p.h index ffce9c9..f962986 100644 --- a/src/declarative/qml/qdeclarativedeclarativedata_p.h +++ b/src/declarative/qml/qdeclarativedeclarativedata_p.h @@ -67,7 +67,7 @@ class Q_AUTOTEST_EXPORT QDeclarativeDeclarativeData : public QDeclarativeData { public: QDeclarativeDeclarativeData(QDeclarativeContext *ctxt = 0) - : indestructible(true), explicitIndestructibleSet(false), context(ctxt), + : ownMemory(true), indestructible(true), explicitIndestructibleSet(false), context(ctxt), bindings(0), nextContextObject(0), prevContextObject(0), bindingBitsSize(0), bindingBits(0), outerContext(0), lineNumber(0), columnNumber(0), deferredComponent(0), deferredIdx(0), attachedProperties(0), propertyCache(0), guards(0) {} @@ -79,6 +79,7 @@ public: if (!explicitIndestructibleSet) indestructible = false; } + quint32 ownMemory:1; quint32 indestructible:1; quint32 explicitIndestructibleSet:1; quint32 dummy:29; diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index 0d8c7e9..2a26626 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -828,7 +828,10 @@ void QDeclarativeDeclarativeData::destroyed(QObject *object) g->objectDestroyed(object); } - delete this; + if (ownMemory) + delete this; + else + this->~QDeclarativeDeclarativeData(); } void QDeclarativeDeclarativeData::parentChanged(QObject *, QObject *parent) diff --git a/src/declarative/qml/qdeclarativemetatype.cpp b/src/declarative/qml/qdeclarativemetatype.cpp index 55c7413..b32e575 100644 --- a/src/declarative/qml/qdeclarativemetatype.cpp +++ b/src/declarative/qml/qdeclarativemetatype.cpp @@ -287,6 +287,20 @@ QObject *QDeclarativeType::create() const return rv; } +void QDeclarativeType::create(QObject **out, void **memory, size_t additionalMemory) const +{ + d->init(); + + QObject *rv = (QObject *)operator new(d->m_allocationSize + additionalMemory); + d->m_newFunc(rv); + + if (rv && !d->m_metaObjects.isEmpty()) + (void *)new QDeclarativeProxyMetaObject(rv, &d->m_metaObjects); + + *out = rv; + *memory = ((char *)rv) + d->m_allocationSize; +} + QDeclarativeCustomParser *QDeclarativeType::customParser() const { return d->m_customParser; diff --git a/src/declarative/qml/qdeclarativemetatype_p.h b/src/declarative/qml/qdeclarativemetatype_p.h index cf8946d..1a36f10 100644 --- a/src/declarative/qml/qdeclarativemetatype_p.h +++ b/src/declarative/qml/qdeclarativemetatype_p.h @@ -111,6 +111,7 @@ public: bool availableInVersion(int vmajor, int vminor) const; QObject *create() const; + void create(QObject **, void **, size_t) const; QDeclarativeCustomParser *customParser() const; |