aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2022-06-13 15:28:39 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-06-18 04:18:17 +0000
commit45ba50f7bd33eaca23927cd720c7b89eeb006675 (patch)
tree8b473093a2aa753eafcf6ddd56206e87d6ad09b7
parentd23ee198656db1998e213d6befaa93e3d79c2d91 (diff)
QML: Drop backup source code once we're done with it
If a component is done loading, we don't need the source code anymore. Dropping it makes it possible to unmap any resources it may be part of. Fixes: QTBUG-86088 Change-Id: Id523fffb788b5ffa60cb1e7b777328c6648c2a88 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: hjk <hjk@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit f3d9e9214be92bc79c1d5e58f07f730a6ff31528) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/qml/qml/qqmldatablob_p.h5
-rw-r--r--src/qml/qml/qqmltypedata.cpp2
-rw-r--r--src/qml/qml/qqmltypedata_p.h1
-rw-r--r--tests/auto/qml/qqmlengine/tst_qqmlengine.cpp2
-rw-r--r--tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp1
-rw-r--r--tests/auto/qml/qqmltranslation/tst_qqmltranslation.cpp2
-rw-r--r--tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp5
7 files changed, 17 insertions, 1 deletions
diff --git a/src/qml/qml/qqmldatablob_p.h b/src/qml/qml/qqmldatablob_p.h
index d05b29a999..e975043871 100644
--- a/src/qml/qml/qqmldatablob_p.h
+++ b/src/qml/qml/qqmldatablob_p.h
@@ -85,6 +85,11 @@ public:
QDateTime sourceTimeStamp() const;
bool exists() const;
bool isEmpty() const;
+ bool isValid() const
+ {
+ return hasInlineSourceCode || !fileInfo.filePath().isEmpty();
+ }
+
private:
friend class QQmlDataBlob;
friend class QQmlTypeLoader;
diff --git a/src/qml/qml/qqmltypedata.cpp b/src/qml/qml/qqmltypedata.cpp
index c8db50f664..972723326a 100644
--- a/src/qml/qml/qqmltypedata.cpp
+++ b/src/qml/qml/qqmltypedata.cpp
@@ -277,6 +277,7 @@ void QQmlTypeData::setCompileUnit(const Container &container)
void QQmlTypeData::done()
{
auto cleanup = qScopeGuard([this]{
+ m_backupSourceCode = SourceCodeData();
m_document.reset();
m_typeReferences.clear();
if (isError()) {
@@ -401,7 +402,6 @@ void QQmlTypeData::done()
qCDebug(DBG_DISK_CACHE) << "Checksum mismatch for cached version of" << m_compiledData->fileName();
if (!loadFromSource())
return;
- m_backupSourceCode = SourceCodeData();
m_compiledData.reset();
}
diff --git a/src/qml/qml/qqmltypedata_p.h b/src/qml/qml/qqmltypedata_p.h
index 85f4f8206f..d5398b0b5f 100644
--- a/src/qml/qml/qqmltypedata_p.h
+++ b/src/qml/qml/qqmltypedata_p.h
@@ -71,6 +71,7 @@ public:
CompositeMetaTypeIds typeIds(int objectId = 0) const;
QByteArray typeClassName() const { return m_typeClassName; }
+ SourceCodeData backupSourceCode() const { return m_backupSourceCode; }
protected:
void done() override;
diff --git a/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp b/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp
index 1f13738b44..bd8db65fac 100644
--- a/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp
+++ b/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp
@@ -1061,6 +1061,7 @@ void tst_qqmlengine::qrcUrls()
{
QQmlRefPointer<QQmlTypeData> oneQml(pEngine->typeLoader.getType(QUrl("qrc:/qrcurls.qml")));
QVERIFY(oneQml.data() != nullptr);
+ QVERIFY(!oneQml->backupSourceCode().isValid());
QQmlRefPointer<QQmlTypeData> twoQml(pEngine->typeLoader.getType(QUrl("qrc:///qrcurls.qml")));
QVERIFY(twoQml.data() != nullptr);
QCOMPARE(oneQml.data(), twoQml.data());
@@ -1069,6 +1070,7 @@ void tst_qqmlengine::qrcUrls()
{
QQmlRefPointer<QQmlTypeData> oneJS(pEngine->typeLoader.getType(QUrl("qrc:/qrcurls.js")));
QVERIFY(oneJS.data() != nullptr);
+ QVERIFY(!oneJS->backupSourceCode().isValid());
QQmlRefPointer<QQmlTypeData> twoJS(pEngine->typeLoader.getType(QUrl("qrc:///qrcurls.js")));
QVERIFY(twoJS.data() != nullptr);
QCOMPARE(oneJS.data(), twoJS.data());
diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
index 548004b24e..b9b7d3e6a9 100644
--- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
+++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
@@ -2524,6 +2524,7 @@ void tst_qqmllanguage::scriptStringWithoutSourceCode()
QQmlEnginePrivate *eng = QQmlEnginePrivate::get(&engine);
QQmlRefPointer<QQmlTypeData> td = eng->typeLoader.getType(url);
Q_ASSERT(td);
+ QVERIFY(!td->backupSourceCode().isValid());
QQmlRefPointer<QV4::ExecutableCompilationUnit> compilationUnit = td->compilationUnit();
readOnlyQmlUnit.reset(compilationUnit->unitData());
diff --git a/tests/auto/qml/qqmltranslation/tst_qqmltranslation.cpp b/tests/auto/qml/qqmltranslation/tst_qqmltranslation.cpp
index fa9f5a6b48..20d81b352d 100644
--- a/tests/auto/qml/qqmltranslation/tst_qqmltranslation.cpp
+++ b/tests/auto/qml/qqmltranslation/tst_qqmltranslation.cpp
@@ -55,6 +55,7 @@ void tst_qqmltranslation::translation()
QQmlContext *context = qmlContext(object);
QQmlEnginePrivate *engine = QQmlEnginePrivate::get(context->engine());
QQmlRefPointer<QQmlTypeData> typeData = engine->typeLoader.getType(context->baseUrl());
+ QVERIFY(!typeData->backupSourceCode().isValid());
QV4::CompiledData::CompilationUnit *compilationUnit = typeData->compilationUnit();
QVERIFY(compilationUnit);
@@ -115,6 +116,7 @@ void tst_qqmltranslation::idTranslation()
QQmlContext *context = qmlContext(object);
QQmlEnginePrivate *engine = QQmlEnginePrivate::get(context->engine());
QQmlRefPointer<QQmlTypeData> typeData = engine->typeLoader.getType(context->baseUrl());
+ QVERIFY(!typeData->backupSourceCode().isValid());
QV4::CompiledData::CompilationUnit *compilationUnit = typeData->compilationUnit();
QVERIFY(compilationUnit);
diff --git a/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp b/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp
index f08efb9dc6..d28035b266 100644
--- a/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp
+++ b/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp
@@ -98,6 +98,10 @@ void tst_QQMLTypeLoader::trimCache()
url.setQuery(QString::number(i));
QQmlTypeData *data = loader.getType(url).take();
+
+ // Backup source code should be dropped right after loading, even without cache trimming.
+ QVERIFY(!data->backupSourceCode().isValid());
+
// Run an event loop to receive the callback that release()es.
QTRY_COMPARE(data->count(), 2);
@@ -660,6 +664,7 @@ static void getCompilationUnitAndRuntimeInfo(QQmlRefPointer<QV4::ExecutableCompi
QQmlTypeLoader &loader = QQmlEnginePrivate::get(engine)->typeLoader;
auto typeData = loader.getType(url);
QVERIFY(typeData);
+ QVERIFY(!typeData->backupSourceCode().isValid());
if (typeData->isError()) {
const auto errors = typeData->errors();