Skip to content

Commit d3ccb34

Browse files
committed
lua: update to 5.4.8
1 parent d39df08 commit d3ccb34

File tree

11 files changed

+56
-29
lines changed

11 files changed

+56
-29
lines changed

Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
[package]
22
name = "suricata-lua-sys"
33
description = "Vendored Lua for Suricata"
4-
version = "0.1.0-alpha.9"
54
edition = "2021"
65
rust-version = "1.56.0"
76
license = "MIT"
87

8+
# For versioning we use a schema that lets us to patch releases on Lua
9+
# patch releases. For example:
10+
# 5.4.8 -> 5.4.8000
11+
# Then if we need to make a patch we can release 5.4.8001.
12+
version = "5.4.8000"
13+
914
[build-dependencies]
1015
fs_extra = "1.3.0"

lua/lapi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1343,7 +1343,7 @@ void lua_warning (lua_State *L, const char *msg, int tocont) {
13431343
LUA_API void *lua_newuserdatauv (lua_State *L, size_t size, int nuvalue) {
13441344
Udata *u;
13451345
lua_lock(L);
1346-
api_check(L, 0 <= nuvalue && nuvalue < USHRT_MAX, "invalid value");
1346+
api_check(L, 0 <= nuvalue && nuvalue < SHRT_MAX, "invalid value");
13471347
u = luaS_newudata(L, size, nuvalue);
13481348
setuvalue(L, s2v(L->top.p), u);
13491349
api_incr_top(L);

lua/lcode.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#define MAXREGS 255
3636

3737

38+
/* (note that expressions VJMP also have jumps.) */
3839
#define hasjumps(e) ((e)->t != (e)->f)
3940

4041

@@ -985,7 +986,7 @@ void luaK_exp2anyregup (FuncState *fs, expdesc *e) {
985986
** or it is a constant.
986987
*/
987988
void luaK_exp2val (FuncState *fs, expdesc *e) {
988-
if (hasjumps(e))
989+
if (e->k == VJMP || hasjumps(e))
989990
luaK_exp2anyreg(fs, e);
990991
else
991992
luaK_dischargevars(fs, e);

lua/ldebug.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
static const char *funcnamefromcall (lua_State *L, CallInfo *ci,
3838
const char **name);
3939

40+
static const char strlocal[] = "local";
41+
static const char strupval[] = "upvalue";
42+
4043

4144
static int currentpc (CallInfo *ci) {
4245
lua_assert(isLua(ci));
@@ -497,7 +500,7 @@ static const char *basicgetobjname (const Proto *p, int *ppc, int reg,
497500
int pc = *ppc;
498501
*name = luaF_getlocalname(p, reg + 1, pc);
499502
if (*name) /* is a local? */
500-
return "local";
503+
return strlocal;
501504
/* else try symbolic execution */
502505
*ppc = pc = findsetreg(p, pc, reg);
503506
if (pc != -1) { /* could find instruction? */
@@ -512,7 +515,7 @@ static const char *basicgetobjname (const Proto *p, int *ppc, int reg,
512515
}
513516
case OP_GETUPVAL: {
514517
*name = upvalname(p, GETARG_B(i));
515-
return "upvalue";
518+
return strupval;
516519
}
517520
case OP_LOADK: return kname(p, GETARG_Bx(i), name);
518521
case OP_LOADKX: return kname(p, GETARG_Ax(p->code[pc + 1]), name);
@@ -547,15 +550,21 @@ static void rkname (const Proto *p, int pc, Instruction i, const char **name) {
547550

548551
/*
549552
** Check whether table being indexed by instruction 'i' is the
550-
** environment '_ENV'
553+
** environment '_ENV'. If the table is an upvalue, get its name;
554+
** otherwise, find some "name" for the table and check whether
555+
** that name is the name of a local variable (and not, for instance,
556+
** a string). Then check that, if there is a name, it is '_ENV'.
551557
*/
552558
static const char *isEnv (const Proto *p, int pc, Instruction i, int isup) {
553559
int t = GETARG_B(i); /* table index */
554560
const char *name; /* name of indexed variable */
555561
if (isup) /* is 't' an upvalue? */
556562
name = upvalname(p, t);
557-
else /* 't' is a register */
558-
basicgetobjname(p, &pc, t, &name);
563+
else { /* 't' is a register */
564+
const char *what = basicgetobjname(p, &pc, t, &name);
565+
if (what != strlocal && what != strupval)
566+
name = NULL; /* cannot be the variable _ENV */
567+
}
559568
return (name && strcmp(name, LUA_ENV) == 0) ? "global" : "field";
560569
}
561570

@@ -701,7 +710,7 @@ static const char *getupvalname (CallInfo *ci, const TValue *o,
701710
for (i = 0; i < c->nupvalues; i++) {
702711
if (c->upvals[i]->v.p == o) {
703712
*name = upvalname(c->p, i);
704-
return "upvalue";
713+
return strupval;
705714
}
706715
}
707716
return NULL;

lua/ldo.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,6 @@ void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop) {
9494
setsvalue2s(L, oldtop, G(L)->memerrmsg); /* reuse preregistered msg. */
9595
break;
9696
}
97-
case LUA_ERRERR: {
98-
setsvalue2s(L, oldtop, luaS_newliteral(L, "error in error handling"));
99-
break;
100-
}
10197
case LUA_OK: { /* special case only for closing upvalues */
10298
setnilvalue(s2v(oldtop)); /* no error message */
10399
break;
@@ -120,6 +116,7 @@ l_noret luaD_throw (lua_State *L, int errcode) {
120116
else { /* thread has no error handler */
121117
global_State *g = G(L);
122118
errcode = luaE_resetthread(L, errcode); /* close all upvalues */
119+
L->status = errcode;
123120
if (g->mainthread->errorJmp) { /* main thread has a handler? */
124121
setobjs2s(L, g->mainthread->top.p++, L->top.p - 1); /* copy error obj. */
125122
luaD_throw(g->mainthread, errcode); /* re-throw in main thread */
@@ -198,6 +195,16 @@ static void correctstack (lua_State *L) {
198195
/* some space for error handling */
199196
#define ERRORSTACKSIZE (LUAI_MAXSTACK + 200)
200197

198+
199+
/* raise an error while running the message handler */
200+
l_noret luaD_errerr (lua_State *L) {
201+
TString *msg = luaS_newliteral(L, "error in error handling");
202+
setsvalue2s(L, L->top.p, msg);
203+
L->top.p++; /* assume EXTRA_STACK */
204+
luaD_throw(L, LUA_ERRERR);
205+
}
206+
207+
201208
/*
202209
** Reallocate the stack to a new size, correcting all pointers into it.
203210
** In ISO C, any pointer use after the pointer has been deallocated is
@@ -247,7 +254,7 @@ int luaD_growstack (lua_State *L, int n, int raiseerror) {
247254
a stack error; cannot grow further than that. */
248255
lua_assert(stacksize(L) == ERRORSTACKSIZE);
249256
if (raiseerror)
250-
luaD_throw(L, LUA_ERRERR); /* error inside message handler */
257+
luaD_errerr(L); /* error inside message handler */
251258
return 0; /* if not 'raiseerror', just signal it */
252259
}
253260
else if (n < LUAI_MAXSTACK) { /* avoids arithmetic overflows */

lua/ldo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
/* type of protected functions, to be ran by 'runprotected' */
6161
typedef void (*Pfunc) (lua_State *L, void *ud);
6262

63+
LUAI_FUNC l_noret luaD_errerr (lua_State *L);
6364
LUAI_FUNC void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop);
6465
LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name,
6566
const char *mode);

lua/lparser.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ static int new_localvar (LexState *ls, TString *name) {
198198
checklimit(fs, dyd->actvar.n + 1 - fs->firstlocal,
199199
MAXVARS, "local variables");
200200
luaM_growvector(L, dyd->actvar.arr, dyd->actvar.n + 1,
201-
dyd->actvar.size, Vardesc, USHRT_MAX, "local variables");
201+
dyd->actvar.size, Vardesc, SHRT_MAX, "local variables");
202202
var = &dyd->actvar.arr[dyd->actvar.n++];
203203
var->vd.kind = VDKREG; /* default */
204204
var->vd.name = name;
@@ -849,12 +849,11 @@ static void recfield (LexState *ls, ConsControl *cc) {
849849
FuncState *fs = ls->fs;
850850
int reg = ls->fs->freereg;
851851
expdesc tab, key, val;
852-
if (ls->t.token == TK_NAME) {
853-
checklimit(fs, cc->nh, MAX_INT, "items in a constructor");
852+
if (ls->t.token == TK_NAME)
854853
codename(ls, &key);
855-
}
856854
else /* ls->t.token == '[' */
857855
yindex(ls, &key);
856+
checklimit(fs, cc->nh, MAX_INT, "items in a constructor");
858857
cc->nh++;
859858
checknext(ls, '=');
860859
tab = *cc->t;

lua/lstate.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ void luaE_checkcstack (lua_State *L) {
166166
if (getCcalls(L) == LUAI_MAXCCALLS)
167167
luaG_runerror(L, "C stack overflow");
168168
else if (getCcalls(L) >= (LUAI_MAXCCALLS / 10 * 11))
169-
luaD_throw(L, LUA_ERRERR); /* error while handling stack error */
169+
luaD_errerr(L); /* error while handling stack error */
170170
}
171171

172172

@@ -272,7 +272,9 @@ static void close_state (lua_State *L) {
272272
luaC_freeallobjects(L); /* just collect its objects */
273273
else { /* closing a fully built state */
274274
L->ci = &L->base_ci; /* unwind CallInfo list */
275+
L->errfunc = 0; /* stack unwind can "throw away" the error function */
275276
luaD_closeprotected(L, 1, LUA_OK); /* close all upvalues */
277+
L->top.p = L->stack.p + 1; /* empty the stack to run finalizers */
276278
luaC_freeallobjects(L); /* collect all objects */
277279
luai_userstateclose(L);
278280
}
@@ -328,6 +330,7 @@ int luaE_resetthread (lua_State *L, int status) {
328330
if (status == LUA_YIELD)
329331
status = LUA_OK;
330332
L->status = LUA_OK; /* so it can run __close metamethods */
333+
L->errfunc = 0; /* stack unwind can "throw away" the error function */
331334
status = luaD_closeprotected(L, 1, status);
332335
if (status != LUA_OK) /* errors? */
333336
luaD_seterrorobj(L, status, L->stack.p + 1);

lua/lua.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -490,10 +490,8 @@ static int incomplete (lua_State *L, int status) {
490490
if (status == LUA_ERRSYNTAX) {
491491
size_t lmsg;
492492
const char *msg = lua_tolstring(L, -1, &lmsg);
493-
if (lmsg >= marklen && strcmp(msg + lmsg - marklen, EOFMARK) == 0) {
494-
lua_pop(L, 1);
493+
if (lmsg >= marklen && strcmp(msg + lmsg - marklen, EOFMARK) == 0)
495494
return 1;
496-
}
497495
}
498496
return 0; /* else... */
499497
}
@@ -508,9 +506,9 @@ static int pushline (lua_State *L, int firstline) {
508506
size_t l;
509507
const char *prmt = get_prompt(L, firstline);
510508
int readstatus = lua_readline(L, b, prmt);
511-
if (readstatus == 0)
512-
return 0; /* no input (prompt will be popped by caller) */
513509
lua_pop(L, 1); /* remove prompt */
510+
if (readstatus == 0)
511+
return 0; /* no input */
514512
l = strlen(b);
515513
if (l > 0 && b[l-1] == '\n') /* line ends with newline? */
516514
b[--l] = '\0'; /* remove it */
@@ -552,8 +550,9 @@ static int multiline (lua_State *L) {
552550
int status = luaL_loadbuffer(L, line, len, "=stdin"); /* try it */
553551
if (!incomplete(L, status) || !pushline(L, 0)) {
554552
lua_saveline(L, line); /* keep history */
555-
return status; /* cannot or should not try to add continuation line */
553+
return status; /* should not or cannot try to add continuation line */
556554
}
555+
lua_remove(L, -2); /* remove error message (from incomplete line) */
557556
lua_pushliteral(L, "\n"); /* add newline... */
558557
lua_insert(L, -2); /* ...between the two lines */
559558
lua_concat(L, 3); /* join them */

lua/lua.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818

1919
#define LUA_VERSION_MAJOR "5"
2020
#define LUA_VERSION_MINOR "4"
21-
#define LUA_VERSION_RELEASE "7"
21+
#define LUA_VERSION_RELEASE "8"
2222

2323
#define LUA_VERSION_NUM 504
24-
#define LUA_VERSION_RELEASE_NUM (LUA_VERSION_NUM * 100 + 7)
24+
#define LUA_VERSION_RELEASE_NUM (LUA_VERSION_NUM * 100 + 8)
2525

2626
#define LUA_VERSION "Lua " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR
2727
#define LUA_RELEASE LUA_VERSION "." LUA_VERSION_RELEASE
28-
#define LUA_COPYRIGHT LUA_RELEASE " Copyright (C) 1994-2024 Lua.org, PUC-Rio"
28+
#define LUA_COPYRIGHT LUA_RELEASE " Copyright (C) 1994-2025 Lua.org, PUC-Rio"
2929
#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo, W. Celes"
3030

3131

@@ -497,7 +497,7 @@ struct lua_Debug {
497497

498498

499499
/******************************************************************************
500-
* Copyright (C) 1994-2024 Lua.org, PUC-Rio.
500+
* Copyright (C) 1994-2025 Lua.org, PUC-Rio.
501501
*
502502
* Permission is hereby granted, free of charge, to any person obtaining
503503
* a copy of this software and associated documentation files (the

0 commit comments

Comments
 (0)