lua

A copy of the Lua development repository
Log | Files | Refs | README

commit 3dc5475e239e2da52a380288ae8b293a6b019f81
parent 8a008a20579dd6818cb770147c8765b72eb2acfe
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date:   Tue, 23 Aug 2011 14:24:10 -0300

'nCcalls' should be local to each thread, as each thread may have its
own C stack (with LuaThreads or something similar)

Diffstat:
Mlcorolib.c | 4++--
Mldo.c | 28++++++++++++++--------------
Mlparser.c | 12++++++------
Mlstate.c | 4++--
Mlstate.h | 4++--
Mltests.c | 6+++---
Mlua.h | 4++--
7 files changed, 31 insertions(+), 31 deletions(-)

diff --git a/lcorolib.c b/lcorolib.c @@ -1,5 +1,5 @@ /* -** $Id: lcorolib.c,v 1.1 2010/06/10 21:30:26 roberto Exp roberto $ +** $Id: lcorolib.c,v 1.2 2010/07/02 11:38:13 roberto Exp roberto $ ** Coroutine Library ** See Copyright Notice in lua.h */ @@ -28,7 +28,7 @@ static int auxresume (lua_State *L, lua_State *co, int narg) { return -1; /* error flag */ } lua_xmove(L, co, narg); - status = lua_resume(co, narg); + status = lua_resume(co, L, narg); if (status == LUA_OK || status == LUA_YIELD) { int nres = lua_gettop(co); if (!lua_checkstack(L, nres + 1)) { diff --git a/ldo.c b/ldo.c @@ -1,5 +1,5 @@ /* -** $Id: ldo.c,v 2.97 2011/06/20 16:36:03 roberto Exp roberto $ +** $Id: ldo.c,v 2.98 2011/06/28 15:42:04 roberto Exp roberto $ ** Stack and Call structure of Lua ** See Copyright Notice in lua.h */ @@ -123,7 +123,7 @@ void luaD_throw (lua_State *L, int errcode) { int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) { - unsigned short oldnCcalls = G(L)->nCcalls; + unsigned short oldnCcalls = L->nCcalls; struct lua_longjmp lj; lj.status = LUA_OK; lj.previous = L->errorJmp; /* chain new error handler */ @@ -132,7 +132,7 @@ int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) { (*f)(L, ud); ); L->errorJmp = lj.previous; /* restore old error handler */ - G(L)->nCcalls = oldnCcalls; + L->nCcalls = oldnCcalls; return lj.status; } @@ -382,18 +382,17 @@ int luaD_poscall (lua_State *L, StkId firstResult) { ** function position. */ void luaD_call (lua_State *L, StkId func, int nResults, int allowyield) { - global_State *g = G(L); - if (++g->nCcalls >= LUAI_MAXCCALLS) { - if (g->nCcalls == LUAI_MAXCCALLS) + if (++L->nCcalls >= LUAI_MAXCCALLS) { + if (L->nCcalls == LUAI_MAXCCALLS) luaG_runerror(L, "C stack overflow"); - else if (g->nCcalls >= (LUAI_MAXCCALLS + (LUAI_MAXCCALLS>>3))) + else if (L->nCcalls >= (LUAI_MAXCCALLS + (LUAI_MAXCCALLS>>3))) luaD_throw(L, LUA_ERRERR); /* error while handing stack error */ } if (!allowyield) L->nny++; if (!luaD_precall(L, func, nResults)) /* is a Lua function? */ luaV_execute(L); /* call it */ if (!allowyield) L->nny--; - g->nCcalls--; + L->nCcalls--; luaC_checkGC(L); } @@ -404,7 +403,7 @@ static void finishCcall (lua_State *L) { lua_assert(ci->u.c.k != NULL); /* must have a continuation */ lua_assert(L->nny == 0); /* finish 'luaD_call' */ - G(L)->nCcalls--; + L->nCcalls--; /* finish 'lua_callk' */ adjustresults(L, ci->nresults); /* call continuation function */ @@ -487,7 +486,7 @@ static void resume_error (lua_State *L, const char *msg, StkId firstArg) { static void resume (lua_State *L, void *ud) { StkId firstArg = cast(StkId, ud); CallInfo *ci = L->ci; - if (G(L)->nCcalls >= LUAI_MAXCCALLS) + if (L->nCcalls >= LUAI_MAXCCALLS) resume_error(L, "C stack overflow", firstArg); if (L->status == LUA_OK) { /* may be starting a coroutine */ if (ci != &L->base_ci) /* not in base level? */ @@ -514,7 +513,7 @@ static void resume (lua_State *L, void *ud) { api_checknelems(L, n); firstArg = L->top - n; /* yield results come from continuation */ } - G(L)->nCcalls--; /* finish 'luaD_call' */ + L->nCcalls--; /* finish 'luaD_call' */ luaD_poscall(L, firstArg); /* finish 'luaD_precall' */ } unroll(L, NULL); @@ -522,11 +521,11 @@ static void resume (lua_State *L, void *ud) { } -LUA_API int lua_resume (lua_State *L, int nargs) { +LUA_API int lua_resume (lua_State *L, lua_State *from, int nargs) { int status; lua_lock(L); luai_userstateresume(L, nargs); - ++G(L)->nCcalls; /* count resume */ + L->nCcalls = (from) ? from->nCcalls + 1 : 1; L->nny = 0; /* allow yields */ api_checknelems(L, (L->status == LUA_OK) ? nargs + 1 : nargs); status = luaD_rawrunprotected(L, resume, L->top - nargs); @@ -546,7 +545,8 @@ LUA_API int lua_resume (lua_State *L, int nargs) { lua_assert(status == L->status); } L->nny = 1; /* do not allow yields */ - --G(L)->nCcalls; + L->nCcalls--; + lua_assert(L->nCcalls == ((from) ? from->nCcalls : 0)); lua_unlock(L); return status; } diff --git a/lparser.c b/lparser.c @@ -1,5 +1,5 @@ /* -** $Id: lparser.c,v 2.114 2011/07/15 12:50:29 roberto Exp roberto $ +** $Id: lparser.c,v 2.115 2011/07/27 18:09:01 roberto Exp roberto $ ** Lua Parser ** See Copyright Notice in lua.h */ @@ -328,13 +328,13 @@ static void adjust_assign (LexState *ls, int nvars, int nexps, expdesc *e) { static void enterlevel (LexState *ls) { - global_State *g = G(ls->L); - ++g->nCcalls; - checklimit(ls->fs, g->nCcalls, LUAI_MAXCCALLS, "syntax levels"); + lua_State *L = ls->L; + ++L->nCcalls; + checklimit(ls->fs, L->nCcalls, LUAI_MAXCCALLS, "syntax levels"); } -#define leavelevel(ls) (G((ls)->L)->nCcalls--) +#define leavelevel(ls) ((ls)->L->nCcalls--) static void closegoto (LexState *ls, int g, Labeldesc *label) { @@ -1144,7 +1144,7 @@ static void assignment (LexState *ls, struct LHS_assign *lh, int nvars) { primaryexp(ls, &nv.v); if (nv.v.k != VINDEXED) check_conflict(ls, lh, &nv.v); - checklimit(ls->fs, nvars, LUAI_MAXCCALLS - G(ls->L)->nCcalls, + checklimit(ls->fs, nvars, LUAI_MAXCCALLS - ls->L->nCcalls, "variable names"); assignment(ls, &nv, nvars+1); } diff --git a/lstate.c b/lstate.c @@ -1,5 +1,5 @@ /* -** $Id: lstate.c,v 2.89 2010/12/20 19:40:07 roberto Exp roberto $ +** $Id: lstate.c,v 2.90 2011/08/09 20:58:29 roberto Exp roberto $ ** Global State ** See Copyright Notice in lua.h */ @@ -171,6 +171,7 @@ static void preinit_state (lua_State *L, global_State *g) { L->ci = NULL; L->stacksize = 0; L->errorJmp = NULL; + L->nCcalls = 0; L->hook = NULL; L->hookmask = 0; L->basehookcount = 0; @@ -237,7 +238,6 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { g->currentwhite = bit2mask(WHITE0BIT, FIXEDBIT); L->marked = luaC_white(g); g->gckind = KGC_NORMAL; - g->nCcalls = 0; preinit_state(L, g); g->frealloc = f; g->ud = ud; diff --git a/lstate.h b/lstate.h @@ -1,5 +1,5 @@ /* -** $Id: lstate.h,v 2.71 2010/12/20 19:40:07 roberto Exp roberto $ +** $Id: lstate.h,v 2.72 2011/06/02 19:31:40 roberto Exp roberto $ ** Global State ** See Copyright Notice in lua.h */ @@ -118,7 +118,6 @@ typedef struct global_State { lu_mem lastmajormem; /* memory in use after last major collection */ stringtable strt; /* hash table for strings */ TValue l_registry; - unsigned short nCcalls; /* number of nested C calls */ lu_byte currentwhite; lu_byte gcstate; /* state of garbage collector */ lu_byte gckind; /* kind of GC running */ @@ -161,6 +160,7 @@ struct lua_State { StkId stack; /* stack base */ int stacksize; unsigned short nny; /* number of non-yieldable calls in stack */ + unsigned short nCcalls; /* number of nested C calls */ lu_byte hookmask; lu_byte allowhook; int basehookcount; diff --git a/ltests.c b/ltests.c @@ -1,5 +1,5 @@ /* -** $Id: ltests.c,v 2.120 2011/06/24 14:36:21 roberto Exp roberto $ +** $Id: ltests.c,v 2.121 2011/07/02 15:59:17 roberto Exp roberto $ ** Internal Module for Debugging of the Lua Implementation ** See Copyright Notice in lua.h */ @@ -1210,7 +1210,7 @@ static int runC (lua_State *L, lua_State *L1, const char *pc) { } else if EQ("resume") { int i = getindex; - status = lua_resume(lua_tothread(L1, i), getnum); + status = lua_resume(lua_tothread(L1, i), L, getnum); } else if EQ("pushstatus") { pushcode(L1, status); @@ -1397,7 +1397,7 @@ static int coresume (lua_State *L) { int status; lua_State *co = lua_tothread(L, 1); luaL_argcheck(L, co, 1, "coroutine expected"); - status = lua_resume(co, 0); + status = lua_resume(co, L, 0); if (status != LUA_OK && status != LUA_YIELD) { lua_pushboolean(L, 0); lua_insert(L, -2); diff --git a/lua.h b/lua.h @@ -1,5 +1,5 @@ /* -** $Id: lua.h,v 1.277 2011/04/18 14:15:48 roberto Exp roberto $ +** $Id: lua.h,v 1.278 2011/07/02 16:00:15 roberto Exp roberto $ ** Lua - A Scripting Language ** Lua.org, PUC-Rio, Brazil (http://www.lua.org) ** See Copyright Notice at the end of this file @@ -261,7 +261,7 @@ LUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data); LUA_API int (lua_yieldk) (lua_State *L, int nresults, int ctx, lua_CFunction k); #define lua_yield(L,n) lua_yieldk(L, (n), 0, NULL) -LUA_API int (lua_resume) (lua_State *L, int narg); +LUA_API int (lua_resume) (lua_State *L, lua_State *from, int narg); LUA_API int (lua_status) (lua_State *L); /*