|
@@ -13,20 +13,40 @@ local function checkerror (msg, f, ...)
|
|
assert(not s and string.find(err, msg))
|
|
assert(not s and string.find(err, msg))
|
|
end
|
|
end
|
|
|
|
|
|
|
|
+local count
|
|
|
|
+local back = string.rep("\b", 8)
|
|
|
|
+local function progress ()
|
|
|
|
+ count = count + 1
|
|
|
|
+ local n = string.format("%-8d", count)
|
|
|
|
+ io.stderr:write(back, n)
|
|
|
|
+end
|
|
|
|
+
|
|
|
|
|
|
-do -- simple recursion
|
|
|
|
- local count = 0
|
|
|
|
|
|
+do print("testing simple recursion:")
|
|
|
|
+ count = 0
|
|
local function foo ()
|
|
local function foo ()
|
|
- count = count + 1
|
|
|
|
|
|
+ progress()
|
|
foo()
|
|
foo()
|
|
end
|
|
end
|
|
checkerror("stack overflow", foo)
|
|
checkerror("stack overflow", foo)
|
|
- print(" maximum recursion: " .. count)
|
|
|
|
|
|
+ print("\tfinal count: ", count)
|
|
|
|
+end
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+do print("testing stack overflow in message handling")
|
|
|
|
+ count = 0
|
|
|
|
+ local function loop (x, y, z)
|
|
|
|
+ progress()
|
|
|
|
+ return 1 + loop(x, y, z)
|
|
|
|
+ end
|
|
|
|
+ local res, msg = xpcall(loop, loop)
|
|
|
|
+ assert(msg == "error in error handling")
|
|
|
|
+ print("\tfinal count: ", count)
|
|
end
|
|
end
|
|
|
|
|
|
|
|
|
|
-- bug since 2.5 (C-stack overflow in recursion inside pattern matching)
|
|
-- bug since 2.5 (C-stack overflow in recursion inside pattern matching)
|
|
-do
|
|
|
|
|
|
+do print("testing recursion inside pattern matching")
|
|
local function f (size)
|
|
local function f (size)
|
|
local s = string.rep("a", size)
|
|
local s = string.rep("a", size)
|
|
local p = string.rep(".?", size)
|
|
local p = string.rep(".?", size)
|
|
@@ -38,25 +58,25 @@ do
|
|
end
|
|
end
|
|
|
|
|
|
|
|
|
|
--- testing stack-overflow in recursive 'gsub'
|
|
|
|
-do
|
|
|
|
- local count = 0
|
|
|
|
|
|
+do print("testing stack-overflow in recursive 'gsub'")
|
|
|
|
+ count = 0
|
|
local function foo ()
|
|
local function foo ()
|
|
- count = count + 1
|
|
|
|
|
|
+ progress()
|
|
string.gsub("a", ".", foo)
|
|
string.gsub("a", ".", foo)
|
|
end
|
|
end
|
|
checkerror("stack overflow", foo)
|
|
checkerror("stack overflow", foo)
|
|
- print(" maximum 'gsub' nest (calls): " .. count)
|
|
|
|
|
|
+ print("\tfinal count: ", count)
|
|
|
|
|
|
- -- can be done with metamethods, too
|
|
|
|
|
|
+ print("testing stack-overflow in recursive 'gsub' with metatables")
|
|
count = 0
|
|
count = 0
|
|
local t = setmetatable({}, {__index = foo})
|
|
local t = setmetatable({}, {__index = foo})
|
|
foo = function ()
|
|
foo = function ()
|
|
count = count + 1
|
|
count = count + 1
|
|
|
|
+ progress(count)
|
|
string.gsub("a", ".", t)
|
|
string.gsub("a", ".", t)
|
|
end
|
|
end
|
|
checkerror("stack overflow", foo)
|
|
checkerror("stack overflow", foo)
|
|
- print(" maximum 'gsub' nest (metamethods): " .. count)
|
|
|
|
|
|
+ print("\tfinal count: ", count)
|
|
end
|
|
end
|
|
|
|
|
|
print'OK'
|
|
print'OK'
|