Skip to content

Commit 10d42c6

Browse files
feat: update from origin to latest 5.4.5 changes
1 parent 05a8879 commit 10d42c6

58 files changed

Lines changed: 5481 additions & 3473 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

include/lapi.h

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,29 @@
1212
#include "lstate.h"
1313

1414

15+
#if defined(LUA_USE_APICHECK)
16+
#include <assert.h>
17+
#define api_check(l,e,msg) assert(e)
18+
#else /* for testing */
19+
#define api_check(l,e,msg) ((void)(l), lua_assert((e) && msg))
20+
#endif
21+
22+
23+
1524
/* Increments 'L->top.p', checking for stack overflows */
16-
#define api_incr_top(L) {L->top.p++; \
17-
api_check(L, L->top.p <= L->ci->top.p, \
18-
"stack overflow");}
25+
#define api_incr_top(L) \
26+
(L->top.p++, api_check(L, L->top.p <= L->ci->top.p, "stack overflow"))
27+
28+
29+
/*
30+
** macros that are executed whenever program enters the Lua core
31+
** ('lua_lock') and leaves the core ('lua_unlock')
32+
*/
33+
#if !defined(lua_lock)
34+
#define lua_lock(L) ((void) 0)
35+
#define lua_unlock(L) ((void) 0)
36+
#endif
37+
1938

2039

2140
/*
@@ -30,23 +49,17 @@
3049

3150
/* Ensure the stack has at least 'n' elements */
3251
#define api_checknelems(L,n) \
33-
api_check(L, (n) < (L->top.p - L->ci->func.p), \
34-
"not enough elements in the stack")
52+
api_check(L, (n) < (L->top.p - L->ci->func.p), \
53+
"not enough elements in the stack")
3554

3655

37-
/*
38-
** To reduce the overhead of returning from C functions, the presence of
39-
** to-be-closed variables in these functions is coded in the CallInfo's
40-
** field 'nresults', in a way that functions with no to-be-closed variables
41-
** with zero, one, or "all" wanted results have no overhead. Functions
42-
** with other number of wanted results, as well as functions with
43-
** variables to be closed, have an extra check.
56+
/* Ensure the stack has at least 'n' elements to be popped. (Some
57+
** functions only update a slot after checking it for popping, but that
58+
** is only an optimization for a pop followed by a push.)
4459
*/
45-
46-
#define hastocloseCfunc(n) ((n) < LUA_MULTRET)
47-
48-
/* Map [-1, inf) (range of 'nresults') into (-inf, -2] */
49-
#define codeNresults(n) (-(n) - 3)
50-
#define decodeNresults(n) (-(n) - 3)
60+
#define api_checkpop(L,n) \
61+
api_check(L, (n) < L->top.p - L->ci->func.p && \
62+
L->tbclist.p < L->top.p - (n), \
63+
"not enough free elements in the stack")
5164

5265
#endif

include/lauxlib.h

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s);
100100

101101
LUALIB_API lua_State *(luaL_newstate) (void);
102102

103+
LUALIB_API unsigned luaL_makeseed (lua_State *L);
104+
103105
LUALIB_API lua_Integer (luaL_len) (lua_State *L, int idx);
104106

105107
LUALIB_API void (luaL_addgsub) (luaL_Buffer *b, const char *s,
@@ -163,21 +165,10 @@ LUALIB_API void (luaL_requiref) (lua_State *L, const char *modname,
163165

164166

165167
/* push the value used to represent failure/error */
166-
#define luaL_pushfail(L) lua_pushnil(L)
167-
168-
169-
/*
170-
** Internal assertions for in-house debugging
171-
*/
172-
#if !defined(lua_assert)
173-
174-
#if defined LUAI_ASSERT
175-
#include <assert.h>
176-
#define lua_assert(c) assert(c)
168+
#if defined(LUA_FAILISFALSE)
169+
#define luaL_pushfail(L) lua_pushboolean(L, 0)
177170
#else
178-
#define lua_assert(c) ((void)0)
179-
#endif
180-
171+
#define luaL_pushfail(L) lua_pushnil(L)
181172
#endif
182173

183174

@@ -249,30 +240,6 @@ typedef struct luaL_Stream {
249240

250241
/* }====================================================== */
251242

252-
/*
253-
** {==================================================================
254-
** "Abstraction Layer" for basic report of messages and errors
255-
** ===================================================================
256-
*/
257-
258-
/* print a string */
259-
#if !defined(lua_writestring)
260-
#define lua_writestring(s,l) fwrite((s), sizeof(char), (l), stdout)
261-
#endif
262-
263-
/* print a newline and flush the output */
264-
#if !defined(lua_writeline)
265-
#define lua_writeline() (lua_writestring("\n", 1), fflush(stdout))
266-
#endif
267-
268-
/* print an error message */
269-
#if !defined(lua_writestringerror)
270-
#define lua_writestringerror(s,p) \
271-
(fprintf(stderr, (s), (p)), fflush(stderr))
272-
#endif
273-
274-
/* }================================================================== */
275-
276243

277244
/*
278245
** {============================================================

include/lcode.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ typedef enum UnOpr { OPR_MINUS, OPR_BNOT, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr;
6060
#define luaK_jumpto(fs,t) luaK_patchlist(fs, luaK_jump(fs), t)
6161

6262
LUAI_FUNC int luaK_code (FuncState *fs, Instruction i);
63-
LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx);
64-
LUAI_FUNC int luaK_codeAsBx (FuncState *fs, OpCode o, int A, int Bx);
65-
LUAI_FUNC int luaK_codeABCk (FuncState *fs, OpCode o, int A,
66-
int B, int C, int k);
67-
LUAI_FUNC int luaK_isKint (expdesc *e);
63+
LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, int Bx);
64+
LUAI_FUNC int luaK_codeABCk (FuncState *fs, OpCode o, int A, int B, int C,
65+
int k);
66+
LUAI_FUNC int luaK_codevABCk (FuncState *fs, OpCode o, int A, int B, int C,
67+
int k);
6868
LUAI_FUNC int luaK_exp2const (FuncState *fs, const expdesc *e, TValue *v);
6969
LUAI_FUNC void luaK_fixline (FuncState *fs, int line);
7070
LUAI_FUNC void luaK_nil (FuncState *fs, int from, int n);
@@ -76,7 +76,6 @@ LUAI_FUNC int luaK_exp2anyreg (FuncState *fs, expdesc *e);
7676
LUAI_FUNC void luaK_exp2anyregup (FuncState *fs, expdesc *e);
7777
LUAI_FUNC void luaK_exp2nextreg (FuncState *fs, expdesc *e);
7878
LUAI_FUNC void luaK_exp2val (FuncState *fs, expdesc *e);
79-
LUAI_FUNC int luaK_exp2RK (FuncState *fs, expdesc *e);
8079
LUAI_FUNC void luaK_self (FuncState *fs, expdesc *e, expdesc *key);
8180
LUAI_FUNC void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k);
8281
LUAI_FUNC void luaK_goiftrue (FuncState *fs, expdesc *e);
@@ -98,7 +97,7 @@ LUAI_FUNC void luaK_settablesize (FuncState *fs, int pc,
9897
int ra, int asize, int hsize);
9998
LUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore);
10099
LUAI_FUNC void luaK_finish (FuncState *fs);
101-
LUAI_FUNC l_noret luaK_semerror (LexState *ls, const char *msg);
100+
LUAI_FUNC l_noret luaK_semerror (LexState *ls, const char *fmt, ...);
102101

103102

104103
#endif

include/ldebug.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ LUAI_FUNC const char *luaG_addinfo (lua_State *L, const char *msg,
5858
TString *src, int line);
5959
LUAI_FUNC l_noret luaG_errormsg (lua_State *L);
6060
LUAI_FUNC int luaG_traceexec (lua_State *L, const Instruction *pc);
61+
LUAI_FUNC int luaG_tracecall (lua_State *L);
6162

6263

6364
#endif

include/ldo.h

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,19 @@
2323
** 'condmovestack' is used in heavy tests to force a stack reallocation
2424
** at every check.
2525
*/
26+
27+
#if !defined(HARDSTACKTESTS)
28+
#define condmovestack(L,pre,pos) ((void)0)
29+
#else
30+
/* realloc stack keeping its size */
31+
#define condmovestack(L,pre,pos) \
32+
{ int sz_ = stacksize(L); pre; luaD_reallocstack((L), sz_, 0); pos; }
33+
#endif
34+
2635
#define luaD_checkstackaux(L,n,pre,pos) \
2736
if (l_unlikely(L->stack_last.p - L->top.p <= (n))) \
2837
{ pre; luaD_growstack(L, n, 1); pos; } \
29-
else { condmovestack(L,pre,pos); }
38+
else { condmovestack(L,pre,pos); }
3039

3140
/* In general, 'pre'/'pos' are empty (nothing to save) */
3241
#define luaD_checkstack(L,n) luaD_checkstackaux(L,n,(void)0,(void)0)
@@ -44,24 +53,24 @@
4453
p = restorestack(L, t__)) /* 'pos' part: restore 'p' */
4554

4655

47-
/* macro to check stack size and GC, preserving 'p' */
48-
#define checkstackGCp(L,n,p) \
49-
luaD_checkstackaux(L, n, \
50-
ptrdiff_t t__ = savestack(L, p); /* save 'p' */ \
51-
luaC_checkGC(L), /* stack grow uses memory */ \
52-
p = restorestack(L, t__)) /* 'pos' part: restore 'p' */
53-
54-
55-
/* macro to check stack size and GC */
56-
#define checkstackGC(L,fsize) \
57-
luaD_checkstackaux(L, (fsize), luaC_checkGC(L), (void)0)
56+
/*
57+
** Maximum depth for nested C calls, syntactical nested non-terminals,
58+
** and other features implemented through recursion in C. (Value must
59+
** fit in a 16-bit unsigned integer. It must also be compatible with
60+
** the size of the C stack.)
61+
*/
62+
#if !defined(LUAI_MAXCCALLS)
63+
#define LUAI_MAXCCALLS 200
64+
#endif
5865

5966

6067
/* type of protected functions, to be ran by 'runprotected' */
6168
typedef void (*Pfunc) (lua_State *L, void *ud);
6269

63-
LUAI_FUNC void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop);
64-
LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name,
70+
LUAI_FUNC l_noret luaD_errerr (lua_State *L);
71+
LUAI_FUNC void luaD_seterrorobj (lua_State *L, TStatus errcode, StkId oldtop);
72+
LUAI_FUNC TStatus luaD_protectedparser (lua_State *L, ZIO *z,
73+
const char *name,
6574
const char *mode);
6675
LUAI_FUNC void luaD_hook (lua_State *L, int event, int line,
6776
int fTransfer, int nTransfer);
@@ -71,18 +80,19 @@ LUAI_FUNC int luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func,
7180
LUAI_FUNC CallInfo *luaD_precall (lua_State *L, StkId func, int nResults);
7281
LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults);
7382
LUAI_FUNC void luaD_callnoyield (lua_State *L, StkId func, int nResults);
74-
LUAI_FUNC StkId luaD_tryfuncTM (lua_State *L, StkId func);
75-
LUAI_FUNC int luaD_closeprotected (lua_State *L, ptrdiff_t level, int status);
76-
LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u,
83+
LUAI_FUNC TStatus luaD_closeprotected (lua_State *L, ptrdiff_t level,
84+
TStatus status);
85+
LUAI_FUNC TStatus luaD_pcall (lua_State *L, Pfunc func, void *u,
7786
ptrdiff_t oldtop, ptrdiff_t ef);
7887
LUAI_FUNC void luaD_poscall (lua_State *L, CallInfo *ci, int nres);
7988
LUAI_FUNC int luaD_reallocstack (lua_State *L, int newsize, int raiseerror);
8089
LUAI_FUNC int luaD_growstack (lua_State *L, int n, int raiseerror);
8190
LUAI_FUNC void luaD_shrinkstack (lua_State *L);
8291
LUAI_FUNC void luaD_inctop (lua_State *L);
8392

84-
LUAI_FUNC l_noret luaD_throw (lua_State *L, int errcode);
85-
LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud);
93+
LUAI_FUNC l_noret luaD_throw (lua_State *L, TStatus errcode);
94+
LUAI_FUNC l_noret luaD_throwbaselevel (lua_State *L, TStatus errcode);
95+
LUAI_FUNC TStatus luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud);
8696

8797
#endif
8898

include/lfunc.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
#include "lobject.h"
1212

1313

14-
#define sizeCclosure(n) (cast_int(offsetof(CClosure, upvalue)) + \
15-
cast_int(sizeof(TValue)) * (n))
14+
#define sizeCclosure(n) \
15+
(offsetof(CClosure, upvalue) + sizeof(TValue) * cast_uint(n))
1616

17-
#define sizeLclosure(n) (cast_int(offsetof(LClosure, upvals)) + \
18-
cast_int(sizeof(TValue *)) * (n))
17+
#define sizeLclosure(n) \
18+
(offsetof(LClosure, upvals) + sizeof(UpVal *) * cast_uint(n))
1919

2020

2121
/* test whether thread is in 'twups' list */
@@ -44,7 +44,7 @@
4444

4545

4646
/* special status to close upvalues preserving the top of the stack */
47-
#define CLOSEKTOP (-1)
47+
#define CLOSEKTOP (LUA_ERRERR + 1)
4848

4949

5050
LUAI_FUNC Proto *luaF_newproto (lua_State *L);
@@ -54,8 +54,9 @@ LUAI_FUNC void luaF_initupvals (lua_State *L, LClosure *cl);
5454
LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level);
5555
LUAI_FUNC void luaF_newtbcupval (lua_State *L, StkId level);
5656
LUAI_FUNC void luaF_closeupval (lua_State *L, StkId level);
57-
LUAI_FUNC StkId luaF_close (lua_State *L, StkId level, int status, int yy);
57+
LUAI_FUNC StkId luaF_close (lua_State *L, StkId level, TStatus status, int yy);
5858
LUAI_FUNC void luaF_unlinkupval (UpVal *uv);
59+
LUAI_FUNC lu_mem luaF_protosize (Proto *p);
5960
LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f);
6061
LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number,
6162
int pc);

0 commit comments

Comments
 (0)