aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lgc.c10
-rw-r--r--lstate.c16
2 files changed, 10 insertions, 16 deletions
diff --git a/lgc.c b/lgc.c
index 598fc9d4..1fd19973 100644
--- a/lgc.c
+++ b/lgc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lgc.c,v 2.46 2008/06/23 22:07:44 roberto Exp roberto $ 2** $Id: lgc.c,v 2.47 2008/06/26 19:42:45 roberto Exp roberto $
3** Garbage Collector 3** Garbage Collector
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -599,6 +599,12 @@ static Udata *udata2finalize (global_State *g) {
599} 599}
600 600
601 601
602static void dothecall (lua_State *L, void *ud) {
603 UNUSED(ud);
604 luaD_call(L, L->top - 2, 0);
605}
606
607
602static void GCTM (lua_State *L) { 608static void GCTM (lua_State *L) {
603 global_State *g = G(L); 609 global_State *g = G(L);
604 Udata *udata = udata2finalize(g); 610 Udata *udata = udata2finalize(g);
@@ -611,7 +617,7 @@ static void GCTM (lua_State *L) {
611 setobj2s(L, L->top, tm); 617 setobj2s(L, L->top, tm);
612 setuvalue(L, L->top+1, udata); 618 setuvalue(L, L->top+1, udata);
613 L->top += 2; 619 L->top += 2;
614 luaD_call(L, L->top - 2, 0); 620 luaD_pcall(L, dothecall, NULL, savestack(L, L->top - 2), 0);
615 L->allowhook = oldah; /* restore hooks */ 621 L->allowhook = oldah; /* restore hooks */
616 g->GCthreshold = oldt; /* restore threshold */ 622 g->GCthreshold = oldt; /* restore threshold */
617 } 623 }
diff --git a/lstate.c b/lstate.c
index c57b11d6..be7eed91 100644
--- a/lstate.c
+++ b/lstate.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstate.c,v 2.46 2008/08/13 17:01:33 roberto Exp roberto $ 2** $Id: lstate.c,v 2.47 2008/08/26 13:27:42 roberto Exp roberto $
3** Global State 3** Global State
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -199,25 +199,13 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
199} 199}
200 200
201 201
202static void callallgcTM (lua_State *L, void *ud) {
203 UNUSED(ud);
204 luaC_callAllGCTM(L); /* call GC metamethods for all udata */
205}
206
207
208LUA_API void lua_close (lua_State *L) { 202LUA_API void lua_close (lua_State *L) {
209 L = G(L)->mainthread; /* only the main thread can be closed */ 203 L = G(L)->mainthread; /* only the main thread can be closed */
210 lua_lock(L); 204 lua_lock(L);
211 luaF_close(L, L->stack); /* close all upvalues for this thread */ 205 luaF_close(L, L->stack); /* close all upvalues for this thread */
212 luaC_separateudata(L, 1); /* separate all udata with GC metamethods */ 206 luaC_separateudata(L, 1); /* separate all udata with GC metamethods */
213 lua_assert(L->next == NULL); 207 lua_assert(L->next == NULL);
214 L->errfunc = 0; /* no error function during GC metamethods */ 208 luaC_callAllGCTM(L); /* call GC metamethods for all udata */
215 do { /* repeat until no more errors */
216 L->ci = L->base_ci;
217 L->base = L->top = L->ci->base;
218 G(L)->nCcalls = 0;
219 } while (luaD_rawrunprotected(L, callallgcTM, NULL) != LUA_OK);
220 lua_assert(G(L)->tobefnz == NULL);
221 luai_userstateclose(L); 209 luai_userstateclose(L);
222 close_state(L); 210 close_state(L);
223} 211}