From 435f587ed05e2c4d542e1db9ae9e4efbb7e02305 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Fri, 4 Aug 2000 16:38:35 -0300 Subject: (much) better handling of memory alloction errors --- ltable.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'ltable.c') diff --git a/ltable.c b/ltable.c index 0e271e8c..d91ed36c 100644 --- a/ltable.c +++ b/ltable.c @@ -1,5 +1,5 @@ /* -** $Id: ltable.c,v 1.49 2000/06/28 17:03:56 roberto Exp roberto $ +** $Id: ltable.c,v 1.50 2000/06/30 14:35:17 roberto Exp roberto $ ** Lua tables (hash) ** See Copyright Notice in lua.h */ @@ -154,19 +154,22 @@ static void setnodevector (lua_State *L, Hash *t, lint32 size) { ttype(&t->node[i].key) = ttype(&t->node[i].val) = TAG_NIL; t->node[i].next = NULL; } + L->nblocks += gcsize(L, size) - gcsize(L, t->size); t->size = size; t->firstfree = &t->node[size-1]; /* first free position to be used */ - L->nblocks += gcsize(L, size); } Hash *luaH_new (lua_State *L, int size) { Hash *t = luaM_new(L, Hash); - setnodevector(L, t, luaO_power2(size)); t->htag = TagDefault; t->next = L->roottable; L->roottable = t; t->marked = 0; + t->size = 0; + L->nblocks += gcsize(L, 0); + t->node = NULL; + setnodevector(L, t, luaO_power2(size)); return t; } @@ -204,7 +207,6 @@ static void rehash (lua_State *L, Hash *t) { setnodevector(L, t, oldsize/2); else setnodevector(L, t, oldsize); - L->nblocks -= gcsize(L, oldsize); for (i=0; ival) != TAG_NIL) -- cgit v1.2.3-55-g6feb