MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / luaD_shrinkstack

Function luaD_shrinkstack

lib/lua/src/ldo.c:300–312  ·  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

298** will be reduced to a "regular" size.
299*/
300void luaD_shrinkstack (lua_State *L) {
301 int inuse = stackinuse(L);
302 int max = (inuse > LUAI_MAXSTACK / 3) ? LUAI_MAXSTACK : inuse * 3;
303 /* if thread is currently not handling a stack overflow and its
304 size is larger than maximum "reasonable" size, shrink it */
305 if (inuse <= LUAI_MAXSTACK && stacksize(L) > max) {
306 int nsize = (inuse > LUAI_MAXSTACK / 2) ? LUAI_MAXSTACK : inuse * 2;
307 luaD_reallocstack(L, nsize, 0); /* ok if that fails */
308 }
309 else /* don't change stack */
310 condmovestack(L,{},{}); /* (change only for debugging) */
311 luaE_shrinkCI(L); /* shrink CI list */
312}
313
314
315void 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