diff options
| author | Oswald Buddenhagen <oswald.buddenhagen@qt.io> | 2017-08-14 18:30:29 +0200 |
|---|---|---|
| committer | Simon Hausmann <simon.hausmann@qt.io> | 2017-08-15 10:54:50 +0000 |
| commit | 190aa94be7f5e146bef44862b974d733755cec85 (patch) | |
| tree | f347424990930691ebc2b9cd39794ae74984f8f5 /qmake/library/qmakeparser.cpp | |
| parent | e6fad35155a25a932386ad6f8421efd74404ac7f (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>
Diffstat (limited to 'qmake/library/qmakeparser.cpp')
| -rw-r--r-- | qmake/library/qmakeparser.cpp | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/qmake/library/qmakeparser.cpp b/qmake/library/qmakeparser.cpp index 78350c76c4f..b5d89c1ba68 100644 --- a/qmake/library/qmakeparser.cpp +++ b/qmake/library/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) |
