MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / luaD_shrinkstack

Function luaD_shrinkstack

3rd/lua-5.4.3/src/ldo.c:274–290  ·  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

272** will be reduced to a "regular" size.
273*/
274void luaD_shrinkstack (lua_State *L) {
275 int inuse = stackinuse(L);
276 int nsize = inuse * 2; /* proposed new size */
277 int max = inuse * 3; /* maximum "reasonable" size */
278 if (max > LUAI_MAXSTACK) {
279 max = LUAI_MAXSTACK; /* respect stack limit */
280 if (nsize > LUAI_MAXSTACK)
281 nsize = LUAI_MAXSTACK;
282 }
283 /* if thread is currently not handling a stack overflow and its
284 size is larger than maximum "reasonable" size, shrink it */
285 if (inuse <= LUAI_MAXSTACK && stacksize(L) > max)
286 luaD_reallocstack(L, nsize, 0); /* ok if that fails */
287 else /* don't change stack */
288 condmovestack(L,{},{}); /* (change only for debugging) */
289 luaE_shrinkCI(L); /* shrink CI list */
290}
291
292
293void luaD_inctop (lua_State *L) {

Callers 3

finishpcallkFunction · 0.85
luaD_pcallFunction · 0.85
traversethreadFunction · 0.85

Calls 3

stackinuseFunction · 0.85
luaD_reallocstackFunction · 0.85
luaE_shrinkCIFunction · 0.85

Tested by

no test coverage detected