allow setting template/macro recursive evaluation limits (#7652)
* allow setting template/macro recursive evaluation limits * revert setting template/macro eval limits set them to 1000
This commit is contained in:
parent
3402926372
commit
7e15d5134b
7 changed files with 14 additions and 10 deletions
|
|
@ -1729,14 +1729,16 @@ iterator genericParamsInMacroCall*(macroSym: PSym, call: PNode): (PSym, PNode) =
|
|||
let posInCall = macroSym.typ.len + i
|
||||
yield (genericParam, call[posInCall])
|
||||
|
||||
# to prevent endless recursion in macro instantiation
|
||||
const evalMacroLimit = 1000
|
||||
var evalMacroCounter: int
|
||||
|
||||
proc evalMacroCall*(module: PSym; cache: IdentCache, n, nOrig: PNode,
|
||||
sym: PSym): PNode =
|
||||
# XXX globalError() is ugly here, but I don't know a better solution for now
|
||||
inc(evalMacroCounter)
|
||||
if evalMacroCounter > 100:
|
||||
globalError(n.info, errTemplateInstantiationTooNested)
|
||||
if evalMacroCounter > evalMacroLimit:
|
||||
globalError(n.info, errMacroInstantiationTooNested)
|
||||
|
||||
# immediate macros can bypass any type and arity checking so we check the
|
||||
# arity here too:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue