aboutsummaryrefslogtreecommitdiff
path: root/testes
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2021-12-22 09:00:52 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2021-12-22 09:00:52 -0300
commit597a53bbc681089d85b082b46c2e2428dec43b86 (patch)
treeb7dc3fc3f21b66bd8e9422e16b0fdde6d1ec6e01 /testes
parent86ec152433baf8daf39f03a59c6842cbe33a179d (diff)
downloadlua-597a53bbc681089d85b082b46c2e2428dec43b86.tar.gz
lua-597a53bbc681089d85b082b46c2e2428dec43b86.tar.bz2
lua-597a53bbc681089d85b082b46c2e2428dec43b86.zip
Bug: finalizer calling exit can corrupt finalization order
'os.exit' can call lua_close again, separating new finalizers created after all previous finalizers were already separated.
Diffstat (limited to 'testes')
-rw-r--r--testes/main.lua28
1 files changed, 28 insertions, 0 deletions
diff --git a/testes/main.lua b/testes/main.lua
index 52c77954..9def6386 100644
--- a/testes/main.lua
+++ b/testes/main.lua
@@ -261,6 +261,34 @@ u2 = setmetatable({}, {__gc = function () error("ZYX") end})
261RUN('lua -W %s 2> %s', prog, out) 261RUN('lua -W %s 2> %s', prog, out)
262checkprogout("ZYX)\nXYZ)\n") 262checkprogout("ZYX)\nXYZ)\n")
263 263
264-- bug since 5.2: finalizer called when closing a state could
265-- subvert finalization order
266prepfile[[
267-- should be called last
268print("creating 1")
269setmetatable({}, {__gc = function () print(1) end})
270
271print("creating 2")
272setmetatable({}, {__gc = function ()
273 print("2")
274 print("creating 3")
275 -- this finalizer should not be called, as object will be
276 -- created after 'lua_close' has been called
277 setmetatable({}, {__gc = function () print(3) end})
278 print(collectgarbage()) -- cannot call collector here
279 os.exit(0, true)
280end})
281]]
282RUN('lua -W %s > %s', prog, out)
283checkout[[
284creating 1
285creating 2
2862
287creating 3
288nil
2891
290]]
291
264 292
265-- test many arguments 293-- test many arguments
266prepfile[[print(({...})[30])]] 294prepfile[[print(({...})[30])]]