MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / luaD_shrinkstack

Function luaD_shrinkstack

third-party/lua-5.4.6/src/ldo.c:307–319  ·  view source on GitHub ↗

** If stack size is more than 3 times the current use, reduce that size ** to twice the current use. (So, the final stack size is at most 2/3 the ** previous size, and half of its entries are empty.) ** As a particular case, if stack was handling a stack overflow and now ** it is not, 'max' (limited by LUAI_MAXSTACK) will be smaller than ** stacksize (equal to ERRORSTACKSIZE in this case), and so

Source from the content-addressed store, hash-verified

305** will be reduced to a "regular" size.
306*/
307void luaD_shrinkstack (lua_State *L) {
308 int inuse = stackinuse(L);
309 int max = (inuse > LUAI_MAXSTACK / 3) ? LUAI_MAXSTACK : inuse * 3;
310 /* if thread is currently not handling a stack overflow and its
311 size is larger than maximum "reasonable" size, shrink it */
312 if (inuse <= LUAI_MAXSTACK && stacksize(L) > max) {
313 int nsize = (inuse > LUAI_MAXSTACK / 2) ? LUAI_MAXSTACK : inuse * 2;
314 luaD_reallocstack(L, nsize, 0); /* ok if that fails */
315 }
316 else /* don't change stack */
317 condmovestack(L,{},{}); /* (change only for debugging) */
318 luaE_shrinkCI(L); /* shrink CI list */
319}
320
321
322void luaD_inctop (lua_State *L) {

Callers 3

finishpcallkFunction · 0.70
luaD_pcallFunction · 0.70
traversethreadFunction · 0.70

Calls 3

stackinuseFunction · 0.70
luaD_reallocstackFunction · 0.70
luaE_shrinkCIFunction · 0.70

Tested by

no test coverage detected