MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / luaD_reallocstack

Function luaD_reallocstack

lib/lua/src/ldo.c:212–235  ·  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

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

Callers 3

luaE_resetthreadFunction · 0.85
luaD_growstackFunction · 0.85
luaD_shrinkstackFunction · 0.85

Calls 3

relstackFunction · 0.85
correctstackFunction · 0.85
GFunction · 0.50

Tested by

no test coverage detected