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

Function luaD_reallocstack

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

** Reallocate the stack to a new size, correcting all pointers into it. ** In ISO C, any pointer use after the pointer has been deallocated is ** undefined behavior. So, before the reallocation, all pointers are ** changed to offsets, and after the reallocation they are changed back ** to pointers. As during the reallocation the pointers are invalid, the ** reallocation cannot run emergency collec

Source from the content-addressed store, hash-verified

217** to 'raiseerror'.
218*/
219int luaD_reallocstack (lua_State *L, int newsize, int raiseerror) {
220 int oldsize = stacksize(L);
221 int i;
222 StkId newstack;
223 int oldgcstop = G(L)->gcstopem;
224 lua_assert(newsize <= LUAI_MAXSTACK || newsize == ERRORSTACKSIZE);
225 relstack(L); /* change pointers to offsets */
226 G(L)->gcstopem = 1; /* stop emergency collection */
227 newstack = luaM_reallocvector(L, L->stack.p, oldsize + EXTRA_STACK,
228 newsize + EXTRA_STACK, StackValue);
229 G(L)->gcstopem = oldgcstop; /* restore emergency collection */
230 if (l_unlikely(newstack == NULL)) { /* reallocation failed? */
231 correctstack(L); /* change offsets back to pointers */
232 if (raiseerror)
233 luaM_error(L);
234 else return 0; /* do not raise an error */
235 }
236 L->stack.p = newstack;
237 correctstack(L); /* change offsets back to pointers */
238 L->stack_last.p = L->stack.p + newsize;
239 for (i = oldsize + EXTRA_STACK; i < newsize + EXTRA_STACK; i++)
240 setnilvalue(s2v(newstack + i)); /* erase new segment */
241 return 1;
242}
243
244
245/*

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