diff -Nr lua-5.4.4/Makefile lua-5.4.5/Makefile 39c39 < PLATS= guess aix bsd c89 freebsd generic linux linux-readline macosx mingw posix solaris --- > PLATS= guess aix bsd c89 freebsd generic ios linux linux-readline macosx mingw posix solaris 49c49 < R= $V.4 --- > R= $V.5 diff -Nr lua-5.4.4/README lua-5.4.5/README 2c2 < This is Lua 5.4.4, released on 13 Jan 2022. --- > This is Lua 5.4.5, released on 18 Apr 2023. diff -Nr lua-5.4.4/doc/contents.html lua-5.4.5/doc/contents.html 35c35 < Copyright © 2020–2022 Lua.org, PUC-Rio. --- > Copyright © 2020–2023 Lua.org, PUC-Rio. 87a88,89 >
p
' or 'P
'.
---
> marked by a letter 'p
' or 'P
' and written in decimal.
> (For instance, 0x1.fp10
denotes 1984,
> which is 0x1f / 16 multiplied by 210.)
1624,1632c1626
< the list of variables.
< If there are more values than needed,
< the excess values are thrown away.
< If there are fewer values than needed,
< the list is extended with nil's.
< If the list of expressions ends with a function call,
< then all values returned by that call enter the list of values,
< before the adjustment
< (except when the call is enclosed in parentheses; see §3.4).
---
> the list of variables (see §3.4.12).
1638c1632
< Lua ensures all reads get the value of the variable
---
> Lua ensures that all reads get the value of the variable
1742,1746d1735
< Labels and empty statements are called void statements,
< as they perform no actions.
<
<
< 2062c2051 < directly inside a vararg function; --- > directly inside a variadic function; 2077,2122d2065 <
< Both function calls and vararg expressions can result in multiple values. < If a function call is used as a statement (see §3.3.6), < then its return list is adjusted to zero elements, < thus discarding all returned values. < If an expression is used as the last (or the only) element < of a list of expressions, < then no adjustment is made < (unless the expression is enclosed in parentheses). < In all other contexts, < Lua adjusts the result list to one element, < either discarding all values except the first one < or adding a single nil if there are no values. < < <
< Here are some examples: < <
< f() -- adjusted to 0 results < g(f(), x) -- f() is adjusted to 1 result < g(x, f()) -- g gets x plus all results from f() < a,b,c = f(), x -- f() is adjusted to 1 result (c gets nil) < a,b = ... -- a gets the first vararg argument, b gets < -- the second (both a and b can get nil if there < -- is no corresponding vararg argument) < < a,b,c = x, f() -- f() is adjusted to 2 results < a,b,c = f() -- f() is adjusted to 3 results < return f() -- returns all results from f() < return ... -- returns all received vararg arguments < return x,y,f() -- returns x, y, and all results from f() < {f()} -- creates a list with all results from f() < {...} -- creates a list with all vararg arguments < {f(), nil} -- f() is adjusted to 1 result << <
< Any expression enclosed in parentheses always results in only one value.
< Thus,
< (f(x,y,z))
is always a single value,
< even if f
returns several values.
< (The value of (f(x,y,z))
is the first value returned by f
< or nil if f
does not return any values.)
<
<
2255,2256c2198,2200
< Nonetheless, it is always a good practice not to rely on these
< implicit coercions, as they are not always applied;
---
> It is always a good practice not to rely on the
> implicit coercions from strings to numbers,
> as they are not always applied;
2561c2505
< and the expression is a function call or a vararg expression,
---
> and the expression is a multires expression,
2563c2507
< (see §3.4.10).
---
> (see §3.4.12).
2627c2571
< in a tail call,
---
> In a tail call,
2730,2731c2674,2675
< the length of its list of parameters,
< unless the function is a vararg function,
---
> the length of its list of parameters (see §3.4.12),
> unless the function is a variadic function,
2734c2678
< A vararg function does not adjust its argument list;
---
> A variadic function does not adjust its argument list;
2739,2745c2683
< similar to a function with multiple results.
< If a vararg expression is used inside another expression
< or in the middle of a list of expressions,
< then its return list is adjusted to one element.
< If the expression is used as the last element of a list of expressions,
< then no adjustment is made
< (unless that last expression is enclosed in parentheses).
---
> similar to a function with multiple results (see §3.4.12).
2805a2744,2859
>
> Both function calls and vararg expressions can result in multiple values. > These expressions are called multires expressions. > > >
> When a multires expression is used as the last element > of a list of expressions, > all results from the expression are added to the > list of values produced by the list of expressions. > Note that a single expression > in a place that expects a list of expressions > is the last expression in that (singleton) list. > > >
> These are the places where Lua expects a list of expressions: > >
return e1, e2, e3
(see §3.3.4).{e1, e2, e3}
(see §3.4.9).foo(e1, e2, e3)
(see §3.4.10).a , b, c = e1, e2, e3
(see §3.3.3).local a , b, c = e1, e2, e3
(see §3.3.7).for k in e1, e2, e3 do ... end
(see §3.3.5).> In the last four cases, > the list of values from the list of expressions > must be adjusted to a specific length: > the number of parameters in a call to a non-variadic function > (see §3.4.11), > the number of variables in a multiple assignment or > a local declaration, > and exactly four values for a generic for loop. > The adjustment follows these rules: > If there are more values than needed, > the extra values are thrown away; > if there are fewer values than needed, > the list is extended with nil's. > When the list of expressions ends with a multires expression, > all results from that expression enter the list of values > before the adjustment. > > >
> When a multires expression is used > in a list of expressions without being the last element, > or in a place where the syntax expects a single expression, > Lua adjusts the result list of that expression to one element. > As a particular case, > the syntax expects a single expression inside a parenthesized expression; > therefore, adding parentheses around a multires expression > forces it to produce exactly one result. > > >
> We seldom need to use a vararg expression in a place > where the syntax expects a single expression. > (Usually it is simpler to add a regular parameter before > the variadic part and use that parameter.) > When there is such a need, > we recommend assigning the vararg expression > to a single variable and using that variable > in its place. > > >
> Here are some examples of uses of mutlres expressions. > In all cases, when the construction needs > "the n-th result" and there is no such result, > it uses a nil. > >
> print(x, f()) -- prints x and all results from f(). > print(x, (f())) -- prints x and the first result from f(). > print(f(), x) -- prints the first result from f() and x. > print(1 + f()) -- prints 1 added to the first result from f(). > local x = ... -- x gets the first vararg argument. > x,y = ... -- x gets the first vararg argument, > -- y gets the second vararg argument. > x,y,z = w, f() -- x gets w, y gets the first result from f(), > -- z gets the second result from f(). > x,y,z = f() -- x gets the first result from f(), > -- y gets the second result from f(), > -- z gets the third result from f(). > x,y,z = f(), g() -- x gets the first result from f(), > -- y gets the first result from g(), > -- z gets the second result from g(). > x,y,z = (f()) -- x gets the first result from f(), y and z get nil. > return f() -- returns all results from f(). > return x, ... -- returns x and all received vararg arguments. > return x,y,f() -- returns x, y, and all results from f(). > {f()} -- creates a list with all results from f(). > {...} -- creates a list with all vararg arguments. > {f(), 5} -- creates a list with the first result from f() and 5. >> > > > 2815a2870 > (Void statements are labels and empty statements.) 3074c3129 < The API guarantees that any pointer to a string in a stack index --- > the API guarantees that any pointer to a string in a stack index 3540c3595 < Note that Standard C ensures --- > Note that ISO C ensures 3788,3789c3843 < (Exceptionally, this function was introduced in release 5.4.3. < It is not present in previous 5.4 releases.) --- > (This function was introduced in release 5.4.3.) 4545c4599 < then
lua_next
returns 0 and pushes nothing.
---
> then lua_next
returns 0 and pushes nothing.
4987a5042
> The value at index
must be a table.
5053a5109
> The value at index
must be a table.
5166c5222
< int lua_resetthread (lua_State *L);--- >
int lua_resetthread (lua_State *L, lua_State *from);5179a5236,5242 >
> The parameter from
represents the coroutine that is resetting L
.
> If there is no such coroutine,
> this parameter can be NULL
.
> (This parameter was introduced in release 5.4.5.)
>
>
6036c6099
< true if the function is a vararg function
---
> true if the function is a variadic function
6776c6839
< Removes n
bytes from the the buffer B
---
> Removes n
bytes from the buffer B
6971,6972c7034,7035
< It returns LUA_OK
if there are no errors,
< or an error code in case of errors (see §4.4.1).
---
> It returns 0 (LUA_OK
) if there are no errors,
> or 1 in case of errors.
6989,6990c7052,7053
< It returns LUA_OK
if there are no errors,
< or an error code in case of errors (see §4.4.1).
---
> It returns 0 (LUA_OK
) if there are no errors,
> or 1 in case of errors.
7297c7360
< allocator based on the standard C allocation functions
---
> allocator based on the ISO C allocation functions
7688,7690c7751
<
const char *luaL_typeerror (lua_State *L, < int arg, < const char *tname);--- >
int luaL_typeerror (lua_State *L, int arg, const char *tname);8710a8772,8773 > The real table is stored in the C registry (see §4.3), > indexed by the key
LUA_LOADED_TABLE
, a string.
8748c8811
< This function is not supported by Standard C.
---
> This functionality is not supported by ISO C.
8801a8865,8866
> The real table is stored in the C registry (see §4.3),
> indexed by the key LUA_PRELOAD_TABLE
, a string.
9314c9379
< Returns the size of a string resulting from string.pack
---
> Returns the length of a string resulting from string.pack
10094c10159
<
---
>
10096c10161
< but uses the signs of both arguments to find the
---
> using the signs of both arguments to find the
10956c11021
< closes the Lua state before exiting.
---
> the function closes the Lua state before exiting (see lua_close
).
11505a11571,11572
> -l g=mod
: "require" mod and assign the
> result to global g;-l g=mod
was introduced in release 5.4.4.)
>
>
>
11585c11656
< the script is compiled as a vararg function.
---
> the script is compiled as a variadic function.
11952c12023
< Thu Jan 13 11:33:16 UTC 2022
---
> Tue Apr 18 12:51:25 UTC 2023
11955c12026
< Last change: revised for Lua 5.4.4
---
> Last change: revised for Lua 5.4.5
diff -Nr lua-5.4.4/doc/readme.html lua-5.4.5/doc/readme.html
101,103d100
< Try also
< LuaDist,
< a multi-platform distribution of Lua that includes batteries.
113c110
< the top-level directory, which is named lua-5.4.4.
---
> the top-level directory, which is named lua-5.4.5.
124c121
< guess aix bsd c89 freebsd generic linux linux-readline macosx mingw posix solaris
---
> guess aix bsd c89 freebsd generic ios linux linux-readline macosx mingw posix solaris
306c303
< Copyright © 1994–2022 Lua.org, PUC-Rio.
---
> Copyright © 1994–2023 Lua.org, PUC-Rio.
333c330
< Mon Jan 3 09:54:18 UTC 2022
---
> Mon Mar 27 21:22:06 UTC 2023
336c333
< Last change: revised for Lua 5.4.4
---
> Last change: revised for Lua 5.4.5
diff -Nr lua-5.4.4/src/Makefile lua-5.4.5/src/Makefile
33c33
< PLATS= guess aix bsd c89 freebsd generic linux linux-readline macosx mingw posix solaris
---
> PLATS= guess aix bsd c89 freebsd generic ios linux linux-readline macosx mingw posix solaris
118a119,121
>
> ios:
> $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_IOS"
diff -Nr lua-5.4.4/src/lapi.c lua-5.4.5/src/lapi.c
63,65c63,65
< StkId o = ci->func + idx;
< api_check(L, idx <= L->ci->top - (ci->func + 1), "unacceptable index");
< if (o >= L->top) return &G(L)->nilvalue;
---
> StkId o = ci->func.p + idx;
> api_check(L, idx <= ci->top.p - (ci->func.p + 1), "unacceptable index");
> if (o >= L->top.p) return &G(L)->nilvalue;
69,70c69,71
< api_check(L, idx != 0 && -idx <= L->top - (ci->func + 1), "invalid index");
< return s2v(L->top + idx);
---
> api_check(L, idx != 0 && -idx <= L->top.p - (ci->func.p + 1),
> "invalid index");
> return s2v(L->top.p + idx);
77,78c78,79
< if (ttisCclosure(s2v(ci->func))) { /* C closure? */
< CClosure *func = clCvalue(s2v(ci->func));
---
> if (ttisCclosure(s2v(ci->func.p))) { /* C closure? */
> CClosure *func = clCvalue(s2v(ci->func.p));
83c84
< api_check(L, ttislcf(s2v(ci->func)), "caller not a C function");
---
> api_check(L, ttislcf(s2v(ci->func.p)), "caller not a C function");
97,98c98,99
< StkId o = ci->func + idx;
< api_check(L, o < L->top, "invalid index");
---
> StkId o = ci->func.p + idx;
> api_check(L, o < L->top.p, "invalid index");
102c103,104
< api_check(L, idx != 0 && -idx <= L->top - (ci->func + 1), "invalid index");
---
> api_check(L, idx != 0 && -idx <= L->top.p - (ci->func.p + 1),
> "invalid index");
104c106
< return L->top + idx;
---
> return L->top.p + idx;
115c117
< if (L->stack_last - L->top > n) /* stack large enough? */
---
> if (L->stack_last.p - L->top.p > n) /* stack large enough? */
117,125c119,122
< else { /* no; need to grow stack */
< int inuse = cast_int(L->top - L->stack) + EXTRA_STACK;
< if (inuse > LUAI_MAXSTACK - n) /* can grow without overflow? */
< res = 0; /* no */
< else /* try to grow stack */
< res = luaD_growstack(L, n, 0);
< }
< if (res && ci->top < L->top + n)
< ci->top = L->top + n; /* adjust frame top */
---
> else /* need to grow stack */
> res = luaD_growstack(L, n, 0);
> if (res && ci->top.p < L->top.p + n)
> ci->top.p = L->top.p + n; /* adjust frame top */
137,138c134,135
< api_check(from, to->ci->top - to->top >= n, "stack overflow");
< from->top -= n;
---
> api_check(from, to->ci->top.p - to->top.p >= n, "stack overflow");
> from->top.p -= n;
140,141c137,138
< setobjs2s(to, to->top, from->top + i);
< to->top++; /* stack already checked by previous 'api_check' */
---
> setobjs2s(to, to->top.p, from->top.p + i);
> to->top.p++; /* stack already checked by previous 'api_check' */
175c172
< : cast_int(L->top - L->ci->func) + idx;
---
> : cast_int(L->top.p - L->ci->func.p) + idx;
180c177
< return cast_int(L->top - (L->ci->func + 1));
---
> return cast_int(L->top.p - (L->ci->func.p + 1));
190c187
< func = ci->func;
---
> func = ci->func.p;
192,193c189,190
< api_check(L, idx <= ci->top - (func + 1), "new top too large");
< diff = ((func + 1) + idx) - L->top;
---
> api_check(L, idx <= ci->top.p - (func + 1), "new top too large");
> diff = ((func + 1) + idx) - L->top.p;
195c192
< setnilvalue(s2v(L->top++)); /* clear new slots */
---
> setnilvalue(s2v(L->top.p++)); /* clear new slots */
198c195
< api_check(L, -(idx+1) <= (L->top - (func + 1)), "invalid new top");
---
> api_check(L, -(idx+1) <= (L->top.p - (func + 1)), "invalid new top");
201,203c198,200
< api_check(L, L->tbclist < L->top, "previous pop of an unclosed slot");
< newtop = L->top + diff;
< if (diff < 0 && L->tbclist >= newtop) {
---
> api_check(L, L->tbclist.p < L->top.p, "previous pop of an unclosed slot");
> newtop = L->top.p + diff;
> if (diff < 0 && L->tbclist.p >= newtop) {
205c202
< luaF_close(L, newtop, CLOSEKTOP, 0);
---
> newtop = luaF_close(L, newtop, CLOSEKTOP, 0);
207c204
< L->top = newtop; /* correct top only after closing any upvalue */
---
> L->top.p = newtop; /* correct top only after closing any upvalue */
216c213
< api_check(L, hastocloseCfunc(L->ci->nresults) && L->tbclist == level,
---
> api_check(L, hastocloseCfunc(L->ci->nresults) && L->tbclist.p == level,
218,219c215
< luaF_close(L, level, CLOSEKTOP, 0);
< level = index2stack(L, idx); /* stack may be moved */
---
> level = luaF_close(L, level, CLOSEKTOP, 0);
248c244
< t = L->top - 1; /* end of stack segment being rotated */
---
> t = L->top.p - 1; /* end of stack segment being rotated */
267c263
< luaC_barrier(L, clCvalue(s2v(L->ci->func)), fr);
---
> luaC_barrier(L, clCvalue(s2v(L->ci->func.p)), fr);
276c272
< setobj2s(L, L->top, index2value(L, idx));
---
> setobj2s(L, L->top.p, index2value(L, idx));
345c341
< setobjs2s(L, L->top, L->top - 1);
---
> setobjs2s(L, L->top.p, L->top.p - 1);
349,350c345,346
< luaO_arith(L, op, s2v(L->top - 2), s2v(L->top - 1), L->top - 2);
< L->top--; /* remove second operand */
---
> luaO_arith(L, op, s2v(L->top.p - 2), s2v(L->top.p - 1), L->top.p - 2);
> L->top.p--; /* remove second operand */
376c372
< size_t sz = luaO_str2num(s, s2v(L->top));
---
> size_t sz = luaO_str2num(s, s2v(L->top.p));
503c499
< setnilvalue(s2v(L->top));
---
> setnilvalue(s2v(L->top.p));
511c507
< setfltvalue(s2v(L->top), n);
---
> setfltvalue(s2v(L->top.p), n);
519c515
< setivalue(s2v(L->top), n);
---
> setivalue(s2v(L->top.p), n);
534c530
< setsvalue2s(L, L->top, ts);
---
> setsvalue2s(L, L->top.p, ts);
545c541
< setnilvalue(s2v(L->top));
---
> setnilvalue(s2v(L->top.p));
549c545
< setsvalue2s(L, L->top, ts);
---
> setsvalue2s(L, L->top.p, ts);
586c582
< setfvalue(s2v(L->top), fn);
---
> setfvalue(s2v(L->top.p), fn);
595c591
< L->top -= n;
---
> L->top.p -= n;
597c593
< setobj2n(L, &cl->upvalue[n], s2v(L->top + n));
---
> setobj2n(L, &cl->upvalue[n], s2v(L->top.p + n));
601c597
< setclCvalue(L, s2v(L->top), cl);
---
> setclCvalue(L, s2v(L->top.p), cl);
612c608
< setbtvalue(s2v(L->top));
---
> setbtvalue(s2v(L->top.p));
614c610
< setbfvalue(s2v(L->top));
---
> setbfvalue(s2v(L->top.p));
622c618
< setpvalue(s2v(L->top), p);
---
> setpvalue(s2v(L->top.p), p);
630c626
< setthvalue(L, s2v(L->top), L);
---
> setthvalue(L, s2v(L->top.p), L);
647c643
< setobj2s(L, L->top, slot);
---
> setobj2s(L, L->top.p, slot);
651c647
< setsvalue2s(L, L->top, str);
---
> setsvalue2s(L, L->top.p, str);
653c649
< luaV_finishget(L, t, s2v(L->top - 1), L->top - 1, slot);
---
> luaV_finishget(L, t, s2v(L->top.p - 1), L->top.p - 1, slot);
656c652
< return ttype(s2v(L->top - 1));
---
> return ttype(s2v(L->top.p - 1));
683,684c679,680
< if (luaV_fastget(L, t, s2v(L->top - 1), slot, luaH_get)) {
< setobj2s(L, L->top - 1, slot);
---
> if (luaV_fastget(L, t, s2v(L->top.p - 1), slot, luaH_get)) {
> setobj2s(L, L->top.p - 1, slot);
687c683
< luaV_finishget(L, t, s2v(L->top - 1), L->top - 1, slot);
---
> luaV_finishget(L, t, s2v(L->top.p - 1), L->top.p - 1, slot);
689c685
< return ttype(s2v(L->top - 1));
---
> return ttype(s2v(L->top.p - 1));
705c701
< setobj2s(L, L->top, slot);
---
> setobj2s(L, L->top.p, slot);
710c706
< luaV_finishget(L, t, &aux, L->top, slot);
---
> luaV_finishget(L, t, &aux, L->top.p, slot);
714c710
< return ttype(s2v(L->top - 1));
---
> return ttype(s2v(L->top.p - 1));
720c716
< setnilvalue(s2v(L->top));
---
> setnilvalue(s2v(L->top.p));
722c718
< setobj2s(L, L->top, val);
---
> setobj2s(L, L->top.p, val);
725c721
< return ttype(s2v(L->top - 1));
---
> return ttype(s2v(L->top.p - 1));
742,743c738,739
< val = luaH_get(t, s2v(L->top - 1));
< L->top--; /* remove key */
---
> val = luaH_get(t, s2v(L->top.p - 1));
> L->top.p--; /* remove key */
770c766
< sethvalue2s(L, L->top, t);
---
> sethvalue2s(L, L->top.p, t);
797c793
< sethvalue2s(L, L->top, mt);
---
> sethvalue2s(L, L->top.p, mt);
813c809
< setnilvalue(s2v(L->top));
---
> setnilvalue(s2v(L->top.p));
817,818c813,814
< setobj2s(L, L->top, &uvalue(o)->uv[n - 1].uv);
< t = ttype(s2v(L->top));
---
> setobj2s(L, L->top.p, &uvalue(o)->uv[n - 1].uv);
> t = ttype(s2v(L->top.p));
838,839c834,835
< luaV_finishfastset(L, t, slot, s2v(L->top - 1));
< L->top--; /* pop value */
---
> luaV_finishfastset(L, t, slot, s2v(L->top.p - 1));
> L->top.p--; /* pop value */
842c838
< setsvalue2s(L, L->top, str); /* push 'str' (to make it a TValue) */
---
> setsvalue2s(L, L->top.p, str); /* push 'str' (to make it a TValue) */
844,845c840,841
< luaV_finishset(L, t, s2v(L->top - 1), s2v(L->top - 2), slot);
< L->top -= 2; /* pop value and key */
---
> luaV_finishset(L, t, s2v(L->top.p - 1), s2v(L->top.p - 2), slot);
> L->top.p -= 2; /* pop value and key */
865,866c861,862
< if (luaV_fastget(L, t, s2v(L->top - 2), slot, luaH_get)) {
< luaV_finishfastset(L, t, slot, s2v(L->top - 1));
---
> if (luaV_fastget(L, t, s2v(L->top.p - 2), slot, luaH_get)) {
> luaV_finishfastset(L, t, slot, s2v(L->top.p - 1));
869,870c865,866
< luaV_finishset(L, t, s2v(L->top - 2), s2v(L->top - 1), slot);
< L->top -= 2; /* pop index and value */
---
> luaV_finishset(L, t, s2v(L->top.p - 2), s2v(L->top.p - 1), slot);
> L->top.p -= 2; /* pop index and value */
888c884
< luaV_finishfastset(L, t, slot, s2v(L->top - 1));
---
> luaV_finishfastset(L, t, slot, s2v(L->top.p - 1));
893c889
< luaV_finishset(L, t, &aux, s2v(L->top - 1), slot);
---
> luaV_finishset(L, t, &aux, s2v(L->top.p - 1), slot);
895c891
< L->top--; /* pop value */
---
> L->top.p--; /* pop value */
905c901
< luaH_set(L, t, key, s2v(L->top - 1));
---
> luaH_set(L, t, key, s2v(L->top.p - 1));
907,908c903,904
< luaC_barrierback(L, obj2gco(t), s2v(L->top - 1));
< L->top -= n;
---
> luaC_barrierback(L, obj2gco(t), s2v(L->top.p - 1));
> L->top.p -= n;
914c910
< aux_rawset(L, idx, s2v(L->top - 2), 2);
---
> aux_rawset(L, idx, s2v(L->top.p - 2), 2);
930,932c926,928
< luaH_setint(L, t, n, s2v(L->top - 1));
< luaC_barrierback(L, obj2gco(t), s2v(L->top - 1));
< L->top--;
---
> luaH_setint(L, t, n, s2v(L->top.p - 1));
> luaC_barrierback(L, obj2gco(t), s2v(L->top.p - 1));
> L->top.p--;
943c939
< if (ttisnil(s2v(L->top - 1)))
---
> if (ttisnil(s2v(L->top.p - 1)))
946,947c942,943
< api_check(L, ttistable(s2v(L->top - 1)), "table expected");
< mt = hvalue(s2v(L->top - 1));
---
> api_check(L, ttistable(s2v(L->top.p - 1)), "table expected");
> mt = hvalue(s2v(L->top.p - 1));
971c967
< L->top--;
---
> L->top.p--;
987,988c983,984
< setobj(L, &uvalue(o)->uv[n - 1].uv, s2v(L->top - 1));
< luaC_barrierback(L, gcvalue(o), s2v(L->top - 1));
---
> setobj(L, &uvalue(o)->uv[n - 1].uv, s2v(L->top.p - 1));
> luaC_barrierback(L, gcvalue(o), s2v(L->top.p - 1));
991c987
< L->top--;
---
> L->top.p--;
1003c999,1000
< api_check(L, (nr) == LUA_MULTRET || (L->ci->top - L->top >= (nr) - (na)), \
---
> api_check(L, (nr) == LUA_MULTRET \
> || (L->ci->top.p - L->top.p >= (nr) - (na)), \
1016c1013
< func = L->top - (nargs+1);
---
> func = L->top.p - (nargs+1);
1064c1061
< c.func = L->top - (nargs+1); /* function to be called */
---
> c.func = L->top.p - (nargs+1); /* function to be called */
1099c1096
< LClosure *f = clLvalue(s2v(L->top - 1)); /* get newly created function */
---
> LClosure *f = clLvalue(s2v(L->top.p - 1)); /* get new function */
1104c1101
< setobj(L, f->upvals[0]->v, gt);
---
> setobj(L, f->upvals[0]->v.p, gt);
1118c1115
< o = s2v(L->top - 1);
---
> o = s2v(L->top.p - 1);
1244c1241
< errobj = s2v(L->top - 1);
---
> errobj = s2v(L->top.p - 1);
1262c1259
< more = luaH_next(L, t, L->top - 1);
---
> more = luaH_next(L, t, L->top.p - 1);
1267c1264
< L->top -= 1; /* remove key */
---
> L->top.p -= 1; /* remove key */
1279c1276
< api_check(L, L->tbclist < o, "given index below or equal a marked one");
---
> api_check(L, L->tbclist.p < o, "given index below or equal a marked one");
1294c1291
< setsvalue2s(L, L->top, luaS_newlstr(L, "", 0)); /* push empty string */
---
> setsvalue2s(L, L->top.p, luaS_newlstr(L, "", 0)); /* push empty string */
1306c1303
< luaV_objlen(L, L->top, t);
---
> luaV_objlen(L, L->top.p, t);
1351c1348
< setuvalue(L, s2v(L->top), u);
---
> setuvalue(L, s2v(L->top.p), u);
1377c1374
< *val = f->upvals[n-1]->v;
---
> *val = f->upvals[n-1]->v.p;
1393c1390
< setobj2s(L, L->top, val);
---
> setobj2s(L, L->top.p, val);
1411,1412c1408,1409
< L->top--;
< setobj(L, val, s2v(L->top));
---
> L->top.p--;
> setobj(L, val, s2v(L->top.p));
diff -Nr lua-5.4.4/src/lapi.h lua-5.4.5/src/lapi.h
15,17c15,18
< /* Increments 'L->top', checking for stack overflows */
< #define api_incr_top(L) {L->top++; api_check(L, L->top <= L->ci->top, \
< "stack overflow");}
---
> /* Increments 'L->top.p', checking for stack overflows */
> #define api_incr_top(L) {L->top.p++; \
> api_check(L, L->top.p <= L->ci->top.p, \
> "stack overflow");}
23c24
< ** increases its stack space ('L->ci->top').
---
> ** increases its stack space ('L->ci->top.p').
26c27,28
< { if ((nres) <= LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; }
---
> { if ((nres) <= LUA_MULTRET && L->ci->top.p < L->top.p) \
> L->ci->top.p = L->top.p; }
30,31c32,34
< #define api_checknelems(L,n) api_check(L, (n) < (L->top - L->ci->func), \
< "not enough elements in the stack")
---
> #define api_checknelems(L,n) \
> api_check(L, (n) < (L->top.p - L->ci->func.p), \
> "not enough elements in the stack")
diff -Nr lua-5.4.4/src/lauxlib.c lua-5.4.5/src/lauxlib.c
529c529,530
< ** bytes.
---
> ** bytes. (The test for "not big enough" also gets the case when the
> ** computation of 'newsize' overflows.)
532c533
< size_t newsize = B->size * 2; /* double buffer size */
---
> size_t newsize = (B->size / 2) * 3; /* buffer size * 1.5 */
535c536
< if (newsize < B->n + sz) /* double is not big enough? */
---
> if (newsize < B->n + sz) /* not big enough? */
614c615
< ** be) bellow the string being added to the buffer. (Box creation can
---
> ** be) below the string being added to the buffer. (Box creation can
742,752c743,754
< static int skipBOM (LoadF *lf) {
< const char *p = "\xEF\xBB\xBF"; /* UTF-8 BOM mark */
< int c;
< lf->n = 0;
< do {
< c = getc(lf->f);
< if (c == EOF || c != *(const unsigned char *)p++) return c;
< lf->buff[lf->n++] = c; /* to be read by the parser */
< } while (*p != '\0');
< lf->n = 0; /* prefix matched; discard it */
< return getc(lf->f); /* return next character */
---
> /*
> ** Skip an optional BOM at the start of a stream. If there is an
> ** incomplete BOM (the first character is correct but the rest is
> ** not), returns the first character anyway to force an error
> ** (as no chunk can start with 0xEF).
> */
> static int skipBOM (FILE *f) {
> int c = getc(f); /* read first character */
> if (c == 0xEF && getc(f) == 0xBB && getc(f) == 0xBF) /* correct BOM? */
> return getc(f); /* ignore BOM and return next char */
> else /* no (valid) BOM */
> return c; /* return first character */
763,764c765,766
< static int skipcomment (LoadF *lf, int *cp) {
< int c = *cp = skipBOM(lf);
---
> static int skipcomment (FILE *f, int *cp) {
> int c = *cp = skipBOM(f);
767c769
< c = getc(lf->f);
---
> c = getc(f);
769c771
< *cp = getc(lf->f); /* skip end-of-line, if present */
---
> *cp = getc(f); /* next character after comment, if present */
791,796c793,802
< if (skipcomment(&lf, &c)) /* read initial portion */
< lf.buff[lf.n++] = '\n'; /* add line to correct line numbers */
< if (c == LUA_SIGNATURE[0] && filename) { /* binary file? */
< lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */
< if (lf.f == NULL) return errfile(L, "reopen", fnameindex);
< skipcomment(&lf, &c); /* re-read initial portion */
---
> lf.n = 0;
> if (skipcomment(lf.f, &c)) /* read initial portion */
> lf.buff[lf.n++] = '\n'; /* add newline to correct line numbers */
> if (c == LUA_SIGNATURE[0]) { /* binary file? */
> lf.n = 0; /* remove possible newline */
> if (filename) { /* "real" file? */
> lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */
> if (lf.f == NULL) return errfile(L, "reopen", fnameindex);
> skipcomment(lf.f, &c); /* re-read initial portion */
> }
diff -Nr lua-5.4.4/src/lcode.c lua-5.4.5/src/lcode.c
1354a1355,1383
> ** Convert a BinOpr to an OpCode (ORDER OPR - ORDER OP)
> */
> l_sinline OpCode binopr2op (BinOpr opr, BinOpr baser, OpCode base) {
> lua_assert(baser <= opr &&
> ((baser == OPR_ADD && opr <= OPR_SHR) ||
> (baser == OPR_LT && opr <= OPR_LE)));
> return cast(OpCode, (cast_int(opr) - cast_int(baser)) + cast_int(base));
> }
>
>
> /*
> ** Convert a UnOpr to an OpCode (ORDER OPR - ORDER OP)
> */
> l_sinline OpCode unopr2op (UnOpr opr) {
> return cast(OpCode, (cast_int(opr) - cast_int(OPR_MINUS)) +
> cast_int(OP_UNM));
> }
>
>
> /*
> ** Convert a BinOpr to a tag method (ORDER OPR - ORDER TM)
> */
> l_sinline TMS binopr2TM (BinOpr opr) {
> lua_assert(OPR_ADD <= opr && opr <= OPR_SHR);
> return cast(TMS, (cast_int(opr) - cast_int(OPR_ADD)) + cast_int(TM_ADD));
> }
>
>
> /*
1392c1421
< static void codebinexpval (FuncState *fs, OpCode op,
---
> static void codebinexpval (FuncState *fs, BinOpr opr,
1394c1423,1427
< int v2 = luaK_exp2anyreg(fs, e2); /* both operands are in registers */
---
> OpCode op = binopr2op(opr, OPR_ADD, OP_ADD);
> int v2 = luaK_exp2anyreg(fs, e2); /* make sure 'e2' is in a register */
> /* 'e1' must be already in a register or it is a constant */
> lua_assert((VNIL <= e1->k && e1->k <= VKSTR) ||
> e1->k == VNONRELOC || e1->k == VRELOC);
1396,1397c1429
< finishbinexpval(fs, e1, e2, op, v2, 0, line, OP_MMBIN,
< cast(TMS, (op - OP_ADD) + TM_ADD));
---
> finishbinexpval(fs, e1, e2, op, v2, 0, line, OP_MMBIN, binopr2TM(opr));
1412a1445,1456
> /*
> ** Code binary operators with K operand.
> */
> static void codebinK (FuncState *fs, BinOpr opr,
> expdesc *e1, expdesc *e2, int flip, int line) {
> TMS event = binopr2TM(opr);
> int v2 = e2->u.info; /* K index */
> OpCode op = binopr2op(opr, OPR_ADD, OP_ADDK);
> finishbinexpval(fs, e1, e2, op, v2, flip, line, OP_MMBINK, event);
> }
>
>
1440a1485,1495
> ** Code binary operators with no constant operand.
> */
> static void codebinNoK (FuncState *fs, BinOpr opr,
> expdesc *e1, expdesc *e2, int flip, int line) {
> if (flip)
> swapexps(e1, e2); /* back to original order */
> codebinexpval(fs, opr, e1, e2, line); /* use standard operators */
> }
>
>
> /*
1446,1457c1501,1504
< TMS event = cast(TMS, opr + TM_ADD);
< if (tonumeral(e2, NULL) && luaK_exp2K(fs, e2)) { /* K operand? */
< int v2 = e2->u.info; /* K index */
< OpCode op = cast(OpCode, opr + OP_ADDK);
< finishbinexpval(fs, e1, e2, op, v2, flip, line, OP_MMBINK, event);
< }
< else { /* 'e2' is neither an immediate nor a K operand */
< OpCode op = cast(OpCode, opr + OP_ADD);
< if (flip)
< swapexps(e1, e2); /* back to original order */
< codebinexpval(fs, op, e1, e2, line); /* use standard operators */
< }
---
> if (tonumeral(e2, NULL) && luaK_exp2K(fs, e2)) /* K operand? */
> codebinK(fs, opr, e1, e2, flip, line);
> else /* 'e2' is neither an immediate nor a K operand */
> codebinNoK(fs, opr, e1, e2, flip, line);
1474c1521
< codebini(fs, cast(OpCode, OP_ADDI), e1, e2, flip, line, TM_ADD);
---
> codebini(fs, OP_ADDI, e1, e2, flip, line, TM_ADD);
1481c1528
< ** Code bitwise operations; they are all associative, so the function
---
> ** Code bitwise operations; they are all commutative, so the function
1487,1489c1534
< int v2;
< OpCode op;
< if (e1->k == VKINT && luaK_exp2RK(fs, e1)) {
---
> if (e1->k == VKINT) {
1493,1502c1538,1541
< else if (!(e2->k == VKINT && luaK_exp2RK(fs, e2))) { /* no constants? */
< op = cast(OpCode, opr + OP_ADD);
< codebinexpval(fs, op, e1, e2, line); /* all-register opcodes */
< return;
< }
< v2 = e2->u.info; /* index in K array */
< op = cast(OpCode, opr + OP_ADDK);
< lua_assert(ttisinteger(&fs->f->k[v2]));
< finishbinexpval(fs, e1, e2, op, v2, flip, line, OP_MMBINK,
< cast(TMS, opr + TM_ADD));
---
> if (e2->k == VKINT && luaK_exp2K(fs, e2)) /* K operand? */
> codebinK(fs, opr, e1, e2, flip, line);
> else /* no constants */
> codebinNoK(fs, opr, e1, e2, flip, line);
1510c1549
< static void codeorder (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2) {
---
> static void codeorder (FuncState *fs, BinOpr opr, expdesc *e1, expdesc *e2) {
1513a1553
> OpCode op;
1518c1558
< op = cast(OpCode, (op - OP_LT) + OP_LTI);
---
> op = binopr2op(opr, OPR_LT, OP_LTI);
1524c1564
< op = (op == OP_LT) ? OP_GTI : OP_GEI;
---
> op = binopr2op(opr, OPR_LT, OP_GTI);
1528a1569
> op = binopr2op(opr, OPR_LT, OP_LT);
1554c1595
< else if (luaK_exp2RK(fs, e2)) { /* 1st expression is constant? */
---
> else if (luaK_exp2RK(fs, e2)) { /* 2nd expression is constant? */
1571c1612
< void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e, int line) {
---
> void luaK_prefix (FuncState *fs, UnOpr opr, expdesc *e, int line) {
1574c1615
< switch (op) {
---
> switch (opr) {
1576c1617
< if (constfolding(fs, op + LUA_OPUNM, e, &ef))
---
> if (constfolding(fs, opr + LUA_OPUNM, e, &ef))
1580c1621
< codeunexpval(fs, cast(OpCode, op + OP_UNM), e, line);
---
> codeunexpval(fs, unopr2op(opr), e, line);
1614c1655,1656
< /* else keep numeral, which may be folded with 2nd operand */
---
> /* else keep numeral, which may be folded or used as an immediate
> operand */
1709c1751
< codebinexpval(fs, OP_SHL, e1, e2, line);
---
> codebinexpval(fs, opr, e1, e2, line);
1716c1758
< codebinexpval(fs, OP_SHR, e1, e2, line);
---
> codebinexpval(fs, opr, e1, e2, line);
1723,1727d1764
< case OPR_LT: case OPR_LE: {
< OpCode op = cast(OpCode, (opr - OPR_EQ) + OP_EQ);
< codeorder(fs, op, e1, e2);
< break;
< }
1730d1766
< OpCode op = cast(OpCode, (opr - OPR_NE) + OP_EQ);
1732c1768,1771
< codeorder(fs, op, e1, e2);
---
> opr = cast(BinOpr, (opr - OPR_GT) + OPR_LT);
> } /* FALLTHROUGH */
> case OPR_LT: case OPR_LE: {
> codeorder(fs, opr, e1, e2);
diff -Nr lua-5.4.4/src/lcorolib.c lua-5.4.5/src/lcorolib.c
79c79
< stat = lua_resetthread(co); /* close its tbc variables */
---
> stat = lua_resetthread(co, L); /* close its tbc variables */
175c175
< status = lua_resetthread(co);
---
> status = lua_resetthread(co, L);
diff -Nr lua-5.4.4/src/ldebug.c lua-5.4.5/src/ldebug.c
185c185
< if (clLvalue(s2v(ci->func))->p->is_vararg) {
---
> if (clLvalue(s2v(ci->func.p))->p->is_vararg) {
188c188
< *pos = ci->func - nextra - (n + 1);
---
> *pos = ci->func.p - nextra - (n + 1);
197c197
< StkId base = ci->func + 1;
---
> StkId base = ci->func.p + 1;
206c206
< StkId limit = (ci == L->ci) ? L->top : ci->next->func;
---
> StkId limit = (ci == L->ci) ? L->top.p : ci->next->func.p;
224c224
< if (!isLfunction(s2v(L->top - 1))) /* not a Lua function? */
---
> if (!isLfunction(s2v(L->top.p - 1))) /* not a Lua function? */
227c227
< name = luaF_getlocalname(clLvalue(s2v(L->top - 1))->p, n, 0);
---
> name = luaF_getlocalname(clLvalue(s2v(L->top.p - 1))->p, n, 0);
233c233
< setobjs2s(L, L->top, pos);
---
> setobjs2s(L, L->top.p, pos);
248,249c248,249
< setobjs2s(L, pos, L->top - 1);
< L->top--; /* pop value */
---
> setobjs2s(L, pos, L->top.p - 1);
> L->top.p--; /* pop value */
292c292
< setnilvalue(s2v(L->top));
---
> setnilvalue(s2v(L->top.p));
301c301
< sethvalue2s(L, L->top, t); /* push it on stack */
---
> sethvalue2s(L, L->top.p, t); /* push it on stack */
391c391
< func = s2v(L->top - 1);
---
> func = s2v(L->top.p - 1);
394c394
< L->top--; /* pop function */
---
> L->top.p--; /* pop function */
398c398
< func = s2v(ci->func);
---
> func = s2v(ci->func.p);
404c404
< setobj2s(L, L->top, func);
---
> setobj2s(L, L->top.p, func);
659,668c659,669
< ** Check whether pointer 'o' points to some value in the stack
< ** frame of the current function. Because 'o' may not point to a
< ** value in this stack, we cannot compare it with the region
< ** boundaries (undefined behaviour in ISO C).
< */
< static int isinstack (CallInfo *ci, const TValue *o) {
< StkId pos;
< for (pos = ci->func + 1; pos < ci->top; pos++) {
< if (o == s2v(pos))
< return 1;
---
> ** Check whether pointer 'o' points to some value in the stack frame of
> ** the current function and, if so, returns its index. Because 'o' may
> ** not point to a value in this stack, we cannot compare it with the
> ** region boundaries (undefined behavior in ISO C).
> */
> static int instack (CallInfo *ci, const TValue *o) {
> int pos;
> StkId base = ci->func.p + 1;
> for (pos = 0; base + pos < ci->top.p; pos++) {
> if (o == s2v(base + pos))
> return pos;
670c671
< return 0; /* not found */
---
> return -1; /* not found */
684c685
< if (c->upvals[i]->v == o) {
---
> if (c->upvals[i]->v.p == o) {
711,713c712,716
< if (!kind && isinstack(ci, o)) /* no? try a register */
< kind = getobjname(ci_func(ci)->p, currentpc(ci),
< cast_int(cast(StkId, o) - (ci->func + 1)), &name);
---
> if (!kind) { /* not an upvalue? */
> int reg = instack(ci, o); /* try a register */
> if (reg >= 0) /* is 'o' a register? */
> kind = getobjname(ci_func(ci)->p, currentpc(ci), reg, &name);
> }
810,813c813,816
< setobjs2s(L, L->top, L->top - 1); /* move argument */
< setobjs2s(L, L->top - 1, errfunc); /* push function */
< L->top++; /* assume EXTRA_STACK */
< luaD_callnoyield(L, L->top - 2, 1); /* call it */
---
> setobjs2s(L, L->top.p, L->top.p - 1); /* move argument */
> setobjs2s(L, L->top.p - 1, errfunc); /* push function */
> L->top.p++; /* assume EXTRA_STACK */
> luaD_callnoyield(L, L->top.p - 2, 1); /* call it */
827c830
< if (isLua(ci)) /* if Lua function, add source:line information */
---
> if (isLua(ci)) { /* if Lua function, add source:line information */
828a832,834
> setobjs2s(L, L->top.p - 2, L->top.p - 1); /* remove 'msg' */
> L->top.p--;
> }
845c851
< int delta = 0; /* line diference */
---
> int delta = 0; /* line difference */
872c878
< ** 'L->top' before calling anything that can run the GC.
---
> ** 'L->top.p' before calling anything that can run the GC.
895c901
< L->top = ci->top; /* correct top */
---
> L->top.p = ci->top.p; /* correct top */
diff -Nr lua-5.4.4/src/ldebug.h lua-5.4.5/src/ldebug.h
18c18
< #define ci_func(ci) (clLvalue(s2v((ci)->func)))
---
> #define ci_func(ci) (clLvalue(s2v((ci)->func.p)))
diff -Nr lua-5.4.4/src/ldo.c lua-5.4.5/src/ldo.c
107c107
< setobjs2s(L, oldtop, L->top - 1); /* error message on current top */
---
> setobjs2s(L, oldtop, L->top.p - 1); /* error message on current top */
111c111
< L->top = oldtop + 1;
---
> L->top.p = oldtop + 1;
124c124
< setobjs2s(L, g->mainthread->top++, L->top - 1); /* copy error obj. */
---
> setobjs2s(L, g->mainthread->top.p++, L->top.p - 1); /* copy error obj. */
160c160,182
< static void correctstack (lua_State *L, StkId oldstack, StkId newstack) {
---
>
>
> /*
> ** Change all pointers to the stack into offsets.
> */
> static void relstack (lua_State *L) {
> CallInfo *ci;
> UpVal *up;
> L->top.offset = savestack(L, L->top.p);
> L->tbclist.offset = savestack(L, L->tbclist.p);
> for (up = L->openupval; up != NULL; up = up->u.open.next)
> up->v.offset = savestack(L, uplevel(up));
> for (ci = L->ci; ci != NULL; ci = ci->previous) {
> ci->top.offset = savestack(L, ci->top.p);
> ci->func.offset = savestack(L, ci->func.p);
> }
> }
>
>
> /*
> ** Change back all offsets into pointers.
> */
> static void correctstack (lua_State *L) {
163,164c185,186
< L->top = (L->top - oldstack) + newstack;
< L->tbclist = (L->tbclist - oldstack) + newstack;
---
> L->top.p = restorestack(L, L->top.offset);
> L->tbclist.p = restorestack(L, L->tbclist.offset);
166c188
< up->v = s2v((uplevel(up) - oldstack) + newstack);
---
> up->v.p = s2v(restorestack(L, up->v.offset));
168,169c190,191
< ci->top = (ci->top - oldstack) + newstack;
< ci->func = (ci->func - oldstack) + newstack;
---
> ci->top.p = restorestack(L, ci->top.offset);
> ci->func.p = restorestack(L, ci->func.offset);
179d200
<
181,187c202,208
< ** Reallocate the stack to a new size, correcting all pointers into
< ** it. (There are pointers to a stack from its upvalues, from its list
< ** of call infos, plus a few individual pointers.) The reallocation is
< ** done in two steps (allocation + free) because the correction must be
< ** done while both addresses (the old stack and the new one) are valid.
< ** (In ISO C, any pointer use after the pointer has been deallocated is
< ** undefined behavior.)
---
> ** Reallocate the stack to a new size, correcting all pointers into it.
> ** In ISO C, any pointer use after the pointer has been deallocated is
> ** undefined behavior. So, before the reallocation, all pointers are
> ** changed to offsets, and after the reallocation they are changed back
> ** to pointers. As during the reallocation the pointers are invalid, the
> ** reallocation cannot run emergency collections.
> **
194,195c215,216
< StkId newstack = luaM_reallocvector(L, NULL, 0,
< newsize + EXTRA_STACK, StackValue);
---
> StkId newstack;
> int oldgcstop = G(L)->gcstopem;
196a218,222
> relstack(L); /* change pointers to offsets */
> G(L)->gcstopem = 1; /* stop emergency collection */
> newstack = luaM_reallocvector(L, L->stack.p, oldsize + EXTRA_STACK,
> newsize + EXTRA_STACK, StackValue);
> G(L)->gcstopem = oldgcstop; /* restore emergency collection */
197a224
> correctstack(L); /* change offsets back to pointers */
202,205c229,232
< /* number of elements to be copied to the new stack */
< i = ((oldsize <= newsize) ? oldsize : newsize) + EXTRA_STACK;
< memcpy(newstack, L->stack, i * sizeof(StackValue));
< for (; i < newsize + EXTRA_STACK; i++)
---
> L->stack.p = newstack;
> correctstack(L); /* change offsets back to pointers */
> L->stack_last.p = L->stack.p + newsize;
> for (i = oldsize + EXTRA_STACK; i < newsize + EXTRA_STACK; i++)
207,210d233
< correctstack(L, L->stack, newstack);
< luaM_freearray(L, L->stack, oldsize + EXTRA_STACK);
< L->stack = newstack;
< L->stack_last = L->stack + newsize;
216c239
< ** Try to grow the stack by at least 'n' elements. when 'raiseerror'
---
> ** Try to grow the stack by at least 'n' elements. When 'raiseerror'
230c253
< else {
---
> else if (n < LUAI_MAXSTACK) { /* avoids arithmetic overflows */
232c255
< int needed = cast_int(L->top - L->stack) + n;
---
> int needed = cast_int(L->top.p - L->stack.p) + n;
239,245d261
< else { /* stack overflow */
< /* add extra size to be able to handle the error message */
< luaD_reallocstack(L, ERRORSTACKSIZE, raiseerror);
< if (raiseerror)
< luaG_runerror(L, "stack overflow");
< return 0;
< }
246a263,268
> /* else stack overflow */
> /* add extra size to be able to handle the error message */
> luaD_reallocstack(L, ERRORSTACKSIZE, raiseerror);
> if (raiseerror)
> luaG_runerror(L, "stack overflow");
> return 0;
249a272,275
> /*
> ** Compute how much of the stack is being used, by computing the
> ** maximum top of all call frames in the stack and the current top.
> */
253c279
< StkId lim = L->top;
---
> StkId lim = L->top.p;
255c281
< if (lim < ci->top) lim = ci->top;
---
> if (lim < ci->top.p) lim = ci->top.p;
257,258c283,284
< lua_assert(lim <= L->stack_last);
< res = cast_int(lim - L->stack) + 1; /* part of stack in use */
---
> lua_assert(lim <= L->stack_last.p + EXTRA_STACK);
> res = cast_int(lim - L->stack.p) + 1; /* part of stack in use */
276,282c302
< int nsize = inuse * 2; /* proposed new size */
< int max = inuse * 3; /* maximum "reasonable" size */
< if (max > LUAI_MAXSTACK) {
< max = LUAI_MAXSTACK; /* respect stack limit */
< if (nsize > LUAI_MAXSTACK)
< nsize = LUAI_MAXSTACK;
< }
---
> int max = (inuse > LUAI_MAXSTACK / 3) ? LUAI_MAXSTACK : inuse * 3;
285c305,306
< if (inuse <= LUAI_MAXSTACK && stacksize(L) > max)
---
> if (inuse <= LUAI_MAXSTACK && stacksize(L) > max) {
> int nsize = (inuse > LUAI_MAXSTACK / 2) ? LUAI_MAXSTACK : inuse * 2;
286a308
> }
295c317
< L->top++;
---
> L->top.p++;
312,313c334,335
< ptrdiff_t top = savestack(L, L->top); /* preserve original 'top' */
< ptrdiff_t ci_top = savestack(L, ci->top); /* idem for 'ci->top' */
---
> ptrdiff_t top = savestack(L, L->top.p); /* preserve original 'top' */
> ptrdiff_t ci_top = savestack(L, ci->top.p); /* idem for 'ci->top' */
323,324c345,346
< if (isLua(ci) && L->top < ci->top)
< L->top = ci->top; /* protect entire activation register */
---
> if (isLua(ci) && L->top.p < ci->top.p)
> L->top.p = ci->top.p; /* protect entire activation register */
326,327c348,349
< if (ci->top < L->top + LUA_MINSTACK)
< ci->top = L->top + LUA_MINSTACK;
---
> if (ci->top.p < L->top.p + LUA_MINSTACK)
> ci->top.p = L->top.p + LUA_MINSTACK;
335,336c357,358
< ci->top = restorestack(L, ci_top);
< L->top = restorestack(L, top);
---
> ci->top.p = restorestack(L, ci_top);
> L->top.p = restorestack(L, top);
367c389
< StkId firstres = L->top - nres; /* index of first result */
---
> StkId firstres = L->top.p - nres; /* index of first result */
375,376c397,398
< ci->func += delta; /* if vararg, back to virtual 'func' */
< ftransfer = cast(unsigned short, firstres - ci->func);
---
> ci->func.p += delta; /* if vararg, back to virtual 'func' */
> ftransfer = cast(unsigned short, firstres - ci->func.p);
378c400
< ci->func -= delta;
---
> ci->func.p -= delta;
397c419
< for (p = L->top; p > func; p--) /* open space for metamethod */
---
> for (p = L->top.p; p > func; p--) /* open space for metamethod */
399c421
< L->top++; /* stack space pre-allocated by the caller */
---
> L->top.p++; /* stack space pre-allocated by the caller */
416c438
< L->top = res;
---
> L->top.p = res;
422,423c444,445
< setobjs2s(L, res, L->top - nres); /* move it to proper place */
< L->top = res + 1;
---
> setobjs2s(L, res, L->top.p - nres); /* move it to proper place */
> L->top.p = res + 1;
430d451
< ptrdiff_t savedres = savestack(L, res);
433c454
< luaF_close(L, res, CLOSEKTOP, 1);
---
> res = luaF_close(L, res, CLOSEKTOP, 1);
435c456,457
< if (L->hookmask) /* if needed, call hook after '__close's */
---
> if (L->hookmask) { /* if needed, call hook after '__close's */
> ptrdiff_t savedres = savestack(L, res);
437c459,460
< res = restorestack(L, savedres); /* close and hook can move stack */
---
> res = restorestack(L, savedres); /* hook can move stack */
> }
445c468
< firstresult = L->top - nres; /* index of first result */
---
> firstresult = L->top.p - nres; /* index of first result */
452c475
< L->top = res + wanted; /* top points after the last result */
---
> L->top.p = res + wanted; /* top points after the last result */
467c490
< moveresults(L, ci->func, nres, wanted);
---
> moveresults(L, ci->func.p, nres, wanted);
482c505
< ci->func = func;
---
> ci->func.p = func;
485c508
< ci->top = top;
---
> ci->top.p = top;
499,500c522,523
< L->top + LUA_MINSTACK);
< lua_assert(ci->top <= L->stack_last);
---
> L->top.p + LUA_MINSTACK);
> lua_assert(ci->top.p <= L->stack_last.p);
502c525
< int narg = cast_int(L->top - func) - 1;
---
> int narg = cast_int(L->top.p - func) - 1;
534c557
< ci->func -= delta; /* restore 'func' (if vararg) */
---
> ci->func.p -= delta; /* restore 'func' (if vararg) */
536,537c559,560
< setobjs2s(L, ci->func + i, func + i);
< func = ci->func; /* moved-down function */
---
> setobjs2s(L, ci->func.p + i, func + i);
> func = ci->func.p; /* moved-down function */
540,541c563,564
< ci->top = func + 1 + fsize; /* top for new function */
< lua_assert(ci->top <= L->stack_last);
---
> ci->top.p = func + 1 + fsize; /* top for new function */
> lua_assert(ci->top.p <= L->stack_last.p);
544c567
< L->top = func + narg1; /* set top */
---
> L->top.p = func + narg1; /* set top */
577c600
< int narg = cast_int(L->top - func) - 1; /* number of real arguments */
---
> int narg = cast_int(L->top.p - func) - 1; /* number of real arguments */
584,585c607,608
< setnilvalue(s2v(L->top++)); /* complete missing arguments */
< lua_assert(ci->top <= L->stack_last);
---
> setnilvalue(s2v(L->top.p++)); /* complete missing arguments */
> lua_assert(ci->top.p <= L->stack_last.p);
600a624,626
> ** This function can be called with some use of EXTRA_STACK, so it should
> ** check the stack before doing anything else. 'luaD_precall' already
> ** does that.
602c628
< l_sinline void ccall (lua_State *L, StkId func, int nResults, int inc) {
---
> l_sinline void ccall (lua_State *L, StkId func, int nResults, l_uint32 inc) {
605c631,632
< if (l_unlikely(getCcalls(L) >= LUAI_MAXCCALLS))
---
> if (l_unlikely(getCcalls(L) >= LUAI_MAXCCALLS)) {
> checkstackp(L, 0, func); /* free any use of EXTRA_STACK */
606a634
> }
654,655c682
< luaF_close(L, func, status, 1); /* can yield or raise an error */
< func = restorestack(L, ci->u2.funcidx); /* stack may be moved */
---
> func = luaF_close(L, func, status, 1); /* can yield or raise an error */
743,744c770,771
< L->top -= narg; /* remove args from the stack */
< setsvalue2s(L, L->top, luaS_new(L, msg)); /* push error message */
---
> L->top.p -= narg; /* remove args from the stack */
> setsvalue2s(L, L->top.p, luaS_new(L, msg)); /* push error message */
760c787
< StkId firstArg = L->top - n; /* first argument */
---
> StkId firstArg = L->top.p - n; /* first argument */
768c795
< L->top = firstArg; /* discard arguments */
---
> L->top.p = firstArg; /* discard arguments */
811c838
< else if (L->top - (L->ci->func + 1) == nargs) /* no function? */
---
> else if (L->top.p - (L->ci->func.p + 1) == nargs) /* no function? */
829,830c856,857
< luaD_seterrorobj(L, status, L->top); /* push error message */
< L->ci->top = L->top;
---
> luaD_seterrorobj(L, status, L->top.p); /* push error message */
> L->ci->top.p = L->top.p;
833c860
< : cast_int(L->top - (L->ci->func + 1));
---
> : cast_int(L->top.p - (L->ci->func.p + 1));
988c1015
< status = luaD_pcall(L, f_parser, &p, savestack(L, L->top), L->errfunc);
---
> status = luaD_pcall(L, f_parser, &p, savestack(L, L->top.p), L->errfunc);
diff -Nr lua-5.4.4/src/ldo.h lua-5.4.5/src/ldo.h
10a11
> #include "llimits.h"
26c27
< if (l_unlikely(L->stack_last - L->top <= (n))) \
---
> if (l_unlikely(L->stack_last.p - L->top.p <= (n))) \
35,36c36,37
< #define savestack(L,p) ((char *)(p) - (char *)L->stack)
< #define restorestack(L,n) ((StkId)((char *)L->stack + (n)))
---
> #define savestack(L,pt) (cast_charp(pt) - cast_charp(L->stack.p))
> #define restorestack(L,n) cast(StkId, cast_charp(L->stack.p) + (n))
39a41,47
> #define checkstackp(L,n,p) \
> luaD_checkstackaux(L, n, \
> ptrdiff_t t__ = savestack(L, p), /* save 'p' */ \
> p = restorestack(L, t__)) /* 'pos' part: restore 'p' */
>
>
> /* macro to check stack size and GC, preserving 'p' */
61c69,70
< LUAI_FUNC int luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func, int narg1, int delta);
---
> LUAI_FUNC int luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func,
> int narg1, int delta);
diff -Nr lua-5.4.4/src/ldump.c lua-5.4.5/src/ldump.c
12a13
> #include