Limit number of userdata __gc separations at state close.

This commit is contained in:
Mike Pall 2012-04-11 15:15:50 +02:00
parent e14b6346b4
commit 44876ec99f

View File

@ -234,6 +234,7 @@ static TValue *cpfinalize(lua_State *L, lua_CFunction dummy, void *ud)
LUA_API void lua_close(lua_State *L) LUA_API void lua_close(lua_State *L)
{ {
global_State *g = G(L); global_State *g = G(L);
int i;
L = mainthread(g); /* Only the main thread can be closed. */ L = mainthread(g); /* Only the main thread can be closed. */
lj_func_closeuv(L, tvref(L->stack)); lj_func_closeuv(L, tvref(L->stack));
lj_gc_separateudata(g, 1); /* Separate udata which have GC metamethods. */ lj_gc_separateudata(g, 1); /* Separate udata which have GC metamethods. */
@ -242,7 +243,7 @@ LUA_API void lua_close(lua_State *L)
G2J(g)->state = LJ_TRACE_IDLE; G2J(g)->state = LJ_TRACE_IDLE;
lj_dispatch_update(g); lj_dispatch_update(g);
#endif #endif
for (;;) { for (i = 0; i < 10; ) {
hook_enter(g); hook_enter(g);
L->status = 0; L->status = 0;
L->cframe = NULL; L->cframe = NULL;
@ -251,6 +252,7 @@ LUA_API void lua_close(lua_State *L)
lj_gc_separateudata(g, 1); /* Separate udata again. */ lj_gc_separateudata(g, 1); /* Separate udata again. */
if (gcref(g->gc.mmudata) == NULL) /* Until nothing is left to do. */ if (gcref(g->gc.mmudata) == NULL) /* Until nothing is left to do. */
break; break;
i++;
} }
} }
close_state(L); close_state(L);