Skip to content

Commit 17da2ed

Browse files
chore: pulled version 5.4.4 from origin
1 parent 7216fc9 commit 17da2ed

52 files changed

Lines changed: 2740 additions & 1720 deletions

Some content is hidden

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

fetch_origin.sh

100644100755
File mode changed.

include/lapi.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242

4343
#define hastocloseCfunc(n) ((n) < LUA_MULTRET)
4444

45+
/* Map [-1, inf) (range of 'nresults') into (-inf, -2] */
4546
#define codeNresults(n) (-(n) - 3)
47+
#define decodeNresults(n) (-(n) - 3)
4648

4749
#endif

include/lauxlib.h

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <stddef.h>
1313
#include <stdio.h>
1414

15+
#include "luaconf.h"
1516
#include "lua.h"
1617

1718

@@ -101,7 +102,7 @@ LUALIB_API lua_State *(luaL_newstate) (void);
101102

102103
LUALIB_API lua_Integer (luaL_len) (lua_State *L, int idx);
103104

104-
LUALIB_API void luaL_addgsub (luaL_Buffer *b, const char *s,
105+
LUALIB_API void (luaL_addgsub) (luaL_Buffer *b, const char *s,
105106
const char *p, const char *r);
106107
LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s,
107108
const char *p, const char *r);
@@ -130,10 +131,10 @@ LUALIB_API void (luaL_requiref) (lua_State *L, const char *modname,
130131
(luaL_checkversion(L), luaL_newlibtable(L,l), luaL_setfuncs(L,l,0))
131132

132133
#define luaL_argcheck(L, cond,arg,extramsg) \
133-
((void)((cond) || luaL_argerror(L, (arg), (extramsg))))
134+
((void)(luai_likely(cond) || luaL_argerror(L, (arg), (extramsg))))
134135

135136
#define luaL_argexpected(L,cond,arg,tname) \
136-
((void)((cond) || luaL_typeerror(L, (arg), (tname))))
137+
((void)(luai_likely(cond) || luaL_typeerror(L, (arg), (tname))))
137138

138139
#define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL))
139140
#define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL))
@@ -153,10 +154,34 @@ LUALIB_API void (luaL_requiref) (lua_State *L, const char *modname,
153154
#define luaL_loadbuffer(L,s,sz,n) luaL_loadbufferx(L,s,sz,n,NULL)
154155

155156

157+
/*
158+
** Perform arithmetic operations on lua_Integer values with wrap-around
159+
** semantics, as the Lua core does.
160+
*/
161+
#define luaL_intop(op,v1,v2) \
162+
((lua_Integer)((lua_Unsigned)(v1) op (lua_Unsigned)(v2)))
163+
164+
156165
/* push the value used to represent failure/error */
157166
#define luaL_pushfail(L) lua_pushnil(L)
158167

159168

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)
177+
#else
178+
#define lua_assert(c) ((void)0)
179+
#endif
180+
181+
#endif
182+
183+
184+
160185
/*
161186
** {======================================================
162187
** Generic Buffer manipulation

include/lctype.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
/*
1414
** WARNING: the functions defined here do not necessarily correspond
1515
** to the similar functions in the standard C ctype.h. They are
16-
** optimized for the specific needs of Lua
16+
** optimized for the specific needs of Lua.
1717
*/
1818

1919
#if !defined(LUA_USE_CTYPE)
@@ -61,13 +61,19 @@
6161
#define lisprint(c) testprop(c, MASK(PRINTBIT))
6262
#define lisxdigit(c) testprop(c, MASK(XDIGITBIT))
6363

64+
6465
/*
65-
** this 'ltolower' only works for alphabetic characters
66+
** In ASCII, this 'ltolower' is correct for alphabetic characters and
67+
** for '.'. That is enough for Lua needs. ('check_exp' ensures that
68+
** the character either is an upper-case letter or is unchanged by
69+
** the transformation, which holds for lower-case letters and '.'.)
6670
*/
67-
#define ltolower(c) ((c) | ('A' ^ 'a'))
71+
#define ltolower(c) \
72+
check_exp(('A' <= (c) && (c) <= 'Z') || (c) == ((c) | ('A' ^ 'a')), \
73+
(c) | ('A' ^ 'a'))
6874

6975

70-
/* two more entries for 0 and -1 (EOZ) */
76+
/* one entry for each character and for -1 (EOZ) */
7177
LUAI_DDEC(const lu_byte luai_ctype_[UCHAR_MAX + 2];)
7278

7379

include/ldebug.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313

1414
#define pcRel(pc, p) (cast_int((pc) - (p)->code) - 1)
1515

16+
17+
/* Active Lua function (given call info) */
18+
#define ci_func(ci) (clLvalue(s2v((ci)->func)))
19+
20+
1621
#define resethookcount(L) (L->hookcount = L->basehookcount)
1722

1823
/*
@@ -21,11 +26,22 @@
2126
*/
2227
#define ABSLINEINFO (-0x80)
2328

29+
30+
/*
31+
** MAXimum number of successive Instructions WiTHout ABSolute line
32+
** information. (A power of two allows fast divisions.)
33+
*/
34+
#if !defined(MAXIWTHABS)
35+
#define MAXIWTHABS 128
36+
#endif
37+
38+
2439
LUAI_FUNC int luaG_getfuncline (const Proto *f, int pc);
2540
LUAI_FUNC const char *luaG_findlocal (lua_State *L, CallInfo *ci, int n,
2641
StkId *pos);
2742
LUAI_FUNC l_noret luaG_typeerror (lua_State *L, const TValue *o,
2843
const char *opname);
44+
LUAI_FUNC l_noret luaG_callerror (lua_State *L, const TValue *o);
2945
LUAI_FUNC l_noret luaG_forerror (lua_State *L, const TValue *o,
3046
const char *what);
3147
LUAI_FUNC l_noret luaG_concaterror (lua_State *L, const TValue *p1,

include/ldo.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717
** Macro to check stack size and grow stack if needed. Parameters
1818
** 'pre'/'pos' allow the macro to preserve a pointer into the
1919
** stack across reallocations, doing the work only when needed.
20+
** It also allows the running of one GC step when the stack is
21+
** reallocated.
2022
** 'condmovestack' is used in heavy tests to force a stack reallocation
2123
** at every check.
2224
*/
2325
#define luaD_checkstackaux(L,n,pre,pos) \
24-
if (L->stack_last - L->top <= (n)) \
26+
if (l_unlikely(L->stack_last - L->top <= (n))) \
2527
{ pre; luaD_growstack(L, n, 1); pos; } \
2628
else { condmovestack(L,pre,pos); }
2729

@@ -35,7 +37,7 @@
3537

3638

3739
/* macro to check stack size, preserving 'p' */
38-
#define checkstackp(L,n,p) \
40+
#define checkstackGCp(L,n,p) \
3941
luaD_checkstackaux(L, n, \
4042
ptrdiff_t t__ = savestack(L, p); /* save 'p' */ \
4143
luaC_checkGC(L), /* stack grow uses memory */ \
@@ -44,7 +46,7 @@
4446

4547
/* macro to check stack size and GC */
4648
#define checkstackGC(L,fsize) \
47-
luaD_checkstackaux(L, (fsize), (void)0, luaC_checkGC(L))
49+
luaD_checkstackaux(L, (fsize), luaC_checkGC(L), (void)0)
4850

4951

5052
/* type of protected functions, to be ran by 'runprotected' */
@@ -56,10 +58,12 @@ LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name,
5658
LUAI_FUNC void luaD_hook (lua_State *L, int event, int line,
5759
int fTransfer, int nTransfer);
5860
LUAI_FUNC void luaD_hookcall (lua_State *L, CallInfo *ci);
59-
LUAI_FUNC void luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func, int n);
61+
LUAI_FUNC int luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func, int narg1, int delta);
62+
LUAI_FUNC CallInfo *luaD_precall (lua_State *L, StkId func, int nResults);
6063
LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults);
6164
LUAI_FUNC void luaD_callnoyield (lua_State *L, StkId func, int nResults);
62-
LUAI_FUNC void luaD_tryfuncTM (lua_State *L, StkId func);
65+
LUAI_FUNC StkId luaD_tryfuncTM (lua_State *L, StkId func);
66+
LUAI_FUNC int luaD_closeprotected (lua_State *L, ptrdiff_t level, int status);
6367
LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u,
6468
ptrdiff_t oldtop, ptrdiff_t ef);
6569
LUAI_FUNC void luaD_poscall (lua_State *L, CallInfo *ci, int nres);

include/lfunc.h

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,9 @@
4242
#define MAXMISS 10
4343

4444

45-
/*
46-
** Special "status" for 'luaF_close'
47-
*/
48-
49-
/* close upvalues without running their closing methods */
50-
#define NOCLOSINGMETH (-1)
5145

52-
/* close upvalues running all closing methods in protected mode */
53-
#define CLOSEPROTECT (-2)
46+
/* special status to close upvalues preserving the top of the stack */
47+
#define CLOSEKTOP (-1)
5448

5549

5650
LUAI_FUNC Proto *luaF_newproto (lua_State *L);
@@ -59,7 +53,8 @@ LUAI_FUNC LClosure *luaF_newLclosure (lua_State *L, int nupvals);
5953
LUAI_FUNC void luaF_initupvals (lua_State *L, LClosure *cl);
6054
LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level);
6155
LUAI_FUNC void luaF_newtbcupval (lua_State *L, StkId level);
62-
LUAI_FUNC int luaF_close (lua_State *L, StkId level, int status);
56+
LUAI_FUNC void luaF_closeupval (lua_State *L, StkId level);
57+
LUAI_FUNC void luaF_close (lua_State *L, StkId level, int status, int yy);
6358
LUAI_FUNC void luaF_unlinkupval (UpVal *uv);
6459
LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f);
6560
LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number,

include/lgc.h

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@
1212
#include "lstate.h"
1313

1414
/*
15-
** Collectable objects may have one of three colors: white, which
16-
** means the object is not marked; gray, which means the
17-
** object is marked, but its references may be not marked; and
18-
** black, which means that the object and all its references are marked.
19-
** The main invariant of the garbage collector, while marking objects,
20-
** is that a black object can never point to a white one. Moreover,
21-
** any gray object must be in a "gray list" (gray, grayagain, weak,
22-
** allweak, ephemeron) so that it can be visited again before finishing
23-
** the collection cycle. These lists have no meaning when the invariant
24-
** is not being enforced (e.g., sweep phase).
15+
** Collectable objects may have one of three colors: white, which means
16+
** the object is not marked; gray, which means the object is marked, but
17+
** its references may be not marked; and black, which means that the
18+
** object and all its references are marked. The main invariant of the
19+
** garbage collector, while marking objects, is that a black object can
20+
** never point to a white one. Moreover, any gray object must be in a
21+
** "gray list" (gray, grayagain, weak, allweak, ephemeron) so that it
22+
** can be visited again before finishing the collection cycle. (Open
23+
** upvalues are an exception to this rule.) These lists have no meaning
24+
** when the invariant is not being enforced (e.g., sweep phase).
2525
*/
2626

2727

@@ -69,14 +69,16 @@
6969

7070
/*
7171
** Layout for bit use in 'marked' field. First three bits are
72-
** used for object "age" in generational mode. Last bit is free
73-
** to be used by respective objects.
72+
** used for object "age" in generational mode. Last bit is used
73+
** by tests.
7474
*/
7575
#define WHITE0BIT 3 /* object is white (type 0) */
7676
#define WHITE1BIT 4 /* object is white (type 1) */
7777
#define BLACKBIT 5 /* object is black */
7878
#define FINALIZEDBIT 6 /* object has been marked for finalization */
7979

80+
#define TESTBIT 7
81+
8082

8183

8284
#define WHITEBITS bit2mask(WHITE0BIT, WHITE1BIT)
@@ -94,7 +96,8 @@
9496
#define isdead(g,v) isdeadm(otherwhite(g), (v)->marked)
9597

9698
#define changewhite(x) ((x)->marked ^= WHITEBITS)
97-
#define gray2black(x) l_setbit((x)->marked, BLACKBIT)
99+
#define nw2black(x) \
100+
check_exp(!iswhite(x), l_setbit((x)->marked, BLACKBIT))
98101

99102
#define luaC_white(g) cast_byte((g)->currentwhite & WHITEBITS)
100103

@@ -145,6 +148,16 @@
145148
*/
146149
#define isdecGCmodegen(g) (g->gckind == KGC_GEN || g->lastatomic != 0)
147150

151+
152+
/*
153+
** Control when GC is running:
154+
*/
155+
#define GCSTPUSR 1 /* bit true when GC stopped by user */
156+
#define GCSTPGC 2 /* bit true when GC stopped by itself */
157+
#define GCSTPCLS 4 /* bit true when closing Lua state */
158+
#define gcrunning(g) ((g)->gcstp == 0)
159+
160+
148161
/*
149162
** Does one step of collection when debt becomes positive. 'pre'/'pos'
150163
** allows some adjustments to be done only when needed. macro

include/llex.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,17 @@
77
#ifndef llex_h
88
#define llex_h
99

10+
#include <limits.h>
11+
1012
#include "lobject.h"
1113
#include "lzio.h"
1214

1315

14-
#define FIRST_RESERVED 257
16+
/*
17+
** Single-char tokens (terminal symbols) are represented by their own
18+
** numeric code. Other tokens start at the following value.
19+
*/
20+
#define FIRST_RESERVED (UCHAR_MAX + 1)
1521

1622

1723
#if !defined(LUA_ENV)

0 commit comments

Comments
 (0)