diff options
Diffstat (limited to 'ldo.c')
-rw-r--r-- | ldo.c | 9 |
1 files changed, 6 insertions, 3 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.c,v 2.201 2018/05/22 12:02:36 roberto Exp roberto $ | 2 | ** $Id: ldo.c $ |
3 | ** Stack and Call structure of Lua | 3 | ** Stack and Call structure of Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -137,6 +137,7 @@ l_noret luaD_throw (lua_State *L, int errcode) { | |||
137 | int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) { | 137 | int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) { |
138 | unsigned short oldnCcalls = L->nCcalls - L->nci; | 138 | unsigned short oldnCcalls = L->nCcalls - L->nci; |
139 | struct lua_longjmp lj; | 139 | struct lua_longjmp lj; |
140 | lua_assert(L->nCcalls >= L->nci); | ||
140 | lj.status = LUA_OK; | 141 | lj.status = LUA_OK; |
141 | lj.previous = L->errorJmp; /* chain new error handler */ | 142 | lj.previous = L->errorJmp; /* chain new error handler */ |
142 | L->errorJmp = &lj; | 143 | L->errorJmp = &lj; |
@@ -653,7 +654,10 @@ LUA_API int lua_resume (lua_State *L, lua_State *from, int nargs, | |||
653 | } | 654 | } |
654 | else if (L->status != LUA_YIELD) | 655 | else if (L->status != LUA_YIELD) |
655 | return resume_error(L, "cannot resume dead coroutine", nargs); | 656 | return resume_error(L, "cannot resume dead coroutine", nargs); |
656 | L->nCcalls = (from) ? from->nCcalls + 1 : 1; | 657 | if (from == NULL) |
658 | L->nCcalls = 1; | ||
659 | else /* correct 'nCcalls' for this thread */ | ||
660 | L->nCcalls = from->nCcalls - from->nci + L->nci + 1; | ||
657 | if (L->nCcalls >= LUAI_MAXCCALLS) | 661 | if (L->nCcalls >= LUAI_MAXCCALLS) |
658 | return resume_error(L, "C stack overflow", nargs); | 662 | return resume_error(L, "C stack overflow", nargs); |
659 | luai_userstateresume(L, nargs); | 663 | luai_userstateresume(L, nargs); |
@@ -677,7 +681,6 @@ LUA_API int lua_resume (lua_State *L, lua_State *from, int nargs, | |||
677 | *nresults = (status == LUA_YIELD) ? L->ci->u2.nyield | 681 | *nresults = (status == LUA_YIELD) ? L->ci->u2.nyield |
678 | : cast_int(L->top - (L->ci->func + 1)); | 682 | : cast_int(L->top - (L->ci->func + 1)); |
679 | L->nny = oldnny; /* restore 'nny' */ | 683 | L->nny = oldnny; /* restore 'nny' */ |
680 | L->nCcalls--; | ||
681 | lua_unlock(L); | 684 | lua_unlock(L); |
682 | return status; | 685 | return status; |
683 | } | 686 | } |