aboutsummaryrefslogtreecommitdiff
path: root/testes/tracegc.lua
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2021-03-01 13:54:29 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2021-03-01 13:54:29 -0300
commit5276973224066e591b0f1a79c3b091d395848ac4 (patch)
treee72f167dca7796b4014b1833cb1e9eaed58a623e /testes/tracegc.lua
parentf9d857a81b87b695c1e3b34f1e7fe55884d1288f (diff)
downloadlua-5276973224066e591b0f1a79c3b091d395848ac4.tar.gz
lua-5276973224066e591b0f1a79c3b091d395848ac4.tar.bz2
lua-5276973224066e591b0f1a79c3b091d395848ac4.zip
New test module 'tracegc'
New module easies the inclusion of GC tracing in individual test files.
Diffstat (limited to 'testes/tracegc.lua')
-rw-r--r--testes/tracegc.lua40
1 files changed, 40 insertions, 0 deletions
diff --git a/testes/tracegc.lua b/testes/tracegc.lua
new file mode 100644
index 00000000..9c5c1b3f
--- /dev/null
+++ b/testes/tracegc.lua
@@ -0,0 +1,40 @@
1-- track collections
2
3local M = {}
4
5-- import list
6local setmetatable, stderr, collectgarbage =
7 setmetatable, io.stderr, collectgarbage
8
9_ENV = nil
10
11local active = false
12
13
14-- each time a table is collected, remark it for finalization on next
15-- cycle
16local mt = {}
17function mt.__gc (o)
18 stderr:write'.' -- mark progress
19 if active then
20 setmetatable(o, mt) -- remark object for finalization
21 end
22end
23
24
25function M.start ()
26 if not active then
27 active = true
28 setmetatable({}, mt) -- create initial object
29 end
30end
31
32
33function M.stop ()
34 if active then
35 active = false
36 collectgarbage() -- call finalizer for the last time
37 end
38end
39
40return M