From 0b63d79b36790febd4c081bf8d6737df27529f8d Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 13 May 2019 16:20:40 -0300 Subject: [PATCH] Details - 'luaL_setfuncs' avoids creating closures for placeholders. - Fixed some warnings about unused values in comma expressions. - Comments. --- lauxlib.c | 10 +++++++--- ldo.c | 2 +- liolib.c | 2 +- ltablib.c | 2 +- ltests.c | 8 +++----- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/lauxlib.c b/lauxlib.c index dfe501a7..89e53dc1 100644 --- a/lauxlib.c +++ b/lauxlib.c @@ -898,9 +898,13 @@ LUALIB_API void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) { luaL_checkstack(L, nup, "too many upvalues"); for (; l->name != NULL; l++) { /* fill the table with given functions */ int i; - for (i = 0; i < nup; i++) /* copy upvalues to the top */ - lua_pushvalue(L, -nup); - lua_pushcclosure(L, l->func, nup); /* closure with those upvalues */ + if (l->func == NULL) /* place holder? */ + lua_pushboolean(L, 0); + else { + for (i = 0; i < nup; i++) /* copy upvalues to the top */ + lua_pushvalue(L, -nup); + lua_pushcclosure(L, l->func, nup); /* closure with those upvalues */ + } lua_setfield(L, -(nup + 2), l->name); } lua_pop(L, nup); /* remove upvalues */ diff --git a/ldo.c b/ldo.c index e9a88e9e..e7e76a65 100644 --- a/ldo.c +++ b/ldo.c @@ -669,7 +669,7 @@ LUA_API int lua_resume (lua_State *L, lua_State *from, int nargs, else if (L->top - (L->ci->func + 1) == nargs) /* no function? */ return resume_error(L, "cannot resume dead coroutine", nargs); } - else if (L->status != LUA_YIELD) + else if (L->status != LUA_YIELD) /* ended with errors? */ return resume_error(L, "cannot resume dead coroutine", nargs); if (from == NULL) L->nCcalls = 1; diff --git a/liolib.c b/liolib.c index 7d6d51e6..fa6a0939 100644 --- a/liolib.c +++ b/liolib.c @@ -39,7 +39,7 @@ /* Check whether 'mode' matches '[rwa]%+?[L_MODEEXT]*' */ static int l_checkmode (const char *mode) { return (*mode != '\0' && strchr("rwa", *(mode++)) != NULL && - (*mode != '+' || (++mode, 1)) && /* skip if char is '+' */ + (*mode != '+' || ((void)(++mode), 1)) && /* skip if char is '+' */ (strspn(mode, L_MODEEXT) == strlen(mode))); /* check extensions */ } diff --git a/ltablib.c b/ltablib.c index a9169f9e..48a6bdfe 100644 --- a/ltablib.c +++ b/ltablib.c @@ -299,7 +299,7 @@ static IdxT partition (lua_State *L, IdxT lo, IdxT up) { /* loop invariant: a[lo .. i] <= P <= a[j .. up] */ for (;;) { /* next loop: repeat ++i while a[i] < P */ - while (lua_geti(L, 1, ++i), sort_comp(L, -1, -2)) { + while ((void)lua_geti(L, 1, ++i), sort_comp(L, -1, -2)) { if (i == up - 1) /* a[i] < P but a[up - 1] == P ?? */ luaL_error(L, "invalid order function for sorting"); lua_pop(L, 1); /* remove a[i] */ diff --git a/ltests.c b/ltests.c index 7d441d1a..f786eeb3 100644 --- a/ltests.c +++ b/ltests.c @@ -51,9 +51,8 @@ static int runC (lua_State *L, lua_State *L1, const char *pc); static void setnameval (lua_State *L, const char *name, int val) { - lua_pushstring(L, name); lua_pushinteger(L, val); - lua_settable(L, -3); + lua_setfield(L, -2, name); } @@ -710,12 +709,11 @@ static void printstack (lua_State *L) { static int get_limits (lua_State *L) { - lua_createtable(L, 0, 5); - setnameval(L, "BITS_INT", LUAI_BITSINT); + lua_createtable(L, 0, 6); + setnameval(L, "IS32INT", LUAI_IS32INT); setnameval(L, "MAXARG_Ax", MAXARG_Ax); setnameval(L, "MAXARG_Bx", MAXARG_Bx); setnameval(L, "OFFSET_sBx", OFFSET_sBx); - setnameval(L, "BITS_INT", LUAI_BITSINT); setnameval(L, "LFPF", LFIELDS_PER_FLUSH); setnameval(L, "NUM_OPCODES", NUM_OPCODES); return 1;