Skip to content

Commit 4c6afbc

Browse files
committed
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.
1 parent f2206b2 commit 4c6afbc

File tree

3 files changed

+16
-24
lines changed

3 files changed

+16
-24
lines changed

ldebug.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,11 +364,11 @@ static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar,
364364
break;
365365
}
366366
case 'r': {
367-
if (ci == NULL || !(ci->callstatus & CIST_TRAN))
367+
if (ci == NULL || !(ci->callstatus & CIST_HOOKED))
368368
ar->ftransfer = ar->ntransfer = 0;
369369
else {
370-
ar->ftransfer = ci->u2.transferinfo.ftransfer;
371-
ar->ntransfer = ci->u2.transferinfo.ntransfer;
370+
ar->ftransfer = L->transferinfo.ftransfer;
371+
ar->ntransfer = L->transferinfo.ntransfer;
372372
}
373373
break;
374374
}

ldo.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -357,34 +357,30 @@ void luaD_hook (lua_State *L, int event, int line,
357357
int ftransfer, int ntransfer) {
358358
lua_Hook hook = L->hook;
359359
if (hook && L->allowhook) { /* make sure there is a hook */
360-
unsigned mask = CIST_HOOKED;
361360
CallInfo *ci = L->ci;
362361
ptrdiff_t top = savestack(L, L->top.p); /* preserve original 'top' */
363362
ptrdiff_t ci_top = savestack(L, ci->top.p); /* idem for 'ci->top' */
364363
lua_Debug ar;
365364
ar.event = event;
366365
ar.currentline = line;
367366
ar.i_ci = ci;
368-
if (ntransfer != 0) {
369-
mask |= CIST_TRAN; /* 'ci' has transfer information */
370-
ci->u2.transferinfo.ftransfer = ftransfer;
371-
ci->u2.transferinfo.ntransfer = ntransfer;
372-
}
367+
L->transferinfo.ftransfer = ftransfer;
368+
L->transferinfo.ntransfer = ntransfer;
373369
if (isLua(ci) && L->top.p < ci->top.p)
374370
L->top.p = ci->top.p; /* protect entire activation register */
375371
luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */
376372
if (ci->top.p < L->top.p + LUA_MINSTACK)
377373
ci->top.p = L->top.p + LUA_MINSTACK;
378374
L->allowhook = 0; /* cannot call hooks inside a hook */
379-
ci->callstatus |= mask;
375+
ci->callstatus |= CIST_HOOKED;
380376
lua_unlock(L);
381377
(*hook)(L, &ar);
382378
lua_lock(L);
383379
lua_assert(!L->allowhook);
384380
L->allowhook = 1;
385381
ci->top.p = restorestack(L, ci_top);
386382
L->top.p = restorestack(L, top);
387-
ci->callstatus &= ~mask;
383+
ci->callstatus &= ~CIST_HOOKED;
388384
}
389385
}
390386

@@ -525,7 +521,7 @@ void luaD_poscall (lua_State *L, CallInfo *ci, int nres) {
525521
moveresults(L, ci->func.p, nres, fwanted);
526522
/* function cannot be in any of these cases when returning */
527523
lua_assert(!(ci->callstatus &
528-
(CIST_HOOKED | CIST_YPCALL | CIST_FIN | CIST_TRAN | CIST_CLSRET)));
524+
(CIST_HOOKED | CIST_YPCALL | CIST_FIN | CIST_CLSRET)));
529525
L->ci = ci->previous; /* back to caller (after closing variables) */
530526
}
531527

lstate.h

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,6 @@ typedef struct stringtable {
183183
** yield (from the yield until the next resume);
184184
** - field 'nres' is used only while closing tbc variables when
185185
** returning from a function;
186-
** - field 'transferinfo' is used only during call/returnhooks,
187-
** before the function starts or after it ends.
188186
*/
189187
struct CallInfo {
190188
StkIdRel func; /* function index in the stack */
@@ -206,10 +204,6 @@ struct CallInfo {
206204
int funcidx; /* called-function index */
207205
int nyield; /* number of values yielded */
208206
int nres; /* number of values returned */
209-
struct { /* info about transferred values (for call/return hooks) */
210-
int ftransfer; /* offset of first value transferred */
211-
int ntransfer; /* number of values transferred */
212-
} transferinfo;
213207
} u2;
214208
l_uint32 callstatus;
215209
};
@@ -236,15 +230,13 @@ struct CallInfo {
236230
#define CIST_HOOKYIELD (cast(l_uint32, 1) << 14)
237231
/* function "called" a finalizer */
238232
#define CIST_FIN (cast(l_uint32, 1) << 15)
239-
/* 'ci' has transfer information */
240-
#define CIST_TRAN (cast(l_uint32, 1) << 16)
241233
/* function is closing tbc variables */
242-
#define CIST_CLSRET (cast(l_uint32, 1) << 17)
243-
/* Bits 18-20 are used for CIST_RECST (see below) */
244-
#define CIST_RECST 18 /* the offset, not the mask */
234+
#define CIST_CLSRET (cast(l_uint32, 1) << 16)
235+
/* Bits 17-19 are used for CIST_RECST (see below) */
236+
#define CIST_RECST 17 /* the offset, not the mask */
245237
#if defined(LUA_COMPAT_LT_LE)
246238
/* using __lt for __le */
247-
#define CIST_LEQ (cast(l_uint32, 1) << 21)
239+
#define CIST_LEQ (cast(l_uint32, 1) << 20)
248240
#endif
249241

250242

@@ -354,6 +346,10 @@ struct lua_State {
354346
int basehookcount;
355347
int hookcount;
356348
volatile l_signalT hookmask;
349+
struct { /* info about transferred values (for call/return hooks) */
350+
int ftransfer; /* offset of first value transferred */
351+
int ntransfer; /* number of values transferred */
352+
} transferinfo;
357353
};
358354

359355

0 commit comments

Comments
 (0)