Skip to content

Commit b71a8ce

Browse files
committed
update lua
1 parent 2bae990 commit b71a8ce

File tree

14 files changed

+77
-43
lines changed

14 files changed

+77
-43
lines changed

3rd/lua/lua-latest/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;

3rd/lua/lua-latest/lgc.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -553,8 +553,12 @@ static lu_mem traversetable (global_State *g, Table *h) {
553553
traverseweakvalue(g, h);
554554
else if (!weakvalue) /* strong values? */
555555
traverseephemeron(g, h, 0);
556-
else /* all weak */
557-
linkgclist(h, g->allweak); /* nothing to traverse now */
556+
else { /* all weak */
557+
if (g->gcstate == GCSpropagate)
558+
linkgclist(h, g->grayagain); /* must visit again its metatable */
559+
else
560+
linkgclist(h, g->allweak); /* must clear collected entries */
561+
}
558562
}
559563
else /* not weak */
560564
traversestrongtable(g, h);

3rd/lua/lua-latest/lparser.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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;

3rd/lua/lua-latest/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

@@ -501,7 +501,7 @@ struct lua_Debug {
501501

502502

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

3rd/lua/lua54/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);

3rd/lua/lua54/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);

3rd/lua/lua54/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;

3rd/lua/lua54/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;
@@ -123,6 +119,7 @@ l_noret luaD_throw (lua_State *L, int errcode) {
123119
else { /* thread has no error handler */
124120
global_State *g = G(L);
125121
errcode = luaE_resetthread(L, errcode); /* close all upvalues */
122+
L->status = errcode;
126123
if (g->mainthread->errorJmp) { /* main thread has a handler? */
127124
setobjs2s(L, g->mainthread->top.p++, L->top.p - 1); /* copy error obj. */
128125
luaD_throw(g->mainthread, errcode); /* re-throw in main thread */
@@ -201,6 +198,16 @@ static void correctstack (lua_State *L) {
201198
/* some space for error handling */
202199
#define ERRORSTACKSIZE (LUAI_MAXSTACK + 200)
203200

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

3rd/lua/lua54/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);

3rd/lua/lua54/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;

0 commit comments

Comments
 (0)