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

@ -16,7 +16,7 @@ end
assert(not debug.gethook())
local testline = 19 -- line where 'test' is defined
function test (s, l, p) -- this must be line 19
local function test (s, l, p) -- this must be line 19
collectgarbage() -- avoid gc during trace
local function f (event, line)
assert(event == 'line')
@ -50,7 +50,7 @@ end
-- test file and string names truncation
a = "function f () end"
local a = "function f () end"
local function dostring (s, x) return load(s, x)() end
dostring(a)
assert(debug.getinfo(f).short_src == string.format('[string "%s"]', a))
@ -72,7 +72,8 @@ dostring(a, string.format("=%s", string.rep('x', 500)))
assert(string.find(debug.getinfo(f).short_src, "^x*$"))
dostring(a, "=")
assert(debug.getinfo(f).short_src == "")
a = nil; f = nil;
_G.a = nil; _G.f = nil;
_G[string.rep("p", 400)] = nil
repeat
@ -120,6 +121,7 @@ else
end
]], {2,3,4,7})
test([[
local function foo()
end
@ -128,6 +130,7 @@ A = 1
A = 2
A = 3
]], {2, 3, 2, 4, 5, 6})
_G.A = nil
test([[--
@ -175,6 +178,8 @@ end
test([[for i=1,4 do a=1 end]], {1,1,1,1})
_G.a = nil
do -- testing line info/trace with large gaps in source
@ -194,6 +199,50 @@ do -- testing line info/trace with large gaps in source
end
end
end
_G.a = nil
do -- testing active lines
local function checkactivelines (f, lines)
local t = debug.getinfo(f, "SL")
for _, l in pairs(lines) do
l = l + t.linedefined
assert(t.activelines[l])
t.activelines[l] = undef
end
assert(next(t.activelines) == nil) -- no extra lines
end
checkactivelines(function (...) -- vararg function
-- 1st line is empty
-- 2nd line is empty
-- 3th line is empty
local a = 20
-- 5th line is empty
local b = 30
-- 7th line is empty
end, {4, 6, 8})
checkactivelines(function (a)
-- 1st line is empty
-- 2nd line is empty
local a = 20
local b = 30
-- 5th line is empty
end, {3, 4, 6})
checkactivelines(function (a, b, ...) end, {0})
checkactivelines(function (a, b)
end, {1})
for _, n in pairs{0, 1, 2, 10, 50, 100, 1000, 10000} do
checkactivelines(
load(string.format("%s return 1", string.rep("\n", n))),
{n + 1})
end
end
print'+'
@ -244,7 +293,6 @@ foo(200, 3, 4)
local a = {}
for i = 1, (_soft and 100 or 1000) do a[i] = i end
foo(table.unpack(a))
a = nil
@ -264,13 +312,14 @@ do -- test hook presence in debug info
debug.sethook()
assert(count == 4)
end
_ENV.a = nil
-- hook table has weak keys
assert(getmetatable(debug.getregistry()._HOOKKEY).__mode == 'k')
a = {}; L = nil
a = {}; local L = nil
local glob = 1
local oldglob = glob
debug.sethook(function (e,l)
@ -311,7 +360,7 @@ function foo()
end; foo() -- set L
-- check line counting inside strings and empty lines
_ = 'alo\
local _ = 'alo\
alo' .. [[
]]
@ -360,6 +409,7 @@ function g(a,b) return (a+1) + f() end
assert(g(0,0) == 30)
_G.f, _G.g = nil
debug.sethook(nil);
assert(not debug.gethook())
@ -403,7 +453,7 @@ local function collectlocals (level)
end
X = nil
local X = nil
a = {}
function a:f (a, b, ...) local arg = {...}; local c = 13 end
debug.sethook(function (e)
@ -426,6 +476,7 @@ a:f(1,2,3,4,5)
assert(X.self == a and X.a == 1 and X.b == 2 and X.c == nil)
assert(XX == 12)
assert(not debug.gethook())
_G.XX = nil
-- testing access to local variables in return hook (bug in 5.2)
@ -550,6 +601,7 @@ end
debug.sethook()
local g, g1
-- tests for tail calls
local function f (x)
@ -595,7 +647,7 @@ h(false)
debug.sethook()
assert(b == 2) -- two tail calls
lim = _soft and 3000 or 30000
local lim = _soft and 3000 or 30000
local function foo (x)
if x==0 then
assert(debug.getinfo(2).what == "main")
@ -844,7 +896,7 @@ do -- testing debug info for finalizers
-- create a piece of garbage with a finalizer
setmetatable({}, {__gc = function ()
local t = debug.getinfo(2) -- get callee information
local t = debug.getinfo(1) -- get function information
assert(t.namewhat == "metamethod")
name = t.name
end})
@ -897,7 +949,7 @@ end
print("testing debug functions on chunk without debug info")
prog = [[-- program to be loaded without debug information (strip)
local prog = [[-- program to be loaded without debug information (strip)
local debug = require'debug'
local a = 12 -- a local variable