mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-21 02:32:06 +00:00
Allow changing recursion depth limit at runtime
This commit is contained in:
@@ -668,14 +668,8 @@ static void beginExpansion(char const *str, bool owned, char const *name)
|
||||
if (!size)
|
||||
return;
|
||||
|
||||
if (name) {
|
||||
size_t depth = 0;
|
||||
|
||||
for (struct Expansion *exp = lexerState->expansions; exp; exp = exp->parent) {
|
||||
if (depth++ >= maxRecursionDepth)
|
||||
fatalerror("Recursion limit (%zu) exceeded\n", maxRecursionDepth);
|
||||
}
|
||||
}
|
||||
if (name)
|
||||
lexer_CheckRecursionDepth();
|
||||
|
||||
struct Expansion *exp = malloc(sizeof(*exp));
|
||||
|
||||
@@ -692,6 +686,16 @@ static void beginExpansion(char const *str, bool owned, char const *name)
|
||||
lexerState->expansions = exp;
|
||||
}
|
||||
|
||||
void lexer_CheckRecursionDepth(void)
|
||||
{
|
||||
size_t depth = 0;
|
||||
|
||||
for (struct Expansion *exp = lexerState->expansions; exp; exp = exp->parent) {
|
||||
if (depth++ >= maxRecursionDepth)
|
||||
fatalerror("Recursion limit (%zu) exceeded\n", maxRecursionDepth);
|
||||
}
|
||||
}
|
||||
|
||||
static void freeExpansion(struct Expansion *expansion)
|
||||
{
|
||||
free(expansion->name);
|
||||
|
||||
Reference in New Issue
Block a user