From 52051f444e6b1bfff20d5dd8967cd1f3effad610 Mon Sep 17 00:00:00 2001 From: acqn Date: Sun, 2 Aug 2020 21:51:32 +0800 Subject: [PATCH] Using tracked individual string buffers instead of a shared static string buffer for full type names. --- src/cc65/datatype.c | 11 ++++------ src/cc65/datatype.h | 4 +--- src/cc65/error.c | 51 +++++++++++++++++++++++++++++++++++++++++++++ src/cc65/error.h | 15 +++++++++++++ src/cc65/main.c | 6 ++++++ 5 files changed, 77 insertions(+), 10 deletions(-) diff --git a/src/cc65/datatype.c b/src/cc65/datatype.c index 2c2167188..d1c34c825 100644 --- a/src/cc65/datatype.c +++ b/src/cc65/datatype.c @@ -273,15 +273,12 @@ const char* GetBasicTypeName (const Type* T) const char* GetFullTypeName (const Type* T) -/* Return the full name string of the given type. -** Note: This may use a static buffer that could be overwritten by other calls. -*/ +/* Return the full name string of the given type */ { - static struct StrBuf Buf = STATIC_STRBUF_INITIALIZER; - SB_Clear (&Buf); - GetFullTypeNameBuf (&Buf, T); + struct StrBuf* Buf = NewDiagnosticStrBuf (); + GetFullTypeNameBuf (Buf, T); - return SB_GetConstBuf (&Buf); + return SB_GetConstBuf (Buf); } diff --git a/src/cc65/datatype.h b/src/cc65/datatype.h index 8e32d6404..ad382d50f 100644 --- a/src/cc65/datatype.h +++ b/src/cc65/datatype.h @@ -219,9 +219,7 @@ const char* GetBasicTypeName (const Type* T); */ const char* GetFullTypeName (const Type* T); -/* Return the full name string of the given type. -** Note: This may use a static buffer that could be overwritten by other calls. -*/ +/* Return the full name string of the given type */ struct StrBuf* GetFullTypeNameBuf (struct StrBuf* S, const Type* T); /* Return the full name string of the given type */ diff --git a/src/cc65/error.c b/src/cc65/error.c index c3ebebf77..10d20a34b 100644 --- a/src/cc65/error.c +++ b/src/cc65/error.c @@ -38,7 +38,9 @@ #include /* common */ +#include "coll.h" #include "print.h" +#include "strbuf.h" /* cc65 */ #include "global.h" @@ -92,6 +94,8 @@ static WarnMapEntry WarnMap[] = { { &WarnUnusedVar, "unused-var" }, }; +Collection DiagnosticStrBufs; + /*****************************************************************************/ @@ -323,3 +327,50 @@ void ErrorReport (void) { Print (stdout, 1, "%u errors, %u warnings\n", ErrorCount, WarningCount); } + + + +/*****************************************************************************/ +/* Tracked StrBufs */ +/*****************************************************************************/ + + + +void InitDiagnosticStrBufs (void) +/* Init tracking string buffers used for diagnostics */ +{ + InitCollection (&DiagnosticStrBufs); +} + + + +void DoneDiagnosticStrBufs (void) +/* Done with tracked string buffers used for diagnostics */ +{ + ClearDiagnosticStrBufs (); + DoneCollection (&DiagnosticStrBufs); +} + + + +void ClearDiagnosticStrBufs (void) +/* Free all tracked string buffers */ +{ + unsigned I; + + for (I = 0; I < CollCount (&DiagnosticStrBufs); ++I) { + SB_Done (CollAtUnchecked (&DiagnosticStrBufs, I)); + } + + CollDeleteAll (&DiagnosticStrBufs); +} + + + +struct StrBuf* NewDiagnosticStrBuf (void) +/* Get a new tracked string buffer */ +{ + StrBuf *Buf = NewStrBuf (); + CollAppend (&DiagnosticStrBufs, Buf); + return Buf; +} diff --git a/src/cc65/error.h b/src/cc65/error.h index 97ee09591..a443aeff8 100644 --- a/src/cc65/error.h +++ b/src/cc65/error.h @@ -72,6 +72,9 @@ extern IntStack WarnUnusedLabel; /* - unused labels */ extern IntStack WarnUnusedParam; /* - unused parameters */ extern IntStack WarnUnusedVar; /* - unused variables */ +/* Forward */ +struct StrBuf; + /*****************************************************************************/ @@ -115,6 +118,18 @@ void ListWarnings (FILE* F); void ErrorReport (void); /* Report errors (called at end of compile) */ +void InitDiagnosticStrBufs (void); +/* Init tracking string buffers used for diagnostics */ + +void DoneDiagnosticStrBufs (void); +/* Done with tracked string buffers used for diagnostics */ + +void ClearDiagnosticStrBufs (void); +/* Free all tracked string buffers */ + +struct StrBuf* NewDiagnosticStrBuf (void); +/* Get a new tracked string buffer */ + /* End of error.h */ diff --git a/src/cc65/main.c b/src/cc65/main.c index e86ae13ba..ed2e9d7ba 100644 --- a/src/cc65/main.c +++ b/src/cc65/main.c @@ -1060,6 +1060,9 @@ int main (int argc, char* argv[]) IS_Set (&Standard, STD_DEFAULT); } + /* Track string buffer allocation */ + InitDiagnosticStrBufs (); + /* Go! */ Compile (InputFile); @@ -1083,6 +1086,9 @@ int main (int argc, char* argv[]) CreateDependencies (); } + /* Done with tracked string buffer allocation */ + DoneDiagnosticStrBufs (); + /* Return an apropriate exit code */ return (ErrorCount > 0)? EXIT_FAILURE : EXIT_SUCCESS; }