diffs-lua-5.5.0-beta-rc1
README
2c2
< This is Lua 5.5.0 (beta), released on 28 Jun 2025.
> This is Lua 5.5.0, released on 14 Nov 2025.
doc/contents.html
88a89
> </UL>
151c152
< <A HREF="manual.html#6.1">basic</A><BR>
> <A HREF="manual.html#6.2">basic</A><BR>
180c181
< <A HREF="manual.html#6.2">coroutine</A><BR>
> <A HREF="manual.html#6.3">coroutine</A><BR>
191c192
< <A HREF="manual.html#6.10">debug</A><BR>
> <A HREF="manual.html#6.11">debug</A><BR>
210c211
< <A HREF="manual.html#6.8">io</A><BR>
> <A HREF="manual.html#6.9">io</A><BR>
238c239
< <A HREF="manual.html#6.7">math</A><BR>
> <A HREF="manual.html#6.8">math</A><BR>
248a250
> <A HREF="manual.html#pdf-math.frexp">math.frexp</A><BR>
249a252
> <A HREF="manual.html#pdf-math.ldexp">math.ldexp</A><BR>
268c271
< <A HREF="manual.html#6.9">os</A><BR>
> <A HREF="manual.html#6.10">os</A><BR>
282c285
< <A HREF="manual.html#6.3">package</A><BR>
> <A HREF="manual.html#6.4">package</A><BR>
293c296
< <A HREF="manual.html#6.4">string</A><BR>
> <A HREF="manual.html#6.5">string</A><BR>
313c316
< <A HREF="manual.html#6.6">table</A><BR>
> <A HREF="manual.html#6.7">table</A><BR>
314a318
> <A HREF="manual.html#pdf-table.create">table.create</A><BR>
323c327
< <A HREF="manual.html#6.5">utf8</A><BR>
> <A HREF="manual.html#6.6">utf8</A><BR>
530a535
> <A HREF="manual.html#luaL_alloc">luaL_alloc</A><BR>
672c677
< Tue Jun 24 10:26:21 UTC 2025
> Sat Nov 15 00:51:05 UTC 2025
doc/manual.html
193c193,194
< The length of any string in Lua must fit in a Lua integer.
> The length of any string in Lua must fit in a Lua integer,
> and the string plus a small header must fit in <code>size_t</code>.
317c318
< global Y -- voids implicit initial declaration
> global Y -- voids the implicit initial declaration
363c364
< and so the <code>x</code> in the left-hand side refers to the outside variable.
> and so the <code>x</code> on the right-hand side refers to the outside variable.
1898c1899,1900
< which is a new read-only variable local to the loop body (<em>block</em>).
> which is a new read-only (<code>const</code>) variable local to the loop body
> (<em>block</em>).
1966c1968
< which is a read-only variable.
> which is a read-only (<code>const</code>) variable.
2018c2020
< The declaration for locals can include an initialization:
> The declaration can include an initialization:
2022c2024
< stat ::= <b>global</b> attnamelist
> stat ::= <b>global</b> attnamelist [‘<b>=</b>’ explist]
2024c2026,2029
< If present, an initial assignment has the same semantics
> If there is no initialization,
> local variables are initialized with <b>nil</b>;
> global variables are left unchanged.
> Otherwise, the initialization gets the same adjustment
2026c2031,2034
< Otherwise, all local variables are initialized with <b>nil</b>.
> Moreover, for global variables,
> the initialization will raise a runtime error
> if the variable is already defined,
> that is, it has a non-nil value.
2087c2095,2096
< the effect of any declaration is only syntactical:
> the effect of any declaration is only syntactical
> (except for the optional assignment):
2750c2759
< The syntax for function definition is
> The syntax for a function definition is
2813c2822,2840
< global f; f = function () <em>body</em> end
> global f; global f = function () <em>body</em> end
> </pre><p>
> The second <b>global</b> makes the assignment an initialization,
> which will raise an error if that global is already defined.
>
>
> <p>
> The <em>colon</em> syntax
> is used to emulate <em>methods</em>,
> adding an implicit extra parameter <code>self</code> to the function.
> Thus, the statement
>
> <pre>
> function t.a.b.c:f (<em>params</em>) <em>body</em> end
> </pre><p>
> is syntactic sugar for
>
> <pre>
> t.a.b.c.f = function (self, <em>params</em>) <em>body</em> end
2828a2856,2872
> Results are returned using the <b>return</b> statement (see <a href="#3.3.4">§3.3.4</a>).
> If control reaches the end of a function
> without encountering a <b>return</b> statement,
> then the function returns with no results.
>
>
> <p>
>
> There is a system-dependent limit on the number of values
> that a function may return.
> This limit is guaranteed to be at least 1000.
>
>
>
> <h4>Parameters</h4>
>
> <p>
2833c2877,2878
< parlist ::= namelist [‘<b>,</b>’ ‘<b>...</b>’] | ‘<b>...</b>’
> parlist ::= namelist [‘<b>,</b>’ varargparam] | varargparam
> varargparam ::= ‘<b>...</b>’ [Name]
2843,2845c2888,2894
< to the function through a <em>vararg expression</em>,
< which is also written as three dots.
< The value of this expression is a list of all actual extra arguments,
> to the function through a <em>vararg expression</em> and,
> if present, a <em>vararg table</em>.
>
>
> <p>
> A vararg expression is also written as three dots,
> and its value is a list of all actual extra arguments,
2876,2879c2925,2935
< Results are returned using the <b>return</b> statement (see <a href="#3.3.4">§3.3.4</a>).
< If control reaches the end of a function
< without encountering a <b>return</b> statement,
< then the function returns with no results.
> The presence of a varag table in a variadic function is indicated
> by a name after the three dots.
> When present,
> a vararg table behaves like a read-only local variable
> with the given name that is initialized with a table.
> In that table,
> the values at indices 1, 2, etc. are the extra arguments,
> and the value at index "<code>n</code>" is the number of extra arguments.
> In other words, the code behaves as if the function started with
> the following statement,
> assuming the standard behavior of <a href="#pdf-table.pack"><code>table.pack</code></a>:
2880a2937,2939
> <pre>
> local <const> name = table.pack(...)
> </pre>
2882a2942,2946
> As an optimization,
> if the vararg table is used only as a base in indexing expressions
> (the <code>t</code> in <code>t[exp]</code> or <code>t.id</code>) and it is not an upvalue,
> the code does not create an actual table and instead translates
> the indexing expressions into accesses to the internal vararg data.
2884,2893d2947
< There is a system-dependent limit on the number of values
< that a function may return.
< This limit is guaranteed to be at least 1000.
<
<
< <p>
< The <em>colon</em> syntax
< is used to emulate <em>methods</em>,
< adding an implicit extra parameter <code>self</code> to the function.
< Thus, the statement
2895,2898d2948
< <pre>
< function t.a.b.c:f (<em>params</em>) <em>body</em> end
< </pre><p>
< is syntactic sugar for
2900,2902d2949
< <pre>
< t.a.b.c.f = function (self, <em>params</em>) <em>body</em> end
< </pre>
2942,2943c2989,2990
< <li>A local declaration,
< for instance <code>local a , b, c = e1, e2, e3</code> (see <a href="#3.3.7">§3.3.7</a>).</li>
> <li>A local or global declaration,
> which is similar to a multiple assignment.</li>
2954,2955c3001
< the number of variables in a multiple assignment or
< a local declaration,
> the number of variables in a multiple assignment or a declaration,
3425c3471,3480
< <li><b><a name="pdf-LUA_ERRERR"><code>LUA_ERRERR</code></a></b>: error while running the message handler.</li>
> <li><b><a name="pdf-LUA_ERRERR"><code>LUA_ERRERR</code></a></b>:
> stack overflow while running the message handler
> due to another stack overflow.
> More often than not,
> this error is the result of some other error while running
> a message handler.
> An error in a message handler will call the handler again,
> which will generate the error again, and so on,
> until this loop exhausts the stack and cause this error.
> </li>
3634c3689
< The type of the memory-allocation function used by Lua states.
> The type of the memory-allocator function used by Lua states.
3681,3682c3736,3738
< Here is a simple implementation for the allocator function.
< It is used in the auxiliary library by <a href="#luaL_newstate"><code>luaL_newstate</code></a>.
> Here is a simple implementation for the allocator function,
> corresponding to the function <a href="#luaL_alloc"><code>luaL_alloc</code></a> from the
> auxiliary library.
3685,3686c3741,3742
< static void *l_alloc (void *ud, void *ptr, size_t osize,
< size_t nsize) {
> void *luaL_alloc (void *ud, void *ptr, size_t osize,
> size_t nsize) {
4216c4272
< Returns the memory-allocation function of a given state.
> Returns the memory-allocator function of a given state.
4858,4859c4914,4915
< <pre>unsigned (lua_numbertocstring) (lua_State *L, int idx,
< char *buff);</pre>
> <pre>unsigned lua_numbertocstring (lua_State *L, int idx,
> char *buff);</pre>
5027c5083
< <pre>const char *(lua_pushexternalstring) (lua_State *L,
> <pre>const char *lua_pushexternalstring (lua_State *L,
5054,5060d5109
< Lua always internalizes strings with lengths up to 40 characters.
< So, for strings in that range,
< this function will immediately internalize the string
< and call <code>falloc</code> to free the buffer.
<
<
< <p>
5071c5120
< <span class="apii">[-0, +1, <em>m</em>]</span>
> <span class="apii">[-0, +1, <em>v</em>]</span>
5095a5145,5149
> <p>
> Besides memory allocation errors,
> this function may raise an error if the resulting string is too large.
>
>
5143c5197
< <span class="apii">[-0, +1, <em>m</em>]</span>
> <span class="apii">[-0, +1, <em>v</em>]</span>
5156c5210
< <span class="apii">[-0, +1, <em>m</em>]</span>
> <span class="apii">[-0, +1, <em>v</em>]</span>
5172a5227,5231
> <p>
> Besides memory allocation errors,
> this function may raise an error if the string is too large.
>
>
6320,6321c6379,6380
< <code>"global"</code>, <code>"local"</code>, <code>"method"</code>,
< <code>"field"</code>, <code>"upvalue"</code>, or <code>""</code> (the empty string),
> <code>"global"</code>, <code>"local"</code>, <code>"upvalue"</code>,
> <code>"field"</code>, <code>""</code> (the empty string), plus some other options,
7546,7548c7605,7606
< (It produces that value based on the current date and time
< and the address of an internal variable,
< in case the machine has Address Space Layout Randomization.)
> The parameter <code>L</code> can be <code>NULL</code>
> if there is no Lua state available.
7626,7627c7684,7686
< It calls <a href="#lua_newstate"><code>lua_newstate</code></a> with an
< allocator based on the ISO C allocation functions
> It calls <a href="#lua_newstate"><code>lua_newstate</code></a> with <a href="#luaL_alloc"><code>luaL_alloc</code></a> as
> the allocator function and the result of <code>luaL_makeseed(NULL)</code>
> as the seed,
7926a7986,7996
> <hr><h3><a name="luaL_alloc"><code>luaL_alloc</code></a></h3>
> <pre>void *luaL_alloc (void *ud, void *ptr, size_t osize, size_t nsize);</pre>
>
> <p>
> A standard allocator function for Lua (see <a href="#lua_Alloc"><code>lua_Alloc</code></a>),
> built on top of the C functions <code>realloc</code> and <code>free</code>.
>
>
>
>
>
8344c8414
< Lua rounds these values before storing them;
> Lua stores these values in a compressed format,
8362c8432,8433
< Opens the named file and executes its content as a Lua chunk.
> Opens the named file and executes its content as a Lua chunk,
> returning all values returned by the chunk.
8365d8435
< Returns all values returned by the chunk.
8563c8633
< calls it with <code>t</code> as argument and returns the first three
> calls it with <code>t</code> as argument and returns the first four
8569c8639
< returns three values: the <a href="#pdf-next"><code>next</code></a> function, the table <code>t</code>, and <b>nil</b>,
> returns the <a href="#pdf-next"><code>next</code></a> function, the table <code>t</code>, plus two <b>nil</b> values,
8865c8935
< otherwise ir returns <b>true</b>.
> otherwise it returns <b>true</b>.
10632a10703,10717
> <hr><h3><a name="pdf-math.frexp"><code>math.frexp (x)</code></a></h3>
>
>
> <p>
> Returns two numbers <code>m</code> and <code>e</code> such that <em>x = m2<sup>e</sup></em>,
> where <code>e</code> is an integer.
> When <code>x</code> is zero, NaN, +inf, or -inf,
> <code>m</code> is equal to <code>x</code>;
> otherwise, the absolute value of <code>m</code>
> is in the range <em>[0.5, 1)</em> .
>
>
>
>
> <p>
10643a10729,10738
> <hr><h3><a name="pdf-math.ldexp"><code>math.ldexp(m, e)</code></a></h3>
>
>
> <p>
> Returns <em>m2<sup>e</sup></em>, where <code>e</code> is an integer.
>
>
>
>
> <p>
10729c10824
< in the range <em>[0,1)</em>.
> in the range <em>[0, 1)</em>.
12363c12458,12460
< parlist ::= namelist [‘<b>,</b>’ ‘<b>...</b>’] | ‘<b>...</b>’
> parlist ::= namelist [‘<b>,</b>’ varargparam] | varargparam
>
> varargparam ::= ‘<b>...</b>’ [Name]
12391c12488
< Sat Jun 28 10:06:59 UTC 2025
> Sat Nov 15 00:41:28 UTC 2025
doc/readme.html
89,90c89,90
< Lua is implemented in pure ANSI C and compiles unmodified in all known
< platforms that have an ANSI C compiler.
> Lua is implemented in pure ISO C and compiles unmodified in all known
> platforms that have an ISO C compiler.
326c326
< Thu Jun 26 13:06:11 UTC 2025
> Tue Sep 2 21:25:09 UTC 2025
src/Makefile
130c130
< $(MAKE) "LUA_A=lua54.dll" "LUA_T=lua.exe" \
> $(MAKE) "LUA_A=lua55.dll" "LUA_T=lua.exe" \
src/lapi.c
443c443,449
< case LUA_VTABLE: return luaH_getn(hvalue(o));
> case LUA_VTABLE: {
> lua_Unsigned res;
> lua_lock(L);
> res = luaH_getn(L, hvalue(o));
> lua_unlock(L);
> return res;
> }
481c487
< ** Note that ANSI C does not allow the conversion of a pointer to
> ** Note that ISO C does not allow the conversion of a pointer to
682c688
< ** table, so that en mergency collection while using the global table
> ** table; so, an emergency collection while using the global table
src/lauxlib.c
745c745
< (void)L; /* not used */
> UNUSED(L);
859c859
< (void)L; /* not used */
> UNUSED(L);
1049,1050c1049,1050
< static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
< (void)ud; (void)osize; /* not used */
> void *luaL_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
> UNUSED(ud); UNUSED(osize);
1175c1175
< (void)L; /* unused */
> UNUSED(L);
1180,1181c1180,1185
< LUALIB_API lua_State *luaL_newstate (void) {
< lua_State *L = lua_newstate(l_alloc, NULL, luai_makeseed());
> /*
> ** Use the name with parentheses so that headers can redefine it
> ** as a macro.
> */
> LUALIB_API lua_State *(luaL_newstate) (void) {
> lua_State *L = lua_newstate(luaL_alloc, NULL, luaL_makeseed(NULL));
src/lauxlib.h
83a84,86
> LUALIB_API void *luaL_alloc (void *ud, void *ptr, size_t osize,
> size_t nsize);
>
src/lbaselib.c
282c282
< return 3;
> return 4; /* __pairs did all the work, just return its results */
288,290c288,291
< lua_pushcfunction(L, luaB_next); /* will return generator, */
< lua_pushvalue(L, 1); /* state, */
< lua_pushnil(L); /* and initial value */
> lua_pushcfunction(L, luaB_next); /* will return generator and */
> lua_pushvalue(L, 1); /* state */
> lua_pushnil(L); /* initial value */
> lua_pushnil(L); /* to-be-closed object */
294c295
< lua_callk(L, 1, 3, 0, pairscont); /* get 3 values from metamethod */
> lua_callk(L, 1, 4, 0, pairscont); /* get 4 values from metamethod */
296c297
< return 3;
> return 4;
src/lcode.c
47a48
> ls->linenumber = ls->lastline; /* back to line of last used token */
568d568
< int k;
570c570
< k = cast_int(ivalue(&val));
> int k = cast_int(ivalue(&val));
575,581c575,582
< /* constant not found; create a new entry */
< k = addk(fs, f, v);
< /* cache it for reuse; numerical value does not need GC barrier;
< table is not a metatable, so it does not need to invalidate cache */
< setivalue(&val, k);
< luaH_set(fs->ls->L, fs->kcache, key, &val);
< return k;
> else { /* constant not found; create a new entry */
> int k = addk(fs, f, v);
> /* cache it for reuse; numerical value does not need GC barrier;
> table is not a metatable, so it does not need to invalidate cache */
> setivalue(&val, k);
> luaH_set(fs->ls->L, fs->kcache, key, &val);
> return k;
> }
607c608
< ** with actual integers. To that, we add to the number its smaller
> ** with actual integers. To that end, we add to the number its smaller
609c610
< ** For doubles, that would be 1/2^52.
> ** (For doubles, the fraction would be 2^-52).
612,613c613,615
< ** floats larger than 2^53 the result is still an integer. At worst,
< ** this only wastes an entry with a duplicate.
> ** floats larger than 2^53 the result is still an integer. For those
> ** cases, just generate a new entry. At worst, this only wastes an entry
> ** with a duplicate.
628c630
< if (!luaV_flttointeger(k, &ik, F2Ieq)) { /* not an integral value? */
> if (!luaV_flttointeger(k, &ik, F2Ieq)) { /* not an integer value? */
707a710,725
> ** Get the value of 'var' in a register and generate an opcode to check
> ** whether that register is nil. 'k' is the index of the variable name
> ** in the list of constants. If its value cannot be encoded in Bx, a 0
> ** will use '?' for the name.
> */
> void luaK_codecheckglobal (FuncState *fs, expdesc *var, int k, int line) {
> luaK_exp2anyreg(fs, var);
> luaK_fixline(fs, line);
> k = (k >= MAXARG_Bx) ? 0 : k + 1;
> luaK_codeABx(fs, OP_ERRNNIL, var->u.info, k);
> luaK_fixline(fs, line);
> freeexp(fs, var);
> }
>
>
> /*
786a805,813
> /*
> ** Change a vararg parameter into a regular local variable
> */
> void luaK_vapar2local (FuncState *fs, expdesc *var) {
> fs->f->flag |= PF_VATAB; /* function will need a vararg table */
> /* now a vararg parameter is equivalent to a regular local variable */
> var->k = VLOCAL;
> }
>
797a825,827
> case VVARGVAR: {
> luaK_vapar2local(fs, e); /* turn it into a local variable */
> } /* FALLTHROUGH */
831a862,867
> case VVARGIND: {
> freeregs(fs, e->u.ind.t, e->u.ind.idx);
> e->u.info = luaK_codeABC(fs, OP_GETVARG, 0, e->u.ind.t, e->u.ind.idx);
> e->k = VRELOC;
> break;
> }
994,995c1030,1031
< ** Ensures final expression result is either in a register
< ** or in an upvalue.
> ** Ensures final expression result is either in a register,
> ** in an upvalue, or it is the vararg parameter.
998c1034
< if (e->k != VUPVAL || hasjumps(e))
> if ((e->k != VUPVAL && e->k != VVARGVAR) || hasjumps(e))
1092a1129,1132
> case VVARGIND: {
> fs->f->flag |= PF_VATAB; /* function will need a vararg table */
> /* now, assignment is to a regular table */
> } /* FALLTHROUGH */
1165c1205
< void luaK_goiffalse (FuncState *fs, expdesc *e) {
> static void luaK_goiffalse (FuncState *fs, expdesc *e) {
1226c1266
< return (e->k == VK && !hasjumps(e) && e->u.info <= MAXARG_B &&
> return (e->k == VK && !hasjumps(e) && e->u.info <= MAXINDEXRK &&
1303a1344,1350
> /* auxiliary function to define indexing expressions */
> static void fillidxk (expdesc *t, int idx, expkind k) {
> t->u.ind.idx = cast_byte(idx);
> t->k = k;
> }
>
>
1315c1362,1363
< (t->k == VLOCAL || t->k == VNONRELOC || t->k == VUPVAL));
> (t->k == VLOCAL || t->k == VVARGVAR ||
> t->k == VNONRELOC || t->k == VUPVAL));
1322,1323c1370,1375
< t->u.ind.idx = cast_short(k->u.info); /* literal short string */
< t->k = VINDEXUP;
> fillidxk(t, k->u.info, VINDEXUP); /* literal short string */
> }
> else if (t->k == VVARGVAR) { /* indexing the vararg parameter? */
> lua_assert(t->u.ind.t == fs->f->numparams);
> t->u.ind.t = cast_byte(t->u.var.ridx);
> fillidxk(t, luaK_exp2anyreg(fs, k), VVARGIND); /* register */
1328,1339c1380,1385
< if (isKstr(fs, k)) {
< t->u.ind.idx = cast_short(k->u.info); /* literal short string */
< t->k = VINDEXSTR;
< }
< else if (isCint(k)) { /* int. constant in proper range? */
< t->u.ind.idx = cast_short(k->u.ival);
< t->k = VINDEXI;
< }
< else {
< t->u.ind.idx = cast_short(luaK_exp2anyreg(fs, k)); /* register */
< t->k = VINDEXED;
< }
> if (isKstr(fs, k))
> fillidxk(t, k->u.info, VINDEXSTR); /* literal short string */
> else if (isCint(k)) /* int. constant in proper range? */
> fillidxk(t, cast_int(k->u.ival), VINDEXI);
> else
> fillidxk(t, luaK_exp2anyreg(fs, k), VINDEXED); /* register */
1903c1949,1954
< case OP_JMP: {
> case OP_GETVARG: {
> if (p->flag & PF_VATAB) /* function has a vararg table? */
> SET_OPCODE(*pc, OP_GETTABLE); /* must get vararg there */
> break;
> }
> case OP_JMP: { /* to optimize jumps to jumps */
1905c1956
< fixjump(fs, i, target);
> fixjump(fs, i, target); /* jump directly to final target */
src/lcode.h
70a71,72
> LUAI_FUNC void luaK_codecheckglobal (FuncState *fs, expdesc *var, int k,
> int line);
73a76
> LUAI_FUNC void luaK_vapar2local (FuncState *fs, expdesc *var);
82d84
< LUAI_FUNC void luaK_goiffalse (FuncState *fs, expdesc *e);
src/lctype.c
21c21
< /* consider all non-ascii codepoints to be alphabetic */
> /* consider all non-ASCII codepoints to be alphabetic */
src/ldebug.c
816a817,824
> l_noret luaG_errnnil (lua_State *L, LClosure *cl, int k) {
> const char *globalname = "?"; /* default name if k == 0 */
> if (k > 0)
> kname(cl->p, k - 1, &globalname);
> luaG_runerror(L, "global '%s' already defined", globalname);
> }
>
>
src/ldebug.h
55a56
> LUAI_FUNC l_noret luaG_errnnil (lua_State *L, LClosure *cl, int k);
src/ldo.c
59a60,67
> /* chained list of long jump buffers */
> typedef struct lua_longjmp {
> struct lua_longjmp *previous;
> jmp_buf b;
> volatile TStatus status; /* error code */
> } lua_longjmp;
>
>
63c71
< ** C++ code, with _longjmp/_setjmp when asked to use them, and with
> ** C++ code, with _longjmp/_setjmp when available (POSIX), and with
72,74c80,93
< #define LUAI_TRY(L,c,f,ud) \
< try { (f)(L, ud); } catch(...) { if ((c)->status == 0) (c)->status = -1; }
< #define luai_jmpbuf int /* dummy field */
>
> static void LUAI_TRY (lua_State *L, lua_longjmp *c, Pfunc f, void *ud) {
> try {
> f(L, ud); /* call function protected */
> }
> catch (lua_longjmp *c1) { /* Lua error */
> if (c1 != c) /* not the correct level? */
> throw; /* rethrow to upper level */
> }
> catch (...) { /* non-Lua exception */
> c->status = -1; /* create some error code */
> }
> }
>
78c97
< /* in POSIX, try _longjmp/_setjmp (more efficient) */
> /* in POSIX, use _longjmp/_setjmp (more efficient) */
81d99
< #define luai_jmpbuf jmp_buf
88d105
< #define luai_jmpbuf jmp_buf
95,103d111
<
< /* chain list of long jump buffers */
< struct lua_longjmp {
< struct lua_longjmp *previous;
< luai_jmpbuf b;
< volatile TStatus status; /* error code */
< };
<
<
154c162
< struct lua_longjmp lj;
> lua_longjmp lj;
176a185,198
> /*
> ** LUAI_MAXSTACK limits the size of the Lua stack.
> ** It must fit into INT_MAX/2.
> */
>
> #if !defined(LUAI_MAXSTACK)
> #if 1000000 < (INT_MAX / 2)
> #define LUAI_MAXSTACK 1000000
> #else
> #define LUAI_MAXSTACK (INT_MAX / 2u)
> #endif
> #endif
>
>
192c214
< /* raise an error while running the message handler */
> /* raise a stack error while running the message handler */
328c350
< luaD_errerr(L); /* error inside message handler */
> luaD_errerr(L); /* stack error inside message handler */
src/ldump.c
135,139c135,141
< ** Dump a String. First dump its "size": size==0 means NULL;
< ** size==1 is followed by an index and means "reuse saved string with
< ** that index"; size>=2 is followed by the string contents with real
< ** size==size-2 and means that string, which will be saved with
< ** the next available index.
> ** Dump a String. First dump its "size":
> ** size==0 is followed by an index and means "reuse saved string with
> ** that index"; index==0 means NULL.
> ** size>=1 is followed by the string contents with real size==size-1 and
> ** means that string, which will be saved with the next available index.
> ** The real size does not include the ending '\0' (which is not dumped),
> ** so adding 1 to it cannot overflow a size_t.
142,143c144,147
< if (ts == NULL)
< dumpSize(D, 0);
> if (ts == NULL) {
> dumpVarint(D, 0); /* will "reuse" NULL */
> dumpVarint(D, 0); /* special index for NULL */
> }
148c152
< dumpVarint(D, 1); /* reuse a saved string */
> dumpVarint(D, 0); /* reuse a saved string */
155c159
< dumpSize(D, size + 2);
> dumpSize(D, size + 1);
src/lfunc.c
199,200c199
< StkId upl; /* stack index pointed by 'uv' */
< while ((uv = L->openupval) != NULL && (upl = uplevel(uv)) >= level) {
> while ((uv = L->openupval) != NULL && uplevel(uv) >= level) {
src/lgc.c
597,598c597,598
< if (mode == NULL || !ttisshrstring(mode))
< return 0; /* ignore non-(short)string modes */
> if (mode == NULL || !ttisstring(mode))
> return 0; /* ignore non-string modes */
600c600
< const char *smode = getshrstr(tsvalue(mode));
> const char *smode = getstr(tsvalue(mode));
627c627
< return 1 + 2*sizenode(h) + h->asize;
> return cast(l_mem, 1 + 2*sizenode(h) + h->asize);
src/liolib.c
117c117
< #if defined(LUA_USE_POSIX) /* { */
> #if defined(LUA_USE_POSIX) || defined(LUA_USE_OFF_T) /* { */
src/ljumptab.h
24c24
< ** sed -n '/^OP_/\!d; s/OP_/\&\&L_OP_/ ; s/,.*/,/ ; s/\/.*// ; p' lopcodes.h
> ** sed -n '/^OP_/!d; s/OP_/\&\&L_OP_/ ; s/,.*/,/ ; s/\/.*// ; p' lopcodes.h
60d59
< &&L_OP_SHRI,
61a61
> &&L_OP_SHRI,
108a109,110
> &&L_OP_GETVARG,
> &&L_OP_ERRNNIL,
src/llimits.h
23,24c23,24
< ** computations.) Usually, 'ptrdiff_t' should work, but we use 'long'
< ** for 16-bit machines.
> ** computations.) 'lu_mem' is a corresponding unsigned type. Usually,
> ** 'ptrdiff_t' should work, but we use 'long' for 16-bit machines.
63,69d62
< ** floor of the log2 of the maximum signed value for integral type 't'.
< ** (That is, maximum 'n' such that '2^n' fits in the given signed type.)
< */
< #define log2maxs(t) (l_numbits(t) - 2)
<
<
< /*
288a282,330
>
>
> /*
> ** lua_numbertointeger converts a float number with an integral value
> ** to an integer, or returns 0 if the float is not within the range of
> ** a lua_Integer. (The range comparisons are tricky because of
> ** rounding. The tests here assume a two-complement representation,
> ** where MININTEGER always has an exact representation as a float;
> ** MAXINTEGER may not have one, and therefore its conversion to float
> ** may have an ill-defined value.)
> */
> #define lua_numbertointeger(n,p) \
> ((n) >= (LUA_NUMBER)(LUA_MININTEGER) && \
> (n) < -(LUA_NUMBER)(LUA_MININTEGER) && \
> (*(p) = (LUA_INTEGER)(n), 1))
>
>
>
> /*
> ** LUAI_FUNC is a mark for all extern functions that are not to be
> ** exported to outside modules.
> ** LUAI_DDEF and LUAI_DDEC are marks for all extern (const) variables,
> ** none of which to be exported to outside modules (LUAI_DDEF for
> ** definitions and LUAI_DDEC for declarations).
> ** Elf and MACH/gcc (versions 3.2 and later) mark them as "hidden" to
> ** optimize access when Lua is compiled as a shared library. Not all elf
> ** targets support this attribute. Unfortunately, gcc does not offer
> ** a way to check whether the target offers that support, and those
> ** without support give a warning about it. To avoid these warnings,
> ** change to the default definition.
> */
> #if !defined(LUAI_FUNC)
>
> #if defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \
> (defined(__ELF__) || defined(__MACH__))
> #define LUAI_FUNC __attribute__((visibility("internal"))) extern
> #else
> #define LUAI_FUNC extern
> #endif
>
> #define LUAI_DDEC(dec) LUAI_FUNC dec
> #define LUAI_DDEF /* empty */
>
> #endif
>
>
> /* Give these macros simpler names for internal use */
> #define l_likely(x) luai_likely(x)
> #define l_unlikely(x) luai_unlikely(x)
src/lmathlib.c
40a41
>
45a47
>
50a53
>
55a59
>
60a65
>
65a71
>
169a176
>
190a198
>
195a204
>
200a210
>
206a217,233
> static int math_frexp (lua_State *L) {
> lua_Number x = luaL_checknumber(L, 1);
> int ep;
> lua_pushnumber(L, l_mathop(frexp)(x, &ep));
> lua_pushinteger(L, ep);
> return 2;
> }
>
>
> static int math_ldexp (lua_State *L) {
> lua_Number x = luaL_checknumber(L, 1);
> int ep = (int)luaL_checkinteger(L, 2);
> lua_pushnumber(L, l_mathop(ldexp)(x, ep));
> return 1;
> }
>
>
254c281
< ** This code uses lots of shifts. ANSI C does not allow shifts greater
> ** This code uses lots of shifts. ISO C does not allow shifts greater
669,682d695
< static int math_frexp (lua_State *L) {
< int e;
< lua_pushnumber(L, l_mathop(frexp)(luaL_checknumber(L, 1), &e));
< lua_pushinteger(L, e);
< return 2;
< }
<
< static int math_ldexp (lua_State *L) {
< lua_Number x = luaL_checknumber(L, 1);
< int ep = (int)luaL_checkinteger(L, 2);
< lua_pushnumber(L, l_mathop(ldexp)(x, ep));
< return 1;
< }
<
704a718
> {"frexp", math_frexp},
705a720
> {"ldexp", math_ldexp},
721,722d735
< {"frexp", math_frexp},
< {"ldexp", math_ldexp},
src/loadlib.c
309a310,319
> ** External strings created by DLLs may need the DLL code to be
> ** deallocated. This implies that a DLL can only be unloaded after all
> ** its strings were deallocated. To ensure that, we create a 'library
> ** string' to represent each DLL, and when this string is deallocated
> ** it closes its corresponding DLL.
> ** (The string itself is irrelevant; its userdata is the DLL pointer.)
> */
>
>
> /*
323,324c333,334
< ** registry.CLIBS[path] = plib -- for queries
< ** registry.CLIBS[#CLIBS + 1] = plib -- also keep a list of all libraries
> ** Deallocate function for library strings.
> ** Unload the DLL associated with the string being deallocated.
326,332c336,340
< static void addtoclib (lua_State *L, const char *path, void *plib) {
< lua_getfield(L, LUA_REGISTRYINDEX, CLIBS);
< lua_pushlightuserdata(L, plib);
< lua_pushvalue(L, -1);
< lua_setfield(L, -3, path); /* CLIBS[path] = plib */
< lua_rawseti(L, -2, luaL_len(L, -2) + 1); /* CLIBS[#CLIBS + 1] = plib */
< lua_pop(L, 1); /* pop CLIBS table */
> static void *freelib (void *ud, void *ptr, size_t osize, size_t nsize) {
> /* string itself is irrelevant and static */
> (void)ptr; (void)osize; (void)nsize;
> lsys_unloadlib(ud); /* unload library represented by the string */
> return NULL;
337,338c345
< ** __gc tag method for CLIBS table: calls 'lsys_unloadlib' for all lib
< ** handles in list CLIBS
> ** Create a library string that, when deallocated, will unload 'plib'
340,347c347,350
< static int gctm (lua_State *L) {
< lua_Integer n = luaL_len(L, 1);
< for (; n >= 1; n--) { /* for each handle, in reverse order */
< lua_rawgeti(L, 1, n); /* get handle CLIBS[n] */
< lsys_unloadlib(lua_touserdata(L, -1));
< lua_pop(L, 1); /* pop handle */
< }
< return 0;
> static void createlibstr (lua_State *L, void *plib) {
> /* common content for all library strings */
> static const char dummy[] = "01234567890";
> lua_pushexternalstring(L, dummy, sizeof(dummy) - 1, freelib, plib);
350a354,367
> /*
> ** registry.CLIBS[path] = plib -- for queries.
> ** Also create a reference to strlib, so that the library string will
> ** only be collected when registry.CLIBS is collected.
> */
> static void addtoclib (lua_State *L, const char *path, void *plib) {
> lua_getfield(L, LUA_REGISTRYINDEX, CLIBS);
> lua_pushlightuserdata(L, plib);
> lua_setfield(L, -2, path); /* CLIBS[path] = plib */
> createlibstr(L, plib);
> luaL_ref(L, -2); /* keep library string in CLIBS */
> lua_pop(L, 1); /* pop CLIBS table */
> }
>
364,365c381,382
< ** Return 0 and 'true' or a function in the stack; in case of
< ** errors, return an error code and an error message in the stack.
> ** Return 0 with 'true' or a function in the stack; in case of
> ** errors, return an error code with an error message in the stack.
707,719d723
< /*
< ** create table CLIBS to keep track of loaded C libraries,
< ** setting a finalizer to close all libraries when closing state.
< */
< static void createclibstable (lua_State *L) {
< luaL_getsubtable(L, LUA_REGISTRYINDEX, CLIBS); /* create CLIBS table */
< lua_createtable(L, 0, 1); /* create metatable for CLIBS */
< lua_pushcfunction(L, gctm);
< lua_setfield(L, -2, "__gc"); /* set finalizer for CLIBS table */
< lua_setmetatable(L, -2);
< }
<
<
721c725,726
< createclibstable(L);
> luaL_getsubtable(L, LUA_REGISTRYINDEX, CLIBS); /* create CLIBS table */
> lua_pop(L, 1); /* will not use it now */
src/lobject.c
34c34,35
< ** Computes ceil(log2(x))
> ** Computes ceil(log2(x)), which is the smallest integer n such that
> ** x <= (1 << n).
89c90
< unsigned int m = p & 0xF; /* mantissa */
> int m = p & 0xF; /* mantissa */
388c389
< if (x < 0x80) /* ascii? */
> if (x < 0x80) /* ASCII? */
src/lobject.h
420a421
> #define isextstr(ts) (ttislngstring(ts) && tsvalue(ts)->shrlen != LSTRREG)
585,586c586,589
< #define PF_ISVARARG 1
< #define PF_FIXED 2 /* prototype has parts in fixed memory */
> #define PF_ISVARARG 1 /* function is vararg */
> #define PF_VAVAR 2 /* function has vararg parameter */
> #define PF_VATAB 4 /* function has vararg table */
> #define PF_FIXED 8 /* prototype has parts in fixed memory */
src/lopcodes.c
56d55
< ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SHRI */
57a57
> ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SHRI */
104a105,106
> ,opmode(0, 0, 0, 0, 1, iABC) /* OP_GETVARG */
> ,opmode(0, 0, 0, 0, 0, iABx) /* OP_ERRNNIL */
src/lopcodes.h
275d274
< OP_SHRI,/* A B sC R[A] := R[B] >> sC */
276a276
> OP_SHRI,/* A B sC R[A] := R[B] >> sC */
341c341,345
< OP_VARARGPREP,/*A (adjust vararg parameters) */
> OP_GETVARG, /* A B C R[A] := R[B][R[C]], R[B] is vararg parameter */
>
> OP_ERRNNIL,/* A Bx raise error if R[A] ~= nil (K[Bx] is global name)*/
>
> OP_VARARGPREP,/* (adjust vararg parameters) */
src/lopnames.h
48d47
< "SHRI",
49a49
> "SHRI",
96a97,98
> "GETVARG",
> "ERRNNIL",
src/loslib.c
37c37
< #elif defined(LUA_USE_C89) /* ANSI C 89 (only 1-char options) */
> #elif defined(LUA_USE_C89) /* C89 (only 1-char options) */
src/lparser.c
33c33
< /* maximum number of variable declarationss per function (must be
> /* maximum number of variable declarations per function (must be
200c200
< dyd->actvar.size, Vardesc, SHRT_MAX, "variable declarationss");
> dyd->actvar.size, Vardesc, SHRT_MAX, "variable declarations");
282c282,284
< ** Raises an error if variable described by 'e' is read only
> ** Raises an error if variable described by 'e' is read only; moreover,
> ** if 'e' is t[exp] where t is the vararg parameter, change it to index
> ** a real table. (Virtual vararg tables cannot be changed.)
292c294
< case VLOCAL: {
> case VLOCAL: case VVARGVAR: {
303a306,309
> case VVARGIND: {
> fs->f->flag |= PF_VATAB; /* function will need a vararg table */
> e->k = VINDEXED;
> } /* FALLTHROUGH */
429c435
< else /* local variable */
> else { /* local variable */
430a437,439
> if (vd->vd.kind == RDKVAVAR) /* vararg parameter? */
> var->k = VVARGVAR;
> }
470,471c479,485
< if (v == VLOCAL && !base)
< markupval(fs, var->u.var.vidx); /* local will be used as an upval */
> if (!base) {
> if (var->k == VVARGVAR) /* vararg parameter? */
> luaK_vapar2local(fs, var); /* change it to a regular local */
> if (var->k == VLOCAL)
> markupval(fs, var->u.var.vidx); /* will be used as an upvalue */
> }
> /* else nothing else to be done */
487a502,515
> static void buildglobal (LexState *ls, TString *varname, expdesc *var) {
> FuncState *fs = ls->fs;
> expdesc key;
> init_exp(var, VGLOBAL, -1); /* global by default */
> singlevaraux(fs, ls->envn, var, 1); /* get environment variable */
> if (var->k == VGLOBAL)
> luaK_semerror(ls, "_ENV is global when accessing variable '%s'",
> getstr(varname));
> luaK_exp2anyregup(fs, var); /* _ENV could be a constant */
> codestring(&key, varname); /* key is variable name */
> luaK_indexed(fs, var, &key); /* 'var' represents _ENV[varname] */
> }
>
>
497d524
< expdesc key;
502,508c529
< singlevaraux(fs, ls->envn, var, 1); /* get environment variable */
< if (var->k == VGLOBAL)
< luaK_semerror(ls, "_ENV is global when accessing variable '%s'",
< getstr(varname));
< luaK_exp2anyregup(fs, var); /* but could be a constant */
< codestring(&key, varname); /* key is variable name */
< luaK_indexed(fs, var, &key); /* env[varname] */
> buildglobal(ls, varname, var);
528a550
> luaK_checkstack(fs, needed);
668c690
< ** Traverse the pending goto's of the finishing block checking whether
> ** Traverse the pending gotos of the finishing block checking whether
900a923,935
> /*
> ** Maximum number of elements in a constructor, to control the following:
> ** * counter overflows;
> ** * overflows in 'extra' for OP_NEWTABLE and OP_SETLIST;
> ** * overflows when adding multiple returns in OP_SETLIST.
> */
> #define MAX_CNST (INT_MAX/2)
> #if MAX_CNST/(MAXARG_vC + 1) > MAXARG_Ax
> #undef MAX_CNST
> #define MAX_CNST (MAXARG_Ax * (MAXARG_vC + 1))
> #endif
>
>
921c956
< if (cc->v.k == VVOID) return; /* there is no list item */
> lua_assert(cc->tostore > 0);
1009d1043
< lua_assert(cc.v.k == VVOID || cc.tostore > 0);
1011c1045,1046
< closelistfield(fs, &cc);
> if (cc.v.k != VVOID) /* is there a previous list item? */
> closelistfield(fs, &cc); /* close it */
1012a1048,1049
> luaY_checklimit(fs, cc.tostore + cc.na + cc.nh, MAX_CNST,
> "items in a constructor");
1022,1024c1059,1062
< static void setvararg (FuncState *fs, int nparams) {
< fs->f->flag |= PF_ISVARARG;
< luaK_codeABC(fs, OP_VARARGPREP, nparams, 0, 0);
> static void setvararg (FuncState *fs, int kind) {
> lua_assert(kind & PF_ISVARARG);
> fs->f->flag |= cast_byte(kind);
> luaK_codeABC(fs, OP_VARARGPREP, 0, 0, 0);
1033c1071
< int isvararg = 0;
> int varargk = 0;
1043,1044c1081,1086
< luaX_next(ls);
< isvararg = 1;
> varargk |= PF_ISVARARG;
> luaX_next(ls); /* skip '...' */
> if (ls->t.token == TK_NAME) {
> new_varkind(ls, str_checkname(ls), RDKVAVAR);
> varargk |= PF_VAVAR;
> }
1049c1091
< } while (!isvararg && testnext(ls, ','));
> } while (!varargk && testnext(ls, ','));
1053,1055c1095,1101
< if (isvararg)
< setvararg(fs, f->numparams); /* declared vararg */
< luaK_reserveregs(fs, fs->nactvar); /* reserve registers for parameters */
> if (varargk != 0) {
> setvararg(fs, varargk); /* declared vararg */
> if (varargk & PF_VAVAR)
> adjustlocalvars(ls, 1); /* vararg parameter */
> }
> /* reserve registers for parameters (plus vararg parameter, if present) */
> luaK_reserveregs(fs, fs->nactvar);
1437a1484,1492
>
> /* Create code to store the "top" register in 'var' */
> static void storevartop (FuncState *fs, expdesc *var) {
> expdesc e;
> init_exp(&e, VNONRELOC, fs->freereg - 1);
> luaK_storevar(fs, var, &e); /* will also free the top register */
> }
>
>
1471,1472c1526
< init_exp(&e, VNONRELOC, ls->fs->freereg-1); /* default assignment */
< luaK_storevar(ls->fs, &lh->v, &e);
> storevartop(ls->fs, &lh->v); /* default assignment */
1815c1869
< break; /* to avoid warnings */
> return kind; /* to avoid warnings */
1823a1878,1932
> static void checkglobal (LexState *ls, TString *varname, int line) {
> FuncState *fs = ls->fs;
> expdesc var;
> int k;
> buildglobal(ls, varname, &var); /* create global variable in 'var' */
> k = var.u.ind.keystr; /* index of global name in 'k' */
> luaK_codecheckglobal(fs, &var, k, line);
> }
>
>
> /*
> ** Recursively traverse list of globals to be initalized. When
> ** going, generate table description for the global. In the end,
> ** after all indices have been generated, read list of initializing
> ** expressions. When returning, generate the assignment of the value on
> ** the stack to the corresponding table description. 'n' is the variable
> ** being handled, range [0, nvars - 1].
> */
> static void initglobal (LexState *ls, int nvars, int firstidx, int n,
> int line) {
> if (n == nvars) { /* traversed all variables? */
> expdesc e;
> int nexps = explist(ls, &e); /* read list of expressions */
> adjust_assign(ls, nvars, nexps, &e);
> }
> else { /* handle variable 'n' */
> FuncState *fs = ls->fs;
> expdesc var;
> TString *varname = getlocalvardesc(fs, firstidx + n)->vd.name;
> buildglobal(ls, varname, &var); /* create global variable in 'var' */
> enterlevel(ls); /* control recursion depth */
> initglobal(ls, nvars, firstidx, n + 1, line);
> leavelevel(ls);
> checkglobal(ls, varname, line);
> storevartop(fs, &var);
> }
> }
>
>
> static void globalnames (LexState *ls, lu_byte defkind) {
> FuncState *fs = ls->fs;
> int nvars = 0;
> int lastidx; /* index of last registered variable */
> do { /* for each name */
> TString *vname = str_checkname(ls);
> lu_byte kind = getglobalattribute(ls, defkind);
> lastidx = new_varkind(ls, vname, kind);
> nvars++;
> } while (testnext(ls, ','));
> if (testnext(ls, '=')) /* initialization? */
> initglobal(ls, nvars, lastidx - nvars + 1, 0, ls->linenumber);
> fs->nactvar = cast_short(fs->nactvar + nvars); /* activate declaration */
> }
>
>
1830c1939,1941
< if (testnext(ls, '*')) {
> if (!testnext(ls, '*'))
> globalnames(ls, defkind);
> else {
1835,1842d1945
< else {
< do { /* list of names */
< TString *vname = str_checkname(ls);
< lu_byte kind = getglobalattribute(ls, defkind);
< new_varkind(ls, vname, kind);
< fs->nactvar++; /* activate declaration */
< } while (testnext(ls, ','));
< }
1853c1956
< buildvar(ls, fname, &var);
> buildglobal(ls, fname, &var);
1854a1958
> checkglobal(ls, fname, line);
2052c2156
< setvararg(fs, 0); /* main function is always declared vararg */
> setvararg(fs, PF_ISVARARG); /* main function is always vararg */
src/lparser.h
39a40,41
> VVARGVAR, /* vararg parameter; var.ridx = register index;
> var.vidx = relative index in 'actvar.arr' */
51a54,55
> VVARGIND, /* indexed vararg parameter;
> ind.* as in VINDEXED */
100,103c104,108
< #define RDKTOCLOSE 2 /* to-be-closed */
< #define RDKCTC 3 /* local compile-time constant */
< #define GDKREG 4 /* regular global */
< #define GDKCONST 5 /* global constant */
> #define RDKVAVAR 2 /* vararg parameter */
> #define RDKTOCLOSE 3 /* to-be-closed */
> #define RDKCTC 4 /* local compile-time constant */
> #define GDKREG 5 /* regular global */
> #define GDKCONST 6 /* global constant */
src/lstate.h
88c88
< ** - Open upvales are kept gray to avoid barriers, but they stay out
> ** - Open upvalues are kept gray to avoid barriers, but they stay out
235c235
< #define CIST_FRESH cast(l_uint32, CIST_C << 1)
> #define CIST_FRESH (cast(l_uint32, CIST_C) << 1)
252,255d251
< #if defined(LUA_COMPAT_LT_LE)
< /* using __lt for __le */
< #define CIST_LEQ (CIST_FIN << 1)
< #endif
433d428
< ** (The access to 'tt' tries to ensure that 'v' is actually a Lua object.)
435c430,431
< #define obj2gco(v) check_exp((v)->tt >= LUA_TSTRING, &(cast_u(v)->gc))
> #define obj2gco(v) \
> check_exp(novariant((v)->tt) >= LUA_TSTRING, &(cast_u(v)->gc))
src/lstring.c
42c42
< ** equality for long strings
> ** generic equality for strings
44,49c44,49
< int luaS_eqlngstr (TString *a, TString *b) {
< size_t len = a->u.lnglen;
< lua_assert(a->tt == LUA_VLNGSTR && b->tt == LUA_VLNGSTR);
< return (a == b) || /* same instance or... */
< ((len == b->u.lnglen) && /* equal length and ... */
< (memcmp(getlngstr(a), getlngstr(b), len) == 0)); /* equal contents */
> int luaS_eqstr (TString *a, TString *b) {
> size_t len1, len2;
> const char *s1 = getlstr(a, len1);
> const char *s2 = getlstr(b, len2);
> return ((len1 == len2) && /* equal length and ... */
> (memcmp(s1, s2, len1) == 0)); /* equal contents */
53c53
< unsigned luaS_hash (const char *str, size_t l, unsigned seed) {
> static unsigned luaS_hash (const char *str, size_t l, unsigned seed) {
318,323d317
< static void f_pintern (lua_State *L, void *ud) {
< struct NewExt *ne = cast(struct NewExt *, ud);
< ne->ts = internshrstr(L, ne->s, ne->len);
< }
<
<
327,339d320
< if (len <= LUAI_MAXSHORTLEN) { /* short string? */
< ne.s = s; ne.len = len;
< if (!falloc)
< f_pintern(L, &ne); /* just internalize string */
< else {
< TStatus status = luaD_rawrunprotected(L, f_pintern, &ne);
< (*falloc)(ud, cast_voidp(s), len + 1, 0); /* free external string */
< if (status != LUA_OK) /* memory error? */
< luaM_error(L); /* re-raise memory error */
< }
< return ne.ts;
< }
< /* "normal" case: long strings */
358a340,352
>
> /*
> ** Normalize an external string: If it is short, internalize it.
> */
> TString *luaS_normstr (lua_State *L, TString *ts) {
> size_t len = ts->u.lnglen;
> if (len > LUAI_MAXSHORTLEN)
> return ts; /* long string; keep the original */
> else {
> const char *str = getlngstr(ts);
> return internshrstr(L, str, len);
> }
> }
src/lstring.h
57d56
< LUAI_FUNC unsigned luaS_hash (const char *str, size_t l, unsigned seed);
59c58
< LUAI_FUNC int luaS_eqlngstr (TString *a, TString *b);
> LUAI_FUNC int luaS_eqstr (TString *a, TString *b);
71a71
> LUAI_FUNC TString *luaS_normstr (lua_State *L, TString *ts);
src/lstrlib.c
134a135,138
> /*
> ** MAX_SIZE is limited both by size_t and lua_Integer.
> ** When x <= MAX_SIZE, x can be safely cast to size_t or lua_Integer.
> */
136,137c140,141
< size_t l, lsep;
< const char *s = luaL_checklstring(L, 1, &l);
> size_t len, lsep;
> const char *s = luaL_checklstring(L, 1, &len);
142c146,147
< else if (l_unlikely(l + lsep < l || l + lsep > MAX_SIZE / cast_sizet(n)))
> else if (l_unlikely(len > MAX_SIZE - lsep ||
> cast_st2S(len + lsep) > cast_st2S(MAX_SIZE) / n))
145c150
< size_t totallen = ((size_t)n * (l + lsep)) - lsep;
> size_t totallen = (cast_sizet(n) * (len + lsep)) - lsep;
149c154
< memcpy(p, s, l * sizeof(char)); p += l;
> memcpy(p, s, len * sizeof(char)); p += len;
151,152c156
< memcpy(p, sep, lsep * sizeof(char));
< p += lsep;
> memcpy(p, sep, lsep * sizeof(char)); p += lsep;
155c159
< memcpy(p, s, l * sizeof(char)); /* last copy (not followed by separator) */
> memcpy(p, s, len * sizeof(char)); /* last copy without separator */
268c272,279
< static void trymt (lua_State *L, const char *mtname) {
> /*
> ** To be here, either the first operand was a string or the first
> ** operand didn't have a corresponding metamethod. (Otherwise, that
> ** other metamethod would have been called.) So, if this metamethod
> ** doesn't work, the only other option would be for the second
> ** operand to have a different metamethod.
> */
> static void trymt (lua_State *L, const char *mtkey, const char *opname) {
271,272c282,283
< !luaL_getmetafield(L, 2, mtname)))
< luaL_error(L, "attempt to %s a '%s' with a '%s'", mtname + 2,
> !luaL_getmetafield(L, 2, mtkey)))
> luaL_error(L, "attempt to %s a '%s' with a '%s'", opname,
283c294
< trymt(L, mtname);
> trymt(L, mtname, mtname + 2);
1814,1815c1825,1826
< lua_pushlstring(L, data + pos + size, len);
< pos += len; /* skip string */
> lua_pushlstring(L, data + pos + size, cast_sizet(len));
> pos += cast_sizet(len); /* skip string */
src/ltable.c
159c159
< ** In a two-complement representation, INT_MAX does not has an exact
> ** In a two-complement representation, INT_MAX may not have an exact
237,251c237,250
< ** floats. It is assumed that 'eqshrstr' is simply pointer equality, so
< ** that short strings are handled in the default case.
< ** A true 'deadok' means to accept dead keys as equal to their original
< ** values. All dead keys are compared in the default case, by pointer
< ** identity. (Only collectable objects can produce dead keys.) Note that
< ** dead long strings are also compared by identity.
< ** Once a key is dead, its corresponding value may be collected, and
< ** then another value can be created with the same address. If this
< ** other value is given to 'next', 'equalkey' will signal a false
< ** positive. In a regular traversal, this situation should never happen,
< ** as all keys given to 'next' came from the table itself, and therefore
< ** could not have been collected. Outside a regular traversal, we
< ** have garbage in, garbage out. What is relevant is that this false
< ** positive does not break anything. (In particular, 'next' will return
< ** some other valid item on the table or nil.)
> ** floats. It is assumed that 'eqshrstr' is simply pointer equality,
> ** so that short strings are handled in the default case. The flag
> ** 'deadok' means to accept dead keys as equal to their original values.
> ** (Only collectable objects can produce dead keys.) Note that dead
> ** long strings are also compared by identity. Once a key is dead,
> ** its corresponding value may be collected, and then another value
> ** can be created with the same address. If this other value is given
> ** to 'next', 'equalkey' will signal a false positive. In a regular
> ** traversal, this situation should never happen, as all keys given to
> ** 'next' came from the table itself, and therefore could not have been
> ** collected. Outside a regular traversal, we have garbage in, garbage
> ** out. What is relevant is that this false positive does not break
> ** anything. (In particular, 'next' will return some other valid item
> ** on the table or nil.)
254,270c253,259
< if ((rawtt(k1) != keytt(n2)) && /* not the same variants? */
< !(deadok && keyisdead(n2) && iscollectable(k1)))
< return 0; /* cannot be same key */
< switch (keytt(n2)) {
< case LUA_VNIL: case LUA_VFALSE: case LUA_VTRUE:
< return 1;
< case LUA_VNUMINT:
< return (ivalue(k1) == keyival(n2));
< case LUA_VNUMFLT:
< return luai_numeq(fltvalue(k1), fltvalueraw(keyval(n2)));
< case LUA_VLIGHTUSERDATA:
< return pvalue(k1) == pvalueraw(keyval(n2));
< case LUA_VLCF:
< return fvalue(k1) == fvalueraw(keyval(n2));
< case ctb(LUA_VLNGSTR):
< return luaS_eqlngstr(tsvalue(k1), keystrval(n2));
< default:
> if (rawtt(k1) != keytt(n2)) { /* not the same variants? */
> if (keyisshrstr(n2) && ttislngstring(k1)) {
> /* an external string can be equal to a short-string key */
> return luaS_eqstr(tsvalue(k1), keystrval(n2));
> }
> else if (deadok && keyisdead(n2) && iscollectable(k1)) {
> /* a collectable value can be equal to a dead key */
271a261,281
> }
> else
> return 0; /* otherwise, different variants cannot be equal */
> }
> else { /* equal variants */
> switch (keytt(n2)) {
> case LUA_VNIL: case LUA_VFALSE: case LUA_VTRUE:
> return 1;
> case LUA_VNUMINT:
> return (ivalue(k1) == keyival(n2));
> case LUA_VNUMFLT:
> return luai_numeq(fltvalue(k1), fltvalueraw(keyval(n2)));
> case LUA_VLIGHTUSERDATA:
> return pvalue(k1) == pvalueraw(keyval(n2));
> case LUA_VLCF:
> return fvalue(k1) == fvalueraw(keyval(n2));
> case ctb(LUA_VLNGSTR):
> return luaS_eqstr(tsvalue(k1), keystrval(n2));
> default:
> return gcvalue(k1) == gcvalueraw(keyval(n2));
> }
1160a1171,1178
> else if (isextstr(key)) { /* external string? */
> /* If string is short, must internalize it to be used as table key */
> TString *ts = luaS_normstr(L, tsvalue(key));
> setsvalue2s(L, L->top.p++, ts); /* anchor 'ts' (EXTRA_STACK) */
> luaH_newkey(L, t, s2v(L->top.p - 1), value);
> L->top.p--;
> return;
> }
1205,1219c1223,1247
< ** caller, we know that 'j' is zero or present and that 'j + 1' is
< ** present. We want to find a larger key that is absent from the
< ** table, so that we can do a binary search between the two keys to
< ** find a boundary. We keep doubling 'j' until we get an absent index.
< ** If the doubling would overflow, we try LUA_MAXINTEGER. If it is
< ** absent, we are ready for the binary search. ('j', being max integer,
< ** is larger or equal to 'i', but it cannot be equal because it is
< ** absent while 'i' is present; so 'j > i'.) Otherwise, 'j' is a
< ** boundary. ('j + 1' cannot be a present integer key because it is
< ** not a valid integer in Lua.)
< */
< static lua_Unsigned hash_search (Table *t, lua_Unsigned j) {
< lua_Unsigned i;
< if (j == 0) j++; /* the caller ensures 'j + 1' is present */
< do {
> ** caller, we know that 'asize + 1' is present. We want to find a larger
> ** key that is absent from the table, so that we can do a binary search
> ** between the two keys to find a boundary. We keep doubling 'j' until
> ** we get an absent index. If the doubling would overflow, we try
> ** LUA_MAXINTEGER. If it is absent, we are ready for the binary search.
> ** ('j', being max integer, is larger or equal to 'i', but it cannot be
> ** equal because it is absent while 'i' is present.) Otherwise, 'j' is a
> ** boundary. ('j + 1' cannot be a present integer key because it is not
> ** a valid integer in Lua.)
> ** About 'rnd': If we used a fixed algorithm, a bad actor could fill
> ** a table with only the keys that would be probed, in such a way that
> ** a small table could result in a huge length. To avoid that, we use
> ** the state's seed as a source of randomness. For the first probe,
> ** we "randomly double" 'i' by adding to it a random number roughly its
> ** width.
> */
> static lua_Unsigned hash_search (lua_State *L, Table *t, unsigned asize) {
> lua_Unsigned i = asize + 1; /* caller ensures t[i] is present */
> unsigned rnd = G(L)->seed;
> int n = (asize > 0) ? luaO_ceillog2(asize) : 0; /* width of 'asize' */
> unsigned mask = (1u << n) - 1; /* 11...111 with the width of 'asize' */
> unsigned incr = (rnd & mask) + 1; /* first increment (at least 1) */
> lua_Unsigned j = (incr <= l_castS2U(LUA_MAXINTEGER) - i) ? i + incr : i + 1;
> rnd >>= n; /* used 'n' bits from 'rnd' */
> while (!hashkeyisempty(t, j)) { /* repeat until an absent t[j] */
1221,1222c1249,1252
< if (j <= l_castS2U(LUA_MAXINTEGER) / 2)
< j *= 2;
> if (j <= l_castS2U(LUA_MAXINTEGER)/2 - 1) {
> j = j*2 + (rnd & 1); /* try again with 2j or 2j+1 */
> rnd >>= 1;
> }
1230c1260
< } while (!hashkeyisempty(t, j)); /* repeat until an absent t[j] */
> }
1271c1301
< lua_Unsigned luaH_getn (Table *t) {
> lua_Unsigned luaH_getn (lua_State *L, Table *t) {
1312c1342
< return hash_search(t, asize);
> return hash_search(L, t, asize);
src/ltable.h
176c176
< LUAI_FUNC lua_Unsigned luaH_getn (Table *t);
> LUAI_FUNC lua_Unsigned luaH_getn (lua_State *L, Table *t);
src/ltm.c
199,204d198
< ** For lessequal, LUA_COMPAT_LT_LE keeps compatibility with old
< ** behavior: if there is no '__le', try '__lt', based on l <= r iff
< ** !(r < l) (assuming a total order). If the metamethod yields during
< ** this substitution, the continuation has to know about it (to negate
< ** the result of r<l); bit CIST_LEQ in the call status keeps that
< ** information.
211,220d204
< #if defined(LUA_COMPAT_LT_LE)
< else if (event == TM_LE) {
< /* try '!(p2 < p1)' for '(p1 <= p2)' */
< L->ci->callstatus |= CIST_LEQ; /* mark it is doing 'lt' for 'le' */
< tag = callbinTM(L, p2, p1, L->top.p, TM_LT);
< L->ci->callstatus ^= CIST_LEQ; /* clear mark */
< if (tag >= 0) /* found tag method? */
< return tagisfalse(tag);
< }
< #endif
243,244c227,254
< void luaT_adjustvarargs (lua_State *L, int nfixparams, CallInfo *ci,
< const Proto *p) {
> /*
> ** Create a vararg table at the top of the stack, with 'n' elements
> ** starting at 'f'.
> */
> static void createvarargtab (lua_State *L, StkId f, int n) {
> int i;
> TValue key, value;
> Table *t = luaH_new(L);
> sethvalue(L, s2v(L->top.p), t);
> L->top.p++;
> luaH_resize(L, t, cast_uint(n), 1);
> setsvalue(L, &key, luaS_new(L, "n")); /* key is "n" */
> setivalue(&value, n); /* value is n */
> /* No need to anchor the key: Due to the resize, the next operation
> cannot trigger a garbage collection */
> luaH_set(L, t, &key, &value); /* t.n = n */
> for (i = 0; i < n; i++)
> luaH_setint(L, t, i + 1, s2v(f + i));
> }
>
>
> /*
> ** initial stack: func arg1 ... argn extra1 ...
> ** ^ ci->func ^ L->top
> ** final stack: func nil ... nil extra1 ... func arg1 ... argn
> ** ^ ci->func ^ L->top
> */
> void luaT_adjustvarargs (lua_State *L, CallInfo *ci, const Proto *p) {
246,247c256,258
< int actual = cast_int(L->top.p - ci->func.p) - 1; /* number of arguments */
< int nextra = actual - nfixparams; /* number of extra arguments */
> int totalargs = cast_int(L->top.p - ci->func.p) - 1;
> int nfixparams = p->numparams;
> int nextra = totalargs - nfixparams; /* number of extra arguments */
257,258c268,275
< ci->func.p += actual + 1;
< ci->top.p += actual + 1;
> if (p->flag & PF_VAVAR) { /* is there a vararg parameter? */
> if (p->flag & PF_VATAB) /* does it need a vararg table? */
> createvarargtab(L, ci->func.p + nfixparams + 1, nextra);
> else /* no table; set parameter to nil */
> setnilvalue(s2v(L->top.p));
> }
> ci->func.p += totalargs + 1;
> ci->top.p += totalargs + 1;
259a277,298
> }
>
>
> void luaT_getvararg (CallInfo *ci, StkId ra, TValue *rc) {
> int nextra = ci->u.l.nextraargs;
> lua_Integer n;
> if (tointegerns(rc, &n)) { /* integral value? */
> if (l_castS2U(n) - 1 < cast_uint(nextra)) {
> StkId slot = ci->func.p - nextra + cast_int(n) - 1;
> setobjs2s(((lua_State*)NULL), ra, slot);
> return;
> }
> }
> else if (ttisstring(rc)) { /* string value? */
> size_t len;
> const char *s = getlstr(tsvalue(rc), len);
> if (len == 1 && s[0] == 'n') { /* key is "n"? */
> setivalue(s2v(ra), nextra);
> return;
> }
> }
> setnilvalue(s2v(ra)); /* else produce nil */
src/ltm.h
98,99c98,100
< LUAI_FUNC void luaT_adjustvarargs (lua_State *L, int nfixparams,
< struct CallInfo *ci, const Proto *p);
> LUAI_FUNC void luaT_adjustvarargs (lua_State *L, struct CallInfo *ci,
> const Proto *p);
> LUAI_FUNC void luaT_getvararg (CallInfo *ci, StkId ra, TValue *rc);
src/lua.c
306c306,307
< *first = i + 1;
> /* if there is a script name, it comes after '--' */
> *first = (argv[i + 1] != NULL) ? i + 1 : 0;
440,441d440
< **
< ** If lua_readline is defined, all of them should be defined.
444a444
> /* Otherwise, all previously listed functions should be defined. */
446c446,458
< /* Code to use the readline library, either statically or dynamically linked */
> #if defined(LUA_USE_READLINE) /* { */
> /* Lua will be linked with '-lreadline' */
>
> #include <readline/readline.h>
> #include <readline/history.h>
>
> #define lua_initreadline(L) ((void)L, rl_readline_name="lua")
> #define lua_readline(buff,prompt) ((void)buff, readline(prompt))
> #define lua_saveline(line) add_history(line)
> #define lua_freeline(line) free(line)
>
> #else /* }{ */
> /* use dynamically loaded readline (or nothing) */
482,496c494
< #if defined(LUA_USE_READLINE) /* { */
<
< /* assume Lua will be linked with '-lreadline' */
< #include <readline/readline.h>
< #include <readline/history.h>
<
< static void lua_initreadline(lua_State *L) {
< UNUSED(L);
< rl_readline_name = "lua";
< l_readline = cast(l_readlineT, readline);
< l_addhist = cast(l_addhistT, add_history);
< }
<
< #elif defined(LUA_USE_DLOPEN) && defined(LUA_READLINELIB) /* }{ */
<
> #if defined(LUA_USE_DLOPEN) && defined(LUA_READLINELIB) /* { */
497a496
>
509a509,510
> if (l_readline == NULL)
> lua_warning(L, "unable to load 'readline'", 0);
513c514,515
< #else /* }{ */
> #else /* }{ */
> /* no dlopen or LUA_READLINELIB undefined */
515,516c517,518
< /* no readline; leave function pointers as NULL */
< #define lua_initreadline(L) cast(void, L)
> /* Leave pointers with NULL */
> #define lua_initreadline(L) ((void)L)
518c520,522
< #endif /* } */
> #endif /* } */
>
> #endif /* } */
src/lua.h
40,41c40,41
< ** (-LUAI_MAXSTACK is the minimum valid index; we keep some free empty
< ** space after that to help overflow detection)
> ** (The stack size is limited to INT_MAX/2; we keep some free empty
> ** space after that to help overflow detection.)
43c43
< #define LUA_REGISTRYINDEX (-LUAI_MAXSTACK - 1000)
> #define LUA_REGISTRYINDEX (-(INT_MAX/2 + 1000))
435,441d434
< #if defined(LUA_COMPAT_APIINTCASTS)
<
< #define lua_pushunsigned(L,n) lua_pushinteger(L, (lua_Integer)(n))
< #define lua_tounsignedx(L,i,is) ((lua_Unsigned)lua_tointegerx(L,i,is))
< #define lua_tounsigned(L,i) lua_tounsignedx(L,(i),NULL)
<
< #endif
src/luac.c
481c481
< case OP_SHRI:
> case OP_SHLI:
484c484
< case OP_SHLI:
> case OP_SHRI:
647a648,654
> case OP_GETVARG:
> printf("%d %d %d",a,b,c);
> break;
> case OP_ERRNNIL:
> printf("%d %d",a,bx);
> printf(COMMENT); PrintConstant(f,bx);
> break;
664d670
<
src/luaconf.h
62c62
< ** When Posix DLL ('LUA_USE_DLOPEN') is enabled, the Lua stand-alone
> ** When POSIX DLL ('LUA_USE_DLOPEN') is enabled, the Lua stand-alone
79c79
< #define LUA_USE_DLOPEN /* MacOS does not need -ldl */
> #define LUA_USE_DLOPEN /* macOS does not need -ldl */
91c91
< #error "Posix is not compatible with C89"
> #error "POSIX is not compatible with C89"
141c141
< #define LUA_32BITS 0
> /* #define LUA_32BITS */
156c156
< #if LUA_32BITS /* { */
> #if defined(LUA_32BITS) /* { */
322,323d321
< #define LUAMOD_API LUA_API
<
325,347c323,328
< /*
< @@ LUAI_FUNC is a mark for all extern functions that are not to be
< ** exported to outside modules.
< @@ LUAI_DDEF and LUAI_DDEC are marks for all extern (const) variables,
< ** none of which to be exported to outside modules (LUAI_DDEF for
< ** definitions and LUAI_DDEC for declarations).
< ** CHANGE them if you need to mark them in some special way. Elf/gcc
< ** (versions 3.2 and later) mark them as "hidden" to optimize access
< ** when Lua is compiled as a shared library. Not all elf targets support
< ** this attribute. Unfortunately, gcc does not offer a way to check
< ** whether the target offers that support, and those without support
< ** give a warning about it. To avoid these warnings, change to the
< ** default definition.
< */
< #if defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \
< defined(__ELF__) /* { */
< #define LUAI_FUNC __attribute__((visibility("internal"))) extern
< #else /* }{ */
< #define LUAI_FUNC extern
< #endif /* } */
<
< #define LUAI_DDEC(dec) LUAI_FUNC dec
< #define LUAI_DDEF /* empty */
> #if defined(__cplusplus)
> /* Lua uses the "C name" when calling open functions */
> #define LUAMOD_API extern "C"
> #else
> #define LUAMOD_API LUA_API
> #endif
365,371d345
< @@ LUA_COMPAT_5_3 controls other macros for compatibility with Lua 5.3.
< ** You can define it to get all options, or change specific options
< ** to fit your specific needs.
< */
< #if defined(LUA_COMPAT_5_3) /* { */
<
< /*
377,393c351
< #define LUA_COMPAT_MATHLIB
<
< /*
< @@ LUA_COMPAT_APIINTCASTS controls the presence of macros for
< ** manipulating other integer types (lua_pushunsigned, lua_tounsigned,
< ** luaL_checkint, luaL_checklong, etc.)
< ** (These macros were also officially removed in 5.3, but they are still
< ** available here.)
< */
< #define LUA_COMPAT_APIINTCASTS
<
<
< /*
< @@ LUA_COMPAT_LT_LE controls the emulation of the '__le' metamethod
< ** using '__lt'.
< */
< #define LUA_COMPAT_LT_LE
> /* #define LUA_COMPAT_MATHLIB */
410,411d367
< #endif /* } */
<
443c399
< /* The following definitions are good for most cases here */
> /* The following definition is good for most cases here */
448,462d403
< /*
< @@ lua_numbertointeger converts a float number with an integral value
< ** to an integer, or returns 0 if float is not within the range of
< ** a lua_Integer. (The range comparisons are tricky because of
< ** rounding. The tests here assume a two-complement representation,
< ** where MININTEGER always has an exact representation as a float;
< ** MAXINTEGER may not have one, and therefore its conversion to float
< ** may have an ill-defined value.)
< */
< #define lua_numbertointeger(n,p) \
< ((n) >= (LUA_NUMBER)(LUA_MININTEGER) && \
< (n) < -(LUA_NUMBER)(LUA_MININTEGER) && \
< (*(p) = (LUA_INTEGER)(n), 1))
<
<
722,728d662
< #if defined(LUA_CORE) || defined(LUA_LIB)
< /* shorter names for Lua's own use */
< #define l_likely(x) luai_likely(x)
< #define l_unlikely(x) luai_unlikely(x)
< #endif
<
<
767,780d700
< @@ LUAI_MAXSTACK limits the size of the Lua stack.
< ** CHANGE it if you need a different limit. This limit is arbitrary;
< ** its only purpose is to stop Lua from consuming unlimited stack
< ** space and to reserve some numbers for pseudo-indices.
< ** (It must fit into max(int)/2.)
< */
< #if 1000000 < (INT_MAX / 2)
< #define LUAI_MAXSTACK 1000000
< #else
< #define LUAI_MAXSTACK (INT_MAX / 2u)
< #endif
<
<
< /*
821,822d740
<
<
src/lundump.c
112c112
< return loadVarint(S, MAX_SIZE);
> return cast_sizet(loadVarint(S, MAX_SIZE));
150,154c150
< if (size == 0) { /* no string? */
< lua_assert(*sl == NULL); /* must be prefilled */
< return;
< }
< else if (size == 1) { /* previously saved string? */
> if (size == 0) { /* previously saved string? */
156a153,156
> if (idx == 0) { /* no string? */
> lua_assert(*sl == NULL); /* must be prefilled */
> return;
> }
163c163
< else if ((size -= 2) <= LUAI_MAXSHORTLEN) { /* short string? */
> else if ((size -= 1) <= LUAI_MAXSHORTLEN) { /* short string? */
330c330,331
< f->flag = loadByte(S) & PF_ISVARARG; /* get only the meaningful flags */
> /* get only the meaningful flags */
> f->flag = cast_byte(loadByte(S) & ~PF_FIXED);
src/lutf8lib.c
13d12
< #include <assert.h>
50c49
< ** entry forces an error for non-ascii bytes with no continuation
> ** entry forces an error for non-ASCII bytes with no continuation
58c57
< if (c < 0x80) /* ascii? */
> if (c < 0x80) /* ASCII? */
218,220c217,220
< do {
< posi++;
< } while (iscontp(s + posi + 1)); /* skip to final byte */
> if (iscont(s[posi]))
> return luaL_error(L, "initial position is a continuation byte");
> while (iscontp(s + posi + 1))
> posi++; /* skip to last continuation byte */
src/lvm.c
375a376,383
> ** Function to be used for 0-terminated string order comparison
> */
> #if !defined(l_strcoll)
> #define l_strcoll strcoll
> #endif
>
>
> /*
389c397
< int temp = strcoll(s1, s2);
> int temp = l_strcoll(s1, s2);
576,586c584,609
< if (ttypetag(t1) != ttypetag(t2)) { /* not the same variant? */
< if (ttype(t1) != ttype(t2) || ttype(t1) != LUA_TNUMBER)
< return 0; /* only numbers can be equal with different variants */
< else { /* two numbers with different variants */
< /* One of them is an integer. If the other does not have an
< integer value, they cannot be equal; otherwise, compare their
< integer values. */
< lua_Integer i1, i2;
< return (luaV_tointegerns(t1, &i1, F2Ieq) &&
< luaV_tointegerns(t2, &i2, F2Ieq) &&
< i1 == i2);
> if (ttype(t1) != ttype(t2)) /* not the same type? */
> return 0;
> else if (ttypetag(t1) != ttypetag(t2)) {
> switch (ttypetag(t1)) {
> case LUA_VNUMINT: { /* integer == float? */
> /* integer and float can only be equal if float has an integer
> value equal to the integer */
> lua_Integer i2;
> return (luaV_flttointeger(fltvalue(t2), &i2, F2Ieq) &&
> ivalue(t1) == i2);
> }
> case LUA_VNUMFLT: { /* float == integer? */
> lua_Integer i1; /* see comment in previous case */
> return (luaV_flttointeger(fltvalue(t1), &i1, F2Ieq) &&
> i1 == ivalue(t2));
> }
> case LUA_VSHRSTR: case LUA_VLNGSTR: {
> /* compare two strings with different variants: they can be
> equal when one string is a short string and the other is
> an external string */
> return luaS_eqstr(tsvalue(t1), tsvalue(t2));
> }
> default:
> /* only numbers (integer/float) and strings (long/short) can have
> equal values with different variants */
> return 0;
589,604c612,644
< /* values have same type and same variant */
< switch (ttypetag(t1)) {
< case LUA_VNIL: case LUA_VFALSE: case LUA_VTRUE: return 1;
< case LUA_VNUMINT: return (ivalue(t1) == ivalue(t2));
< case LUA_VNUMFLT: return luai_numeq(fltvalue(t1), fltvalue(t2));
< case LUA_VLIGHTUSERDATA: return pvalue(t1) == pvalue(t2);
< case LUA_VLCF: return fvalue(t1) == fvalue(t2);
< case LUA_VSHRSTR: return eqshrstr(tsvalue(t1), tsvalue(t2));
< case LUA_VLNGSTR: return luaS_eqlngstr(tsvalue(t1), tsvalue(t2));
< case LUA_VUSERDATA: {
< if (uvalue(t1) == uvalue(t2)) return 1;
< else if (L == NULL) return 0;
< tm = fasttm(L, uvalue(t1)->metatable, TM_EQ);
< if (tm == NULL)
< tm = fasttm(L, uvalue(t2)->metatable, TM_EQ);
< break; /* will try TM */
> else { /* equal variants */
> switch (ttypetag(t1)) {
> case LUA_VNIL: case LUA_VFALSE: case LUA_VTRUE:
> return 1;
> case LUA_VNUMINT:
> return (ivalue(t1) == ivalue(t2));
> case LUA_VNUMFLT:
> return (fltvalue(t1) == fltvalue(t2));
> case LUA_VLIGHTUSERDATA: return pvalue(t1) == pvalue(t2);
> case LUA_VSHRSTR:
> return eqshrstr(tsvalue(t1), tsvalue(t2));
> case LUA_VLNGSTR:
> return luaS_eqstr(tsvalue(t1), tsvalue(t2));
> case LUA_VUSERDATA: {
> if (uvalue(t1) == uvalue(t2)) return 1;
> else if (L == NULL) return 0;
> tm = fasttm(L, uvalue(t1)->metatable, TM_EQ);
> if (tm == NULL)
> tm = fasttm(L, uvalue(t2)->metatable, TM_EQ);
> break; /* will try TM */
> }
> case LUA_VTABLE: {
> if (hvalue(t1) == hvalue(t2)) return 1;
> else if (L == NULL) return 0;
> tm = fasttm(L, hvalue(t1)->metatable, TM_EQ);
> if (tm == NULL)
> tm = fasttm(L, hvalue(t2)->metatable, TM_EQ);
> break; /* will try TM */
> }
> case LUA_VLCF:
> return (fvalue(t1) == fvalue(t2));
> default: /* functions and threads */
> return (gcvalue(t1) == gcvalue(t2));
606,612c646,650
< case LUA_VTABLE: {
< if (hvalue(t1) == hvalue(t2)) return 1;
< else if (L == NULL) return 0;
< tm = fasttm(L, hvalue(t1)->metatable, TM_EQ);
< if (tm == NULL)
< tm = fasttm(L, hvalue(t2)->metatable, TM_EQ);
< break; /* will try TM */
> if (tm == NULL) /* no TM? */
> return 0; /* objects are different */
> else {
> int tag = luaT_callTMres(L, tm, t1, t2, L->top.p); /* call TM */
> return !tagisfalse(tag);
614,621d651
< default:
< return gcvalue(t1) == gcvalue(t2);
< }
< if (tm == NULL) /* no TM? */
< return 0; /* objects are different */
< else {
< int tag = luaT_callTMres(L, tm, t1, t2, L->top.p); /* call TM */
< return !tagisfalse(tag);
629a660,664
> /*
> ** Check whether object is a short empty string to optimize concatenation.
> ** (External strings can be empty too; they will be concatenated like
> ** non-empty ones.)
> */
664,665c699,700
< /* at least two non-empty string values; get as many as possible */
< size_t tl = tsslen(tsvalue(s2v(top - 1)));
> /* at least two string values; get as many as possible */
> size_t tl = tsslen(tsvalue(s2v(top - 1))); /* total length */
703c738
< setivalue(s2v(ra), l_castU2S(luaH_getn(h))); /* else primitive len */
> setivalue(s2v(ra), l_castU2S(luaH_getn(L, h))); /* else primitive len */
842,847d876
< #if defined(LUA_COMPAT_LT_LE)
< if (ci->callstatus & CIST_LEQ) { /* "<=" using "<" instead? */
< ci->callstatus ^= CIST_LEQ; /* clear mark */
< res = !res; /* negate result */
< }
< #endif
890a920,923
> **
> ** All these macros are to be used exclusively inside the main
> ** iterpreter loop (function luaV_execute) and may access directly
> ** the local variables of that function (L, i, pc, ci, etc.).
912c945
< StkId ra = RA(i); \
> TValue *ra = vRA(i); \
917c950
< pc++; setivalue(s2v(ra), iop(L, iv1, imm)); \
> pc++; setivalue(ra, iop(L, iv1, imm)); \
922c955
< pc++; setfltvalue(s2v(ra), fop(L, nb, fimm)); \
> pc++; setfltvalue(ra, fop(L, nb, fimm)); \
932a966
> StkId ra = RA(i); \
941d974
< StkId ra = RA(i); \
951d983
< StkId ra = RA(i); \
961d992
< StkId ra = RA(i); \
962a994
> StkId ra = RA(i); \
991d1022
< StkId ra = RA(i); \
996a1028
> StkId ra = RA(i); \
1005d1036
< StkId ra = RA(i); \
1009a1041
> StkId ra = RA(i); \
1020c1052
< StkId ra = RA(i); \
> TValue *ra = vRA(i); \
1023,1024c1055,1056
< if (ttisinteger(s2v(ra)) && ttisinteger(rb)) { \
< lua_Integer ia = ivalue(s2v(ra)); \
> if (ttisinteger(ra) && ttisinteger(rb)) { \
> lua_Integer ia = ivalue(ra); \
1028,1029c1060,1061
< else if (ttisnumber(s2v(ra)) && ttisnumber(rb)) \
< cond = opn(s2v(ra), rb); \
> else if (ttisnumber(ra) && ttisnumber(rb)) \
> cond = opn(ra, rb); \
1031c1063
< Protect(cond = other(L, s2v(ra), rb)); \
> Protect(cond = other(L, ra, rb)); \
1040c1072
< StkId ra = RA(i); \
> TValue *ra = vRA(i); \
1043,1046c1075,1078
< if (ttisinteger(s2v(ra))) \
< cond = opi(ivalue(s2v(ra)), im); \
< else if (ttisfloat(s2v(ra))) { \
< lua_Number fa = fltvalue(s2v(ra)); \
> if (ttisinteger(ra)) \
> cond = opi(ivalue(ra), im); \
> else if (ttisfloat(ra)) { \
> lua_Number fa = fltvalue(ra); \
1052c1084
< Protect(cond = luaT_callorderiTM(L, s2v(ra), im, inv, isf, tm)); \
> Protect(cond = luaT_callorderiTM(L, ra, im, inv, isf, tm)); \
1070a1103
> #define vRA(i) s2v(RA(i))
1111c1144
< #define savepc(L) (ci->u.l.savedpc = pc)
> #define savepc(ci) (ci->u.l.savedpc = pc)
1118c1151
< #define savestate(L,ci) (savepc(L), L->top.p = ci->top.p)
> #define savestate(L,ci) (savepc(ci), L->top.p = ci->top.p)
1128c1161
< #define ProtectNT(exp) (savepc(L), (exp), updatetrap(ci))
> #define ProtectNT(exp) (savepc(ci), (exp), updatetrap(ci))
1146c1179
< { luaC_condGC(L, (savepc(L), L->top.p = (c)), \
> { luaC_condGC(L, (savepc(ci), L->top.p = (c)), \
1453c1486
< vmcase(OP_SHRI) {
> vmcase(OP_SHLI) {
1459c1492
< pc++; setivalue(s2v(ra), luaV_shiftl(ib, -ic));
> pc++; setivalue(s2v(ra), luaV_shiftl(ic, ib));
1463c1496
< vmcase(OP_SHLI) {
> vmcase(OP_SHRI) {
1469c1502
< pc++; setivalue(s2v(ra), luaV_shiftl(ic, ib));
> pc++; setivalue(s2v(ra), luaV_shiftl(ib, -ic));
1515,1518d1547
< vmcase(OP_SHR) {
< op_bitwise(L, luaV_shiftr);
< vmbreak;
< }
1522a1552,1555
> vmcase(OP_SHR) {
> op_bitwise(L, luaV_shiftr);
> vmbreak;
> }
1695c1728
< savepc(L); /* in case of errors */
> savepc(ci); /* in case of errors */
1871c1904
< unsigned int last = cast_uint(GETARG_vC(i));
> unsigned last = cast_uint(GETARG_vC(i));
1908a1942,1953
> vmcase(OP_GETVARG) {
> StkId ra = RA(i);
> TValue *rc = vRC(i);
> luaT_getvararg(ci, ra, rc);
> vmbreak;
> }
> vmcase(OP_ERRNNIL) {
> TValue *ra = vRA(i);
> if (!ttisnil(ra))
> halfProtect(luaG_errnnil(L, cl, GETARG_Bx(i)));
> vmbreak;
> }
1910c1955
< ProtectNT(luaT_adjustvarargs(L, GETARG_A(i), ci, cl->p));
> ProtectNT(luaT_adjustvarargs(L, ci, cl->p));