aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/3rdParty/lua/lapi.c14
-rw-r--r--src/3rdParty/lua/lauxlib.c52
-rw-r--r--src/3rdParty/lua/lcode.c70
-rw-r--r--src/3rdParty/lua/ldebug.c5
-rw-r--r--src/3rdParty/lua/ldo.c42
-rw-r--r--src/3rdParty/lua/ldo.h10
-rw-r--r--src/3rdParty/lua/lfunc.c7
-rw-r--r--src/3rdParty/lua/lfunc.h2
-rw-r--r--src/3rdParty/lua/lgc.c63
-rw-r--r--src/3rdParty/lua/loadlib.c9
-rw-r--r--src/3rdParty/lua/lobject.c34
-rw-r--r--src/3rdParty/lua/lobject.h2
-rw-r--r--src/3rdParty/lua/lparser.c16
-rw-r--r--src/3rdParty/lua/lua.h4
-rw-r--r--src/3rdParty/lua/luaconf.h2
-rw-r--r--src/3rdParty/lua/lvm.c12
16 files changed, 197 insertions, 147 deletions
diff --git a/src/3rdParty/lua/lapi.c b/src/3rdParty/lua/lapi.c
index 5ee6579..5833c7b 100644
--- a/src/3rdParty/lua/lapi.c
+++ b/src/3rdParty/lua/lapi.c
@@ -114,13 +114,8 @@ LUA_API int lua_checkstack (lua_State *L, int n) {
114 api_check(L, n >= 0, "negative 'n'"); 114 api_check(L, n >= 0, "negative 'n'");
115 if (L->stack_last - L->top > n) /* stack large enough? */ 115 if (L->stack_last - L->top > n) /* stack large enough? */
116 res = 1; /* yes; check is OK */ 116 res = 1; /* yes; check is OK */
117 else { /* no; need to grow stack */ 117 else /* need to grow stack */
118 int inuse = cast_int(L->top - L->stack) + EXTRA_STACK; 118 res = luaD_growstack(L, n, 0);
119 if (inuse > LUAI_MAXSTACK - n) /* can grow without overflow? */
120 res = 0; /* no */
121 else /* try to grow stack */
122 res = luaD_growstack(L, n, 0);
123 }
124 if (res && ci->top < L->top + n) 119 if (res && ci->top < L->top + n)
125 ci->top = L->top + n; /* adjust frame top */ 120 ci->top = L->top + n; /* adjust frame top */
126 lua_unlock(L); 121 lua_unlock(L);
@@ -202,7 +197,7 @@ LUA_API void lua_settop (lua_State *L, int idx) {
202 newtop = L->top + diff; 197 newtop = L->top + diff;
203 if (diff < 0 && L->tbclist >= newtop) { 198 if (diff < 0 && L->tbclist >= newtop) {
204 lua_assert(hastocloseCfunc(ci->nresults)); 199 lua_assert(hastocloseCfunc(ci->nresults));
205 luaF_close(L, newtop, CLOSEKTOP, 0); 200 newtop = luaF_close(L, newtop, CLOSEKTOP, 0);
206 } 201 }
207 L->top = newtop; /* correct top only after closing any upvalue */ 202 L->top = newtop; /* correct top only after closing any upvalue */
208 lua_unlock(L); 203 lua_unlock(L);
@@ -215,8 +210,7 @@ LUA_API void lua_closeslot (lua_State *L, int idx) {
215 level = index2stack(L, idx); 210 level = index2stack(L, idx);
216 api_check(L, hastocloseCfunc(L->ci->nresults) && L->tbclist == level, 211 api_check(L, hastocloseCfunc(L->ci->nresults) && L->tbclist == level,
217 "no variable to close at given level"); 212 "no variable to close at given level");
218 luaF_close(L, level, CLOSEKTOP, 0); 213 level = luaF_close(L, level, CLOSEKTOP, 0);
219 level = index2stack(L, idx); /* stack may be moved */
220 setnilvalue(s2v(level)); 214 setnilvalue(s2v(level));
221 lua_unlock(L); 215 lua_unlock(L);
222} 216}
diff --git a/src/3rdParty/lua/lauxlib.c b/src/3rdParty/lua/lauxlib.c
index 8ed1da1..cba5df9 100644
--- a/src/3rdParty/lua/lauxlib.c
+++ b/src/3rdParty/lua/lauxlib.c
@@ -526,7 +526,8 @@ static void newbox (lua_State *L) {
526 526
527/* 527/*
528** Compute new size for buffer 'B', enough to accommodate extra 'sz' 528** Compute new size for buffer 'B', enough to accommodate extra 'sz'
529** bytes. 529** bytes. (The test for "double is not big enough" also gets the
530** case when the multiplication by 2 overflows.)
530*/ 531*/
531static size_t newbuffsize (luaL_Buffer *B, size_t sz) { 532static size_t newbuffsize (luaL_Buffer *B, size_t sz) {
532 size_t newsize = B->size * 2; /* double buffer size */ 533 size_t newsize = B->size * 2; /* double buffer size */
@@ -611,7 +612,7 @@ LUALIB_API void luaL_pushresultsize (luaL_Buffer *B, size_t sz) {
611** box (if existent) is not on the top of the stack. So, instead of 612** box (if existent) is not on the top of the stack. So, instead of
612** calling 'luaL_addlstring', it replicates the code using -2 as the 613** calling 'luaL_addlstring', it replicates the code using -2 as the
613** last argument to 'prepbuffsize', signaling that the box is (or will 614** last argument to 'prepbuffsize', signaling that the box is (or will
614** be) bellow the string being added to the buffer. (Box creation can 615** be) below the string being added to the buffer. (Box creation can
615** trigger an emergency GC, so we should not remove the string from the 616** trigger an emergency GC, so we should not remove the string from the
616** stack before we have the space guaranteed.) 617** stack before we have the space guaranteed.)
617*/ 618*/
@@ -739,17 +740,18 @@ static int errfile (lua_State *L, const char *what, int fnameindex) {
739} 740}
740 741
741 742
742static int skipBOM (LoadF *lf) { 743/*
743 const char *p = "\xEF\xBB\xBF"; /* UTF-8 BOM mark */ 744** Skip an optional BOM at the start of a stream. If there is an
744 int c; 745** incomplete BOM (the first character is correct but the rest is
745 lf->n = 0; 746** not), returns the first character anyway to force an error
746 do { 747** (as no chunk can start with 0xEF).
747 c = getc(lf->f); 748*/
748 if (c == EOF || c != *(const unsigned char *)p++) return c; 749static int skipBOM (FILE *f) {
749 lf->buff[lf->n++] = c; /* to be read by the parser */ 750 int c = getc(f); /* read first character */
750 } while (*p != '\0'); 751 if (c == 0xEF && getc(f) == 0xBB && getc(f) == 0xBF) /* correct BOM? */
751 lf->n = 0; /* prefix matched; discard it */ 752 return getc(f); /* ignore BOM and return next char */
752 return getc(lf->f); /* return next character */ 753 else /* no (valid) BOM */
754 return c; /* return first character */
753} 755}
754 756
755 757
@@ -760,13 +762,13 @@ static int skipBOM (LoadF *lf) {
760** first "valid" character of the file (after the optional BOM and 762** first "valid" character of the file (after the optional BOM and
761** a first-line comment). 763** a first-line comment).
762*/ 764*/
763static int skipcomment (LoadF *lf, int *cp) { 765static int skipcomment (FILE *f, int *cp) {
764 int c = *cp = skipBOM(lf); 766 int c = *cp = skipBOM(f);
765 if (c == '#') { /* first line is a comment (Unix exec. file)? */ 767 if (c == '#') { /* first line is a comment (Unix exec. file)? */
766 do { /* skip first line */ 768 do { /* skip first line */
767 c = getc(lf->f); 769 c = getc(f);
768 } while (c != EOF && c != '\n'); 770 } while (c != EOF && c != '\n');
769 *cp = getc(lf->f); /* skip end-of-line, if present */ 771 *cp = getc(f); /* next character after comment, if present */
770 return 1; /* there was a comment */ 772 return 1; /* there was a comment */
771 } 773 }
772 else return 0; /* no comment */ 774 else return 0; /* no comment */
@@ -788,12 +790,16 @@ LUALIB_API int luaL_loadfilex (lua_State *L, const char *filename,
788 lf.f = fopen(filename, "r"); 790 lf.f = fopen(filename, "r");
789 if (lf.f == NULL) return errfile(L, "open", fnameindex); 791 if (lf.f == NULL) return errfile(L, "open", fnameindex);
790 } 792 }
791 if (skipcomment(&lf, &c)) /* read initial portion */ 793 lf.n = 0;
792 lf.buff[lf.n++] = '\n'; /* add line to correct line numbers */ 794 if (skipcomment(lf.f, &c)) /* read initial portion */
793 if (c == LUA_SIGNATURE[0] && filename) { /* binary file? */ 795 lf.buff[lf.n++] = '\n'; /* add newline to correct line numbers */
794 lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */ 796 if (c == LUA_SIGNATURE[0]) { /* binary file? */
795 if (lf.f == NULL) return errfile(L, "reopen", fnameindex); 797 lf.n = 0; /* remove possible newline */
796 skipcomment(&lf, &c); /* re-read initial portion */ 798 if (filename) { /* "real" file? */
799 lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */
800 if (lf.f == NULL) return errfile(L, "reopen", fnameindex);
801 skipcomment(lf.f, &c); /* re-read initial portion */
802 }
797 } 803 }
798 if (c != EOF) 804 if (c != EOF)
799 lf.buff[lf.n++] = c; /* 'c' is the first character of the stream */ 805 lf.buff[lf.n++] = c; /* 'c' is the first character of the stream */
diff --git a/src/3rdParty/lua/lcode.c b/src/3rdParty/lua/lcode.c
index 06425a1..911dbd5 100644
--- a/src/3rdParty/lua/lcode.c
+++ b/src/3rdParty/lua/lcode.c
@@ -1391,7 +1391,10 @@ static void finishbinexpval (FuncState *fs, expdesc *e1, expdesc *e2,
1391*/ 1391*/
1392static void codebinexpval (FuncState *fs, OpCode op, 1392static void codebinexpval (FuncState *fs, OpCode op,
1393 expdesc *e1, expdesc *e2, int line) { 1393 expdesc *e1, expdesc *e2, int line) {
1394 int v2 = luaK_exp2anyreg(fs, e2); /* both operands are in registers */ 1394 int v2 = luaK_exp2anyreg(fs, e2); /* make sure 'e2' is in a register */
1395 /* 'e1' must be already in a register or it is a constant */
1396 lua_assert((VNIL <= e1->k && e1->k <= VKSTR) ||
1397 e1->k == VNONRELOC || e1->k == VRELOC);
1395 lua_assert(OP_ADD <= op && op <= OP_SHR); 1398 lua_assert(OP_ADD <= op && op <= OP_SHR);
1396 finishbinexpval(fs, e1, e2, op, v2, 0, line, OP_MMBIN, 1399 finishbinexpval(fs, e1, e2, op, v2, 0, line, OP_MMBIN,
1397 cast(TMS, (op - OP_ADD) + TM_ADD)); 1400 cast(TMS, (op - OP_ADD) + TM_ADD));
@@ -1410,6 +1413,18 @@ static void codebini (FuncState *fs, OpCode op,
1410} 1413}
1411 1414
1412 1415
1416/*
1417** Code binary operators with K operand.
1418*/
1419static void codebinK (FuncState *fs, BinOpr opr,
1420 expdesc *e1, expdesc *e2, int flip, int line) {
1421 TMS event = cast(TMS, opr + TM_ADD);
1422 int v2 = e2->u.info; /* K index */
1423 OpCode op = cast(OpCode, opr + OP_ADDK);
1424 finishbinexpval(fs, e1, e2, op, v2, flip, line, OP_MMBINK, event);
1425}
1426
1427
1413/* Try to code a binary operator negating its second operand. 1428/* Try to code a binary operator negating its second operand.
1414** For the metamethod, 2nd operand must keep its original value. 1429** For the metamethod, 2nd operand must keep its original value.
1415*/ 1430*/
@@ -1438,23 +1453,27 @@ static void swapexps (expdesc *e1, expdesc *e2) {
1438 1453
1439 1454
1440/* 1455/*
1456** Code binary operators with no constant operand.
1457*/
1458static void codebinNoK (FuncState *fs, BinOpr opr,
1459 expdesc *e1, expdesc *e2, int flip, int line) {
1460 OpCode op = cast(OpCode, opr + OP_ADD);
1461 if (flip)
1462 swapexps(e1, e2); /* back to original order */
1463 codebinexpval(fs, op, e1, e2, line); /* use standard operators */
1464}
1465
1466
1467/*
1441** Code arithmetic operators ('+', '-', ...). If second operand is a 1468** Code arithmetic operators ('+', '-', ...). If second operand is a
1442** constant in the proper range, use variant opcodes with K operands. 1469** constant in the proper range, use variant opcodes with K operands.
1443*/ 1470*/
1444static void codearith (FuncState *fs, BinOpr opr, 1471static void codearith (FuncState *fs, BinOpr opr,
1445 expdesc *e1, expdesc *e2, int flip, int line) { 1472 expdesc *e1, expdesc *e2, int flip, int line) {
1446 TMS event = cast(TMS, opr + TM_ADD); 1473 if (tonumeral(e2, NULL) && luaK_exp2K(fs, e2)) /* K operand? */
1447 if (tonumeral(e2, NULL) && luaK_exp2K(fs, e2)) { /* K operand? */ 1474 codebinK(fs, opr, e1, e2, flip, line);
1448 int v2 = e2->u.info; /* K index */ 1475 else /* 'e2' is neither an immediate nor a K operand */
1449 OpCode op = cast(OpCode, opr + OP_ADDK); 1476 codebinNoK(fs, opr, e1, e2, flip, line);
1450 finishbinexpval(fs, e1, e2, op, v2, flip, line, OP_MMBINK, event);
1451 }
1452 else { /* 'e2' is neither an immediate nor a K operand */
1453 OpCode op = cast(OpCode, opr + OP_ADD);
1454 if (flip)
1455 swapexps(e1, e2); /* back to original order */
1456 codebinexpval(fs, op, e1, e2, line); /* use standard operators */
1457 }
1458} 1477}
1459 1478
1460 1479
@@ -1478,28 +1497,20 @@ static void codecommutative (FuncState *fs, BinOpr op,
1478 1497
1479 1498
1480/* 1499/*
1481** Code bitwise operations; they are all associative, so the function 1500** Code bitwise operations; they are all commutative, so the function
1482** tries to put an integer constant as the 2nd operand (a K operand). 1501** tries to put an integer constant as the 2nd operand (a K operand).
1483*/ 1502*/
1484static void codebitwise (FuncState *fs, BinOpr opr, 1503static void codebitwise (FuncState *fs, BinOpr opr,
1485 expdesc *e1, expdesc *e2, int line) { 1504 expdesc *e1, expdesc *e2, int line) {
1486 int flip = 0; 1505 int flip = 0;
1487 int v2; 1506 if (e1->k == VKINT) {
1488 OpCode op;
1489 if (e1->k == VKINT && luaK_exp2RK(fs, e1)) {
1490 swapexps(e1, e2); /* 'e2' will be the constant operand */ 1507 swapexps(e1, e2); /* 'e2' will be the constant operand */
1491 flip = 1; 1508 flip = 1;
1492 } 1509 }
1493 else if (!(e2->k == VKINT && luaK_exp2RK(fs, e2))) { /* no constants? */ 1510 if (e2->k == VKINT && luaK_exp2K(fs, e2)) /* K operand? */
1494 op = cast(OpCode, opr + OP_ADD); 1511 codebinK(fs, opr, e1, e2, flip, line);
1495 codebinexpval(fs, op, e1, e2, line); /* all-register opcodes */ 1512 else /* no constants */
1496 return; 1513 codebinNoK(fs, opr, e1, e2, flip, line);
1497 }
1498 v2 = e2->u.info; /* index in K array */
1499 op = cast(OpCode, opr + OP_ADDK);
1500 lua_assert(ttisinteger(&fs->f->k[v2]));
1501 finishbinexpval(fs, e1, e2, op, v2, flip, line, OP_MMBINK,
1502 cast(TMS, opr + TM_ADD));
1503} 1514}
1504 1515
1505 1516
@@ -1551,7 +1562,7 @@ static void codeeq (FuncState *fs, BinOpr opr, expdesc *e1, expdesc *e2) {
1551 op = OP_EQI; 1562 op = OP_EQI;
1552 r2 = im; /* immediate operand */ 1563 r2 = im; /* immediate operand */
1553 } 1564 }
1554 else if (luaK_exp2RK(fs, e2)) { /* 1st expression is constant? */ 1565 else if (luaK_exp2RK(fs, e2)) { /* 2nd expression is constant? */
1555 op = OP_EQK; 1566 op = OP_EQK;
1556 r2 = e2->u.info; /* constant index */ 1567 r2 = e2->u.info; /* constant index */
1557 } 1568 }
@@ -1611,7 +1622,8 @@ void luaK_infix (FuncState *fs, BinOpr op, expdesc *v) {
1611 case OPR_SHL: case OPR_SHR: { 1622 case OPR_SHL: case OPR_SHR: {
1612 if (!tonumeral(v, NULL)) 1623 if (!tonumeral(v, NULL))
1613 luaK_exp2anyreg(fs, v); 1624 luaK_exp2anyreg(fs, v);
1614 /* else keep numeral, which may be folded with 2nd operand */ 1625 /* else keep numeral, which may be folded or used as an immediate
1626 operand */
1615 break; 1627 break;
1616 } 1628 }
1617 case OPR_EQ: case OPR_NE: { 1629 case OPR_EQ: case OPR_NE: {
diff --git a/src/3rdParty/lua/ldebug.c b/src/3rdParty/lua/ldebug.c
index a716d95..fa15eaf 100644
--- a/src/3rdParty/lua/ldebug.c
+++ b/src/3rdParty/lua/ldebug.c
@@ -824,8 +824,11 @@ l_noret luaG_runerror (lua_State *L, const char *fmt, ...) {
824 va_start(argp, fmt); 824 va_start(argp, fmt);
825 msg = luaO_pushvfstring(L, fmt, argp); /* format message */ 825 msg = luaO_pushvfstring(L, fmt, argp); /* format message */
826 va_end(argp); 826 va_end(argp);
827 if (isLua(ci)) /* if Lua function, add source:line information */ 827 if (isLua(ci)) { /* if Lua function, add source:line information */
828 luaG_addinfo(L, msg, ci_func(ci)->p->source, getcurrentline(ci)); 828 luaG_addinfo(L, msg, ci_func(ci)->p->source, getcurrentline(ci));
829 setobjs2s(L, L->top - 2, L->top - 1); /* remove 'msg' from the stack */
830 L->top--;
831 }
829 luaG_errormsg(L); 832 luaG_errormsg(L);
830} 833}
831 834
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*/
219int luaD_growstack (lua_State *L, int n, int raiseerror) { 219int 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*/
250static int stackinuse (lua_State *L) { 253static 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*/
602l_sinline void ccall (lua_State *L, StkId func, int nResults, int inc) { 609l_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 */
diff --git a/src/3rdParty/lua/ldo.h b/src/3rdParty/lua/ldo.h
index 911e67f..4661aa0 100644
--- a/src/3rdParty/lua/ldo.h
+++ b/src/3rdParty/lua/ldo.h
@@ -37,6 +37,13 @@
37 37
38 38
39/* macro to check stack size, preserving 'p' */ 39/* macro to check stack size, preserving 'p' */
40#define checkstackp(L,n,p) \
41 luaD_checkstackaux(L, n, \
42 ptrdiff_t t__ = savestack(L, p), /* save 'p' */ \
43 p = restorestack(L, t__)) /* 'pos' part: restore 'p' */
44
45
46/* macro to check stack size and GC, preserving 'p' */
40#define checkstackGCp(L,n,p) \ 47#define checkstackGCp(L,n,p) \
41 luaD_checkstackaux(L, n, \ 48 luaD_checkstackaux(L, n, \
42 ptrdiff_t t__ = savestack(L, p); /* save 'p' */ \ 49 ptrdiff_t t__ = savestack(L, p); /* save 'p' */ \
@@ -58,7 +65,8 @@ LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name,
58LUAI_FUNC void luaD_hook (lua_State *L, int event, int line, 65LUAI_FUNC void luaD_hook (lua_State *L, int event, int line,
59 int fTransfer, int nTransfer); 66 int fTransfer, int nTransfer);
60LUAI_FUNC void luaD_hookcall (lua_State *L, CallInfo *ci); 67LUAI_FUNC void luaD_hookcall (lua_State *L, CallInfo *ci);
61LUAI_FUNC int luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func, int narg1, int delta); 68LUAI_FUNC int luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func,
69 int narg1, int delta);
62LUAI_FUNC CallInfo *luaD_precall (lua_State *L, StkId func, int nResults); 70LUAI_FUNC CallInfo *luaD_precall (lua_State *L, StkId func, int nResults);
63LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults); 71LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults);
64LUAI_FUNC void luaD_callnoyield (lua_State *L, StkId func, int nResults); 72LUAI_FUNC void luaD_callnoyield (lua_State *L, StkId func, int nResults);
diff --git a/src/3rdParty/lua/lfunc.c b/src/3rdParty/lua/lfunc.c
index f5889a2..daba0ab 100644
--- a/src/3rdParty/lua/lfunc.c
+++ b/src/3rdParty/lua/lfunc.c
@@ -209,7 +209,7 @@ void luaF_closeupval (lua_State *L, StkId level) {
209 209
210 210
211/* 211/*
212** Remove firt element from the tbclist plus its dummy nodes. 212** Remove first element from the tbclist plus its dummy nodes.
213*/ 213*/
214static void poptbclist (lua_State *L) { 214static void poptbclist (lua_State *L) {
215 StkId tbc = L->tbclist; 215 StkId tbc = L->tbclist;
@@ -223,9 +223,9 @@ static void poptbclist (lua_State *L) {
223 223
224/* 224/*
225** Close all upvalues and to-be-closed variables up to the given stack 225** Close all upvalues and to-be-closed variables up to the given stack
226** level. 226** level. Return restored 'level'.
227*/ 227*/
228void luaF_close (lua_State *L, StkId level, int status, int yy) { 228StkId luaF_close (lua_State *L, StkId level, int status, int yy) {
229 ptrdiff_t levelrel = savestack(L, level); 229 ptrdiff_t levelrel = savestack(L, level);
230 luaF_closeupval(L, level); /* first, close the upvalues */ 230 luaF_closeupval(L, level); /* first, close the upvalues */
231 while (L->tbclist >= level) { /* traverse tbc's down to that level */ 231 while (L->tbclist >= level) { /* traverse tbc's down to that level */
@@ -234,6 +234,7 @@ void luaF_close (lua_State *L, StkId level, int status, int yy) {
234 prepcallclosemth(L, tbc, status, yy); /* close variable */ 234 prepcallclosemth(L, tbc, status, yy); /* close variable */
235 level = restorestack(L, levelrel); 235 level = restorestack(L, levelrel);
236 } 236 }
237 return level;
237} 238}
238 239
239 240
diff --git a/src/3rdParty/lua/lfunc.h b/src/3rdParty/lua/lfunc.h
index dc1cebc..3d29697 100644
--- a/src/3rdParty/lua/lfunc.h
+++ b/src/3rdParty/lua/lfunc.h
@@ -54,7 +54,7 @@ LUAI_FUNC void luaF_initupvals (lua_State *L, LClosure *cl);
54LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level); 54LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level);
55LUAI_FUNC void luaF_newtbcupval (lua_State *L, StkId level); 55LUAI_FUNC void luaF_newtbcupval (lua_State *L, StkId level);
56LUAI_FUNC void luaF_closeupval (lua_State *L, StkId level); 56LUAI_FUNC void luaF_closeupval (lua_State *L, StkId level);
57LUAI_FUNC void luaF_close (lua_State *L, StkId level, int status, int yy); 57LUAI_FUNC StkId luaF_close (lua_State *L, StkId level, int status, int yy);
58LUAI_FUNC void luaF_unlinkupval (UpVal *uv); 58LUAI_FUNC void luaF_unlinkupval (UpVal *uv);
59LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); 59LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f);
60LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number, 60LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number,
diff --git a/src/3rdParty/lua/lgc.c b/src/3rdParty/lua/lgc.c
index 42a73d8..317ea45 100644
--- a/src/3rdParty/lua/lgc.c
+++ b/src/3rdParty/lua/lgc.c
@@ -1041,7 +1041,25 @@ void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt) {
1041** ======================================================= 1041** =======================================================
1042*/ 1042*/
1043 1043
1044static void setpause (global_State *g); 1044
1045/*
1046** Set the "time" to wait before starting a new GC cycle; cycle will
1047** start when memory use hits the threshold of ('estimate' * pause /
1048** PAUSEADJ). (Division by 'estimate' should be OK: it cannot be zero,
1049** because Lua cannot even start with less than PAUSEADJ bytes).
1050*/
1051static void setpause (global_State *g) {
1052 l_mem threshold, debt;
1053 int pause = getgcparam(g->gcpause);
1054 l_mem estimate = g->GCestimate / PAUSEADJ; /* adjust 'estimate' */
1055 lua_assert(estimate > 0);
1056 threshold = (pause < MAX_LMEM / estimate) /* overflow? */
1057 ? estimate * pause /* no overflow */
1058 : MAX_LMEM; /* overflow; truncate to maximum */
1059 debt = gettotalbytes(g) - threshold;
1060 if (debt > 0) debt = 0;
1061 luaE_setdebt(g, debt);
1062}
1045 1063
1046 1064
1047/* 1065/*
@@ -1286,6 +1304,15 @@ static void atomic2gen (lua_State *L, global_State *g) {
1286 1304
1287 1305
1288/* 1306/*
1307** Set debt for the next minor collection, which will happen when
1308** memory grows 'genminormul'%.
1309*/
1310static void setminordebt (global_State *g) {
1311 luaE_setdebt(g, -(cast(l_mem, (gettotalbytes(g) / 100)) * g->genminormul));
1312}
1313
1314
1315/*
1289** Enter generational mode. Must go until the end of an atomic cycle 1316** Enter generational mode. Must go until the end of an atomic cycle
1290** to ensure that all objects are correctly marked and weak tables 1317** to ensure that all objects are correctly marked and weak tables
1291** are cleared. Then, turn all objects into old and finishes the 1318** are cleared. Then, turn all objects into old and finishes the
@@ -1297,6 +1324,7 @@ static lu_mem entergen (lua_State *L, global_State *g) {
1297 luaC_runtilstate(L, bitmask(GCSpropagate)); /* start new cycle */ 1324 luaC_runtilstate(L, bitmask(GCSpropagate)); /* start new cycle */
1298 numobjs = atomic(L); /* propagates all and then do the atomic stuff */ 1325 numobjs = atomic(L); /* propagates all and then do the atomic stuff */
1299 atomic2gen(L, g); 1326 atomic2gen(L, g);
1327 setminordebt(g); /* set debt assuming next cycle will be minor */
1300 return numobjs; 1328 return numobjs;
1301} 1329}
1302 1330
@@ -1343,15 +1371,6 @@ static lu_mem fullgen (lua_State *L, global_State *g) {
1343 1371
1344 1372
1345/* 1373/*
1346** Set debt for the next minor collection, which will happen when
1347** memory grows 'genminormul'%.
1348*/
1349static void setminordebt (global_State *g) {
1350 luaE_setdebt(g, -(cast(l_mem, (gettotalbytes(g) / 100)) * g->genminormul));
1351}
1352
1353
1354/*
1355** Does a major collection after last collection was a "bad collection". 1374** Does a major collection after last collection was a "bad collection".
1356** 1375**
1357** When the program is building a big structure, it allocates lots of 1376** When the program is building a big structure, it allocates lots of
@@ -1422,8 +1441,8 @@ static void genstep (lua_State *L, global_State *g) {
1422 lu_mem numobjs = fullgen(L, g); /* do a major collection */ 1441 lu_mem numobjs = fullgen(L, g); /* do a major collection */
1423 if (gettotalbytes(g) < majorbase + (majorinc / 2)) { 1442 if (gettotalbytes(g) < majorbase + (majorinc / 2)) {
1424 /* collected at least half of memory growth since last major 1443 /* collected at least half of memory growth since last major
1425 collection; keep doing minor collections */ 1444 collection; keep doing minor collections. */
1426 setminordebt(g); 1445 lua_assert(g->lastatomic == 0);
1427 } 1446 }
1428 else { /* bad collection */ 1447 else { /* bad collection */
1429 g->lastatomic = numobjs; /* signal that last collection was bad */ 1448 g->lastatomic = numobjs; /* signal that last collection was bad */
@@ -1450,26 +1469,6 @@ static void genstep (lua_State *L, global_State *g) {
1450 1469
1451 1470
1452/* 1471/*
1453** Set the "time" to wait before starting a new GC cycle; cycle will
1454** start when memory use hits the threshold of ('estimate' * pause /
1455** PAUSEADJ). (Division by 'estimate' should be OK: it cannot be zero,
1456** because Lua cannot even start with less than PAUSEADJ bytes).
1457*/
1458static void setpause (global_State *g) {
1459 l_mem threshold, debt;
1460 int pause = getgcparam(g->gcpause);
1461 l_mem estimate = g->GCestimate / PAUSEADJ; /* adjust 'estimate' */
1462 lua_assert(estimate > 0);
1463 threshold = (pause < MAX_LMEM / estimate) /* overflow? */
1464 ? estimate * pause /* no overflow */
1465 : MAX_LMEM; /* overflow; truncate to maximum */
1466 debt = gettotalbytes(g) - threshold;
1467 if (debt > 0) debt = 0;
1468 luaE_setdebt(g, debt);
1469}
1470
1471
1472/*
1473** Enter first sweep phase. 1472** Enter first sweep phase.
1474** The call to 'sweeptolive' makes the pointer point to an object 1473** The call to 'sweeptolive' makes the pointer point to an object
1475** inside the list (instead of to the header), so that the real sweep do 1474** inside the list (instead of to the header), so that the real sweep do
diff --git a/src/3rdParty/lua/loadlib.c b/src/3rdParty/lua/loadlib.c
index 6f9fa37..d792dff 100644
--- a/src/3rdParty/lua/loadlib.c
+++ b/src/3rdParty/lua/loadlib.c
@@ -708,8 +708,13 @@ static const luaL_Reg ll_funcs[] = {
708 708
709 709
710static void createsearcherstable (lua_State *L) { 710static void createsearcherstable (lua_State *L) {
711 static const lua_CFunction searchers[] = 711 static const lua_CFunction searchers[] = {
712 {searcher_preload, searcher_Lua, searcher_C, searcher_Croot, NULL}; 712 searcher_preload,
713 searcher_Lua,
714 searcher_C,
715 searcher_Croot,
716 NULL
717 };
713 int i; 718 int i;
714 /* create 'searchers' table */ 719 /* create 'searchers' table */
715 lua_createtable(L, sizeof(searchers)/sizeof(searchers[0]) - 1, 0); 720 lua_createtable(L, sizeof(searchers)/sizeof(searchers[0]) - 1, 0);
diff --git a/src/3rdParty/lua/lobject.c b/src/3rdParty/lua/lobject.c
index 301aa90..a2c0060 100644
--- a/src/3rdParty/lua/lobject.c
+++ b/src/3rdParty/lua/lobject.c
@@ -386,29 +386,39 @@ void luaO_tostring (lua_State *L, TValue *obj) {
386** =================================================================== 386** ===================================================================
387*/ 387*/
388 388
389/* size for buffer space used by 'luaO_pushvfstring' */ 389/*
390#define BUFVFS 200 390** Size for buffer space used by 'luaO_pushvfstring'. It should be
391** (LUA_IDSIZE + MAXNUMBER2STR) + a minimal space for basic messages,
392** so that 'luaG_addinfo' can work directly on the buffer.
393*/
394#define BUFVFS (LUA_IDSIZE + MAXNUMBER2STR + 95)
391 395
392/* buffer used by 'luaO_pushvfstring' */ 396/* buffer used by 'luaO_pushvfstring' */
393typedef struct BuffFS { 397typedef struct BuffFS {
394 lua_State *L; 398 lua_State *L;
395 int pushed; /* number of string pieces already on the stack */ 399 int pushed; /* true if there is a part of the result on the stack */
396 int blen; /* length of partial string in 'space' */ 400 int blen; /* length of partial string in 'space' */
397 char space[BUFVFS]; /* holds last part of the result */ 401 char space[BUFVFS]; /* holds last part of the result */
398} BuffFS; 402} BuffFS;
399 403
400 404
401/* 405/*
402** Push given string to the stack, as part of the buffer, and 406** Push given string to the stack, as part of the result, and
403** join the partial strings in the stack into one. 407** join it to previous partial result if there is one.
408** It may call 'luaV_concat' while using one slot from EXTRA_STACK.
409** This call cannot invoke metamethods, as both operands must be
410** strings. It can, however, raise an error if the result is too
411** long. In that case, 'luaV_concat' frees the extra slot before
412** raising the error.
404*/ 413*/
405static void pushstr (BuffFS *buff, const char *str, size_t l) { 414static void pushstr (BuffFS *buff, const char *str, size_t lstr) {
406 lua_State *L = buff->L; 415 lua_State *L = buff->L;
407 setsvalue2s(L, L->top, luaS_newlstr(L, str, l)); 416 setsvalue2s(L, L->top, luaS_newlstr(L, str, lstr));
408 L->top++; /* may use one extra slot */ 417 L->top++; /* may use one slot from EXTRA_STACK */
409 buff->pushed++; 418 if (!buff->pushed) /* no previous string on the stack? */
410 luaV_concat(L, buff->pushed); /* join partial results into one */ 419 buff->pushed = 1; /* now there is one */
411 buff->pushed = 1; 420 else /* join previous string with new one */
421 luaV_concat(L, 2);
412} 422}
413 423
414 424
@@ -454,7 +464,7 @@ static void addstr2buff (BuffFS *buff, const char *str, size_t slen) {
454 464
455 465
456/* 466/*
457** Add a number to the buffer. 467** Add a numeral to the buffer.
458*/ 468*/
459static void addnum2buff (BuffFS *buff, TValue *num) { 469static void addnum2buff (BuffFS *buff, TValue *num) {
460 char *numbuff = getbuff(buff, MAXNUMBER2STR); 470 char *numbuff = getbuff(buff, MAXNUMBER2STR);
diff --git a/src/3rdParty/lua/lobject.h b/src/3rdParty/lua/lobject.h
index 0e05b3e..77cc606 100644
--- a/src/3rdParty/lua/lobject.h
+++ b/src/3rdParty/lua/lobject.h
@@ -52,6 +52,8 @@ typedef union Value {
52 lua_CFunction f; /* light C functions */ 52 lua_CFunction f; /* light C functions */
53 lua_Integer i; /* integer numbers */ 53 lua_Integer i; /* integer numbers */
54 lua_Number n; /* float numbers */ 54 lua_Number n; /* float numbers */
55 /* not used, but may avoid warnings for uninitialized value */
56 lu_byte ub;
55} Value; 57} Value;
56 58
57 59
diff --git a/src/3rdParty/lua/lparser.c b/src/3rdParty/lua/lparser.c
index a5cd552..fe693b5 100644
--- a/src/3rdParty/lua/lparser.c
+++ b/src/3rdParty/lua/lparser.c
@@ -674,19 +674,19 @@ static void leaveblock (FuncState *fs) {
674 LexState *ls = fs->ls; 674 LexState *ls = fs->ls;
675 int hasclose = 0; 675 int hasclose = 0;
676 int stklevel = reglevel(fs, bl->nactvar); /* level outside the block */ 676 int stklevel = reglevel(fs, bl->nactvar); /* level outside the block */
677 if (bl->isloop) /* fix pending breaks? */ 677 removevars(fs, bl->nactvar); /* remove block locals */
678 lua_assert(bl->nactvar == fs->nactvar); /* back to level on entry */
679 if (bl->isloop) /* has to fix pending breaks? */
678 hasclose = createlabel(ls, luaS_newliteral(ls->L, "break"), 0, 0); 680 hasclose = createlabel(ls, luaS_newliteral(ls->L, "break"), 0, 0);
679 if (!hasclose && bl->previous && bl->upval) 681 if (!hasclose && bl->previous && bl->upval) /* still need a 'close'? */
680 luaK_codeABC(fs, OP_CLOSE, stklevel, 0, 0); 682 luaK_codeABC(fs, OP_CLOSE, stklevel, 0, 0);
681 fs->bl = bl->previous;
682 removevars(fs, bl->nactvar);
683 lua_assert(bl->nactvar == fs->nactvar);
684 fs->freereg = stklevel; /* free registers */ 683 fs->freereg = stklevel; /* free registers */
685 ls->dyd->label.n = bl->firstlabel; /* remove local labels */ 684 ls->dyd->label.n = bl->firstlabel; /* remove local labels */
686 if (bl->previous) /* inner block? */ 685 fs->bl = bl->previous; /* current block now is previous one */
687 movegotosout(fs, bl); /* update pending gotos to outer block */ 686 if (bl->previous) /* was it a nested block? */
687 movegotosout(fs, bl); /* update pending gotos to enclosing block */
688 else { 688 else {
689 if (bl->firstgoto < ls->dyd->gt.n) /* pending gotos in outer block? */ 689 if (bl->firstgoto < ls->dyd->gt.n) /* still pending gotos? */
690 undefgoto(ls, &ls->dyd->gt.arr[bl->firstgoto]); /* error */ 690 undefgoto(ls, &ls->dyd->gt.arr[bl->firstgoto]); /* error */
691 } 691 }
692} 692}
diff --git a/src/3rdParty/lua/lua.h b/src/3rdParty/lua/lua.h
index e661839..219784c 100644
--- a/src/3rdParty/lua/lua.h
+++ b/src/3rdParty/lua/lua.h
@@ -18,10 +18,10 @@
18 18
19#define LUA_VERSION_MAJOR "5" 19#define LUA_VERSION_MAJOR "5"
20#define LUA_VERSION_MINOR "4" 20#define LUA_VERSION_MINOR "4"
21#define LUA_VERSION_RELEASE "4" 21#define LUA_VERSION_RELEASE "5"
22 22
23#define LUA_VERSION_NUM 504 23#define LUA_VERSION_NUM 504
24#define LUA_VERSION_RELEASE_NUM (LUA_VERSION_NUM * 100 + 4) 24#define LUA_VERSION_RELEASE_NUM (LUA_VERSION_NUM * 100 + 5)
25 25
26#define LUA_VERSION "Lua " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR 26#define LUA_VERSION "Lua " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR
27#define LUA_RELEASE LUA_VERSION "." LUA_VERSION_RELEASE 27#define LUA_RELEASE LUA_VERSION "." LUA_VERSION_RELEASE
diff --git a/src/3rdParty/lua/luaconf.h b/src/3rdParty/lua/luaconf.h
index d42d14b..fcc0018 100644
--- a/src/3rdParty/lua/luaconf.h
+++ b/src/3rdParty/lua/luaconf.h
@@ -728,7 +728,7 @@
728** CHANGE it if you need a different limit. This limit is arbitrary; 728** CHANGE it if you need a different limit. This limit is arbitrary;
729** its only purpose is to stop Lua from consuming unlimited stack 729** its only purpose is to stop Lua from consuming unlimited stack
730** space (and to reserve some numbers for pseudo-indices). 730** space (and to reserve some numbers for pseudo-indices).
731** (It must fit into max(size_t)/32.) 731** (It must fit into max(size_t)/32 and max(int)/2.)
732*/ 732*/
733#if LUAI_IS32INT 733#if LUAI_IS32INT
734#define LUAI_MAXSTACK 1000000 734#define LUAI_MAXSTACK 1000000
diff --git a/src/3rdParty/lua/lvm.c b/src/3rdParty/lua/lvm.c
index f3a5662..614df05 100644
--- a/src/3rdParty/lua/lvm.c
+++ b/src/3rdParty/lua/lvm.c
@@ -643,7 +643,7 @@ void luaV_concat (lua_State *L, int total) {
643 int n = 2; /* number of elements handled in this pass (at least 2) */ 643 int n = 2; /* number of elements handled in this pass (at least 2) */
644 if (!(ttisstring(s2v(top - 2)) || cvt2str(s2v(top - 2))) || 644 if (!(ttisstring(s2v(top - 2)) || cvt2str(s2v(top - 2))) ||
645 !tostring(L, s2v(top - 1))) 645 !tostring(L, s2v(top - 1)))
646 luaT_tryconcatTM(L); 646 luaT_tryconcatTM(L); /* may invalidate 'top' */
647 else if (isemptystr(s2v(top - 1))) /* second operand is empty? */ 647 else if (isemptystr(s2v(top - 1))) /* second operand is empty? */
648 cast_void(tostring(L, s2v(top - 2))); /* result is first operand */ 648 cast_void(tostring(L, s2v(top - 2))); /* result is first operand */
649 else if (isemptystr(s2v(top - 2))) { /* first operand is empty string? */ 649 else if (isemptystr(s2v(top - 2))) { /* first operand is empty string? */
@@ -656,8 +656,10 @@ void luaV_concat (lua_State *L, int total) {
656 /* collect total length and number of strings */ 656 /* collect total length and number of strings */
657 for (n = 1; n < total && tostring(L, s2v(top - n - 1)); n++) { 657 for (n = 1; n < total && tostring(L, s2v(top - n - 1)); n++) {
658 size_t l = vslen(s2v(top - n - 1)); 658 size_t l = vslen(s2v(top - n - 1));
659 if (l_unlikely(l >= (MAX_SIZE/sizeof(char)) - tl)) 659 if (l_unlikely(l >= (MAX_SIZE/sizeof(char)) - tl)) {
660 L->top = top - total; /* pop strings to avoid wasting stack */
660 luaG_runerror(L, "string length overflow"); 661 luaG_runerror(L, "string length overflow");
662 }
661 tl += l; 663 tl += l;
662 } 664 }
663 if (tl <= LUAI_MAXSHORTLEN) { /* is result a short string? */ 665 if (tl <= LUAI_MAXSHORTLEN) { /* is result a short string? */
@@ -671,8 +673,8 @@ void luaV_concat (lua_State *L, int total) {
671 } 673 }
672 setsvalue2s(L, top - n, ts); /* create result */ 674 setsvalue2s(L, top - n, ts); /* create result */
673 } 675 }
674 total -= n-1; /* got 'n' strings to create 1 new */ 676 total -= n - 1; /* got 'n' strings to create one new */
675 L->top -= n-1; /* popped 'n' strings and pushed one */ 677 L->top -= n - 1; /* popped 'n' strings and pushed one */
676 } while (total > 1); /* repeat until only 1 result left */ 678 } while (total > 1); /* repeat until only 1 result left */
677} 679}
678 680
@@ -1177,7 +1179,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1177 printf("line: %d\n", luaG_getfuncline(cl->p, pcRel(pc, cl->p))); 1179 printf("line: %d\n", luaG_getfuncline(cl->p, pcRel(pc, cl->p)));
1178 #endif 1180 #endif
1179 lua_assert(base == ci->func + 1); 1181 lua_assert(base == ci->func + 1);
1180 lua_assert(base <= L->top && L->top < L->stack_last); 1182 lua_assert(base <= L->top && L->top <= L->stack_last);
1181 /* invalidate top for instructions not expecting it */ 1183 /* invalidate top for instructions not expecting it */
1182 lua_assert(isIT(i) || (cast_void(L->top = base), 1)); 1184 lua_assert(isIT(i) || (cast_void(L->top = base), 1));
1183 vmdispatch (GET_OPCODE(i)) { 1185 vmdispatch (GET_OPCODE(i)) {