diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-12-30 11:45:08 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-12-30 11:45:08 -0300 |
| commit | bd1b87c5790c0c6fe23f76aa360e879922e1e738 (patch) | |
| tree | 49978c2dd847c7ff4ec84e1a153ca37deef79e2a /testes/cstack.lua | |
| parent | d7bb8df8414f71a290c8a4b1c9f7c6fe839a94df (diff) | |
| download | lua-github-bd1b87c5790c0c6fe23f76aa360e879922e1e738.tar.gz | |
Comments (mosty typos)
Diffstat (limited to 'testes/cstack.lua')
| -rw-r--r-- | testes/cstack.lua | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/testes/cstack.lua b/testes/cstack.lua index 486abc1d..cd74fd28 100644 --- a/testes/cstack.lua +++ b/testes/cstack.lua @@ -4,7 +4,7 @@ local debug = require "debug" print"testing C-stack overflow detection" -print"If this test craches, see its file ('cstack.lua')" +print"If this test crashes, see its file ('cstack.lua')" -- Segmentation faults in these tests probably result from a C-stack -- overflow. To avoid these errors, you can use the function @@ -19,10 +19,13 @@ print"If this test craches, see its file ('cstack.lua')" -- higher than 2_000. +-- get and print original limit local origlimit = debug.setcstacklimit(400) print("default stack limit: " .. origlimit) --- change this value for different limits for this test suite +-- Do the tests using the original limit. Or else you may want to change +-- 'currentlimit' to lower values to avoid a seg. fault or to higher +-- values to check whether they are reliable. local currentlimit = origlimit debug.setcstacklimit(currentlimit) print("current stack limit: " .. currentlimit) @@ -33,12 +36,14 @@ local function checkerror (msg, f, ...) assert(not s and string.find(err, msg)) end +-- auxiliary function to keep 'count' on the screen even if the program +-- crashes. 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) + io.stderr:write(back, n) -- erase previous value and write new one end @@ -46,7 +51,7 @@ do print("testing simple recursion:") count = 0 local function foo () progress() - foo() + foo() -- do recursive calls until a stack error (or crash) end checkerror("stack overflow", foo) print("\tfinal count: ", count) @@ -118,9 +123,11 @@ do print("testing changes in C-stack limit") return n end + -- set limit to 400 assert(debug.setcstacklimit(400) == currentlimit) local lim400 = check() - -- a very low limit (given that the several calls to arive here) + -- set a very low limit (given that there are already several active + -- calls to arrive here) local lowlimit = 38 assert(debug.setcstacklimit(lowlimit) == 400) assert(check() < lowlimit - 30) |
