diff options
author | Li Jin <dragon-fly@qq.com> | 2022-08-25 11:24:10 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2022-08-26 10:10:19 +0800 |
commit | df85ad2e7f975026ca1e6bd84b26fff81c8d99c8 (patch) | |
tree | 2b9300041c291382b15da3c354de3640a1498c1b /src/3rdParty/lua/ldo.c | |
parent | 2f497477c984e576e9ba7e8f6cb92ee9f794e56b (diff) | |
download | yuescript-df85ad2e7f975026ca1e6bd84b26fff81c8d99c8.tar.gz yuescript-df85ad2e7f975026ca1e6bd84b26fff81c8d99c8.tar.bz2 yuescript-df85ad2e7f975026ca1e6bd84b26fff81c8d99c8.zip |
update to Lua 5.4.5.
Diffstat (limited to 'src/3rdParty/lua/ldo.c')
-rw-r--r-- | src/3rdParty/lua/ldo.c | 42 |
1 files changed, 25 insertions, 17 deletions
diff --git a/src/3rdParty/lua/ldo.c b/src/3rdParty/lua/ldo.c index a48e35f..419b3db 100644 --- a/src/3rdParty/lua/ldo.c +++ b/src/3rdParty/lua/ldo.c | |||
@@ -213,7 +213,7 @@ int luaD_reallocstack (lua_State *L, int newsize, int raiseerror) { | |||
213 | 213 | ||
214 | 214 | ||
215 | /* | 215 | /* |
216 | ** Try to grow the stack by at least 'n' elements. when 'raiseerror' | 216 | ** Try to grow the stack by at least 'n' elements. When 'raiseerror' |
217 | ** is true, raises any error; otherwise, return 0 in case of errors. | 217 | ** is true, raises any error; otherwise, return 0 in case of errors. |
218 | */ | 218 | */ |
219 | int luaD_growstack (lua_State *L, int n, int raiseerror) { | 219 | int luaD_growstack (lua_State *L, int n, int raiseerror) { |
@@ -227,7 +227,7 @@ int luaD_growstack (lua_State *L, int n, int raiseerror) { | |||
227 | luaD_throw(L, LUA_ERRERR); /* error inside message handler */ | 227 | luaD_throw(L, LUA_ERRERR); /* error inside message handler */ |
228 | return 0; /* if not 'raiseerror', just signal it */ | 228 | return 0; /* if not 'raiseerror', just signal it */ |
229 | } | 229 | } |
230 | else { | 230 | else if (n < LUAI_MAXSTACK) { /* avoids arithmetic overflows */ |
231 | int newsize = 2 * size; /* tentative new size */ | 231 | int newsize = 2 * size; /* tentative new size */ |
232 | int needed = cast_int(L->top - L->stack) + n; | 232 | int needed = cast_int(L->top - L->stack) + n; |
233 | if (newsize > LUAI_MAXSTACK) /* cannot cross the limit */ | 233 | if (newsize > LUAI_MAXSTACK) /* cannot cross the limit */ |
@@ -236,17 +236,20 @@ int luaD_growstack (lua_State *L, int n, int raiseerror) { | |||
236 | newsize = needed; | 236 | newsize = needed; |
237 | if (l_likely(newsize <= LUAI_MAXSTACK)) | 237 | if (l_likely(newsize <= LUAI_MAXSTACK)) |
238 | return luaD_reallocstack(L, newsize, raiseerror); | 238 | return luaD_reallocstack(L, newsize, raiseerror); |
239 | else { /* stack overflow */ | ||
240 | /* add extra size to be able to handle the error message */ | ||
241 | luaD_reallocstack(L, ERRORSTACKSIZE, raiseerror); | ||
242 | if (raiseerror) | ||
243 | luaG_runerror(L, "stack overflow"); | ||
244 | return 0; | ||
245 | } | ||
246 | } | 239 | } |
240 | /* else stack overflow */ | ||
241 | /* add extra size to be able to handle the error message */ | ||
242 | luaD_reallocstack(L, ERRORSTACKSIZE, raiseerror); | ||
243 | if (raiseerror) | ||
244 | luaG_runerror(L, "stack overflow"); | ||
245 | return 0; | ||
247 | } | 246 | } |
248 | 247 | ||
249 | 248 | ||
249 | /* | ||
250 | ** Compute how much of the stack is being used, by computing the | ||
251 | ** maximum top of all call frames in the stack and the current top. | ||
252 | */ | ||
250 | static int stackinuse (lua_State *L) { | 253 | static int stackinuse (lua_State *L) { |
251 | CallInfo *ci; | 254 | CallInfo *ci; |
252 | int res; | 255 | int res; |
@@ -254,7 +257,7 @@ static int stackinuse (lua_State *L) { | |||
254 | for (ci = L->ci; ci != NULL; ci = ci->previous) { | 257 | for (ci = L->ci; ci != NULL; ci = ci->previous) { |
255 | if (lim < ci->top) lim = ci->top; | 258 | if (lim < ci->top) lim = ci->top; |
256 | } | 259 | } |
257 | lua_assert(lim <= L->stack_last); | 260 | lua_assert(lim <= L->stack_last + EXTRA_STACK); |
258 | res = cast_int(lim - L->stack) + 1; /* part of stack in use */ | 261 | res = cast_int(lim - L->stack) + 1; /* part of stack in use */ |
259 | if (res < LUA_MINSTACK) | 262 | if (res < LUA_MINSTACK) |
260 | res = LUA_MINSTACK; /* ensure a minimum size */ | 263 | res = LUA_MINSTACK; /* ensure a minimum size */ |
@@ -427,14 +430,15 @@ l_sinline void moveresults (lua_State *L, StkId res, int nres, int wanted) { | |||
427 | break; | 430 | break; |
428 | default: /* two/more results and/or to-be-closed variables */ | 431 | default: /* two/more results and/or to-be-closed variables */ |
429 | if (hastocloseCfunc(wanted)) { /* to-be-closed variables? */ | 432 | if (hastocloseCfunc(wanted)) { /* to-be-closed variables? */ |
430 | ptrdiff_t savedres = savestack(L, res); | ||
431 | L->ci->callstatus |= CIST_CLSRET; /* in case of yields */ | 433 | L->ci->callstatus |= CIST_CLSRET; /* in case of yields */ |
432 | L->ci->u2.nres = nres; | 434 | L->ci->u2.nres = nres; |
433 | luaF_close(L, res, CLOSEKTOP, 1); | 435 | res = luaF_close(L, res, CLOSEKTOP, 1); |
434 | L->ci->callstatus &= ~CIST_CLSRET; | 436 | L->ci->callstatus &= ~CIST_CLSRET; |
435 | if (L->hookmask) /* if needed, call hook after '__close's */ | 437 | if (L->hookmask) { /* if needed, call hook after '__close's */ |
438 | ptrdiff_t savedres = savestack(L, res); | ||
436 | rethook(L, L->ci, nres); | 439 | rethook(L, L->ci, nres); |
437 | res = restorestack(L, savedres); /* close and hook can move stack */ | 440 | res = restorestack(L, savedres); /* hook can move stack */ |
441 | } | ||
438 | wanted = decodeNresults(wanted); | 442 | wanted = decodeNresults(wanted); |
439 | if (wanted == LUA_MULTRET) | 443 | if (wanted == LUA_MULTRET) |
440 | wanted = nres; /* we want all results */ | 444 | wanted = nres; /* we want all results */ |
@@ -598,12 +602,17 @@ CallInfo *luaD_precall (lua_State *L, StkId func, int nresults) { | |||
598 | ** Call a function (C or Lua) through C. 'inc' can be 1 (increment | 602 | ** Call a function (C or Lua) through C. 'inc' can be 1 (increment |
599 | ** number of recursive invocations in the C stack) or nyci (the same | 603 | ** number of recursive invocations in the C stack) or nyci (the same |
600 | ** plus increment number of non-yieldable calls). | 604 | ** plus increment number of non-yieldable calls). |
605 | ** This function can be called with some use of EXTRA_STACK, so it should | ||
606 | ** check the stack before doing anything else. 'luaD_precall' already | ||
607 | ** does that. | ||
601 | */ | 608 | */ |
602 | l_sinline void ccall (lua_State *L, StkId func, int nResults, int inc) { | 609 | l_sinline void ccall (lua_State *L, StkId func, int nResults, int inc) { |
603 | CallInfo *ci; | 610 | CallInfo *ci; |
604 | L->nCcalls += inc; | 611 | L->nCcalls += inc; |
605 | if (l_unlikely(getCcalls(L) >= LUAI_MAXCCALLS)) | 612 | if (l_unlikely(getCcalls(L) >= LUAI_MAXCCALLS)) { |
613 | checkstackp(L, 0, func); /* free any use of EXTRA_STACK */ | ||
606 | luaE_checkcstack(L); | 614 | luaE_checkcstack(L); |
615 | } | ||
607 | if ((ci = luaD_precall(L, func, nResults)) != NULL) { /* Lua function? */ | 616 | if ((ci = luaD_precall(L, func, nResults)) != NULL) { /* Lua function? */ |
608 | ci->callstatus = CIST_FRESH; /* mark that it is a "fresh" execute */ | 617 | ci->callstatus = CIST_FRESH; /* mark that it is a "fresh" execute */ |
609 | luaV_execute(L, ci); /* call it */ | 618 | luaV_execute(L, ci); /* call it */ |
@@ -651,8 +660,7 @@ static int finishpcallk (lua_State *L, CallInfo *ci) { | |||
651 | else { /* error */ | 660 | else { /* error */ |
652 | StkId func = restorestack(L, ci->u2.funcidx); | 661 | StkId func = restorestack(L, ci->u2.funcidx); |
653 | L->allowhook = getoah(ci->callstatus); /* restore 'allowhook' */ | 662 | L->allowhook = getoah(ci->callstatus); /* restore 'allowhook' */ |
654 | luaF_close(L, func, status, 1); /* can yield or raise an error */ | 663 | func = luaF_close(L, func, status, 1); /* can yield or raise an error */ |
655 | func = restorestack(L, ci->u2.funcidx); /* stack may be moved */ | ||
656 | luaD_seterrorobj(L, status, func); | 664 | luaD_seterrorobj(L, status, func); |
657 | luaD_shrinkstack(L); /* restore stack size in case of overflow */ | 665 | luaD_shrinkstack(L); /* restore stack size in case of overflow */ |
658 | setcistrecst(ci, LUA_OK); /* clear original status */ | 666 | setcistrecst(ci, LUA_OK); /* clear original status */ |