[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: bug in Lua 5.1.4 with GC, userdata and fenv
- From: Francesco Abbate <francesco.bbt@...>
- Date: Tue, 3 Aug 2010 15:10:35 +0200
2010/8/3 Francesco Abbate <francesco.bbt@gmail.com>:
> Actually the method works very well with the exception of the Lua
> termination. If I terminate the Lua top level with ctrl-D
> (end-of-file) it seems that the whole machinery fails to ensure the
> proper order for finalizers.
It seems that I've found the cause of the problem but it is still very
unclear to me. The problem arise in the function lua_close, shown
below:
LUA_API void lua_close (lua_State *L) {
L = G(L)->mainthread; /* only the main thread can be closed */
lua_lock(L);
luaF_close(L, L->stack); /* close all upvalues for this thread */
luaC_separateudata(L, 1); /* separate udata that have GC metamethods */
L->errfunc = 0; /* no error function during GC metamethods */
do { /* repeat until no more errors */
L->ci = L->base_ci;
L->base = L->top = L->ci->base;
L->nCcalls = L->baseCcalls = 0;
} while (luaD_rawrunprotected(L, callallgcTM, NULL) != 0);
lua_assert(G(L)->tmudata == NULL);
luai_userstateclose(L);
close_state(L);
}
I believe that the function luaC_separateudata followed by callallgcTM
triggers the finalization of all the "dead" userdata even if they are
referenced in a table residing in the registry. I believe the main
idea behind lua_close is that all the userdata object will be
finalized regardless of any existing references. Because of this
behaviour the weak-table that collect the references is unable to
unsure that the finaliser are executed in the proper order.
For the moment I'm stuck, I don't see any solution to my problem...
Francesco