From 73517e86b02b47531bec189d4230e359274d8d04 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 11 Dec 2002 10:34:22 -0200 Subject: [PATCH] OP_TFORLOOP uses extra stack space --- lcode.c | 4 ++-- lcode.h | 3 ++- ldebug.c | 4 ++-- lparser.c | 3 ++- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lcode.c b/lcode.c index 3e22de75..0d96f632 100644 --- a/lcode.c +++ b/lcode.c @@ -1,5 +1,5 @@ /* -** $Id: lcode.c,v 1.113 2002/11/14 16:15:53 roberto Exp roberto $ +** $Id: lcode.c,v 1.114 2002/12/04 17:38:31 roberto Exp roberto $ ** Code generator for Lua ** See Copyright Notice in lua.h */ @@ -176,7 +176,7 @@ void luaK_concat (FuncState *fs, int *l1, int l2) { } -static void luaK_checkstack (FuncState *fs, int n) { +void luaK_checkstack (FuncState *fs, int n) { int newstack = fs->freereg + n; if (newstack > fs->f->maxstacksize) { if (newstack >= MAXSTACK) diff --git a/lcode.h b/lcode.h index 3c5da39a..8a0eece9 100644 --- a/lcode.h +++ b/lcode.h @@ -1,5 +1,5 @@ /* -** $Id: lcode.h,v 1.36 2002/05/13 13:07:48 roberto Exp roberto $ +** $Id: lcode.h,v 1.37 2002/06/12 19:16:00 roberto Exp roberto $ ** Code generator for Lua ** See Copyright Notice in lua.h */ @@ -47,6 +47,7 @@ int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C); void luaK_fixline (FuncState *fs, int line); void luaK_nil (FuncState *fs, int from, int n); void luaK_reserveregs (FuncState *fs, int n); +void luaK_checkstack (FuncState *fs, int n); int luaK_stringK (FuncState *fs, TString *s); int luaK_numberK (FuncState *fs, lua_Number r); void luaK_dischargevars (FuncState *fs, expdesc *e); diff --git a/ldebug.c b/ldebug.c index 9f170c6b..bf58d0a8 100644 --- a/ldebug.c +++ b/ldebug.c @@ -1,5 +1,5 @@ /* -** $Id: ldebug.c,v 1.141 2002/12/04 17:38:31 roberto Exp roberto $ +** $Id: ldebug.c,v 1.142 2002/12/06 17:15:35 roberto Exp roberto $ ** Debug Interface ** See Copyright Notice in lua.h */ @@ -364,7 +364,7 @@ static Instruction luaG_symbexec (const Proto *pt, int lastpc, int reg) { break; } case OP_TFORLOOP: - checkreg(pt, a+2+c); + checkreg(pt, a+c+5); if (reg >= a) last = pc; /* affect all registers above base */ /* go through */ case OP_FORLOOP: diff --git a/lparser.c b/lparser.c index ef1a1b03..e016b835 100644 --- a/lparser.c +++ b/lparser.c @@ -1,5 +1,5 @@ /* -** $Id: lparser.c,v 1.200 2002/12/04 17:38:31 roberto Exp roberto $ +** $Id: lparser.c,v 1.201 2002/12/06 17:09:00 roberto Exp roberto $ ** Lua Parser ** See Copyright Notice in lua.h */ @@ -1070,6 +1070,7 @@ static void forlist (LexState *ls, TString *indexname) { check(ls, TK_IN); line = ls->linenumber; adjust_assign(ls, nvars, explist1(ls, &e), &e); + luaK_checkstack(fs, 3); /* extra space to call generator */ luaK_codeAsBx(fs, OP_TFORPREP, base, NO_JUMP); forbody(ls, base, line, nvars, 0); }