changed garbage collection of file handles a bit. although it was working, in hindsight i'm really not quite sure *how*, or rather: Lua seems to be smarter than I already gave it credit for. it apparently realized that a new reference to the object to be gc'ed was created in its finalizer, so it let it live. however, i'm not quite sure why that didn't lead to a pseudo-infinite loop. now we just keep the stream as an upvalue for the timer callback that actually closes the stream; also, removed the checks if event.timer exists. if people remove that it's really their own problem

This commit is contained in:
Florian Nücke 2013-10-24 18:45:01 +02:00
parent 4a664bb2e5
commit a628822d14

View File

@ -267,11 +267,10 @@ function file.new(mode, stream, nogc)
metatable.__gc = function(self)
-- file.close does a syscall, which yields, and that's not possible in
-- the __gc metamethod. So we start a timer to do the yield/cleanup.
if type(event) == "table" and type(event.timer) == "function" then
event.timer(0, function()
self:close()
end)
end
local stream = self.stream -- only keep the stream as an upvalue
event.timer(0, function()
stream:close()
end)
end
end
return setmetatable(result, metatable)