From 3b06f983ae0e57b90cdeb500c84bb524e5c3635b Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 11 Dec 2018 11:54:14 -0200 Subject: [PATCH] Details - in 'luaB_tonumber', do not need to "checkany" when argument is a number. - in 'lua_resume', the call to 'luaD_rawrunprotected' cannot return a status equal to -1. --- lbaselib.c | 2 +- ldo.c | 29 +++++++++++++---------------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/lbaselib.c b/lbaselib.c index 201c93e3..7c0ebfec 100644 --- a/lbaselib.c +++ b/lbaselib.c @@ -68,7 +68,6 @@ static const char *b_str2int (const char *s, int base, lua_Integer *pn) { static int luaB_tonumber (lua_State *L) { if (lua_isnoneornil(L, 2)) { /* standard conversion? */ - luaL_checkany(L, 1); if (lua_type(L, 1) == LUA_TNUMBER) { /* already a number? */ lua_settop(L, 1); /* yes; return it */ return 1; @@ -79,6 +78,7 @@ static int luaB_tonumber (lua_State *L) { if (s != NULL && lua_stringtonumber(L, s) == l + 1) return 1; /* successful conversion to number */ /* else not a number */ + luaL_checkany(L, 1); /* (but there must be some parameter) */ } } else { diff --git a/ldo.c b/ldo.c index 2762fefa..bdd7fb6d 100644 --- a/ldo.c +++ b/ldo.c @@ -678,22 +678,19 @@ LUA_API int lua_resume (lua_State *L, lua_State *from, int nargs, L->nny = 0; /* allow yields */ api_checknelems(L, (L->status == LUA_OK) ? nargs + 1 : nargs); status = luaD_rawrunprotected(L, resume, &nargs); - if (unlikely(status == -1)) /* error calling 'lua_resume'? */ - status = LUA_ERRRUN; - else { /* continue running after recoverable errors */ - while (errorstatus(status) && recover(L, status)) { - /* unroll continuation */ - status = luaD_rawrunprotected(L, unroll, &status); - } - if (likely(!errorstatus(status))) - lua_assert(status == L->status); /* normal end or yield */ - else { /* unrecoverable error */ - status = luaF_close(L, L->stack, status); /* close all upvalues */ - L->status = cast_byte(status); /* mark thread as 'dead' */ - luaD_seterrorobj(L, status, L->stack + 1); /* push error message */ - L->ci = &L->base_ci; /* back to the original C level */ - L->ci->top = L->top; - } + /* continue running after recoverable errors */ + while (errorstatus(status) && recover(L, status)) { + /* unroll continuation */ + status = luaD_rawrunprotected(L, unroll, &status); + } + if (likely(!errorstatus(status))) + lua_assert(status == L->status); /* normal end or yield */ + else { /* unrecoverable error */ + status = luaF_close(L, L->stack, status); /* close all upvalues */ + L->status = cast_byte(status); /* mark thread as 'dead' */ + luaD_seterrorobj(L, status, L->stack + 1); /* push error message */ + L->ci = &L->base_ci; /* back to the original C level */ + L->ci->top = L->top; } *nresults = (status == LUA_YIELD) ? L->ci->u2.nyield : cast_int(L->top - (L->ci->func + 1));