mirror of
https://github.com/lua/lua.git
synced 2026-06-08 08:03:49 +00:00
GC checks stack space before running finalizer
If the stack does not have some minimum available space, the GC defers calling a finalizer until the next cycle. That avoids errors while running a finalizer that the programmer cannot control.
This commit is contained in:
7
lgc.c
7
lgc.c
@@ -1293,7 +1293,7 @@ static void finishgencycle (lua_State *L, global_State *g) {
|
||||
correctgraylists(g);
|
||||
checkSizes(L, g);
|
||||
g->gcstate = GCSpropagate; /* skip restart */
|
||||
if (!g->gcemergency)
|
||||
if (!g->gcemergency && luaD_checkminstack(L))
|
||||
callallpendingfinalizers(L);
|
||||
}
|
||||
|
||||
@@ -1667,12 +1667,13 @@ static l_mem singlestep (lua_State *L, int fast) {
|
||||
break;
|
||||
}
|
||||
case GCScallfin: { /* call finalizers */
|
||||
if (g->tobefnz && !g->gcemergency) {
|
||||
if (g->tobefnz && !g->gcemergency && luaD_checkminstack(L)) {
|
||||
g->gcstopem = 0; /* ok collections during finalizers */
|
||||
GCTM(L); /* call one finalizer */
|
||||
stepresult = CWUFIN;
|
||||
}
|
||||
else { /* emergency mode or no more finalizers */
|
||||
else { /* no more finalizers or emergency mode or no enough stack
|
||||
to run finalizers */
|
||||
g->gcstate = GCSpause; /* finish collection */
|
||||
stepresult = step2pause;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user