aboutsummaryrefslogtreecommitdiff
path: root/lstring.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2006-07-11 12:53:29 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2006-07-11 12:53:29 -0300
commit3ca9af51a4f060cf2178901a67a21f8269af3224 (patch)
tree4f1bb541280aa8b4960b16d0925eca60adb2b1a8 /lstring.c
parentc7b89dd28097296bbc14d9b47b4cea72514b2b76 (diff)
downloadlua-3ca9af51a4f060cf2178901a67a21f8269af3224.tar.gz
lua-3ca9af51a4f060cf2178901a67a21f8269af3224.tar.bz2
lua-3ca9af51a4f060cf2178901a67a21f8269af3224.zip
emergency garbage collector (core forces a GC when allocation fails)
Diffstat (limited to 'lstring.c')
-rw-r--r--lstring.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/lstring.c b/lstring.c
index 08dbe87f..dc1a780d 100644
--- a/lstring.c
+++ b/lstring.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstring.c,v 2.7 2005/02/18 12:40:02 roberto Exp roberto $ 2** $Id: lstring.c,v 2.8 2005/12/22 16:19:56 roberto Exp roberto $
3** String table (keeps all strings handled by Lua) 3** String table (keeps all strings handled by Lua)
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -50,9 +50,11 @@ void luaS_resize (lua_State *L, int newsize) {
50static TString *newlstr (lua_State *L, const char *str, size_t l, 50static TString *newlstr (lua_State *L, const char *str, size_t l,
51 unsigned int h) { 51 unsigned int h) {
52 TString *ts; 52 TString *ts;
53 stringtable *tb; 53 stringtable *tb = &G(L)->strt;
54 if (l+1 > (MAX_SIZET - sizeof(TString))/sizeof(char)) 54 if (l+1 > (MAX_SIZET - sizeof(TString))/sizeof(char))
55 luaM_toobig(L); 55 luaM_toobig(L);
56 if (tb->nuse >= cast(lu_int32, tb->size) && tb->size <= MAX_INT/2)
57 luaS_resize(L, tb->size*2); /* too crowded */
56 ts = cast(TString *, luaM_malloc(L, (l+1)*sizeof(char)+sizeof(TString))); 58 ts = cast(TString *, luaM_malloc(L, (l+1)*sizeof(char)+sizeof(TString)));
57 ts->tsv.len = l; 59 ts->tsv.len = l;
58 ts->tsv.hash = h; 60 ts->tsv.hash = h;
@@ -61,13 +63,10 @@ static TString *newlstr (lua_State *L, const char *str, size_t l,
61 ts->tsv.reserved = 0; 63 ts->tsv.reserved = 0;
62 memcpy(ts+1, str, l*sizeof(char)); 64 memcpy(ts+1, str, l*sizeof(char));
63 ((char *)(ts+1))[l] = '\0'; /* ending 0 */ 65 ((char *)(ts+1))[l] = '\0'; /* ending 0 */
64 tb = &G(L)->strt;
65 h = lmod(h, tb->size); 66 h = lmod(h, tb->size);
66 ts->tsv.next = tb->hash[h]; /* chain new entry */ 67 ts->tsv.next = tb->hash[h]; /* chain new entry */
67 tb->hash[h] = obj2gco(ts); 68 tb->hash[h] = obj2gco(ts);
68 tb->nuse++; 69 tb->nuse++;
69 if (tb->nuse > cast(lu_int32, tb->size) && tb->size <= MAX_INT/2)
70 luaS_resize(L, tb->size*2); /* too crowded */
71 return ts; 70 return ts;
72} 71}
73 72