From e7af9cdf0b9fca080e8bb3463e16d60933e786f9 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 27 Dec 2023 17:42:00 -0300 Subject: Fixed buffers reuse absolute line information --- lundump.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'lundump.c') diff --git a/lundump.c b/lundump.c index f850dc4a..b33258b0 100644 --- a/lundump.c +++ b/lundump.c @@ -36,7 +36,7 @@ typedef struct { ZIO *Z; const char *name; 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 */ lu_byte fixed; /* dump is fixed in memory */ } LoadState; @@ -73,8 +73,10 @@ static void loadAlign (LoadState *S, int align) { #define getaddr(S,n,t) cast(t *, getaddr_(S,n,sizeof(t))) -static const void *getaddr_ (LoadState *S, int n, int sz) { - const void *block = luaZ_getaddr(S->Z, n * sz); +static const void *getaddr_ (LoadState *S, int n, size_t sz) { + size_t size = n * sz; + const void *block = luaZ_getaddr(S->Z, size); + S->offset += size; if (block == NULL) error(S, "truncated fixed buffer"); return block; @@ -143,7 +145,7 @@ static void loadString (LoadState *S, Proto *p, TString **sl) { TValue sv; size_t size = loadSize(S); if (size == 0) { /* no string? */ - *sl = NULL; + lua_assert(*sl == NULL); /* must be prefilled */ return; } else if (size == 1) { /* previously saved string? */ @@ -287,11 +289,17 @@ static void loadDebug (LoadState *S, Proto *f) { loadVector(S, f->lineinfo, n); } n = loadInt(S); - f->abslineinfo = luaM_newvectorchecked(S->L, n, AbsLineInfo); - f->sizeabslineinfo = n; - for (i = 0; i < n; i++) { - f->abslineinfo[i].pc = loadInt(S); - f->abslineinfo[i].line = 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->sizeabslineinfo = n; + loadVector(S, f->abslineinfo, n); + } } n = loadInt(S); f->locvars = luaM_newvectorchecked(S->L, n, LocVar); -- cgit v1.2.3-55-g6feb