lua-users home
lua-l archive

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

On 09/01/16 11:54 PM, 书呆彭, Peng Yi wrote:
在 2016/1/9 20:35, 张伟智 写道:
Lua version is 5.2.4.
In lgc.c line 820, function GCTM,
g->gcrunning is set to 0 to avoid GC steps,
I think if g->gcrunning remains unchanged,
line 824 luaD_pcall will trigger luaC_step->luaC_forcestep->GCTM during executing __gc finalizer.
But what is the problem if recursive enter GCTM ?

In my understanding, the Lua VM is reentrant, but the finalizers are meant to be called in sequence. according to Lua's semantic, the finalizers are called in the reverse order that the objects were marked for for finalization. so the finalizer for the next object
must be called _after_ the current object's finished its execution.

What if it were to add the finalizers to a queue instead?

Also, setmetatable({}, {__gc=function(t) while true do table.insert(t,{}) end end}) -- (instant DoS. try it with a debug hook-based sandbox, it didn't work in Lua 5.1 because you needed either newproxy() or an unprotected userdata metatable to do it. this is also an issue when debugging finalizers with e.g. ZeroBrane Studio.)

Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.