allows different 'source' for each prototype, but inherits it from

parent when they are equal (only possible case for chunks created
by the parser)
This commit is contained in:
Roberto Ierusalimschy 2014-06-18 15:35:43 -03:00
parent 04da0a40c0
commit 7021cc9bc8
2 changed files with 34 additions and 21 deletions

27
ldump.c
View File

@ -1,5 +1,5 @@
/* /*
** $Id: ldump.c,v 2.30 2014/06/18 13:21:12 roberto Exp roberto $ ** $Id: ldump.c,v 2.31 2014/06/18 13:54:31 roberto Exp roberto $
** save precompiled Lua chunks ** save precompiled Lua chunks
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -89,7 +89,7 @@ static void DumpCode (const Proto *f, DumpState *D) {
} }
static void DumpFunction(const Proto *f, DumpState *D); static void DumpFunction(const Proto *f, TString *psource, DumpState *D);
static void DumpConstants (const Proto *f, DumpState *D) { static void DumpConstants (const Proto *f, DumpState *D) {
int i; int i;
@ -118,12 +118,15 @@ static void DumpConstants (const Proto *f, DumpState *D) {
lua_assert(0); lua_assert(0);
} }
} }
n = f->sizep; }
static void DumpProtos (const Proto *f, DumpState *D) {
int i;
int n = f->sizep;
DumpInt(n, D); DumpInt(n, D);
for (i = 0; i < n; i++) { for (i = 0; i < n; i++)
lua_assert(f->source == f->p[i]->source); /* same source for all protos */ DumpFunction(f->p[i], f->source, D);
DumpFunction(f->p[i], D);
}
} }
@ -156,7 +159,11 @@ static void DumpDebug (const Proto *f, DumpState *D) {
} }
static void DumpFunction (const Proto *f, DumpState *D) { static void DumpFunction (const Proto *f, TString *psource, DumpState *D) {
if (D->strip || f->source == psource)
DumpString(NULL, D); /* no debug info or same source as its parent */
else
DumpString(f->source, D);
DumpInt(f->linedefined, D); DumpInt(f->linedefined, D);
DumpInt(f->lastlinedefined, D); DumpInt(f->lastlinedefined, D);
DumpByte(f->numparams, D); DumpByte(f->numparams, D);
@ -165,6 +172,7 @@ static void DumpFunction (const Proto *f, DumpState *D) {
DumpCode(f, D); DumpCode(f, D);
DumpConstants(f, D); DumpConstants(f, D);
DumpUpvalues(f, D); DumpUpvalues(f, D);
DumpProtos(f, D);
DumpDebug(f, D); DumpDebug(f, D);
} }
@ -197,8 +205,7 @@ int luaU_dump(lua_State *L, const Proto *f, lua_Writer w, void *data,
D.status = 0; D.status = 0;
DumpHeader(&D); DumpHeader(&D);
DumpByte(f->sizeupvalues, &D); DumpByte(f->sizeupvalues, &D);
DumpString((D.strip) ? NULL : f->source, &D); DumpFunction(f, NULL, &D);
DumpFunction(f, &D);
return D.status; return D.status;
} }

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lundump.c,v 2.37 2014/04/29 18:14:16 roberto Exp roberto $ ** $Id: lundump.c,v 2.38 2014/06/18 13:19:17 roberto Exp roberto $
** load precompiled Lua chunks ** load precompiled Lua chunks
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -31,7 +31,6 @@ typedef struct {
ZIO *Z; ZIO *Z;
Mbuffer *b; Mbuffer *b;
const char *name; const char *name;
TString *source; /* source (the same for all prototypes) */
} LoadState; } LoadState;
@ -106,12 +105,12 @@ static void LoadCode (LoadState *S, Proto *f) {
} }
static void LoadFunction(LoadState *S, Proto *f); static void LoadFunction(LoadState *S, Proto *f, TString *psource);
static void LoadConstants (LoadState *S, Proto *f) { static void LoadConstants (LoadState *S, Proto *f) {
int i, n; int i;
n = LoadInt(S); int n = LoadInt(S);
f->k = luaM_newvector(S->L, n, TValue); f->k = luaM_newvector(S->L, n, TValue);
f->sizek = n; f->sizek = n;
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
@ -140,14 +139,19 @@ static void LoadConstants (LoadState *S, Proto *f) {
lua_assert(0); lua_assert(0);
} }
} }
n = LoadInt(S); }
static void LoadProtos (LoadState *S, Proto *f) {
int i;
int n = LoadInt(S);
f->p = luaM_newvector(S->L, n, Proto *); f->p = luaM_newvector(S->L, n, Proto *);
f->sizep = n; f->sizep = n;
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
f->p[i] = NULL; f->p[i] = NULL;
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
f->p[i] = luaF_newproto(S->L); f->p[i] = luaF_newproto(S->L);
LoadFunction(S, f->p[i]); LoadFunction(S, f->p[i], f->source);
} }
} }
@ -168,7 +172,6 @@ static void LoadUpvalues (LoadState *S, Proto *f) {
static void LoadDebug (LoadState *S, Proto *f) { static void LoadDebug (LoadState *S, Proto *f) {
int i, n; int i, n;
f->source = S->source;
n = LoadInt(S); n = LoadInt(S);
f->lineinfo = luaM_newvector(S->L, n, int); f->lineinfo = luaM_newvector(S->L, n, int);
f->sizelineinfo = n; f->sizelineinfo = n;
@ -189,7 +192,10 @@ static void LoadDebug (LoadState *S, Proto *f) {
} }
static void LoadFunction (LoadState *S, Proto *f) { static void LoadFunction (LoadState *S, Proto *f, TString *psource) {
f->source = LoadString(S);
if (f->source == NULL) /* no source in dump? */
f->source = psource; /* reuse parent's source */
f->linedefined = LoadInt(S); f->linedefined = LoadInt(S);
f->lastlinedefined = LoadInt(S); f->lastlinedefined = LoadInt(S);
f->numparams = LoadByte(S); f->numparams = LoadByte(S);
@ -198,6 +204,7 @@ static void LoadFunction (LoadState *S, Proto *f) {
LoadCode(S, f); LoadCode(S, f);
LoadConstants(S, f); LoadConstants(S, f);
LoadUpvalues(S, f); LoadUpvalues(S, f);
LoadProtos(S, f);
LoadDebug(S, f); LoadDebug(S, f);
} }
@ -259,8 +266,7 @@ Closure *luaU_undump(lua_State *L, ZIO *Z, Mbuffer *buff,
setclLvalue(L, L->top, cl); setclLvalue(L, L->top, cl);
incr_top(L); incr_top(L);
cl->l.p = luaF_newproto(L); cl->l.p = luaF_newproto(L);
S.source = cl->l.p->source = LoadString(&S); /* read source */ LoadFunction(&S, cl->l.p, NULL);
LoadFunction(&S, cl->l.p);
lua_assert(cl->l.nupvalues == cl->l.p->sizeupvalues); lua_assert(cl->l.nupvalues == cl->l.p->sizeupvalues);
luai_verifycode(L, buff, cl->l.p); luai_verifycode(L, buff, cl->l.p);
return cl; return cl;