From fa3113ffbf4455871baf1d1d9d48679a17e6f3e5 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 12 Jun 2014 16:07:30 -0300 Subject: [PATCH] cleaner way to handle bit CIST_OAH (with auxiliar macros) --- lapi.c | 7 ++----- ldo.c | 4 ++-- lstate.h | 21 ++++++++++++--------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/lapi.c b/lapi.c index f775b1df..106da209 100644 --- a/lapi.c +++ b/lapi.c @@ -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; diff --git a/ldo.c b/ldo.c index 6e695a5c..6b131d46 100644 --- a/ldo.c +++ b/ldo.c @@ -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; diff --git a/lstate.h b/lstate.h index b03ed4f8..47dddcec 100644 --- a/lstate.h +++ b/lstate.h @@ -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