aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2011-08-23 14:24:34 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2011-08-23 14:24:34 -0300
commit3dc5475e239e2da52a380288ae8b293a6b019f81 (patch)
tree3da13bd67407f9717b5fb9a024dca38b78589bfc
parent8a008a20579dd6818cb770147c8765b72eb2acfe (diff)
downloadlua-3dc5475e239e2da52a380288ae8b293a6b019f81.tar.gz
lua-3dc5475e239e2da52a380288ae8b293a6b019f81.tar.bz2
lua-3dc5475e239e2da52a380288ae8b293a6b019f81.zip
'nCcalls' should be local to each thread, as each thread may have its
own C stack (with LuaThreads or something similar)
-rw-r--r--lcorolib.c4
-rw-r--r--ldo.c28
-rw-r--r--lparser.c12
-rw-r--r--lstate.c4
-rw-r--r--lstate.h4
-rw-r--r--ltests.c6
-rw-r--r--lua.h4
7 files changed, 31 insertions, 31 deletions
diff --git a/lcorolib.c b/lcorolib.c
index 1eef89c9..78eb9e98 100644
--- a/lcorolib.c
+++ b/lcorolib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lcorolib.c,v 1.1 2010/06/10 21:30:26 roberto Exp roberto $ 2** $Id: lcorolib.c,v 1.2 2010/07/02 11:38:13 roberto Exp roberto $
3** Coroutine Library 3** Coroutine Library
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -28,7 +28,7 @@ static int auxresume (lua_State *L, lua_State *co, int narg) {
28 return -1; /* error flag */ 28 return -1; /* error flag */
29 } 29 }
30 lua_xmove(L, co, narg); 30 lua_xmove(L, co, narg);
31 status = lua_resume(co, narg); 31 status = lua_resume(co, L, narg);
32 if (status == LUA_OK || status == LUA_YIELD) { 32 if (status == LUA_OK || status == LUA_YIELD) {
33 int nres = lua_gettop(co); 33 int nres = lua_gettop(co);
34 if (!lua_checkstack(L, nres + 1)) { 34 if (!lua_checkstack(L, nres + 1)) {
diff --git a/ldo.c b/ldo.c
index efcfaaa0..20b0a6ae 100644
--- a/ldo.c
+++ b/ldo.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldo.c,v 2.97 2011/06/20 16:36:03 roberto Exp roberto $ 2** $Id: ldo.c,v 2.98 2011/06/28 15:42:04 roberto Exp roberto $
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*/
@@ -123,7 +123,7 @@ void luaD_throw (lua_State *L, int errcode) {
123 123
124 124
125int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) { 125int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) {
126 unsigned short oldnCcalls = G(L)->nCcalls; 126 unsigned short oldnCcalls = L->nCcalls;
127 struct lua_longjmp lj; 127 struct lua_longjmp lj;
128 lj.status = LUA_OK; 128 lj.status = LUA_OK;
129 lj.previous = L->errorJmp; /* chain new error handler */ 129 lj.previous = L->errorJmp; /* chain new error handler */
@@ -132,7 +132,7 @@ int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) {
132 (*f)(L, ud); 132 (*f)(L, ud);
133 ); 133 );
134 L->errorJmp = lj.previous; /* restore old error handler */ 134 L->errorJmp = lj.previous; /* restore old error handler */
135 G(L)->nCcalls = oldnCcalls; 135 L->nCcalls = oldnCcalls;
136 return lj.status; 136 return lj.status;
137} 137}
138 138
@@ -382,18 +382,17 @@ int luaD_poscall (lua_State *L, StkId firstResult) {
382** function position. 382** function position.
383*/ 383*/
384void luaD_call (lua_State *L, StkId func, int nResults, int allowyield) { 384void luaD_call (lua_State *L, StkId func, int nResults, int allowyield) {
385 global_State *g = G(L); 385 if (++L->nCcalls >= LUAI_MAXCCALLS) {
386 if (++g->nCcalls >= LUAI_MAXCCALLS) { 386 if (L->nCcalls == LUAI_MAXCCALLS)
387 if (g->nCcalls == LUAI_MAXCCALLS)
388 luaG_runerror(L, "C stack overflow"); 387 luaG_runerror(L, "C stack overflow");
389 else if (g->nCcalls >= (LUAI_MAXCCALLS + (LUAI_MAXCCALLS>>3))) 388 else if (L->nCcalls >= (LUAI_MAXCCALLS + (LUAI_MAXCCALLS>>3)))
390 luaD_throw(L, LUA_ERRERR); /* error while handing stack error */ 389 luaD_throw(L, LUA_ERRERR); /* error while handing stack error */
391 } 390 }
392 if (!allowyield) L->nny++; 391 if (!allowyield) L->nny++;
393 if (!luaD_precall(L, func, nResults)) /* is a Lua function? */ 392 if (!luaD_precall(L, func, nResults)) /* is a Lua function? */
394 luaV_execute(L); /* call it */ 393 luaV_execute(L); /* call it */
395 if (!allowyield) L->nny--; 394 if (!allowyield) L->nny--;
396 g->nCcalls--; 395 L->nCcalls--;
397 luaC_checkGC(L); 396 luaC_checkGC(L);
398} 397}
399 398
@@ -404,7 +403,7 @@ static void finishCcall (lua_State *L) {
404 lua_assert(ci->u.c.k != NULL); /* must have a continuation */ 403 lua_assert(ci->u.c.k != NULL); /* must have a continuation */
405 lua_assert(L->nny == 0); 404 lua_assert(L->nny == 0);
406 /* finish 'luaD_call' */ 405 /* finish 'luaD_call' */
407 G(L)->nCcalls--; 406 L->nCcalls--;
408 /* finish 'lua_callk' */ 407 /* finish 'lua_callk' */
409 adjustresults(L, ci->nresults); 408 adjustresults(L, ci->nresults);
410 /* call continuation function */ 409 /* call continuation function */
@@ -487,7 +486,7 @@ static void resume_error (lua_State *L, const char *msg, StkId firstArg) {
487static void resume (lua_State *L, void *ud) { 486static void resume (lua_State *L, void *ud) {
488 StkId firstArg = cast(StkId, ud); 487 StkId firstArg = cast(StkId, ud);
489 CallInfo *ci = L->ci; 488 CallInfo *ci = L->ci;
490 if (G(L)->nCcalls >= LUAI_MAXCCALLS) 489 if (L->nCcalls >= LUAI_MAXCCALLS)
491 resume_error(L, "C stack overflow", firstArg); 490 resume_error(L, "C stack overflow", firstArg);
492 if (L->status == LUA_OK) { /* may be starting a coroutine */ 491 if (L->status == LUA_OK) { /* may be starting a coroutine */
493 if (ci != &L->base_ci) /* not in base level? */ 492 if (ci != &L->base_ci) /* not in base level? */
@@ -514,7 +513,7 @@ static void resume (lua_State *L, void *ud) {
514 api_checknelems(L, n); 513 api_checknelems(L, n);
515 firstArg = L->top - n; /* yield results come from continuation */ 514 firstArg = L->top - n; /* yield results come from continuation */
516 } 515 }
517 G(L)->nCcalls--; /* finish 'luaD_call' */ 516 L->nCcalls--; /* finish 'luaD_call' */
518 luaD_poscall(L, firstArg); /* finish 'luaD_precall' */ 517 luaD_poscall(L, firstArg); /* finish 'luaD_precall' */
519 } 518 }
520 unroll(L, NULL); 519 unroll(L, NULL);
@@ -522,11 +521,11 @@ static void resume (lua_State *L, void *ud) {
522} 521}
523 522
524 523
525LUA_API int lua_resume (lua_State *L, int nargs) { 524LUA_API int lua_resume (lua_State *L, lua_State *from, int nargs) {
526 int status; 525 int status;
527 lua_lock(L); 526 lua_lock(L);
528 luai_userstateresume(L, nargs); 527 luai_userstateresume(L, nargs);
529 ++G(L)->nCcalls; /* count resume */ 528 L->nCcalls = (from) ? from->nCcalls + 1 : 1;
530 L->nny = 0; /* allow yields */ 529 L->nny = 0; /* allow yields */
531 api_checknelems(L, (L->status == LUA_OK) ? nargs + 1 : nargs); 530 api_checknelems(L, (L->status == LUA_OK) ? nargs + 1 : nargs);
532 status = luaD_rawrunprotected(L, resume, L->top - nargs); 531 status = luaD_rawrunprotected(L, resume, L->top - nargs);
@@ -546,7 +545,8 @@ LUA_API int lua_resume (lua_State *L, int nargs) {
546 lua_assert(status == L->status); 545 lua_assert(status == L->status);
547 } 546 }
548 L->nny = 1; /* do not allow yields */ 547 L->nny = 1; /* do not allow yields */
549 --G(L)->nCcalls; 548 L->nCcalls--;
549 lua_assert(L->nCcalls == ((from) ? from->nCcalls : 0));
550 lua_unlock(L); 550 lua_unlock(L);
551 return status; 551 return status;
552} 552}
diff --git a/lparser.c b/lparser.c
index 57e5d9de..8d79f21d 100644
--- a/lparser.c
+++ b/lparser.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lparser.c,v 2.114 2011/07/15 12:50:29 roberto Exp roberto $ 2** $Id: lparser.c,v 2.115 2011/07/27 18:09:01 roberto Exp roberto $
3** Lua Parser 3** Lua Parser
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -328,13 +328,13 @@ static void adjust_assign (LexState *ls, int nvars, int nexps, expdesc *e) {
328 328
329 329
330static void enterlevel (LexState *ls) { 330static void enterlevel (LexState *ls) {
331 global_State *g = G(ls->L); 331 lua_State *L = ls->L;
332 ++g->nCcalls; 332 ++L->nCcalls;
333 checklimit(ls->fs, g->nCcalls, LUAI_MAXCCALLS, "syntax levels"); 333 checklimit(ls->fs, L->nCcalls, LUAI_MAXCCALLS, "syntax levels");
334} 334}
335 335
336 336
337#define leavelevel(ls) (G((ls)->L)->nCcalls--) 337#define leavelevel(ls) ((ls)->L->nCcalls--)
338 338
339 339
340static void closegoto (LexState *ls, int g, Labeldesc *label) { 340static void closegoto (LexState *ls, int g, Labeldesc *label) {
@@ -1144,7 +1144,7 @@ static void assignment (LexState *ls, struct LHS_assign *lh, int nvars) {
1144 primaryexp(ls, &nv.v); 1144 primaryexp(ls, &nv.v);
1145 if (nv.v.k != VINDEXED) 1145 if (nv.v.k != VINDEXED)
1146 check_conflict(ls, lh, &nv.v); 1146 check_conflict(ls, lh, &nv.v);
1147 checklimit(ls->fs, nvars, LUAI_MAXCCALLS - G(ls->L)->nCcalls, 1147 checklimit(ls->fs, nvars, LUAI_MAXCCALLS - ls->L->nCcalls,
1148 "variable names"); 1148 "variable names");
1149 assignment(ls, &nv, nvars+1); 1149 assignment(ls, &nv, nvars+1);
1150 } 1150 }
diff --git a/lstate.c b/lstate.c
index 506af472..64b03dc1 100644
--- a/lstate.c
+++ b/lstate.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstate.c,v 2.89 2010/12/20 19:40:07 roberto Exp roberto $ 2** $Id: lstate.c,v 2.90 2011/08/09 20:58:29 roberto Exp roberto $
3** Global State 3** Global State
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -171,6 +171,7 @@ static void preinit_state (lua_State *L, global_State *g) {
171 L->ci = NULL; 171 L->ci = NULL;
172 L->stacksize = 0; 172 L->stacksize = 0;
173 L->errorJmp = NULL; 173 L->errorJmp = NULL;
174 L->nCcalls = 0;
174 L->hook = NULL; 175 L->hook = NULL;
175 L->hookmask = 0; 176 L->hookmask = 0;
176 L->basehookcount = 0; 177 L->basehookcount = 0;
@@ -237,7 +238,6 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
237 g->currentwhite = bit2mask(WHITE0BIT, FIXEDBIT); 238 g->currentwhite = bit2mask(WHITE0BIT, FIXEDBIT);
238 L->marked = luaC_white(g); 239 L->marked = luaC_white(g);
239 g->gckind = KGC_NORMAL; 240 g->gckind = KGC_NORMAL;
240 g->nCcalls = 0;
241 preinit_state(L, g); 241 preinit_state(L, g);
242 g->frealloc = f; 242 g->frealloc = f;
243 g->ud = ud; 243 g->ud = ud;
diff --git a/lstate.h b/lstate.h
index 606bb669..fb757373 100644
--- a/lstate.h
+++ b/lstate.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstate.h,v 2.71 2010/12/20 19:40:07 roberto Exp roberto $ 2** $Id: lstate.h,v 2.72 2011/06/02 19:31:40 roberto Exp roberto $
3** Global State 3** Global State
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -118,7 +118,6 @@ typedef struct global_State {
118 lu_mem lastmajormem; /* memory in use after last major collection */ 118 lu_mem lastmajormem; /* memory in use after last major collection */
119 stringtable strt; /* hash table for strings */ 119 stringtable strt; /* hash table for strings */
120 TValue l_registry; 120 TValue l_registry;
121 unsigned short nCcalls; /* number of nested C calls */
122 lu_byte currentwhite; 121 lu_byte currentwhite;
123 lu_byte gcstate; /* state of garbage collector */ 122 lu_byte gcstate; /* state of garbage collector */
124 lu_byte gckind; /* kind of GC running */ 123 lu_byte gckind; /* kind of GC running */
@@ -161,6 +160,7 @@ struct lua_State {
161 StkId stack; /* stack base */ 160 StkId stack; /* stack base */
162 int stacksize; 161 int stacksize;
163 unsigned short nny; /* number of non-yieldable calls in stack */ 162 unsigned short nny; /* number of non-yieldable calls in stack */
163 unsigned short nCcalls; /* number of nested C calls */
164 lu_byte hookmask; 164 lu_byte hookmask;
165 lu_byte allowhook; 165 lu_byte allowhook;
166 int basehookcount; 166 int basehookcount;
diff --git a/ltests.c b/ltests.c
index f1cb252d..07bde473 100644
--- a/ltests.c
+++ b/ltests.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltests.c,v 2.120 2011/06/24 14:36:21 roberto Exp roberto $ 2** $Id: ltests.c,v 2.121 2011/07/02 15:59:17 roberto Exp roberto $
3** Internal Module for Debugging of the Lua Implementation 3** Internal Module for Debugging of the Lua Implementation
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -1210,7 +1210,7 @@ static int runC (lua_State *L, lua_State *L1, const char *pc) {
1210 } 1210 }
1211 else if EQ("resume") { 1211 else if EQ("resume") {
1212 int i = getindex; 1212 int i = getindex;
1213 status = lua_resume(lua_tothread(L1, i), getnum); 1213 status = lua_resume(lua_tothread(L1, i), L, getnum);
1214 } 1214 }
1215 else if EQ("pushstatus") { 1215 else if EQ("pushstatus") {
1216 pushcode(L1, status); 1216 pushcode(L1, status);
@@ -1397,7 +1397,7 @@ static int coresume (lua_State *L) {
1397 int status; 1397 int status;
1398 lua_State *co = lua_tothread(L, 1); 1398 lua_State *co = lua_tothread(L, 1);
1399 luaL_argcheck(L, co, 1, "coroutine expected"); 1399 luaL_argcheck(L, co, 1, "coroutine expected");
1400 status = lua_resume(co, 0); 1400 status = lua_resume(co, L, 0);
1401 if (status != LUA_OK && status != LUA_YIELD) { 1401 if (status != LUA_OK && status != LUA_YIELD) {
1402 lua_pushboolean(L, 0); 1402 lua_pushboolean(L, 0);
1403 lua_insert(L, -2); 1403 lua_insert(L, -2);
diff --git a/lua.h b/lua.h
index 2cd70ae7..349ef6ed 100644
--- a/lua.h
+++ b/lua.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lua.h,v 1.277 2011/04/18 14:15:48 roberto Exp roberto $ 2** $Id: lua.h,v 1.278 2011/07/02 16:00:15 roberto Exp roberto $
3** Lua - A Scripting Language 3** Lua - A Scripting Language
4** Lua.org, PUC-Rio, Brazil (http://www.lua.org) 4** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
5** See Copyright Notice at the end of this file 5** 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);
261LUA_API int (lua_yieldk) (lua_State *L, int nresults, int ctx, 261LUA_API int (lua_yieldk) (lua_State *L, int nresults, int ctx,
262 lua_CFunction k); 262 lua_CFunction k);
263#define lua_yield(L,n) lua_yieldk(L, (n), 0, NULL) 263#define lua_yield(L,n) lua_yieldk(L, (n), 0, NULL)
264LUA_API int (lua_resume) (lua_State *L, int narg); 264LUA_API int (lua_resume) (lua_State *L, lua_State *from, int narg);
265LUA_API int (lua_status) (lua_State *L); 265LUA_API int (lua_status) (lua_State *L);
266 266
267/* 267/*