mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-28 08:12:28 +00:00
Upgrade Lua to 5.4.3 (#217)
Based on https://github.com/lua/lua/releases/tag/v5.4.3 (commit eadd8c7).
This commit is contained in:
parent
3ac6576fe5
commit
a73e808b25
41 changed files with 464 additions and 264 deletions
14
third_party/lua/test/all.lua
vendored
14
third_party/lua/test/all.lua
vendored
|
@ -154,18 +154,8 @@ end
|
|||
|
||||
dofile('main.lua')
|
||||
|
||||
do
|
||||
local next, setmetatable, stderr = next, setmetatable, io.stderr
|
||||
-- track collections
|
||||
local mt = {}
|
||||
-- each time a table is collected, remark it for finalization
|
||||
-- on next cycle
|
||||
mt.__gc = function (o)
|
||||
stderr:write'.' -- mark progress
|
||||
local n = setmetatable(o, mt) -- remark it
|
||||
end
|
||||
local n = setmetatable({}, mt) -- create object
|
||||
end
|
||||
-- trace GC cycles
|
||||
require"tracegc".start()
|
||||
|
||||
report"gc.lua"
|
||||
local f = assert(loadfile('gc.lua'))
|
||||
|
|
26
third_party/lua/test/api.lua
vendored
26
third_party/lua/test/api.lua
vendored
|
@ -1130,7 +1130,7 @@ do
|
|||
-- closing resources with 'closeslot'
|
||||
_ENV.xxx = true
|
||||
local a = T.testC([[
|
||||
pushvalue 2 # stack: S, NR, CH
|
||||
pushvalue 2 # stack: S, NR, CH, NR
|
||||
call 0 1 # create resource; stack: S, NR, CH, R
|
||||
toclose -1 # mark it to be closed
|
||||
pushvalue 2 # stack: S, NR, CH, R, NR
|
||||
|
@ -1151,6 +1151,30 @@ do
|
|||
]], newresource, check)
|
||||
assert(a == 3 and _ENV.xxx == nil) -- no extra items left in the stack
|
||||
|
||||
-- closing resources with 'pop'
|
||||
local a = T.testC([[
|
||||
pushvalue 2 # stack: S, NR, CH, NR
|
||||
call 0 1 # create resource; stack: S, NR, CH, R
|
||||
toclose -1 # mark it to be closed
|
||||
pushvalue 2 # stack: S, NR, CH, R, NR
|
||||
call 0 1 # create another resource; stack: S, NR, CH, R, R
|
||||
toclose -1 # mark it to be closed
|
||||
pushvalue 3 # stack: S, NR, CH, R, R, CH
|
||||
pushint 2 # there should be two open resources
|
||||
call 1 0 # stack: S, NR, CH, R, R
|
||||
pop 1 # pop second resource
|
||||
pushvalue 3 # stack: S, NR, CH, R, CH
|
||||
pushint 1 # there should be one open resource
|
||||
call 1 0 # stack: S, NR, CH, R
|
||||
pop 1 # pop other resource from the stack
|
||||
pushvalue 3 # stack: S, NR, CH, CH
|
||||
pushint 0 # there should be no open resources
|
||||
call 1 0 # stack: S, NR, CH
|
||||
pushint *
|
||||
return 1 # return stack size
|
||||
]], newresource, check)
|
||||
assert(a == 3) -- no extra items left in the stack
|
||||
|
||||
-- non-closable value
|
||||
local a, b = pcall(T.makeCfunc[[
|
||||
pushint 32
|
||||
|
|
12
third_party/lua/test/cstack.lua
vendored
12
third_party/lua/test/cstack.lua
vendored
|
@ -2,6 +2,8 @@
|
|||
-- See Copyright Notice in file all.lua
|
||||
|
||||
|
||||
local tracegc = require"tracegc"
|
||||
|
||||
print"testing stack overflow detection"
|
||||
|
||||
-- Segmentation faults in these tests probably result from a C-stack
|
||||
|
@ -21,7 +23,9 @@ do print("testing stack overflow in message handling")
|
|||
count = count + 1
|
||||
return 1 + loop(x, y, z)
|
||||
end
|
||||
tracegc.stop() -- __gc should not be called with a full stack
|
||||
local res, msg = xpcall(loop, loop)
|
||||
tracegc.start()
|
||||
assert(msg == "error in error handling")
|
||||
print("final count: ", count)
|
||||
end
|
||||
|
@ -135,18 +139,18 @@ if T then
|
|||
local topB, sizeB -- top and size Before overflow
|
||||
local topA, sizeA -- top and size After overflow
|
||||
topB, sizeB = T.stacklevel()
|
||||
collectgarbage("stop") -- __gc should not be called with a full stack
|
||||
tracegc.stop() -- __gc should not be called with a full stack
|
||||
xpcall(f, err)
|
||||
collectgarbage("restart")
|
||||
tracegc.start()
|
||||
topA, sizeA = T.stacklevel()
|
||||
-- sizes should be comparable
|
||||
assert(topA == topB and sizeA < sizeB * 2)
|
||||
print(string.format("maximum stack size: %d", stack1))
|
||||
LIM = N -- will stop recursion at maximum level
|
||||
N = 0 -- to count again
|
||||
collectgarbage("stop") -- __gc should not be called with a full stack
|
||||
tracegc.stop() -- __gc should not be called with a full stack
|
||||
f()
|
||||
collectgarbage("restart")
|
||||
tracegc.start()
|
||||
print"+"
|
||||
end
|
||||
|
||||
|
|
15
third_party/lua/test/errors.lua
vendored
15
third_party/lua/test/errors.lua
vendored
|
@ -191,6 +191,13 @@ checkmessage("a = 24 // 0", "divide by zero")
|
|||
checkmessage("a = 1 % 0", "'n%0'")
|
||||
|
||||
|
||||
-- type error for an object which is neither in an upvalue nor a register.
|
||||
-- The following code will try to index the value 10 that is stored in
|
||||
-- the metatable, without moving it to a register.
|
||||
checkmessage("local a = setmetatable({}, {__index = 10}).x",
|
||||
"attempt to index a number value")
|
||||
|
||||
|
||||
-- numeric for loops
|
||||
checkmessage("for i = {}, 10 do end", "table")
|
||||
checkmessage("for i = io.stdin, 10 do end", "FILE")
|
||||
|
@ -413,6 +420,14 @@ if not b then
|
|||
end
|
||||
end]], 5)
|
||||
|
||||
do
|
||||
-- Force a negative estimate for base line. Error in instruction 2
|
||||
-- (after VARARGPREP, GETGLOBAL), with first absolute line information
|
||||
-- (forced by too many lines) in instruction 0.
|
||||
local s = string.format("%s return __A.x", string.rep("\n", 300))
|
||||
lineerror(s, 301)
|
||||
end
|
||||
|
||||
|
||||
if not _soft then
|
||||
-- several tests that exaust the Lua stack
|
||||
|
|
8
third_party/lua/test/gc.lua
vendored
8
third_party/lua/test/gc.lua
vendored
|
@ -676,6 +676,14 @@ end
|
|||
-- just to make sure
|
||||
assert(collectgarbage'isrunning')
|
||||
|
||||
do -- check that the collector is reentrant in incremental mode
|
||||
setmetatable({}, {__gc = function ()
|
||||
collectgarbage()
|
||||
end})
|
||||
collectgarbage()
|
||||
end
|
||||
|
||||
|
||||
collectgarbage(oldmode)
|
||||
|
||||
print('OK')
|
||||
|
|
6
third_party/lua/test/locals.lua
vendored
6
third_party/lua/test/locals.lua
vendored
|
@ -5,6 +5,8 @@ print('testing local variables and environments')
|
|||
|
||||
local debug = require"debug"
|
||||
|
||||
local tracegc = require"tracegc"
|
||||
|
||||
|
||||
-- bug in 5.1:
|
||||
|
||||
|
@ -554,9 +556,9 @@ do -- test for tbc variable high in the stack
|
|||
obj[1] = 100
|
||||
flag = obj
|
||||
end)
|
||||
collectgarbage("stop")
|
||||
tracegc.stop()
|
||||
st, obj = xpcall(overflow, errorh, 0)
|
||||
collectgarbage("restart")
|
||||
tracegc.start()
|
||||
end)
|
||||
co()
|
||||
assert(not st and obj[1] == 10 and flag[1] == 100)
|
||||
|
|
1
third_party/lua/test/packtests
vendored
1
third_party/lua/test/packtests
vendored
|
@ -33,6 +33,7 @@ $NAME/pm.lua \
|
|||
$NAME/sort.lua \
|
||||
$NAME/strings.lua \
|
||||
$NAME/tpack.lua \
|
||||
$NAME/tracegc.lua \
|
||||
$NAME/utf8.lua \
|
||||
$NAME/vararg.lua \
|
||||
$NAME/verybig.lua \
|
||||
|
|
40
third_party/lua/test/tracegc.lua
vendored
Normal file
40
third_party/lua/test/tracegc.lua
vendored
Normal file
|
@ -0,0 +1,40 @@
|
|||
-- track collections
|
||||
|
||||
local M = {}
|
||||
|
||||
-- import list
|
||||
local setmetatable, stderr, collectgarbage =
|
||||
setmetatable, io.stderr, collectgarbage
|
||||
|
||||
_ENV = nil
|
||||
|
||||
local active = false
|
||||
|
||||
|
||||
-- each time a table is collected, remark it for finalization on next
|
||||
-- cycle
|
||||
local mt = {}
|
||||
function mt.__gc (o)
|
||||
stderr:write'.' -- mark progress
|
||||
if active then
|
||||
setmetatable(o, mt) -- remark object for finalization
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function M.start ()
|
||||
if not active then
|
||||
active = true
|
||||
setmetatable({}, mt) -- create initial object
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function M.stop ()
|
||||
if active then
|
||||
active = false
|
||||
collectgarbage() -- call finalizer for the last time
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
Loading…
Add table
Add a link
Reference in a new issue