diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2021-12-22 09:00:52 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2021-12-22 09:00:52 -0300 |
commit | 597a53bbc681089d85b082b46c2e2428dec43b86 (patch) | |
tree | b7dc3fc3f21b66bd8e9422e16b0fdde6d1ec6e01 /testes | |
parent | 86ec152433baf8daf39f03a59c6842cbe33a179d (diff) | |
download | lua-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.lua | 28 |
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}) | |||
261 | RUN('lua -W %s 2> %s', prog, out) | 261 | RUN('lua -W %s 2> %s', prog, out) |
262 | checkprogout("ZYX)\nXYZ)\n") | 262 | checkprogout("ZYX)\nXYZ)\n") |
263 | 263 | ||
264 | -- bug since 5.2: finalizer called when closing a state could | ||
265 | -- subvert finalization order | ||
266 | prepfile[[ | ||
267 | -- should be called last | ||
268 | print("creating 1") | ||
269 | setmetatable({}, {__gc = function () print(1) end}) | ||
270 | |||
271 | print("creating 2") | ||
272 | setmetatable({}, {__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) | ||
280 | end}) | ||
281 | ]] | ||
282 | RUN('lua -W %s > %s', prog, out) | ||
283 | checkout[[ | ||
284 | creating 1 | ||
285 | creating 2 | ||
286 | 2 | ||
287 | creating 3 | ||
288 | nil | ||
289 | 1 | ||
290 | ]] | ||
291 | |||
264 | 292 | ||
265 | -- test many arguments | 293 | -- test many arguments |
266 | prepfile[[print(({...})[30])]] | 294 | prepfile[[print(({...})[30])]] |