aboutsummaryrefslogtreecommitdiff
path: root/src/lua/ldo.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lua/ldo.c')
-rw-r--r--src/lua/ldo.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/src/lua/ldo.c b/src/lua/ldo.c
index c563b1d..4c976a1 100644
--- a/src/lua/ldo.c
+++ b/src/lua/ldo.c
@@ -245,13 +245,12 @@ static int stackinuse (lua_State *L) {
245 245
246void luaD_shrinkstack (lua_State *L) { 246void luaD_shrinkstack (lua_State *L) {
247 int inuse = stackinuse(L); 247 int inuse = stackinuse(L);
248 int goodsize = inuse + (inuse / 8) + 2*EXTRA_STACK; 248 int goodsize = inuse + BASIC_STACK_SIZE;
249 if (goodsize > LUAI_MAXSTACK) 249 if (goodsize > LUAI_MAXSTACK)
250 goodsize = LUAI_MAXSTACK; /* respect stack limit */ 250 goodsize = LUAI_MAXSTACK; /* respect stack limit */
251 /* if thread is currently not handling a stack overflow and its 251 /* if thread is currently not handling a stack overflow and its
252 good size is smaller than current size, shrink its stack */ 252 good size is smaller than current size, shrink its stack */
253 if (inuse <= (LUAI_MAXSTACK - EXTRA_STACK) && 253 if (inuse <= (LUAI_MAXSTACK - EXTRA_STACK) && goodsize < L->stacksize)
254 goodsize < L->stacksize)
255 luaD_reallocstack(L, goodsize, 0); /* ok if that fails */ 254 luaD_reallocstack(L, goodsize, 0); /* ok if that fails */
256 else /* don't change stack */ 255 else /* don't change stack */
257 condmovestack(L,{},{}); /* (change only for debugging) */ 256 condmovestack(L,{},{}); /* (change only for debugging) */
@@ -466,13 +465,13 @@ void luaD_call (lua_State *L, StkId func, int nresults) {
466 f = fvalue(s2v(func)); 465 f = fvalue(s2v(func));
467 Cfunc: { 466 Cfunc: {
468 int n; /* number of returns */ 467 int n; /* number of returns */
469 CallInfo *ci = next_ci(L); 468 CallInfo *ci;
470 checkstackp(L, LUA_MINSTACK, func); /* ensure minimum stack size */ 469 checkstackGCp(L, LUA_MINSTACK, func); /* ensure minimum stack size */
470 L->ci = ci = next_ci(L);
471 ci->nresults = nresults; 471 ci->nresults = nresults;
472 ci->callstatus = CIST_C; 472 ci->callstatus = CIST_C;
473 ci->top = L->top + LUA_MINSTACK; 473 ci->top = L->top + LUA_MINSTACK;
474 ci->func = func; 474 ci->func = func;
475 L->ci = ci;
476 lua_assert(ci->top <= L->stack_last); 475 lua_assert(ci->top <= L->stack_last);
477 if (L->hookmask & LUA_MASKCALL) { 476 if (L->hookmask & LUA_MASKCALL) {
478 int narg = cast_int(L->top - func) - 1; 477 int narg = cast_int(L->top - func) - 1;
@@ -486,12 +485,13 @@ void luaD_call (lua_State *L, StkId func, int nresults) {
486 break; 485 break;
487 } 486 }
488 case LUA_VLCL: { /* Lua function */ 487 case LUA_VLCL: { /* Lua function */
489 CallInfo *ci = next_ci(L); 488 CallInfo *ci;
490 Proto *p = clLvalue(s2v(func))->p; 489 Proto *p = clLvalue(s2v(func))->p;
491 int narg = cast_int(L->top - func) - 1; /* number of real arguments */ 490 int narg = cast_int(L->top - func) - 1; /* number of real arguments */
492 int nfixparams = p->numparams; 491 int nfixparams = p->numparams;
493 int fsize = p->maxstacksize; /* frame size */ 492 int fsize = p->maxstacksize; /* frame size */
494 checkstackp(L, fsize, func); 493 checkstackGCp(L, fsize, func);
494 L->ci = ci = next_ci(L);
495 ci->nresults = nresults; 495 ci->nresults = nresults;
496 ci->u.l.savedpc = p->code; /* starting point */ 496 ci->u.l.savedpc = p->code; /* starting point */
497 ci->callstatus = 0; 497 ci->callstatus = 0;
@@ -505,7 +505,7 @@ void luaD_call (lua_State *L, StkId func, int nresults) {
505 break; 505 break;
506 } 506 }
507 default: { /* not a function */ 507 default: { /* not a function */
508 checkstackp(L, 1, func); /* space for metamethod */ 508 checkstackGCp(L, 1, func); /* space for metamethod */
509 luaD_tryfuncTM(L, func); /* try to get '__call' metamethod */ 509 luaD_tryfuncTM(L, func); /* try to get '__call' metamethod */
510 goto retry; /* try again with metamethod */ 510 goto retry; /* try again with metamethod */
511 } 511 }
@@ -674,7 +674,7 @@ LUA_API int lua_resume (lua_State *L, lua_State *from, int nargs,
674 if (from == NULL) 674 if (from == NULL)
675 L->nCcalls = CSTACKTHREAD; 675 L->nCcalls = CSTACKTHREAD;
676 else /* correct 'nCcalls' for this thread */ 676 else /* correct 'nCcalls' for this thread */
677 L->nCcalls = getCcalls(from) + from->nci - L->nci - CSTACKCF; 677 L->nCcalls = getCcalls(from) - L->nci - CSTACKCF;
678 if (L->nCcalls <= CSTACKERR) 678 if (L->nCcalls <= CSTACKERR)
679 return resume_error(L, "C stack overflow", nargs); 679 return resume_error(L, "C stack overflow", nargs);
680 luai_userstateresume(L, nargs); 680 luai_userstateresume(L, nargs);
@@ -706,9 +706,10 @@ LUA_API int lua_isyieldable (lua_State *L) {
706 706
707LUA_API int lua_yieldk (lua_State *L, int nresults, lua_KContext ctx, 707LUA_API int lua_yieldk (lua_State *L, int nresults, lua_KContext ctx,
708 lua_KFunction k) { 708 lua_KFunction k) {
709 CallInfo *ci = L->ci; 709 CallInfo *ci;
710 luai_userstateyield(L, nresults); 710 luai_userstateyield(L, nresults);
711 lua_lock(L); 711 lua_lock(L);
712 ci = L->ci;
712 api_checknelems(L, nresults); 713 api_checknelems(L, nresults);
713 if (unlikely(!yieldable(L))) { 714 if (unlikely(!yieldable(L))) {
714 if (L != G(L)->mainthread) 715 if (L != G(L)->mainthread)