** 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
| 210 | ** to 'raiseerror'. |
| 211 | */ |
| 212 | int 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 | /* |
no test coverage detected