aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmlcompiler
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2020-10-15 12:16:08 +0200
committerUlf Hermann <ulf.hermann@qt.io>2020-10-15 13:16:57 +0200
commitfa48382c492097d06d7ce066ac36dba04fd5e801 (patch)
tree6d8bc1d8b0ab829c09554ebe93fb3d6155b29d4b /src/qmlcompiler
parent3abe34472b56d32aa1b14f54aa8a0e2ebe4d5537 (diff)
QDeferredPointer: Remove the factory before executing it
Only this way we avoid infinite recursion on cyclic references. Change-Id: I4d6323a093d17f7d55965dc40f9dc5f1a647df9c Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qmlcompiler')
-rw-r--r--src/qmlcompiler/qdeferredpointer_p.h12
-rw-r--r--src/qmlcompiler/qqmljsscope_p.h7
2 files changed, 9 insertions, 10 deletions
diff --git a/src/qmlcompiler/qdeferredpointer_p.h b/src/qmlcompiler/qdeferredpointer_p.h
index 07875013fa..b8a06cc13c 100644
--- a/src/qmlcompiler/qdeferredpointer_p.h
+++ b/src/qmlcompiler/qdeferredpointer_p.h
@@ -50,7 +50,6 @@ class QDeferredFactory
public:
T create() const;
bool isValid() const;
- void clear();
};
template<typename T>
@@ -79,8 +78,9 @@ public:
operator QSharedPointer<T>() const
{
if (m_factory && m_factory->isValid()) {
- const_cast<std::remove_const_t<T> &>(*m_data) = m_factory->create();
- m_factory->clear();
+ Factory localFactory;
+ std::swap(localFactory, *m_factory); // Swap before executing, to avoid recursion
+ const_cast<std::remove_const_t<T> &>(*m_data) = localFactory.create();
}
return m_data;
}
@@ -135,8 +135,10 @@ public:
if (m_factory) {
auto factory = m_factory.toStrongRef();
if (factory->isValid()) {
- const_cast<std::remove_const_t<T> &>(*(m_data.toStrongRef())) = factory->create();
- factory->clear();
+ Factory localFactory;
+ std::swap(localFactory, *factory); // Swap before executing, to avoid recursion
+ const_cast<std::remove_const_t<T> &>(*(m_data.toStrongRef()))
+ = localFactory.create();
}
}
return m_data;
diff --git a/src/qmlcompiler/qqmljsscope_p.h b/src/qmlcompiler/qqmljsscope_p.h
index df7aad840d..90696166e4 100644
--- a/src/qmlcompiler/qqmljsscope_p.h
+++ b/src/qmlcompiler/qqmljsscope_p.h
@@ -60,6 +60,8 @@ template<>
class QDeferredFactory<QQmlJSScope>
{
public:
+ QDeferredFactory() = default;
+
QDeferredFactory(QQmlJSImporter *importer, const QString &filePath) :
m_filePath(filePath), m_importer(importer)
{}
@@ -71,11 +73,6 @@ public:
return !m_filePath.isEmpty() && m_importer != nullptr;
}
- void clear() {
- m_filePath.clear();
- m_importer = nullptr;
- }
-
private:
QString m_filePath;
QQmlJSImporter *m_importer = nullptr;