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>
This commit is contained in:
Christian Kandeler
2022-02-24 13:00:58 +01:00
parent 1172eeb060
commit 86f1864d3c
7 changed files with 21 additions and 10 deletions

View File

@@ -120,7 +120,7 @@ BaseEditorDocumentParser::Ptr BaseEditorDocumentParser::get(const QString &fileP
ProjectPartInfo BaseEditorDocumentParser::determineProjectPart(const QString &filePath, ProjectPartInfo BaseEditorDocumentParser::determineProjectPart(const QString &filePath,
const QString &preferredProjectPartId, const QString &preferredProjectPartId,
const ProjectPartInfo &currentProjectPartInfo, const ProjectPartInfo &currentProjectPartInfo,
const ProjectExplorer::Project *activeProject, const Utils::FilePath &activeProject,
Utils::Language languagePreference, Utils::Language languagePreference,
bool projectsUpdated) bool projectsUpdated)
{ {

View File

@@ -30,6 +30,8 @@
#include "cppworkingcopy.h" #include "cppworkingcopy.h"
#include "projectpart.h" #include "projectpart.h"
#include <projectexplorer/project.h>
#include <QFutureInterface> #include <QFutureInterface>
#include <QObject> #include <QObject>
#include <QMutex> #include <QMutex>
@@ -65,14 +67,14 @@ public:
Utils::Language languagePreference, Utils::Language languagePreference,
bool projectsUpdated) bool projectsUpdated)
: workingCopy(workingCopy) : workingCopy(workingCopy)
, activeProject(activeProject) , activeProject(activeProject ? activeProject->projectFilePath() : Utils::FilePath())
, languagePreference(languagePreference) , languagePreference(languagePreference)
, projectsUpdated(projectsUpdated) , projectsUpdated(projectsUpdated)
{ {
} }
WorkingCopy workingCopy; WorkingCopy workingCopy;
const ProjectExplorer::Project *activeProject = nullptr; const Utils::FilePath activeProject;
Utils::Language languagePreference = Utils::Language::Cxx; Utils::Language languagePreference = Utils::Language::Cxx;
bool projectsUpdated = false; bool projectsUpdated = false;
}; };
@@ -104,7 +106,7 @@ protected:
static ProjectPartInfo determineProjectPart(const QString &filePath, static ProjectPartInfo determineProjectPart(const QString &filePath,
const QString &preferredProjectPartId, const QString &preferredProjectPartId,
const ProjectPartInfo &currentProjectPartInfo, const ProjectPartInfo &currentProjectPartInfo,
const ProjectExplorer::Project *activeProject, const Utils::FilePath &activeProject,
Utils::Language languagePreference, Utils::Language languagePreference,
bool projectsUpdated); bool projectsUpdated);

View File

@@ -46,7 +46,7 @@ public:
ProjectPartPrioritizer(const QList<ProjectPart::ConstPtr> &projectParts, ProjectPartPrioritizer(const QList<ProjectPart::ConstPtr> &projectParts,
const QString &preferredProjectPartId, const QString &preferredProjectPartId,
const ProjectExplorer::Project *activeProject, const Utils::FilePath &activeProject,
Language languagePreference, Language languagePreference,
bool areProjectPartsFromDependencies) bool areProjectPartsFromDependencies)
: m_preferredProjectPartId(preferredProjectPartId) : m_preferredProjectPartId(preferredProjectPartId)
@@ -124,7 +124,7 @@ private:
private: private:
const QString m_preferredProjectPartId; const QString m_preferredProjectPartId;
const ProjectExplorer::Project *m_activeProject = nullptr; const Utils::FilePath m_activeProject;
Language m_languagePreference = Language::Cxx; Language m_languagePreference = Language::Cxx;
// Results // Results
@@ -134,7 +134,7 @@ private:
ProjectPartInfo ProjectPartChooser::choose(const QString &filePath, ProjectPartInfo ProjectPartChooser::choose(const QString &filePath,
const ProjectPartInfo &currentProjectPartInfo, const ProjectPartInfo &currentProjectPartInfo,
const QString &preferredProjectPartId, const QString &preferredProjectPartId,
const ProjectExplorer::Project *activeProject, const Utils::FilePath &activeProject,
Language languagePreference, Language languagePreference,
bool projectsUpdated) const bool projectsUpdated) const
{ {

View File

@@ -50,7 +50,7 @@ public:
ProjectPartInfo choose(const QString &filePath, ProjectPartInfo choose(const QString &filePath,
const ProjectPartInfo &currentProjectPartInfo, const ProjectPartInfo &currentProjectPartInfo,
const QString &preferredProjectPartId, const QString &preferredProjectPartId,
const ProjectExplorer::Project *activeProject, const Utils::FilePath &activeProject,
Utils::Language languagePreference, Utils::Language languagePreference,
bool projectsUpdated) const; bool projectsUpdated) const;

View File

@@ -60,8 +60,11 @@ public:
const ProjectPartInfo choose() 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, return chooser.choose(filePath, currentProjectPartInfo, preferredProjectPartId,
projectMap.value(activeProject).get(), projectFilePath,
languagePreference, projectsChanged); languagePreference, projectsChanged);
} }

View File

@@ -57,7 +57,12 @@ QString ProjectPart::projectFileLocation() const
bool ProjectPart::belongsToProject(const ProjectExplorer::Project *project) 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) QByteArray ProjectPart::readProjectConfigFile(const QString &projectConfigFile)

View File

@@ -75,6 +75,7 @@ public:
QString projectFileLocation() const; QString projectFileLocation() const;
bool hasProject() const { return !topLevelProject.isEmpty(); } bool hasProject() const { return !topLevelProject.isEmpty(); }
bool belongsToProject(const ProjectExplorer::Project *project) const; bool belongsToProject(const ProjectExplorer::Project *project) const;
bool belongsToProject(const Utils::FilePath &project) const;
static QByteArray readProjectConfigFile(const QString &projectConfigFile); static QByteArray readProjectConfigFile(const QString &projectConfigFile);