Skip to content

Commit ae23e72

Browse files
committed
new macro 'setnilvalue2s'
1 parent 4c5d506 commit ae23e72

9 files changed

Lines changed: 24 additions & 23 deletions

File tree

lapi.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ LUA_API void lua_settop (lua_State *L, int idx) {
187187
api_check(L, idx <= ci->top.p - (func + 1), "new top too large");
188188
diff = ((func + 1) + idx) - L->top.p;
189189
for (; diff > 0; diff--)
190-
setnilvalue(s2v(L->top.p++)); /* clear new slots */
190+
setnilvalue2s(L->top.p++); /* clear new slots */
191191
}
192192
else {
193193
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) {
210210
api_check(L, (L->ci->callstatus & CIST_TBC) && (L->tbclist.p == level),
211211
"no variable to close at given level");
212212
level = luaF_close(L, level, CLOSEKTOP, 0);
213-
setnilvalue(s2v(level));
213+
setnilvalue2s(level);
214214
lua_unlock(L);
215215
}
216216

@@ -513,7 +513,7 @@ LUA_API const void *lua_topointer (lua_State *L, int idx) {
513513

514514
LUA_API void lua_pushnil (lua_State *L) {
515515
lua_lock(L);
516-
setnilvalue(s2v(L->top.p));
516+
setnilvalue2s(L->top.p);
517517
api_incr_top(L);
518518
lua_unlock(L);
519519
}
@@ -570,7 +570,7 @@ LUA_API const char *lua_pushexternalstring (lua_State *L,
570570
LUA_API const char *lua_pushstring (lua_State *L, const char *s) {
571571
lua_lock(L);
572572
if (s == NULL)
573-
setnilvalue(s2v(L->top.p));
573+
setnilvalue2s(L->top.p);
574574
else {
575575
TString *ts;
576576
ts = luaS_new(L, s);
@@ -743,7 +743,7 @@ LUA_API int lua_geti (lua_State *L, int idx, lua_Integer n) {
743743

744744
static int finishrawget (lua_State *L, lu_byte tag) {
745745
if (tagisempty(tag)) /* avoid copying empty items to the stack */
746-
setnilvalue(s2v(L->top.p));
746+
setnilvalue2s(L->top.p);
747747
api_incr_top(L);
748748
lua_unlock(L);
749749
return novariant(tag);
@@ -836,7 +836,7 @@ LUA_API int lua_getiuservalue (lua_State *L, int idx, int n) {
836836
o = index2value(L, idx);
837837
api_check(L, ttisfulluserdata(o), "full userdata expected");
838838
if (n <= 0 || n > uvalue(o)->nuvalue) {
839-
setnilvalue(s2v(L->top.p));
839+
setnilvalue2s(L->top.p);
840840
t = LUA_TNONE;
841841
}
842842
else {

ldebug.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ static int nextline (const Proto *p, int currentline, int pc) {
291291

292292
static void collectvalidlines (lua_State *L, Closure *f) {
293293
if (!LuaClosure(f)) {
294-
setnilvalue(s2v(L->top.p));
294+
setnilvalue2s(L->top.p);
295295
api_incr_top(L);
296296
}
297297
else {

ldo.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ int luaD_reallocstack (lua_State *L, int newsize, int raiseerror) {
349349
correctstack(L, oldstack); /* change offsets back to pointers */
350350
L->stack_last.p = L->stack.p + newsize;
351351
for (i = oldsize + EXTRA_STACK; i < newsize + EXTRA_STACK; i++)
352-
setnilvalue(s2v(newstack + i)); /* erase new segment */
352+
setnilvalue2s(newstack + i); /* erase new segment */
353353
return 1;
354354
}
355355

@@ -554,7 +554,7 @@ l_sinline void genmoveresults (lua_State *L, StkId res, int nres,
554554
for (i = 0; i < nres; i++) /* move all results to correct place */
555555
setobjs2s(L, res + i, firstresult + i);
556556
for (; i < wanted; i++) /* complete wanted number of results */
557-
setnilvalue(s2v(res + i));
557+
setnilvalue2s(res + i);
558558
L->top.p = res + wanted; /* top points after the last result */
559559
}
560560

@@ -574,7 +574,7 @@ l_sinline void moveresults (lua_State *L, StkId res, int nres,
574574
return;
575575
case 1 + 1: /* one value needed */
576576
if (nres == 0) /* no results? */
577-
setnilvalue(s2v(res)); /* adjust with nil */
577+
setnilvalue2s(res); /* adjust with nil */
578578
else /* at least one result */
579579
setobjs2s(L, res, L->top.p - nres); /* move it to proper place */
580580
L->top.p = res + 1;
@@ -694,7 +694,7 @@ int luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func,
694694
setobjs2s(L, ci->func.p + i, func + i);
695695
func = ci->func.p; /* moved-down function */
696696
for (; narg1 <= nfixparams; narg1++)
697-
setnilvalue(s2v(func + narg1)); /* complete missing arguments */
697+
setnilvalue2s(func + narg1); /* complete missing arguments */
698698
ci->top.p = func + 1 + fsize; /* top for new function */
699699
lua_assert(ci->top.p <= L->stack_last.p);
700700
ci->u.l.savedpc = p->code; /* starting point */
@@ -741,7 +741,7 @@ CallInfo *luaD_precall (lua_State *L, StkId func, int nresults) {
741741
L->ci = ci = prepCallInfo(L, func, status, func + 1 + fsize);
742742
ci->u.l.savedpc = p->code; /* starting point */
743743
for (; narg < nfixparams; narg++)
744-
setnilvalue(s2v(L->top.p++)); /* complete missing arguments */
744+
setnilvalue2s(L->top.p++); /* complete missing arguments */
745745
lua_assert(ci->top.p <= L->stack_last.p);
746746
return ci;
747747
}

lgc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ static l_mem traversethread (global_State *g, lua_State *th) {
709709
if (!g->gcemergency)
710710
luaD_shrinkstack(th); /* do not change stack in emergency cycle */
711711
for (o = th->top.p; o < th->stack_last.p + EXTRA_STACK; o++)
712-
setnilvalue(s2v(o)); /* clear dead stack slice */
712+
setnilvalue2s(o); /* clear dead stack slice */
713713
/* 'remarkupvals' may have removed thread from 'twups' list */
714714
if (!isintwups(th) && th->openupval != NULL) {
715715
th->twups = g->twups; /* link it back to the list */

lobject.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ typedef union {
208208
#define ttisstrictnil(o) checktag((o), LUA_VNIL)
209209

210210

211-
#define setnilvalue(obj) settt_(obj, LUA_VNIL)
211+
#define setnilvalue(obj) settt_(obj, LUA_VNIL)
212+
#define setnilvalue2s(stk) setnilvalue(s2v(stk))
212213

213214

214215
#define isabstkey(v) checktag((v), LUA_VABSTKEY)

lstate.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ LUAI_FUNC void luaE_incCstack (lua_State *L) {
151151
static void resetCI (lua_State *L) {
152152
CallInfo *ci = L->ci = &L->base_ci;
153153
ci->func.p = L->stack.p;
154-
setnilvalue(s2v(ci->func.p)); /* 'function' entry for basic 'ci' */
154+
setnilvalue2s(ci->func.p); /* 'function' entry for basic 'ci' */
155155
ci->top.p = ci->func.p + 1 + LUA_MINSTACK; /* +1 for 'function' entry */
156156
ci->u.c.k = NULL;
157157
ci->callstatus = CIST_C;
@@ -166,7 +166,7 @@ static void stack_init (lua_State *L1, lua_State *L) {
166166
L1->stack.p = luaM_newvector(L, BASIC_STACK_SIZE + EXTRA_STACK, StackValue);
167167
L1->tbclist.p = L1->stack.p;
168168
for (i = 0; i < BASIC_STACK_SIZE + EXTRA_STACK; i++)
169-
setnilvalue(s2v(L1->stack.p + i)); /* erase new stack */
169+
setnilvalue2s(L1->stack.p + i); /* erase new stack */
170170
L1->stack_last.p = L1->stack.p + BASIC_STACK_SIZE;
171171
/* initialize first ci */
172172
resetCI(L1);

ltests.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1145,7 +1145,7 @@ static int table_query (lua_State *L) {
11451145
if (!tagisempty(*getArrTag(t, i)))
11461146
arr2obj(t, cast_uint(i), s2v(L->top.p));
11471147
else
1148-
setnilvalue(s2v(L->top.p));
1148+
setnilvalue2s(L->top.p);
11491149
api_incr_top(L);
11501150
lua_pushnil(L);
11511151
}

ltm.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ static void buildhiddenargs (lua_State *L, CallInfo *ci, const Proto *p,
262262
/* move fixed parameters to after the copied function */
263263
for (i = 1; i <= nfixparams; i++) {
264264
setobjs2s(L, L->top.p++, ci->func.p + i);
265-
setnilvalue(s2v(ci->func.p + i)); /* erase original parameter (for GC) */
265+
setnilvalue2s(ci->func.p + i); /* erase original parameter (for GC) */
266266
}
267267
ci->func.p += totalargs + 1; /* 'func' now lives after hidden arguments */
268268
ci->top.p += totalargs + 1;
@@ -283,7 +283,7 @@ void luaT_adjustvarargs (lua_State *L, CallInfo *ci, const Proto *p) {
283283
lua_assert(p->flag & PF_VAHID);
284284
buildhiddenargs(L, ci, p, totalargs, nfixparams, nextra);
285285
/* set vararg parameter to nil */
286-
setnilvalue(s2v(ci->func.p + nfixparams + 1));
286+
setnilvalue2s(ci->func.p + nfixparams + 1);
287287
lua_assert(L->top.p <= ci->top.p && ci->top.p <= L->stack_last.p);
288288
}
289289
}
@@ -307,7 +307,7 @@ void luaT_getvararg (CallInfo *ci, StkId ra, TValue *rc) {
307307
return;
308308
}
309309
}
310-
setnilvalue(s2v(ra)); /* else produce nil */
310+
setnilvalue2s(ra); /* else produce nil */
311311
}
312312

313313

@@ -355,10 +355,10 @@ void luaT_getvarargs (lua_State *L, CallInfo *ci, StkId where, int wanted,
355355
for (i = 0; i < touse; i++) {
356356
lu_byte tag = luaH_getint(h, i + 1, s2v(where + i));
357357
if (tagisempty(tag))
358-
setnilvalue(s2v(where + i));
358+
setnilvalue2s(where + i);
359359
}
360360
}
361361
for (; i < wanted; i++) /* complete required results with nil */
362-
setnilvalue(s2v(where + i));
362+
setnilvalue2s(where + i);
363363
}
364364

lvm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ lu_byte luaV_finishget (lua_State *L, const TValue *t, TValue *key,
303303
else { /* 't' is a table */
304304
tm = fasttm(L, hvalue(t)->metatable, TM_INDEX); /* table's metamethod */
305305
if (tm == NULL) { /* no metamethod? */
306-
setnilvalue(s2v(val)); /* result is nil */
306+
setnilvalue2s(val); /* result is nil */
307307
return LUA_VNIL;
308308
}
309309
/* else will try the metamethod */

0 commit comments

Comments
 (0)