aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-03-20 17:36:19 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-03-20 17:36:19 -0300
commitae067dcddd837ca72c03998fd4d83b91dc872aa4 (patch)
treeabe720cbfa967b60df071609e686899975450b7a
parent5d60470508aad81eac145ab4e004fbf150130267 (diff)
downloadlua-ae067dcddd837ca72c03998fd4d83b91dc872aa4.tar.gz
lua-ae067dcddd837ca72c03998fd4d83b91dc872aa4.tar.bz2
lua-ae067dcddd837ca72c03998fd4d83b91dc872aa4.zip
BUG: lua_newtag can be called before luaI_IMtable is initialized.
-rw-r--r--fallback.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/fallback.c b/fallback.c
index 0516919c..902d8be4 100644
--- a/fallback.c
+++ b/fallback.c
@@ -3,7 +3,7 @@
3** TecCGraf - PUC-Rio 3** TecCGraf - PUC-Rio
4*/ 4*/
5 5
6char *rcs_fallback="$Id: fallback.c,v 1.29 1997/03/19 21:12:34 roberto Exp roberto $"; 6char *rcs_fallback="$Id: fallback.c,v 1.30 1997/03/20 19:20:43 roberto Exp roberto $";
7 7
8#include <stdio.h> 8#include <stdio.h>
9#include <string.h> 9#include <string.h>
@@ -174,12 +174,14 @@ static void init_entry (int tag)
174 174
175void luaI_initfallbacks (void) 175void luaI_initfallbacks (void)
176{ 176{
177 int i; 177 if (luaI_IMtable == NULL) {
178 IMtable_size = NUM_TYPES+10; 178 int i;
179 luaI_IMtable = newvector(IMtable_size, struct IM); 179 IMtable_size = NUM_TYPES+10;
180 for (i=LUA_T_NIL; i<=LUA_T_USERDATA; i++) { 180 luaI_IMtable = newvector(IMtable_size, struct IM);
181 luaI_IMtable[-i].tp = (lua_Type)i; 181 for (i=LUA_T_NIL; i<=LUA_T_USERDATA; i++) {
182 init_entry(i); 182 luaI_IMtable[-i].tp = (lua_Type)i;
183 init_entry(i);
184 }
183 } 185 }
184} 186}
185 187
@@ -187,9 +189,11 @@ int lua_newtag (char *t)
187{ 189{
188 int tp; 190 int tp;
189 --last_tag; 191 --last_tag;
190 if ((-last_tag) >= IMtable_size) 192 if ((-last_tag) >= IMtable_size) {
193 luaI_initfallbacks();
191 IMtable_size = growvector(&luaI_IMtable, IMtable_size, 194 IMtable_size = growvector(&luaI_IMtable, IMtable_size,
192 struct IM, memEM, MAX_INT); 195 struct IM, memEM, MAX_INT);
196 }
193 tp = -findstring(t, typenames); 197 tp = -findstring(t, typenames);
194 if (tp == LUA_T_ARRAY || tp == LUA_T_USERDATA) 198 if (tp == LUA_T_ARRAY || tp == LUA_T_USERDATA)
195 luaI_IMtable[-last_tag].tp = tp; 199 luaI_IMtable[-last_tag].tp = tp;