diff options
Diffstat (limited to '')
-rw-r--r-- | ldump.c | 7 | ||||
-rw-r--r-- | lfunc.c | 2 | ||||
-rw-r--r-- | lundump.c | 26 | ||||
-rw-r--r-- | testes/api.lua | 14 |
4 files changed, 36 insertions, 13 deletions
@@ -212,9 +212,10 @@ static void dumpDebug (DumpState *D, const Proto *f) { | |||
212 | dumpVector(D, f->lineinfo, n); | 212 | dumpVector(D, f->lineinfo, n); |
213 | n = (D->strip) ? 0 : f->sizeabslineinfo; | 213 | n = (D->strip) ? 0 : f->sizeabslineinfo; |
214 | dumpInt(D, n); | 214 | dumpInt(D, n); |
215 | for (i = 0; i < n; i++) { | 215 | if (n > 0) { |
216 | dumpInt(D, f->abslineinfo[i].pc); | 216 | /* 'abslineinfo' is an array of structures of int's */ |
217 | dumpInt(D, f->abslineinfo[i].line); | 217 | dumpAlign(D, sizeof(int)); |
218 | dumpVector(D, f->abslineinfo, n); | ||
218 | } | 219 | } |
219 | n = (D->strip) ? 0 : f->sizelocvars; | 220 | n = (D->strip) ? 0 : f->sizelocvars; |
220 | dumpInt(D, n); | 221 | dumpInt(D, n); |
@@ -268,10 +268,10 @@ void luaF_freeproto (lua_State *L, Proto *f) { | |||
268 | if (!(f->flag & PF_FIXED)) { | 268 | if (!(f->flag & PF_FIXED)) { |
269 | luaM_freearray(L, f->code, f->sizecode); | 269 | luaM_freearray(L, f->code, f->sizecode); |
270 | luaM_freearray(L, f->lineinfo, f->sizelineinfo); | 270 | luaM_freearray(L, f->lineinfo, f->sizelineinfo); |
271 | luaM_freearray(L, f->abslineinfo, f->sizeabslineinfo); | ||
271 | } | 272 | } |
272 | luaM_freearray(L, f->p, f->sizep); | 273 | luaM_freearray(L, f->p, f->sizep); |
273 | luaM_freearray(L, f->k, f->sizek); | 274 | luaM_freearray(L, f->k, f->sizek); |
274 | luaM_freearray(L, f->abslineinfo, f->sizeabslineinfo); | ||
275 | luaM_freearray(L, f->locvars, f->sizelocvars); | 275 | luaM_freearray(L, f->locvars, f->sizelocvars); |
276 | luaM_freearray(L, f->upvalues, f->sizeupvalues); | 276 | luaM_freearray(L, f->upvalues, f->sizeupvalues); |
277 | luaM_free(L, f); | 277 | luaM_free(L, f); |
@@ -36,7 +36,7 @@ typedef struct { | |||
36 | ZIO *Z; | 36 | ZIO *Z; |
37 | const char *name; | 37 | const char *name; |
38 | Table *h; /* list for string reuse */ | 38 | Table *h; /* list for string reuse */ |
39 | lu_mem offset; /* current position relative to beginning of dump */ | 39 | size_t offset; /* current position relative to beginning of dump */ |
40 | lua_Integer nstr; /* number of strings in the list */ | 40 | lua_Integer nstr; /* number of strings in the list */ |
41 | lu_byte fixed; /* dump is fixed in memory */ | 41 | lu_byte fixed; /* dump is fixed in memory */ |
42 | } LoadState; | 42 | } LoadState; |
@@ -73,8 +73,10 @@ static void loadAlign (LoadState *S, int align) { | |||
73 | 73 | ||
74 | #define getaddr(S,n,t) cast(t *, getaddr_(S,n,sizeof(t))) | 74 | #define getaddr(S,n,t) cast(t *, getaddr_(S,n,sizeof(t))) |
75 | 75 | ||
76 | static const void *getaddr_ (LoadState *S, int n, int sz) { | 76 | static const void *getaddr_ (LoadState *S, int n, size_t sz) { |
77 | const void *block = luaZ_getaddr(S->Z, n * sz); | 77 | size_t size = n * sz; |
78 | const void *block = luaZ_getaddr(S->Z, size); | ||
79 | S->offset += size; | ||
78 | if (block == NULL) | 80 | if (block == NULL) |
79 | error(S, "truncated fixed buffer"); | 81 | error(S, "truncated fixed buffer"); |
80 | return block; | 82 | return block; |
@@ -143,7 +145,7 @@ static void loadString (LoadState *S, Proto *p, TString **sl) { | |||
143 | TValue sv; | 145 | TValue sv; |
144 | size_t size = loadSize(S); | 146 | size_t size = loadSize(S); |
145 | if (size == 0) { /* no string? */ | 147 | if (size == 0) { /* no string? */ |
146 | *sl = NULL; | 148 | lua_assert(*sl == NULL); /* must be prefilled */ |
147 | return; | 149 | return; |
148 | } | 150 | } |
149 | else if (size == 1) { /* previously saved string? */ | 151 | else if (size == 1) { /* previously saved string? */ |
@@ -287,11 +289,17 @@ static void loadDebug (LoadState *S, Proto *f) { | |||
287 | loadVector(S, f->lineinfo, n); | 289 | loadVector(S, f->lineinfo, n); |
288 | } | 290 | } |
289 | n = loadInt(S); | 291 | n = loadInt(S); |
290 | f->abslineinfo = luaM_newvectorchecked(S->L, n, AbsLineInfo); | 292 | if (n > 0) { |
291 | f->sizeabslineinfo = n; | 293 | loadAlign(S, sizeof(int)); |
292 | for (i = 0; i < n; i++) { | 294 | if (S->fixed) { |
293 | f->abslineinfo[i].pc = loadInt(S); | 295 | f->abslineinfo = getaddr(S, n, AbsLineInfo); |
294 | f->abslineinfo[i].line = loadInt(S); | 296 | f->sizeabslineinfo = n; |
297 | } | ||
298 | else { | ||
299 | f->abslineinfo = luaM_newvectorchecked(S->L, n, AbsLineInfo); | ||
300 | f->sizeabslineinfo = n; | ||
301 | loadVector(S, f->abslineinfo, n); | ||
302 | } | ||
295 | } | 303 | } |
296 | n = loadInt(S); | 304 | n = loadInt(S); |
297 | f->locvars = luaM_newvectorchecked(S->L, n, LocVar); | 305 | f->locvars = luaM_newvectorchecked(S->L, n, LocVar); |
diff --git a/testes/api.lua b/testes/api.lua index 7d64cb22..85dadb69 100644 --- a/testes/api.lua +++ b/testes/api.lua | |||
@@ -551,6 +551,20 @@ do | |||
551 | assert(m2 > m1 and m2 - m1 < 350) | 551 | assert(m2 > m1 and m2 - m1 < 350) |
552 | X = 0; code(); assert(X == N and Y == string.rep("a", N)) | 552 | X = 0; code(); assert(X == N and Y == string.rep("a", N)) |
553 | X = nil; Y = nil | 553 | X = nil; Y = nil |
554 | |||
555 | -- testing debug info in fixed buffers | ||
556 | source = {"X = 0"} | ||
557 | for i = 2, 300 do source[i] = "X = X + 1" end | ||
558 | source[#source + 1] = "X = X + {}" -- error in last line | ||
559 | source = table.concat(source, "\n") | ||
560 | source = load(source, "name1") | ||
561 | source = string.dump(source) | ||
562 | -- load dump using fixed buffer | ||
563 | local code = T.testC([[ | ||
564 | loadstring 2 name B; | ||
565 | return 1 | ||
566 | ]], source) | ||
567 | checkerr(":301:", code) -- correct line information | ||
554 | end | 568 | end |
555 | 569 | ||
556 | 570 | ||