From fabf5db2373d18a7c97016ea00acc0e05601960a Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 7 Apr 2005 10:09:07 -0300 Subject: C stack is the same for the parser and the interpreter, so depth control should be unified in both parts. --- llex.h | 3 +-- lparser.c | 17 ++++++++++------- luaconf.h | 12 +++--------- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/llex.h b/llex.h index e463a98d..25582643 100644 --- a/llex.h +++ b/llex.h @@ -1,5 +1,5 @@ /* -** $Id: llex.h,v 1.51 2004/12/02 12:59:10 roberto Exp roberto $ +** $Id: llex.h,v 1.52 2004/12/03 20:54:12 roberto Exp roberto $ ** Lexical Analyzer ** See Copyright Notice in lua.h */ @@ -63,7 +63,6 @@ typedef struct LexState { ZIO *z; /* input stream */ Mbuffer *buff; /* buffer for tokens */ TString *source; /* current source name */ - int nestlevel; /* level of nested non-terminals */ } LexState; diff --git a/lparser.c b/lparser.c index 4355f5fc..6db1bf1a 100644 --- a/lparser.c +++ b/lparser.c @@ -1,5 +1,5 @@ /* -** $Id: lparser.c,v 2.18 2005/03/09 16:28:07 roberto Exp roberto $ +** $Id: lparser.c,v 2.19 2005/03/16 16:59:21 roberto Exp roberto $ ** Lua Parser ** See Copyright Notice in lua.h */ @@ -33,10 +33,6 @@ #define luaY_checklimit(fs,v,l,m) if ((v)>(l)) errorlimit(fs,l,m) -#define enterlevel(ls) if (++(ls)->nestlevel > LUAI_MAXPARSERLEVEL) \ - luaX_lexerror(ls, "chunk has too many syntax levels", 0) -#define leavelevel(ls) ((ls)->nestlevel--) - /* ** nodes for block list (list of active blocks) @@ -295,6 +291,15 @@ static void adjust_assign (LexState *ls, int nvars, int nexps, expdesc *e) { } +static void enterlevel (LexState *ls) { + if (++ls->L->nCcalls > LUAI_MAXCCALLS) + luaX_lexerror(ls, "chunk has too many syntax levels", 0); +} + + +#define leavelevel(ls) ((ls)->L->nCcalls--) + + static void enterblock (FuncState *fs, BlockCnt *bl, int isbreakable) { bl->breaklist = NO_JUMP; bl->isbreakable = isbreakable; @@ -395,7 +400,6 @@ Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) { struct LexState lexstate; struct FuncState funcstate; lexstate.buff = buff; - lexstate.nestlevel = 0; luaX_setinput(L, &lexstate, z, luaS_new(L, name)); open_func(&lexstate, &funcstate); funcstate.f->is_vararg = NEWSTYLEVARARG; @@ -405,7 +409,6 @@ Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) { close_func(&lexstate); lua_assert(funcstate.prev == NULL); lua_assert(funcstate.f->nups == 0); - lua_assert(lexstate.nestlevel == 0); lua_assert(lexstate.fs == NULL); return funcstate.f; } diff --git a/luaconf.h b/luaconf.h index 83221e8b..ba65a311 100644 --- a/luaconf.h +++ b/luaconf.h @@ -1,5 +1,5 @@ /* -** $Id: luaconf.h,v 1.40 2005/03/29 16:20:48 roberto Exp roberto $ +** $Id: luaconf.h,v 1.41 2005/04/06 17:30:13 roberto Exp roberto $ ** Configuration file for Lua ** See Copyright Notice in lua.h */ @@ -351,18 +351,12 @@ /* -@@ LUAI_MAXCCALLS is the maximum depth for nested C calls (short). +@@ LUAI_MAXCCALLS is the maximum depth for nested C calls (short) and +@* syntactical nested non-terminals in a program. */ #define LUAI_MAXCCALLS 200 -/* -@@ LUAI_MAXPARSERLEVEL is the maximum number of syntactical nested -@* non-terminals in a program. -*/ -#define LUAI_MAXPARSERLEVEL 200 - - /* @@ LUAI_MAXVARS is the maximum number of local variables per function @* (must be smaller than 250). -- cgit v1.2.3-55-g6feb