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 /ltm.c | |
parent | 6af005ec20323defd2a5ead01e2d389462884d04 (diff) | |
download | lua-8c49e198654567f770a7d5081b886a7c35201d81.tar.gz lua-8c49e198654567f770a7d5081b886a7c35201d81.tar.bz2 lua-8c49e198654567f770a7d5081b886a7c35201d81.zip |
explicit control of size for growing vectors
Diffstat (limited to 'ltm.c')
-rw-r--r-- | ltm.c | 20 |
1 files changed, 10 insertions, 10 deletions
@@ -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 | ||