Skip to content

Commit

Permalink
Merge branch 'declname' into auditlog
Browse files Browse the repository at this point in the history
  • Loading branch information
lukego committed May 9, 2018
2 parents c8b1388 + 96e00a6 commit 0a588b4
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 34 deletions.
17 changes: 8 additions & 9 deletions src/lj_bcread.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ static uint32_t bcread_uleb128_33(LexState *ls)
static void bcread_dbg(LexState *ls, GCproto *pt, MSize sizedbg)
{
uint32_t *lineinfo = (uint32_t*)proto_lineinfo(pt);
bcread_block(ls, (void*)proto_declname(pt), sizedbg);
bcread_block(ls, (void*)lineinfo, sizedbg);
/* Swap lineinfo if the endianess differs. */
if (bcread_swap(ls)) {
int i;
Expand Down Expand Up @@ -299,9 +299,9 @@ GCproto *lj_bcread_proto(LexState *ls)
{
GCproto *pt;
MSize framesize, numparams, flags, sizeuv, sizekgc, sizekn, sizebc, sizept;
MSize ofsk, ofsuv, ofsdbg;
MSize ofsk, ofsuv, ofsdbg, ofsdeclname = 0;
MSize sizedbg = 0;
BCLine firstline = 0, numline = 0, ndeclname = 0;
BCLine firstline = 0, numline = 0;

/* Read prototype header. */
flags = bcread_byte(ls);
Expand All @@ -314,9 +314,9 @@ GCproto *lj_bcread_proto(LexState *ls)
if (!(bcread_flags(ls) & BCDUMP_F_STRIP)) {
sizedbg = bcread_uleb128(ls);
if (sizedbg) {
ndeclname = bcread_uleb128(ls);
firstline = bcread_uleb128(ls);
numline = bcread_uleb128(ls);
ofsdeclname = bcread_uleb128(ls);
}
}

Expand Down Expand Up @@ -362,17 +362,16 @@ GCproto *lj_bcread_proto(LexState *ls)
pt->numline = numline;
if (sizedbg) {
MSize sizeli = (sizebc-1) * sizeof(BCLine);
setmref(pt->declname, (char *)pt + ofsdbg);
setmref(pt->lineinfo, (char *)pt + ofsdbg + ndeclname);
setmref(pt->uvinfo, (char *)pt + ofsdbg + ndeclname + sizeli);
setmref(pt->lineinfo, (char *)pt + ofsdbg);
setmref(pt->uvinfo, (char *)pt + ofsdbg + sizeli);
setmref(pt->declname, (char *)pt + ofsdbg + ofsdeclname);
bcread_dbg(ls, pt, sizedbg);
setmref(pt->varinfo, bcread_varinfo(pt));
lua_assert(strlen(pt->declname)+1 == ndeclname);
} else {
setmref(pt->declname, NULL);
setmref(pt->lineinfo, NULL);
setmref(pt->uvinfo, NULL);
setmref(pt->varinfo, NULL);
setmref(pt->declname, NULL);
}
lj_auditlog_new_prototype(pt);
return pt;
Expand Down
13 changes: 7 additions & 6 deletions src/lj_bcwrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,8 @@ static char *bcwrite_bytecode(BCWriteCtx *ctx, char *p, GCproto *pt)
/* Write prototype. */
static void bcwrite_proto(BCWriteCtx *ctx, GCproto *pt)
{
MSize sizedbg = 0;
MSize sizedbg = 0, ofsdeclname = 0;
char *p;
const char *declname = pt->declname ? proto_declname(pt) : "";

/* Recursively write children of prototype. */
if ((pt->flags & PROTO_CHILD)) {
Expand All @@ -239,13 +238,15 @@ static void bcwrite_proto(BCWriteCtx *ctx, GCproto *pt)
p = lj_strfmt_wuleb128(p, pt->sizekn);
p = lj_strfmt_wuleb128(p, pt->sizebc-1);
if (!ctx->strip) {
if (proto_lineinfo(pt))
sizedbg = pt->sizept - (MSize)((char *)proto_declname(pt) - (char *)pt);
if (proto_lineinfo(pt)) {
sizedbg = pt->sizept - (MSize)((char *)proto_lineinfo(pt) - (char *)pt);
ofsdeclname = (MSize)((char*)proto_declname(pt) - (char *)proto_lineinfo(pt));
}
p = lj_strfmt_wuleb128(p, sizedbg);
if (sizedbg) {
p = lj_strfmt_wuleb128(p, strlen(declname)+1);
p = lj_strfmt_wuleb128(p, pt->firstline);
p = lj_strfmt_wuleb128(p, pt->numline);
p = lj_strfmt_wuleb128(p, ofsdeclname);
}
}

Expand All @@ -261,7 +262,7 @@ static void bcwrite_proto(BCWriteCtx *ctx, GCproto *pt)
/* Write debug info, if not stripped. */
if (sizedbg) {
p = lj_buf_more(&ctx->sb, sizedbg);
p = lj_buf_wmem(p, declname, sizedbg);
p = lj_buf_wmem(p, proto_lineinfo(pt), sizedbg);
setsbufP(&ctx->sb, p);
}

Expand Down
4 changes: 2 additions & 2 deletions src/lj_obj.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,10 @@ typedef struct GCproto {
GCRef chunkname; /* Name of the chunk this function was defined in. */
BCLine firstline; /* First line of the function definition. */
BCLine numline; /* Number of lines for the function definition. */
MRef declname; /* Declared name of function (null-terminated). */
MRef lineinfo; /* Map from bytecode ins. to source line. */
MRef uvinfo; /* Upvalue names. */
MRef varinfo; /* Names and compressed extents of local variables. */
MRef declname; /* Declared name of function (null-terminated). */
} GCproto;

/* Flags for prototype. */
Expand Down Expand Up @@ -345,10 +345,10 @@ typedef struct GCproto {

#define proto_chunkname(pt) (strref((pt)->chunkname))
#define proto_chunknamestr(pt) (strdata(proto_chunkname((pt))))
#define proto_declname(pt) (mref((pt)->declname, const char))
#define proto_lineinfo(pt) (mref((pt)->lineinfo, const uint32_t))
#define proto_uvinfo(pt) (mref((pt)->uvinfo, const uint8_t))
#define proto_varinfo(pt) (mref((pt)->varinfo, const uint8_t))
#define proto_declname(pt) (mref((pt)->declname, const char))

/* -- Upvalue object ------------------------------------------------------ */

Expand Down
34 changes: 17 additions & 17 deletions src/lj_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -1367,20 +1367,13 @@ static void fs_fixup_line(FuncState *fs, GCproto *pt,
}

/* Prepare variable info for prototype. */
static size_t fs_prep_var(LexState *ls, FuncState *fs, size_t *ofsvar, const char *declname)
static size_t fs_prep_var(LexState *ls, FuncState *fs, size_t *ofsvar,
size_t *ofsdeclname, const char *declname)
{
VarInfo *vs =ls->vstack, *ve;
MSize i, n;
BCPos lastpc;
lj_buf_reset(&ls->sb); /* Copy to temp. string buffer. */
/* Store function declaration name. */
{
char *p;
int len = strlen(declname) + 1;
p = lj_buf_more(&ls->sb, len);
p = lj_buf_wmem(p, declname, len);
setsbufP(&ls->sb, p);
}
/* Store upvalue names. */
for (i = 0, n = fs->nuv; i < n; i++) {
GCstr *s = strref(vs[fs->uvmap[i]].name);
Expand Down Expand Up @@ -1413,16 +1406,24 @@ static size_t fs_prep_var(LexState *ls, FuncState *fs, size_t *ofsvar, const cha
}
}
lj_buf_putb(&ls->sb, '\0'); /* Terminator for varinfo. */
/* Store function declaration name. */
*ofsdeclname = sbuflen(&ls->sb);
{
char *p;
int len = strlen(declname) + 1;
p = lj_buf_more(&ls->sb, len);
p = lj_buf_wmem(p, declname, len);
setsbufP(&ls->sb, p);
}
return sbuflen(&ls->sb);
}

/* Fixup variable info for prototype. */
static void fs_fixup_var(LexState *ls, GCproto *pt, uint8_t *p, size_t ofsvar)
static void fs_fixup_var(LexState *ls, GCproto *pt, uint8_t *p, size_t ofsvar, size_t ofsdeclname)
{
int ndeclname = strlen((char*)p)+1;
setmref(pt->declname, p);
setmref(pt->uvinfo, p + ndeclname);
setmref(pt->uvinfo, p);
setmref(pt->varinfo, (char *)p + ofsvar);
setmref(pt->declname, (char*)p + ofsdeclname);
memcpy(p, sbufB(&ls->sb), sbuflen(&ls->sb)); /* Copy from temp. buffer. */
}

Expand Down Expand Up @@ -1482,7 +1483,7 @@ static GCproto *fs_finish(LexState *ls, BCLine line, char *declname)
lua_State *L = ls->L;
FuncState *fs = ls->fs;
BCLine numline = line - fs->linedefined;
size_t sizept, ofsk, ofsuv, ofsli, ofsdbg, ofsvar;
size_t sizept, ofsk, ofsuv, ofsli, ofsdbg, ofsvar, ofsdeclname;
GCproto *pt;

/* Apply final fixups. */
Expand All @@ -1494,7 +1495,7 @@ static GCproto *fs_finish(LexState *ls, BCLine line, char *declname)
ofsk = sizept; sizept += fs->nkn*sizeof(TValue);
ofsuv = sizept; sizept += ((fs->nuv+1)&~1)*2;
ofsli = sizept; sizept += fs_prep_line(fs, numline);
ofsdbg = sizept; sizept += fs_prep_var(ls, fs, &ofsvar, declname);
ofsdbg = sizept; sizept += fs_prep_var(ls, fs, &ofsvar, &ofsdeclname, declname);

/* Allocate prototype and initialize its fields. */
pt = (GCproto *)lj_mem_newgco(L, (MSize)sizept);
Expand All @@ -1512,7 +1513,7 @@ static GCproto *fs_finish(LexState *ls, BCLine line, char *declname)
fs_fixup_k(fs, pt, (void *)((char *)pt + ofsk));
fs_fixup_uv1(fs, pt, (uint16_t *)((char *)pt + ofsuv));
fs_fixup_line(fs, pt, (void *)((char *)pt + ofsli), numline);
fs_fixup_var(ls, pt, (uint8_t *)((char *)pt + ofsdbg), ofsvar);
fs_fixup_var(ls, pt, (uint8_t *)((char *)pt + ofsdbg), ofsvar, ofsdeclname);

L->top--; /* Pop table of constants. */
ls->vtop = fs->vbase; /* Reset variable stack. */
Expand Down Expand Up @@ -2208,7 +2209,6 @@ static void parse_func(LexState *ls, BCLine line)
ExpDesc v, b;
int needself = 0;
char log[128];
log[0] = 'c';
memset(log, 0, sizeof(log));
lj_lex_log(ls, log, sizeof(log)-1);
lj_lex_next(ls); /* Skip 'function'. */
Expand Down

0 comments on commit 0a588b4

Please sign in to comment.