aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlmetatype.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2021-08-10 12:21:58 +0200
committerUlf Hermann <ulf.hermann@qt.io>2021-08-18 11:32:55 +0200
commit3eece79ddbe110c9021ed9b9715c6fd4f70f3ca6 (patch)
treeddc5ed8be89d3f074e72f14b07655d49c09c1b49 /src/qml/qml/qqmlmetatype.cpp
parentc39e4b02621a15edc978dbfa45b6a00681f41121 (diff)
Avoid querying the file system for qmldir files for locked modules
If the user explicitly locks a module using qmlProtectModule, we don't load any additional qmldir files afterwards. In particular, this means you can only do that with modules that don't contain qmldir files or with modules for which the qmldir files have already been loaded in all engines that need them. This is in contrast to the "weak" locking we automatically perform when loading a plugin. When importing the module again after loading a plugin we do want to re-evaluate the qmldir directives. If the module is imported from a different engine than before, we also have to search for the qmldir file again. Amends commit 914e0300792856ddac9b99b20a8d88dd6f087fa6. [ChangeLog][QtQml] The pre-5.15 behavior of qmlProtectModule() has mostly been restored: If you explicitly protect a module, the QML engine will never look for any qmldir files or plugins for that module again. This severely limits what you can do with such a module. However, once all affected engines have loaded the module, protecting it can be a useful optimization. In contrast to pre-5.15, the qmldir cache for such modules continues to be re-used even after they are locked. Therefore, in QML engines that have loaded the module before, you can expect any "prefer" or "import" directives and any composite types to still be available after protecting the module. Fixes: QTBUG-85591 Change-Id: Ia4edd860e2ddda5e0c419e1ce9764f10f32ace1f Reviewed-by: Thorbjørn Lindeijer <bjorn@lindeijer.nl> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Fawzi Mohamed <fawzi.mohamed@qt.io> (cherry picked from commit d0dc91158d0b44d9e1b73c3b0dacdd6699741ad7) Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/qml/qqmlmetatype.cpp')
-rw-r--r--src/qml/qml/qqmlmetatype.cpp25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/qml/qml/qqmlmetatype.cpp b/src/qml/qml/qqmlmetatype.cpp
index e412263825..8b92a2ff8c 100644
--- a/src/qml/qml/qqmlmetatype.cpp
+++ b/src/qml/qml/qqmlmetatype.cpp
@@ -431,7 +431,7 @@ bool checkRegistration(QQmlType::RegistrationType typeType, QQmlMetaTypeData *da
if (uri && !typeName.isEmpty()) {
QString nameSpace = QString::fromUtf8(uri);
QQmlTypeModule *qqtm = data->findTypeModule(nameSpace, version);
- if (qqtm && qqtm->isLocked()) {
+ if (qqtm && qqtm->lockLevel() != QQmlTypeModule::LockLevel::Open) {
QString failure(QCoreApplication::translate(
"qmlRegisterType",
"Cannot install %1 '%2' into protected module '%3' version '%4'"));
@@ -645,18 +645,19 @@ void QQmlMetaType::unregisterSequentialContainer(int id)
unregisterType(id);
}
-bool QQmlMetaType::protectModule(const QString &uri, QTypeRevision version, bool protectAllVersions)
+bool QQmlMetaType::protectModule(const QString &uri, QTypeRevision version,
+ bool weakProtectAllVersions)
{
QQmlMetaTypeDataPtr data;
if (version.hasMajorVersion()) {
- if (QQmlTypeModule *module = data->findTypeModule(uri, version)) {
- if (!protectAllVersions) {
- module->lock();
- return true;
+ if (QQmlTypeModule *module = data->findTypeModule(uri, version)) {
+ if (!weakProtectAllVersions) {
+ module->setLockLevel(QQmlTypeModule::LockLevel::Strong);
+ return true;
+ }
+ } else {
+ return false;
}
- } else {
- return false;
- }
}
const auto range = std::equal_range(
@@ -664,7 +665,7 @@ bool QQmlMetaType::protectModule(const QString &uri, QTypeRevision version, bool
std::less<ModuleUri>());
for (auto it = range.first; it != range.second; ++it)
- (*it)->lock();
+ (*it)->setLockLevel(QQmlTypeModule::LockLevel::Weak);
return range.first != range.second;
}
@@ -981,12 +982,12 @@ QTypeRevision QQmlMetaType::latestModuleVersion(const QString &uri)
/*
Returns true if a module \a uri of this version is installed and locked;
*/
-bool QQmlMetaType::isLockedModule(const QString &uri, QTypeRevision version)
+bool QQmlMetaType::isStronglyLockedModule(const QString &uri, QTypeRevision version)
{
QQmlMetaTypeDataPtr data;
if (QQmlTypeModule* qqtm = data->findTypeModule(uri, version))
- return qqtm->isLocked();
+ return qqtm->lockLevel() == QQmlTypeModule::LockLevel::Strong;
return false;
}