Преглед на файлове

store number of upvalues of main function in front of the dump,
so that undump can create initial closure before reading its prototype

Roberto Ierusalimschy преди 11 години
родител
ревизия
de84b3fecb
променени са 2 файла, в които са добавени 5 реда и са изтрити 10 реда
  1. 2 1
      ldump.c
  2. 3 9
      lundump.c

+ 2 - 1
ldump.c

@@ -1,5 +1,5 @@
 /*
-** $Id: ldump.c,v 2.19 2013/04/26 18:48:35 roberto Exp roberto $
+** $Id: ldump.c,v 2.20 2014/02/27 16:56:20 roberto Exp roberto $
 ** save precompiled Lua chunks
 ** See Copyright Notice in lua.h
 */
@@ -184,6 +184,7 @@ int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip
  D.strip=strip;
  D.status=0;
  DumpHeader(&D);
+ DumpChar(f->sizeupvalues,&D);
  DumpFunction(f,&D);
  return D.status;
 }

+ 3 - 9
lundump.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lundump.c,v 2.25 2014/02/13 12:11:34 roberto Exp roberto $
+** $Id: lundump.c,v 2.26 2014/02/27 16:56:20 roberto Exp roberto $
 ** load precompiled Lua chunks
 ** See Copyright Notice in lua.h
 */
@@ -238,17 +238,11 @@ Closure* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name)
  S.Z=Z;
  S.b=buff;
  checkHeader(&S);
- cl=luaF_newLclosure(L,1);
+ cl=luaF_newLclosure(L,LoadByte(&S));
  setclLvalue(L,L->top,cl); incr_top(L);
  cl->l.p=luaF_newproto(L);
  LoadFunction(&S,cl->l.p);
- if (cl->l.p->sizeupvalues != 1)
- {
-  Proto* p=cl->l.p;
-  cl=luaF_newLclosure(L,cl->l.p->sizeupvalues);
-  cl->l.p=p;
-  setclLvalue(L,L->top-1,cl);
- }
+ lua_assert(cl->l.nupvalues==cl->l.p->sizeupvalues);
  luai_verifycode(L,buff,cl->l.p);
  return cl;
 }