Browse Source

Struct 'transferinfo' moved to "lua_State"

That reduces the size of "CallInfo". Moreover, bit CIST_HOOKED from
call status is not needed. When in a hook, 'transferinfo' is always
valid, being zero when the hook is not call/return.
master
Roberto Ierusalimschy 3 months ago
parent
commit
4c6afbcb01
  1. 6
      ldebug.c
  2. 14
      ldo.c
  3. 20
      lstate.h

6
ldebug.c

@ -364,11 +364,11 @@ static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar,
break; break;
} }
case 'r': { case 'r': {
if (ci == NULL || !(ci->callstatus & CIST_TRAN)) if (ci == NULL || !(ci->callstatus & CIST_HOOKED))
ar->ftransfer = ar->ntransfer = 0; ar->ftransfer = ar->ntransfer = 0;
else { else {
ar->ftransfer = ci->u2.transferinfo.ftransfer; ar->ftransfer = L->transferinfo.ftransfer;
ar->ntransfer = ci->u2.transferinfo.ntransfer; ar->ntransfer = L->transferinfo.ntransfer;
} }
break; break;
} }

14
ldo.c

@ -357,7 +357,6 @@ void luaD_hook (lua_State *L, int event, int line,
int ftransfer, int ntransfer) { int ftransfer, int ntransfer) {
lua_Hook hook = L->hook; lua_Hook hook = L->hook;
if (hook && L->allowhook) { /* make sure there is a hook */ if (hook && L->allowhook) { /* make sure there is a hook */
unsigned mask = CIST_HOOKED;
CallInfo *ci = L->ci; CallInfo *ci = L->ci;
ptrdiff_t top = savestack(L, L->top.p); /* preserve original 'top' */ ptrdiff_t top = savestack(L, L->top.p); /* preserve original 'top' */
ptrdiff_t ci_top = savestack(L, ci->top.p); /* idem for 'ci->top' */ ptrdiff_t ci_top = savestack(L, ci->top.p); /* idem for 'ci->top' */
@ -365,18 +364,15 @@ void luaD_hook (lua_State *L, int event, int line,
ar.event = event; ar.event = event;
ar.currentline = line; ar.currentline = line;
ar.i_ci = ci; ar.i_ci = ci;
if (ntransfer != 0) { L->transferinfo.ftransfer = ftransfer;
mask |= CIST_TRAN; /* 'ci' has transfer information */ L->transferinfo.ntransfer = ntransfer;
ci->u2.transferinfo.ftransfer = ftransfer;
ci->u2.transferinfo.ntransfer = ntransfer;
}
if (isLua(ci) && L->top.p < ci->top.p) if (isLua(ci) && L->top.p < ci->top.p)
L->top.p = ci->top.p; /* protect entire activation register */ L->top.p = ci->top.p; /* protect entire activation register */
luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */
if (ci->top.p < L->top.p + LUA_MINSTACK) if (ci->top.p < L->top.p + LUA_MINSTACK)
ci->top.p = L->top.p + LUA_MINSTACK; ci->top.p = L->top.p + LUA_MINSTACK;
L->allowhook = 0; /* cannot call hooks inside a hook */ L->allowhook = 0; /* cannot call hooks inside a hook */
ci->callstatus |= mask; ci->callstatus |= CIST_HOOKED;
lua_unlock(L); lua_unlock(L);
(*hook)(L, &ar); (*hook)(L, &ar);
lua_lock(L); lua_lock(L);
@ -384,7 +380,7 @@ void luaD_hook (lua_State *L, int event, int line,
L->allowhook = 1; L->allowhook = 1;
ci->top.p = restorestack(L, ci_top); ci->top.p = restorestack(L, ci_top);
L->top.p = restorestack(L, top); L->top.p = restorestack(L, top);
ci->callstatus &= ~mask; ci->callstatus &= ~CIST_HOOKED;
} }
} }
@ -525,7 +521,7 @@ void luaD_poscall (lua_State *L, CallInfo *ci, int nres) {
moveresults(L, ci->func.p, nres, fwanted); moveresults(L, ci->func.p, nres, fwanted);
/* function cannot be in any of these cases when returning */ /* function cannot be in any of these cases when returning */
lua_assert(!(ci->callstatus & lua_assert(!(ci->callstatus &
(CIST_HOOKED | CIST_YPCALL | CIST_FIN | CIST_TRAN | CIST_CLSRET))); (CIST_HOOKED | CIST_YPCALL | CIST_FIN | CIST_CLSRET)));
L->ci = ci->previous; /* back to caller (after closing variables) */ L->ci = ci->previous; /* back to caller (after closing variables) */
} }

20
lstate.h

@ -183,8 +183,6 @@ typedef struct stringtable {
** yield (from the yield until the next resume); ** yield (from the yield until the next resume);
** - field 'nres' is used only while closing tbc variables when ** - field 'nres' is used only while closing tbc variables when
** returning from a function; ** returning from a function;
** - field 'transferinfo' is used only during call/returnhooks,
** before the function starts or after it ends.
*/ */
struct CallInfo { struct CallInfo {
StkIdRel func; /* function index in the stack */ StkIdRel func; /* function index in the stack */
@ -206,10 +204,6 @@ struct CallInfo {
int funcidx; /* called-function index */ int funcidx; /* called-function index */
int nyield; /* number of values yielded */ int nyield; /* number of values yielded */
int nres; /* number of values returned */ int nres; /* number of values returned */
struct { /* info about transferred values (for call/return hooks) */
int ftransfer; /* offset of first value transferred */
int ntransfer; /* number of values transferred */
} transferinfo;
} u2; } u2;
l_uint32 callstatus; l_uint32 callstatus;
}; };
@ -236,15 +230,13 @@ struct CallInfo {
#define CIST_HOOKYIELD (cast(l_uint32, 1) << 14) #define CIST_HOOKYIELD (cast(l_uint32, 1) << 14)
/* function "called" a finalizer */ /* function "called" a finalizer */
#define CIST_FIN (cast(l_uint32, 1) << 15) #define CIST_FIN (cast(l_uint32, 1) << 15)
/* 'ci' has transfer information */
#define CIST_TRAN (cast(l_uint32, 1) << 16)
/* function is closing tbc variables */ /* function is closing tbc variables */
#define CIST_CLSRET (cast(l_uint32, 1) << 17) #define CIST_CLSRET (cast(l_uint32, 1) << 16)
/* Bits 18-20 are used for CIST_RECST (see below) */ /* Bits 17-19 are used for CIST_RECST (see below) */
#define CIST_RECST 18 /* the offset, not the mask */ #define CIST_RECST 17 /* the offset, not the mask */
#if defined(LUA_COMPAT_LT_LE) #if defined(LUA_COMPAT_LT_LE)
/* using __lt for __le */ /* using __lt for __le */
#define CIST_LEQ (cast(l_uint32, 1) << 21) #define CIST_LEQ (cast(l_uint32, 1) << 20)
#endif #endif
@ -354,6 +346,10 @@ struct lua_State {
int basehookcount; int basehookcount;
int hookcount; int hookcount;
volatile l_signalT hookmask; volatile l_signalT hookmask;
struct { /* info about transferred values (for call/return hooks) */
int ftransfer; /* offset of first value transferred */
int ntransfer; /* number of values transferred */
} transferinfo;
}; };

Loading…
Cancel
Save