diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-06-18 15:35:43 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-06-18 15:35:43 -0300 |
commit | 7021cc9bc8c216e941c5e5a49b34d58672b3f4c2 (patch) | |
tree | ec301c1861465cb214a0c36f95ef8170115385fb | |
parent | 04da0a40c0a541c32140ac952823a9d768cfaf8d (diff) | |
download | lua-7021cc9bc8c216e941c5e5a49b34d58672b3f4c2.tar.gz lua-7021cc9bc8c216e941c5e5a49b34d58672b3f4c2.tar.bz2 lua-7021cc9bc8c216e941c5e5a49b34d58672b3f4c2.zip |
allows different 'source' for each prototype, but inherits it from
parent when they are equal (only possible case for chunks created
by the parser)
-rw-r--r-- | ldump.c | 27 | ||||
-rw-r--r-- | lundump.c | 28 |
2 files changed, 34 insertions, 21 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldump.c,v 2.30 2014/06/18 13:21:12 roberto Exp roberto $ | 2 | ** $Id: ldump.c,v 2.31 2014/06/18 13:54:31 roberto Exp roberto $ |
3 | ** save precompiled Lua chunks | 3 | ** save precompiled Lua chunks |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -89,7 +89,7 @@ static void DumpCode (const Proto *f, DumpState *D) { | |||
89 | } | 89 | } |
90 | 90 | ||
91 | 91 | ||
92 | static void DumpFunction(const Proto *f, DumpState *D); | 92 | static void DumpFunction(const Proto *f, TString *psource, DumpState *D); |
93 | 93 | ||
94 | static void DumpConstants (const Proto *f, DumpState *D) { | 94 | static void DumpConstants (const Proto *f, DumpState *D) { |
95 | int i; | 95 | int i; |
@@ -118,12 +118,15 @@ static void DumpConstants (const Proto *f, DumpState *D) { | |||
118 | lua_assert(0); | 118 | lua_assert(0); |
119 | } | 119 | } |
120 | } | 120 | } |
121 | n = f->sizep; | 121 | } |
122 | |||
123 | |||
124 | static void DumpProtos (const Proto *f, DumpState *D) { | ||
125 | int i; | ||
126 | int n = f->sizep; | ||
122 | DumpInt(n, D); | 127 | DumpInt(n, D); |
123 | for (i = 0; i < n; i++) { | 128 | for (i = 0; i < n; i++) |
124 | lua_assert(f->source == f->p[i]->source); /* same source for all protos */ | 129 | DumpFunction(f->p[i], f->source, D); |
125 | DumpFunction(f->p[i], D); | ||
126 | } | ||
127 | } | 130 | } |
128 | 131 | ||
129 | 132 | ||
@@ -156,7 +159,11 @@ static void DumpDebug (const Proto *f, DumpState *D) { | |||
156 | } | 159 | } |
157 | 160 | ||
158 | 161 | ||
159 | static void DumpFunction (const Proto *f, DumpState *D) { | 162 | static void DumpFunction (const Proto *f, TString *psource, DumpState *D) { |
163 | if (D->strip || f->source == psource) | ||
164 | DumpString(NULL, D); /* no debug info or same source as its parent */ | ||
165 | else | ||
166 | DumpString(f->source, D); | ||
160 | DumpInt(f->linedefined, D); | 167 | DumpInt(f->linedefined, D); |
161 | DumpInt(f->lastlinedefined, D); | 168 | DumpInt(f->lastlinedefined, D); |
162 | DumpByte(f->numparams, D); | 169 | DumpByte(f->numparams, D); |
@@ -165,6 +172,7 @@ static void DumpFunction (const Proto *f, DumpState *D) { | |||
165 | DumpCode(f, D); | 172 | DumpCode(f, D); |
166 | DumpConstants(f, D); | 173 | DumpConstants(f, D); |
167 | DumpUpvalues(f, D); | 174 | DumpUpvalues(f, D); |
175 | DumpProtos(f, D); | ||
168 | DumpDebug(f, D); | 176 | DumpDebug(f, D); |
169 | } | 177 | } |
170 | 178 | ||
@@ -197,8 +205,7 @@ int luaU_dump(lua_State *L, const Proto *f, lua_Writer w, void *data, | |||
197 | D.status = 0; | 205 | D.status = 0; |
198 | DumpHeader(&D); | 206 | DumpHeader(&D); |
199 | DumpByte(f->sizeupvalues, &D); | 207 | DumpByte(f->sizeupvalues, &D); |
200 | DumpString((D.strip) ? NULL : f->source, &D); | 208 | DumpFunction(f, NULL, &D); |
201 | DumpFunction(f, &D); | ||
202 | return D.status; | 209 | return D.status; |
203 | } | 210 | } |
204 | 211 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lundump.c,v 2.37 2014/04/29 18:14:16 roberto Exp roberto $ | 2 | ** $Id: lundump.c,v 2.38 2014/06/18 13:19:17 roberto Exp roberto $ |
3 | ** load precompiled Lua chunks | 3 | ** load precompiled Lua chunks |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -31,7 +31,6 @@ typedef struct { | |||
31 | ZIO *Z; | 31 | ZIO *Z; |
32 | Mbuffer *b; | 32 | Mbuffer *b; |
33 | const char *name; | 33 | const char *name; |
34 | TString *source; /* source (the same for all prototypes) */ | ||
35 | } LoadState; | 34 | } LoadState; |
36 | 35 | ||
37 | 36 | ||
@@ -106,12 +105,12 @@ static void LoadCode (LoadState *S, Proto *f) { | |||
106 | } | 105 | } |
107 | 106 | ||
108 | 107 | ||
109 | static void LoadFunction(LoadState *S, Proto *f); | 108 | static void LoadFunction(LoadState *S, Proto *f, TString *psource); |
110 | 109 | ||
111 | 110 | ||
112 | static void LoadConstants (LoadState *S, Proto *f) { | 111 | static void LoadConstants (LoadState *S, Proto *f) { |
113 | int i, n; | 112 | int i; |
114 | n = LoadInt(S); | 113 | int n = LoadInt(S); |
115 | f->k = luaM_newvector(S->L, n, TValue); | 114 | f->k = luaM_newvector(S->L, n, TValue); |
116 | f->sizek = n; | 115 | f->sizek = n; |
117 | for (i = 0; i < n; i++) | 116 | for (i = 0; i < n; i++) |
@@ -140,14 +139,19 @@ static void LoadConstants (LoadState *S, Proto *f) { | |||
140 | lua_assert(0); | 139 | lua_assert(0); |
141 | } | 140 | } |
142 | } | 141 | } |
143 | n = LoadInt(S); | 142 | } |
143 | |||
144 | |||
145 | static void LoadProtos (LoadState *S, Proto *f) { | ||
146 | int i; | ||
147 | int n = LoadInt(S); | ||
144 | f->p = luaM_newvector(S->L, n, Proto *); | 148 | f->p = luaM_newvector(S->L, n, Proto *); |
145 | f->sizep = n; | 149 | f->sizep = n; |
146 | for (i = 0; i < n; i++) | 150 | for (i = 0; i < n; i++) |
147 | f->p[i] = NULL; | 151 | f->p[i] = NULL; |
148 | for (i = 0; i < n; i++) { | 152 | for (i = 0; i < n; i++) { |
149 | f->p[i] = luaF_newproto(S->L); | 153 | f->p[i] = luaF_newproto(S->L); |
150 | LoadFunction(S, f->p[i]); | 154 | LoadFunction(S, f->p[i], f->source); |
151 | } | 155 | } |
152 | } | 156 | } |
153 | 157 | ||
@@ -168,7 +172,6 @@ static void LoadUpvalues (LoadState *S, Proto *f) { | |||
168 | 172 | ||
169 | static void LoadDebug (LoadState *S, Proto *f) { | 173 | static void LoadDebug (LoadState *S, Proto *f) { |
170 | int i, n; | 174 | int i, n; |
171 | f->source = S->source; | ||
172 | n = LoadInt(S); | 175 | n = LoadInt(S); |
173 | f->lineinfo = luaM_newvector(S->L, n, int); | 176 | f->lineinfo = luaM_newvector(S->L, n, int); |
174 | f->sizelineinfo = n; | 177 | f->sizelineinfo = n; |
@@ -189,7 +192,10 @@ static void LoadDebug (LoadState *S, Proto *f) { | |||
189 | } | 192 | } |
190 | 193 | ||
191 | 194 | ||
192 | static void LoadFunction (LoadState *S, Proto *f) { | 195 | static void LoadFunction (LoadState *S, Proto *f, TString *psource) { |
196 | f->source = LoadString(S); | ||
197 | if (f->source == NULL) /* no source in dump? */ | ||
198 | f->source = psource; /* reuse parent's source */ | ||
193 | f->linedefined = LoadInt(S); | 199 | f->linedefined = LoadInt(S); |
194 | f->lastlinedefined = LoadInt(S); | 200 | f->lastlinedefined = LoadInt(S); |
195 | f->numparams = LoadByte(S); | 201 | f->numparams = LoadByte(S); |
@@ -198,6 +204,7 @@ static void LoadFunction (LoadState *S, Proto *f) { | |||
198 | LoadCode(S, f); | 204 | LoadCode(S, f); |
199 | LoadConstants(S, f); | 205 | LoadConstants(S, f); |
200 | LoadUpvalues(S, f); | 206 | LoadUpvalues(S, f); |
207 | LoadProtos(S, f); | ||
201 | LoadDebug(S, f); | 208 | LoadDebug(S, f); |
202 | } | 209 | } |
203 | 210 | ||
@@ -259,8 +266,7 @@ Closure *luaU_undump(lua_State *L, ZIO *Z, Mbuffer *buff, | |||
259 | setclLvalue(L, L->top, cl); | 266 | setclLvalue(L, L->top, cl); |
260 | incr_top(L); | 267 | incr_top(L); |
261 | cl->l.p = luaF_newproto(L); | 268 | cl->l.p = luaF_newproto(L); |
262 | S.source = cl->l.p->source = LoadString(&S); /* read source */ | 269 | LoadFunction(&S, cl->l.p, NULL); |
263 | LoadFunction(&S, cl->l.p); | ||
264 | lua_assert(cl->l.nupvalues == cl->l.p->sizeupvalues); | 270 | lua_assert(cl->l.nupvalues == cl->l.p->sizeupvalues); |
265 | luai_verifycode(L, buff, cl->l.p); | 271 | luai_verifycode(L, buff, cl->l.p); |
266 | return cl; | 272 | return cl; |