Forráskód Böngészése

parser/scanner keep GC running

Roberto Ierusalimschy 15 éve
szülő
commit
35fa276099
3 módosított fájl, 16 hozzáadás és 13 törlés
  1. 1 2
      ldo.c
  2. 4 2
      llex.c
  3. 11 9
      lparser.c

+ 1 - 2
ldo.c

@@ -1,5 +1,5 @@
 /*
-** $Id: ldo.c,v 2.69 2009/10/11 20:02:19 roberto Exp roberto $
+** $Id: ldo.c,v 2.70 2009/10/23 19:12:19 roberto Exp roberto $
 ** Stack and Call structure of Lua
 ** See Copyright Notice in lua.h
 */
@@ -573,7 +573,6 @@ static void f_parser (lua_State *L, void *ud) {
   Closure *cl;
   struct SParser *p = cast(struct SParser *, ud);
   int c = luaZ_lookahead(p->z);
-  luaC_checkGC(L);
   tf = (c == LUA_SIGNATURE[0])
            ? luaU_undump(L, p->z, &p->buff, p->name)
            : luaY_parser(L, p->z, &p->buff, &p->varl, p->name);

+ 4 - 2
llex.c

@@ -1,5 +1,5 @@
 /*
-** $Id: llex.c,v 2.32 2009/03/11 13:27:32 roberto Exp roberto $
+** $Id: llex.c,v 2.33 2009/05/18 17:28:04 roberto Exp roberto $
 ** Lexical Analyzer
 ** See Copyright Notice in lua.h
 */
@@ -123,8 +123,10 @@ TString *luaX_newstring (LexState *ls, const char *str, size_t l) {
   TString *ts = luaS_newlstr(L, str, l);
   setsvalue2s(L, L->top++, ts);  /* anchor string */
   o = luaH_setstr(L, ls->fs->h, ts);
-  if (ttisnil(o))
+  if (ttisnil(o)) {
     setbvalue(o, 1);  /* make sure `str' will not be collected */
+    luaC_checkGC(L);
+  }
   L->top--;
   return ts;
 }

+ 11 - 9
lparser.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lparser.c,v 2.70 2009/10/13 19:35:42 roberto Exp roberto $
+** $Id: lparser.c,v 2.71 2009/10/14 16:43:11 roberto Exp roberto $
 ** Lua Parser
 ** See Copyright Notice in lua.h
 */
@@ -370,10 +370,6 @@ static void open_func (LexState *ls, FuncState *fs) {
   fs->firstlocal = ls->varl->nactvar;
   fs->envreg = NO_REG;
   fs->bl = NULL;
-  fs->h = luaH_new(L);
-  /* anchor table of constants (to avoid being collected) */
-  sethvalue2s(L, L->top, fs->h);
-  incr_top(L);
   f = luaF_newproto(L);
   fs->f = f;
   f->source = ls->source;
@@ -381,6 +377,10 @@ static void open_func (LexState *ls, FuncState *fs) {
   /* anchor prototype (to avoid being collected) */
   setptvalue2s(L, L->top, f);
   incr_top(L);
+  fs->h = luaH_new(L);
+  /* anchor table of constants (to avoid being collected) */
+  sethvalue2s(L, L->top, fs->h);
+  incr_top(L);
 }
 
 
@@ -404,9 +404,11 @@ static void close_func (LexState *ls) {
   f->sizeupvalues = fs->nups;
   lua_assert(fs->bl == NULL);
   ls->fs = fs->prev;
-  L->top -= 2;  /* remove table and prototype from the stack */
   /* last token read was anchored in defunct function; must reanchor it */
   anchor_token(ls);
+  L->top--;  /* pop table of constants */
+  luaC_checkGC(L);
+  L->top--;  /* pop prototype (after possible collection) */
 }
 
 
@@ -415,18 +417,18 @@ Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, Varlist *varl,
   struct LexState lexstate;
   struct FuncState funcstate;
   TString *tname = luaS_new(L, name);
-  setsvalue2s(L, L->top, tname);  /* protect name */
+  setsvalue2s(L, L->top, tname);  /* push name to protect it */
   incr_top(L);
   lexstate.buff = buff;
   lexstate.varl = varl;
   luaX_setinput(L, &lexstate, z, tname);
   open_func(&lexstate, &funcstate);
-  funcstate.f->is_vararg = 1;  /* main func. is always vararg */
+  funcstate.f->is_vararg = 1;  /* main function is always vararg */
   luaX_next(&lexstate);  /* read first token */
   chunk(&lexstate);
   check(&lexstate, TK_EOS);
   close_func(&lexstate);
-  L->top--;
+  L->top--;  /* pop name */
   lua_assert(funcstate.prev == NULL);
   lua_assert(funcstate.nups == 0);
   lua_assert(lexstate.fs == NULL);