Skip to content

Commit 9ae371d

Browse files
committed
Update Lua 5.4 to the released 5.4.0 and bump version to 540.0.0
1 parent 38c4d7b commit 9ae371d

File tree

7 files changed

+49
-34
lines changed

7 files changed

+49
-34
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.4+540rc4"
3+
version = "540.0.0"
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(rc4) and logic to build them.
11+
Sources of Lua 5.1/5.2/5.3/5.4 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(rc4) and logic to build them.
7+
This crate contains the sources of Lua 5.1/5.2/5.3/5.4 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

+3-1
Original file line numberDiff line numberDiff line change
@@ -995,8 +995,10 @@ static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
995995

996996

997997
static int panic (lua_State *L) {
998+
const char *msg = lua_tostring(L, -1);
999+
if (msg == NULL) msg = "error object is not a string";
9981000
lua_writestringerror("PANIC: unprotected error in call to Lua API (%s)\n",
999-
lua_tostring(L, -1));
1001+
msg);
10001002
return 0; /* return to Lua to abort */
10011003
}
10021004

lua-5.4.0/ldblib.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ static int db_debug (lua_State *L) {
417417
return 0;
418418
if (luaL_loadbuffer(L, buffer, strlen(buffer), "=(debug command)") ||
419419
lua_pcall(L, 0, 0, 0))
420-
lua_writestringerror("%s\n", lua_tostring(L, -1));
420+
lua_writestringerror("%s\n", luaL_tolstring(L, -1, NULL));
421421
lua_settop(L, 0); /* remove eventual returns */
422422
}
423423
}

lua-5.4.0/lparser.c

+3
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,7 @@ static void open_func (LexState *ls, FuncState *fs, BlockCnt *bl) {
737737
fs->firstlabel = ls->dyd->label.n;
738738
fs->bl = NULL;
739739
f->source = ls->source;
740+
luaC_objbarrier(ls->L, f, f->source);
740741
f->maxstacksize = 2; /* registers 0/1 are always valid */
741742
enterblock(fs, bl, 0);
742743
}
@@ -1959,6 +1960,7 @@ static void mainfunc (LexState *ls, FuncState *fs) {
19591960
env->idx = 0;
19601961
env->kind = VDKREG;
19611962
env->name = ls->envn;
1963+
luaC_objbarrier(ls->L, fs->f, env->name);
19621964
luaX_next(ls); /* read first token */
19631965
statlist(ls); /* parse main body */
19641966
check(ls, TK_EOS);
@@ -1977,6 +1979,7 @@ LClosure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff,
19771979
sethvalue2s(L, L->top, lexstate.h); /* anchor it */
19781980
luaD_inctop(L);
19791981
funcstate.f = cl->p = luaF_newproto(L);
1982+
luaC_objbarrier(L, cl, cl->p);
19801983
funcstate.f->source = luaS_new(L, name); /* create and anchor TString */
19811984
luaC_objbarrier(L, funcstate.f, funcstate.f->source);
19821985
lexstate.buff = buff;

lua-5.4.0/lstate.c

+18-13
Original file line numberDiff line numberDiff line change
@@ -186,20 +186,26 @@ void luaE_freeCI (lua_State *L) {
186186

187187

188188
/*
189-
** free half of the CallInfo structures not in use by a thread
189+
** free half of the CallInfo structures not in use by a thread,
190+
** keeping the first one.
190191
*/
191192
void luaE_shrinkCI (lua_State *L) {
192-
CallInfo *ci = L->ci;
193+
CallInfo *ci = L->ci->next; /* first free CallInfo */
193194
CallInfo *next;
194-
CallInfo *next2; /* next's next */
195+
if (ci == NULL)
196+
return; /* no extra elements */
195197
L->nCcalls += L->nci; /* add removed elements back to 'nCcalls' */
196-
/* while there are two nexts */
197-
while ((next = ci->next) != NULL && (next2 = next->next) != NULL) {
198+
while ((next = ci->next) != NULL) { /* two extra elements? */
199+
CallInfo *next2 = next->next; /* next's next */
198200
ci->next = next2; /* remove next from the list */
199-
next2->previous = ci;
200-
luaM_free(L, next); /* free next */
201201
L->nci--;
202-
ci = next2; /* keep next's next */
202+
luaM_free(L, next); /* free next */
203+
if (next2 == NULL)
204+
break; /* no more elements */
205+
else {
206+
next2->previous = ci;
207+
ci = next2; /* continue */
208+
}
203209
}
204210
L->nCcalls -= L->nci; /* adjust result */
205211
}
@@ -356,19 +362,18 @@ int lua_resetthread (lua_State *L) {
356362
CallInfo *ci;
357363
int status;
358364
lua_lock(L);
359-
ci = &L->base_ci;
360-
status = luaF_close(L, L->stack, CLOSEPROTECT);
365+
L->ci = ci = &L->base_ci; /* unwind CallInfo list */
361366
setnilvalue(s2v(L->stack)); /* 'function' entry for basic 'ci' */
367+
ci->func = L->stack;
368+
ci->callstatus = CIST_C;
369+
status = luaF_close(L, L->stack, CLOSEPROTECT);
362370
if (status != CLOSEPROTECT) /* real errors? */
363371
luaD_seterrorobj(L, status, L->stack + 1);
364372
else {
365373
status = LUA_OK;
366374
L->top = L->stack + 1;
367375
}
368-
ci->callstatus = CIST_C;
369-
ci->func = L->stack;
370376
ci->top = L->top + LUA_MINSTACK;
371-
L->ci = ci;
372377
L->status = status;
373378
lua_unlock(L);
374379
return status;

lua-5.4.0/lundump.c

+21-16
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727

2828
#if !defined(luai_verifycode)
29-
#define luai_verifycode(L,b,f) /* empty */
29+
#define luai_verifycode(L,f) /* empty */
3030
#endif
3131

3232

@@ -105,30 +105,33 @@ static lua_Integer loadInteger (LoadState *S) {
105105

106106

107107
/*
108-
** Load a nullable string.
108+
** Load a nullable string into prototype 'p'.
109109
*/
110-
static TString *loadStringN (LoadState *S) {
110+
static TString *loadStringN (LoadState *S, Proto *p) {
111+
lua_State *L = S->L;
112+
TString *ts;
111113
size_t size = loadSize(S);
112-
if (size == 0)
114+
if (size == 0) /* no string? */
113115
return NULL;
114116
else if (--size <= LUAI_MAXSHORTLEN) { /* short string? */
115117
char buff[LUAI_MAXSHORTLEN];
116-
loadVector(S, buff, size);
117-
return luaS_newlstr(S->L, buff, size);
118+
loadVector(S, buff, size); /* load string into buffer */
119+
ts = luaS_newlstr(L, buff, size); /* create string */
118120
}
119121
else { /* long string */
120-
TString *ts = luaS_createlngstrobj(S->L, size);
122+
ts = luaS_createlngstrobj(L, size); /* create string */
121123
loadVector(S, getstr(ts), size); /* load directly in final place */
122-
return ts;
123124
}
125+
luaC_objbarrier(L, p, ts);
126+
return ts;
124127
}
125128

126129

127130
/*
128-
** Load a non-nullable string.
131+
** Load a non-nullable string into prototype 'p'.
129132
*/
130-
static TString *loadString (LoadState *S) {
131-
TString *st = loadStringN(S);
133+
static TString *loadString (LoadState *S, Proto *p) {
134+
TString *st = loadStringN(S, p);
132135
if (st == NULL)
133136
error(S, "bad format for constant string");
134137
return st;
@@ -174,7 +177,7 @@ static void loadConstants (LoadState *S, Proto *f) {
174177
break;
175178
case LUA_VSHRSTR:
176179
case LUA_VLNGSTR:
177-
setsvalue2n(S->L, o, loadString(S));
180+
setsvalue2n(S->L, o, loadString(S, f));
178181
break;
179182
default: lua_assert(0);
180183
}
@@ -191,6 +194,7 @@ static void loadProtos (LoadState *S, Proto *f) {
191194
f->p[i] = NULL;
192195
for (i = 0; i < n; i++) {
193196
f->p[i] = luaF_newproto(S->L);
197+
luaC_objbarrier(S->L, f, f->p[i]);
194198
loadFunction(S, f->p[i], f->source);
195199
}
196200
}
@@ -229,18 +233,18 @@ static void loadDebug (LoadState *S, Proto *f) {
229233
for (i = 0; i < n; i++)
230234
f->locvars[i].varname = NULL;
231235
for (i = 0; i < n; i++) {
232-
f->locvars[i].varname = loadStringN(S);
236+
f->locvars[i].varname = loadStringN(S, f);
233237
f->locvars[i].startpc = loadInt(S);
234238
f->locvars[i].endpc = loadInt(S);
235239
}
236240
n = loadInt(S);
237241
for (i = 0; i < n; i++)
238-
f->upvalues[i].name = loadStringN(S);
242+
f->upvalues[i].name = loadStringN(S, f);
239243
}
240244

241245

242246
static void loadFunction (LoadState *S, Proto *f, TString *psource) {
243-
f->source = loadStringN(S);
247+
f->source = loadStringN(S, f);
244248
if (f->source == NULL) /* no source in dump? */
245249
f->source = psource; /* reuse parent's source */
246250
f->linedefined = loadInt(S);
@@ -310,9 +314,10 @@ LClosure *luaU_undump(lua_State *L, ZIO *Z, const char *name) {
310314
setclLvalue2s(L, L->top, cl);
311315
luaD_inctop(L);
312316
cl->p = luaF_newproto(L);
317+
luaC_objbarrier(L, cl, cl->p);
313318
loadFunction(&S, cl->p, NULL);
314319
lua_assert(cl->nupvalues == cl->p->sizeupvalues);
315-
luai_verifycode(L, buff, cl->p);
320+
luai_verifycode(L, cl->p);
316321
return cl;
317322
}
318323

0 commit comments

Comments
 (0)