summaryrefslogtreecommitdiff
path: root/lib/lua/src/ldo.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/lua/src/ldo.c')
-rw-r--r--lib/lua/src/ldo.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/lib/lua/src/ldo.c b/lib/lua/src/ldo.c
index 6fc6d3c..71e1084 100644
--- a/lib/lua/src/ldo.c
+++ b/lib/lua/src/ldo.c
@@ -1,5 +1,5 @@
/*
-** $Id: ldo.c,v 1.9 2007-07-27 10:05:53 pixel Exp $
+** $Id: ldo.c,v 1.10 2008-02-17 00:35:20 pixel Exp $
** Stack and Call structure of Lua
** See Copyright Notice in lua.h
*/
@@ -83,7 +83,7 @@ static void resetstack (lua_State *L, int status) {
L->base = L->ci->base;
luaF_close(L, L->base); /* close eventual pending closures */
luaD_seterrorobj(L, status, L->base);
- L->nCcalls = 0;
+ L->nCcalls = L->baseCcalls;
L->allowhook = 1;
restore_stack_limit(L);
L->errfunc = 0;
@@ -336,7 +336,7 @@ static StkId callrethooks (lua_State *L, StkId firstResult) {
ptrdiff_t fr = savestack(L, firstResult); /* next call may change stack */
luaD_callhook(L, LUA_HOOKRET, -1);
if (f_isLua(L->ci)) { /* Lua function? */
- while (L->ci->tailcalls--) /* call hook for eventual tail calls */
+ while ((L->hookmask & LUA_MASKRET) && L->ci->tailcalls--) /* tail calls */
luaD_callhook(L, LUA_HOOKTAILRET, -1);
}
return restorestack(L, fr);
@@ -421,22 +421,24 @@ static int resume_error (lua_State *L, const char *msg) {
LUA_API int lua_resume (lua_State *L, int nargs) {
int status;
lua_lock(L);
- if (L->status != LUA_YIELD) {
- if (L->status != 0)
- return resume_error(L, "cannot resume dead coroutine");
- else if (L->ci != L->base_ci)
+ if (L->status != LUA_YIELD && (L->status != 0 || L->ci != L->base_ci))
return resume_error(L, "cannot resume non-suspended coroutine");
- }
+ if (L->nCcalls >= LUAI_MAXCCALLS)
+ return resume_error(L, "C stack overflow");
luai_userstateresume(L, nargs);
- lua_assert(L->errfunc == 0 && L->nCcalls == 0);
+ lua_assert(L->errfunc == 0);
+ L->baseCcalls = ++L->nCcalls;
status = luaD_rawrunprotected(L, resume, L->top - nargs);
if (status != 0) { /* error? */
L->status = cast_byte(status); /* mark thread as `dead' */
luaD_seterrorobj(L, status, L->top);
L->ci->top = L->top;
}
- else
+ else {
+ lua_assert(L->nCcalls == L->baseCcalls);
status = L->status;
+ }
+ --L->nCcalls;
lua_unlock(L);
return status;
}
@@ -445,7 +447,7 @@ LUA_API int lua_resume (lua_State *L, int nargs) {
LUA_API int lua_yield (lua_State *L, int nresults) {
luai_userstateyield(L, nresults);
lua_lock(L);
- if (L->nCcalls > 0)
+ if (L->nCcalls > L->baseCcalls)
luaG_runerror(L, "attempt to yield across metamethod/C-call boundary");
L->base = L->top - nresults; /* protect stack slots below */
L->status = LUA_YIELD;