** Try to grow the stack by at least 'n' elements. when 'raiseerror' ** is true, raises any error; otherwise, return 0 in case of errors. */
| 207 | ** is true, raises any error; otherwise, return 0 in case of errors. |
| 208 | */ |
| 209 | int luaD_growstack (lua_State *L, int n, int raiseerror) { |
| 210 | int size = L->stacksize; |
| 211 | int newsize = 2 * size; /* tentative new size */ |
| 212 | if (unlikely(size > LUAI_MAXSTACK)) { /* need more space after extra size? */ |
| 213 | if (raiseerror) |
| 214 | luaD_throw(L, LUA_ERRERR); /* error inside message handler */ |
| 215 | else return 0; |
| 216 | } |
| 217 | else { |
| 218 | int needed = cast_int(L->top - L->stack) + n + EXTRA_STACK; |
| 219 | if (newsize > LUAI_MAXSTACK) /* cannot cross the limit */ |
| 220 | newsize = LUAI_MAXSTACK; |
| 221 | if (newsize < needed) /* but must respect what was asked for */ |
| 222 | newsize = needed; |
| 223 | if (unlikely(newsize > LUAI_MAXSTACK)) { /* stack overflow? */ |
| 224 | /* add extra size to be able to handle the error message */ |
| 225 | luaD_reallocstack(L, ERRORSTACKSIZE, raiseerror); |
| 226 | if (raiseerror) |
| 227 | luaG_runerror(L, "stack overflow"); |
| 228 | else return 0; |
| 229 | } |
| 230 | } /* else no errors */ |
| 231 | return luaD_reallocstack(L, newsize, raiseerror); |
| 232 | } |
| 233 | |
| 234 | |
| 235 | static int stackinuse (lua_State *L) { |
no test coverage detected