Skip to content

Commit d4cad11

Browse files
committed
update lua55
1 parent 55a426f commit d4cad11

File tree

11 files changed

+39
-11
lines changed

11 files changed

+39
-11
lines changed

3rd/lua/lua-latest/lauxlib.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1185,7 +1185,7 @@ LUALIB_API lua_State *(luaL_newstate) (void) {
11851185
lua_State *L = lua_newstate(luaL_alloc, NULL, luaL_makeseed(NULL));
11861186
if (l_likely(L)) {
11871187
lua_atpanic(L, &panic);
1188-
lua_setwarnf(L, warnfoff, L); /* default is warnings off */
1188+
lua_setwarnf(L, warnfon, L);
11891189
}
11901190
return L;
11911191
}

3rd/lua/lua-latest/ldo.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,17 @@ l_noret luaD_errerr (lua_State *L) {
223223
}
224224

225225

226+
/*
227+
** Check whether stack has enough space to run a simple function (such
228+
** as a finalizer): At least BASIC_STACK_SIZE in the Lua stack and
229+
** 2 slots in the C stack.
230+
*/
231+
int luaD_checkminstack (lua_State *L) {
232+
return ((stacksize(L) < MAXSTACK - BASIC_STACK_SIZE) &&
233+
(getCcalls(L) < LUAI_MAXCCALLS - 2));
234+
}
235+
236+
226237
/*
227238
** In ISO C, any pointer use after the pointer has been deallocated is
228239
** undefined behavior. So, before a stack reallocation, all pointers

3rd/lua/lua-latest/ldo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ LUAI_FUNC int luaD_reallocstack (lua_State *L, int newsize, int raiseerror);
8989
LUAI_FUNC int luaD_growstack (lua_State *L, int n, int raiseerror);
9090
LUAI_FUNC void luaD_shrinkstack (lua_State *L);
9191
LUAI_FUNC void luaD_inctop (lua_State *L);
92+
LUAI_FUNC int luaD_checkminstack (lua_State *L);
9293

9394
LUAI_FUNC l_noret luaD_throw (lua_State *L, TStatus errcode);
9495
LUAI_FUNC l_noret luaD_throwbaselevel (lua_State *L, TStatus errcode);

3rd/lua/lua-latest/lgc.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,7 +1293,7 @@ static void finishgencycle (lua_State *L, global_State *g) {
12931293
correctgraylists(g);
12941294
checkSizes(L, g);
12951295
g->gcstate = GCSpropagate; /* skip restart */
1296-
if (!g->gcemergency)
1296+
if (!g->gcemergency && luaD_checkminstack(L))
12971297
callallpendingfinalizers(L);
12981298
}
12991299

@@ -1667,12 +1667,13 @@ static l_mem singlestep (lua_State *L, int fast) {
16671667
break;
16681668
}
16691669
case GCScallfin: { /* call finalizers */
1670-
if (g->tobefnz && !g->gcemergency) {
1670+
if (g->tobefnz && !g->gcemergency && luaD_checkminstack(L)) {
16711671
g->gcstopem = 0; /* ok collections during finalizers */
16721672
GCTM(L); /* call one finalizer */
16731673
stepresult = CWUFIN;
16741674
}
1675-
else { /* emergency mode or no more finalizers */
1675+
else { /* no more finalizers or emergency mode or no enough stack
1676+
to run finalizers */
16761677
g->gcstate = GCSpause; /* finish collection */
16771678
stepresult = step2pause;
16781679
}

3rd/lua/lua-latest/lua.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ static int collectargs (char **argv, int *first) {
349349
*/
350350
static int runargs (lua_State *L, char **argv, int n) {
351351
int i;
352+
lua_warning(L, "@off", 0); /* by default, Lua stand-alone has warnings off */
352353
for (i = 1; i < n; i++) {
353354
int option = argv[i][1];
354355
lua_assert(argv[i][0] == '-'); /* already checked */
@@ -725,7 +726,7 @@ static int pmain (lua_State *L) {
725726
if (handle_luainit(L) != LUA_OK) /* run LUA_INIT */
726727
return 0; /* error running LUA_INIT */
727728
}
728-
if (!runargs(L, argv, optlim)) /* execute arguments -e and -l */
729+
if (!runargs(L, argv, optlim)) /* execute arguments -e, -l, and -W */
729730
return 0; /* something failed */
730731
if (script > 0) { /* execute main script (if there is one) */
731732
if (handle_script(L, argv + script) != LUA_OK)

3rd/lua/lua55/lauxlib.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1185,7 +1185,7 @@ LUALIB_API lua_State *(luaL_newstate) (void) {
11851185
lua_State *L = lua_newstate(luaL_alloc, NULL, luaL_makeseed(NULL));
11861186
if (l_likely(L)) {
11871187
lua_atpanic(L, &panic);
1188-
lua_setwarnf(L, warnfoff, L); /* default is warnings off */
1188+
lua_setwarnf(L, warnfon, L);
11891189
}
11901190
return L;
11911191
}

3rd/lua/lua55/ldo.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,17 @@ l_noret luaD_errerr (lua_State *L) {
223223
}
224224

225225

226+
/*
227+
** Check whether stack has enough space to run a simple function (such
228+
** as a finalizer): At least BASIC_STACK_SIZE in the Lua stack and
229+
** 2 slots in the C stack.
230+
*/
231+
int luaD_checkminstack (lua_State *L) {
232+
return ((stacksize(L) < MAXSTACK - BASIC_STACK_SIZE) &&
233+
(getCcalls(L) < LUAI_MAXCCALLS - 2));
234+
}
235+
236+
226237
/*
227238
** In ISO C, any pointer use after the pointer has been deallocated is
228239
** undefined behavior. So, before a stack reallocation, all pointers

3rd/lua/lua55/ldo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ LUAI_FUNC int luaD_reallocstack (lua_State *L, int newsize, int raiseerror);
8989
LUAI_FUNC int luaD_growstack (lua_State *L, int n, int raiseerror);
9090
LUAI_FUNC void luaD_shrinkstack (lua_State *L);
9191
LUAI_FUNC void luaD_inctop (lua_State *L);
92+
LUAI_FUNC int luaD_checkminstack (lua_State *L);
9293

9394
LUAI_FUNC l_noret luaD_throw (lua_State *L, TStatus errcode);
9495
LUAI_FUNC l_noret luaD_throwbaselevel (lua_State *L, TStatus errcode);

3rd/lua/lua55/lgc.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,7 +1293,7 @@ static void finishgencycle (lua_State *L, global_State *g) {
12931293
correctgraylists(g);
12941294
checkSizes(L, g);
12951295
g->gcstate = GCSpropagate; /* skip restart */
1296-
if (!g->gcemergency)
1296+
if (!g->gcemergency && luaD_checkminstack(L))
12971297
callallpendingfinalizers(L);
12981298
}
12991299

@@ -1667,12 +1667,13 @@ static l_mem singlestep (lua_State *L, int fast) {
16671667
break;
16681668
}
16691669
case GCScallfin: { /* call finalizers */
1670-
if (g->tobefnz && !g->gcemergency) {
1670+
if (g->tobefnz && !g->gcemergency && luaD_checkminstack(L)) {
16711671
g->gcstopem = 0; /* ok collections during finalizers */
16721672
GCTM(L); /* call one finalizer */
16731673
stepresult = CWUFIN;
16741674
}
1675-
else { /* emergency mode or no more finalizers */
1675+
else { /* no more finalizers or emergency mode or no enough stack
1676+
to run finalizers */
16761677
g->gcstate = GCSpause; /* finish collection */
16771678
stepresult = step2pause;
16781679
}

0 commit comments

Comments
 (0)