** Reallocate the stack to a new size, correcting all pointers into ** it. (There are pointers to a stack from its upvalues, from its list ** of call infos, plus a few individual pointers.) The reallocation is ** done in two steps (allocation + free) because the correction must be ** done while both addresses (the old stack and the new one) are valid. ** (In ISO C, any pointer use after the pointe
| 189 | ** to 'raiseerror'. |
| 190 | */ |
| 191 | int luaD_reallocstack (lua_State *L, int newsize, int raiseerror) { |
| 192 | int oldsize = stacksize(L); |
| 193 | int i; |
| 194 | StkId newstack = luaM_reallocvector(L, NULL, 0, |
| 195 | newsize + EXTRA_STACK, StackValue); |
| 196 | lua_assert(newsize <= LUAI_MAXSTACK || newsize == ERRORSTACKSIZE); |
| 197 | if (l_unlikely(newstack == NULL)) { /* reallocation failed? */ |
| 198 | if (raiseerror) |
| 199 | luaM_error(L); |
| 200 | else return 0; /* do not raise an error */ |
| 201 | } |
| 202 | /* number of elements to be copied to the new stack */ |
| 203 | i = ((oldsize <= newsize) ? oldsize : newsize) + EXTRA_STACK; |
| 204 | memcpy(newstack, L->stack, i * sizeof(StackValue)); |
| 205 | for (; i < newsize + EXTRA_STACK; i++) |
| 206 | setnilvalue(s2v(newstack + i)); /* erase new segment */ |
| 207 | correctstack(L, L->stack, newstack); |
| 208 | luaM_freearray(L, L->stack, oldsize + EXTRA_STACK); |
| 209 | L->stack = newstack; |
| 210 | L->stack_last = L->stack + newsize; |
| 211 | return 1; |
| 212 | } |
| 213 | |
| 214 | |
| 215 | /* |
no test coverage detected