Fixed buffers reuse absolute line information
This commit is contained in:
7
ldump.c
7
ldump.c
@@ -212,9 +212,10 @@ static void dumpDebug (DumpState *D, const Proto *f) {
|
|||||||
dumpVector(D, f->lineinfo, n);
|
dumpVector(D, f->lineinfo, n);
|
||||||
n = (D->strip) ? 0 : f->sizeabslineinfo;
|
n = (D->strip) ? 0 : f->sizeabslineinfo;
|
||||||
dumpInt(D, n);
|
dumpInt(D, n);
|
||||||
for (i = 0; i < n; i++) {
|
if (n > 0) {
|
||||||
dumpInt(D, f->abslineinfo[i].pc);
|
/* 'abslineinfo' is an array of structures of int's */
|
||||||
dumpInt(D, f->abslineinfo[i].line);
|
dumpAlign(D, sizeof(int));
|
||||||
|
dumpVector(D, f->abslineinfo, n);
|
||||||
}
|
}
|
||||||
n = (D->strip) ? 0 : f->sizelocvars;
|
n = (D->strip) ? 0 : f->sizelocvars;
|
||||||
dumpInt(D, n);
|
dumpInt(D, n);
|
||||||
|
|||||||
2
lfunc.c
2
lfunc.c
@@ -268,10 +268,10 @@ void luaF_freeproto (lua_State *L, Proto *f) {
|
|||||||
if (!(f->flag & PF_FIXED)) {
|
if (!(f->flag & PF_FIXED)) {
|
||||||
luaM_freearray(L, f->code, f->sizecode);
|
luaM_freearray(L, f->code, f->sizecode);
|
||||||
luaM_freearray(L, f->lineinfo, f->sizelineinfo);
|
luaM_freearray(L, f->lineinfo, f->sizelineinfo);
|
||||||
|
luaM_freearray(L, f->abslineinfo, f->sizeabslineinfo);
|
||||||
}
|
}
|
||||||
luaM_freearray(L, f->p, f->sizep);
|
luaM_freearray(L, f->p, f->sizep);
|
||||||
luaM_freearray(L, f->k, f->sizek);
|
luaM_freearray(L, f->k, f->sizek);
|
||||||
luaM_freearray(L, f->abslineinfo, f->sizeabslineinfo);
|
|
||||||
luaM_freearray(L, f->locvars, f->sizelocvars);
|
luaM_freearray(L, f->locvars, f->sizelocvars);
|
||||||
luaM_freearray(L, f->upvalues, f->sizeupvalues);
|
luaM_freearray(L, f->upvalues, f->sizeupvalues);
|
||||||
luaM_free(L, f);
|
luaM_free(L, f);
|
||||||
|
|||||||
22
lundump.c
22
lundump.c
@@ -36,7 +36,7 @@ typedef struct {
|
|||||||
ZIO *Z;
|
ZIO *Z;
|
||||||
const char *name;
|
const char *name;
|
||||||
Table *h; /* list for string reuse */
|
Table *h; /* list for string reuse */
|
||||||
lu_mem offset; /* current position relative to beginning of dump */
|
size_t offset; /* current position relative to beginning of dump */
|
||||||
lua_Integer nstr; /* number of strings in the list */
|
lua_Integer nstr; /* number of strings in the list */
|
||||||
lu_byte fixed; /* dump is fixed in memory */
|
lu_byte fixed; /* dump is fixed in memory */
|
||||||
} LoadState;
|
} LoadState;
|
||||||
@@ -73,8 +73,10 @@ static void loadAlign (LoadState *S, int align) {
|
|||||||
|
|
||||||
#define getaddr(S,n,t) cast(t *, getaddr_(S,n,sizeof(t)))
|
#define getaddr(S,n,t) cast(t *, getaddr_(S,n,sizeof(t)))
|
||||||
|
|
||||||
static const void *getaddr_ (LoadState *S, int n, int sz) {
|
static const void *getaddr_ (LoadState *S, int n, size_t sz) {
|
||||||
const void *block = luaZ_getaddr(S->Z, n * sz);
|
size_t size = n * sz;
|
||||||
|
const void *block = luaZ_getaddr(S->Z, size);
|
||||||
|
S->offset += size;
|
||||||
if (block == NULL)
|
if (block == NULL)
|
||||||
error(S, "truncated fixed buffer");
|
error(S, "truncated fixed buffer");
|
||||||
return block;
|
return block;
|
||||||
@@ -143,7 +145,7 @@ static void loadString (LoadState *S, Proto *p, TString **sl) {
|
|||||||
TValue sv;
|
TValue sv;
|
||||||
size_t size = loadSize(S);
|
size_t size = loadSize(S);
|
||||||
if (size == 0) { /* no string? */
|
if (size == 0) { /* no string? */
|
||||||
*sl = NULL;
|
lua_assert(*sl == NULL); /* must be prefilled */
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (size == 1) { /* previously saved string? */
|
else if (size == 1) { /* previously saved string? */
|
||||||
@@ -287,11 +289,17 @@ static void loadDebug (LoadState *S, Proto *f) {
|
|||||||
loadVector(S, f->lineinfo, n);
|
loadVector(S, f->lineinfo, n);
|
||||||
}
|
}
|
||||||
n = loadInt(S);
|
n = loadInt(S);
|
||||||
|
if (n > 0) {
|
||||||
|
loadAlign(S, sizeof(int));
|
||||||
|
if (S->fixed) {
|
||||||
|
f->abslineinfo = getaddr(S, n, AbsLineInfo);
|
||||||
|
f->sizeabslineinfo = n;
|
||||||
|
}
|
||||||
|
else {
|
||||||
f->abslineinfo = luaM_newvectorchecked(S->L, n, AbsLineInfo);
|
f->abslineinfo = luaM_newvectorchecked(S->L, n, AbsLineInfo);
|
||||||
f->sizeabslineinfo = n;
|
f->sizeabslineinfo = n;
|
||||||
for (i = 0; i < n; i++) {
|
loadVector(S, f->abslineinfo, n);
|
||||||
f->abslineinfo[i].pc = loadInt(S);
|
}
|
||||||
f->abslineinfo[i].line = loadInt(S);
|
|
||||||
}
|
}
|
||||||
n = loadInt(S);
|
n = loadInt(S);
|
||||||
f->locvars = luaM_newvectorchecked(S->L, n, LocVar);
|
f->locvars = luaM_newvectorchecked(S->L, n, LocVar);
|
||||||
|
|||||||
@@ -551,6 +551,20 @@ do
|
|||||||
assert(m2 > m1 and m2 - m1 < 350)
|
assert(m2 > m1 and m2 - m1 < 350)
|
||||||
X = 0; code(); assert(X == N and Y == string.rep("a", N))
|
X = 0; code(); assert(X == N and Y == string.rep("a", N))
|
||||||
X = nil; Y = nil
|
X = nil; Y = nil
|
||||||
|
|
||||||
|
-- testing debug info in fixed buffers
|
||||||
|
source = {"X = 0"}
|
||||||
|
for i = 2, 300 do source[i] = "X = X + 1" end
|
||||||
|
source[#source + 1] = "X = X + {}" -- error in last line
|
||||||
|
source = table.concat(source, "\n")
|
||||||
|
source = load(source, "name1")
|
||||||
|
source = string.dump(source)
|
||||||
|
-- load dump using fixed buffer
|
||||||
|
local code = T.testC([[
|
||||||
|
loadstring 2 name B;
|
||||||
|
return 1
|
||||||
|
]], source)
|
||||||
|
checkerr(":301:", code) -- correct line information
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user