diff options
| author | Roberto I <roberto@inf.puc-rio.br> | 2025-12-13 16:16:59 -0300 |
|---|---|---|
| committer | Roberto I <roberto@inf.puc-rio.br> | 2025-12-13 16:16:59 -0300 |
| commit | a5522f06d2679b8f18534fd6a9968f7eb539dc31 (patch) | |
| tree | 65275619e7829b569bfb18dea624358aa17dbc91 /lgc.c | |
| parent | 3d03ae5bd6314f27c8635e06ec363150c2c19062 (diff) | |
| download | lua-a5522f06d2679b8f18534fd6a9968f7eb539dc31.tar.gz lua-a5522f06d2679b8f18534fd6a9968f7eb539dc31.tar.bz2 lua-a5522f06d2679b8f18534fd6a9968f7eb539dc31.zip | |
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.
Diffstat (limited to 'lgc.c')
| -rw-r--r-- | lgc.c | 7 |
1 files changed, 4 insertions, 3 deletions
| @@ -1293,7 +1293,7 @@ static void finishgencycle (lua_State *L, global_State *g) { | |||
| 1293 | correctgraylists(g); | 1293 | correctgraylists(g); |
| 1294 | checkSizes(L, g); | 1294 | checkSizes(L, g); |
| 1295 | g->gcstate = GCSpropagate; /* skip restart */ | 1295 | g->gcstate = GCSpropagate; /* skip restart */ |
| 1296 | if (!g->gcemergency) | 1296 | if (!g->gcemergency && luaD_checkminstack(L)) |
| 1297 | callallpendingfinalizers(L); | 1297 | callallpendingfinalizers(L); |
| 1298 | } | 1298 | } |
| 1299 | 1299 | ||
| @@ -1667,12 +1667,13 @@ static l_mem singlestep (lua_State *L, int fast) { | |||
| 1667 | break; | 1667 | break; |
| 1668 | } | 1668 | } |
| 1669 | case GCScallfin: { /* call finalizers */ | 1669 | case GCScallfin: { /* call finalizers */ |
| 1670 | if (g->tobefnz && !g->gcemergency) { | 1670 | if (g->tobefnz && !g->gcemergency && luaD_checkminstack(L)) { |
| 1671 | g->gcstopem = 0; /* ok collections during finalizers */ | 1671 | g->gcstopem = 0; /* ok collections during finalizers */ |
| 1672 | GCTM(L); /* call one finalizer */ | 1672 | GCTM(L); /* call one finalizer */ |
| 1673 | stepresult = CWUFIN; | 1673 | stepresult = CWUFIN; |
| 1674 | } | 1674 | } |
| 1675 | else { /* emergency mode or no more finalizers */ | 1675 | else { /* no more finalizers or emergency mode or no enough stack |
| 1676 | to run finalizers */ | ||
| 1676 | g->gcstate = GCSpause; /* finish collection */ | 1677 | g->gcstate = GCSpause; /* finish collection */ |
| 1677 | stepresult = step2pause; | 1678 | stepresult = step2pause; |
| 1678 | } | 1679 | } |
