Skip to content

Commit 4436133

Browse files
committed
update lua
1 parent a6024ac commit 4436133

File tree

6 files changed

+25
-12
lines changed

6 files changed

+25
-12
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#define MAXREGS 255
3636

3737

38+
/* (note that expressions VJMP also have jumps.) */
3839
#define hasjumps(e) ((e)->t != (e)->f)
3940

4041

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,6 @@ void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop) {
9494
setsvalue2s(L, oldtop, G(L)->memerrmsg); /* reuse preregistered msg. */
9595
break;
9696
}
97-
case LUA_ERRERR: {
98-
setsvalue2s(L, oldtop, luaS_newliteral(L, "error in error handling"));
99-
break;
100-
}
10197
case LUA_OK: { /* special case only for closing upvalues */
10298
setnilvalue(s2v(oldtop)); /* no error message */
10399
break;
@@ -202,6 +198,16 @@ static void correctstack (lua_State *L) {
202198
/* some space for error handling */
203199
#define ERRORSTACKSIZE (LUAI_MAXSTACK + 200)
204200

201+
202+
/* raise an error while running the message handler */
203+
l_noret luaD_errerr (lua_State *L) {
204+
TString *msg = luaS_newliteral(L, "error in error handling");
205+
setsvalue2s(L, L->top.p, msg);
206+
L->top.p++; /* assume EXTRA_STACK */
207+
luaD_throw(L, LUA_ERRERR);
208+
}
209+
210+
205211
/*
206212
** Reallocate the stack to a new size, correcting all pointers into it.
207213
** In ISO C, any pointer use after the pointer has been deallocated is
@@ -251,7 +257,7 @@ int luaD_growstack (lua_State *L, int n, int raiseerror) {
251257
a stack error; cannot grow further than that. */
252258
lua_assert(stacksize(L) == ERRORSTACKSIZE);
253259
if (raiseerror)
254-
luaD_throw(L, LUA_ERRERR); /* error inside message handler */
260+
luaD_errerr(L); /* error inside message handler */
255261
return 0; /* if not 'raiseerror', just signal it */
256262
}
257263
else if (n < LUAI_MAXSTACK) { /* avoids arithmetic overflows */

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
/* type of protected functions, to be ran by 'runprotected' */
6161
typedef void (*Pfunc) (lua_State *L, void *ud);
6262

63+
LUAI_FUNC l_noret luaD_errerr (lua_State *L);
6364
LUAI_FUNC void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop);
6465
LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name,
6566
const char *mode);

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ void luaE_checkcstack (lua_State *L) {
166166
if (getCcalls(L) == LUAI_MAXCCALLS)
167167
luaG_runerror(L, "C stack overflow");
168168
else if (getCcalls(L) >= (LUAI_MAXCCALLS / 10 * 11))
169-
luaD_throw(L, LUA_ERRERR); /* error while handling stack error */
169+
luaD_errerr(L); /* error while handling stack error */
170170
}
171171

172172

@@ -272,7 +272,9 @@ static void close_state (lua_State *L) {
272272
luaC_freeallobjects(L); /* just collect its objects */
273273
else { /* closing a fully built state */
274274
L->ci = &L->base_ci; /* unwind CallInfo list */
275+
L->errfunc = 0; /* stack unwind can "throw away" the error function */
275276
luaD_closeprotected(L, 1, LUA_OK); /* close all upvalues */
277+
L->top.p = L->stack.p + 1; /* empty the stack to run finalizers */
276278
luaC_freeallobjects(L); /* collect all objects */
277279
luai_userstateclose(L);
278280
}
@@ -328,6 +330,7 @@ int luaE_resetthread (lua_State *L, int status) {
328330
if (status == LUA_YIELD)
329331
status = LUA_OK;
330332
L->status = LUA_OK; /* so it can run __close metamethods */
333+
L->errfunc = 0; /* stack unwind can "throw away" the error function */
331334
status = luaD_closeprotected(L, 1, status);
332335
if (status != LUA_OK) /* errors? */
333336
luaD_seterrorobj(L, status, L->stack.p + 1);

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -490,10 +490,8 @@ static int incomplete (lua_State *L, int status) {
490490
if (status == LUA_ERRSYNTAX) {
491491
size_t lmsg;
492492
const char *msg = lua_tolstring(L, -1, &lmsg);
493-
if (lmsg >= marklen && strcmp(msg + lmsg - marklen, EOFMARK) == 0) {
494-
lua_pop(L, 1);
493+
if (lmsg >= marklen && strcmp(msg + lmsg - marklen, EOFMARK) == 0)
495494
return 1;
496-
}
497495
}
498496
return 0; /* else... */
499497
}
@@ -508,9 +506,9 @@ static int pushline (lua_State *L, int firstline) {
508506
size_t l;
509507
const char *prmt = get_prompt(L, firstline);
510508
int readstatus = lua_readline(L, b, prmt);
511-
if (readstatus == 0)
512-
return 0; /* no input (prompt will be popped by caller) */
513509
lua_pop(L, 1); /* remove prompt */
510+
if (readstatus == 0)
511+
return 0; /* no input */
514512
l = strlen(b);
515513
if (l > 0 && b[l-1] == '\n') /* line ends with newline? */
516514
b[--l] = '\0'; /* remove it */
@@ -552,8 +550,9 @@ static int multiline (lua_State *L) {
552550
int status = luaL_loadbuffer(L, line, len, "=stdin"); /* try it */
553551
if (!incomplete(L, status) || !pushline(L, 0)) {
554552
lua_saveline(L, line); /* keep history */
555-
return status; /* cannot or should not try to add continuation line */
553+
return status; /* should not or cannot try to add continuation line */
556554
}
555+
lua_remove(L, -2); /* remove error message (from incomplete line) */
557556
lua_pushliteral(L, "\n"); /* add newline... */
558557
lua_insert(L, -2); /* ...between the two lines */
559558
lua_concat(L, 3); /* join them */

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,10 @@ void luaV_finishset (lua_State *L, const TValue *t, TValue *key,
339339
lua_assert(isempty(slot)); /* slot must be empty */
340340
tm = fasttm(L, h->metatable, TM_NEWINDEX); /* get metamethod */
341341
if (tm == NULL) { /* no metamethod? */
342+
sethvalue2s(L, L->top.p, h); /* anchor 't' */
343+
L->top.p++; /* assume EXTRA_STACK */
342344
luaH_finishset(L, h, key, slot, val); /* set new value */
345+
L->top.p--;
343346
invalidateTMcache(h);
344347
luaC_barrierback(L, obj2gco(h), val);
345348
return;

0 commit comments

Comments
 (0)