MCPcopy Create free account
hub / github.com/PlutoLang/Pluto / luaD_reallocstack

Function luaD_reallocstack

src/ldo.cpp:330–354  ·  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

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

Callers 3

luaD_growstackFunction · 0.85
luaD_shrinkstackFunction · 0.85
luaE_resetthreadFunction · 0.85

Calls 2

relstackFunction · 0.85
correctstackFunction · 0.85

Tested by

no test coverage detected