lua-users home
lua-l archive

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


On Thu, Jul 26, 2018 at 8:35 AM, Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
if we create the resource and then
the variable allocation fails, the resource won't be closed.

If the Lua core must take care against this out of memory situation, it follows that any library using scoped vars must take equal care.

But this seems like a tall order in general.  You mean there must be no malloc from the time a resource is created and its corresponding Lua object is assigned to a scoped var.  Does Lua (or LuaJIT) even define when the core or stdlib might allocate memory?  For example, iterators can be complicated and it seems likely the resource object could get wrapped in a closure, etc. before reaching the scoped var.  And what if the iterator contains multiple resources-- is it possible to ensure either both or none are allocated, and cleanup ownership is properly transferred from the iterator constructor to the for loop?