** 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
| 272 | ** will be reduced to a "regular" size. |
| 273 | */ |
| 274 | void 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 | |
| 293 | void luaD_inctop (lua_State *L) { |
no test coverage detected