From ae23e726018bd31a25c1279600328d90207ec81c Mon Sep 17 00:00:00 2001 From: Roberto I Date: Thu, 23 Apr 2026 18:00:23 -0300 Subject: [PATCH] new macro 'setnilvalue2s' --- lapi.c | 12 ++++++------ ldebug.c | 2 +- ldo.c | 10 +++++----- lgc.c | 2 +- lobject.h | 3 ++- lstate.c | 4 ++-- ltests.c | 2 +- ltm.c | 10 +++++----- lvm.c | 2 +- 9 files changed, 24 insertions(+), 23 deletions(-) diff --git a/lapi.c b/lapi.c index 53eb1719..fb994594 100644 --- a/lapi.c +++ b/lapi.c @@ -187,7 +187,7 @@ LUA_API void lua_settop (lua_State *L, int idx) { api_check(L, idx <= ci->top.p - (func + 1), "new top too large"); diff = ((func + 1) + idx) - L->top.p; for (; diff > 0; diff--) - setnilvalue(s2v(L->top.p++)); /* clear new slots */ + setnilvalue2s(L->top.p++); /* clear new slots */ } else { api_check(L, -(idx+1) <= (L->top.p - (func + 1)), "invalid new top"); @@ -210,7 +210,7 @@ LUA_API void lua_closeslot (lua_State *L, int idx) { api_check(L, (L->ci->callstatus & CIST_TBC) && (L->tbclist.p == level), "no variable to close at given level"); level = luaF_close(L, level, CLOSEKTOP, 0); - setnilvalue(s2v(level)); + setnilvalue2s(level); lua_unlock(L); } @@ -513,7 +513,7 @@ LUA_API const void *lua_topointer (lua_State *L, int idx) { LUA_API void lua_pushnil (lua_State *L) { lua_lock(L); - setnilvalue(s2v(L->top.p)); + setnilvalue2s(L->top.p); api_incr_top(L); lua_unlock(L); } @@ -570,7 +570,7 @@ LUA_API const char *lua_pushexternalstring (lua_State *L, LUA_API const char *lua_pushstring (lua_State *L, const char *s) { lua_lock(L); if (s == NULL) - setnilvalue(s2v(L->top.p)); + setnilvalue2s(L->top.p); else { TString *ts; ts = luaS_new(L, s); @@ -743,7 +743,7 @@ LUA_API int lua_geti (lua_State *L, int idx, lua_Integer n) { static int finishrawget (lua_State *L, lu_byte tag) { if (tagisempty(tag)) /* avoid copying empty items to the stack */ - setnilvalue(s2v(L->top.p)); + setnilvalue2s(L->top.p); api_incr_top(L); lua_unlock(L); return novariant(tag); @@ -836,7 +836,7 @@ LUA_API int lua_getiuservalue (lua_State *L, int idx, int n) { o = index2value(L, idx); api_check(L, ttisfulluserdata(o), "full userdata expected"); if (n <= 0 || n > uvalue(o)->nuvalue) { - setnilvalue(s2v(L->top.p)); + setnilvalue2s(L->top.p); t = LUA_TNONE; } else { diff --git a/ldebug.c b/ldebug.c index 2665ec7b..5293ccb9 100644 --- a/ldebug.c +++ b/ldebug.c @@ -291,7 +291,7 @@ static int nextline (const Proto *p, int currentline, int pc) { static void collectvalidlines (lua_State *L, Closure *f) { if (!LuaClosure(f)) { - setnilvalue(s2v(L->top.p)); + setnilvalue2s(L->top.p); api_incr_top(L); } else { diff --git a/ldo.c b/ldo.c index ec360ee8..1f18b186 100644 --- a/ldo.c +++ b/ldo.c @@ -349,7 +349,7 @@ int luaD_reallocstack (lua_State *L, int newsize, int raiseerror) { correctstack(L, oldstack); /* change offsets back to pointers */ L->stack_last.p = L->stack.p + newsize; for (i = oldsize + EXTRA_STACK; i < newsize + EXTRA_STACK; i++) - setnilvalue(s2v(newstack + i)); /* erase new segment */ + setnilvalue2s(newstack + i); /* erase new segment */ return 1; } @@ -554,7 +554,7 @@ l_sinline void genmoveresults (lua_State *L, StkId res, int nres, for (i = 0; i < nres; i++) /* move all results to correct place */ setobjs2s(L, res + i, firstresult + i); for (; i < wanted; i++) /* complete wanted number of results */ - setnilvalue(s2v(res + i)); + setnilvalue2s(res + i); L->top.p = res + wanted; /* top points after the last result */ } @@ -574,7 +574,7 @@ l_sinline void moveresults (lua_State *L, StkId res, int nres, return; case 1 + 1: /* one value needed */ if (nres == 0) /* no results? */ - setnilvalue(s2v(res)); /* adjust with nil */ + setnilvalue2s(res); /* adjust with nil */ else /* at least one result */ setobjs2s(L, res, L->top.p - nres); /* move it to proper place */ L->top.p = res + 1; @@ -694,7 +694,7 @@ int luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func, setobjs2s(L, ci->func.p + i, func + i); func = ci->func.p; /* moved-down function */ for (; narg1 <= nfixparams; narg1++) - setnilvalue(s2v(func + narg1)); /* complete missing arguments */ + setnilvalue2s(func + narg1); /* complete missing arguments */ ci->top.p = func + 1 + fsize; /* top for new function */ lua_assert(ci->top.p <= L->stack_last.p); ci->u.l.savedpc = p->code; /* starting point */ @@ -741,7 +741,7 @@ CallInfo *luaD_precall (lua_State *L, StkId func, int nresults) { L->ci = ci = prepCallInfo(L, func, status, func + 1 + fsize); ci->u.l.savedpc = p->code; /* starting point */ for (; narg < nfixparams; narg++) - setnilvalue(s2v(L->top.p++)); /* complete missing arguments */ + setnilvalue2s(L->top.p++); /* complete missing arguments */ lua_assert(ci->top.p <= L->stack_last.p); return ci; } diff --git a/lgc.c b/lgc.c index 0f89451c..a463e41e 100644 --- a/lgc.c +++ b/lgc.c @@ -709,7 +709,7 @@ static l_mem traversethread (global_State *g, lua_State *th) { if (!g->gcemergency) luaD_shrinkstack(th); /* do not change stack in emergency cycle */ for (o = th->top.p; o < th->stack_last.p + EXTRA_STACK; o++) - setnilvalue(s2v(o)); /* clear dead stack slice */ + setnilvalue2s(o); /* clear dead stack slice */ /* 'remarkupvals' may have removed thread from 'twups' list */ if (!isintwups(th) && th->openupval != NULL) { th->twups = g->twups; /* link it back to the list */ diff --git a/lobject.h b/lobject.h index 156c942f..bf5b65b4 100644 --- a/lobject.h +++ b/lobject.h @@ -208,7 +208,8 @@ typedef union { #define ttisstrictnil(o) checktag((o), LUA_VNIL) -#define setnilvalue(obj) settt_(obj, LUA_VNIL) +#define setnilvalue(obj) settt_(obj, LUA_VNIL) +#define setnilvalue2s(stk) setnilvalue(s2v(stk)) #define isabstkey(v) checktag((v), LUA_VABSTKEY) diff --git a/lstate.c b/lstate.c index 7d341991..ada0b856 100644 --- a/lstate.c +++ b/lstate.c @@ -151,7 +151,7 @@ LUAI_FUNC void luaE_incCstack (lua_State *L) { static void resetCI (lua_State *L) { CallInfo *ci = L->ci = &L->base_ci; ci->func.p = L->stack.p; - setnilvalue(s2v(ci->func.p)); /* 'function' entry for basic 'ci' */ + setnilvalue2s(ci->func.p); /* 'function' entry for basic 'ci' */ ci->top.p = ci->func.p + 1 + LUA_MINSTACK; /* +1 for 'function' entry */ ci->u.c.k = NULL; ci->callstatus = CIST_C; @@ -166,7 +166,7 @@ static void stack_init (lua_State *L1, lua_State *L) { L1->stack.p = luaM_newvector(L, BASIC_STACK_SIZE + EXTRA_STACK, StackValue); L1->tbclist.p = L1->stack.p; for (i = 0; i < BASIC_STACK_SIZE + EXTRA_STACK; i++) - setnilvalue(s2v(L1->stack.p + i)); /* erase new stack */ + setnilvalue2s(L1->stack.p + i); /* erase new stack */ L1->stack_last.p = L1->stack.p + BASIC_STACK_SIZE; /* initialize first ci */ resetCI(L1); diff --git a/ltests.c b/ltests.c index 6ae5f472..2bf5545a 100644 --- a/ltests.c +++ b/ltests.c @@ -1145,7 +1145,7 @@ static int table_query (lua_State *L) { if (!tagisempty(*getArrTag(t, i))) arr2obj(t, cast_uint(i), s2v(L->top.p)); else - setnilvalue(s2v(L->top.p)); + setnilvalue2s(L->top.p); api_incr_top(L); lua_pushnil(L); } diff --git a/ltm.c b/ltm.c index f2a373f8..cfe90e30 100644 --- a/ltm.c +++ b/ltm.c @@ -262,7 +262,7 @@ static void buildhiddenargs (lua_State *L, CallInfo *ci, const Proto *p, /* move fixed parameters to after the copied function */ for (i = 1; i <= nfixparams; i++) { setobjs2s(L, L->top.p++, ci->func.p + i); - setnilvalue(s2v(ci->func.p + i)); /* erase original parameter (for GC) */ + setnilvalue2s(ci->func.p + i); /* erase original parameter (for GC) */ } ci->func.p += totalargs + 1; /* 'func' now lives after hidden arguments */ ci->top.p += totalargs + 1; @@ -283,7 +283,7 @@ void luaT_adjustvarargs (lua_State *L, CallInfo *ci, const Proto *p) { lua_assert(p->flag & PF_VAHID); buildhiddenargs(L, ci, p, totalargs, nfixparams, nextra); /* set vararg parameter to nil */ - setnilvalue(s2v(ci->func.p + nfixparams + 1)); + setnilvalue2s(ci->func.p + nfixparams + 1); lua_assert(L->top.p <= ci->top.p && ci->top.p <= L->stack_last.p); } } @@ -307,7 +307,7 @@ void luaT_getvararg (CallInfo *ci, StkId ra, TValue *rc) { return; } } - setnilvalue(s2v(ra)); /* else produce nil */ + setnilvalue2s(ra); /* else produce nil */ } @@ -355,10 +355,10 @@ void luaT_getvarargs (lua_State *L, CallInfo *ci, StkId where, int wanted, for (i = 0; i < touse; i++) { lu_byte tag = luaH_getint(h, i + 1, s2v(where + i)); if (tagisempty(tag)) - setnilvalue(s2v(where + i)); + setnilvalue2s(where + i); } } for (; i < wanted; i++) /* complete required results with nil */ - setnilvalue(s2v(where + i)); + setnilvalue2s(where + i); } diff --git a/lvm.c b/lvm.c index 96ae1639..f9e87b61 100644 --- a/lvm.c +++ b/lvm.c @@ -303,7 +303,7 @@ lu_byte luaV_finishget (lua_State *L, const TValue *t, TValue *key, else { /* 't' is a table */ tm = fasttm(L, hvalue(t)->metatable, TM_INDEX); /* table's metamethod */ if (tm == NULL) { /* no metamethod? */ - setnilvalue(s2v(val)); /* result is nil */ + setnilvalue2s(val); /* result is nil */ return LUA_VNIL; } /* else will try the metamethod */