Allow changing recursion depth limit at runtime

This commit is contained in:
ISSOtm
2022-02-05 12:15:32 +01:00
committed by Eldred Habert
parent 6842c831fd
commit 7dd8ba37f1
9 changed files with 80 additions and 12 deletions

View File

@@ -284,8 +284,9 @@ bool yywrap(void)
*/
static void newContext(struct FileStackNode *fileInfo)
{
if (++contextDepth >= maxRecursionDepth)
fatalerror("Recursion limit (%zu) exceeded\n", maxRecursionDepth);
++contextDepth;
fstk_NewRecursionDepth(maxRecursionDepth); // Only checks if the max depth was exceeded
struct Context *context = malloc(sizeof(*context));
if (!context)
@@ -507,6 +508,13 @@ bool fstk_Break(void)
return true;
}
void fstk_NewRecursionDepth(size_t newDepth)
{
if (contextDepth >= newDepth)
fatalerror("Recursion limit (%zu) exceeded\n", newDepth);
maxRecursionDepth = newDepth;
}
void fstk_Init(char const *mainPath, size_t maxDepth)
{
struct LexerState *state = lexer_OpenFile(mainPath);