From 60245e55d7551f525c951d8d866aab081be88a69 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Mon, 14 Aug 2017 18:30:29 +0200 Subject: qmake: Change source identifier type in ProString The strings remember in which file they were created/assigned. However, this used a non-counting reference to a ProFile, which could become dangling. If a subsequent ProFile re-used the exact same address, a string's source would be mis-identified, which would be fatal in conjunction with discard_from(). Since we actually need only a unique id for comparison, let's use an integer for that. comment on cherry-pick: this is actually a lot more than a cherry-pick, because the file ids need to be aware of the dual VFS which was concurrently introduced on the qtc side. Started-by: Simon Hausmann Change-Id: I395153afaf7c835d0119690ee7f4b915e6f90d4a (cherry picked from qtbase/190aa94be7f5e146bef44862b974d733755cec85) Reviewed-by: Tobias Hunger --- src/shared/proparser/qmakevfs.h | 55 ++++++++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 15 deletions(-) (limited to 'src/shared/proparser/qmakevfs.h') diff --git a/src/shared/proparser/qmakevfs.h b/src/shared/proparser/qmakevfs.h index b6b93fb5dd..da0d0626d8 100644 --- a/src/shared/proparser/qmakevfs.h +++ b/src/shared/proparser/qmakevfs.h @@ -27,13 +27,11 @@ #include "qmake_global.h" -# include -#ifndef PROEVALUATOR_FULL -# include -# include -# ifdef PROEVALUATOR_THREAD_SAFE -# include -# endif +#include +#include +#include +#ifdef PROEVALUATOR_THREAD_SAFE +# include #endif #ifndef QT_NO_TEXTCODEC @@ -62,23 +60,27 @@ public: VfsExact = 0, #ifdef PROEVALUATOR_DUAL_VFS VfsCumulative = 2, - VfsNoVirtual = 4 + VfsCreate = 4, + VfsCreatedOnly = 8, #else VfsCumulative = 0, - VfsNoVirtual = 0 + VfsCreate = 0, + VfsCreatedOnly = 0, #endif + VfsAccessedOnly = 16 }; Q_DECLARE_FLAGS(VfsFlags, VfsFlag) QMakeVfs(); - bool writeFile(const QString &fn, QIODevice::OpenMode mode, VfsFlags flags, const QString &contents, QString *errStr); - ReadResult readFile(const QString &fn, VfsFlags flags, QString *contents, QString *errStr); - bool exists(const QString &fn, VfsFlags flags); + int idForFileName(const QString &fn, VfsFlags flags); + QString fileNameForId(int id); + static void clearIds(); + bool writeFile(int id, QIODevice::OpenMode mode, VfsFlags flags, const QString &contents, QString *errStr); + ReadResult readFile(int id, QString *contents, QString *errStr); + bool exists(const QString &fn, QMakeVfs::VfsFlags flags); #ifndef PROEVALUATOR_FULL - bool readVirtualFile(const QString &fn, VfsFlags flags, QString *contents); - void invalidateCache(); void invalidateContents(); #endif @@ -88,11 +90,34 @@ public: #endif private: +#ifdef PROEVALUATOR_THREAD_SAFE + static QMutex s_mutex; +#endif + static QAtomicInt s_fileIdCounter; + // Qt Creator's ProFile cache is a singleton to maximize its cross-project + // effectiveness (shared prf files from QtVersions). + // For this to actually work, real files need a global mapping. + // This is fine, because the namespace of real files is indeed global. + static QHash s_fileIdMap; + static QHash s_idFileMap; +#ifdef PROEVALUATOR_DUAL_VFS +# ifdef PROEVALUATOR_THREAD_SAFE + // The simple way to avoid recursing m_mutex. + QMutex m_vmutex; +# endif + // Virtual files are bound to the project context they were created in, + // so their ids need to be local as well. + // We violate that rule in lupdate (which has a non-dual VFS), but that + // does not matter, because it has only one project context anyway. + QHash m_virtualFileIdMap[2]; // Exact and cumulative + QHash m_virtualIdFileMap; // Only one map, as ids are unique across realms. +#endif + #ifndef PROEVALUATOR_FULL # ifdef PROEVALUATOR_THREAD_SAFE QMutex m_mutex; # endif - QHash m_files; + QHash m_files; QString m_magicMissing; QString m_magicExisting; #endif -- cgit v1.2.1