MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / luaD_growstack

Function luaD_growstack

third-party/lua-5.4.6/src/ldo.c:249–276  ·  view source on GitHub ↗

** Try to grow the stack by at least 'n' elements. When 'raiseerror' ** is true, raises any error; otherwise, return 0 in case of errors. */

Source from the content-addressed store, hash-verified

247** is true, raises any error; otherwise, return 0 in case of errors.
248*/
249int luaD_growstack (lua_State *L, int n, int raiseerror) {
250 int size = stacksize(L);
251 if (l_unlikely(size > LUAI_MAXSTACK)) {
252 /* if stack is larger than maximum, thread is already using the
253 extra space reserved for errors, that is, thread is handling
254 a stack error; cannot grow further than that. */
255 lua_assert(stacksize(L) == ERRORSTACKSIZE);
256 if (raiseerror)
257 luaD_errerr(L); /* error inside message handler */
258 return 0; /* if not 'raiseerror', just signal it */
259 }
260 else if (n < LUAI_MAXSTACK) { /* avoids arithmetic overflows */
261 int newsize = 2 * size; /* tentative new size */
262 int needed = cast_int(L->top.p - L->stack.p) + n;
263 if (newsize > LUAI_MAXSTACK) /* cannot cross the limit */
264 newsize = LUAI_MAXSTACK;
265 if (newsize < needed) /* but must respect what was asked for */
266 newsize = needed;
267 if (l_likely(newsize <= LUAI_MAXSTACK))
268 return luaD_reallocstack(L, newsize, raiseerror);
269 }
270 /* else stack overflow */
271 /* add extra size to be able to handle the error message */
272 luaD_reallocstack(L, ERRORSTACKSIZE, raiseerror);
273 if (raiseerror)
274 luaG_runerror(L, "stack overflow");
275 return 0;
276}
277
278
279/*

Callers 1

lua_checkstackFunction · 0.70

Calls 3

luaD_errerrFunction · 0.70
luaD_reallocstackFunction · 0.70
luaG_runerrorFunction · 0.70

Tested by

no test coverage detected