aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlmetatype.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2020-06-09 12:36:29 +0200
committerUlf Hermann <ulf.hermann@qt.io>2020-06-18 14:59:55 +0200
commit34c80149602c1ca52b541cd1adb67b9a1abfd5da (patch)
treea74fe9bb7a84eaaba1ae7036a36b55fcda166b8c /src/qml/qml/qqmlmetatype.cpp
parentd46c406cc67f12e6a0798ef509abbb973b34d39d (diff)
Lock all type modules of the same URI when importing a plugin
A plugin may provide multiple versions of the same types. If we don't lock them all, a further plugin may later mess with the ones we didn't lock. The code clearly attempts to prevent such a situation. Of course, a plugin may still register types under a wholly different URI, and sidestep this mechanism. However, in contrast to exposing multiple major versions from the same plugin, this is not recommended. Change-Id: Ib8d8bbeec8e738020c6d07aedcc4664157b80dcf Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/qml/qqmlmetatype.cpp')
-rw-r--r--src/qml/qml/qqmlmetatype.cpp22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/qml/qml/qqmlmetatype.cpp b/src/qml/qml/qqmlmetatype.cpp
index 0ff5177371..78f1d984e5 100644
--- a/src/qml/qml/qqmlmetatype.cpp
+++ b/src/qml/qml/qqmlmetatype.cpp
@@ -604,14 +604,28 @@ int QQmlMetaType::registerUnitCacheHook(
return 0;
}
-bool QQmlMetaType::protectModule(const QString &uri, QTypeRevision version)
+bool QQmlMetaType::protectModule(const QString &uri, QTypeRevision version, bool protectAllVersions)
{
QQmlMetaTypeDataPtr data;
+ if (version.hasMajorVersion()) {
if (QQmlTypeModule *module = data->findTypeModule(uri, version)) {
- module->lock();
- return true;
+ if (!protectAllVersions) {
+ module->lock();
+ return true;
+ }
+ } else {
+ return false;
}
- return false;
+ }
+
+ const auto range = std::equal_range(
+ data->uriToModule.begin(), data->uriToModule.end(), uri,
+ std::less<ModuleUri>());
+
+ for (auto it = range.first; it != range.second; ++it)
+ (*it)->lock();
+
+ return range.first != range.second;
}
void QQmlMetaType::registerModuleImport(const QString &uri, QTypeRevision version, const QString &import)