aboutsummaryrefslogtreecommitdiff
path: root/ldo.c
diff options
context:
space:
mode:
Diffstat (limited to 'ldo.c')
-rw-r--r--ldo.c20
1 files changed, 8 insertions, 12 deletions
diff --git a/ldo.c b/ldo.c
index 54518aff..3df6a4b8 100644
--- a/ldo.c
+++ b/ldo.c
@@ -299,17 +299,13 @@ static int stackinuse (lua_State *L) {
299*/ 299*/
300void luaD_shrinkstack (lua_State *L) { 300void luaD_shrinkstack (lua_State *L) {
301 int inuse = stackinuse(L); 301 int inuse = stackinuse(L);
302 int nsize = inuse * 2; /* proposed new size */ 302 int max = (inuse > LUAI_MAXSTACK / 3) ? LUAI_MAXSTACK : inuse * 3;
303 int max = inuse * 3; /* maximum "reasonable" size */
304 if (max > LUAI_MAXSTACK) {
305 max = LUAI_MAXSTACK; /* respect stack limit */
306 if (nsize > LUAI_MAXSTACK)
307 nsize = LUAI_MAXSTACK;
308 }
309 /* if thread is currently not handling a stack overflow and its 303 /* if thread is currently not handling a stack overflow and its
310 size is larger than maximum "reasonable" size, shrink it */ 304 size is larger than maximum "reasonable" size, shrink it */
311 if (inuse <= LUAI_MAXSTACK && stacksize(L) > max) 305 if (inuse <= LUAI_MAXSTACK && stacksize(L) > max) {
306 int nsize = (inuse > LUAI_MAXSTACK / 2) ? LUAI_MAXSTACK : inuse * 2;
312 luaD_reallocstack(L, nsize, 0); /* ok if that fails */ 307 luaD_reallocstack(L, nsize, 0); /* ok if that fails */
308 }
313 else /* don't change stack */ 309 else /* don't change stack */
314 condmovestack(L,{},{}); /* (change only for debugging) */ 310 condmovestack(L,{},{}); /* (change only for debugging) */
315 luaE_shrinkCI(L); /* shrink CI list */ 311 luaE_shrinkCI(L); /* shrink CI list */
@@ -413,7 +409,7 @@ static void rethook (lua_State *L, CallInfo *ci, int nres) {
413** stack, below original 'func', so that 'luaD_precall' can call it. Raise 409** stack, below original 'func', so that 'luaD_precall' can call it. Raise
414** an error if there is no '__call' metafield. 410** an error if there is no '__call' metafield.
415*/ 411*/
416StkId luaD_tryfuncTM (lua_State *L, StkId func) { 412static StkId tryfuncTM (lua_State *L, StkId func) {
417 const TValue *tm; 413 const TValue *tm;
418 StkId p; 414 StkId p;
419 checkstackp(L, 1, func); /* space for metamethod */ 415 checkstackp(L, 1, func); /* space for metamethod */
@@ -572,7 +568,7 @@ int luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func,
572 return -1; 568 return -1;
573 } 569 }
574 default: { /* not a function */ 570 default: { /* not a function */
575 func = luaD_tryfuncTM(L, func); /* try to get '__call' metamethod */ 571 func = tryfuncTM(L, func); /* try to get '__call' metamethod */
576 /* return luaD_pretailcall(L, ci, func, narg1 + 1, delta); */ 572 /* return luaD_pretailcall(L, ci, func, narg1 + 1, delta); */
577 narg1++; 573 narg1++;
578 goto retry; /* try again */ 574 goto retry; /* try again */
@@ -613,7 +609,7 @@ CallInfo *luaD_precall (lua_State *L, StkId func, int nresults) {
613 return ci; 609 return ci;
614 } 610 }
615 default: { /* not a function */ 611 default: { /* not a function */
616 func = luaD_tryfuncTM(L, func); /* try to get '__call' metamethod */ 612 func = tryfuncTM(L, func); /* try to get '__call' metamethod */
617 /* return luaD_precall(L, func, nresults); */ 613 /* return luaD_precall(L, func, nresults); */
618 goto retry; /* try again with metamethod */ 614 goto retry; /* try again with metamethod */
619 } 615 }
@@ -629,7 +625,7 @@ CallInfo *luaD_precall (lua_State *L, StkId func, int nresults) {
629** check the stack before doing anything else. 'luaD_precall' already 625** check the stack before doing anything else. 'luaD_precall' already
630** does that. 626** does that.
631*/ 627*/
632l_sinline void ccall (lua_State *L, StkId func, int nResults, int inc) { 628l_sinline void ccall (lua_State *L, StkId func, int nResults, l_uint32 inc) {
633 CallInfo *ci; 629 CallInfo *ci;
634 L->nCcalls += inc; 630 L->nCcalls += inc;
635 if (l_unlikely(getCcalls(L) >= LUAI_MAXCCALLS)) { 631 if (l_unlikely(getCcalls(L) >= LUAI_MAXCCALLS)) {