From 5d4bf35ec9f240fc82cd4e94a395c652b2ab004c Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 29 Sep 2003 13:41:35 -0300 Subject: [PATCH] bug: syntax `local function' does not increment stack size --- bugs | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- lparser.c | 11 +++++++---- 2 files changed, 62 insertions(+), 5 deletions(-) diff --git a/bugs b/bugs index d202ee22..7b272fbb 100644 --- a/bugs +++ b/bugs @@ -358,7 +358,37 @@ coroutine.resume(co) coroutine.resume(co) --> seg. fault ]], report = [[by Alex Bilyk, 09/05/2003]], -patch = [[???]], +patch = [[ +* ldo.c: +325,326c325 +< if (nargs >= L->top - L->base) +< luaG_runerror(L, "cannot resume dead coroutine"); +--- +> lua_assert(nargs < L->top - L->base); +329c328,329 +< else if (ci->state & CI_YIELD) { /* inside a yield? */ +--- +> else { /* inside a yield */ +> lua_assert(ci->state & CI_YIELD); +344,345d343 +< else +< luaG_runerror(L, "cannot resume non-suspended coroutine"); +351a350,358 +> static int resume_error (lua_State *L, const char *msg) { +> L->top = L->ci->base; +> setsvalue2s(L->top, luaS_new(L, msg)); +> incr_top(L); +> lua_unlock(L); +> return LUA_ERRRUN; +> } +> +> +355a363,366 +> if (L->ci == L->base_ci && nargs >= L->top - L->base) +> return resume_error(L, "cannot resume dead coroutine"); +> else if (!(L->ci->state & CI_YIELD)) /* not inside a yield? */ +> return resume_error(L, "cannot resume non-suspended coroutine"); +]], } @@ -514,3 +544,27 @@ patch = [[ > char buff[128]; ]] } + + +Bug{ +what = [[syntax `local function' does not increment stack size]], + +report = [[Rici Lake, 26/09/2003]], + +example = [[ +-- must run this with precompiled code +local a,b,c +local function d () end +]], + +patch = [[ +* lparser.c: +1145c1145,1146 +< init_exp(&v, VLOCAL, ls->fs->freereg++); +--- +> init_exp(&v, VLOCAL, ls->fs->freereg); +> luaK_reserveregs(ls->fs, 1); +]], + +} + diff --git a/lparser.c b/lparser.c index c551047a..a73fab43 100644 --- a/lparser.c +++ b/lparser.c @@ -1,5 +1,5 @@ /* -** $Id: lparser.c,v 1.217 2003/08/27 21:01:44 roberto Exp roberto $ +** $Id: lparser.c,v 1.218 2003/09/05 14:00:27 roberto Exp roberto $ ** Lua Parser ** See Copyright Notice in lua.h */ @@ -1167,11 +1167,13 @@ static void ifstat (LexState *ls, int line) { static void localfunc (LexState *ls) { expdesc v, b; + FuncState *fs = ls->fs; new_localvar(ls, str_checkname(ls), 0); - init_exp(&v, VLOCAL, ls->fs->freereg++); + init_exp(&v, VLOCAL, fs->freereg); + luaK_reserveregs(fs, 1); adjustlocalvars(ls, 1); body(ls, &b, 0, ls->linenumber); - luaK_storevar(ls->fs, &v, &b); + luaK_storevar(fs, &v, &b); } @@ -1346,7 +1348,8 @@ static void chunk (LexState *ls) { while (!islast && !block_follow(ls->t.token)) { islast = statement(ls); testnext(ls, ';'); - lua_assert(ls->fs->freereg >= ls->fs->nactvar); + lua_assert(ls->fs->f->maxstacksize >= ls->fs->freereg && + ls->fs->freereg >= ls->fs->nactvar); ls->fs->freereg = ls->fs->nactvar; /* free registers */ } leavelevel(ls);