瀏覽代碼

no more 'nfield' string

Roberto Ierusalimschy 7 年之前
父節點
當前提交
c7a8cba745
共有 2 個文件被更改,包括 7 次插入10 次删除
  1. 2 2
      lstate.h
  2. 5 8
      lstring.c

+ 2 - 2
lstate.h

@@ -1,5 +1,5 @@
 /*
-** $Id: lstate.h,v 2.153 2017/12/19 16:40:17 roberto Exp roberto $
+** $Id: lstate.h,v 2.154 2018/02/09 15:16:06 roberto Exp roberto $
 ** Global State
 ** See Copyright Notice in lua.h
 */
@@ -176,7 +176,7 @@ typedef struct global_State {
   lua_CFunction panic;  /* to be called in unprotected errors */
   struct lua_State *mainthread;
   const lua_Number *version;  /* pointer to version number */
-  TString *nfield;  /* string "n" (key in vararg tables) */
+  TString *memerrmsg;  /* message for memory-allocation errors */
   TString *tmname[TM_N];  /* array with tag-method names */
   struct Table *mt[LUA_NUMTAGS];  /* metatables for basic types */
   TString *strcache[STRCACHE_N][STRCACHE_M];  /* cache for strings in API */

+ 5 - 8
lstring.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lstring.c,v 2.62 2017/12/18 13:00:57 roberto Exp roberto $
+** $Id: lstring.c,v 2.63 2018/01/28 15:13:26 roberto Exp roberto $
 ** String table (keeps all strings handled by Lua)
 ** See Copyright Notice in lua.h
 */
@@ -122,7 +122,7 @@ void luaS_clearcache (global_State *g) {
   for (i = 0; i < STRCACHE_N; i++)
     for (j = 0; j < STRCACHE_M; j++) {
     if (iswhite(g->strcache[i][j]))  /* will entry be collected? */
-      g->strcache[i][j] = g->nfield;  /* replace it with something fixed */
+      g->strcache[i][j] = g->memerrmsg;  /* replace it with something fixed */
     }
 }
 
@@ -133,19 +133,16 @@ void luaS_clearcache (global_State *g) {
 void luaS_init (lua_State *L) {
   global_State *g = G(L);
   int i, j;
-  TString *memerrmsg;
   stringtable *tb = &G(L)->strt;
   tb->hash = luaM_newvector(L, MINSTRTABSIZE, TString*);
   tablerehash(tb->hash, 0, MINSTRTABSIZE);  /* clear array */
   tb->size = MINSTRTABSIZE;
   /* pre-create memory-error message */
-  memerrmsg = luaS_newliteral(L, MEMERRMSG);
-  luaC_fix(L, obj2gco(memerrmsg));  /* it should never be collected */
-  g->nfield = luaS_newliteral(L, "n");  /* pre-create "n" field name */
-  luaC_fix(L, obj2gco(g->nfield));  /* it also should never be collected */
+  g->memerrmsg = luaS_newliteral(L, MEMERRMSG);
+  luaC_fix(L, obj2gco(g->memerrmsg));  /* it should never be collected */
   for (i = 0; i < STRCACHE_N; i++)  /* fill cache with valid strings */
     for (j = 0; j < STRCACHE_M; j++)
-      g->strcache[i][j] = g->nfield;
+      g->strcache[i][j] = g->memerrmsg;
 }