From 3ca9af51a4f060cf2178901a67a21f8269af3224 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 11 Jul 2006 12:53:29 -0300 Subject: emergency garbage collector (core forces a GC when allocation fails) --- lstring.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'lstring.c') diff --git a/lstring.c b/lstring.c index 08dbe87f..dc1a780d 100644 --- a/lstring.c +++ b/lstring.c @@ -1,5 +1,5 @@ /* -** $Id: lstring.c,v 2.7 2005/02/18 12:40:02 roberto Exp roberto $ +** $Id: lstring.c,v 2.8 2005/12/22 16:19:56 roberto Exp roberto $ ** String table (keeps all strings handled by Lua) ** See Copyright Notice in lua.h */ @@ -50,9 +50,11 @@ void luaS_resize (lua_State *L, int newsize) { static TString *newlstr (lua_State *L, const char *str, size_t l, unsigned int h) { TString *ts; - stringtable *tb; + stringtable *tb = &G(L)->strt; if (l+1 > (MAX_SIZET - sizeof(TString))/sizeof(char)) luaM_toobig(L); + if (tb->nuse >= cast(lu_int32, tb->size) && tb->size <= MAX_INT/2) + luaS_resize(L, tb->size*2); /* too crowded */ ts = cast(TString *, luaM_malloc(L, (l+1)*sizeof(char)+sizeof(TString))); ts->tsv.len = l; ts->tsv.hash = h; @@ -61,13 +63,10 @@ static TString *newlstr (lua_State *L, const char *str, size_t l, ts->tsv.reserved = 0; memcpy(ts+1, str, l*sizeof(char)); ((char *)(ts+1))[l] = '\0'; /* ending 0 */ - tb = &G(L)->strt; h = lmod(h, tb->size); ts->tsv.next = tb->hash[h]; /* chain new entry */ tb->hash[h] = obj2gco(ts); tb->nuse++; - if (tb->nuse > cast(lu_int32, tb->size) && tb->size <= MAX_INT/2) - luaS_resize(L, tb->size*2); /* too crowded */ return ts; } -- cgit v1.2.3-55-g6feb