lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I found that coroutine.close does not update the nCcalls variable of the coroutine it switches to when running the __close methods. This can lead to loss of the C call count and a stack overflow as the following code demonstrates:

local coro = {}
local n = 1
for i = 1, 100000 do
    coro[i] = coroutine.create(function()
        local cc <close> = setmetatable({}, {__close=function()
            n = n + 1
            coroutine.close(coro[n])
        end})
        coroutine.yield()
    end)
    coroutine.resume(coro[i])
end
coroutine.close(coro[1])

This creates 100000 coroutines with low nCcalls counts and then closes all through the __close method using lots of C stack.

Regards,
Xmilia