emergency garbage collector (core forces a GC when allocation fails)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user