cleaner way to handle bit CIST_OAH (with auxiliar macros)

This commit is contained in:
Roberto Ierusalimschy 2014-06-12 16:07:30 -03:00
parent d94bb6c273
commit fa3113ffbf
3 changed files with 16 additions and 16 deletions

7
lapi.c
View File

@ -1,5 +1,5 @@
/*
** $Id: lapi.c,v 2.216 2014/06/10 18:51:21 roberto Exp roberto $
** $Id: lapi.c,v 2.217 2014/06/10 19:13:26 roberto Exp roberto $
** Lua API
** See Copyright Notice in lua.h
*/
@ -970,10 +970,7 @@ LUA_API int lua_pcallk (lua_State *L, int nargs, int nresults, int errfunc,
ci->extra = savestack(L, c.func);
ci->u.c.old_errfunc = L->errfunc;
L->errfunc = func;
if (L->allowhook) /* save original value of 'allowhook' */
ci->callstatus |= CIST_OAH;
else
ci->callstatus &= ~CIST_OAH;
setoah(ci->callstatus, L->allowhook); /* save value of 'allowhook' */
ci->callstatus |= CIST_YPCALL; /* function can do error recovery */
luaD_call(L, c.func, nresults, 1); /* do the call */
ci->callstatus &= ~CIST_YPCALL;

4
ldo.c
View File

@ -1,5 +1,5 @@
/*
** $Id: ldo.c,v 2.120 2014/06/10 19:18:50 roberto Exp roberto $
** $Id: ldo.c,v 2.121 2014/06/11 16:01:55 roberto Exp roberto $
** Stack and Call structure of Lua
** See Copyright Notice in lua.h
*/
@ -492,7 +492,7 @@ static int recover (lua_State *L, int status) {
luaF_close(L, oldtop);
seterrorobj(L, status, oldtop);
L->ci = ci;
L->allowhook = (ci->callstatus & CIST_OAH);
L->allowhook = getoah(ci->callstatus); /* restore original 'allowhook' */
L->nny = 0; /* should be zero to be yieldable */
luaD_shrinkstack(L);
L->errfunc = ci->u.c.old_errfunc;

View File

@ -1,5 +1,5 @@
/*
** $Id: lstate.h,v 2.105 2014/06/10 18:51:21 roberto Exp roberto $
** $Id: lstate.h,v 2.106 2014/06/10 19:18:50 roberto Exp roberto $
** Global State
** See Copyright Notice in lua.h
*/
@ -80,18 +80,21 @@ typedef struct CallInfo {
/*
** Bits in CallInfo status
*/
#define CIST_LUA (1<<0) /* call is running a Lua function */
#define CIST_HOOKED (1<<1) /* call is running a debug hook */
#define CIST_REENTRY (1<<2) /* call is running on same invocation of
#define CIST_OAH (1<<0) /* original value of 'allowhook' */
#define CIST_LUA (1<<1) /* call is running a Lua function */
#define CIST_HOOKED (1<<2) /* call is running a debug hook */
#define CIST_REENTRY (1<<3) /* call is running on same invocation of
luaV_execute of previous call */
#define CIST_YPCALL (1<<3) /* call is a yieldable protected call */
#define CIST_TAIL (1<<4) /* call was tail called */
#define CIST_HOOKYIELD (1<<5) /* last hook called yielded */
#define CIST_OAH (1<<6) /* original value of 'allowhook' */
#define CIST_YPCALL (1<<4) /* call is a yieldable protected call */
#define CIST_TAIL (1<<5) /* call was tail called */
#define CIST_HOOKYIELD (1<<6) /* last hook called yielded */
#define isLua(ci) ((ci)->callstatus & CIST_LUA)
/* assume that CIST_OAH has offset 0 and that 'v' is strictly 0/1 */
#define setoah(st,v) ((st) = ((st) & ~CIST_OAH) | (v))
#define getoah(st) ((st) & CIST_OAH)
/*
** `global state', shared by all threads of this state