From 6f207b15fb20f1c7d06224354cfdf5e32fdbba68 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 10 Feb 2003 15:32:50 -0200 Subject: resist errors in finalizers during lua_close --- lstate.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'lstate.c') diff --git a/lstate.c b/lstate.c index 2744a5de..a71a8abe 100644 --- a/lstate.c +++ b/lstate.c @@ -1,5 +1,5 @@ /* -** $Id: lstate.c,v 1.117 2002/12/04 17:38:31 roberto Exp roberto $ +** $Id: lstate.c,v 1.118 2002/12/19 13:21:08 roberto Exp roberto $ ** Global State ** See Copyright Notice in lua.h */ @@ -197,10 +197,18 @@ LUA_API lua_State *lua_open (void) { } +static void callallgcTM (lua_State *L, void *ud) { + UNUSED(ud); + luaC_callGCTM(L); /* call GC metamethods for all udata */ +} + + LUA_API void lua_close (lua_State *L) { lua_lock(L); L = G(L)->mainthread; /* only the main thread can be closed */ - luaC_callallgcTM(L); /* call GC tag methods for all udata */ + luaC_separateudata(L); /* separate udata that have GC metamethods */ + /* repeat until no more errors */ + while (luaD_rawrunprotected(L, callallgcTM, NULL) != 0) /* skip */; lua_assert(G(L)->tmudata == NULL); close_state(L); } -- cgit v1.2.3-55-g6feb