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