Skip to content

Commit 05a8879

Browse files
feat: update from origit to version 5.4.5
1 parent 17da2ed commit 05a8879

39 files changed

Lines changed: 803 additions & 637 deletions

include/lapi.h

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

1414

15-
/* Increments 'L->top', checking for stack overflows */
16-
#define api_incr_top(L) {L->top++; api_check(L, L->top <= L->ci->top, \
17-
"stack overflow");}
15+
/* 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");}
1819

1920

2021
/*
2122
** If a call returns too many multiple returns, the callee may not have
2223
** stack space to accommodate all results. In this case, this macro
23-
** increases its stack space ('L->ci->top').
24+
** increases its stack space ('L->ci->top.p').
2425
*/
2526
#define adjustresults(L,nres) \
26-
{ if ((nres) <= LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; }
27+
{ if ((nres) <= LUA_MULTRET && L->ci->top.p < L->top.p) \
28+
L->ci->top.p = L->top.p; }
2729

2830

2931
/* Ensure the stack has at least 'n' elements */
30-
#define api_checknelems(L,n) api_check(L, (n) < (L->top - L->ci->func), \
31-
"not enough elements in the stack")
32+
#define api_checknelems(L,n) \
33+
api_check(L, (n) < (L->top.p - L->ci->func.p), \
34+
"not enough elements in the stack")
3235

3336

3437
/*

include/ldebug.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616

1717
/* Active Lua function (given call info) */
18-
#define ci_func(ci) (clLvalue(s2v((ci)->func)))
18+
#define ci_func(ci) (clLvalue(s2v((ci)->func.p)))
1919

2020

2121
#define resethookcount(L) (L->hookcount = L->basehookcount)

include/ldo.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#define ldo_h
99

1010

11+
#include "llimits.h"
1112
#include "lobject.h"
1213
#include "lstate.h"
1314
#include "lzio.h"
@@ -23,7 +24,7 @@
2324
** at every check.
2425
*/
2526
#define luaD_checkstackaux(L,n,pre,pos) \
26-
if (l_unlikely(L->stack_last - L->top <= (n))) \
27+
if (l_unlikely(L->stack_last.p - L->top.p <= (n))) \
2728
{ pre; luaD_growstack(L, n, 1); pos; } \
2829
else { condmovestack(L,pre,pos); }
2930

@@ -32,11 +33,18 @@
3233

3334

3435

35-
#define savestack(L,p) ((char *)(p) - (char *)L->stack)
36-
#define restorestack(L,n) ((StkId)((char *)L->stack + (n)))
36+
#define savestack(L,pt) (cast_charp(pt) - cast_charp(L->stack.p))
37+
#define restorestack(L,n) cast(StkId, cast_charp(L->stack.p) + (n))
3738

3839

3940
/* macro to check stack size, preserving 'p' */
41+
#define checkstackp(L,n,p) \
42+
luaD_checkstackaux(L, n, \
43+
ptrdiff_t t__ = savestack(L, p), /* save 'p' */ \
44+
p = restorestack(L, t__)) /* 'pos' part: restore 'p' */
45+
46+
47+
/* macro to check stack size and GC, preserving 'p' */
4048
#define checkstackGCp(L,n,p) \
4149
luaD_checkstackaux(L, n, \
4250
ptrdiff_t t__ = savestack(L, p); /* save 'p' */ \
@@ -58,7 +66,8 @@ LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name,
5866
LUAI_FUNC void luaD_hook (lua_State *L, int event, int line,
5967
int fTransfer, int nTransfer);
6068
LUAI_FUNC void luaD_hookcall (lua_State *L, CallInfo *ci);
61-
LUAI_FUNC int luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func, int narg1, int delta);
69+
LUAI_FUNC int luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func,
70+
int narg1, int delta);
6271
LUAI_FUNC CallInfo *luaD_precall (lua_State *L, StkId func, int nResults);
6372
LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults);
6473
LUAI_FUNC void luaD_callnoyield (lua_State *L, StkId func, int nResults);

include/lfunc.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929
#define MAXUPVAL 255
3030

3131

32-
#define upisopen(up) ((up)->v != &(up)->u.value)
32+
#define upisopen(up) ((up)->v.p != &(up)->u.value)
3333

3434

35-
#define uplevel(up) check_exp(upisopen(up), cast(StkId, (up)->v))
35+
#define uplevel(up) check_exp(upisopen(up), cast(StkId, (up)->v.p))
3636

3737

3838
/*
@@ -54,7 +54,7 @@ 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 void luaF_close (lua_State *L, StkId level, int status, int yy);
57+
LUAI_FUNC StkId luaF_close (lua_State *L, StkId level, int status, int yy);
5858
LUAI_FUNC void luaF_unlinkupval (UpVal *uv);
5959
LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f);
6060
LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number,

include/lgc.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -172,24 +172,27 @@
172172
#define luaC_checkGC(L) luaC_condGC(L,(void)0,(void)0)
173173

174174

175-
#define luaC_barrier(L,p,v) ( \
176-
(iscollectable(v) && isblack(p) && iswhite(gcvalue(v))) ? \
177-
luaC_barrier_(L,obj2gco(p),gcvalue(v)) : cast_void(0))
178-
179-
#define luaC_barrierback(L,p,v) ( \
180-
(iscollectable(v) && isblack(p) && iswhite(gcvalue(v))) ? \
181-
luaC_barrierback_(L,p) : cast_void(0))
182-
183175
#define luaC_objbarrier(L,p,o) ( \
184176
(isblack(p) && iswhite(o)) ? \
185177
luaC_barrier_(L,obj2gco(p),obj2gco(o)) : cast_void(0))
186178

179+
#define luaC_barrier(L,p,v) ( \
180+
iscollectable(v) ? luaC_objbarrier(L,p,gcvalue(v)) : cast_void(0))
181+
182+
#define luaC_objbarrierback(L,p,o) ( \
183+
(isblack(p) && iswhite(o)) ? luaC_barrierback_(L,p) : cast_void(0))
184+
185+
#define luaC_barrierback(L,p,v) ( \
186+
iscollectable(v) ? luaC_objbarrierback(L, p, gcvalue(v)) : cast_void(0))
187+
187188
LUAI_FUNC void luaC_fix (lua_State *L, GCObject *o);
188189
LUAI_FUNC void luaC_freeallobjects (lua_State *L);
189190
LUAI_FUNC void luaC_step (lua_State *L);
190191
LUAI_FUNC void luaC_runtilstate (lua_State *L, int statesmask);
191192
LUAI_FUNC void luaC_fullgc (lua_State *L, int isemergency);
192193
LUAI_FUNC GCObject *luaC_newobj (lua_State *L, int tt, size_t sz);
194+
LUAI_FUNC GCObject *luaC_newobjdt (lua_State *L, int tt, size_t sz,
195+
size_t offset);
193196
LUAI_FUNC void luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v);
194197
LUAI_FUNC void luaC_barrierback_ (lua_State *L, GCObject *o);
195198
LUAI_FUNC void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt);

include/llimits.h

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,24 @@ typedef signed char ls_byte;
7171

7272

7373
/*
74-
** conversion of pointer to unsigned integer:
75-
** this is for hashing only; there is no problem if the integer
76-
** cannot hold the whole pointer value
74+
** conversion of pointer to unsigned integer: this is for hashing only;
75+
** there is no problem if the integer cannot hold the whole pointer
76+
** value. (In strict ISO C this may cause undefined behavior, but no
77+
** actual machine seems to bother.)
7778
*/
78-
#define point2uint(p) ((unsigned int)((size_t)(p) & UINT_MAX))
79+
#if !defined(LUA_USE_C89) && defined(__STDC_VERSION__) && \
80+
__STDC_VERSION__ >= 199901L
81+
#include <stdint.h>
82+
#if defined(UINTPTR_MAX) /* even in C99 this type is optional */
83+
#define L_P2I uintptr_t
84+
#else /* no 'intptr'? */
85+
#define L_P2I uintmax_t /* use the largerst available integer */
86+
#endif
87+
#else /* C89 option */
88+
#define L_P2I size_t
89+
#endif
90+
91+
#define point2uint(p) ((unsigned int)((L_P2I)(p) & UINT_MAX))
7992

8093

8194

include/lobject.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ typedef union Value {
5252
lua_CFunction f; /* light C functions */
5353
lua_Integer i; /* integer numbers */
5454
lua_Number n; /* float numbers */
55+
/* not used, but may avoid warnings for uninitialized value */
56+
lu_byte ub;
5557
} Value;
5658

5759

@@ -155,6 +157,17 @@ typedef union StackValue {
155157
/* index to stack elements */
156158
typedef StackValue *StkId;
157159

160+
161+
/*
162+
** When reallocating the stack, change all pointers to the stack into
163+
** proper offsets.
164+
*/
165+
typedef union {
166+
StkId p; /* actual pointer */
167+
ptrdiff_t offset; /* used while the stack is being reallocated */
168+
} StkIdRel;
169+
170+
158171
/* convert a 'StackValue' to a 'TValue' */
159172
#define s2v(o) (&(o)->val)
160173

@@ -615,8 +628,10 @@ typedef struct Proto {
615628
*/
616629
typedef struct UpVal {
617630
CommonHeader;
618-
lu_byte tbc; /* true if it represents a to-be-closed variable */
619-
TValue *v; /* points to stack or to its own value */
631+
union {
632+
TValue *p; /* points to stack or to its own value */
633+
ptrdiff_t offset; /* used while the stack is being reallocated */
634+
} v;
620635
union {
621636
struct { /* (when open) */
622637
struct UpVal *next; /* linked list */

include/lstate.h

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99

1010
#include "lua.h"
1111

12+
13+
/* Some header files included here need this definition */
14+
typedef struct CallInfo CallInfo;
15+
16+
1217
#include "lobject.h"
1318
#include "ltm.h"
1419
#include "lzio.h"
@@ -139,7 +144,7 @@ struct lua_longjmp; /* defined in ldo.c */
139144

140145
#define BASIC_STACK_SIZE (2*LUA_MINSTACK)
141146

142-
#define stacksize(th) cast_int((th)->stack_last - (th)->stack)
147+
#define stacksize(th) cast_int((th)->stack_last.p - (th)->stack.p)
143148

144149

145150
/* kinds of Garbage Collection */
@@ -169,9 +174,9 @@ typedef struct stringtable {
169174
** - field 'transferinfo' is used only during call/returnhooks,
170175
** before the function starts or after it ends.
171176
*/
172-
typedef struct CallInfo {
173-
StkId func; /* function index in the stack */
174-
StkId top; /* top for this function */
177+
struct CallInfo {
178+
StkIdRel func; /* function index in the stack */
179+
StkIdRel top; /* top for this function */
175180
struct CallInfo *previous, *next; /* dynamic call link */
176181
union {
177182
struct { /* only for Lua functions */
@@ -196,7 +201,7 @@ typedef struct CallInfo {
196201
} u2;
197202
short nresults; /* expected number of results from this function */
198203
unsigned short callstatus;
199-
} CallInfo;
204+
};
200205

201206

202207
/*
@@ -291,7 +296,7 @@ typedef struct global_State {
291296
struct lua_State *mainthread;
292297
TString *memerrmsg; /* message for memory-allocation errors */
293298
TString *tmname[TM_N]; /* array with tag-method names */
294-
struct Table *mt[LUA_NUMTAGS]; /* metatables for basic types */
299+
struct Table *mt[LUA_NUMTYPES]; /* metatables for basic types */
295300
TString *strcache[STRCACHE_N][STRCACHE_M]; /* cache for strings in API */
296301
lua_WarnFunction warnf; /* warning function */
297302
void *ud_warn; /* auxiliary data to 'warnf' */
@@ -306,13 +311,13 @@ struct lua_State {
306311
lu_byte status;
307312
lu_byte allowhook;
308313
unsigned short nci; /* number of items in 'ci' list */
309-
StkId top; /* first free slot in the stack */
314+
StkIdRel top; /* first free slot in the stack */
310315
global_State *l_G;
311316
CallInfo *ci; /* call info for current function */
312-
StkId stack_last; /* end of stack (last element + 1) */
313-
StkId stack; /* stack base */
317+
StkIdRel stack_last; /* end of stack (last element + 1) */
318+
StkIdRel stack; /* stack base */
314319
UpVal *openupval; /* list of open upvalues in this stack */
315-
StkId tbclist; /* list of to-be-closed variables */
320+
StkIdRel tbclist; /* list of to-be-closed variables */
316321
GCObject *gclist;
317322
struct lua_State *twups; /* list of threads with open upvalues */
318323
struct lua_longjmp *errorJmp; /* current error recover point */

include/ltable.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ LUAI_FUNC unsigned int luaH_realasize (const Table *t);
5959

6060
#if defined(LUA_DEBUG)
6161
LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key);
62-
LUAI_FUNC int luaH_isdummy (const Table *t);
6362
#endif
6463

6564

include/ltests.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,13 @@ LUA_API void *debug_realloc (void *ud, void *block,
125125
#define LUAI_USER_ALIGNMENT_T union { char b[sizeof(void*) * 8]; }
126126

127127

128+
/*
129+
** This one is not compatible with tests for opcode optimizations,
130+
** as it blocks some optimizations
131+
#define MAXINDEXRK 0
132+
*/
133+
134+
128135
/* make stack-overflow tests run faster */
129136
#undef LUAI_MAXSTACK
130137
#define LUAI_MAXSTACK 50000

0 commit comments

Comments
 (0)