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

Function luaD_reallocstack

third-party/lua-5.5.0/src/ldo.c:322–346  ·  view source on GitHub ↗

** Reallocate the stack to a new size, correcting all pointers into it. ** In case of allocation error, raise an error or return false according ** to 'raiseerror'. */

Source from the content-addressed store, hash-verified

320** to 'raiseerror'.
321*/
322int luaD_reallocstack (lua_State *L, int newsize, int raiseerror) {
323 int oldsize = stacksize(L);
324 int i;
325 StkId newstack;
326 StkId oldstack = L->stack.p;
327 lu_byte oldgcstop = G(L)->gcstopem;
328 lua_assert(newsize <= MAXSTACK || newsize == ERRORSTACKSIZE);
329 relstack(L); /* change pointers to offsets */
330 G(L)->gcstopem = 1; /* stop emergency collection */
331 newstack = luaM_reallocvector(L, oldstack, oldsize + EXTRA_STACK,
332 newsize + EXTRA_STACK, StackValue);
333 G(L)->gcstopem = oldgcstop; /* restore emergency collection */
334 if (l_unlikely(newstack == NULL)) { /* reallocation failed? */
335 correctstack(L, oldstack); /* change offsets back to pointers */
336 if (raiseerror)
337 luaM_error(L);
338 else return 0; /* do not raise an error */
339 }
340 L->stack.p = newstack;
341 correctstack(L, oldstack); /* change offsets back to pointers */
342 L->stack_last.p = L->stack.p + newsize;
343 for (i = oldsize + EXTRA_STACK; i < newsize + EXTRA_STACK; i++)
344 setnilvalue(s2v(newstack + i)); /* erase new segment */
345 return 1;
346}
347
348
349/*

Callers 3

luaE_resetthreadFunction · 0.70
luaD_growstackFunction · 0.70
luaD_shrinkstackFunction · 0.70

Calls 2

relstackFunction · 0.70
correctstackFunction · 0.70

Tested by

no test coverage detected