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:
11
ldo.c
11
ldo.c
@@ -220,6 +220,17 @@ l_noret luaD_errerr (lua_State *L) {
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Check whether stack has enough space to run a simple function (such
|
||||
** as a finalizer): At least BASIC_STACK_SIZE in the Lua stack and
|
||||
** 2 slots in the C stack.
|
||||
*/
|
||||
int luaD_checkminstack (lua_State *L) {
|
||||
return ((stacksize(L) < MAXSTACK - BASIC_STACK_SIZE) &&
|
||||
(getCcalls(L) < LUAI_MAXCCALLS - 2));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** In ISO C, any pointer use after the pointer has been deallocated is
|
||||
** undefined behavior. So, before a stack reallocation, all pointers
|
||||
|
||||
Reference in New Issue
Block a user