From b359d1a69e9c2db09444264a8d9d874e156fd14b Mon Sep 17 00:00:00 2001 From: Li Jin Date: Thu, 11 Mar 2021 08:56:23 +0800 Subject: update Lua. --- src/lua/lapi.c | 15 ++++++++------- src/lua/lauxlib.h | 9 +++------ src/lua/ldebug.c | 5 ++++- src/lua/lfunc.c | 40 +++++++++++++++++++++++++++++----------- src/lua/lobject.h | 5 +++-- src/lua/lua.h | 6 +++--- src/lua/luaconf.h | 18 ++++++++++++------ 7 files changed, 62 insertions(+), 36 deletions(-) (limited to 'src') diff --git a/src/lua/lapi.c b/src/lua/lapi.c index a9cf2fd..f8f70cd 100644 --- a/src/lua/lapi.c +++ b/src/lua/lapi.c @@ -173,7 +173,7 @@ LUA_API int lua_gettop (lua_State *L) { LUA_API void lua_settop (lua_State *L, int idx) { CallInfo *ci; - StkId func; + StkId func, newtop; ptrdiff_t diff; /* difference for new top */ lua_lock(L); ci = L->ci; @@ -188,12 +188,13 @@ LUA_API void lua_settop (lua_State *L, int idx) { api_check(L, -(idx+1) <= (L->top - (func + 1)), "invalid new top"); diff = idx + 1; /* will "subtract" index (as it is negative) */ } -#if defined(LUA_COMPAT_5_4_0) - if (diff < 0 && hastocloseCfunc(ci->nresults)) - luaF_close(L, L->top + diff, CLOSEKTOP, 0); -#endif - api_check(L, L->tbclist < L->top + diff, "cannot pop an unclosed slot"); - L->top += diff; + api_check(L, L->tbclist < L->top, "previous pop of an unclosed slot"); + newtop = L->top + diff; + if (diff < 0 && L->tbclist >= newtop) { + lua_assert(hastocloseCfunc(ci->nresults)); + luaF_close(L, newtop, CLOSEKTOP, 0); + } + L->top = newtop; /* correct top only after closing any upvalue */ lua_unlock(L); } diff --git a/src/lua/lauxlib.h b/src/lua/lauxlib.h index 9058e26..72f70e7 100644 --- a/src/lua/lauxlib.h +++ b/src/lua/lauxlib.h @@ -12,6 +12,7 @@ #include #include +#include "luaconf.h" #include "lua.h" @@ -122,10 +123,6 @@ LUALIB_API void (luaL_requiref) (lua_State *L, const char *modname, ** =============================================================== */ -#if !defined(l_likely) -#define l_likely(x) x -#endif - #define luaL_newlibtable(L,l) \ lua_createtable(L, 0, sizeof(l)/sizeof((l)[0]) - 1) @@ -134,10 +131,10 @@ LUALIB_API void (luaL_requiref) (lua_State *L, const char *modname, (luaL_checkversion(L), luaL_newlibtable(L,l), luaL_setfuncs(L,l,0)) #define luaL_argcheck(L, cond,arg,extramsg) \ - ((void)(l_likely(cond) || luaL_argerror(L, (arg), (extramsg)))) + ((void)(luai_likely(cond) || luaL_argerror(L, (arg), (extramsg)))) #define luaL_argexpected(L,cond,arg,tname) \ - ((void)(l_likely(cond) || luaL_typeerror(L, (arg), (tname)))) + ((void)(luai_likely(cond) || luaL_typeerror(L, (arg), (tname)))) #define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL)) #define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL)) diff --git a/src/lua/ldebug.c b/src/lua/ldebug.c index 8e3657a..1feaab2 100644 --- a/src/lua/ldebug.c +++ b/src/lua/ldebug.c @@ -50,6 +50,8 @@ static int currentpc (CallInfo *ci) { ** an integer division gets the right place. When the source file has ** large sequences of empty/comment lines, it may need extra entries, ** so the original estimate needs a correction. +** If the original estimate is -1, the initial 'if' ensures that the +** 'while' will run at least once. ** The assertion that the estimate is a lower bound for the correct base ** is valid as long as the debug info has been generated with the same ** value for MAXIWTHABS or smaller. (Previous releases use a little @@ -63,7 +65,8 @@ static int getbaseline (const Proto *f, int pc, int *basepc) { else { int i = cast_uint(pc) / MAXIWTHABS - 1; /* get an estimate */ /* estimate must be a lower bond of the correct base */ - lua_assert(i < f->sizeabslineinfo && f->abslineinfo[i].pc <= pc); + lua_assert(i < 0 || + (i < f->sizeabslineinfo && f->abslineinfo[i].pc <= pc)); while (i + 1 < f->sizeabslineinfo && pc >= f->abslineinfo[i + 1].pc) i++; /* low estimate; adjust it */ *basepc = f->abslineinfo[i].pc; diff --git a/src/lua/lfunc.c b/src/lua/lfunc.c index b4c04bd..f5889a2 100644 --- a/src/lua/lfunc.c +++ b/src/lua/lfunc.c @@ -154,6 +154,15 @@ static void prepcallclosemth (lua_State *L, StkId level, int status, int yy) { } +/* +** Maximum value for deltas in 'tbclist', dependent on the type +** of delta. (This macro assumes that an 'L' is in scope where it +** is used.) +*/ +#define MAXDELTA \ + ((256ul << ((sizeof(L->stack->tbclist.delta) - 1) * 8)) - 1) + + /* ** Insert a variable in the list of to-be-closed variables. */ @@ -162,13 +171,11 @@ void luaF_newtbcupval (lua_State *L, StkId level) { if (l_isfalse(s2v(level))) return; /* false doesn't need to be closed */ checkclosemth(L, level); /* value must have a close method */ - while (level - L->tbclist > USHRT_MAX) { /* is delta too large? */ - L->tbclist += USHRT_MAX; /* create a dummy node at maximum delta */ - L->tbclist->tbclist.delta = USHRT_MAX; - L->tbclist->tbclist.isdummy = 1; + while (cast_uint(level - L->tbclist) > MAXDELTA) { + L->tbclist += MAXDELTA; /* create a dummy node at maximum delta */ + L->tbclist->tbclist.delta = 0; } - level->tbclist.delta = level - L->tbclist; - level->tbclist.isdummy = 0; + level->tbclist.delta = cast(unsigned short, level - L->tbclist); L->tbclist = level; } @@ -201,6 +208,19 @@ void luaF_closeupval (lua_State *L, StkId level) { } +/* +** Remove firt element from the tbclist plus its dummy nodes. +*/ +static void poptbclist (lua_State *L) { + StkId tbc = L->tbclist; + lua_assert(tbc->tbclist.delta > 0); /* first element cannot be dummy */ + tbc -= tbc->tbclist.delta; + while (tbc > L->stack && tbc->tbclist.delta == 0) + tbc -= MAXDELTA; /* remove dummy nodes */ + L->tbclist = tbc; +} + + /* ** Close all upvalues and to-be-closed variables up to the given stack ** level. @@ -210,11 +230,9 @@ void luaF_close (lua_State *L, StkId level, int status, int yy) { luaF_closeupval(L, level); /* first, close the upvalues */ while (L->tbclist >= level) { /* traverse tbc's down to that level */ StkId tbc = L->tbclist; /* get variable index */ - L->tbclist -= tbc->tbclist.delta; /* remove it from list */ - if (!tbc->tbclist.isdummy) { /* not a dummy entry? */ - prepcallclosemth(L, tbc, status, yy); /* close variable */ - level = restorestack(L, levelrel); - } + poptbclist(L); /* remove it from list */ + prepcallclosemth(L, tbc, status, yy); /* close variable */ + level = restorestack(L, levelrel); } } diff --git a/src/lua/lobject.h b/src/lua/lobject.h index 1a7a737..950bebb 100644 --- a/src/lua/lobject.h +++ b/src/lua/lobject.h @@ -139,13 +139,14 @@ typedef struct TValue { ** Entries in a Lua stack. Field 'tbclist' forms a list of all ** to-be-closed variables active in this stack. Dummy entries are ** used when the distance between two tbc variables does not fit -** in an unsigned short. +** in an unsigned short. They are represented by delta==0, and +** their real delta is always the maximum value that fits in +** that field. */ typedef union StackValue { TValue val; struct { TValuefields; - lu_byte isdummy; unsigned short delta; } tbclist; } StackValue; diff --git a/src/lua/lua.h b/src/lua/lua.h index aec70da..820535b 100644 --- a/src/lua/lua.h +++ b/src/lua/lua.h @@ -18,14 +18,14 @@ #define LUA_VERSION_MAJOR "5" #define LUA_VERSION_MINOR "4" -#define LUA_VERSION_RELEASE "2" +#define LUA_VERSION_RELEASE "3" #define LUA_VERSION_NUM 504 #define LUA_VERSION_RELEASE_NUM (LUA_VERSION_NUM * 100 + 0) #define LUA_VERSION "Lua " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR #define LUA_RELEASE LUA_VERSION "." LUA_VERSION_RELEASE -#define LUA_COPYRIGHT LUA_RELEASE " Copyright (C) 1994-2020 Lua.org, PUC-Rio" +#define LUA_COPYRIGHT LUA_RELEASE " Copyright (C) 1994-2021 Lua.org, PUC-Rio" #define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo, W. Celes" @@ -492,7 +492,7 @@ struct lua_Debug { /****************************************************************************** -* Copyright (C) 1994-2020 Lua.org, PUC-Rio. +* Copyright (C) 1994-2021 Lua.org, PUC-Rio. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/src/lua/luaconf.h b/src/lua/luaconf.h index ae73e2f..38e14ed 100644 --- a/src/lua/luaconf.h +++ b/src/lua/luaconf.h @@ -665,20 +665,26 @@ ** macros to improve jump prediction, used mostly for error handling ** and debug facilities. */ -#if (defined(LUA_CORE) || defined(LUA_LIB)) && !defined(l_likely) +#if !defined(luai_likely) -#include #if defined(__GNUC__) -#define l_likely(x) (__builtin_expect(((x) != 0), 1)) -#define l_unlikely(x) (__builtin_expect(((x) != 0), 0)) +#define luai_likely(x) (__builtin_expect(((x) != 0), 1)) +#define luai_unlikely(x) (__builtin_expect(((x) != 0), 0)) #else -#define l_likely(x) (x) -#define l_unlikely(x) (x) +#define luai_likely(x) (x) +#define luai_unlikely(x) (x) #endif #endif +#if defined(LUA_CORE) || defined(LUA_LIB) +/* shorter names for Lua's own use */ +#define l_likely(x) luai_likely(x) +#define l_unlikely(x) luai_unlikely(x) +#endif + + /* }================================================================== */ -- cgit v1.2.3-55-g6feb