summaryrefslogtreecommitdiffstats
path: root/src/linguist/shared/qmakeparser.cpp
diff options
context:
space:
mode:
authorOswald Buddenhagen <oswald.buddenhagen@qt.io>2017-08-14 18:30:29 +0200
committerOswald Buddenhagen <oswald.buddenhagen@qt.io>2018-09-14 13:49:31 +0000
commit1f191ccd929b688be4abda12be42f90dd9966ea1 (patch)
treea925d0018403abac191f3db28d81de7f4784b140 /src/linguist/shared/qmakeparser.cpp
parente249691b3a35001f7861fa5049f8d49c1cb3048e (diff)
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. Task-number: QTBUG-62434 Started-by: Simon Hausmann <simon.hausmann@qt.io> Change-Id: I395153afaf7c835d0119690ee7f4b915e6f90d4a Reviewed-by: Simon Hausmann <simon.hausmann@qt.io> (cherry picked from qtbase/190aa94be7f5e146bef44862b974d733755cec85) Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/linguist/shared/qmakeparser.cpp')
-rw-r--r--src/linguist/shared/qmakeparser.cpp27
1 files changed, 17 insertions, 10 deletions
diff --git a/src/linguist/shared/qmakeparser.cpp b/src/linguist/shared/qmakeparser.cpp
index 5fff018b1..ea6377e07 100644
--- a/src/linguist/shared/qmakeparser.cpp
+++ b/src/linguist/shared/qmakeparser.cpp
@@ -167,7 +167,7 @@ QMakeParser::QMakeParser(ProFileCache *cache, QMakeVfs *vfs, QMakeParserHandler
ProFile *QMakeParser::parsedProFile(const QString &fileName, ParseFlags flags)
{
ProFile *pro;
- if ((flags & (ParseUseCache|ParseOnlyCached)) && m_cache) {
+ if ((flags & ParseUseCache) && m_cache) {
ProFileCache::Entry *ent;
#ifdef PROPARSER_THREAD_SAFE
QMutexLocker locker(&m_cache->mutex);
@@ -189,13 +189,13 @@ ProFile *QMakeParser::parsedProFile(const QString &fileName, ParseFlags flags)
#endif
if ((pro = ent->pro))
pro->ref();
- } else if (!(flags & ParseOnlyCached)) {
+ } else {
ent = &m_cache->parsed_files[fileName];
#ifdef PROPARSER_THREAD_SAFE
ent->locker = new ProFileCache::Entry::Locker;
locker.unlock();
#endif
- pro = new ProFile(fileName);
+ pro = new ProFile(idForFileName(fileName), fileName);
if (!read(pro, flags)) {
delete pro;
pro = 0;
@@ -214,17 +214,13 @@ ProFile *QMakeParser::parsedProFile(const QString &fileName, ParseFlags flags)
ent->locker = 0;
}
#endif
- } else {
- pro = 0;
}
- } else if (!(flags & ParseOnlyCached)) {
- pro = new ProFile(fileName);
+ } else {
+ pro = new ProFile(idForFileName(fileName), fileName);
if (!read(pro, flags)) {
delete pro;
pro = 0;
}
- } else {
- pro = 0;
}
return pro;
}
@@ -232,11 +228,22 @@ ProFile *QMakeParser::parsedProFile(const QString &fileName, ParseFlags flags)
ProFile *QMakeParser::parsedProBlock(
const QStringRef &contents, const QString &name, int line, SubGrammar grammar)
{
- ProFile *pro = new ProFile(name);
+ ProFile *pro = new ProFile(0, name);
read(pro, contents, line, grammar);
return pro;
}
+int QMakeParser::idForFileName(const QString &fileName)
+{
+#ifdef PROPARSER_THREAD_SAFE
+ QMutexLocker lck(&fileIdMutex);
+#endif
+ int &place = fileIdMap[fileName];
+ if (!place)
+ place = ++fileIdCounter;
+ return place;
+}
+
void QMakeParser::discardFileFromCache(const QString &fileName)
{
if (m_cache)