diff options
author | Christian Kandeler <christian.kandeler@qt.io> | 2022-02-24 13:00:58 +0100 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@qt.io> | 2022-02-24 14:28:23 +0000 |
commit | 86f1864d3c3c6aed73611e188fd6f36d9df427fd (patch) | |
tree | c9c24db49c1fbe810b2edaed61d893e417d6bd7e | |
parent | 1172eeb06090b1268712039a1c1cae802fce3494 (diff) |
CppEditor: Catch another project pointer access from a thread
Amends 33108795d6.
Fixes: QTCREATORBUG-27044
Change-Id: I53d716355b0784841fd8d965c8af14fe321c33de
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
-rw-r--r-- | src/plugins/cppeditor/baseeditordocumentparser.cpp | 2 | ||||
-rw-r--r-- | src/plugins/cppeditor/baseeditordocumentparser.h | 8 | ||||
-rw-r--r-- | src/plugins/cppeditor/cppprojectpartchooser.cpp | 6 | ||||
-rw-r--r-- | src/plugins/cppeditor/cppprojectpartchooser.h | 2 | ||||
-rw-r--r-- | src/plugins/cppeditor/projectinfo_test.cpp | 5 | ||||
-rw-r--r-- | src/plugins/cppeditor/projectpart.cpp | 7 | ||||
-rw-r--r-- | src/plugins/cppeditor/projectpart.h | 1 |
7 files changed, 21 insertions, 10 deletions
diff --git a/src/plugins/cppeditor/baseeditordocumentparser.cpp b/src/plugins/cppeditor/baseeditordocumentparser.cpp index f1066bd838..9dafd42380 100644 --- a/src/plugins/cppeditor/baseeditordocumentparser.cpp +++ b/src/plugins/cppeditor/baseeditordocumentparser.cpp @@ -120,7 +120,7 @@ BaseEditorDocumentParser::Ptr BaseEditorDocumentParser::get(const QString &fileP ProjectPartInfo BaseEditorDocumentParser::determineProjectPart(const QString &filePath, const QString &preferredProjectPartId, const ProjectPartInfo ¤tProjectPartInfo, - const ProjectExplorer::Project *activeProject, + const Utils::FilePath &activeProject, Utils::Language languagePreference, bool projectsUpdated) { diff --git a/src/plugins/cppeditor/baseeditordocumentparser.h b/src/plugins/cppeditor/baseeditordocumentparser.h index 2f48058b8b..6e7bf4326f 100644 --- a/src/plugins/cppeditor/baseeditordocumentparser.h +++ b/src/plugins/cppeditor/baseeditordocumentparser.h @@ -30,6 +30,8 @@ #include "cppworkingcopy.h" #include "projectpart.h" +#include <projectexplorer/project.h> + #include <QFutureInterface> #include <QObject> #include <QMutex> @@ -65,14 +67,14 @@ public: Utils::Language languagePreference, bool projectsUpdated) : workingCopy(workingCopy) - , activeProject(activeProject) + , activeProject(activeProject ? activeProject->projectFilePath() : Utils::FilePath()) , languagePreference(languagePreference) , projectsUpdated(projectsUpdated) { } WorkingCopy workingCopy; - const ProjectExplorer::Project *activeProject = nullptr; + const Utils::FilePath activeProject; Utils::Language languagePreference = Utils::Language::Cxx; bool projectsUpdated = false; }; @@ -104,7 +106,7 @@ protected: static ProjectPartInfo determineProjectPart(const QString &filePath, const QString &preferredProjectPartId, const ProjectPartInfo ¤tProjectPartInfo, - const ProjectExplorer::Project *activeProject, + const Utils::FilePath &activeProject, Utils::Language languagePreference, bool projectsUpdated); diff --git a/src/plugins/cppeditor/cppprojectpartchooser.cpp b/src/plugins/cppeditor/cppprojectpartchooser.cpp index 65911000e7..ca2e5943d7 100644 --- a/src/plugins/cppeditor/cppprojectpartchooser.cpp +++ b/src/plugins/cppeditor/cppprojectpartchooser.cpp @@ -46,7 +46,7 @@ public: ProjectPartPrioritizer(const QList<ProjectPart::ConstPtr> &projectParts, const QString &preferredProjectPartId, - const ProjectExplorer::Project *activeProject, + const Utils::FilePath &activeProject, Language languagePreference, bool areProjectPartsFromDependencies) : m_preferredProjectPartId(preferredProjectPartId) @@ -124,7 +124,7 @@ private: private: const QString m_preferredProjectPartId; - const ProjectExplorer::Project *m_activeProject = nullptr; + const Utils::FilePath m_activeProject; Language m_languagePreference = Language::Cxx; // Results @@ -134,7 +134,7 @@ private: ProjectPartInfo ProjectPartChooser::choose(const QString &filePath, const ProjectPartInfo ¤tProjectPartInfo, const QString &preferredProjectPartId, - const ProjectExplorer::Project *activeProject, + const Utils::FilePath &activeProject, Language languagePreference, bool projectsUpdated) const { diff --git a/src/plugins/cppeditor/cppprojectpartchooser.h b/src/plugins/cppeditor/cppprojectpartchooser.h index 4b8ee2dd1f..0ffa3dbb77 100644 --- a/src/plugins/cppeditor/cppprojectpartchooser.h +++ b/src/plugins/cppeditor/cppprojectpartchooser.h @@ -50,7 +50,7 @@ public: ProjectPartInfo choose(const QString &filePath, const ProjectPartInfo ¤tProjectPartInfo, const QString &preferredProjectPartId, - const ProjectExplorer::Project *activeProject, + const Utils::FilePath &activeProject, Utils::Language languagePreference, bool projectsUpdated) const; diff --git a/src/plugins/cppeditor/projectinfo_test.cpp b/src/plugins/cppeditor/projectinfo_test.cpp index e12f832991..825bd88b42 100644 --- a/src/plugins/cppeditor/projectinfo_test.cpp +++ b/src/plugins/cppeditor/projectinfo_test.cpp @@ -60,8 +60,11 @@ public: const ProjectPartInfo choose() { + const Project * const project = projectMap.value(activeProject).get(); + const Utils::FilePath projectFilePath = project ? project->projectFilePath() + : Utils::FilePath(); return chooser.choose(filePath, currentProjectPartInfo, preferredProjectPartId, - projectMap.value(activeProject).get(), + projectFilePath, languagePreference, projectsChanged); } diff --git a/src/plugins/cppeditor/projectpart.cpp b/src/plugins/cppeditor/projectpart.cpp index a0eaf79922..1d827648fc 100644 --- a/src/plugins/cppeditor/projectpart.cpp +++ b/src/plugins/cppeditor/projectpart.cpp @@ -57,7 +57,12 @@ QString ProjectPart::projectFileLocation() const bool ProjectPart::belongsToProject(const ProjectExplorer::Project *project) const { - return project ? topLevelProject == project->projectFilePath() : !hasProject(); + return belongsToProject(project ? project->projectFilePath() : Utils::FilePath()); +} + +bool ProjectPart::belongsToProject(const Utils::FilePath &project) const +{ + return topLevelProject == project; } QByteArray ProjectPart::readProjectConfigFile(const QString &projectConfigFile) diff --git a/src/plugins/cppeditor/projectpart.h b/src/plugins/cppeditor/projectpart.h index 2c420c8f87..c65932e6a7 100644 --- a/src/plugins/cppeditor/projectpart.h +++ b/src/plugins/cppeditor/projectpart.h @@ -75,6 +75,7 @@ public: QString projectFileLocation() const; bool hasProject() const { return !topLevelProject.isEmpty(); } bool belongsToProject(const ProjectExplorer::Project *project) const; + bool belongsToProject(const Utils::FilePath &project) const; static QByteArray readProjectConfigFile(const QString &projectConfigFile); |