Bring Lua to 5.4.6. (#1214)

This essentially re-does the work of #875 on top of master.

This is what I did to check that Cosmo's Lua extensions still worked:

```
$ build/bootstrap/make MODE=aarch64 o/aarch64/third_party/lua/lua
$ ape o/aarch64/third_party/lua/lua
>: 10
10
>: 010
8
>: 0b10
2
>: string.byte("\e")
27
>: "Hello, %s" % {"world"}
Hello, world
>: "*" * 3
***
```

`luaL_traceback2` was used to show the stack trace with parameter
values; it's used in `LuaCallWithTrace`, which is used in Redbean to run
Lua code. You should be able to see the extended stack trace by running
something like this: `redbean -e "function a(b)c()end a(2)"` (with
"params" indicating the extended stack trace):

```
stack traceback:
 [string "function a(b)c()end a(2)"]:1: in function 'a', params: b = 2;
 [string "function a(b)c()end a(2)"]:1: in main chunk
```
@pkulchenko confirmed that I get the expected result with the updated
code.

This is what I did to check that Lua itself still worked:

```
$ cd third_party/lua/test/
$ ape ../../../o/aarch64/third_party/lua/lua all.lua
```

There's one test failure, in `files.lua`:

```
***** FILE 'files.lua'*****
testing i/o
../../../o/aarch64/third_party/lua/lua: files.lua:84: assertion failed!
stack traceback:
[C]: in function 'assert'
files.lua:84: in main chunk
(...tail calls...)
all.lua:195: in main chunk
[C]: in ?
.>>> closing state <<<
```

That isn't a result of these changes; the same test is failing in
master.

The failure is here:

```lua
if not _port then   -- invalid seek
  local status, msg, code = io.stdin:seek("set", 1000)
  assert(not status and type(msg) == "string" and type(code) == "number")
end
```

The test expects a seek to offset 1,000 on stdin to fail — but it
doesn't. `status` ends up being the new offset rather than `nil`.

If I comment out that one test, the remaining tests succeed.
This commit is contained in:
Michael Lenaghan 2024-06-15 20:13:08 -04:00 committed by GitHub
parent 3a599bfbe1
commit 0dbf01bf1d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
90 changed files with 2741 additions and 1376 deletions

View file

@ -3,7 +3,7 @@
Lua
Copyright © 2004-2021 Lua.org, PUC-Rio.
Copyright © 2004-2023 Lua.org, PUC-Rio.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
@ -27,6 +27,7 @@
*/
#define ltests_c
#define LUA_CORE
#include "third_party/lua/lapi.h"
#include "third_party/lua/lauxlib.h"
#include "third_party/lua/lcode.h"
@ -55,7 +56,7 @@ __static_yoink("lua_notice");
void *l_Trick = 0;
#define obj_at(L,k) s2v(L->ci->func + (k))
#define obj_at(L,k) s2v(L->ci->func.p + (k))
static int runC (lua_State *L, lua_State *L1, const char *pc);
@ -68,7 +69,7 @@ static void setnameval (lua_State *L, const char *name, int val) {
static void pushobject (lua_State *L, const TValue *o) {
setobj2s(L, L->top, o);
setobj2s(L, L->top.p, o);
api_incr_top(L);
}
@ -430,7 +431,7 @@ static void checkLclosure (global_State *g, LClosure *cl) {
if (uv) {
checkobjrefN(g, clgc, uv);
if (!upisopen(uv))
checkvalref(g, obj2gco(uv), uv->v);
checkvalref(g, obj2gco(uv), uv->v.p);
}
}
}
@ -439,7 +440,7 @@ static void checkLclosure (global_State *g, LClosure *cl) {
static int lua_checkpc (CallInfo *ci) {
if (!isLua(ci)) return 1;
else {
StkId f = ci->func;
StkId f = ci->func.p;
Proto *p = clLvalue(s2v(f))->p;
return p->code <= ci->u.l.savedpc &&
ci->u.l.savedpc <= p->code + p->sizecode;
@ -452,19 +453,19 @@ static void checkstack (global_State *g, lua_State *L1) {
CallInfo *ci;
UpVal *uv;
assert(!isdead(g, L1));
if (L1->stack == NULL) { /* incomplete thread? */
if (L1->stack.p == NULL) { /* incomplete thread? */
assert(L1->openupval == NULL && L1->ci == NULL);
return;
}
for (uv = L1->openupval; uv != NULL; uv = uv->u.open.next)
assert(upisopen(uv)); /* must be open */
assert(L1->top <= L1->stack_last);
assert(L1->tbclist <= L1->top);
assert(L1->top.p <= L1->stack_last.p);
assert(L1->tbclist.p <= L1->top.p);
for (ci = L1->ci; ci != NULL; ci = ci->previous) {
assert(ci->top <= L1->stack_last);
assert(ci->top.p <= L1->stack_last.p);
assert(lua_checkpc(ci));
}
for (o = L1->stack; o < L1->stack_last; o++)
for (o = L1->stack.p; o < L1->stack_last.p; o++)
checkliveness(L1, s2v(o)); /* entire stack must have valid values */
}
@ -476,7 +477,7 @@ static void checkrefs (global_State *g, GCObject *o) {
break;
}
case LUA_VUPVAL: {
checkvalref(g, o, gco2upv(o)->v);
checkvalref(g, o, gco2upv(o)->v.p);
break;
}
case LUA_VTABLE: {
@ -544,7 +545,7 @@ static void checkobject (global_State *g, GCObject *o, int maybedead,
static lu_mem checkgraylist (global_State *g, GCObject *o) {
int total = 0; /* count number of elements in the list */
((void)g); /* better to keep it available if we need to print an object */
cast_void(g); /* better to keep it if we need to print an object */
while (o) {
assert(!!isgray(o) ^ (getage(o) == G_TOUCHED2));
assert(!testbit(o->marked, TESTBIT));
@ -991,7 +992,7 @@ static int hash_query (lua_State *L) {
static int stacklevel (lua_State *L) {
unsigned long a = 0;
lua_pushinteger(L, (L->top - L->stack));
lua_pushinteger(L, (L->top.p - L->stack.p));
lua_pushinteger(L, stacksize(L));
lua_pushinteger(L, L->nCcalls);
lua_pushinteger(L, L->nci);
@ -1051,7 +1052,7 @@ static int string_query (lua_State *L) {
TString *ts;
int n = 0;
for (ts = tb->hash[s]; ts != NULL; ts = ts->u.hnext) {
setsvalue2s(L, L->top, ts);
setsvalue2s(L, L->top.p, ts);
api_incr_top(L);
n++;
}
@ -1066,7 +1067,7 @@ static int tref (lua_State *L) {
luaL_checkany(L, 1);
lua_pushvalue(L, 1);
lua_pushinteger(L, luaL_ref(L, LUA_REGISTRYINDEX));
(void)level; /* to avoid warnings */
cast_void(level); /* to avoid warnings */
lua_assert(lua_gettop(L) == level+1); /* +1 for result */
return 1;
}
@ -1074,7 +1075,7 @@ static int tref (lua_State *L) {
static int getref (lua_State *L) {
int level = lua_gettop(L);
lua_rawgeti(L, LUA_REGISTRYINDEX, luaL_checkinteger(L, 1));
(void)level; /* to avoid warnings */
cast_void(level); /* to avoid warnings */
lua_assert(lua_gettop(L) == level+1);
return 1;
}
@ -1082,7 +1083,7 @@ static int getref (lua_State *L) {
static int unref (lua_State *L) {
int level = lua_gettop(L);
luaL_unref(L, LUA_REGISTRYINDEX, cast_int(luaL_checkinteger(L, 1)));
(void)level; /* to avoid warnings */
cast_void(level); /* to avoid warnings */
lua_assert(lua_gettop(L) == level);
return 0;
}
@ -1258,7 +1259,7 @@ static int panicback (lua_State *L) {
b = (struct Aux *)lua_touserdata(L, -1);
lua_pop(L, 1); /* remove 'Aux' struct */
runC(b->L, L, b->paniccode); /* run optional panic code */
gclongjmp(b->jb, 1);
gclongjmp(b->jb, 1); // [jart]
return 1; /* to avoid warnings */
}
@ -1544,7 +1545,7 @@ static int runC (lua_State *L, lua_State *L1, const char *pc) {
lua_newthread(L1);
}
else if EQ("resetthread") {
lua_pushinteger(L1, lua_resetthread(L1));
lua_pushinteger(L1, lua_resetthread(L1)); /* deprecated */
}
else if EQ("newuserdata") {
lua_newuserdata(L1, getnum);
@ -1719,7 +1720,7 @@ static int runC (lua_State *L, lua_State *L1, const char *pc) {
lua_error(L1);
}
else if EQ("abort") {
__die();
__die(); // [jart]
}
else if EQ("throw") {
#if defined(__cplusplus)
@ -1751,9 +1752,12 @@ static struct X { int x; } x;
else if EQ("tostring") {
const char *s = lua_tostring(L1, getindex);
const char *s1 = lua_pushstring(L1, s);
(void)s1; /* to avoid warnings */
cast_void(s1); /* to avoid warnings */
lua_longassert((s == NULL && s1 == NULL) || strcmp(s, s1) == 0);
}
else if EQ("Ltolstring") {
luaL_tolstring(L1, getindex, NULL);
}
else if EQ("type") {
lua_pushstring(L1, luaL_typename(L1, getnum));
}