Skip to content

Commit f3df462

Browse files
committed
Update Lua 5.3 to 5.3.6 and bump version to 540.0.1
1 parent 9ae371d commit f3df462

Some content is hidden

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

60 files changed

+62
-41
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "lua-src"
3-
version = "540.0.0"
3+
version = "540.0.1"
44
authors = ["Aleksandr Orlenko <zxteam@protonmail.com>"]
55
edition = "2018"
66
repository = "https://github.com/khvzak/lua-src-rs"

lua-5.3.5/lapi.c renamed to lua-5.3.6/lapi.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -1254,13 +1254,12 @@ LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) {
12541254
}
12551255

12561256

1257-
static UpVal **getupvalref (lua_State *L, int fidx, int n, LClosure **pf) {
1257+
static UpVal **getupvalref (lua_State *L, int fidx, int n) {
12581258
LClosure *f;
12591259
StkId fi = index2addr(L, fidx);
12601260
api_check(L, ttisLclosure(fi), "Lua function expected");
12611261
f = clLvalue(fi);
12621262
api_check(L, (1 <= n && n <= f->p->sizeupvalues), "invalid upvalue index");
1263-
if (pf) *pf = f;
12641263
return &f->upvals[n - 1]; /* get its upvalue pointer */
12651264
}
12661265

@@ -1269,7 +1268,7 @@ LUA_API void *lua_upvalueid (lua_State *L, int fidx, int n) {
12691268
StkId fi = index2addr(L, fidx);
12701269
switch (ttype(fi)) {
12711270
case LUA_TLCL: { /* lua closure */
1272-
return *getupvalref(L, fidx, n, NULL);
1271+
return *getupvalref(L, fidx, n);
12731272
}
12741273
case LUA_TCCL: { /* C closure */
12751274
CClosure *f = clCvalue(fi);
@@ -1286,9 +1285,10 @@ LUA_API void *lua_upvalueid (lua_State *L, int fidx, int n) {
12861285

12871286
LUA_API void lua_upvaluejoin (lua_State *L, int fidx1, int n1,
12881287
int fidx2, int n2) {
1289-
LClosure *f1;
1290-
UpVal **up1 = getupvalref(L, fidx1, n1, &f1);
1291-
UpVal **up2 = getupvalref(L, fidx2, n2, NULL);
1288+
UpVal **up1 = getupvalref(L, fidx1, n1);
1289+
UpVal **up2 = getupvalref(L, fidx2, n2);
1290+
if (*up1 == *up2)
1291+
return;
12921292
luaC_upvdeccount(L, *up1);
12931293
*up1 = *up2;
12941294
(*up1)->refcount++;
File renamed without changes.

lua-5.3.5/lauxlib.c renamed to lua-5.3.6/lauxlib.c

+7-2
Original file line numberDiff line numberDiff line change
@@ -1011,8 +1011,13 @@ static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
10111011
free(ptr);
10121012
return NULL;
10131013
}
1014-
else
1015-
return realloc(ptr, nsize);
1014+
else { /* cannot fail when shrinking a block */
1015+
void *newptr = realloc(ptr, nsize);
1016+
if (newptr == NULL && ptr != NULL && nsize <= osize)
1017+
return ptr; /* keep the original block */
1018+
else /* no fail or not shrinking */
1019+
return newptr; /* use the new block */
1020+
}
10161021
}
10171022

10181023

File renamed without changes.
File renamed without changes.
File renamed without changes.

lua-5.3.5/lcode.c renamed to lua-5.3.6/lcode.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,7 @@ static void codecomp (FuncState *fs, BinOpr opr, expdesc *e1, expdesc *e2) {
10611061

10621062

10631063
/*
1064-
** Aplly prefix operation 'op' to expression 'e'.
1064+
** Apply prefix operation 'op' to expression 'e'.
10651065
*/
10661066
void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e, int line) {
10671067
static const expdesc ef = {VKINT, {0}, NO_JUMP, NO_JUMP};
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

lua-5.3.5/ldebug.c renamed to lua-5.3.6/ldebug.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,11 @@ static const char *upvalname (Proto *p, int uv) {
133133

134134
static const char *findvararg (CallInfo *ci, int n, StkId *pos) {
135135
int nparams = clLvalue(ci->func)->p->numparams;
136-
if (n >= cast_int(ci->u.l.base - ci->func) - nparams)
136+
int nvararg = cast_int(ci->u.l.base - ci->func) - nparams;
137+
if (n <= -nvararg)
137138
return NULL; /* no such vararg */
138139
else {
139-
*pos = ci->func + nparams + n;
140+
*pos = ci->func + nparams - n;
140141
return "(*vararg)"; /* generic name for any vararg */
141142
}
142143
}
@@ -148,7 +149,7 @@ static const char *findlocal (lua_State *L, CallInfo *ci, int n,
148149
StkId base;
149150
if (isLua(ci)) {
150151
if (n < 0) /* access to vararg values? */
151-
return findvararg(ci, -n, pos);
152+
return findvararg(ci, n, pos);
152153
else {
153154
base = ci->u.l.base;
154155
name = luaF_getlocalname(ci_func(ci)->p, n, currentpc(ci));
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

lua-5.3.5/liolib.c renamed to lua-5.3.6/liolib.c

+2
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,8 @@ static int io_popen (lua_State *L) {
277277
const char *filename = luaL_checkstring(L, 1);
278278
const char *mode = luaL_optstring(L, 2, "r");
279279
LStream *p = newprefile(L);
280+
luaL_argcheck(L, ((mode[0] == 'r' || mode[0] == 'w') && mode[1] == '\0'),
281+
2, "invalid mode");
280282
p->f = l_popen(L, filename, mode);
281283
p->closef = &io_pclose;
282284
return (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1;

lua-5.3.5/llex.c renamed to lua-5.3.6/llex.c

+17-14
Original file line numberDiff line numberDiff line change
@@ -244,24 +244,27 @@ static int read_numeral (LexState *ls, SemInfo *seminfo) {
244244

245245

246246
/*
247-
** skip a sequence '[=*[' or ']=*]'; if sequence is well formed, return
248-
** its number of '='s; otherwise, return a negative number (-1 iff there
249-
** are no '='s after initial bracket)
247+
** reads a sequence '[=*[' or ']=*]', leaving the last bracket.
248+
** If sequence is well formed, return its number of '='s + 2; otherwise,
249+
** return 1 if there is no '='s or 0 otherwise (an unfinished '[==...').
250250
*/
251-
static int skip_sep (LexState *ls) {
252-
int count = 0;
251+
static size_t skip_sep (LexState *ls) {
252+
size_t count = 0;
253253
int s = ls->current;
254254
lua_assert(s == '[' || s == ']');
255255
save_and_next(ls);
256256
while (ls->current == '=') {
257257
save_and_next(ls);
258258
count++;
259259
}
260-
return (ls->current == s) ? count : (-count) - 1;
260+
return (ls->current == s) ? count + 2
261+
: (count == 0) ? 1
262+
: 0;
263+
261264
}
262265

263266

264-
static void read_long_string (LexState *ls, SemInfo *seminfo, int sep) {
267+
static void read_long_string (LexState *ls, SemInfo *seminfo, size_t sep) {
265268
int line = ls->linenumber; /* initial line (for error message) */
266269
save_and_next(ls); /* skip 2nd '[' */
267270
if (currIsNewline(ls)) /* string starts with a newline? */
@@ -295,8 +298,8 @@ static void read_long_string (LexState *ls, SemInfo *seminfo, int sep) {
295298
}
296299
} endloop:
297300
if (seminfo)
298-
seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + (2 + sep),
299-
luaZ_bufflen(ls->buff) - 2*(2 + sep));
301+
seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + sep,
302+
luaZ_bufflen(ls->buff) - 2 * sep);
300303
}
301304

302305

@@ -444,9 +447,9 @@ static int llex (LexState *ls, SemInfo *seminfo) {
444447
/* else is a comment */
445448
next(ls);
446449
if (ls->current == '[') { /* long comment? */
447-
int sep = skip_sep(ls);
450+
size_t sep = skip_sep(ls);
448451
luaZ_resetbuffer(ls->buff); /* 'skip_sep' may dirty the buffer */
449-
if (sep >= 0) {
452+
if (sep >= 2) {
450453
read_long_string(ls, NULL, sep); /* skip long comment */
451454
luaZ_resetbuffer(ls->buff); /* previous call may dirty the buff. */
452455
break;
@@ -458,12 +461,12 @@ static int llex (LexState *ls, SemInfo *seminfo) {
458461
break;
459462
}
460463
case '[': { /* long string or simply '[' */
461-
int sep = skip_sep(ls);
462-
if (sep >= 0) {
464+
size_t sep = skip_sep(ls);
465+
if (sep >= 2) {
463466
read_long_string(ls, seminfo, sep);
464467
return TK_STRING;
465468
}
466-
else if (sep != -1) /* '[=...' missing second bracket */
469+
else if (sep == 0) /* '[=...' missing second bracket */
467470
lexerror(ls, "invalid long string delimiter", TK_STRING);
468471
return '[';
469472
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

lua-5.3.5/lobject.c renamed to lua-5.3.6/lobject.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ static const char *l_str2dloc (const char *s, lua_Number *result, int mode) {
266266
** - 'n'/'N' means 'inf' or 'nan' (which should be rejected)
267267
** - '.' just optimizes the search for the common case (nothing special)
268268
** This function accepts both the current locale or a dot as the radix
269-
** mark. If the convertion fails, it may mean number has a dot but
269+
** mark. If the conversion fails, it may mean number has a dot but
270270
** locale accepts something else. In that case, the code copies 's'
271271
** to a buffer (because 's' is read-only), changes the dot to the
272272
** current locale radix mark, and tries to convert again.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

lua-5.3.5/lparser.c renamed to lua-5.3.6/lparser.c

+3
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,7 @@ static void open_func (LexState *ls, FuncState *fs, BlockCnt *bl) {
544544
fs->bl = NULL;
545545
f = fs->f;
546546
f->source = ls->source;
547+
luaC_objbarrier(ls->L, f, f->source);
547548
f->maxstacksize = 2; /* registers 0/1 are always valid */
548549
enterblock(fs, bl, 0);
549550
}
@@ -1616,6 +1617,7 @@ static void mainfunc (LexState *ls, FuncState *fs) {
16161617
fs->f->is_vararg = 1; /* main function is always declared vararg */
16171618
init_exp(&v, VLOCAL, 0); /* create and... */
16181619
newupvalue(fs, ls->envn, &v); /* ...set environment upvalue */
1620+
luaC_objbarrier(ls->L, fs->f, ls->envn);
16191621
luaX_next(ls); /* read first token */
16201622
statlist(ls); /* parse main body */
16211623
check(ls, TK_EOS);
@@ -1634,6 +1636,7 @@ LClosure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff,
16341636
sethvalue(L, L->top, lexstate.h); /* anchor it */
16351637
luaD_inctop(L);
16361638
funcstate.f = cl->p = luaF_newproto(L);
1639+
luaC_objbarrier(L, cl, cl->p);
16371640
funcstate.f->source = luaS_new(L, name); /* create and anchor TString */
16381641
lua_assert(iswhite(funcstate.f)); /* do not need barrier here */
16391642
lexstate.buff = buff;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

lua-5.3.5/lua.h renamed to lua-5.3.6/lua.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/*
2-
** $Id: lua.h,v 1.332.1.2 2018/06/13 16:58:17 roberto Exp $
32
** Lua - A Scripting Language
43
** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
54
** See Copyright Notice at the end of this file
@@ -19,11 +18,11 @@
1918
#define LUA_VERSION_MAJOR "5"
2019
#define LUA_VERSION_MINOR "3"
2120
#define LUA_VERSION_NUM 503
22-
#define LUA_VERSION_RELEASE "5"
21+
#define LUA_VERSION_RELEASE "6"
2322

2423
#define LUA_VERSION "Lua " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR
2524
#define LUA_RELEASE LUA_VERSION "." LUA_VERSION_RELEASE
26-
#define LUA_COPYRIGHT LUA_RELEASE " Copyright (C) 1994-2018 Lua.org, PUC-Rio"
25+
#define LUA_COPYRIGHT LUA_RELEASE " Copyright (C) 1994-2020 Lua.org, PUC-Rio"
2726
#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo, W. Celes"
2827

2928

@@ -460,7 +459,7 @@ struct lua_Debug {
460459

461460

462461
/******************************************************************************
463-
* Copyright (C) 1994-2018 Lua.org, PUC-Rio.
462+
* Copyright (C) 1994-2020 Lua.org, PUC-Rio.
464463
*
465464
* Permission is hereby granted, free of charge, to any person obtaining
466465
* a copy of this software and associated documentation files (the
File renamed without changes.
File renamed without changes.

lua-5.3.5/lundump.c renamed to lua-5.3.6/lundump.c

+16-8
Original file line numberDiff line numberDiff line change
@@ -85,22 +85,28 @@ static lua_Integer LoadInteger (LoadState *S) {
8585
}
8686

8787

88-
static TString *LoadString (LoadState *S) {
88+
static TString *LoadString (LoadState *S, Proto *p) {
89+
lua_State *L = S->L;
8990
size_t size = LoadByte(S);
91+
TString *ts;
9092
if (size == 0xFF)
9193
LoadVar(S, size);
9294
if (size == 0)
9395
return NULL;
9496
else if (--size <= LUAI_MAXSHORTLEN) { /* short string? */
9597
char buff[LUAI_MAXSHORTLEN];
9698
LoadVector(S, buff, size);
97-
return luaS_newlstr(S->L, buff, size);
99+
ts = luaS_newlstr(L, buff, size);
98100
}
99101
else { /* long string */
100-
TString *ts = luaS_createlngstrobj(S->L, size);
102+
ts = luaS_createlngstrobj(L, size);
103+
setsvalue2s(L, L->top, ts); /* anchor it ('loadVector' can GC) */
104+
luaD_inctop(L);
101105
LoadVector(S, getstr(ts), size); /* load directly in final place */
102-
return ts;
106+
L->top--; /* pop string */
103107
}
108+
luaC_objbarrier(L, p, ts);
109+
return ts;
104110
}
105111

106112

@@ -140,7 +146,7 @@ static void LoadConstants (LoadState *S, Proto *f) {
140146
break;
141147
case LUA_TSHRSTR:
142148
case LUA_TLNGSTR:
143-
setsvalue2n(S->L, o, LoadString(S));
149+
setsvalue2n(S->L, o, LoadString(S, f));
144150
break;
145151
default:
146152
lua_assert(0);
@@ -158,6 +164,7 @@ static void LoadProtos (LoadState *S, Proto *f) {
158164
f->p[i] = NULL;
159165
for (i = 0; i < n; i++) {
160166
f->p[i] = luaF_newproto(S->L);
167+
luaC_objbarrier(S->L, f, f->p[i]);
161168
LoadFunction(S, f->p[i], f->source);
162169
}
163170
}
@@ -189,18 +196,18 @@ static void LoadDebug (LoadState *S, Proto *f) {
189196
for (i = 0; i < n; i++)
190197
f->locvars[i].varname = NULL;
191198
for (i = 0; i < n; i++) {
192-
f->locvars[i].varname = LoadString(S);
199+
f->locvars[i].varname = LoadString(S, f);
193200
f->locvars[i].startpc = LoadInt(S);
194201
f->locvars[i].endpc = LoadInt(S);
195202
}
196203
n = LoadInt(S);
197204
for (i = 0; i < n; i++)
198-
f->upvalues[i].name = LoadString(S);
205+
f->upvalues[i].name = LoadString(S, f);
199206
}
200207

201208

202209
static void LoadFunction (LoadState *S, Proto *f, TString *psource) {
203-
f->source = LoadString(S);
210+
f->source = LoadString(S, f);
204211
if (f->source == NULL) /* no source in dump? */
205212
f->source = psource; /* reuse parent's source */
206213
f->linedefined = LoadInt(S);
@@ -271,6 +278,7 @@ LClosure *luaU_undump(lua_State *L, ZIO *Z, const char *name) {
271278
setclLvalue(L, L->top, cl);
272279
luaD_inctop(L);
273280
cl->p = luaF_newproto(L);
281+
luaC_objbarrier(L, cl, cl->p);
274282
LoadFunction(&S, cl->p, NULL);
275283
lua_assert(cl->nupvalues == cl->p->sizeupvalues);
276284
luai_verifycode(L, buff, cl->p);
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl Build {
5858
let source_dir = match version {
5959
Lua51 => source_dir_base.join("lua-5.1.5"),
6060
Lua52 => source_dir_base.join("lua-5.2.4"),
61-
Lua53 => source_dir_base.join("lua-5.3.5"),
61+
Lua53 => source_dir_base.join("lua-5.3.6"),
6262
Lua54 => source_dir_base.join("lua-5.4.0"),
6363
};
6464

0 commit comments

Comments
 (0)