aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lstate.h4
-rw-r--r--lstring.c13
2 files changed, 7 insertions, 10 deletions
diff --git a/lstate.h b/lstate.h
index 2cce8e4f..65229491 100644
--- a/lstate.h
+++ b/lstate.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstate.h,v 2.153 2017/12/19 16:40:17 roberto Exp roberto $ 2** $Id: lstate.h,v 2.154 2018/02/09 15:16:06 roberto Exp roberto $
3** Global State 3** Global State
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -176,7 +176,7 @@ typedef struct global_State {
176 lua_CFunction panic; /* to be called in unprotected errors */ 176 lua_CFunction panic; /* to be called in unprotected errors */
177 struct lua_State *mainthread; 177 struct lua_State *mainthread;
178 const lua_Number *version; /* pointer to version number */ 178 const lua_Number *version; /* pointer to version number */
179 TString *nfield; /* string "n" (key in vararg tables) */ 179 TString *memerrmsg; /* message for memory-allocation errors */
180 TString *tmname[TM_N]; /* array with tag-method names */ 180 TString *tmname[TM_N]; /* array with tag-method names */
181 struct Table *mt[LUA_NUMTAGS]; /* metatables for basic types */ 181 struct Table *mt[LUA_NUMTAGS]; /* metatables for basic types */
182 TString *strcache[STRCACHE_N][STRCACHE_M]; /* cache for strings in API */ 182 TString *strcache[STRCACHE_N][STRCACHE_M]; /* cache for strings in API */
diff --git a/lstring.c b/lstring.c
index f22ac5b8..fbc3e02d 100644
--- a/lstring.c
+++ b/lstring.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstring.c,v 2.62 2017/12/18 13:00:57 roberto Exp roberto $ 2** $Id: lstring.c,v 2.63 2018/01/28 15:13:26 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*/
@@ -122,7 +122,7 @@ void luaS_clearcache (global_State *g) {
122 for (i = 0; i < STRCACHE_N; i++) 122 for (i = 0; i < STRCACHE_N; i++)
123 for (j = 0; j < STRCACHE_M; j++) { 123 for (j = 0; j < STRCACHE_M; j++) {
124 if (iswhite(g->strcache[i][j])) /* will entry be collected? */ 124 if (iswhite(g->strcache[i][j])) /* will entry be collected? */
125 g->strcache[i][j] = g->nfield; /* replace it with something fixed */ 125 g->strcache[i][j] = g->memerrmsg; /* replace it with something fixed */
126 } 126 }
127} 127}
128 128
@@ -133,19 +133,16 @@ void luaS_clearcache (global_State *g) {
133void luaS_init (lua_State *L) { 133void luaS_init (lua_State *L) {
134 global_State *g = G(L); 134 global_State *g = G(L);
135 int i, j; 135 int i, j;
136 TString *memerrmsg;
137 stringtable *tb = &G(L)->strt; 136 stringtable *tb = &G(L)->strt;
138 tb->hash = luaM_newvector(L, MINSTRTABSIZE, TString*); 137 tb->hash = luaM_newvector(L, MINSTRTABSIZE, TString*);
139 tablerehash(tb->hash, 0, MINSTRTABSIZE); /* clear array */ 138 tablerehash(tb->hash, 0, MINSTRTABSIZE); /* clear array */
140 tb->size = MINSTRTABSIZE; 139 tb->size = MINSTRTABSIZE;
141 /* pre-create memory-error message */ 140 /* pre-create memory-error message */
142 memerrmsg = luaS_newliteral(L, MEMERRMSG); 141 g->memerrmsg = luaS_newliteral(L, MEMERRMSG);
143 luaC_fix(L, obj2gco(memerrmsg)); /* it should never be collected */ 142 luaC_fix(L, obj2gco(g->memerrmsg)); /* it should never be collected */
144 g->nfield = luaS_newliteral(L, "n"); /* pre-create "n" field name */
145 luaC_fix(L, obj2gco(g->nfield)); /* it also should never be collected */
146 for (i = 0; i < STRCACHE_N; i++) /* fill cache with valid strings */ 143 for (i = 0; i < STRCACHE_N; i++) /* fill cache with valid strings */
147 for (j = 0; j < STRCACHE_M; j++) 144 for (j = 0; j < STRCACHE_M; j++)
148 g->strcache[i][j] = g->nfield; 145 g->strcache[i][j] = g->memerrmsg;
149} 146}
150 147
151 148