summaryrefslogtreecommitdiff
path: root/lgc.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-03-07 15:14:29 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-03-07 15:14:29 -0300
commit8f837e83b20f3c409ba187765c2bf5aefc111923 (patch)
treefdd9128cd1401155708f6f31df9dea4e0f0d51ad /lgc.c
parent6658b9588faa3dae1747f2b705e99e96c6cf0e31 (diff)
downloadlua-8f837e83b20f3c409ba187765c2bf5aefc111923.tar.gz
lua-8f837e83b20f3c409ba187765c2bf5aefc111923.tar.bz2
lua-8f837e83b20f3c409ba187765c2bf5aefc111923.zip
using `ci->top' to control acceptable indices in C calls
Diffstat (limited to 'lgc.c')
-rw-r--r--lgc.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/lgc.c b/lgc.c
index 884f689f..1088cb23 100644
--- a/lgc.c
+++ b/lgc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lgc.c,v 1.128 2002/03/04 21:32:34 roberto Exp roberto $ 2** $Id: lgc.c,v 1.129 2002/03/05 16:22:54 roberto Exp roberto $
3** Garbage Collector 3** Garbage Collector
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -122,12 +122,12 @@ static void reallymarkobject (GCState *st, TObject *o) {
122} 122}
123 123
124 124
125static void checkstacksizes (lua_State *L) { 125static void checkstacksizes (lua_State *L, StkId max) {
126 int used = L->ci - L->base_ci; /* number of `ci' in use */ 126 int used = L->ci - L->base_ci; /* number of `ci' in use */
127 if (4*used < L->size_ci && 2*BASIC_CI_SIZE < L->size_ci) 127 if (4*used < L->size_ci && 2*BASIC_CI_SIZE < L->size_ci)
128 luaD_reallocCI(L, L->size_ci/2); /* still big enough... */ 128 luaD_reallocCI(L, L->size_ci/2); /* still big enough... */
129 used = L->top - L->stack; /* part of stack in use */ 129 used = max - L->stack; /* part of stack in use */
130 if (2*(used+MAXSTACK) < L->stacksize && 2*BASIC_STACK_SIZE < L->stacksize) 130 if (4*used < L->stacksize && 2*BASIC_STACK_SIZE < L->stacksize)
131 luaD_reallocstack(L, L->stacksize/2); /* still big enough... */ 131 luaD_reallocstack(L, L->stacksize/2); /* still big enough... */
132} 132}
133 133
@@ -136,6 +136,7 @@ static void markstacks (GCState *st) {
136 lua_State *L1 = st->L; 136 lua_State *L1 = st->L;
137 do { /* for each thread */ 137 do { /* for each thread */
138 StkId o, lim; 138 StkId o, lim;
139 CallInfo *ci;
139 if (L1->base_ci == NULL) { /* incomplete state? */ 140 if (L1->base_ci == NULL) { /* incomplete state? */
140 lua_assert(L1 != st->L); 141 lua_assert(L1 != st->L);
141 L1 = L1->next; 142 L1 = L1->next;
@@ -144,10 +145,11 @@ static void markstacks (GCState *st) {
144 } 145 }
145 for (o=L1->stack; o<L1->top; o++) 146 for (o=L1->stack; o<L1->top; o++)
146 markobject(st, o); 147 markobject(st, o);
147 lim = (L1->stack_last - L1->ci->base > MAXSTACK) ? L1->ci->base+MAXSTACK 148 lim = o;
148 : L1->stack_last; 149 for (ci = L1->base_ci; ci <= L1->ci; ci++)
150 if (lim < ci->top) lim = ci->top;
149 for (; o<=lim; o++) setnilvalue(o); 151 for (; o<=lim; o++) setnilvalue(o);
150 checkstacksizes(L1); 152 checkstacksizes(L1, lim);
151 lua_assert(L1->previous->next == L1 && L1->next->previous == L1); 153 lua_assert(L1->previous->next == L1 && L1->next->previous == L1);
152 L1 = L1->next; 154 L1 = L1->next;
153 } while (L1 != st->L); 155 } while (L1 != st->L);