diff options
Diffstat (limited to 'ldo.c')
-rw-r--r-- | ldo.c | 19 |
1 files changed, 9 insertions, 10 deletions
@@ -182,10 +182,10 @@ static void correctstack (lua_State *L, StkId oldstack, StkId newstack) { | |||
182 | 182 | ||
183 | 183 | ||
184 | int luaD_reallocstack (lua_State *L, int newsize, int raiseerror) { | 184 | int luaD_reallocstack (lua_State *L, int newsize, int raiseerror) { |
185 | int lim = L->stacksize; | 185 | int lim = stacksize(L); |
186 | StkId newstack = luaM_reallocvector(L, L->stack, lim, newsize, StackValue); | 186 | StkId newstack = luaM_reallocvector(L, L->stack, |
187 | lim + EXTRA_STACK, newsize + EXTRA_STACK, StackValue); | ||
187 | lua_assert(newsize <= LUAI_MAXSTACK || newsize == ERRORSTACKSIZE); | 188 | lua_assert(newsize <= LUAI_MAXSTACK || newsize == ERRORSTACKSIZE); |
188 | lua_assert(L->stack_last - L->stack == L->stacksize - EXTRA_STACK); | ||
189 | if (unlikely(newstack == NULL)) { /* reallocation failed? */ | 189 | if (unlikely(newstack == NULL)) { /* reallocation failed? */ |
190 | if (raiseerror) | 190 | if (raiseerror) |
191 | luaM_error(L); | 191 | luaM_error(L); |
@@ -195,8 +195,7 @@ int luaD_reallocstack (lua_State *L, int newsize, int raiseerror) { | |||
195 | setnilvalue(s2v(newstack + lim)); /* erase new segment */ | 195 | setnilvalue(s2v(newstack + lim)); /* erase new segment */ |
196 | correctstack(L, L->stack, newstack); | 196 | correctstack(L, L->stack, newstack); |
197 | L->stack = newstack; | 197 | L->stack = newstack; |
198 | L->stacksize = newsize; | 198 | L->stack_last = L->stack + newsize; |
199 | L->stack_last = L->stack + newsize - EXTRA_STACK; | ||
200 | return 1; | 199 | return 1; |
201 | } | 200 | } |
202 | 201 | ||
@@ -206,19 +205,19 @@ int luaD_reallocstack (lua_State *L, int newsize, int raiseerror) { | |||
206 | ** is true, raises any error; otherwise, return 0 in case of errors. | 205 | ** is true, raises any error; otherwise, return 0 in case of errors. |
207 | */ | 206 | */ |
208 | int luaD_growstack (lua_State *L, int n, int raiseerror) { | 207 | int luaD_growstack (lua_State *L, int n, int raiseerror) { |
209 | int size = L->stacksize; | 208 | int size = stacksize(L); |
210 | if (unlikely(size > LUAI_MAXSTACK)) { | 209 | if (unlikely(size > LUAI_MAXSTACK)) { |
211 | /* if stack is larger than maximum, thread is already using the | 210 | /* if stack is larger than maximum, thread is already using the |
212 | extra space reserved for errors, that is, thread is handling | 211 | extra space reserved for errors, that is, thread is handling |
213 | a stack error; cannot grow further than that. */ | 212 | a stack error; cannot grow further than that. */ |
214 | lua_assert(L->stacksize == ERRORSTACKSIZE); | 213 | lua_assert(stacksize(L) == ERRORSTACKSIZE); |
215 | if (raiseerror) | 214 | if (raiseerror) |
216 | luaD_throw(L, LUA_ERRERR); /* error inside message handler */ | 215 | luaD_throw(L, LUA_ERRERR); /* error inside message handler */ |
217 | return 0; /* if not 'raiseerror', just signal it */ | 216 | return 0; /* if not 'raiseerror', just signal it */ |
218 | } | 217 | } |
219 | else { | 218 | else { |
220 | int newsize = 2 * size; /* tentative new size */ | 219 | int newsize = 2 * size; /* tentative new size */ |
221 | int needed = cast_int(L->top - L->stack) + n + EXTRA_STACK; | 220 | int needed = cast_int(L->top - L->stack) + n; |
222 | if (newsize > LUAI_MAXSTACK) /* cannot cross the limit */ | 221 | if (newsize > LUAI_MAXSTACK) /* cannot cross the limit */ |
223 | newsize = LUAI_MAXSTACK; | 222 | newsize = LUAI_MAXSTACK; |
224 | if (newsize < needed) /* but must respect what was asked for */ | 223 | if (newsize < needed) /* but must respect what was asked for */ |
@@ -257,7 +256,7 @@ static int stackinuse (lua_State *L) { | |||
257 | ** previous size, and half of its entries are empty.) | 256 | ** previous size, and half of its entries are empty.) |
258 | ** As a particular case, if stack was handling a stack overflow and now | 257 | ** As a particular case, if stack was handling a stack overflow and now |
259 | ** it is not, 'max' (limited by LUAI_MAXSTACK) will be smaller than | 258 | ** it is not, 'max' (limited by LUAI_MAXSTACK) will be smaller than |
260 | ** 'stacksize' (equal to ERRORSTACKSIZE in this case), and so the stack | 259 | ** stacksize (equal to ERRORSTACKSIZE in this case), and so the stack |
261 | ** will be reduced to a "regular" size. | 260 | ** will be reduced to a "regular" size. |
262 | */ | 261 | */ |
263 | void luaD_shrinkstack (lua_State *L) { | 262 | void luaD_shrinkstack (lua_State *L) { |
@@ -271,7 +270,7 @@ void luaD_shrinkstack (lua_State *L) { | |||
271 | } | 270 | } |
272 | /* if thread is currently not handling a stack overflow and its | 271 | /* if thread is currently not handling a stack overflow and its |
273 | size is larger than maximum "reasonable" size, shrink it */ | 272 | size is larger than maximum "reasonable" size, shrink it */ |
274 | if (inuse <= (LUAI_MAXSTACK - EXTRA_STACK) && L->stacksize > max) | 273 | if (inuse <= LUAI_MAXSTACK && stacksize(L) > max) |
275 | luaD_reallocstack(L, nsize, 0); /* ok if that fails */ | 274 | luaD_reallocstack(L, nsize, 0); /* ok if that fails */ |
276 | else /* don't change stack */ | 275 | else /* don't change stack */ |
277 | condmovestack(L,{},{}); /* (change only for debugging) */ | 276 | condmovestack(L,{},{}); /* (change only for debugging) */ |