mirror of https://github.com/rusefi/lua.git
Avoid GCs when testing stack overflow
A GC step may invoke some finalizer, which may error and emit a warning due to stack overflfow.
This commit is contained in:
parent
490d42b5f8
commit
0085db4596
|
@ -386,25 +386,33 @@ if not _soft then
|
||||||
collectgarbage()
|
collectgarbage()
|
||||||
print"testing stack overflow"
|
print"testing stack overflow"
|
||||||
C = 0
|
C = 0
|
||||||
local l = debug.getinfo(1, "l").currentline; function y () C=C+1; y() end
|
-- get line where stack overflow will happen
|
||||||
|
local l = debug.getinfo(1, "l").currentline + 1
|
||||||
|
local function auxy () C=C+1; auxy() end -- produce a stack overflow
|
||||||
|
function y ()
|
||||||
|
collectgarbage("stop") -- avoid running finalizers without stack space
|
||||||
|
auxy()
|
||||||
|
collectgarbage("restart")
|
||||||
|
end
|
||||||
|
|
||||||
local function checkstackmessage (m)
|
local function checkstackmessage (m)
|
||||||
|
print("(expected stack overflow after " .. C .. " calls)")
|
||||||
|
C = 0 -- prepare next count
|
||||||
return (string.find(m, "stack overflow"))
|
return (string.find(m, "stack overflow"))
|
||||||
end
|
end
|
||||||
-- repeated stack overflows (to check stack recovery)
|
-- repeated stack overflows (to check stack recovery)
|
||||||
assert(checkstackmessage(doit('y()')))
|
assert(checkstackmessage(doit('y()')))
|
||||||
print('+')
|
|
||||||
assert(checkstackmessage(doit('y()')))
|
assert(checkstackmessage(doit('y()')))
|
||||||
print('+')
|
|
||||||
assert(checkstackmessage(doit('y()')))
|
assert(checkstackmessage(doit('y()')))
|
||||||
print('+')
|
|
||||||
|
|
||||||
|
|
||||||
-- error lines in stack overflow
|
-- error lines in stack overflow
|
||||||
C = 0
|
|
||||||
local l1
|
local l1
|
||||||
local function g(x)
|
local function g(x)
|
||||||
l1 = debug.getinfo(x, "l").currentline; y()
|
l1 = debug.getinfo(x, "l").currentline + 2
|
||||||
|
collectgarbage("stop") -- avoid running finalizers without stack space
|
||||||
|
auxy()
|
||||||
|
collectgarbage("restart")
|
||||||
end
|
end
|
||||||
local _, stackmsg = xpcall(g, debug.traceback, 1)
|
local _, stackmsg = xpcall(g, debug.traceback, 1)
|
||||||
print('+')
|
print('+')
|
||||||
|
|
Loading…
Reference in New Issue