aboutsummaryrefslogtreecommitdiff
path: root/ldo.c
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 /ldo.c
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)
Diffstat (limited to 'ldo.c')
-rw-r--r--ldo.c28
1 files changed, 14 insertions, 14 deletions
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}