From 9e029f98b9b4859aa30305a0c36e560a085c02a9 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 26 Nov 1997 18:44:52 -0200 Subject: details --- ldo.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) (limited to 'ldo.c') diff --git a/ldo.c b/ldo.c index 5b03633f..2318dd81 100644 --- a/ldo.c +++ b/ldo.c @@ -1,5 +1,5 @@ /* -** $Id: ldo.c,v 1.10 1997/11/21 19:00:46 roberto Exp roberto $ +** $Id: ldo.c,v 1.11 1997/11/26 20:28:22 roberto Exp $ ** Stack and Call structure of Lua ** See Copyright Notice in lua.h */ @@ -52,33 +52,32 @@ static void initCfunc (TObject *o, lua_CFunction f) } -#define STACK_EXTRA 32 -#define INIT_STACK_SIZE 32 +#define STACK_UNIT 128 void luaD_init (void) { - L->stack.stack = luaM_newvector(INIT_STACK_SIZE, TObject); + L->stack.stack = luaM_newvector(STACK_UNIT, TObject); L->stack.top = L->stack.stack; - L->stack.last = L->stack.stack+(INIT_STACK_SIZE-1); + L->stack.last = L->stack.stack+(STACK_UNIT-1); initCfunc(&L->errorim, stderrorim); } void luaD_checkstack (int n) { - if (L->stack.last-L->stack.top <= n) { - StkId top = L->stack.top-L->stack.stack; - int stacksize = (L->stack.last-L->stack.stack)+1+STACK_EXTRA+n; - L->stack.stack = luaM_reallocvector(L->stack.stack, stacksize, TObject); - L->stack.last = L->stack.stack+(stacksize-1); - L->stack.top = L->stack.stack + top; - if (stacksize >= STACK_LIMIT) { - if (lua_stackedfunction(100) == LUA_NOOBJECT) - /* doesn't look like a recursive loop */ - lua_error("Lua2C - C2Lua overflow"); + struct Stack *S = &L->stack; + if (S->last-S->top <= n) { + StkId top = S->top-S->stack; + int stacksize = (S->last-S->stack)+1+STACK_UNIT+n; + S->stack = luaM_reallocvector(S->stack, stacksize, TObject); + S->last = S->stack+(stacksize-1); + S->top = S->stack + top; + if (stacksize >= STACK_LIMIT) { /* stack overflow? */ + if (lua_stackedfunction(100) == LUA_NOOBJECT) /* 100 funcs on stack? */ + lua_error("Lua2C - C2Lua overflow"); /* doesn't look like a rec. loop */ else - lua_error(stackEM); + lua_error("stack size overflow"); } } } -- cgit v1.2.3-55-g6feb