diff options
author | Liang Qi <liang.qi@theqtcompany.com> | 2015-12-18 19:17:30 +0100 |
---|---|---|
committer | Liang Qi <liang.qi@theqtcompany.com> | 2015-12-18 19:17:30 +0100 |
commit | 9f38956fc9a58a2fdfd83c91d65502964047eda3 (patch) | |
tree | 3156fa78c621e3588b230d8334944d4c9e857d45 /src/qml | |
parent | 57cd6337a87f4a8a77ea7136c60a32d2825426df (diff) | |
parent | 839d2d3e2368bc8e107d22203b0611c852f54319 (diff) |
Merge remote-tracking branch 'origin/5.6' into dev
Conflicts:
tests/auto/quick/qquicklistview/tst_qquicklistview.cpp
Change-Id: I9588a3e2c7d590e031dd4c66905a79f0d74d3ac8
Diffstat (limited to 'src/qml')
-rw-r--r-- | src/qml/jsruntime/qv4persistent.cpp | 7 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4qobjectwrapper.cpp | 5 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4qobjectwrapper_p.h | 1 | ||||
-rw-r--r-- | src/qml/memory/qv4mm.cpp | 11 | ||||
-rw-r--r-- | src/qml/memory/qv4mm_p.h | 2 | ||||
-rw-r--r-- | src/qml/qml/qqmlimport.cpp | 19 | ||||
-rw-r--r-- | src/qml/qml/qqmlimport_p.h | 2 | ||||
-rw-r--r-- | src/qml/qml/qqmltypeloader.cpp | 4 | ||||
-rw-r--r-- | src/qml/types/qqmllistmodel.cpp | 3 |
9 files changed, 44 insertions, 10 deletions
diff --git a/src/qml/jsruntime/qv4persistent.cpp b/src/qml/jsruntime/qv4persistent.cpp index 4a0f84b685..032ad0d00a 100644 --- a/src/qml/jsruntime/qv4persistent.cpp +++ b/src/qml/jsruntime/qv4persistent.cpp @@ -34,6 +34,7 @@ #include "qv4persistent_p.h" #include <private/qv4mm_p.h> #include "qv4object_p.h" +#include "qv4qobjectwrapper_p.h" #include "PageAllocation.h" using namespace QV4; @@ -204,6 +205,12 @@ void PersistentValueStorage::free(Value *v) Page *p = getPage(v); + // Keep track of QObjectWrapper to release its resources later in MemoryManager::sweep() + if (p->header.engine) { + if (QObjectWrapper *qobjectWrapper = v->as<QObjectWrapper>()) + p->header.engine->memoryManager->m_pendingDestroyedObjectWrappers.push_back(qobjectWrapper->d()); + } + v->setTag(QV4::Value::Empty_Type); v->setInt_32(p->header.freeList); p->header.freeList = v - p->values; diff --git a/src/qml/jsruntime/qv4qobjectwrapper.cpp b/src/qml/jsruntime/qv4qobjectwrapper.cpp index ee294b3678..594df67f44 100644 --- a/src/qml/jsruntime/qv4qobjectwrapper.cpp +++ b/src/qml/jsruntime/qv4qobjectwrapper.cpp @@ -1019,6 +1019,11 @@ void QObjectWrapper::markObjects(Heap::Base *that, QV4::ExecutionEngine *e) void QObjectWrapper::destroyObject(bool lastCall) { Heap::QObjectWrapper *h = d(); + destroyObject(h, lastCall); +} + +void QObjectWrapper::destroyObject(Heap::QObjectWrapper *h, bool lastCall) +{ if (!h->internalClass) return; // destroyObject already got called diff --git a/src/qml/jsruntime/qv4qobjectwrapper_p.h b/src/qml/jsruntime/qv4qobjectwrapper_p.h index 1126013806..29e1263f2d 100644 --- a/src/qml/jsruntime/qv4qobjectwrapper_p.h +++ b/src/qml/jsruntime/qv4qobjectwrapper_p.h @@ -120,6 +120,7 @@ struct Q_QML_EXPORT QObjectWrapper : public Object void setProperty(ExecutionEngine *engine, int propertyIndex, const Value &value); void destroyObject(bool lastCall); + static void destroyObject(Heap::QObjectWrapper *h, bool lastCall); protected: static bool isEqualTo(Managed *that, Managed *o); diff --git a/src/qml/memory/qv4mm.cpp b/src/qml/memory/qv4mm.cpp index 5181bf912b..053dfb856c 100644 --- a/src/qml/memory/qv4mm.cpp +++ b/src/qml/memory/qv4mm.cpp @@ -41,8 +41,6 @@ #include "StdLibExtras.h" #include <QTime> -#include <QVector> -#include <QVector> #include <QMap> #include <iostream> @@ -437,6 +435,15 @@ void MemoryManager::sweep(bool lastSweep) (*it) = Primitive::undefinedValue(); } + // Some QV4::QObjectWrapper objects will be removed from PersistentValueStorage in WeakValue::~WeakValue() + // before MemoryManager::sweep() is being called, in this case we will never have a chance to call detroyObject() + // on those QV4::QObjectWrapper objects. Here we call detroyObject() for each pending destroyed Heap::QObjectWrapper + // object on the heap to make sure that we can release all the resources held by them + for (QVector<Heap::QObjectWrapper *>::const_iterator it = m_pendingDestroyedObjectWrappers.constBegin(); + it != m_pendingDestroyedObjectWrappers.constEnd(); ++it) + QObjectWrapper::destroyObject(*it, lastSweep); + m_pendingDestroyedObjectWrappers.clear(); + if (MultiplyWrappedQObjectMap *multiplyWrappedQObjects = engine->m_multiplyWrappedQObjects) { for (MultiplyWrappedQObjectMap::Iterator it = multiplyWrappedQObjects->begin(); it != multiplyWrappedQObjects->end();) { if (!it.value().isNullOrUndefined()) diff --git a/src/qml/memory/qv4mm_p.h b/src/qml/memory/qv4mm_p.h index 3543da0907..69aae1c5bf 100644 --- a/src/qml/memory/qv4mm_p.h +++ b/src/qml/memory/qv4mm_p.h @@ -49,6 +49,7 @@ #include <private/qv4value_p.h> #include <private/qv4scopedvalue_p.h> #include <private/qv4object_p.h> +#include <QVector> //#define DETAILED_MM_STATS @@ -327,6 +328,7 @@ public: QScopedPointer<Data> m_d; PersistentValueStorage *m_persistentValues; PersistentValueStorage *m_weakValues; + QVector<Heap::QObjectWrapper *> m_pendingDestroyedObjectWrappers; }; } diff --git a/src/qml/qml/qqmlimport.cpp b/src/qml/qml/qqmlimport.cpp index de1e8722fe..fcd05bfb1b 100644 --- a/src/qml/qml/qqmlimport.cpp +++ b/src/qml/qml/qqmlimport.cpp @@ -125,7 +125,9 @@ bool isPathAbsolute(const QString &path) } // If the type does not already exist as a file import, add the type and return the new type -QQmlType *getTypeForUrl(const QString &urlString, const QHashedStringRef& typeName, bool isCompositeSingleton, QList<QQmlError> *errors) +QQmlType *getTypeForUrl(const QString &urlString, const QHashedStringRef& typeName, + bool isCompositeSingleton, QList<QQmlError> *errors, + int majorVersion=-1, int minorVersion=-1) { QUrl url(urlString); QQmlType *ret = QQmlMetaType::qmlType(url); @@ -140,8 +142,8 @@ QQmlType *getTypeForUrl(const QString &urlString, const QHashedStringRef& typeNa QQmlPrivate::RegisterCompositeSingletonType reg = { url, "", //Empty URI indicates loaded via file imports - -1, - -1, + majorVersion, + minorVersion, buf.constData() }; ret = QQmlMetaType::qmlTypeFromIndex(QQmlPrivate::qmlregister(QQmlPrivate::CompositeSingletonRegistration, ®)); @@ -149,8 +151,8 @@ QQmlType *getTypeForUrl(const QString &urlString, const QHashedStringRef& typeNa QQmlPrivate::RegisterCompositeType reg = { url, "", //Empty URI indicates loaded via file imports - -1, - -1, + majorVersion, + minorVersion, buf.constData() }; ret = QQmlMetaType::qmlTypeFromIndex(QQmlPrivate::qmlregister(QQmlPrivate::CompositeRegistration, ®)); @@ -416,6 +418,8 @@ void findCompositeSingletons(const QQmlImportNamespace &set, QList<QQmlImports:: QQmlImports::CompositeSingletonReference ref; ref.typeName = cit->typeName; ref.prefix = set.prefix; + ref.majorVersion = cit->majorVersion; + ref.minorVersion = cit->minorVersion; resultList.append(ref); } } @@ -656,7 +660,10 @@ bool QQmlImportNamespace::Import::resolveType(QQmlTypeLoader *typeLoader, } if (candidate != end) { - QQmlType *returnType = getTypeForUrl(componentUrl, type, isCompositeSingleton, 0); + int major = vmajor ? *vmajor : -1; + int minor = vminor ? *vminor : -1; + QQmlType *returnType = getTypeForUrl(componentUrl, type, isCompositeSingleton, 0, + major, minor); if (type_return) *type_return = returnType; return returnType != 0; diff --git a/src/qml/qml/qqmlimport_p.h b/src/qml/qml/qqmlimport_p.h index bda87f29b1..951b9752f3 100644 --- a/src/qml/qml/qqmlimport_p.h +++ b/src/qml/qml/qqmlimport_p.h @@ -118,6 +118,8 @@ public: { QString typeName; QString prefix; + int majorVersion; + int minorVersion; }; QList<CompositeSingletonReference> resolvedCompositeSingletons() const; diff --git a/src/qml/qml/qqmltypeloader.cpp b/src/qml/qml/qqmltypeloader.cpp index e96e03115a..98c4341e06 100644 --- a/src/qml/qml/qqmltypeloader.cpp +++ b/src/qml/qml/qqmltypeloader.cpp @@ -2320,8 +2320,8 @@ void QQmlTypeData::resolveTypes() m_namespaces.insert(csRef.prefix); } - int majorVersion = -1; - int minorVersion = -1; + int majorVersion = csRef.majorVersion > -1 ? csRef.majorVersion : -1; + int minorVersion = csRef.minorVersion > -1 ? csRef.minorVersion : -1; if (!resolveType(typeName, majorVersion, minorVersion, ref)) return; diff --git a/src/qml/types/qqmllistmodel.cpp b/src/qml/types/qqmllistmodel.cpp index a4c0f7043f..4b0aa47c63 100644 --- a/src/qml/types/qqmllistmodel.cpp +++ b/src/qml/types/qqmllistmodel.cpp @@ -2277,6 +2277,9 @@ QQmlV4Handle QQmlListModel::get(int index) const } else { QObject *object = m_listModel->getOrCreateModelObject(const_cast<QQmlListModel *>(this), index); result = scope.engine->memoryManager->allocObject<QV4::ModelObject>(object, const_cast<QQmlListModel *>(this), index); + // Keep track of the QObjectWrapper in persistent value storage + QV4::Value *val = scope.engine->memoryManager->m_weakValues->allocate(); + *val = result; } } |