aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2020-09-28 10:14:06 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2020-10-12 12:29:09 -0300
commit0085db4596df99b43fc245f71ee444da68cb830b (patch)
tree217d9553142dde1378adc2bb9e0d40a67e6bbfd9
parent490d42b5f89563a94994505c75e24086b0a487e6 (diff)
downloadlua-0085db4596df99b43fc245f71ee444da68cb830b.tar.gz
lua-0085db4596df99b43fc245f71ee444da68cb830b.tar.bz2
lua-0085db4596df99b43fc245f71ee444da68cb830b.zip
Avoid GCs when testing stack overflow
A GC step may invoke some finalizer, which may error and emit a warning due to stack overflfow.
-rw-r--r--testes/errors.lua20
1 files changed, 14 insertions, 6 deletions
diff --git a/testes/errors.lua b/testes/errors.lua
index f975b3dd..422c1128 100644
--- a/testes/errors.lua
+++ b/testes/errors.lua
@@ -386,25 +386,33 @@ if not _soft then
386 collectgarbage() 386 collectgarbage()
387 print"testing stack overflow" 387 print"testing stack overflow"
388 C = 0 388 C = 0
389 local l = debug.getinfo(1, "l").currentline; function y () C=C+1; y() end 389 -- get line where stack overflow will happen
390 local l = debug.getinfo(1, "l").currentline + 1
391 local function auxy () C=C+1; auxy() end -- produce a stack overflow
392 function y ()
393 collectgarbage("stop") -- avoid running finalizers without stack space
394 auxy()
395 collectgarbage("restart")
396 end
390 397
391 local function checkstackmessage (m) 398 local function checkstackmessage (m)
399 print("(expected stack overflow after " .. C .. " calls)")
400 C = 0 -- prepare next count
392 return (string.find(m, "stack overflow")) 401 return (string.find(m, "stack overflow"))
393 end 402 end
394 -- repeated stack overflows (to check stack recovery) 403 -- repeated stack overflows (to check stack recovery)
395 assert(checkstackmessage(doit('y()'))) 404 assert(checkstackmessage(doit('y()')))
396 print('+')
397 assert(checkstackmessage(doit('y()'))) 405 assert(checkstackmessage(doit('y()')))
398 print('+')
399 assert(checkstackmessage(doit('y()'))) 406 assert(checkstackmessage(doit('y()')))
400 print('+')
401 407
402 408
403 -- error lines in stack overflow 409 -- error lines in stack overflow
404 C = 0
405 local l1 410 local l1
406 local function g(x) 411 local function g(x)
407 l1 = debug.getinfo(x, "l").currentline; y() 412 l1 = debug.getinfo(x, "l").currentline + 2
413 collectgarbage("stop") -- avoid running finalizers without stack space
414 auxy()
415 collectgarbage("restart")
408 end 416 end
409 local _, stackmsg = xpcall(g, debug.traceback, 1) 417 local _, stackmsg = xpcall(g, debug.traceback, 1)
410 print('+') 418 print('+')