diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2012-06-08 12:14:04 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2012-06-08 12:14:04 -0300 |
| commit | cc2a60ecb7e4c57ed31e5c5c3f49d8dc7447acc5 (patch) | |
| tree | bd702ddf14ba4e1b57959bf978ec062f03ad861f /ldo.c | |
| parent | 43bfb60ac8add40a6099b933bc8454c11471c386 (diff) | |
| download | lua-cc2a60ecb7e4c57ed31e5c5c3f49d8dc7447acc5.tar.gz lua-cc2a60ecb7e4c57ed31e5c5c3f49d8dc7447acc5.tar.bz2 lua-cc2a60ecb7e4c57ed31e5c5c3f49d8dc7447acc5.zip | |
bugs in yields inside debug hooks
Diffstat (limited to 'ldo.c')
| -rw-r--r-- | ldo.c | 8 |
1 files changed, 4 insertions, 4 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldo.c,v 2.103 2012/04/26 20:41:18 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 2.104 2012/05/08 13:53:33 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 | */ |
| @@ -451,7 +451,7 @@ static int recover (lua_State *L, int status) { | |||
| 451 | CallInfo *ci = findpcall(L); | 451 | CallInfo *ci = findpcall(L); |
| 452 | if (ci == NULL) return 0; /* no recovery point */ | 452 | if (ci == NULL) return 0; /* no recovery point */ |
| 453 | /* "finish" luaD_pcall */ | 453 | /* "finish" luaD_pcall */ |
| 454 | oldtop = restorestack(L, ci->u.c.extra); | 454 | oldtop = restorestack(L, ci->extra); |
| 455 | luaF_close(L, oldtop); | 455 | luaF_close(L, oldtop); |
| 456 | seterrorobj(L, status, oldtop); | 456 | seterrorobj(L, status, oldtop); |
| 457 | L->ci = ci; | 457 | L->ci = ci; |
| @@ -498,10 +498,10 @@ static void resume (lua_State *L, void *ud) { | |||
| 498 | resume_error(L, "cannot resume dead coroutine", firstArg); | 498 | resume_error(L, "cannot resume dead coroutine", firstArg); |
| 499 | else { /* resuming from previous yield */ | 499 | else { /* resuming from previous yield */ |
| 500 | L->status = LUA_OK; | 500 | L->status = LUA_OK; |
| 501 | ci->func = restorestack(L, ci->extra); | ||
| 501 | if (isLua(ci)) /* yielded inside a hook? */ | 502 | if (isLua(ci)) /* yielded inside a hook? */ |
| 502 | luaV_execute(L); /* just continue running Lua code */ | 503 | luaV_execute(L); /* just continue running Lua code */ |
| 503 | else { /* 'common' yield */ | 504 | else { /* 'common' yield */ |
| 504 | ci->func = restorestack(L, ci->u.c.extra); | ||
| 505 | if (ci->u.c.k != NULL) { /* does it have a continuation? */ | 505 | if (ci->u.c.k != NULL) { /* does it have a continuation? */ |
| 506 | int n; | 506 | int n; |
| 507 | ci->u.c.status = LUA_YIELD; /* 'default' status */ | 507 | ci->u.c.status = LUA_YIELD; /* 'default' status */ |
| @@ -563,13 +563,13 @@ LUA_API int lua_yieldk (lua_State *L, int nresults, int ctx, lua_CFunction k) { | |||
| 563 | luaG_runerror(L, "attempt to yield from outside a coroutine"); | 563 | luaG_runerror(L, "attempt to yield from outside a coroutine"); |
| 564 | } | 564 | } |
| 565 | L->status = LUA_YIELD; | 565 | L->status = LUA_YIELD; |
| 566 | ci->extra = savestack(L, ci->func); /* save current 'func' */ | ||
| 566 | if (isLua(ci)) { /* inside a hook? */ | 567 | if (isLua(ci)) { /* inside a hook? */ |
| 567 | api_check(L, k == NULL, "hooks cannot continue after yielding"); | 568 | api_check(L, k == NULL, "hooks cannot continue after yielding"); |
| 568 | } | 569 | } |
| 569 | else { | 570 | else { |
| 570 | if ((ci->u.c.k = k) != NULL) /* is there a continuation? */ | 571 | if ((ci->u.c.k = k) != NULL) /* is there a continuation? */ |
| 571 | ci->u.c.ctx = ctx; /* save context */ | 572 | ci->u.c.ctx = ctx; /* save context */ |
| 572 | ci->u.c.extra = savestack(L, ci->func); /* save current 'func' */ | ||
| 573 | ci->func = L->top - nresults - 1; /* protect stack below results */ | 573 | ci->func = L->top - nresults - 1; /* protect stack below results */ |
| 574 | luaD_throw(L, LUA_YIELD); | 574 | luaD_throw(L, LUA_YIELD); |
| 575 | } | 575 | } |
