summaryrefslogtreecommitdiff
path: root/ldo.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-11-26 18:44:52 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-11-26 18:44:52 -0200
commit9e029f98b9b4859aa30305a0c36e560a085c02a9 (patch)
treefa299d9d4f138071495f948716cd58f2b132bb45 /ldo.c
parente962330df9311515cf414097cd077ab93a928089 (diff)
downloadlua-9e029f98b9b4859aa30305a0c36e560a085c02a9.tar.gz
lua-9e029f98b9b4859aa30305a0c36e560a085c02a9.tar.bz2
lua-9e029f98b9b4859aa30305a0c36e560a085c02a9.zip
details
Diffstat (limited to 'ldo.c')
-rw-r--r--ldo.c31
1 files changed, 15 insertions, 16 deletions
diff --git a/ldo.c b/ldo.c
index 5b03633f..2318dd81 100644
--- a/ldo.c
+++ b/ldo.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldo.c,v 1.10 1997/11/21 19:00:46 roberto Exp roberto $ 2** $Id: ldo.c,v 1.11 1997/11/26 20:28:22 roberto Exp $
3** Stack and Call structure of Lua 3** Stack and Call structure of Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -52,33 +52,32 @@ static void initCfunc (TObject *o, lua_CFunction f)
52} 52}
53 53
54 54
55#define STACK_EXTRA 32 55#define STACK_UNIT 128
56#define INIT_STACK_SIZE 32
57 56
58 57
59void luaD_init (void) 58void luaD_init (void)
60{ 59{
61 L->stack.stack = luaM_newvector(INIT_STACK_SIZE, TObject); 60 L->stack.stack = luaM_newvector(STACK_UNIT, TObject);
62 L->stack.top = L->stack.stack; 61 L->stack.top = L->stack.stack;
63 L->stack.last = L->stack.stack+(INIT_STACK_SIZE-1); 62 L->stack.last = L->stack.stack+(STACK_UNIT-1);
64 initCfunc(&L->errorim, stderrorim); 63 initCfunc(&L->errorim, stderrorim);
65} 64}
66 65
67 66
68void luaD_checkstack (int n) 67void luaD_checkstack (int n)
69{ 68{
70 if (L->stack.last-L->stack.top <= n) { 69 struct Stack *S = &L->stack;
71 StkId top = L->stack.top-L->stack.stack; 70 if (S->last-S->top <= n) {
72 int stacksize = (L->stack.last-L->stack.stack)+1+STACK_EXTRA+n; 71 StkId top = S->top-S->stack;
73 L->stack.stack = luaM_reallocvector(L->stack.stack, stacksize, TObject); 72 int stacksize = (S->last-S->stack)+1+STACK_UNIT+n;
74 L->stack.last = L->stack.stack+(stacksize-1); 73 S->stack = luaM_reallocvector(S->stack, stacksize, TObject);
75 L->stack.top = L->stack.stack + top; 74 S->last = S->stack+(stacksize-1);
76 if (stacksize >= STACK_LIMIT) { 75 S->top = S->stack + top;
77 if (lua_stackedfunction(100) == LUA_NOOBJECT) 76 if (stacksize >= STACK_LIMIT) { /* stack overflow? */
78 /* doesn't look like a recursive loop */ 77 if (lua_stackedfunction(100) == LUA_NOOBJECT) /* 100 funcs on stack? */
79 lua_error("Lua2C - C2Lua overflow"); 78 lua_error("Lua2C - C2Lua overflow"); /* doesn't look like a rec. loop */
80 else 79 else
81 lua_error(stackEM); 80 lua_error("stack size overflow");
82 } 81 }
83 } 82 }
84} 83}