** Try to grow the stack by at least 'n' elements. when 'raiseerror' ** is true, raises any error; otherwise, return 0 in case of errors. */
| 217 | ** is true, raises any error; otherwise, return 0 in case of errors. |
| 218 | */ |
| 219 | int luaD_growstack (lua_State *L, int n, int raiseerror) { |
| 220 | int size = stacksize(L); |
| 221 | if (l_unlikely(size > LUAI_MAXSTACK)) { |
| 222 | /* if stack is larger than maximum, thread is already using the |
| 223 | extra space reserved for errors, that is, thread is handling |
| 224 | a stack error; cannot grow further than that. */ |
| 225 | lua_assert(stacksize(L) == ERRORSTACKSIZE); |
| 226 | if (raiseerror) |
| 227 | luaD_throw(L, LUA_ERRERR); /* error inside message handler */ |
| 228 | return 0; /* if not 'raiseerror', just signal it */ |
| 229 | } |
| 230 | else { |
| 231 | int newsize = 2 * size; /* tentative new size */ |
| 232 | int needed = cast_int(L->top - L->stack) + n; |
| 233 | if (newsize > LUAI_MAXSTACK) /* cannot cross the limit */ |
| 234 | newsize = LUAI_MAXSTACK; |
| 235 | if (newsize < needed) /* but must respect what was asked for */ |
| 236 | newsize = needed; |
| 237 | if (l_likely(newsize <= LUAI_MAXSTACK)) |
| 238 | return luaD_reallocstack(L, newsize, raiseerror); |
| 239 | else { /* stack overflow */ |
| 240 | /* add extra size to be able to handle the error message */ |
| 241 | luaD_reallocstack(L, ERRORSTACKSIZE, raiseerror); |
| 242 | if (raiseerror) |
| 243 | luaG_runerror(L, "stack overflow"); |
| 244 | return 0; |
| 245 | } |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | |
| 250 | static int stackinuse (lua_State *L) { |
no test coverage detected