diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-12-26 16:46:09 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-12-26 16:46:09 -0200 |
commit | 8c49e198654567f770a7d5081b886a7c35201d81 (patch) | |
tree | 8c1de3e885ef138574e51a8868f175feeaab71e2 | |
parent | 6af005ec20323defd2a5ead01e2d389462884d04 (diff) | |
download | lua-8c49e198654567f770a7d5081b886a7c35201d81.tar.gz lua-8c49e198654567f770a7d5081b886a7c35201d81.tar.bz2 lua-8c49e198654567f770a7d5081b886a7c35201d81.zip |
explicit control of size for growing vectors
-rw-r--r-- | lapi.c | 12 | ||||
-rw-r--r-- | lcode.c | 19 | ||||
-rw-r--r-- | ldebug.c | 4 | ||||
-rw-r--r-- | lgc.c | 10 | ||||
-rw-r--r-- | lmem.c | 25 | ||||
-rw-r--r-- | lmem.h | 12 | ||||
-rw-r--r-- | lparser.c | 31 | ||||
-rw-r--r-- | lparser.h | 8 | ||||
-rw-r--r-- | lstate.c | 12 | ||||
-rw-r--r-- | lstate.h | 8 | ||||
-rw-r--r-- | ltm.c | 20 | ||||
-rw-r--r-- | ltm.h | 4 |
12 files changed, 95 insertions, 70 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 1.111 2000/11/24 17:39:56 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 1.112 2000/12/04 18:33:40 roberto Exp roberto $ |
3 | ** Lua API | 3 | ** Lua API |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -289,7 +289,7 @@ LUA_API void lua_getglobals (lua_State *L) { | |||
289 | LUA_API int lua_getref (lua_State *L, int ref) { | 289 | LUA_API int lua_getref (lua_State *L, int ref) { |
290 | if (ref == LUA_REFNIL) | 290 | if (ref == LUA_REFNIL) |
291 | ttype(L->top) = LUA_TNIL; | 291 | ttype(L->top) = LUA_TNIL; |
292 | else if (0 <= ref && ref < L->refSize && | 292 | else if (0 <= ref && ref < L->nref && |
293 | (L->refArray[ref].st == LOCK || L->refArray[ref].st == HOLD)) | 293 | (L->refArray[ref].st == LOCK || L->refArray[ref].st == HOLD)) |
294 | *L->top = L->refArray[ref].o; | 294 | *L->top = L->refArray[ref].o; |
295 | else | 295 | else |
@@ -360,10 +360,10 @@ LUA_API int lua_ref (lua_State *L, int lock) { | |||
360 | L->refFree = L->refArray[ref].st; | 360 | L->refFree = L->refArray[ref].st; |
361 | } | 361 | } |
362 | else { /* no more free places */ | 362 | else { /* no more free places */ |
363 | luaM_growvector(L, L->refArray, L->refSize, 1, struct Ref, | 363 | luaM_growvector(L, L->refArray, L->nref, L->sizeref, struct Ref, |
364 | "reference table overflow", MAX_INT); | 364 | MAX_INT, "reference table overflow"); |
365 | L->nblocks += sizeof(struct Ref); | 365 | L->nblocks += sizeof(struct Ref); |
366 | ref = L->refSize++; | 366 | ref = L->nref++; |
367 | } | 367 | } |
368 | L->refArray[ref].o = *(L->top-1); | 368 | L->refArray[ref].o = *(L->top-1); |
369 | L->refArray[ref].st = lock ? LOCK : HOLD; | 369 | L->refArray[ref].st = lock ? LOCK : HOLD; |
@@ -430,7 +430,7 @@ LUA_API void lua_settag (lua_State *L, int tag) { | |||
430 | 430 | ||
431 | LUA_API void lua_unref (lua_State *L, int ref) { | 431 | LUA_API void lua_unref (lua_State *L, int ref) { |
432 | if (ref >= 0) { | 432 | if (ref >= 0) { |
433 | LUA_ASSERT(ref < L->refSize && L->refArray[ref].st < 0, "invalid ref"); | 433 | LUA_ASSERT(ref < L->nref && L->refArray[ref].st < 0, "invalid ref"); |
434 | L->refArray[ref].st = L->refFree; | 434 | L->refArray[ref].st = L->refFree; |
435 | L->refFree = ref; | 435 | L->refFree = ref; |
436 | } | 436 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lcode.c,v 1.52 2000/11/30 18:50:47 roberto Exp roberto $ | 2 | ** $Id: lcode.c,v 1.53 2000/12/04 18:33:40 roberto Exp roberto $ |
3 | ** Code generator for Lua | 3 | ** Code generator for Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -107,8 +107,8 @@ static int number_constant (FuncState *fs, lua_Number r) { | |||
107 | while (--c >= lim) | 107 | while (--c >= lim) |
108 | if (f->knum[c] == r) return c; | 108 | if (f->knum[c] == r) return c; |
109 | /* not found; create a new entry */ | 109 | /* not found; create a new entry */ |
110 | luaM_growvector(fs->L, f->knum, f->nknum, 1, lua_Number, | 110 | luaM_growvector(fs->L, f->knum, f->nknum, fs->sizeknum, lua_Number, |
111 | "constant table overflow", MAXARG_U); | 111 | MAXARG_U, "constant table overflow"); |
112 | c = f->nknum++; | 112 | c = f->nknum++; |
113 | f->knum[c] = r; | 113 | f->knum[c] = r; |
114 | return c; | 114 | return c; |
@@ -423,10 +423,13 @@ static void codelineinfo (FuncState *fs) { | |||
423 | Proto *f = fs->f; | 423 | Proto *f = fs->f; |
424 | LexState *ls = fs->ls; | 424 | LexState *ls = fs->ls; |
425 | if (ls->lastline > fs->lastline) { | 425 | if (ls->lastline > fs->lastline) { |
426 | luaM_growvector(fs->L, f->lineinfo, f->nlineinfo, 2, int, | 426 | if (ls->lastline > fs->lastline+1) { |
427 | "line info overflow", MAX_INT); | 427 | luaM_growvector(fs->L, f->lineinfo, f->nlineinfo, fs->sizelineinfo, int, |
428 | if (ls->lastline > fs->lastline+1) | 428 | MAX_INT, "line info overflow"); |
429 | f->lineinfo[f->nlineinfo++] = -(ls->lastline - (fs->lastline+1)); | 429 | f->lineinfo[f->nlineinfo++] = -(ls->lastline - (fs->lastline+1)); |
430 | } | ||
431 | luaM_growvector(fs->L, f->lineinfo, f->nlineinfo, fs->sizelineinfo, int, | ||
432 | MAX_INT, "line info overflow"); | ||
430 | f->lineinfo[f->nlineinfo++] = fs->pc; | 433 | f->lineinfo[f->nlineinfo++] = fs->pc; |
431 | fs->lastline = ls->lastline; | 434 | fs->lastline = ls->lastline; |
432 | } | 435 | } |
@@ -640,8 +643,8 @@ int luaK_code2 (FuncState *fs, OpCode o, int arg1, int arg2) { | |||
640 | } | 643 | } |
641 | codelineinfo(fs); | 644 | codelineinfo(fs); |
642 | /* put new instruction in code array */ | 645 | /* put new instruction in code array */ |
643 | luaM_growvector(fs->L, fs->f->code, fs->pc, 1, Instruction, | 646 | luaM_growvector(fs->L, fs->f->code, fs->pc, fs->sizecode, Instruction, |
644 | "code size overflow", MAX_INT); | 647 | MAX_INT, "code size overflow"); |
645 | fs->f->code[fs->pc] = i; | 648 | fs->f->code[fs->pc] = i; |
646 | return fs->pc++; | 649 | return fs->pc++; |
647 | } | 650 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldebug.c,v 1.50 2000/10/30 12:38:50 roberto Exp roberto $ | 2 | ** $Id: ldebug.c,v 1.51 2000/11/30 18:50:47 roberto Exp roberto $ |
3 | ** Debug Interface | 3 | ** Debug Interface |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -210,7 +210,7 @@ static const char *travtagmethods (lua_State *L, const TObject *o) { | |||
210 | int e; | 210 | int e; |
211 | for (e=0; e<TM_N; e++) { | 211 | for (e=0; e<TM_N; e++) { |
212 | int t; | 212 | int t; |
213 | for (t=0; t<=L->last_tag; t++) | 213 | for (t=0; t<L->ntag; t++) |
214 | if (clvalue(o) == luaT_gettm(L, t, e)) | 214 | if (clvalue(o) == luaT_gettm(L, t, e)) |
215 | return luaT_eventname[e]; | 215 | return luaT_eventname[e]; |
216 | } | 216 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lgc.c,v 1.72 2000/10/26 12:47:05 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 1.73 2000/11/24 17:39:56 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 | */ |
@@ -56,7 +56,7 @@ static void markstack (lua_State *L, GCState *st) { | |||
56 | 56 | ||
57 | static void marklock (lua_State *L, GCState *st) { | 57 | static void marklock (lua_State *L, GCState *st) { |
58 | int i; | 58 | int i; |
59 | for (i=0; i<L->refSize; i++) { | 59 | for (i=0; i<L->nref; i++) { |
60 | if (L->refArray[i].st == LOCK) | 60 | if (L->refArray[i].st == LOCK) |
61 | markobject(st, &L->refArray[i].o); | 61 | markobject(st, &L->refArray[i].o); |
62 | } | 62 | } |
@@ -77,7 +77,7 @@ static void marktagmethods (lua_State *L, GCState *st) { | |||
77 | int e; | 77 | int e; |
78 | for (e=0; e<TM_N; e++) { | 78 | for (e=0; e<TM_N; e++) { |
79 | int t; | 79 | int t; |
80 | for (t=0; t<=L->last_tag; t++) { | 80 | for (t=0; t<L->ntag; t++) { |
81 | Closure *cl = luaT_gettm(L, t, e); | 81 | Closure *cl = luaT_gettm(L, t, e); |
82 | if (cl) markclosure(st, cl); | 82 | if (cl) markclosure(st, cl); |
83 | } | 83 | } |
@@ -162,7 +162,7 @@ static int hasmark (const TObject *o) { | |||
162 | #define VALIDLINK(L, st,n) (NONEXT <= (st) && (st) < (n)) | 162 | #define VALIDLINK(L, st,n) (NONEXT <= (st) && (st) < (n)) |
163 | 163 | ||
164 | static void invalidaterefs (lua_State *L) { | 164 | static void invalidaterefs (lua_State *L) { |
165 | int n = L->refSize; | 165 | int n = L->nref; |
166 | int i; | 166 | int i; |
167 | for (i=0; i<n; i++) { | 167 | for (i=0; i<n; i++) { |
168 | struct Ref *r = &L->refArray[i]; | 168 | struct Ref *r = &L->refArray[i]; |
@@ -314,7 +314,7 @@ static void callgcTMudata (lua_State *L) { | |||
314 | TObject o; | 314 | TObject o; |
315 | ttype(&o) = LUA_TUSERDATA; | 315 | ttype(&o) = LUA_TUSERDATA; |
316 | L->GCthreshold = 2*L->nblocks; /* avoid GC during tag methods */ | 316 | L->GCthreshold = 2*L->nblocks; /* avoid GC during tag methods */ |
317 | for (tag=L->last_tag; tag>=0; tag--) { /* for each tag (in reverse order) */ | 317 | for (tag=L->ntag-1; tag>=0; tag--) { /* for each tag (in reverse order) */ |
318 | TString *udata; | 318 | TString *udata; |
319 | while ((udata = L->TMtable[tag].collected) != NULL) { | 319 | while ((udata = L->TMtable[tag].collected) != NULL) { |
320 | L->TMtable[tag].collected = udata->nexthash; /* remove it from list */ | 320 | L->TMtable[tag].collected = udata->nexthash; /* remove it from list */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lmem.c,v 1.39 2000/10/30 16:29:59 roberto Exp roberto $ | 2 | ** $Id: lmem.c,v 1.40 2000/11/24 17:39:56 roberto Exp roberto $ |
3 | ** Interface to Memory Manager | 3 | ** Interface to Memory Manager |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -116,15 +116,20 @@ static void *debug_realloc (void *block, size_t size) { | |||
116 | #endif | 116 | #endif |
117 | 117 | ||
118 | 118 | ||
119 | void *luaM_growaux (lua_State *L, void *block, size_t nelems, | 119 | void *luaM_growaux (lua_State *L, void *block, int *size, int size_elems, |
120 | int inc, size_t size, const char *errormsg, size_t limit) { | 120 | int limit, const char *errormsg) { |
121 | size_t newn = nelems+inc; | 121 | void *newblock; |
122 | if (nelems >= limit-inc) lua_error(L, errormsg); | 122 | int newsize = (*size)*2; |
123 | if ((newn ^ nelems) <= nelems || /* still the same power-of-2 limit? */ | 123 | if (newsize < MINPOWER2) |
124 | (nelems > 0 && newn < MINPOWER2)) /* or block already is MINPOWER2? */ | 124 | newsize = MINPOWER2; /* minimum size */ |
125 | return block; /* do not need to reallocate */ | 125 | else if (*size >= limit/2) { /* cannot double it? */ |
126 | else /* it crossed a power-of-2 boundary; grow to next power */ | 126 | if (*size < limit - MINPOWER2) /* try something smaller... */ |
127 | return luaM_realloc(L, block, luaO_power2(newn)*size); | 127 | newsize = limit; /* still have at least MINPOWER2 free places */ |
128 | else lua_error(L, errormsg); | ||
129 | } | ||
130 | newblock = luaM_realloc(L, block, (luint32)newsize*(luint32)size_elems); | ||
131 | *size = newsize; /* update only when everything else is OK */ | ||
132 | return newblock; | ||
128 | } | 133 | } |
129 | 134 | ||
130 | 135 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lmem.h,v 1.16 2000/10/30 16:29:59 roberto Exp roberto $ | 2 | ** $Id: lmem.h,v 1.17 2000/11/24 17:39:56 roberto Exp roberto $ |
3 | ** Interface to Memory Manager | 3 | ** Interface to Memory Manager |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -14,17 +14,17 @@ | |||
14 | #include "lua.h" | 14 | #include "lua.h" |
15 | 15 | ||
16 | void *luaM_realloc (lua_State *L, void *oldblock, luint32 size); | 16 | void *luaM_realloc (lua_State *L, void *oldblock, luint32 size); |
17 | void *luaM_growaux (lua_State *L, void *block, size_t nelems, | 17 | void *luaM_growaux (lua_State *L, void *block, int *size, int size_elem, |
18 | int inc, size_t size, const char *errormsg, | 18 | int limit, const char *errormsg); |
19 | size_t limit); | ||
20 | 19 | ||
21 | #define luaM_free(L, b) luaM_realloc(L, (b), 0) | 20 | #define luaM_free(L, b) luaM_realloc(L, (b), 0) |
22 | #define luaM_malloc(L, t) luaM_realloc(L, NULL, (t)) | 21 | #define luaM_malloc(L, t) luaM_realloc(L, NULL, (t)) |
23 | #define luaM_new(L, t) ((t *)luaM_malloc(L, sizeof(t))) | 22 | #define luaM_new(L, t) ((t *)luaM_malloc(L, sizeof(t))) |
24 | #define luaM_newvector(L, n,t) ((t *)luaM_malloc(L, (n)*(luint32)sizeof(t))) | 23 | #define luaM_newvector(L, n,t) ((t *)luaM_malloc(L, (n)*(luint32)sizeof(t))) |
25 | 24 | ||
26 | #define luaM_growvector(L, v,nelems,inc,t,e,l) \ | 25 | #define luaM_growvector(L,v,nelems,size,t,limit,e) \ |
27 | ((v)=(t *)luaM_growaux(L, v,nelems,inc,sizeof(t),e,l)) | 26 | if (((nelems)+1) > (size)) \ |
27 | ((v)=(t *)luaM_growaux(L,v,&(size),sizeof(t),limit,e)) | ||
28 | 28 | ||
29 | #define luaM_reallocvector(L, v,n,t) \ | 29 | #define luaM_reallocvector(L, v,n,t) \ |
30 | ((v)=(t *)luaM_realloc(L, v,(n)*(luint32)sizeof(t))) | 30 | ((v)=(t *)luaM_realloc(L, v,(n)*(luint32)sizeof(t))) |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lparser.c,v 1.118 2000/11/30 18:50:47 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 1.119 2000/12/04 18:33:40 roberto Exp roberto $ |
3 | ** LL(1) Parser and code generator for Lua | 3 | ** LL(1) Parser and code generator for Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -121,8 +121,8 @@ static int string_constant (FuncState *fs, TString *s) { | |||
121 | Proto *f = fs->f; | 121 | Proto *f = fs->f; |
122 | int c = s->u.s.constindex; | 122 | int c = s->u.s.constindex; |
123 | if (c >= f->nkstr || f->kstr[c] != s) { | 123 | if (c >= f->nkstr || f->kstr[c] != s) { |
124 | luaM_growvector(fs->L, f->kstr, f->nkstr, 1, TString *, | 124 | luaM_growvector(fs->L, f->kstr, f->nkstr, fs->sizekstr, TString *, |
125 | "constant table overflow", MAXARG_U); | 125 | MAXARG_U, "constant table overflow"); |
126 | c = f->nkstr++; | 126 | c = f->nkstr++; |
127 | f->kstr[c] = s; | 127 | f->kstr[c] = s; |
128 | s->u.s.constindex = c; /* hint for next time */ | 128 | s->u.s.constindex = c; /* hint for next time */ |
@@ -152,7 +152,8 @@ static int checkname (LexState *ls) { | |||
152 | 152 | ||
153 | static int luaI_registerlocalvar (LexState *ls, TString *varname) { | 153 | static int luaI_registerlocalvar (LexState *ls, TString *varname) { |
154 | Proto *f = ls->fs->f; | 154 | Proto *f = ls->fs->f; |
155 | luaM_growvector(ls->L, f->locvars, f->nlocvars, 1, LocVar, "", MAX_INT); | 155 | luaM_growvector(ls->L, f->locvars, f->nlocvars, ls->fs->sizelocvars, |
156 | LocVar, MAX_INT, ""); | ||
156 | f->locvars[f->nlocvars].varname = varname; | 157 | f->locvars[f->nlocvars].varname = varname; |
157 | return f->nlocvars++; | 158 | return f->nlocvars++; |
158 | } | 159 | } |
@@ -294,8 +295,8 @@ static void pushclosure (LexState *ls, FuncState *func) { | |||
294 | int i; | 295 | int i; |
295 | for (i=0; i<func->nupvalues; i++) | 296 | for (i=0; i<func->nupvalues; i++) |
296 | luaK_tostack(ls, &func->upvalues[i], 1); | 297 | luaK_tostack(ls, &func->upvalues[i], 1); |
297 | luaM_growvector(ls->L, f->kproto, f->nkproto, 1, Proto *, | 298 | luaM_growvector(ls->L, f->kproto, f->nkproto, fs->sizekproto, Proto *, |
298 | "constant table overflow", MAXARG_A); | 299 | MAXARG_A, "constant table overflow"); |
299 | f->kproto[f->nkproto++] = func->f; | 300 | f->kproto[f->nkproto++] = func->f; |
300 | luaK_code2(fs, OP_CLOSURE, f->nkproto-1, func->nupvalues); | 301 | luaK_code2(fs, OP_CLOSURE, f->nkproto-1, func->nupvalues); |
301 | } | 302 | } |
@@ -303,21 +304,27 @@ static void pushclosure (LexState *ls, FuncState *func) { | |||
303 | 304 | ||
304 | static void open_func (LexState *ls, FuncState *fs) { | 305 | static void open_func (LexState *ls, FuncState *fs) { |
305 | Proto *f = luaF_newproto(ls->L); | 306 | Proto *f = luaF_newproto(ls->L); |
307 | fs->f = f; | ||
306 | fs->prev = ls->fs; /* linked list of funcstates */ | 308 | fs->prev = ls->fs; /* linked list of funcstates */ |
307 | fs->ls = ls; | 309 | fs->ls = ls; |
308 | fs->L = ls->L; | 310 | fs->L = ls->L; |
309 | ls->fs = fs; | 311 | ls->fs = fs; |
312 | fs->pc = 0; | ||
313 | fs->lasttarget = 0; | ||
314 | fs->jlt = NO_JUMP; | ||
310 | fs->stacklevel = 0; | 315 | fs->stacklevel = 0; |
316 | fs->sizekstr = 0; | ||
317 | fs->sizekproto = 0; | ||
318 | fs->sizeknum = 0; | ||
319 | fs->sizelineinfo = 0; | ||
320 | fs->sizecode = 0; | ||
321 | fs->sizelocvars = 0; | ||
311 | fs->nactloc = 0; | 322 | fs->nactloc = 0; |
312 | fs->nupvalues = 0; | 323 | fs->nupvalues = 0; |
313 | fs->bl = NULL; | ||
314 | fs->f = f; | ||
315 | f->source = ls->source; | ||
316 | fs->pc = 0; | ||
317 | fs->lasttarget = 0; | ||
318 | fs->lastline = 0; | 324 | fs->lastline = 0; |
319 | fs->jlt = NO_JUMP; | 325 | fs->bl = NULL; |
320 | f->code = NULL; | 326 | f->code = NULL; |
327 | f->source = ls->source; | ||
321 | f->maxstacksize = 0; | 328 | f->maxstacksize = 0; |
322 | f->numparams = 0; /* default for main chunk */ | 329 | f->numparams = 0; /* default for main chunk */ |
323 | f->is_vararg = 0; /* default for main chunk */ | 330 | f->is_vararg = 0; /* default for main chunk */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lparser.h,v 1.26 2000/10/09 13:47:46 roberto Exp roberto $ | 2 | ** $Id: lparser.h,v 1.27 2000/11/30 18:50:47 roberto Exp roberto $ |
3 | ** LL(1) Parser and code generator for Lua | 3 | ** LL(1) Parser and code generator for Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -45,6 +45,12 @@ typedef struct FuncState { | |||
45 | int lasttarget; /* `pc' of last `jump target' */ | 45 | int lasttarget; /* `pc' of last `jump target' */ |
46 | int jlt; /* list of jumps to `lasttarget' */ | 46 | int jlt; /* list of jumps to `lasttarget' */ |
47 | int stacklevel; /* number of values on activation register */ | 47 | int stacklevel; /* number of values on activation register */ |
48 | int sizekstr; /* size of array `kstr' */ | ||
49 | int sizekproto; /* size of array `kproto' */ | ||
50 | int sizeknum; /* size of array `knum' */ | ||
51 | int sizelineinfo; /* size of array `lineinfo' */ | ||
52 | int sizecode; /* size of array `code' */ | ||
53 | int sizelocvars; /* size of array `locvars' */ | ||
48 | int nactloc; /* number of active local variables */ | 54 | int nactloc; /* number of active local variables */ |
49 | int nupvalues; /* number of upvalues */ | 55 | int nupvalues; /* number of upvalues */ |
50 | int lastline; /* line where last `lineinfo' was generated */ | 56 | int lastline; /* line where last `lineinfo' was generated */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstate.c,v 1.47 2000/10/26 12:47:05 roberto Exp roberto $ | 2 | ** $Id: lstate.c,v 1.48 2000/10/30 16:29:59 roberto Exp roberto $ |
3 | ** Global State | 3 | ** Global State |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -77,9 +77,11 @@ LUA_API lua_State *lua_open (int stacksize) { | |||
77 | L->rootcl = NULL; | 77 | L->rootcl = NULL; |
78 | L->roottable = NULL; | 78 | L->roottable = NULL; |
79 | L->TMtable = NULL; | 79 | L->TMtable = NULL; |
80 | L->last_tag = -1; | 80 | L->sizeTM = 0; |
81 | L->ntag = 0; | ||
81 | L->refArray = NULL; | 82 | L->refArray = NULL; |
82 | L->refSize = 0; | 83 | L->nref = 0; |
84 | L->sizeref = 0; | ||
83 | L->refFree = NONEXT; | 85 | L->refFree = NONEXT; |
84 | L->nblocks = sizeof(lua_State); | 86 | L->nblocks = sizeof(lua_State); |
85 | L->GCthreshold = MAX_INT; /* to avoid GC during pre-definitions */ | 87 | L->GCthreshold = MAX_INT; /* to avoid GC during pre-definitions */ |
@@ -107,9 +109,9 @@ LUA_API void lua_close (lua_State *L) { | |||
107 | if (L->stack) | 109 | if (L->stack) |
108 | L->nblocks -= (L->stack_last - L->stack + 1)*sizeof(TObject); | 110 | L->nblocks -= (L->stack_last - L->stack + 1)*sizeof(TObject); |
109 | luaM_free(L, L->stack); | 111 | luaM_free(L, L->stack); |
110 | L->nblocks -= (L->last_tag+1)*sizeof(struct TM); | 112 | L->nblocks -= L->ntag*sizeof(struct TM); |
111 | luaM_free(L, L->TMtable); | 113 | luaM_free(L, L->TMtable); |
112 | L->nblocks -= (L->refSize)*sizeof(struct Ref); | 114 | L->nblocks -= (L->nref)*sizeof(struct Ref); |
113 | luaM_free(L, L->refArray); | 115 | luaM_free(L, L->refArray); |
114 | L->nblocks -= (L->Mbuffsize)*sizeof(char); | 116 | L->nblocks -= (L->Mbuffsize)*sizeof(char); |
115 | luaM_free(L, L->Mbuffer); | 117 | luaM_free(L, L->Mbuffer); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstate.h,v 1.41 2000/10/05 13:00:17 roberto Exp roberto $ | 2 | ** $Id: lstate.h,v 1.42 2000/11/24 17:39:56 roberto Exp roberto $ |
3 | ** Global State | 3 | ** Global State |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -61,9 +61,11 @@ struct lua_State { | |||
61 | stringtable udt; /* hash table for udata */ | 61 | stringtable udt; /* hash table for udata */ |
62 | Hash *gt; /* table for globals */ | 62 | Hash *gt; /* table for globals */ |
63 | struct TM *TMtable; /* table for tag methods */ | 63 | struct TM *TMtable; /* table for tag methods */ |
64 | int last_tag; /* last used tag in TMtable */ | 64 | int sizeTM; /* size of TMtable */ |
65 | int ntag; /* number of tags in TMtable */ | ||
65 | struct Ref *refArray; /* locked objects */ | 66 | struct Ref *refArray; /* locked objects */ |
66 | int refSize; /* size of refArray */ | 67 | int nref; /* first unused element in refArray */ |
68 | int sizeref; /* size of refArray */ | ||
67 | int refFree; /* list of free positions in refArray */ | 69 | int refFree; /* list of free positions in refArray */ |
68 | mem_int GCthreshold; | 70 | mem_int GCthreshold; |
69 | mem_int nblocks; /* number of `bytes' currently allocated */ | 71 | mem_int nblocks; /* number of `bytes' currently allocated */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltm.c,v 1.56 2000/10/31 13:10:24 roberto Exp roberto $ | 2 | ** $Id: ltm.c,v 1.57 2000/11/30 18:50:47 roberto Exp roberto $ |
3 | ** Tag methods | 3 | ** Tag methods |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -75,26 +75,26 @@ static void init_entry (lua_State *L, int tag) { | |||
75 | 75 | ||
76 | void luaT_init (lua_State *L) { | 76 | void luaT_init (lua_State *L) { |
77 | int t; | 77 | int t; |
78 | luaM_growvector(L, L->TMtable, 0, NUM_TAGS, struct TM, "", MAX_INT); | 78 | L->sizeTM = NUM_TAGS+2; |
79 | L->TMtable = luaM_newvector(L, L->sizeTM, struct TM); | ||
79 | L->nblocks += NUM_TAGS*sizeof(struct TM); | 80 | L->nblocks += NUM_TAGS*sizeof(struct TM); |
80 | L->last_tag = NUM_TAGS-1; | 81 | L->ntag = NUM_TAGS; |
81 | for (t=0; t<=L->last_tag; t++) | 82 | for (t=0; t<L->ntag; t++) |
82 | init_entry(L, t); | 83 | init_entry(L, t); |
83 | } | 84 | } |
84 | 85 | ||
85 | 86 | ||
86 | LUA_API int lua_newtag (lua_State *L) { | 87 | LUA_API int lua_newtag (lua_State *L) { |
87 | luaM_growvector(L, L->TMtable, L->last_tag, 1, struct TM, | 88 | luaM_growvector(L, L->TMtable, L->ntag, L->sizeTM, struct TM, |
88 | "tag table overflow", MAX_INT); | 89 | MAX_INT, "tag table overflow"); |
89 | L->nblocks += sizeof(struct TM); | 90 | L->nblocks += sizeof(struct TM); |
90 | L->last_tag++; | 91 | init_entry(L, L->ntag); |
91 | init_entry(L, L->last_tag); | 92 | return L->ntag++; |
92 | return L->last_tag; | ||
93 | } | 93 | } |
94 | 94 | ||
95 | 95 | ||
96 | static void checktag (lua_State *L, int tag) { | 96 | static void checktag (lua_State *L, int tag) { |
97 | if (!(0 <= tag && tag <= L->last_tag)) | 97 | if (!(0 <= tag && tag < L->ntag)) |
98 | luaO_verror(L, "%d is not a valid tag", tag); | 98 | luaO_verror(L, "%d is not a valid tag", tag); |
99 | } | 99 | } |
100 | 100 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltm.h,v 1.17 2000/10/05 12:14:08 roberto Exp roberto $ | 2 | ** $Id: ltm.h,v 1.18 2000/10/05 13:00:17 roberto Exp roberto $ |
3 | ** Tag methods | 3 | ** Tag methods |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -45,7 +45,7 @@ struct TM { | |||
45 | #define luaT_gettmbyObj(L,o,e) (luaT_gettm((L),luaT_tag(o),(e))) | 45 | #define luaT_gettmbyObj(L,o,e) (luaT_gettm((L),luaT_tag(o),(e))) |
46 | 46 | ||
47 | 47 | ||
48 | #define validtag(t) (NUM_TAGS <= (t) && (t) <= L->last_tag) | 48 | #define validtag(t) (NUM_TAGS <= (t) && (t) < L->ntag) |
49 | 49 | ||
50 | extern const char *const luaT_eventname[]; | 50 | extern const char *const luaT_eventname[]; |
51 | 51 | ||