From f651a0ac32060907b43eb6ccc7f1472986034270 Mon Sep 17 00:00:00 2001 From: Dimitri van Heesch Date: Sat, 28 Nov 2020 16:14:32 +0100 Subject: Protect mutable access to members in code generators with mutexes --- src/code.l | 6 ++++++ src/fortrancode.l | 7 +++++++ src/pycode.l | 9 +++++++++ 3 files changed, 22 insertions(+) diff --git a/src/code.l b/src/code.l index 1b6cf42..df4dd53 100644 --- a/src/code.l +++ b/src/code.l @@ -244,6 +244,8 @@ static void addVariable(yyscan_t yyscanner,QCString type,QCString name); static std::mutex g_searchIndexMutex; static std::mutex g_docCrossReferenceMutex; +static std::mutex g_addExampleMutex; +static std::mutex g_countFlowKeywordsMutex; /* ----------------------------------------------------------------- */ @@ -2447,6 +2449,7 @@ static void codifyLines(yyscan_t yyscanner,const char *text) static void incrementFlowKeyWordCount(yyscan_t yyscanner) { + std::lock_guard lock(g_countFlowKeywordsMutex); struct yyguts_t *yyg = (struct yyguts_t*)yyscanner; if (yyextra->currentMemberDef && yyextra->currentMemberDef->isFunction()) { @@ -2733,6 +2736,7 @@ static bool getLinkInScope(yyscan_t yyscanner, //printf("found it %s!\n",md->qualifiedName().data()); if (yyextra->exampleBlock) { + std::lock_guard lock(g_addExampleMutex); QCString anchor; anchor.sprintf("a%d",yyextra->anchorCount); //printf("addExampleFile(%s,%s,%s)\n",anchor.data(),yyextra->exampleName.data(), @@ -2899,6 +2903,7 @@ static void generateClassOrGlobalLink(yyscan_t yyscanner, DBG_CTX((stderr,"is linkable class %s\n",clName)); if (yyextra->exampleBlock) { + std::lock_guard lock(g_addExampleMutex); QCString anchor; anchor.sprintf("_a%d",yyextra->anchorCount); //printf("addExampleClass(%s,%s,%s)\n",anchor.data(),yyextra->exampleName.data(), @@ -2989,6 +2994,7 @@ static bool generateClassMemberLink(yyscan_t yyscanner, if (yyextra->exampleBlock) { + std::lock_guard lock(g_addExampleMutex); QCString anchor; anchor.sprintf("a%d",yyextra->anchorCount); //printf("addExampleFile(%s,%s,%s)\n",anchor.data(),yyextra->exampleName.data(), diff --git a/src/fortrancode.l b/src/fortrancode.l index a3795e4..1c1287d 100644 --- a/src/fortrancode.l +++ b/src/fortrancode.l @@ -213,6 +213,11 @@ static MemberDef *getFortranDefs(yyscan_t yyscanner,const QCString &memberName, static yy_size_t yyread(yyscan_t yyscanner,char *buf,yy_size_t max_size); +//------------------------------------------------------------------- + +static std::mutex g_docCrossReferenceMutex; +static std::mutex g_countFlowKeywordsMutex; + /* -----------------------------------------------------------------*/ #undef YY_INPUT #define YY_INPUT(buf,result,max_size) result=yyread(yyscanner,buf,max_size); @@ -296,6 +301,7 @@ LANGUAGE_BIND_SPEC BIND{BS}"("{BS}C{BS}(,{BS}NAME{BS}"="{BS}"\""(.*)"\""{BS})?") } if (yyextra->currentMemberDef && yyextra->currentMemberDef->isFunction()) { + std::lock_guard lock(g_countFlowKeywordsMutex); MemberDefMutable *mdm = toMemberDefMutable(yyextra->currentMemberDef); if (mdm) { @@ -1236,6 +1242,7 @@ static bool getLink(yyscan_t yyscanner,UseSDict *usedict, // dictionary with use if (yyextra->currentDefinition && yyextra->currentMemberDef && md!=yyextra->currentMemberDef && yyextra->insideBody && yyextra->collectXRefs) { + std::lock_guard lock(g_docCrossReferenceMutex); addDocCrossReference(toMemberDefMutable(yyextra->currentMemberDef),toMemberDefMutable(md)); } writeMultiLineCodeLink(yyscanner,ol,md,text ? text : memberText); diff --git a/src/pycode.l b/src/pycode.l index 970ac91..b7f3b66 100644 --- a/src/pycode.l +++ b/src/pycode.l @@ -149,6 +149,8 @@ static void addVariable(yyscan_t yyscanner, QCString type, QCString name); //------------------------------------------------------------------- static std::mutex g_searchIndexMutex; +static std::mutex g_docCrossReferenceMutex; +static std::mutex g_countFlowKeywordsMutex; //------------------------------------------------------------------- @@ -487,6 +489,7 @@ TARGET ({IDENTIFIER}|"("{TARGET_LIST}")"|"["{TARGET_LIST}"]"|{ATTRIBU {FLOWKW} { if (yyextra->currentMemberDef && yyextra->currentMemberDef->isFunction()) { + std::lock_guard lock(g_countFlowKeywordsMutex); MemberDefMutable *mdm = toMemberDefMutable(yyextra->currentMemberDef); if (mdm) { @@ -532,6 +535,7 @@ TARGET ({IDENTIFIER}|"("{TARGET_LIST}")"|"["{TARGET_LIST}"]"|{ATTRIBU {FLOWKW} { if (yyextra->currentMemberDef && yyextra->currentMemberDef->isFunction()) { + std::lock_guard lock(g_countFlowKeywordsMutex); MemberDefMutable *mdm = toMemberDefMutable(yyextra->currentMemberDef); if (mdm) { @@ -1224,6 +1228,7 @@ static bool getLinkInScope(yyscan_t yyscanner, if (yyextra->currentDefinition && yyextra->currentMemberDef && md!=yyextra->currentMemberDef && yyextra->collectXRefs) { + std::lock_guard lock(g_docCrossReferenceMutex); addDocCrossReference(toMemberDefMutable(yyextra->currentMemberDef),toMemberDefMutable(md)); } //printf("d->getReference()='%s' d->getOutputBase()='%s' name='%s' member name='%s'\n",d->getReference().data(),d->getOutputFileBase().data(),d->name().data(),md->name().data()); @@ -1334,6 +1339,7 @@ static void generateClassOrGlobalLink(yyscan_t yyscanner, if (d && d->isLinkable() && md->isLinkable() && yyextra->currentMemberDef && yyextra->collectXRefs) { + std::lock_guard lock(g_docCrossReferenceMutex); addDocCrossReference(toMemberDefMutable(yyextra->currentMemberDef),toMemberDefMutable(md)); } } @@ -1361,6 +1367,7 @@ static void generateClassOrGlobalLink(yyscan_t yyscanner, if (d && d->isLinkable() && mmd->isLinkable() && yyextra->currentMemberDef && yyextra->collectXRefs) { + std::lock_guard lock(g_docCrossReferenceMutex); addDocCrossReference(toMemberDefMutable(yyextra->currentMemberDef),toMemberDefMutable(mmd)); } return; @@ -1384,6 +1391,7 @@ static void generateClassOrGlobalLink(yyscan_t yyscanner, if (d && d->isLinkable() && mmd->isLinkable() && yyextra->currentMemberDef && yyextra->collectXRefs) { + std::lock_guard lock(g_docCrossReferenceMutex); addDocCrossReference(toMemberDefMutable(yyextra->currentMemberDef),toMemberDefMutable(mmd)); } return; @@ -1470,6 +1478,7 @@ static bool findMemberLink(yyscan_t yyscanner, { if (yyextra->currentMemberDef && yyextra->collectXRefs) { + std::lock_guard lock(g_docCrossReferenceMutex); addDocCrossReference(toMemberDefMutable(yyextra->currentMemberDef),toMemberDefMutable(toMemberDef(sym))); } } -- cgit v0.12