Skip to content

Commit 38c4d7b

Browse files
committed
Update Lua 5.4 to 5.4.0-rc4 and bump version to 535.0.4+540rc4
1 parent b690e4a commit 38c4d7b

14 files changed

+84
-67
lines changed

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
[package]
22
name = "lua-src"
3-
version = "535.0.3+540rc3"
3+
version = "535.0.4+540rc4"
44
authors = ["Aleksandr Orlenko <zxteam@protonmail.com>"]
55
edition = "2018"
66
repository = "https://github.com/khvzak/lua-src-rs"
77
keywords = ["lua", "lua51", "lua52", "lua53", "lua54"]
88
readme = "README.md"
99
license = "MIT"
1010
description = """
11-
Sources of Lua 5.1/5.2/5.3/5.4(rc3) and logic to build them.
11+
Sources of Lua 5.1/5.2/5.3/5.4(rc4) and logic to build them.
1212
"""
1313

1414
[workspace]

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[Build Status]: https://github.com/khvzak/lua-src-rs/workflows/CI/badge.svg
55
[github-actions]: https://github.com/khvzak/lua-src-rs/actions
66

7-
This crate contains the sources of Lua 5.1/5.2/5.3/5.4(rc3) and logic to build them.
7+
This crate contains the sources of Lua 5.1/5.2/5.3/5.4(rc4) and logic to build them.
88
Intended to be consumed by the [mlua](https://crates.io/crates/mlua) crate.
99

1010
# License

lua-5.4.0/lauxlib.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ LUALIB_API int luaL_fileresult (lua_State *L, int stat, const char *fname) {
284284

285285
LUALIB_API int luaL_execresult (lua_State *L, int stat) {
286286
const char *what = "exit"; /* type of termination */
287-
if (stat == -1) /* error? */
287+
if (stat != 0 && errno != 0) /* error with an 'errno'? */
288288
return luaL_fileresult(L, 0, NULL);
289289
else {
290290
l_inspectstat(stat, what); /* interpret result */
@@ -476,7 +476,7 @@ static void *resizebox (lua_State *L, int idx, size_t newsize) {
476476
UBox *box = (UBox *)lua_touserdata(L, idx);
477477
void *temp = allocf(ud, box->box, box->bsize, newsize);
478478
if (temp == NULL && newsize > 0) /* allocation error? */
479-
luaL_error(L, "not enough memory for buffer allocation");
479+
luaL_error(L, "not enough memory");
480480
box->box = temp;
481481
box->bsize = newsize;
482482
return temp;

lua-5.4.0/ldebug.c

+11-9
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,15 @@ static int getcurrentline (CallInfo *ci) {
107107

108108

109109
/*
110-
** This function can be called asynchronously (e.g. during a signal),
111-
** under "reasonable" assumptions. A new 'ci' is completely linked
112-
** in the list before it becomes part of the "active" list, and
113-
** we assume that pointers are atomic (see comment in next function).
114-
** (If we traverse one more item, there is no problem. If we traverse
115-
** one less item, the worst that can happen is that the signal will
116-
** not interrupt the script.)
110+
** Set 'trap' for all active Lua frames.
111+
** This function can be called during a signal, under "reasonable"
112+
** assumptions. A new 'ci' is completely linked in the list before it
113+
** becomes part of the "active" list, and we assume that pointers are
114+
** atomic; see comment in next function.
115+
** (A compiler doing interprocedural optimizations could, theoretically,
116+
** reorder memory writes in such a way that the list could be
117+
** temporarily broken while inserting a new element. We simply assume it
118+
** has no good reasons to do that.)
117119
*/
118120
static void settraps (CallInfo *ci) {
119121
for (; ci != NULL; ci = ci->previous)
@@ -123,8 +125,8 @@ static void settraps (CallInfo *ci) {
123125

124126

125127
/*
126-
** This function can be called asynchronously (e.g. during a signal),
127-
** under "reasonable" assumptions.
128+
** This function can be called during a signal, under "reasonable"
129+
** assumptions.
128130
** Fields 'oldpc', 'basehookcount', and 'hookcount' (set by
129131
** 'resethookcount') are for debug only, and it is no problem if they
130132
** get arbitrary values (causes at most one wrong hook call). 'hookmask'

lua-5.4.0/ldo.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ void luaD_poscall (lua_State *L, CallInfo *ci, int nres) {
422422

423423

424424

425-
#define next_ci(L) (L->ci = (L->ci->next ? L->ci->next : luaE_extendCI(L)))
425+
#define next_ci(L) (L->ci->next ? L->ci->next : luaE_extendCI(L))
426426

427427

428428
/*
@@ -466,13 +466,13 @@ void luaD_call (lua_State *L, StkId func, int nresults) {
466466
f = fvalue(s2v(func));
467467
Cfunc: {
468468
int n; /* number of returns */
469-
CallInfo *ci;
469+
CallInfo *ci = next_ci(L);
470470
checkstackp(L, LUA_MINSTACK, func); /* ensure minimum stack size */
471-
ci = next_ci(L);
472471
ci->nresults = nresults;
473472
ci->callstatus = CIST_C;
474473
ci->top = L->top + LUA_MINSTACK;
475474
ci->func = func;
475+
L->ci = ci;
476476
lua_assert(ci->top <= L->stack_last);
477477
if (L->hookmask & LUA_MASKCALL) {
478478
int narg = cast_int(L->top - func) - 1;
@@ -486,18 +486,18 @@ void luaD_call (lua_State *L, StkId func, int nresults) {
486486
break;
487487
}
488488
case LUA_VLCL: { /* Lua function */
489-
CallInfo *ci;
489+
CallInfo *ci = next_ci(L);
490490
Proto *p = clLvalue(s2v(func))->p;
491491
int narg = cast_int(L->top - func) - 1; /* number of real arguments */
492492
int nfixparams = p->numparams;
493493
int fsize = p->maxstacksize; /* frame size */
494494
checkstackp(L, fsize, func);
495-
ci = next_ci(L);
496495
ci->nresults = nresults;
497496
ci->u.l.savedpc = p->code; /* starting point */
498497
ci->callstatus = 0;
499498
ci->top = func + 1 + fsize;
500499
ci->func = func;
500+
L->ci = ci;
501501
for (; narg < nfixparams; narg++)
502502
setnilvalue(s2v(L->top++)); /* complete missing arguments */
503503
lua_assert(ci->top <= L->stack_last);

lua-5.4.0/liolib.c

+1
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ static int io_open (lua_State *L) {
270270
*/
271271
static int io_pclose (lua_State *L) {
272272
LStream *p = tolstream(L);
273+
errno = 0;
273274
return luaL_execresult(L, l_pclose(L, p->f));
274275
}
275276

lua-5.4.0/lobject.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ typedef struct GCObject {
356356

357357

358358
/*
359-
** Header for string value; string bytes follow the end of this structure.
359+
** Header for a string value.
360360
*/
361361
typedef struct TString {
362362
CommonHeader;
@@ -367,16 +367,15 @@ typedef struct TString {
367367
size_t lnglen; /* length for long strings */
368368
struct TString *hnext; /* linked list for hash table */
369369
} u;
370+
char contents[1];
370371
} TString;
371372

372373

373374

374375
/*
375376
** Get the actual string (array of bytes) from a 'TString'.
376-
** (Access to 'extra' ensures that value is really a 'TString'.)
377377
*/
378-
#define getstr(ts) \
379-
check_exp(sizeof((ts)->extra), cast_charp((ts)) + sizeof(TString))
378+
#define getstr(ts) ((ts)->contents)
380379

381380

382381
/* get the actual string (array of bytes) from a Lua value */

lua-5.4.0/loslib.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "lprefix.h"
1111

1212

13+
#include <errno.h>
1314
#include <locale.h>
1415
#include <stdlib.h>
1516
#include <string.h>
@@ -138,10 +139,11 @@
138139

139140

140141

141-
142142
static int os_execute (lua_State *L) {
143143
const char *cmd = luaL_optstring(L, 1, NULL);
144-
int stat = system(cmd);
144+
int stat;
145+
errno = 0;
146+
stat = system(cmd);
145147
if (cmd != NULL)
146148
return luaL_execresult(L, stat);
147149
else {

lua-5.4.0/lparser.c

+36-28
Original file line numberDiff line numberDiff line change
@@ -212,27 +212,28 @@ static int new_localvar (LexState *ls, TString *name) {
212212

213213

214214
/*
215-
** Return the "variable description" (Vardesc) of a given
216-
** variable
215+
** Return the "variable description" (Vardesc) of a given variable.
216+
** (Unless noted otherwise, all variables are referred to by their
217+
** compiler indices.)
217218
*/
218-
static Vardesc *getlocalvardesc (FuncState *fs, int i) {
219-
return &fs->ls->dyd->actvar.arr[fs->firstlocal + i];
219+
static Vardesc *getlocalvardesc (FuncState *fs, int vidx) {
220+
return &fs->ls->dyd->actvar.arr[fs->firstlocal + vidx];
220221
}
221222

222223

223224
/*
224-
** Convert 'nvar' (number of active variables at some point) to
225-
** number of variables in the stack at that point.
225+
** Convert 'nvar', a compiler index level, to it corresponding
226+
** stack index level. For that, search for the highest variable
227+
** below that level that is in the stack and uses its stack
228+
** index ('sidx').
226229
*/
227230
static int stacklevel (FuncState *fs, int nvar) {
228-
while (nvar > 0) {
229-
Vardesc *vd = getlocalvardesc(fs, nvar - 1);
231+
while (nvar-- > 0) {
232+
Vardesc *vd = getlocalvardesc(fs, nvar); /* get variable */
230233
if (vd->vd.kind != RDKCTC) /* is in the stack? */
231234
return vd->vd.sidx + 1;
232-
else
233-
nvar--; /* try previous variable */
234235
}
235-
return 0; /* no variables */
236+
return 0; /* no variables in the stack */
236237
}
237238

238239

@@ -245,10 +246,10 @@ int luaY_nvarstack (FuncState *fs) {
245246

246247

247248
/*
248-
** Get the debug-information entry for current variable 'i'.
249+
** Get the debug-information entry for current variable 'vidx'.
249250
*/
250-
static LocVar *localdebuginfo (FuncState *fs, int i) {
251-
Vardesc *vd = getlocalvardesc(fs, i);
251+
static LocVar *localdebuginfo (FuncState *fs, int vidx) {
252+
Vardesc *vd = getlocalvardesc(fs, vidx);
252253
if (vd->vd.kind == RDKCTC)
253254
return NULL; /* no debug info. for constants */
254255
else {
@@ -259,14 +260,20 @@ static LocVar *localdebuginfo (FuncState *fs, int i) {
259260
}
260261

261262

262-
static void init_var (FuncState *fs, expdesc *e, int i) {
263+
/*
264+
** Create an expression representing variable 'vidx'
265+
*/
266+
static void init_var (FuncState *fs, expdesc *e, int vidx) {
263267
e->f = e->t = NO_JUMP;
264268
e->k = VLOCAL;
265-
e->u.var.vidx = i;
266-
e->u.var.sidx = getlocalvardesc(fs, i)->vd.sidx;
269+
e->u.var.vidx = vidx;
270+
e->u.var.sidx = getlocalvardesc(fs, vidx)->vd.sidx;
267271
}
268272

269273

274+
/*
275+
** Raises an error if variable described by 'e' is read only
276+
*/
270277
static void check_readonly (LexState *ls, expdesc *e) {
271278
FuncState *fs = ls->fs;
272279
TString *varname = NULL; /* to be set if variable is const */
@@ -306,8 +313,8 @@ static void adjustlocalvars (LexState *ls, int nvars) {
306313
int stklevel = luaY_nvarstack(fs);
307314
int i;
308315
for (i = 0; i < nvars; i++) {
309-
int varidx = fs->nactvar++;
310-
Vardesc *var = getlocalvardesc(fs, varidx);
316+
int vidx = fs->nactvar++;
317+
Vardesc *var = getlocalvardesc(fs, vidx);
311318
var->vd.sidx = stklevel++;
312319
var->vd.pidx = registerlocalvar(ls, fs, var->vd.name);
313320
}
@@ -377,7 +384,8 @@ static int newupvalue (FuncState *fs, TString *name, expdesc *v) {
377384

378385
/*
379386
** Look for an active local variable with the name 'n' in the
380-
** function 'fs'.
387+
** function 'fs'. If found, initialize 'var' with it and return
388+
** its expression kind; otherwise return -1.
381389
*/
382390
static int searchvar (FuncState *fs, TString *n, expdesc *var) {
383391
int i;
@@ -1592,7 +1600,7 @@ static void forlist (LexState *ls, TString *indexname) {
15921600
line = ls->linenumber;
15931601
adjust_assign(ls, 4, explist(ls, &e), &e);
15941602
adjustlocalvars(ls, 4); /* control variables */
1595-
markupval(fs, luaY_nvarstack(fs)); /* state may create an upvalue */
1603+
markupval(fs, fs->nactvar); /* last control var. must be closed */
15961604
luaK_checkstack(fs, 3); /* extra space to call generator */
15971605
forbody(ls, base, line, nvars - 4, 1);
15981606
}
@@ -1730,7 +1738,7 @@ static int getlocalattribute (LexState *ls) {
17301738
luaK_semerror(ls,
17311739
luaO_pushfstring(ls->L, "unknown attribute '%s'", attr));
17321740
}
1733-
return VDKREG;
1741+
return VDKREG; /* regular variable */
17341742
}
17351743

17361744

@@ -1739,7 +1747,7 @@ static void checktoclose (LexState *ls, int level) {
17391747
FuncState *fs = ls->fs;
17401748
markupval(fs, level + 1);
17411749
fs->bl->insidetbc = 1; /* in the scope of a to-be-closed variable */
1742-
luaK_codeABC(fs, OP_TBC, level, 0, 0);
1750+
luaK_codeABC(fs, OP_TBC, stacklevel(fs, level), 0, 0);
17431751
}
17441752
}
17451753

@@ -1749,18 +1757,18 @@ static void localstat (LexState *ls) {
17491757
FuncState *fs = ls->fs;
17501758
int toclose = -1; /* index of to-be-closed variable (if any) */
17511759
Vardesc *var; /* last variable */
1752-
int ivar, kind; /* index and kind of last variable */
1760+
int vidx, kind; /* index and kind of last variable */
17531761
int nvars = 0;
17541762
int nexps;
17551763
expdesc e;
17561764
do {
1757-
ivar = new_localvar(ls, str_checkname(ls));
1765+
vidx = new_localvar(ls, str_checkname(ls));
17581766
kind = getlocalattribute(ls);
1759-
getlocalvardesc(fs, ivar)->vd.kind = kind;
1767+
getlocalvardesc(fs, vidx)->vd.kind = kind;
17601768
if (kind == RDKTOCLOSE) { /* to-be-closed? */
17611769
if (toclose != -1) /* one already present? */
17621770
luaK_semerror(ls, "multiple to-be-closed variables in local list");
1763-
toclose = luaY_nvarstack(fs) + nvars;
1771+
toclose = fs->nactvar + nvars;
17641772
}
17651773
nvars++;
17661774
} while (testnext(ls, ','));
@@ -1770,7 +1778,7 @@ static void localstat (LexState *ls) {
17701778
e.k = VVOID;
17711779
nexps = 0;
17721780
}
1773-
var = getlocalvardesc(fs, ivar); /* get last variable */
1781+
var = getlocalvardesc(fs, vidx); /* get last variable */
17741782
if (nvars == nexps && /* no adjustments? */
17751783
var->vd.kind == RDKCONST && /* last variable is const? */
17761784
luaK_exp2const(fs, &e, &var->k)) { /* compile-time constant? */

lua-5.4.0/lparser.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ typedef struct expdesc {
7777
} ind;
7878
struct { /* for local variables */
7979
lu_byte sidx; /* index in the stack */
80-
unsigned short vidx; /* index in 'actvar.arr' */
80+
unsigned short vidx; /* compiler index (in 'actvar.arr') */
8181
} var;
8282
} u;
8383
int t; /* patch list of 'exit when true' */
@@ -125,7 +125,7 @@ typedef struct Labellist {
125125

126126
/* dynamic structures used by the parser */
127127
typedef struct Dyndata {
128-
struct { /* list of active local variables */
128+
struct { /* list of all active local variables */
129129
Vardesc *arr;
130130
int n;
131131
int size;

lua-5.4.0/lstate.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -190,14 +190,15 @@ void luaE_freeCI (lua_State *L) {
190190
*/
191191
void luaE_shrinkCI (lua_State *L) {
192192
CallInfo *ci = L->ci;
193+
CallInfo *next;
193194
CallInfo *next2; /* next's next */
194195
L->nCcalls += L->nci; /* add removed elements back to 'nCcalls' */
195196
/* while there are two nexts */
196-
while (ci->next != NULL && (next2 = ci->next->next) != NULL) {
197-
luaM_free(L, ci->next); /* free next */
198-
L->nci--;
199-
ci->next = next2; /* remove 'next' from the list */
197+
while ((next = ci->next) != NULL && (next2 = next->next) != NULL) {
198+
ci->next = next2; /* remove next from the list */
200199
next2->previous = ci;
200+
luaM_free(L, next); /* free next */
201+
L->nci--;
201202
ci = next2; /* keep next's next */
202203
}
203204
L->nCcalls -= L->nci; /* adjust result */

lua-5.4.0/lstate.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ typedef struct CallInfo {
173173
union {
174174
struct { /* only for Lua functions */
175175
const Instruction *savedpc;
176-
l_signalT trap;
176+
volatile l_signalT trap;
177177
int nextraargs; /* # of extra arguments in vararg functions */
178178
} l;
179179
struct { /* only for C functions */
@@ -300,7 +300,7 @@ struct lua_State {
300300
int stacksize;
301301
int basehookcount;
302302
int hookcount;
303-
l_signalT hookmask;
303+
volatile l_signalT hookmask;
304304
};
305305

306306

0 commit comments

Comments
 (0)