diffs-lua-5.3.1-lua-5.3.2
Makefile
49c49
< R= $V.1
> R= $V.2
README
2c2
< This is Lua 5.3.1, released on 10 Jun 2015.
> This is Lua 5.3.2, released on 25 Nov 2015.
doc/lua.css
133a134,159
>
> table.book {
> border: none ;
> border-spacing: 0 ;
> border-collapse: collapse ;
> }
>
> table.book td {
> padding: 0 ;
> vertical-align: top ;
> }
>
> table.book td.cover {
> padding-right: 1em ;
> }
>
> table.book img {
> border: solid #000080 1px ;
> }
>
> table.book span {
> font-size: small ;
> text-align: left ;
> display: block ;
> margin-top: 0.25em ;
> }
doc/manual.html
38c38
< <!-- $Id: manual.of,v 1.151 2015/06/10 21:08:57 roberto Exp $ -->
> <!-- $Id: manual.of,v 1.153 2015/11/25 16:57:42 roberto Exp $ -->
401c401
< you must use the C API for that.
> you should use the C API for that.
592c592
< The less-equal operation can use two different events.
> the less-equal operation can use two different events.
1054c1054,1055
< not beginning with a digit.
> not beginning with a digit and
> not being a reserved word.
2709c2710,2712
< current function (but not greater than 256),
> current function
> (but not greater than 256,
> which is one plus the maximum number of upvalues in a closure),
2973a2977
> '<code>m</code>' means the function may raise memory errors;
3146c3150,3151
< Lua takes care that the returned values fit into the stack space.
> Lua takes care that the returned values fit into the stack space,
> but it does not ensure any extra space in the stack.
3256c3261,3262
< Ensures that the stack has space for at least <code>n</code> extra slots.
> Ensures that the stack has space for at least <code>n</code> extra slots
> (that is, that you can safely push up to <code>n</code> values into it).
3263c3269
< if the stack is already larger than the new size,
> if the stack already has space for the extra slots,
3348c3354
< <span class="apii">[-0, +1, <em>e</em>]</span>
> <span class="apii">[-0, +1, <em>m</em>]</span>
3358c3364
< This pre-allocation is useful for performance when you know in advance
> This preallocation is useful for performance when you know in advance
3367c3373
< <span class="apii">[-0, +0, <em>e</em>]</span>
> <span class="apii">[-0, +0, –]</span>
3981c3987
< <span class="apii">[-0, +1, <em>e</em>]</span>
> <span class="apii">[-0, +1, <em>m</em>]</span>
3993c3999
< <span class="apii">[-0, +1, <em>e</em>]</span>
> <span class="apii">[-0, +1, <em>m</em>]</span>
4014c4020
< <span class="apii">[-0, +1, <em>e</em>]</span>
> <span class="apii">[-0, +1, <em>m</em>]</span>
4224c4230
< <span class="apii">[-n, +1, <em>e</em>]</span>
> <span class="apii">[-n, +1, <em>m</em>]</span>
4281c4287
< <span class="apii">[-0, +1, <em>e</em>]</span>
> <span class="apii">[-0, +1, <em>m</em>]</span>
4361c4367
< <span class="apii">[-0, +1, <em>e</em>]</span>
> <span class="apii">[-0, +1, <em>m</em>]</span>
4373c4379
< <span class="apii">[-0, +1, <em>e</em>]</span>
> <span class="apii">[-0, +1, <em>m</em>]</span>
4416c4422
< <span class="apii">[-0, +1, <em>e</em>]</span>
> <span class="apii">[-0, +1, <em>m</em>]</span>
4463c4469
< <span class="apii">[-0, +1, <em>e</em>]</span>
> <span class="apii">[-0, +1, <em>m</em>]</span>
4558c4564
< <span class="apii">[-2, +0, <em>e</em>]</span>
> <span class="apii">[-2, +0, <em>m</em>]</span>
4570c4576
< <span class="apii">[-1, +0, <em>e</em>]</span>
> <span class="apii">[-1, +0, <em>m</em>]</span>
4589c4595
< <span class="apii">[-1, +0, <em>e</em>]</span>
> <span class="apii">[-1, +0, <em>m</em>]</span>
4992c4998
< <span class="apii">[-0, +0, <em>e</em>]</span>
> <span class="apii">[-0, +0, <em>m</em>]</span>
4998c5004
< it also sets <code>*len</code> with the string length.
> it sets <code>*len</code> with the string length.
5009c5015
< <code>lua_tolstring</code> returns a fully aligned pointer
> <code>lua_tolstring</code> returns a pointer
5078c5084
< <span class="apii">[-0, +0, <em>e</em>]</span>
> <span class="apii">[-0, +0, <em>m</em>]</span>
5887c5893
< <span class="apii">[-?, +?, <em>e</em>]</span>
> <span class="apii">[-?, +?, <em>m</em>]</span>
5899c5905
< <span class="apii">[-?, +?, <em>e</em>]</span>
> <span class="apii">[-?, +?, <em>m</em>]</span>
5913c5919
< <span class="apii">[-?, +?, <em>e</em>]</span>
> <span class="apii">[-?, +?, –]</span>
5926c5932
< <span class="apii">[-?, +?, <em>e</em>]</span>
> <span class="apii">[-?, +?, <em>m</em>]</span>
5939c5945
< <span class="apii">[-1, +?, <em>e</em>]</span>
> <span class="apii">[-1, +?, <em>m</em>]</span>
6077c6083
< <span class="apii">[-?, +?, <em>e</em>]</span>
> <span class="apii">[-?, +?, <em>m</em>]</span>
6328c6334
< <span class="apii">[-0, +3, <em>e</em>]</span>
> <span class="apii">[-0, +3, <em>m</em>]</span>
6341c6347
< <span class="apii">[-0, +(1|3), <em>e</em>]</span>
> <span class="apii">[-0, +(1|3), <em>m</em>]</span>
6354c6360
< <span class="apii">[-0, +(0|1), <em>e</em>]</span>
> <span class="apii">[-0, +(0|1), <em>m</em>]</span>
6369c6375
< <span class="apii">[-0, +1, –]</span>
> <span class="apii">[-0, +1, <em>m</em>]</span>
6399c6405
< <span class="apii">[-0, +1, <em>e</em>]</span>
> <span class="apii">[-0, +1, <em>m</em>]</span>
6534c6540
< <span class="apii">[-0, +1, <em>e</em>]</span>
> <span class="apii">[-0, +1, <em>m</em>]</span>
6556c6562
< <span class="apii">[-0, +1, <em>e</em>]</span>
> <span class="apii">[-0, +1, <em>m</em>]</span>
6577c6583
< <span class="apii">[-0, +1, <em>e</em>]</span>
> <span class="apii">[-0, +1, <em>m</em>]</span>
6666a6673,6675
> If the result is <code>NULL</code>
> (only possible when returning <code>d</code> and <code>d == NULL</code>),
> its length is considered zero.
6705c6714
< <span class="apii">[-?, +?, <em>e</em>]</span>
> <span class="apii">[-?, +?, <em>m</em>]</span>
6717c6726
< <span class="apii">[-?, +?, <em>e</em>]</span>
> <span class="apii">[-?, +?, <em>m</em>]</span>
6733c6742
< <span class="apii">[-?, +1, <em>e</em>]</span>
> <span class="apii">[-?, +1, <em>m</em>]</span>
6745c6754
< <span class="apii">[-?, +1, <em>e</em>]</span>
> <span class="apii">[-?, +1, <em>m</em>]</span>
6756c6765
< <span class="apii">[-1, +0, <em>e</em>]</span>
> <span class="apii">[-1, +0, <em>m</em>]</span>
6827c6836
< <span class="apii">[-nup, +0, <em>e</em>]</span>
> <span class="apii">[-nup, +0, <em>m</em>]</span>
6891c6900
< the field value is changed to <code>NULL</code>
> it changes the field value to <code>NULL</code>
6899c6908
< <span class="apii">[-0, +0, <em>e</em>]</span>
> <span class="apii">[-0, +0, <em>m</em>]</span>
6935c6944
< <span class="apii">[-0, +1, <em>e</em>]</span>
> <span class="apii">[-0, +1, <em>m</em>]</span>
6982c6991
< <span class="apii">[-0, +1, <em>e</em>]</span>
> <span class="apii">[-0, +1, <em>m</em>]</span>
7479c7488,7489
< (You cannot change the metatable of other types from Lua, only from C.)
> (To change the metatable of other types from Lua code,
> you must use the debug library (<a href="#6.10">§6.10</a>).)
7559a7570,7572
>
>
> <p>
7561c7574
< holds a string containing the current interpreter version.
> holds a string containing the running Lua version.
8197c8210
< Option <code>s</code> expects a string without embedded zeros;
> Option <code>s</code> expects a string;
8199a8213,8214
> If the option has any modifier (flags, width, length),
> the string argument should not contain embedded zeros.
8394a8410,8414
> <p>
> (Note that it is very easy to exhaust the memory of your machine
> with a single call to this function.)
>
>
8966c8986,8987
< (so that <code>not comp(list[i+1],list[i])</code> will be true after the sort).
> (so that, after the sort,
> <code>i < j</code> implies <code>not comp(list[j],list[i])</code>).
8971a8993,8999
> Note that the <code>comp</code> function must define
> a strict partial order over the elements in the list;
> that is, it must be asymmetric and transitive.
> Otherwise, no valid sort may be possible.
>
>
> <p>
8973c9001,9002
< that is, elements considered equal by the given order
> that is, elements not comparable by the given order
> (e.g., equal elements)
9225c9254
< (The value <em>m-n</em> cannot be negative and must fit in a Lua integer.)
> (The value <em>n-m</em> cannot be negative and must fit in a Lua integer.)
9232d9260
< No guarantees can be given for its statistical properties.
9400c9428
< <hr><h3><a name="pdf-io.lines"><code>io.lines ([filename ···])</code></a></h3>
> <hr><h3><a name="pdf-io.lines"><code>io.lines ([filename, ···])</code></a></h3>
9774c9802
< <code>year</code> (four digits), <code>month</code> (1–12), <code>day</code> (1–31),
> <code>year</code>, <code>month</code> (1–12), <code>day</code> (1–31),
9792,9793c9820,9821
< the host system and on the current locale
< (that is, <code>os.date()</code> is equivalent to <code>os.date("%c")</code>).
> the host system and on the current locale.
> (More specifically, <code>os.date()</code> is equivalent to <code>os.date("%c")</code>.)
10800c10828
< Wed Jun 10 18:31:15 BRT 2015
> Wed Nov 25 15:19:10 BRST 2015
10803c10831
< Last change: revised for Lua 5.3.1
> Last change: revised for Lua 5.3.2
src/lapi.c
2c2
< ** $Id: lapi.c,v 2.249 2015/04/06 12:23:48 roberto Exp $
> ** $Id: lapi.c,v 2.257 2015/11/02 18:48:07 roberto Exp $
124c124
< api_check(from, to->ci->top - to->top >= n, "not enough elements to move");
> api_check(from, to->ci->top - to->top >= n, "stack overflow");
128c128
< api_incr_top(to);
> to->top++; /* stack already checked by previous 'api_check' */
473a474,478
> /*
> ** Pushes on the stack a string with given length. Avoid using 's' when
> ** 'len' == 0 (as 's' can be NULL in that case), due to later use of
> ** 'memcmp' and 'memcpy'.
> */
478c483
< ts = luaS_newlstr(L, s, len);
> ts = (len == 0) ? luaS_new(L, "") : luaS_newlstr(L, s, len);
581a587,603
> static int auxgetstr (lua_State *L, const TValue *t, const char *k) {
> const TValue *aux;
> TString *str = luaS_new(L, k);
> if (luaV_fastget(L, t, str, aux, luaH_getstr)) {
> setobj2s(L, L->top, aux);
> api_incr_top(L);
> }
> else {
> setsvalue2s(L, L->top, str);
> api_incr_top(L);
> luaV_finishget(L, t, L->top - 1, L->top - 1, aux);
> }
> lua_unlock(L);
> return ttnov(L->top - 1);
> }
>
>
584d605
< const TValue *gt; /* global table */
586,591c607
< gt = luaH_getint(reg, LUA_RIDX_GLOBALS);
< setsvalue2s(L, L->top, luaS_new(L, name));
< api_incr_top(L);
< luaV_gettable(L, gt, L->top - 1, L->top - 1);
< lua_unlock(L);
< return ttnov(L->top - 1);
> return auxgetstr(L, luaH_getint(reg, LUA_RIDX_GLOBALS), name);
606d621
< StkId t;
608,613c623
< t = index2addr(L, idx);
< setsvalue2s(L, L->top, luaS_new(L, k));
< api_incr_top(L);
< luaV_gettable(L, t, L->top - 1, L->top - 1);
< lua_unlock(L);
< return ttnov(L->top - 1);
> return auxgetstr(L, index2addr(L, idx), k);
618a629
> const TValue *aux;
621,623c632,640
< setivalue(L->top, n);
< api_incr_top(L);
< luaV_gettable(L, t, L->top - 1, L->top - 1);
> if (luaV_fastget(L, t, n, aux, luaH_getint)) {
> setobj2s(L, L->top, aux);
> api_incr_top(L);
> }
> else {
> setivalue(L->top, n);
> api_incr_top(L);
> luaV_finishget(L, t, L->top - 1, L->top - 1, aux);
> }
721a739,756
> /*
> ** t[k] = value at the top of the stack (where 'k' is a string)
> */
> static void auxsetstr (lua_State *L, const TValue *t, const char *k) {
> const TValue *aux;
> TString *str = luaS_new(L, k);
> api_checknelems(L, 1);
> if (luaV_fastset(L, t, str, aux, luaH_getstr, L->top - 1))
> L->top--; /* pop value */
> else {
> setsvalue2s(L, L->top, str); /* push 'str' (to make it a TValue) */
> api_incr_top(L);
> luaV_finishset(L, t, L->top - 1, L->top - 2, aux);
> L->top -= 2; /* pop value and key */
> }
> lua_unlock(L); /* lock done by caller */
> }
>
725,733c760,761
< const TValue *gt; /* global table */
< lua_lock(L);
< api_checknelems(L, 1);
< gt = luaH_getint(reg, LUA_RIDX_GLOBALS);
< setsvalue2s(L, L->top, luaS_new(L, name));
< api_incr_top(L);
< luaV_settable(L, gt, L->top - 1, L->top - 2);
< L->top -= 2; /* pop value and key */
< lua_unlock(L);
> lua_lock(L); /* unlock done in 'auxsetstr' */
> auxsetstr(L, luaH_getint(reg, LUA_RIDX_GLOBALS), name);
749,757c777,778
< StkId t;
< lua_lock(L);
< api_checknelems(L, 1);
< t = index2addr(L, idx);
< setsvalue2s(L, L->top, luaS_new(L, k));
< api_incr_top(L);
< luaV_settable(L, t, L->top - 1, L->top - 2);
< L->top -= 2; /* pop value and key */
< lua_unlock(L);
> lua_lock(L); /* unlock done in 'auxsetstr' */
> auxsetstr(L, index2addr(L, idx), k);
762a784
> const TValue *aux;
766,769c788,795
< setivalue(L->top, n);
< api_incr_top(L);
< luaV_settable(L, t, L->top - 1, L->top - 2);
< L->top -= 2; /* pop value and key */
> if (luaV_fastset(L, t, n, aux, luaH_getint, L->top - 1))
> L->top--; /* pop value */
> else {
> setivalue(L->top, n);
> api_incr_top(L);
> luaV_finishset(L, t, L->top - 1, L->top - 2, aux);
> L->top -= 2; /* pop value and key */
> }
776c802
< Table *t;
> TValue *slot;
781,784c807,810
< t = hvalue(o);
< setobj2t(L, luaH_set(L, t, L->top-2), L->top-1);
< invalidateTMcache(t);
< luaC_barrierback(L, t, L->top-1);
> slot = luaH_set(L, hvalue(o), L->top - 2);
> setobj2t(L, slot, L->top - 1);
> invalidateTMcache(hvalue(o));
> luaC_barrierback(L, hvalue(o), L->top-1);
792d817
< Table *t;
797,799c822,823
< t = hvalue(o);
< luaH_setint(L, t, n, L->top - 1);
< luaC_barrierback(L, t, L->top-1);
> luaH_setint(L, hvalue(o), n, L->top - 1);
> luaC_barrierback(L, hvalue(o), L->top-1);
807,808c831
< Table *t;
< TValue k;
> TValue k, *slot;
813d835
< t = hvalue(o);
815,816c837,839
< setobj2t(L, luaH_set(L, t, &k), L->top - 1);
< luaC_barrierback(L, t, L->top - 1);
> slot = luaH_set(L, hvalue(o), &k);
> setobj2t(L, slot, L->top - 1);
> luaC_barrierback(L, hvalue(o), L->top - 1);
898c921
< luaD_call(L, func, nresults, 1); /* do the call */
> luaD_call(L, func, nresults); /* do the call */
901c924
< luaD_call(L, func, nresults, 0); /* just do the call */
> luaD_callnoyield(L, func, nresults); /* just do the call */
919c942
< luaD_call(L, c->func, c->nresults, 0);
> luaD_callnoyield(L, c->func, c->nresults);
957c980
< luaD_call(L, c.func, nresults, 1); /* do the call */
> luaD_call(L, c.func, nresults); /* do the call */
1046c1069
< int oldrunning = g->gcrunning;
> lu_byte oldrunning = g->gcrunning;
src/lauxlib.c
2c2
< ** $Id: lauxlib.c,v 1.280 2015/02/03 17:38:24 roberto Exp $
> ** $Id: lauxlib.c,v 1.284 2015/11/19 19:16:22 roberto Exp $
36,37c36,37
< #define LEVELS1 12 /* size of the first part of the stack */
< #define LEVELS2 10 /* size of the second part of the stack */
> #define LEVELS1 10 /* size of the first part of the stack */
> #define LEVELS2 11 /* size of the second part of the stack */
110c110
< static int countlevels (lua_State *L) {
> static int lastlevel (lua_State *L) {
129,131c129,133
< int numlevels = countlevels(L1);
< int mark = (numlevels > LEVELS1 + LEVELS2) ? LEVELS1 : 0;
< if (msg) lua_pushfstring(L, "%s\n", msg);
> int last = lastlevel(L1);
> int n1 = (last - level > LEVELS1 + LEVELS2) ? LEVELS1 : -1;
> if (msg)
> lua_pushfstring(L, "%s\n", msg);
> luaL_checkstack(L, 10, NULL);
134c136
< if (level == mark) { /* too many levels? */
> if (n1-- == 0) { /* too many levels? */
136c138
< level = numlevels - LEVELS2; /* and skip to last ones */
> level = last - LEVELS2 + 1; /* and skip to last ones */
292c294
< lua_newtable(L); /* create metatable */
> lua_createtable(L, 0, 2); /* create metatable */
437a440,480
> /* userdata to box arbitrary data */
> typedef struct UBox {
> void *box;
> size_t bsize;
> } UBox;
>
>
> static void *resizebox (lua_State *L, int idx, size_t newsize) {
> void *ud;
> lua_Alloc allocf = lua_getallocf(L, &ud);
> UBox *box = (UBox *)lua_touserdata(L, idx);
> void *temp = allocf(ud, box->box, box->bsize, newsize);
> if (temp == NULL && newsize > 0) { /* allocation error? */
> resizebox(L, idx, 0); /* free buffer */
> luaL_error(L, "not enough memory for buffer allocation");
> }
> box->box = temp;
> box->bsize = newsize;
> return temp;
> }
>
>
> static int boxgc (lua_State *L) {
> resizebox(L, 1, 0);
> return 0;
> }
>
>
> static void *newbox (lua_State *L, size_t newsize) {
> UBox *box = (UBox *)lua_newuserdata(L, sizeof(UBox));
> box->box = NULL;
> box->bsize = 0;
> if (luaL_newmetatable(L, "LUABOX")) { /* creating metatable? */
> lua_pushcfunction(L, boxgc);
> lua_setfield(L, -2, "__gc"); /* metatable.__gc = boxgc */
> }
> lua_setmetatable(L, -2);
> return resizebox(L, -1, newsize);
> }
>
>
458,460d500
< newbuff = (char *)lua_newuserdata(L, newsize * sizeof(char));
< /* move content to new buffer */
< memcpy(newbuff, B->b, B->n * sizeof(char));
462c502,506
< lua_remove(L, -2); /* remove old buffer */
> newbuff = (char *)resizebox(L, -1, newsize);
> else { /* no buffer yet */
> newbuff = (char *)newbox(L, newsize);
> memcpy(newbuff, B->b, B->n * sizeof(char)); /* copy original content */
> }
471,473c515,519
< char *b = luaL_prepbuffsize(B, l);
< memcpy(b, s, l * sizeof(char));
< luaL_addsize(B, l);
> if (l > 0) { /* avoid 'memcpy' when 's' can be NULL */
> char *b = luaL_prepbuffsize(B, l);
> memcpy(b, s, l * sizeof(char));
> luaL_addsize(B, l);
> }
485,486c531,534
< if (buffonstack(B))
< lua_remove(L, -2); /* remove old buffer */
> if (buffonstack(B)) {
> resizebox(L, -2, 0); /* delete old buffer */
> lua_remove(L, -2); /* remove its header from the stack */
> }
608c656
< const char *p = "\xEF\xBB\xBF"; /* Utf8 BOM mark */
> const char *p = "\xEF\xBB\xBF"; /* UTF-8 BOM mark */
src/lauxlib.h
2c2
< ** $Id: lauxlib.h,v 1.128 2014/10/29 16:11:17 roberto Exp $
> ** $Id: lauxlib.h,v 1.129 2015/11/23 11:29:43 roberto Exp $
68c68
< /* pre-defined references */
> /* predefined references */
src/lbaselib.c
2c2
< ** $Id: lbaselib.c,v 1.310 2015/03/28 19:14:47 roberto Exp $
> ** $Id: lbaselib.c,v 1.312 2015/10/29 15:21:04 roberto Exp $
89,90c89,90
< luaL_checktype(L, 1, LUA_TSTRING); /* before 'luaL_checklstring'! */
< s = luaL_checklstring(L, 1, &l);
> luaL_checktype(L, 1, LUA_TSTRING); /* no numbers as strings */
> s = lua_tolstring(L, 1, &l);
201,203d200
< /*
< ** This function has all type names as upvalues, to maximize performance.
< */
205,206c202,204
< luaL_checkany(L, 1);
< lua_pushvalue(L, lua_upvalueindex(lua_type(L, 1) + 1));
> int t = lua_type(L, 1);
> luaL_argcheck(L, t != LUA_TNONE, 1, "value expected");
> lua_pushstring(L, lua_typename(L, t));
246,257c244
< ** Traversal function for 'ipairs' for raw tables
< */
< static int ipairsaux_raw (lua_State *L) {
< lua_Integer i = luaL_checkinteger(L, 2) + 1;
< luaL_checktype(L, 1, LUA_TTABLE);
< lua_pushinteger(L, i);
< return (lua_rawgeti(L, 1, i) == LUA_TNIL) ? 1 : 2;
< }
<
<
< /*
< ** Traversal function for 'ipairs' for tables with metamethods
> ** Traversal function for 'ipairs'
272,273d258
< lua_CFunction iter = (luaL_getmetafield(L, 1, "__index") != LUA_TNIL)
< ? ipairsaux : ipairsaux_raw;
275c260
< return pairsmeta(L, "__ipairs", 1, iter);
> return pairsmeta(L, "__ipairs", 1, ipairsaux);
278c263
< lua_pushcfunction(L, iter); /* iteration function */
> lua_pushcfunction(L, ipairsaux); /* iteration function */
492a478
> {"type", luaB_type},
495d480
< {"type", NULL},
503d487
< int i;
513,517d496
< /* set function 'type' with proper upvalues */
< for (i = 0; i < LUA_NUMTAGS; i++) /* push all type names as upvalues */
< lua_pushstring(L, lua_typename(L, i));
< lua_pushcclosure(L, luaB_type, LUA_NUMTAGS);
< lua_setfield(L, -2, "type");
src/lbitlib.c
2c2
< ** $Id: lbitlib.c,v 1.28 2014/11/02 19:19:04 roberto Exp $
> ** $Id: lbitlib.c,v 1.30 2015/11/11 19:08:09 roberto Exp $
21a22,25
> #define pushunsigned(L,n) lua_pushinteger(L, (lua_Integer)(n))
> #define checkunsigned(L,i) ((lua_Unsigned)luaL_checkinteger(L,i))
>
>
49c53
< r &= luaL_checkunsigned(L, i);
> r &= checkunsigned(L, i);
56c60
< lua_pushunsigned(L, r);
> pushunsigned(L, r);
72,73c76,77
< r |= luaL_checkunsigned(L, i);
< lua_pushunsigned(L, trim(r));
> r |= checkunsigned(L, i);
> pushunsigned(L, trim(r));
82,83c86,87
< r ^= luaL_checkunsigned(L, i);
< lua_pushunsigned(L, trim(r));
> r ^= checkunsigned(L, i);
> pushunsigned(L, trim(r));
89,90c93,94
< lua_Unsigned r = ~luaL_checkunsigned(L, 1);
< lua_pushunsigned(L, trim(r));
> lua_Unsigned r = ~checkunsigned(L, 1);
> pushunsigned(L, trim(r));
107c111
< lua_pushunsigned(L, r);
> pushunsigned(L, r);
113c117
< return b_shift(L, luaL_checkunsigned(L, 1), luaL_checkinteger(L, 2));
> return b_shift(L, checkunsigned(L, 1), luaL_checkinteger(L, 2));
118c122
< return b_shift(L, luaL_checkunsigned(L, 1), -luaL_checkinteger(L, 2));
> return b_shift(L, checkunsigned(L, 1), -luaL_checkinteger(L, 2));
123c127
< lua_Unsigned r = luaL_checkunsigned(L, 1);
> lua_Unsigned r = checkunsigned(L, 1);
131c135
< lua_pushunsigned(L, r);
> pushunsigned(L, r);
138c142
< lua_Unsigned r = luaL_checkunsigned(L, 1);
> lua_Unsigned r = checkunsigned(L, 1);
143c147
< lua_pushunsigned(L, trim(r));
> pushunsigned(L, trim(r));
178c182
< lua_Unsigned r = trim(luaL_checkunsigned(L, 1));
> lua_Unsigned r = trim(checkunsigned(L, 1));
181c185
< lua_pushunsigned(L, r);
> pushunsigned(L, r);
188,189c192,193
< lua_Unsigned r = trim(luaL_checkunsigned(L, 1));
< lua_Unsigned v = luaL_checkunsigned(L, 2);
> lua_Unsigned r = trim(checkunsigned(L, 1));
> lua_Unsigned v = trim(checkunsigned(L, 2));
191,194c195,197
< int m = mask(w);
< v &= m; /* erase bits outside given width */
< r = (r & ~(m << f)) | (v << f);
< lua_pushunsigned(L, r);
> lua_Unsigned m = mask(w);
> r = (r & ~(m << f)) | ((v & m) << f);
> pushunsigned(L, r);
src/lcode.c
2c2
< ** $Id: lcode.c,v 2.101 2015/04/29 18:24:11 roberto Exp $
> ** $Id: lcode.c,v 2.103 2015/11/19 19:16:22 roberto Exp $
40c40
< if (e->t != NO_JUMP || e->f != NO_JUMP)
> if (hasjumps(e))
819c819
< e1->k = VRELOCABLE; /* all those operations are relocable */
> e1->k = VRELOCABLE; /* all those operations are relocatable */
src/ldblib.c
2c2
< ** $Id: ldblib.c,v 1.149 2015/02/19 17:06:21 roberto Exp $
> ** $Id: ldblib.c,v 1.151 2015/11/23 11:29:43 roberto Exp $
31,32c31,32
< ** If L1 != L, L1 can be in any state, and therefore there is no
< ** garanties about its stack space; any push in L1 must be
> ** If L1 != L, L1 can be in any state, and therefore there are no
> ** guarantees about its stack space; any push in L1 must be
src/ldebug.c
2c2
< ** $Id: ldebug.c,v 2.115 2015/05/22 17:45:56 roberto Exp $
> ** $Id: ldebug.c,v 2.117 2015/11/02 18:48:07 roberto Exp $
621c621
< luaD_call(L, L->top - 2, 1, 0); /* call it */
> luaD_callnoyield(L, L->top - 2, 1); /* call it */
643c643
< int counthook = ((mask & LUA_MASKCOUNT) && L->hookcount == 0);
> int counthook = (--L->hookcount == 0 && (mask & LUA_MASKCOUNT));
645a646,647
> else if (!(mask & LUA_MASKLINE))
> return; /* no line hook and count != 0; nothing to be done */
src/ldo.c
2c2
< ** $Id: ldo.c,v 2.138 2015/05/22 17:48:19 roberto Exp $
> ** $Id: ldo.c,v 2.150 2015/11/19 19:16:22 roberto Exp $
152a153,157
> /*
> ** {==================================================================
> ** Stack reallocation
> ** ===================================================================
> */
224,227c229,230
< if (inuse > LUAI_MAXSTACK || /* still handling stack overflow? */
< goodsize >= L->stacksize) /* would grow instead of shrink? */
< condmovestack(L); /* don't change stack (change only for debugging) */
< else
> if (inuse <= LUAI_MAXSTACK && /* not handling stack overflow? */
> goodsize < L->stacksize) /* trying to shrink? */
228a232,233
> else
> condmovestack(L,,); /* don't change stack (change only for debugging) */
231a237,244
> void luaD_inctop (lua_State *L) {
> luaD_checkstack(L, 1);
> L->top++;
> }
>
> /* }================================================================== */
>
>
276d288
< lua_assert(actual >= nfixargs);
278d289
< luaD_checkstack(L, p->maxstacksize); /* check again for new 'base' */
281c292
< for (i=0; i<nfixargs; i++) {
> for (i = 0; i < nfixargs && i < actual; i++) {
283c294
< setnilvalue(fixed + i);
> setnilvalue(fixed + i); /* erase original copy (for GC) */
284a296,297
> for (; i < nfixargs; i++)
> setnilvalue(L->top++); /* complete missing arguments */
310a324,331
> /* macro to check stack size, preserving 'p' */
> #define checkstackp(L,n,p) \
> luaD_checkstackaux(L, n, \
> ptrdiff_t t__ = savestack(L, p); /* save 'p' */ \
> luaC_checkGC(L), /* stack grow uses memory */ \
> p = restorestack(L, t__)) /* 'pos' part: restore 'p' */
>
>
312c333,337
< ** returns true if function has been executed (C function)
> ** Prepares a function call: checks the stack, creates a new CallInfo
> ** entry, fills in the relevant information, calls hook if needed.
> ** If function is a C function, does the call, too. (Otherwise, leave
> ** the execution ('luaV_execute') to the caller, to allow stackless
> ** calls.) Returns true iff function has been executed (C function).
317,318d341
< int n; /* number of arguments (Lua) or returns (C) */
< ptrdiff_t funcr = savestack(L, func);
319a343,345
> case LUA_TCCL: /* C closure */
> f = clCvalue(func)->f;
> goto Cfunc;
322,327c348,350
< goto Cfunc;
< case LUA_TCCL: { /* C closure */
< f = clCvalue(func)->f;
< Cfunc:
< luaC_checkGC(L); /* stack grow uses memory */
< luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */
> Cfunc: {
> int n; /* number of returns */
> checkstackp(L, LUA_MINSTACK, func); /* ensure minimum stack size */
330c353
< ci->func = restorestack(L, funcr);
> ci->func = func;
340c363
< luaD_poscall(L, L->top - n, n);
> luaD_poscall(L, ci, L->top - n, n);
346,352c369,374
< n = cast_int(L->top - func) - 1; /* number of real arguments */
< luaC_checkGC(L); /* stack grow uses memory */
< luaD_checkstack(L, p->maxstacksize);
< for (; n < p->numparams; n++)
< setnilvalue(L->top++); /* complete missing arguments */
< if (!p->is_vararg) {
< func = restorestack(L, funcr);
> int n = cast_int(L->top - func) - 1; /* number of real arguments */
> int fsize = p->maxstacksize; /* frame size */
> checkstackp(L, fsize, func);
> if (p->is_vararg != 1) { /* do not use vararg? */
> for (; n < p->numparams; n++)
> setnilvalue(L->top++); /* complete missing arguments */
355c377
< else {
> else
357,358d378
< func = restorestack(L, funcr); /* previous call can change stack */
< }
363c383
< ci->top = base + p->maxstacksize;
> L->top = ci->top = base + fsize;
367d386
< L->top = ci->top;
373,374c392
< luaD_checkstack(L, 1); /* ensure space for metamethod */
< func = restorestack(L, funcr); /* previous call may change stack */
> checkstackp(L, 1, func); /* ensure space for metamethod */
382c400,448
< int luaD_poscall (lua_State *L, StkId firstResult, int nres) {
> /*
> ** Given 'nres' results at 'firstResult', move 'wanted' of them to 'res'.
> ** Handle most typical cases (zero results for commands, one result for
> ** expressions, multiple results for tail calls/single parameters)
> ** separated.
> */
> static int moveresults (lua_State *L, const TValue *firstResult, StkId res,
> int nres, int wanted) {
> switch (wanted) { /* handle typical cases separately */
> case 0: break; /* nothing to move */
> case 1: { /* one result needed */
> if (nres == 0) /* no results? */
> firstResult = luaO_nilobject; /* adjust with nil */
> setobjs2s(L, res, firstResult); /* move it to proper place */
> break;
> }
> case LUA_MULTRET: {
> int i;
> for (i = 0; i < nres; i++) /* move all results to correct place */
> setobjs2s(L, res + i, firstResult + i);
> L->top = res + nres;
> return 0; /* wanted == LUA_MULTRET */
> }
> default: {
> int i;
> if (wanted <= nres) { /* enough results? */
> for (i = 0; i < wanted; i++) /* move wanted results to correct place */
> setobjs2s(L, res + i, firstResult + i);
> }
> else { /* not enough results; use all of them plus nils */
> for (i = 0; i < nres; i++) /* move all results to correct place */
> setobjs2s(L, res + i, firstResult + i);
> for (; i < wanted; i++) /* complete wanted number of results */
> setnilvalue(res + i);
> }
> break;
> }
> }
> L->top = res + wanted; /* top points after the last result */
> return 1;
> }
>
>
> /*
> ** Finishes a function call: calls hook if necessary, removes CallInfo,
> ** moves current number of results to proper place; returns 0 iff call
> ** wanted multiple (variable number of) results.
> */
> int luaD_poscall (lua_State *L, CallInfo *ci, StkId firstResult, int nres) {
384,385c450
< int wanted, i;
< CallInfo *ci = L->ci;
> int wanted = ci->nresults;
395d459
< wanted = ci->nresults;
397,403c461,477
< /* move results to correct place */
< for (i = wanted; i != 0 && nres-- > 0; i--)
< setobjs2s(L, res++, firstResult++);
< while (i-- > 0)
< setnilvalue(res++);
< L->top = res;
< return (wanted - LUA_MULTRET); /* 0 iff wanted == LUA_MULTRET */
> /* move results to proper place */
> return moveresults(L, firstResult, res, nres, wanted);
> }
>
>
> /*
> ** Check appropriate error for stack overflow ("regular" overflow or
> ** overflow while handling stack overflow). If 'nCalls' is larger than
> ** LUAI_MAXCCALLS (which means it is handling a "regular" overflow) but
> ** smaller than 9/8 of LUAI_MAXCCALLS, does not report an error (to
> ** allow overflow handling to work)
> */
> static void stackerror (lua_State *L) {
> if (L->nCcalls == LUAI_MAXCCALLS)
> luaG_runerror(L, "C stack overflow");
> else if (L->nCcalls >= (LUAI_MAXCCALLS + (LUAI_MAXCCALLS>>3)))
> luaD_throw(L, LUA_ERRERR); /* error while handing stack error */
413,420c487,489
< void luaD_call (lua_State *L, StkId func, int nResults, int allowyield) {
< if (++L->nCcalls >= LUAI_MAXCCALLS) {
< if (L->nCcalls == LUAI_MAXCCALLS)
< luaG_runerror(L, "C stack overflow");
< else if (L->nCcalls >= (LUAI_MAXCCALLS + (LUAI_MAXCCALLS>>3)))
< luaD_throw(L, LUA_ERRERR); /* error while handing stack error */
< }
< if (!allowyield) L->nny++;
> void luaD_call (lua_State *L, StkId func, int nResults) {
> if (++L->nCcalls >= LUAI_MAXCCALLS)
> stackerror(L);
423d491
< if (!allowyield) L->nny--;
428a497,506
> ** Similar to 'luaD_call', but does not allow yields during the call
> */
> void luaD_callnoyield (lua_State *L, StkId func, int nResults) {
> L->nny++;
> luaD_call(L, func, nResults);
> L->nny--;
> }
>
>
> /*
452c530
< luaD_poscall(L, L->top - n, n);
> luaD_poscall(L, ci, L->top - n, n);
563c641
< luaD_poscall(L, firstArg, n); /* finish 'luaD_precall' */
> luaD_poscall(L, ci, firstArg, n); /* finish 'luaD_precall' */
573c651
< int oldnny = L->nny; /* save "number of non-yieldable" calls */
> unsigned short oldnny = L->nny; /* save "number of non-yieldable" calls */
687c765
< cl = luaU_undump(L, p->z, &p->buff, p->name);
> cl = luaU_undump(L, p->z, p->name);
src/ldo.h
2c2
< ** $Id: ldo.h,v 2.22 2015/05/22 17:48:19 roberto Exp $
> ** $Id: ldo.h,v 2.28 2015/11/23 11:29:43 roberto Exp $
16,17c16,28
< #define luaD_checkstack(L,n) if (L->stack_last - L->top <= (n)) \
< luaD_growstack(L, n); else condmovestack(L);
> /*
> ** Macro to check stack size and grow stack if needed. Parameters
> ** 'pre'/'pos' allow the macro to preserve a pointer into the
> ** stack across reallocations, doing the work only when needed.
> ** 'condmovestack' is used in heavy tests to force a stack reallocation
> ** at every check.
> */
> #define luaD_checkstackaux(L,n,pre,pos) \
> if (L->stack_last - L->top <= (n)) \
> { pre; luaD_growstack(L, n); pos; } else { condmovestack(L,pre,pos); }
>
> /* In general, 'pre'/'pos' are empty (nothing to save) */
> #define luaD_checkstack(L,n) luaD_checkstackaux(L,n,,)
20d30
< #define incr_top(L) {L->top++; luaD_checkstack(L,0);}
33,34c43,44
< LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults,
< int allowyield);
> LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults);
> LUAI_FUNC void luaD_callnoyield (lua_State *L, StkId func, int nResults);
37c47,48
< LUAI_FUNC int luaD_poscall (lua_State *L, StkId firstResult, int nres);
> LUAI_FUNC int luaD_poscall (lua_State *L, CallInfo *ci, StkId firstResult,
> int nres);
40a52
> LUAI_FUNC void luaD_inctop (lua_State *L);
src/ldump.c
2c2
< ** $Id: ldump.c,v 2.36 2015/03/30 15:43:51 roberto Exp $
> ** $Id: ldump.c,v 2.37 2015/10/08 15:53:49 roberto Exp $
41c41
< if (D->status == 0) {
> if (D->status == 0 && size > 0) {
src/lgc.c
2c2
< ** $Id: lgc.c,v 2.205 2015/03/25 13:42:19 roberto Exp $
> ** $Id: lgc.c,v 2.210 2015/11/03 18:10:44 roberto Exp $
117,118c117,123
< ** if key is not marked, mark its entry as dead (therefore removing it
< ** from the table)
> ** If key is not marked, mark its entry as dead. This allows key to be
> ** collected, but keeps its entry in the table. A dead node is needed
> ** when Lua looks up for a key (it may be part of a chain) and when
> ** traversing a weak table (key might be removed from the table during
> ** traversal). Other places never manipulate dead keys, because its
> ** associated nil value is enough to signal that the entry is logically
> ** empty.
545c550,551
< return (sizeof(lua_State) + sizeof(TValue) * th->stacksize);
> return (sizeof(lua_State) + sizeof(TValue) * th->stacksize +
> sizeof(CallInfo) * th->nci);
772c778
< ** If possible, free concatenation buffer and shrink string table
> ** If possible, shrink string table
777d782
< luaZ_freebuffer(L, &g->buff); /* free concatenation buffer */
800c805
< luaD_call(L, L->top - 2, 0, 0);
> luaD_callnoyield(L, L->top - 2, 0);
1117,1119c1122,1127
< debt = (debt / STEPMULADJ) + 1;
< debt = (debt < MAX_LMEM / stepmul) ? debt * stepmul : MAX_LMEM;
< return debt;
> if (debt <= 0) return 0; /* minimal debt */
> else {
> debt = (debt / STEPMULADJ) + 1;
> debt = (debt < MAX_LMEM / stepmul) ? debt * stepmul : MAX_LMEM;
> return debt;
> }
src/lgc.h
2c2
< ** $Id: lgc.h,v 2.86 2014/10/25 11:50:46 roberto Exp $
> ** $Id: lgc.h,v 2.90 2015/10/21 18:15:15 roberto Exp $
104,123c104,132
< #define luaC_condGC(L,c) \
< {if (G(L)->GCdebt > 0) {c;}; condchangemem(L);}
< #define luaC_checkGC(L) luaC_condGC(L, luaC_step(L);)
<
<
< #define luaC_barrier(L,p,v) { \
< if (iscollectable(v) && isblack(p) && iswhite(gcvalue(v))) \
< luaC_barrier_(L,obj2gco(p),gcvalue(v)); }
<
< #define luaC_barrierback(L,p,v) { \
< if (iscollectable(v) && isblack(p) && iswhite(gcvalue(v))) \
< luaC_barrierback_(L,p); }
<
< #define luaC_objbarrier(L,p,o) { \
< if (isblack(p) && iswhite(o)) \
< luaC_barrier_(L,obj2gco(p),obj2gco(o)); }
<
< #define luaC_upvalbarrier(L,uv) \
< { if (iscollectable((uv)->v) && !upisopen(uv)) \
< luaC_upvalbarrier_(L,uv); }
> /*
> ** Does one step of collection when debt becomes positive. 'pre'/'pos'
> ** allows some adjustments to be done only when needed. macro
> ** 'condchangemem' is used only for heavy tests (forcing a full
> ** GC cycle on every opportunity)
> */
> #define luaC_condGC(L,pre,pos) \
> { if (G(L)->GCdebt > 0) { pre; luaC_step(L); pos;}; \
> condchangemem(L,pre,pos); }
>
> /* more often than not, 'pre'/'pos' are empty */
> #define luaC_checkGC(L) luaC_condGC(L,,)
>
>
> #define luaC_barrier(L,p,v) ( \
> (iscollectable(v) && isblack(p) && iswhite(gcvalue(v))) ? \
> luaC_barrier_(L,obj2gco(p),gcvalue(v)) : cast_void(0))
>
> #define luaC_barrierback(L,p,v) ( \
> (iscollectable(v) && isblack(p) && iswhite(gcvalue(v))) ? \
> luaC_barrierback_(L,p) : cast_void(0))
>
> #define luaC_objbarrier(L,p,o) ( \
> (isblack(p) && iswhite(o)) ? \
> luaC_barrier_(L,obj2gco(p),obj2gco(o)) : cast_void(0))
>
> #define luaC_upvalbarrier(L,uv) ( \
> (iscollectable((uv)->v) && !upisopen(uv)) ? \
> luaC_upvalbarrier_(L,uv) : cast_void(0))
src/liolib.c
2c2
< ** $Id: liolib.c,v 2.144 2015/04/03 18:41:57 roberto Exp $
> ** $Id: liolib.c,v 2.148 2015/11/23 11:36:11 roberto Exp $
26c26
< #if !defined(l_checkmode)
>
29d28
< ** Check whether 'mode' matches '[rwa]%+?b?'.
32a32,39
> #if !defined(l_checkmode)
>
> /* accepted extensions to 'mode' in 'fopen' */
> #if !defined(L_MODEEXT)
> #define L_MODEEXT "b"
> #endif
>
> /* Check whether 'mode' matches '[rwa]%+?[L_MODEEXT]*' */
35,37c42,43
< (*mode != '+' || ++mode) && /* skip if char is '+' */ \
< (*mode != 'b' || ++mode) && /* skip if char is 'b' */ \
< (*mode == '\0'))
> (*mode != '+' || (++mode, 1)) && /* skip if char is '+' */ \
> (strspn(mode, L_MODEEXT) == strlen(mode)))
179c185
< ** file is not left opened.
> ** handle is in a consistent state.
320a327,332
> /*
> ** maximum number of arguments to 'f:lines'/'io.lines' (it + 3 must fit
> ** in the limit for upvalues of a closure)
> */
> #define MAXARGLINE 250
>
322a335
> luaL_argcheck(L, n <= MAXARGLINE, MAXARGLINE + 2, "too many arguments");
465c478
< char *buff = luaL_prepbuffer(&b); /* pre-allocate buffer */
> char *buff = luaL_prepbuffer(&b); /* preallocate buffer */
486c499
< char *p = luaL_prepbuffsize(&b, LUAL_BUFFERSIZE);
> char *p = luaL_prepbuffer(&b);
src/llex.c
2c2
< ** $Id: llex.c,v 2.93 2015/05/22 17:45:56 roberto Exp $
> ** $Id: llex.c,v 2.95 2015/11/19 19:16:22 roberto Exp $
223,224d222
< #define buff2num(b,o) (luaO_str2num(luaZ_buffer(b), o) != 0)
<
233c231
< if (!buff2num(ls->buff, o)) {
> if (luaO_str2num(luaZ_buffer(ls->buff), o) == 0) {
265c263
< if (!buff2num(ls->buff, &obj)) /* format error? */
> if (luaO_str2num(luaZ_buffer(ls->buff), &obj) == 0) /* format error? */
280c278
< ** skip a sequence '[=*[' or ']=*]'; if sequence is wellformed, return
> ** skip a sequence '[=*[' or ']=*]'; if sequence is well formed, return
src/llimits.h
2c2
< ** $Id: llimits.h,v 1.135 2015/06/09 14:21:00 roberto Exp $
> ** $Id: llimits.h,v 1.141 2015/11/19 19:16:22 roberto Exp $
67c67,73
< typedef union { double u; void *s; lua_Integer i; long l; } L_Umaxalign;
> typedef union {
> lua_Number n;
> double u;
> void *s;
> lua_Integer i;
> long l;
> } L_Umaxalign;
81c87
< #define lua_longassert(c) { if (!(c)) lua_assert(0); }
> #define lua_longassert(c) ((c) ? (void)0 : lua_assert(0))
187,190c193,199
< ** Size of cache for strings in the API (better be a prime)
< */
< #if !defined(STRCACHE_SIZE)
< #define STRCACHE_SIZE 127
> ** Size of cache for strings in the API. 'N' is the number of
> ** sets (better be a prime) and "M" is the size of each set (M == 1
> ** makes a direct cache.)
> */
> #if !defined(STRCACHE_N)
> #define STRCACHE_N 53
> #define STRCACHE_M 2
201c210
< ** macros that are executed whenether program enters the Lua core
> ** macros that are executed whenever program enters the Lua core
300c309
< #define condmovestack(L) ((void)0)
> #define condmovestack(L,pre,pos) ((void)0)
303c312,313
< #define condmovestack(L) luaD_reallocstack((L), (L)->stacksize)
> #define condmovestack(L,pre,pos) \
> { int sz_ = (L)->stacksize; pre; luaD_reallocstack((L), sz_); pos; }
307c317
< #define condchangemem(L) condmovestack(L)
> #define condchangemem(L,pre,pos) ((void)0)
309,310c319,320
< #define condchangemem(L) \
< ((void)(!(G(L)->gcrunning) || (luaC_fullgc(L, 0), 1)))
> #define condchangemem(L,pre,pos) \
> { if (G(L)->gcrunning) { pre; luaC_fullgc(L, 0); pos; } }
src/lmathlib.c
2c2
< ** $Id: lmathlib.c,v 1.115 2015/03/12 14:04:04 roberto Exp $
> ** $Id: lmathlib.c,v 1.117 2015/10/02 15:39:23 roberto Exp $
42c42
< if (n < 0) n = (lua_Integer)(0u - n);
> if (n < 0) n = (lua_Integer)(0u - (lua_Unsigned)n);
276c276
< (void)rand(); /* discard first value to avoid undesirable correlations */
> (void)l_rand(); /* discard first value to avoid undesirable correlations */
src/loadlib.c
2c2
< ** $Id: loadlib.c,v 1.126 2015/02/16 13:14:33 roberto Exp $
> ** $Id: loadlib.c,v 1.127 2015/11/23 11:30:45 roberto Exp $
735c735
< /* fill it with pre-defined searchers */
> /* fill it with predefined searchers */
src/lobject.c
2c2
< ** $Id: lobject.c,v 2.104 2015/04/11 18:30:08 roberto Exp $
> ** $Id: lobject.c,v 2.108 2015/11/02 16:09:30 roberto Exp $
58,60c58
< int e = (x >> 3) & 0x1f;
< if (e == 0) return x;
< else return ((x & 7) + 8) << (e - 1);
> return (x < 8) ? x : ((x & 7) + 8) << ((x >> 3) - 1);
336c334
< len = lua_integer2str(buff, ivalue(obj));
> len = lua_integer2str(buff, sizeof(buff), ivalue(obj));
338c336
< len = lua_number2str(buff, fltvalue(obj));
> len = lua_number2str(buff, sizeof(buff), fltvalue(obj));
351c349,350
< setsvalue2s(L, L->top++, luaS_newlstr(L, str, l));
> setsvalue2s(L, L->top, luaS_newlstr(L, str, l));
> luaD_inctop(L);
362d360
< luaD_checkstack(L, 2); /* fmt + item */
380,382c378,379
< setivalue(L->top++, va_arg(argp, int));
< luaO_tostring(L, L->top - 1);
< break;
> setivalue(L->top, va_arg(argp, int));
> goto top2str;
385,387c382,383
< setivalue(L->top++, cast(lua_Integer, va_arg(argp, l_uacInt)));
< luaO_tostring(L, L->top - 1);
< break;
> setivalue(L->top, cast(lua_Integer, va_arg(argp, l_uacInt)));
> goto top2str;
390c386,388
< setfltvalue(L->top++, cast_num(va_arg(argp, l_uacNumber)));
> setfltvalue(L->top, cast_num(va_arg(argp, l_uacNumber)));
> top2str:
> luaD_inctop(L);
396c394
< int l = sprintf(buff, "%p", va_arg(argp, void *));
> int l = l_sprintf(buff, sizeof(buff), "%p", va_arg(argp, void *));
src/lobject.h
2c2
< ** $Id: lobject.h,v 2.111 2015/06/09 14:21:42 roberto Exp $
> ** $Id: lobject.h,v 2.116 2015/11/03 18:33:10 roberto Exp $
22,23c22,23
< #define LUA_TPROTO LUA_NUMTAGS
< #define LUA_TDEADKEY (LUA_NUMTAGS+1)
> #define LUA_TPROTO LUA_NUMTAGS /* function prototypes */
> #define LUA_TDEADKEY (LUA_NUMTAGS+1) /* removed keys in tables */
91,97d90
< /*
< ** Union of all Lua values
< */
< typedef union Value Value;
<
<
<
103a97,109
> /*
> ** Union of all Lua values
> */
> typedef union Value {
> GCObject *gc; /* collectable objects */
> void *p; /* light userdata */
> int b; /* booleans */
> lua_CFunction f; /* light C functions */
> lua_Integer i; /* integer numbers */
> lua_Number n; /* float numbers */
> } Value;
>
>
106c112,116
< typedef struct lua_TValue TValue;
>
> typedef struct lua_TValue {
> TValuefields;
> } TValue;
>
180c190
< #define checkliveness(g,obj) \
> #define checkliveness(L,obj) \
182c192
< (righttt(obj) && !isdead(g,gcvalue(obj))))
> (righttt(obj) && (L == NULL || !isdead(G(L),gcvalue(obj)))))
218c228
< checkliveness(G(L),io); }
> checkliveness(L,io); }
223c233
< checkliveness(G(L),io); }
> checkliveness(L,io); }
228c238
< checkliveness(G(L),io); }
> checkliveness(L,io); }
233c243
< checkliveness(G(L),io); }
> checkliveness(L,io); }
238c248
< checkliveness(G(L),io); }
> checkliveness(L,io); }
243c253
< checkliveness(G(L),io); }
> checkliveness(L,io); }
251c261
< (void)L; checkliveness(G(L),io1); }
> (void)L; checkliveness(L,io1); }
267,268d276
< /* to table */
< #define setobj2t setobj
272a281,283
> /* to table (define it as an expression to be used in macros) */
> #define setobj2t(L,o1,o2) ((void)L, *(o1)=*(o2), checkliveness(L,(o1)))
>
283,297d293
< union Value {
< GCObject *gc; /* collectable objects */
< void *p; /* light userdata */
< int b; /* booleans */
< lua_CFunction f; /* light C functions */
< lua_Integer i; /* integer numbers */
< lua_Number n; /* float numbers */
< };
<
<
< struct lua_TValue {
< TValuefields;
< };
<
<
332d327
< #define getaddrstr(ts) (cast(char *, (ts)) + sizeof(UTString))
334c329,330
< check_exp(sizeof((ts)->extra), cast(const char*, getaddrstr(ts)))
> check_exp(sizeof((ts)->extra), cast(char *, (ts)) + sizeof(UTString))
>
378c374
< checkliveness(G(L),io); }
> checkliveness(L,io); }
384c380
< checkliveness(G(L),io); }
> checkliveness(L,io); }
414c410
< lu_byte is_vararg;
> lu_byte is_vararg; /* 2: declared vararg; 1: uses vararg */
422,423c418,419
< int linedefined;
< int lastlinedefined;
> int linedefined; /* debug information */
> int lastlinedefined; /* debug information */
492c488
< (void)L; checkliveness(G(L),io_); }
> (void)L; checkliveness(L,io_); }
src/loslib.c
2c2
< ** $Id: loslib.c,v 1.57 2015/04/10 17:41:04 roberto Exp $
> ** $Id: loslib.c,v 1.60 2015/11/19 19:16:22 roberto Exp $
57c57,62
< #define l_checktime(L,a) ((time_t)luaL_checkinteger(L,a))
>
> static time_t l_checktime (lua_State *L, int arg) {
> lua_Integer t = luaL_checkinteger(L, arg);
> luaL_argcheck(L, (time_t)t == t, arg, "time out-of-bounds");
> return (time_t)t;
> }
201,206c206,218
< static int getfield (lua_State *L, const char *key, int d) {
< int res, isnum;
< lua_getfield(L, -1, key);
< res = (int)lua_tointegerx(L, -1, &isnum);
< if (!isnum) {
< if (d < 0)
> /* maximum value for date fields (to avoid arithmetic overflows with 'int') */
> #if !defined(L_MAXDATEFIELD)
> #define L_MAXDATEFIELD (INT_MAX / 2)
> #endif
>
> static int getfield (lua_State *L, const char *key, int d, int delta) {
> int isnum;
> int t = lua_getfield(L, -1, key);
> lua_Integer res = lua_tointegerx(L, -1, &isnum);
> if (!isnum) { /* field is not a number? */
> if (t != LUA_TNIL) /* some other value? */
> return luaL_error(L, "field '%s' not an integer", key);
> else if (d < 0) /* absent field; no default? */
209a222,226
> else {
> if (!(-L_MAXDATEFIELD <= res && res <= L_MAXDATEFIELD))
> return luaL_error(L, "field '%s' out-of-bounds", key);
> res -= delta;
> }
211c228
< return res;
> return (int)res;
238a256,259
> /* maximum size for an individual 'strftime' item */
> #define SIZETIMEFMT 250
>
>
250,251c271,272
< lua_pushnil(L);
< else if (strcmp(s, "*t") == 0) {
> luaL_error(L, "time result cannot be represented in this installation");
> if (strcmp(s, "*t") == 0) {
269c290
< if (*s != '%') /* no conversion specifier? */
> if (*s != '%') /* not a conversion specifier? */
273c294
< char buff[200]; /* should be big enough for any conversion result */
> char *buff = luaL_prepbuffsize(&b, SIZETIMEFMT);
275,276c296,297
< reslen = strftime(buff, sizeof(buff), cc, stm);
< luaL_addlstring(&b, buff, reslen);
> reslen = strftime(buff, SIZETIMEFMT, cc, stm);
> luaL_addsize(&b, reslen);
293,298c314,319
< ts.tm_sec = getfield(L, "sec", 0);
< ts.tm_min = getfield(L, "min", 0);
< ts.tm_hour = getfield(L, "hour", 12);
< ts.tm_mday = getfield(L, "day", -1);
< ts.tm_mon = getfield(L, "month", -1) - 1;
< ts.tm_year = getfield(L, "year", -1) - 1900;
> ts.tm_sec = getfield(L, "sec", 0, 0);
> ts.tm_min = getfield(L, "min", 0, 0);
> ts.tm_hour = getfield(L, "hour", 12, 0);
> ts.tm_mday = getfield(L, "day", -1, 0);
> ts.tm_mon = getfield(L, "month", -1, 1);
> ts.tm_year = getfield(L, "year", -1, 1900);
302,307c323,325
< if (t != (time_t)(l_timet)t)
< luaL_error(L, "time result cannot be represented in this Lua installation");
< else if (t == (time_t)(-1))
< lua_pushnil(L);
< else
< l_pushtime(L, t);
> if (t != (time_t)(l_timet)t || t == (time_t)(-1))
> luaL_error(L, "time result cannot be represented in this installation");
> l_pushtime(L, t);
src/lparser.c
2c2
< ** $Id: lparser.c,v 2.147 2014/12/27 20:31:43 roberto Exp $
> ** $Id: lparser.c,v 2.149 2015/11/02 16:09:30 roberto Exp $
763c763
< f->is_vararg = 1;
> f->is_vararg = 2; /* declared vararg */
958a959
> fs->f->is_vararg = 1; /* function actually uses vararg */
1613c1614
< fs->f->is_vararg = 1; /* main function is always vararg */
> fs->f->is_vararg = 2; /* main function is always declared vararg */
1629c1630
< incr_top(L);
> luaD_inctop(L);
1632c1633
< incr_top(L);
> luaD_inctop(L);
src/lstate.c
2c2
< ** $Id: lstate.c,v 2.128 2015/03/04 13:31:21 roberto Exp $
> ** $Id: lstate.c,v 2.133 2015/11/13 12:16:51 roberto Exp $
79c79
< memcpy(buff + p, &t, sizeof(t)); p += sizeof(t); }
> memcpy(b + p, &t, sizeof(t)); p += sizeof(t); }
96c96
< ** invariant
> ** invariant (and avoiding underflows in 'totalbytes')
99c99,103
< g->totalbytes -= (debt - g->GCdebt);
> l_mem tb = gettotalbytes(g);
> lua_assert(tb > 0);
> if (debt < tb - MAX_LMEM)
> debt = tb - MAX_LMEM; /* will make 'totalbytes == MAX_LMEM' */
> g->totalbytes = tb - debt;
109a114
> L->nci++;
123a129
> L->nci--;
133,136c139,143
< while (ci->next != NULL) { /* while there is 'next' */
< CallInfo *next2 = ci->next->next; /* next's next */
< if (next2 == NULL) break;
< luaM_free(L, ci->next); /* remove next */
> CallInfo *next2; /* next's next */
> /* while there are two nexts */
> while (ci->next != NULL && (next2 = ci->next->next) != NULL) {
> luaM_free(L, ci->next); /* free next */
> L->nci--;
139c146
< ci = next2;
> ci = next2; /* keep next's next */
168a176
> lua_assert(L->nci == 0);
216a225
> L->nci = 0;
240d248
< luaZ_freebuffer(L, &g->buff);
309d316
< luaZ_initbuffer(L, &g->buff);
src/lstate.h
2c2
< ** $Id: lstate.h,v 2.122 2015/06/01 16:34:37 roberto Exp $
> ** $Id: lstate.h,v 2.128 2015/11/13 12:16:51 roberto Exp $
92,93c92,93
< #define CIST_REENTRY (1<<3) /* call is running on same invocation of
< luaV_execute of previous call */
> #define CIST_FRESH (1<<3) /* call is running on a fresh invocation
> of luaV_execute */
112c112
< lu_mem totalbytes; /* number of bytes currently allocated - GCdebt */
> l_mem totalbytes; /* number of bytes currently allocated - GCdebt */
134d133
< Mbuffer buff; /* temporary buffer for string concatenation */
144c143
< TString *strcache[STRCACHE_SIZE][1]; /* cache for strings in API */
> TString *strcache[STRCACHE_N][STRCACHE_M]; /* cache for strings in API */
152a152
> unsigned short nci; /* number of items in 'ci' list */
215c215
< #define gettotalbytes(g) ((g)->totalbytes + (g)->GCdebt)
> #define gettotalbytes(g) cast(lu_mem, (g)->totalbytes + (g)->GCdebt)
src/lstring.c
2c2
< ** $Id: lstring.c,v 2.49 2015/06/01 16:34:37 roberto Exp $
> ** $Id: lstring.c,v 2.56 2015/11/23 11:32:51 roberto Exp $
51d50
< size_t l1;
53,54c52,53
< for (l1 = l; l1 >= step; l1 -= step)
< h = h ^ ((h<<5) + (h>>2) + cast_byte(str[l1 - 1]));
> for (; l >= step; l -= step)
> h ^= ((h<<5) + (h>>2) + cast_byte(str[l - 1]));
58a58,67
> unsigned int luaS_hashlongstr (TString *ts) {
> lua_assert(ts->tt == LUA_TLNGSTR);
> if (ts->extra == 0) { /* no hash? */
> ts->hash = luaS_hash(getstr(ts), ts->u.lnglen, ts->hash);
> ts->extra = 1; /* now it has its hash */
> }
> return ts->hash;
> }
>
>
95,99c104,109
< int i;
< for (i = 0; i < STRCACHE_SIZE; i++) {
< if (iswhite(g->strcache[i][0])) /* will entry be collected? */
< g->strcache[i][0] = g->memerrmsg; /* replace it with something fixed */
< }
> int i, j;
> for (i = 0; i < STRCACHE_N; i++)
> for (j = 0; j < STRCACHE_M; j++) {
> if (iswhite(g->strcache[i][j])) /* will entry be collected? */
> g->strcache[i][j] = g->memerrmsg; /* replace it with something fixed */
> }
108c118
< int i;
> int i, j;
113,114c123,125
< for (i = 0; i < STRCACHE_SIZE; i++) /* fill cache with valid strings */
< g->strcache[i][0] = g->memerrmsg;
> for (i = 0; i < STRCACHE_N; i++) /* fill cache with valid strings */
> for (j = 0; j < STRCACHE_M; j++)
> g->strcache[i][j] = g->memerrmsg;
122,123c133
< static TString *createstrobj (lua_State *L, const char *str, size_t l,
< int tag, unsigned int h) {
> static TString *createstrobj (lua_State *L, size_t l, int tag, unsigned int h) {
132,133c142,149
< memcpy(getaddrstr(ts), str, l * sizeof(char));
< getaddrstr(ts)[l] = '\0'; /* ending 0 */
> getstr(ts)[l] = '\0'; /* ending 0 */
> return ts;
> }
>
>
> TString *luaS_createlngstrobj (lua_State *L, size_t l) {
> TString *ts = createstrobj(L, l, LUA_TLNGSTR, G(L)->seed);
> ts->u.lnglen = l;
155a172
> lua_assert(str != NULL); /* otherwise 'memcmp'/'memcpy' are undefined */
169c186,187
< ts = createstrobj(L, str, l, LUA_TSHRSTR, h);
> ts = createstrobj(L, l, LUA_TSHRSTR, h);
> memcpy(getstr(ts), str, l * sizeof(char));
186c204
< if (l + 1 > (MAX_SIZE - sizeof(TString))/sizeof(char))
> if (l >= (MAX_SIZE - sizeof(TString))/sizeof(char))
188,189c206,207
< ts = createstrobj(L, str, l, LUA_TLNGSTR, G(L)->seed);
< ts->u.lnglen = l;
> ts = luaS_createlngstrobj(L, l);
> memcpy(getstr(ts), str, l * sizeof(char));
202c220,221
< unsigned int i = point2uint(str) % STRCACHE_SIZE; /* hash */
> unsigned int i = point2uint(str) % STRCACHE_N; /* hash */
> int j;
204,210c223,232
< if (strcmp(str, getstr(p[0])) == 0) /* hit? */
< return p[0]; /* that it is */
< else { /* normal route */
< TString *s = luaS_newlstr(L, str, strlen(str));
< p[0] = s;
< return s;
< }
> for (j = 0; j < STRCACHE_M; j++) {
> if (strcmp(str, getstr(p[j])) == 0) /* hit? */
> return p[j]; /* that is it */
> }
> /* normal route */
> for (j = STRCACHE_M - 1; j > 0; j--)
> p[j] = p[j - 1]; /* move out last element */
> /* new element is first in the list */
> p[0] = luaS_newlstr(L, str, strlen(str));
> return p[0];
src/lstring.h
2c2
< ** $Id: lstring.h,v 1.59 2015/03/25 13:42:19 roberto Exp $
> ** $Id: lstring.h,v 1.61 2015/11/03 15:36:01 roberto Exp $
36a37
> LUAI_FUNC unsigned int luaS_hashlongstr (TString *ts);
44a46
> LUAI_FUNC TString *luaS_createlngstrobj (lua_State *L, size_t l);
src/lstrlib.c
2c2
< ** $Id: lstrlib.c,v 1.229 2015/05/20 17:39:23 roberto Exp $
> ** $Id: lstrlib.c,v 1.239 2015/11/25 16:28:17 roberto Exp $
43a44,45
> #define MAX_SIZET ((size_t)(~(size_t)0))
>
45c47
< (sizeof(size_t) < sizeof(int) ? (~(size_t)0) : (size_t)(INT_MAX))
> (sizeof(size_t) < sizeof(int) ? MAX_SIZET : (size_t)(INT_MAX))
211d212
< int matchdepth; /* control for recursive depth (to avoid C stack overflow) */
215a217,218
> size_t nrep; /* limit to avoid non-linear complexity */
> int matchdepth; /* control for recursive depth (to avoid C stack overflow) */
233a237,247
> /*
> ** parameters to control the maximum number of operators handled in
> ** a match (to avoid non-linear complexity). The maximum will be:
> ** (subject length) * A_REPS + B_REPS
> */
> #if !defined(A_REPS)
> #define A_REPS 4
> #define B_REPS 100000
> #endif
>
>
490a505,506
> if (ms->nrep-- == 0)
> luaL_error(ms->L, "pattern too complex");
586a603,622
> static void prepstate (MatchState *ms, lua_State *L,
> const char *s, size_t ls, const char *p, size_t lp) {
> ms->L = L;
> ms->matchdepth = MAXCCALLS;
> ms->src_init = s;
> ms->src_end = s + ls;
> ms->p_end = p + lp;
> if (ls < (MAX_SIZET - B_REPS) / A_REPS)
> ms->nrep = A_REPS * ls + B_REPS;
> else /* overflow (very long subject) */
> ms->nrep = MAX_SIZET; /* no limit */
> }
>
>
> static void reprepstate (MatchState *ms) {
> ms->level = 0;
> lua_assert(ms->matchdepth == MAXCCALLS);
> }
>
>
614,618c650
< ms.L = L;
< ms.matchdepth = MAXCCALLS;
< ms.src_init = s;
< ms.src_end = s + ls;
< ms.p_end = p + lp;
> prepstate(&ms, L, s, ls, p, lp);
621,622c653
< ms.level = 0;
< lua_assert(ms.matchdepth == MAXCCALLS);
> reprepstate(&ms);
648a680,687
> /* state for 'gmatch' */
> typedef struct GMatchState {
> const char *src; /* current position */
> const char *p; /* pattern */
> MatchState ms; /* match state */
> } GMatchState;
>
>
650,653c689
< MatchState ms;
< size_t ls, lp;
< const char *s = lua_tolstring(L, lua_upvalueindex(1), &ls);
< const char *p = lua_tolstring(L, lua_upvalueindex(2), &lp);
> GMatchState *gm = (GMatchState *)lua_touserdata(L, lua_upvalueindex(3));
655,662c691
< ms.L = L;
< ms.matchdepth = MAXCCALLS;
< ms.src_init = s;
< ms.src_end = s+ls;
< ms.p_end = p + lp;
< for (src = s + (size_t)lua_tointeger(L, lua_upvalueindex(3));
< src <= ms.src_end;
< src++) {
> for (src = gm->src; src <= gm->ms.src_end; src++) {
664,671c693,699
< ms.level = 0;
< lua_assert(ms.matchdepth == MAXCCALLS);
< if ((e = match(&ms, src, p)) != NULL) {
< lua_Integer newstart = e-s;
< if (e == src) newstart++; /* empty match? go at least one position */
< lua_pushinteger(L, newstart);
< lua_replace(L, lua_upvalueindex(3));
< return push_captures(&ms, src, e);
> reprepstate(&gm->ms);
> if ((e = match(&gm->ms, src, gm->p)) != NULL) {
> if (e == src) /* empty match? */
> gm->src =src + 1; /* go at least one position */
> else
> gm->src = e;
> return push_captures(&gm->ms, src, e);
679,682c707,714
< luaL_checkstring(L, 1);
< luaL_checkstring(L, 2);
< lua_settop(L, 2);
< lua_pushinteger(L, 0);
> size_t ls, lp;
> const char *s = luaL_checklstring(L, 1, &ls);
> const char *p = luaL_checklstring(L, 2, &lp);
> GMatchState *gm;
> lua_settop(L, 2); /* keep them on closure to avoid being collected */
> gm = (GMatchState *)lua_newuserdata(L, sizeof(GMatchState));
> prepstate(&gm->ms, L, s, ls, p, lp);
> gm->src = s; gm->p = p;
764,768c796
< ms.L = L;
< ms.matchdepth = MAXCCALLS;
< ms.src_init = src;
< ms.src_end = src+srcl;
< ms.p_end = p + lp;
> prepstate(&ms, L, src, srcl, p, lp);
771,774c799,800
< ms.level = 0;
< lua_assert(ms.matchdepth == MAXCCALLS);
< e = match(&ms, src, p);
< if (e) {
> reprepstate(&ms);
> if ((e = match(&ms, src, p)) != NULL) {
833c859
< static int num2straux (char *buff, lua_Number x) {
> static int num2straux (char *buff, int sz, lua_Number x) {
835c861
< return sprintf(buff, LUA_NUMBER_FMT, x); /* equal to '%g' */
> return l_sprintf(buff, sz, LUA_NUMBER_FMT, x); /* equal to '%g' */
837,839c863,864
< sprintf(buff, LUA_NUMBER_FMT, x);
< strcat(buff, "x0p+0"); /* reuses '0/-0' from 'sprintf'... */
< return strlen(buff);
> /* create "0" or "-0" followed by exponent */
> return l_sprintf(buff, sz, LUA_NUMBER_FMT "x0p+0", x);
858c883,884
< n += sprintf(buff + n, "p%+d", e); /* add exponent */
> n += l_sprintf(buff + n, sz - n, "p%+d", e); /* add exponent */
> lua_assert(n < sz);
864,866c890,892
< static int lua_number2strx (lua_State *L, char *buff, const char *fmt,
< lua_Number x) {
< int n = num2straux(buff, x);
> static int lua_number2strx (lua_State *L, char *buff, int sz,
> const char *fmt, lua_Number x) {
> int n = num2straux(buff, sz, x);
882,883c908,911
< ** by format('%.99f', minfloat), and is equal to 99 + 2 ('-' and '.') +
< ** number of decimal digits to represent minfloat.
> ** by format('%.99f', -maxfloat), and is equal to 99 + 3 ('-', '.',
> ** and '\0') + number of decimal digits to represent maxfloat (which
> ** is maximum exponent + 1). (99+3+1 then rounded to 120 for "extra
> ** expenses", such as locale-dependent stuff)
885c913
< #define MAX_ITEM (120 + l_mathlim(MAX_10_EXP))
> #define MAX_ITEM (120 + l_mathlim(MAX_10_EXP))
909c937
< sprintf(buff, "\\%d", (int)uchar(*s));
> l_sprintf(buff, sizeof(buff), "\\%d", (int)uchar(*s));
911c939
< sprintf(buff, "\\%03d", (int)uchar(*s));
> l_sprintf(buff, sizeof(buff), "\\%03d", (int)uchar(*s));
978c1006
< nb = sprintf(buff, form, (int)luaL_checkinteger(L, arg));
> nb = l_sprintf(buff, MAX_ITEM, form, (int)luaL_checkinteger(L, arg));
985c1013
< nb = sprintf(buff, form, n);
> nb = l_sprintf(buff, MAX_ITEM, form, n);
990c1018,1019
< nb = lua_number2strx(L, buff, form, luaL_checknumber(L, arg));
> nb = lua_number2strx(L, buff, MAX_ITEM, form,
> luaL_checknumber(L, arg));
995c1024
< nb = sprintf(buff, form, luaL_checknumber(L, arg));
> nb = l_sprintf(buff, MAX_ITEM, form, luaL_checknumber(L, arg));
1005,1009c1034,1035
< if (!strchr(form, '.') && l >= 100) {
< /* no precision and string is too long to be formatted;
< keep original string */
< luaL_addvalue(&b);
< }
> if (form[2] == '\0') /* no modifiers? */
> luaL_addvalue(&b); /* keep entire string */
1011,1012c1037,1045
< nb = sprintf(buff, form, s);
< lua_pop(L, 1); /* remove result from 'luaL_tolstring' */
> luaL_argcheck(L, l == strlen(s), arg, "string contains zeros");
> if (!strchr(form, '.') && l >= 100) {
> /* no precision and string is too long to be formatted */
> luaL_addvalue(&b); /* keep entire string */
> }
> else { /* format the string into 'buff' */
> nb = l_sprintf(buff, MAX_ITEM, form, s);
> lua_pop(L, 1); /* remove result from 'luaL_tolstring' */
> }
1020a1054
> lua_assert(nb < MAX_ITEM);
1312,1313c1346,1352
< luaL_argcheck(L, len == (size_t)size, arg, "wrong length");
< luaL_addlstring(&b, s, size);
> if ((size_t)size <= len) /* string larger than (or equal to) needed? */
> luaL_addlstring(&b, s, size); /* truncate string to asked size */
> else { /* string smaller than needed */
> luaL_addlstring(&b, s, len); /* add it all */
> while (len++ < (size_t)size) /* pad extra space */
> luaL_addchar(&b, LUA_PACKPADBYTE);
> }
1363c1402
< break;
> /* call never return, but to avoid warnings: *//* FALLTHROUGH */
src/ltable.c
2c2
< ** $Id: ltable.c,v 2.111 2015/06/09 14:21:13 roberto Exp $
> ** $Id: ltable.c,v 2.117 2015/11/19 19:16:22 roberto Exp $
88c88
< ** n = frepx(n, &i); return (n * INT_MAX) + i
> ** n = frexp(n, &i); return (n * INT_MAX) + i
104c104
< lua_assert(luai_numisnan(n) || l_mathop(fabs)(n) == HUGE_VAL);
> lua_assert(luai_numisnan(n) || l_mathop(fabs)(n) == cast_num(HUGE_VAL));
127,134c127,128
< case LUA_TLNGSTR: {
< TString *s = tsvalue(key);
< if (s->extra == 0) { /* no hash? */
< s->hash = luaS_hash(getstr(s), s->u.lnglen, s->hash);
< s->extra = 1; /* now it has its hash */
< }
< return hashstr(t, tsvalue(key));
< }
> case LUA_TLNGSTR:
> return hashpow2(t, luaS_hashlongstr(tsvalue(key)));
141a136
> lua_assert(!ttisdeadkey(key));
466c461
< /* whatever called 'newkey' takes care of TM cache and GC barrier */
> /* whatever called 'newkey' takes care of TM cache */
504c499
< if (l_castS2U(key - 1) < t->sizearray)
> if (l_castS2U(key) - 1 < t->sizearray)
516c511
< };
> }
525c520
< const TValue *luaH_getstr (Table *t, TString *key) {
> const TValue *luaH_getshortstr (Table *t, TString *key) {
534c529,530
< if (nx == 0) break;
> if (nx == 0)
> return luaO_nilobject; /* not found */
537,538c533,563
< };
< return luaO_nilobject;
> }
> }
>
>
> /*
> ** "Generic" get version. (Not that generic: not valid for integers,
> ** which may be in array part, nor for floats with integral values.)
> */
> static const TValue *getgeneric (Table *t, const TValue *key) {
> Node *n = mainposition(t, key);
> for (;;) { /* check whether 'key' is somewhere in the chain */
> if (luaV_rawequalobj(gkey(n), key))
> return gval(n); /* that's it */
> else {
> int nx = gnext(n);
> if (nx == 0)
> return luaO_nilobject; /* not found */
> n += nx;
> }
> }
> }
>
>
> const TValue *luaH_getstr (Table *t, TString *key) {
> if (key->tt == LUA_TSHRSTR)
> return luaH_getshortstr(t, key);
> else { /* for long strings, use generic case */
> TValue ko;
> setsvalue(cast(lua_State *, NULL), &ko, key);
> return getgeneric(t, &ko);
> }
547c572
< case LUA_TSHRSTR: return luaH_getstr(t, tsvalue(key));
> case LUA_TSHRSTR: return luaH_getshortstr(t, tsvalue(key));
556,568c581,582
< default: {
< Node *n = mainposition(t, key);
< for (;;) { /* check whether 'key' is somewhere in the chain */
< if (luaV_rawequalobj(gkey(n), key))
< return gval(n); /* that's it */
< else {
< int nx = gnext(n);
< if (nx == 0) break;
< n += nx;
< }
< };
< return luaO_nilobject;
< }
> default:
> return getgeneric(t, key);
src/ltable.h
2c2
< ** $Id: ltable.h,v 2.20 2014/09/04 18:15:29 roberto Exp $
> ** $Id: ltable.h,v 2.21 2015/11/03 15:47:30 roberto Exp $
20a21,24
> /*
> ** writable version of 'gkey'; allows updates to individual fields,
> ** but not to the whole (which has incompatible type)
> */
33a38
> LUAI_FUNC const TValue *luaH_getshortstr (Table *t, TString *key);
src/ltablib.c
2c2
< ** $Id: ltablib.c,v 1.80 2015/01/13 16:27:29 roberto Exp $
> ** $Id: ltablib.c,v 1.90 2015/11/25 12:48:57 roberto Exp $
14a15
> #include <string.h>
22d22
<
24c24,25
< ** Structure with table-access functions
> ** Operations that an object must define to mimic a table
> ** (some functions only need some of them)
26,29c27,30
< typedef struct {
< int (*geti) (lua_State *L, int idx, lua_Integer n);
< void (*seti) (lua_State *L, int idx, lua_Integer n);
< } TabA;
> #define TAB_R 1 /* read */
> #define TAB_W 2 /* write */
> #define TAB_L 4 /* length */
> #define TAB_RW (TAB_R | TAB_W) /* read/write */
32,51c33,38
< /*
< ** Check that 'arg' has a table and set access functions in 'ta' to raw
< ** or non-raw according to the presence of corresponding metamethods.
< */
< static void checktab (lua_State *L, int arg, TabA *ta) {
< ta->geti = NULL; ta->seti = NULL;
< if (lua_getmetatable(L, arg)) {
< lua_pushliteral(L, "__index"); /* 'index' metamethod */
< if (lua_rawget(L, -2) != LUA_TNIL)
< ta->geti = lua_geti;
< lua_pushliteral(L, "__newindex"); /* 'newindex' metamethod */
< if (lua_rawget(L, -3) != LUA_TNIL)
< ta->seti = lua_seti;
< lua_pop(L, 3); /* pop metatable plus both metamethods */
< }
< if (ta->geti == NULL || ta->seti == NULL) {
< luaL_checktype(L, arg, LUA_TTABLE); /* must be table for raw methods */
< if (ta->geti == NULL) ta->geti = lua_rawgeti;
< if (ta->seti == NULL) ta->seti = lua_rawseti;
< }
> #define aux_getn(L,n,w) (checktab(L, n, (w) | TAB_L), luaL_len(L, n))
>
>
> static int checkfield (lua_State *L, const char *key, int n) {
> lua_pushstring(L, key);
> return (lua_rawget(L, -n) != LUA_TNIL);
55c42,58
< #define aux_getn(L,n,ta) (checktab(L, n, ta), luaL_len(L, n))
> /*
> ** Check that 'arg' either is a table or can behave like one (that is,
> ** has a metatable with the required metamethods)
> */
> static void checktab (lua_State *L, int arg, int what) {
> if (lua_type(L, arg) != LUA_TTABLE) { /* is it not a table? */
> int n = 1; /* number of elements to pop */
> if (lua_getmetatable(L, arg) && /* must have metatable */
> (!(what & TAB_R) || checkfield(L, "__index", ++n)) &&
> (!(what & TAB_W) || checkfield(L, "__newindex", ++n)) &&
> (!(what & TAB_L) || checkfield(L, "__len", ++n))) {
> lua_pop(L, n); /* pop metatable and tested metamethods */
> }
> else
> luaL_argerror(L, arg, "table expected"); /* force an error */
> }
> }
77,78c80
< TabA ta;
< lua_Integer e = aux_getn(L, 1, &ta) + 1; /* first empty element */
> lua_Integer e = aux_getn(L, 1, TAB_RW) + 1; /* first empty element */
90,91c92,93
< (*ta.geti)(L, 1, i - 1);
< (*ta.seti)(L, 1, i); /* t[i] = t[i - 1] */
> lua_geti(L, 1, i - 1);
> lua_seti(L, 1, i); /* t[i] = t[i - 1] */
99c101
< (*ta.seti)(L, 1, pos); /* t[pos] = v */
> lua_seti(L, 1, pos); /* t[pos] = v */
105,106c107
< TabA ta;
< lua_Integer size = aux_getn(L, 1, &ta);
> lua_Integer size = aux_getn(L, 1, TAB_RW);
110c111
< (*ta.geti)(L, 1, pos); /* result = t[pos] */
> lua_geti(L, 1, pos); /* result = t[pos] */
112,113c113,114
< (*ta.geti)(L, 1, pos + 1);
< (*ta.seti)(L, 1, pos); /* t[pos] = t[pos + 1] */
> lua_geti(L, 1, pos + 1);
> lua_seti(L, 1, pos); /* t[pos] = t[pos + 1] */
116c117
< (*ta.seti)(L, 1, pos); /* t[pos] = nil */
> lua_seti(L, 1, pos); /* t[pos] = nil */
120a122,127
> /*
> ** Copy elements (1[f], ..., 1[e]) into (tt[t], tt[t+1], ...). Whenever
> ** possible, copy in increasing order, which is better for rehashing.
> ** "possible" means destination after original range, or smaller
> ** than origin, or copying to another table.
> */
122d128
< TabA ta;
126a133,134
> checktab(L, 1, TAB_R);
> checktab(L, tt, TAB_W);
129,134d136
< ta.geti = (luaL_getmetafield(L, 1, "__index") == LUA_TNIL)
< ? (luaL_checktype(L, 1, LUA_TTABLE), lua_rawgeti)
< : lua_geti;
< ta.seti = (luaL_getmetafield(L, tt, "__newindex") == LUA_TNIL)
< ? (luaL_checktype(L, tt, LUA_TTABLE), lua_rawseti)
< : lua_seti;
140,143c142,145
< if (t > f) {
< for (i = n - 1; i >= 0; i--) {
< (*ta.geti)(L, 1, f + i);
< (*ta.seti)(L, tt, t + i);
> if (t > e || t <= f || tt != 1) {
> for (i = 0; i < n; i++) {
> lua_geti(L, 1, f + i);
> lua_seti(L, tt, t + i);
147,149c149,151
< for (i = 0; i < n; i++) {
< (*ta.geti)(L, 1, f + i);
< (*ta.seti)(L, tt, t + i);
> for (i = n - 1; i >= 0; i--) {
> lua_geti(L, 1, f + i);
> lua_seti(L, tt, t + i);
158,159c160,161
< static void addfield (lua_State *L, luaL_Buffer *b, TabA *ta, lua_Integer i) {
< (*ta->geti)(L, 1, i);
> static void addfield (lua_State *L, luaL_Buffer *b, lua_Integer i) {
> lua_geti(L, 1, i);
168d169
< TabA ta;
169a171
> lua_Integer last = aux_getn(L, 1, TAB_R);
171d172
< lua_Integer i, last;
173,175c174,175
< checktab(L, 1, &ta);
< i = luaL_optinteger(L, 3, 1);
< last = luaL_opt(L, luaL_checkinteger, 4, luaL_len(L, 1));
> lua_Integer i = luaL_optinteger(L, 3, 1);
> last = luaL_opt(L, luaL_checkinteger, 4, last);
178c178
< addfield(L, &b, &ta, i);
> addfield(L, &b, i);
182c182
< addfield(L, &b, &ta, i);
> addfield(L, &b, i);
200c200
< lua_rawseti(L, 1, i);
> lua_seti(L, 1, i);
208,209d207
< TabA ta;
< lua_Integer i, e;
211,213c209,210
< checktab(L, 1, &ta);
< i = luaL_optinteger(L, 2, 1);
< e = luaL_opt(L, luaL_checkinteger, 3, luaL_len(L, 1));
> lua_Integer i = luaL_optinteger(L, 2, 1);
> lua_Integer e = luaL_opt(L, luaL_checkinteger, 3, luaL_len(L, 1));
218,221c215,218
< do { /* must have at least one element */
< (*ta.geti)(L, 1, i); /* push arg[i..e] */
< } while (i++ < e);
<
> for (; i < e; i++) { /* push arg[i..e - 1] (to avoid overflows) */
> lua_geti(L, 1, i);
> }
> lua_geti(L, 1, e); /* push last element */
238,240c235,263
< static void set2 (lua_State *L, TabA *ta, int i, int j) {
< (*ta->seti)(L, 1, i);
< (*ta->seti)(L, 1, j);
> /*
> ** Produce a "random" 'unsigned int' to randomize pivot choice. This
> ** macro is used only when 'sort' detects a big imbalance in the result
> ** of a partition. (If you don't want/need this "randomness", ~0 is a
> ** good choice.)
> */
> #if !defined(l_randomizePivot) /* { */
>
> #include <time.h>
>
> /* size of 'e' measured in number of 'unsigned int's */
> #define sof(e) (sizeof(e) / sizeof(unsigned int))
>
> /*
> ** Use 'time' and 'clock' as sources of "randomness". Because we don't
> ** know the types 'clock_t' and 'time_t', we cannot cast them to
> ** anything without risking overflows. A safe way to use their values
> ** is to copy them to an array of a known type and use the array values.
> */
> static unsigned int l_randomizePivot (void) {
> clock_t c = clock();
> time_t t = time(NULL);
> unsigned int buff[sof(c) + sof(t)];
> unsigned int i, rnd = 0;
> memcpy(buff, &c, sof(c) * sizeof(unsigned int));
> memcpy(buff + sof(c), &t, sof(t) * sizeof(unsigned int));
> for (i = 0; i < sof(buff); i++)
> rnd += buff[i];
> return rnd;
242a266,282
> #endif /* } */
>
>
> /* arrays larger than 'RANLIMIT' may use randomized pivots */
> #define RANLIMIT 100u
>
>
> static void set2 (lua_State *L, unsigned int i, unsigned int j) {
> lua_seti(L, 1, i);
> lua_seti(L, 1, j);
> }
>
>
> /*
> ** Return true iff value at stack index 'a' is less than the value at
> ** index 'b' (according to the order of the sort).
> */
244c284,286
< if (!lua_isnil(L, 2)) { /* function? */
> if (lua_isnil(L, 2)) /* no function? */
> return lua_compare(L, a, b, LUA_OPLT); /* a < b */
> else { /* function */
246c288
< lua_pushvalue(L, 2);
> lua_pushvalue(L, 2); /* push function */
249,251c291,293
< lua_call(L, 2, 1);
< res = lua_toboolean(L, -1);
< lua_pop(L, 1);
> lua_call(L, 2, 1); /* call function */
> res = lua_toboolean(L, -1); /* get result */
> lua_pop(L, 1); /* pop result */
254,255d295
< else /* a < b? */
< return lua_compare(L, a, b, LUA_OPLT);
258,265c298,364
< static void auxsort (lua_State *L, TabA *ta, int l, int u) {
< while (l < u) { /* for tail recursion */
< int i, j;
< /* sort elements a[l], a[(l+u)/2] and a[u] */
< (*ta->geti)(L, 1, l);
< (*ta->geti)(L, 1, u);
< if (sort_comp(L, -1, -2)) /* a[u] < a[l]? */
< set2(L, ta, l, u); /* swap a[l] - a[u] */
>
> /*
> ** Does the partition: Pivot P is at the top of the stack.
> ** precondition: a[lo] <= P == a[up-1] <= a[up],
> ** so it only needs to do the partition from lo + 1 to up - 2.
> ** Pos-condition: a[lo .. i - 1] <= a[i] == P <= a[i + 1 .. up]
> ** returns 'i'.
> */
> static unsigned int partition (lua_State *L, unsigned int lo,
> unsigned int up) {
> unsigned int i = lo; /* will be incremented before first use */
> unsigned int j = up - 1; /* will be decremented before first use */
> /* loop invariant: a[lo .. i] <= P <= a[j .. up] */
> for (;;) {
> /* next loop: repeat ++i while a[i] < P */
> while (lua_geti(L, 1, ++i), sort_comp(L, -1, -2)) {
> if (i == up - 1) /* a[i] < P but a[up - 1] == P ?? */
> luaL_error(L, "invalid order function for sorting");
> lua_pop(L, 1); /* remove a[i] */
> }
> /* after the loop, a[i] >= P and a[lo .. i - 1] < P */
> /* next loop: repeat --j while P < a[j] */
> while (lua_geti(L, 1, --j), sort_comp(L, -3, -1)) {
> if (j < i) /* j < i but a[j] > P ?? */
> luaL_error(L, "invalid order function for sorting");
> lua_pop(L, 1); /* remove a[j] */
> }
> /* after the loop, a[j] <= P and a[j + 1 .. up] >= P */
> if (j < i) { /* no elements out of place? */
> /* a[lo .. i - 1] <= P <= a[j + 1 .. i .. up] */
> lua_pop(L, 1); /* pop a[j] */
> /* swap pivot (a[up - 1]) with a[i] to satisfy pos-condition */
> set2(L, up - 1, i);
> return i;
> }
> /* otherwise, swap a[i] - a[j] to restore invariant and repeat */
> set2(L, i, j);
> }
> }
>
>
> /*
> ** Choose an element in the middle (2nd-3th quarters) of [lo,up]
> ** "randomized" by 'rnd'
> */
> static unsigned int choosePivot (unsigned int lo, unsigned int up,
> unsigned int rnd) {
> unsigned int r4 = (unsigned int)(up - lo) / 4u; /* range/4 */
> unsigned int p = rnd % (r4 * 2) + (lo + r4);
> lua_assert(lo + r4 <= p && p <= up - r4);
> return p;
> }
>
>
> /*
> ** QuickSort algorithm (recursive function)
> */
> static void auxsort (lua_State *L, unsigned int lo, unsigned int up,
> unsigned int rnd) {
> while (lo < up) { /* loop for tail recursion */
> unsigned int p; /* Pivot index */
> unsigned int n; /* to be used later */
> /* sort elements 'lo', 'p', and 'up' */
> lua_geti(L, 1, lo);
> lua_geti(L, 1, up);
> if (sort_comp(L, -1, -2)) /* a[up] < a[lo]? */
> set2(L, lo, up); /* swap a[lo] - a[up] */
267,273c366,376
< lua_pop(L, 2);
< if (u-l == 1) break; /* only 2 elements */
< i = (l+u)/2;
< (*ta->geti)(L, 1, i);
< (*ta->geti)(L, 1, l);
< if (sort_comp(L, -2, -1)) /* a[i]<a[l]? */
< set2(L, ta, i, l);
> lua_pop(L, 2); /* remove both values */
> if (up - lo == 1) /* only 2 elements? */
> return; /* already sorted */
> if (up - lo < RANLIMIT || rnd == 0) /* small interval or no randomize? */
> p = (lo + up)/2; /* middle element is a good pivot */
> else /* for larger intervals, it is worth a random pivot */
> p = choosePivot(lo, up, rnd);
> lua_geti(L, 1, p);
> lua_geti(L, 1, lo);
> if (sort_comp(L, -2, -1)) /* a[p] < a[lo]? */
> set2(L, p, lo); /* swap a[p] - a[lo] */
275,278c378,381
< lua_pop(L, 1); /* remove a[l] */
< (*ta->geti)(L, 1, u);
< if (sort_comp(L, -1, -2)) /* a[u]<a[i]? */
< set2(L, ta, i, u);
> lua_pop(L, 1); /* remove a[lo] */
> lua_geti(L, 1, up);
> if (sort_comp(L, -1, -2)) /* a[up] < a[p]? */
> set2(L, p, up); /* swap a[up] - a[p] */
282,312c385,396
< if (u-l == 2) break; /* only 3 elements */
< (*ta->geti)(L, 1, i); /* Pivot */
< lua_pushvalue(L, -1);
< (*ta->geti)(L, 1, u-1);
< set2(L, ta, i, u-1);
< /* a[l] <= P == a[u-1] <= a[u], only need to sort from l+1 to u-2 */
< i = l; j = u-1;
< for (;;) { /* invariant: a[l..i] <= P <= a[j..u] */
< /* repeat ++i until a[i] >= P */
< while ((*ta->geti)(L, 1, ++i), sort_comp(L, -1, -2)) {
< if (i>=u) luaL_error(L, "invalid order function for sorting");
< lua_pop(L, 1); /* remove a[i] */
< }
< /* repeat --j until a[j] <= P */
< while ((*ta->geti)(L, 1, --j), sort_comp(L, -3, -1)) {
< if (j<=l) luaL_error(L, "invalid order function for sorting");
< lua_pop(L, 1); /* remove a[j] */
< }
< if (j<i) {
< lua_pop(L, 3); /* pop pivot, a[i], a[j] */
< break;
< }
< set2(L, ta, i, j);
< }
< (*ta->geti)(L, 1, u-1);
< (*ta->geti)(L, 1, i);
< set2(L, ta, u-1, i); /* swap pivot (a[u-1]) with a[i] */
< /* a[l..i-1] <= a[i] == P <= a[i+1..u] */
< /* adjust so that smaller half is in [j..i] and larger one in [l..u] */
< if (i-l < u-i) {
< j=l; i=i-1; l=i+2;
> if (up - lo == 2) /* only 3 elements? */
> return; /* already sorted */
> lua_geti(L, 1, p); /* get middle element (Pivot) */
> lua_pushvalue(L, -1); /* push Pivot */
> lua_geti(L, 1, up - 1); /* push a[up - 1] */
> set2(L, p, up - 1); /* swap Pivot (a[p]) with a[up - 1] */
> p = partition(L, lo, up);
> /* a[lo .. p - 1] <= a[p] == P <= a[p + 1 .. up] */
> if (p - lo < up - p) { /* lower interval is smaller? */
> auxsort(L, lo, p - 1, rnd); /* call recursively for lower interval */
> n = p - lo; /* size of smaller interval */
> lo = p + 1; /* tail call for [p + 1 .. up] (upper interval) */
315c399,401
< j=i+1; i=u; u=j-2;
> auxsort(L, p + 1, up, rnd); /* call recursively for upper interval */
> n = up - p; /* size of smaller interval */
> up = p - 1; /* tail call for [lo .. p - 1] (lower interval) */
317,318c403,405
< auxsort(L, ta, j, i); /* call recursively the smaller one */
< } /* repeat the routine for the larger one */
> if ((up - lo) / 128u > n) /* partition too imbalanced? */
> rnd = l_randomizePivot(); /* try a new randomization */
> } /* tail call auxsort(L, lo, up, rnd) */
320a408
>
322,328c410,418
< TabA ta;
< int n = (int)aux_getn(L, 1, &ta);
< luaL_checkstack(L, 50, ""); /* assume array is smaller than 2^50 */
< if (!lua_isnoneornil(L, 2)) /* is there a 2nd argument? */
< luaL_checktype(L, 2, LUA_TFUNCTION);
< lua_settop(L, 2); /* make sure there are two arguments */
< auxsort(L, &ta, 1, n);
> lua_Integer n = aux_getn(L, 1, TAB_RW);
> if (n > 1) { /* non-trivial interval? */
> luaL_argcheck(L, n < INT_MAX, 1, "array too big");
> luaL_checkstack(L, 40, ""); /* assume array is smaller than 2^40 */
> if (!lua_isnoneornil(L, 2)) /* is there a 2nd argument? */
> luaL_checktype(L, 2, LUA_TFUNCTION); /* must be a function */
> lua_settop(L, 2); /* make sure there are two arguments */
> auxsort(L, 1, (unsigned int)n, 0u);
> }
src/ltm.c
2c2
< ** $Id: ltm.c,v 2.34 2015/03/30 15:42:27 roberto Exp $
> ** $Id: ltm.c,v 2.36 2015/11/03 15:47:30 roberto Exp $
60c60
< const TValue *tm = luaH_getstr(events, ename);
> const TValue *tm = luaH_getshortstr(events, ename);
82c82
< return (mt ? luaH_getstr(mt, G(L)->tmname[event]) : luaO_nilobject);
> return (mt ? luaH_getshortstr(mt, G(L)->tmname[event]) : luaO_nilobject);
89,91c89,93
< setobj2s(L, L->top++, f); /* push function (assume EXTRA_STACK) */
< setobj2s(L, L->top++, p1); /* 1st argument */
< setobj2s(L, L->top++, p2); /* 2nd argument */
> StkId func = L->top;
> setobj2s(L, func, f); /* push function (assume EXTRA_STACK) */
> setobj2s(L, func + 1, p1); /* 1st argument */
> setobj2s(L, func + 2, p2); /* 2nd argument */
> L->top += 3;
95c97,100
< luaD_call(L, L->top - (4 - hasres), hasres, isLua(L->ci));
> if (isLua(L->ci))
> luaD_call(L, func, hasres);
> else
> luaD_callnoyield(L, func, hasres);
src/lua.c
2c2
< ** $Id: lua.c,v 1.225 2015/03/30 15:42:59 roberto Exp $
> ** $Id: lua.c,v 1.226 2015/08/14 19:11:20 roberto Exp $
327c327
< ** Try to compile line on the stack as 'return <line>'; on return, stack
> ** Try to compile line on the stack as 'return <line>;'; on return, stack
331,339c331,335
< int status;
< size_t len; const char *line;
< lua_pushliteral(L, "return ");
< lua_pushvalue(L, -2); /* duplicate line */
< lua_concat(L, 2); /* new line is "return ..." */
< line = lua_tolstring(L, -1, &len);
< if ((status = luaL_loadbuffer(L, line, len, "=stdin")) == LUA_OK) {
< lua_remove(L, -3); /* remove original line */
< line += sizeof("return")/sizeof(char); /* remove 'return' for history */
> const char *line = lua_tostring(L, -1); /* original line */
> const char *retline = lua_pushfstring(L, "return %s;", line);
> int status = luaL_loadbuffer(L, retline, strlen(retline), "=stdin");
> if (status == LUA_OK) {
> lua_remove(L, -2); /* remove modified line */
344c340
< lua_pop(L, 2); /* remove result from 'luaL_loadbuffer' and new line */
> lua_pop(L, 2); /* pop result from 'luaL_loadbuffer' and modified line */
src/lua.h
2c2
< ** $Id: lua.h,v 1.328 2015/06/03 13:03:38 roberto Exp $
> ** $Id: lua.h,v 1.329 2015/11/13 17:18:42 roberto Exp $
22c22
< #define LUA_VERSION_RELEASE "1"
> #define LUA_VERSION_RELEASE "2"
src/luaconf.h
2c2
< ** $Id: luaconf.h,v 1.251 2015/05/20 17:39:23 roberto Exp $
> ** $Id: luaconf.h,v 1.254 2015/10/21 18:17:40 roberto Exp $
148c148
< #endif /* } */
> #endif
414a415
> @@ l_floor takes the floor of a float.
417a419,441
>
> /* The following definitions are good for most cases here */
>
> #define l_floor(x) (l_mathop(floor)(x))
>
> #define lua_number2str(s,sz,n) l_sprintf((s), sz, LUA_NUMBER_FMT, (n))
>
> /*
> @@ lua_numbertointeger converts a float number 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))
>
>
> /* now the variable definitions */
>
471,489d494
< #define l_floor(x) (l_mathop(floor)(x))
<
< #define lua_number2str(s,n) sprintf((s), LUA_NUMBER_FMT, (n))
<
<
< /*
< @@ lua_numbertointeger converts a float number 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))
<
<
509c514
< #define lua_integer2str(s,n) sprintf((s), LUA_INTEGER_FMT, (n))
> #define lua_integer2str(s,sz,n) l_sprintf((s), sz, LUA_INTEGER_FMT, (n))
539a545
> /* use presence of macro LLONG_MAX as proxy for C99 compliance */
580a587,597
> @@ l_sprintf is equivalent to 'snprintf' or 'sprintf' in C89.
> ** (All uses in Lua have only one format item.)
> */
> #if !defined(LUA_USE_C89)
> #define l_sprintf(s,sz,f,i) snprintf(s,sz,f,i)
> #else
> #define l_sprintf(s,sz,f,i) ((void)(sz), sprintf(s,f,i))
> #endif
>
>
> /*
587c604
< #define lua_strx2number(s,p) lua_str2number(s,p)
> #define lua_strx2number(s,p) lua_str2number(s,p)
598c615
< #define lua_number2strx(L,b,f,n) sprintf(b,f,n)
> #define lua_number2strx(L,b,sz,f,n) l_sprintf(b,sz,f,n)
src/lundump.c
2c2
< ** $Id: lundump.c,v 2.41 2014/11/02 19:19:04 roberto Exp $
> ** $Id: lundump.c,v 2.44 2015/11/02 16:09:30 roberto Exp $
35d34
< Mbuffer *b;
95,98c94,102
< else {
< char *s = luaZ_openspace(S->L, S->b, --size);
< LoadVector(S, s, size);
< return luaS_newlstr(S->L, s, size);
> else if (--size <= LUAI_MAXSHORTLEN) { /* short string? */
> char buff[LUAI_MAXSHORTLEN];
> LoadVector(S, buff, size);
> return luaS_newlstr(S->L, buff, size);
> }
> else { /* long string */
> TString *ts = luaS_createlngstrobj(S->L, size);
> LoadVector(S, getstr(ts), size); /* load directly in final place */
> return ts;
254,255c258
< LClosure *luaU_undump(lua_State *L, ZIO *Z, Mbuffer *buff,
< const char *name) {
> LClosure *luaU_undump(lua_State *L, ZIO *Z, const char *name) {
266d268
< S.b = buff;
270c272
< incr_top(L);
> luaD_inctop(L);
src/lundump.h
2c2
< ** $Id: lundump.h,v 1.44 2014/06/19 18:27:20 roberto Exp $
> ** $Id: lundump.h,v 1.45 2015/09/08 15:41:05 roberto Exp $
26,27c26
< LUAI_FUNC LClosure* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff,
< const char* name);
> LUAI_FUNC LClosure* luaU_undump (lua_State* L, ZIO* Z, const char* name);
src/lvm.c
2c2
< ** $Id: lvm.c,v 2.245 2015/06/09 15:53:35 roberto Exp $
> ** $Id: lvm.c,v 2.265 2015/11/23 11:30:45 roberto Exp $
156,157c156,157
< ** Main function for table access (invoking metamethods if needed).
< ** Compute 'val = t[key]'
> ** Complete a table access: if 't' is a table, 'tm' has its metamethod;
> ** otherwise, 'tm' is NULL.
159c159,160
< void luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val) {
> void luaV_finishget (lua_State *L, const TValue *t, TValue *key, StkId val,
> const TValue *tm) {
160a162
> lua_assert(tm != NULL || !ttistable(t));
162,171c164,166
< const TValue *tm;
< if (ttistable(t)) { /* 't' is a table? */
< Table *h = hvalue(t);
< const TValue *res = luaH_get(h, key); /* do a primitive get */
< if (!ttisnil(res) || /* result is not nil? */
< (tm = fasttm(L, h->metatable, TM_INDEX)) == NULL) { /* or no TM? */
< setobj2s(L, val, res); /* result is the raw get */
< return;
< }
< /* else will try metamethod */
> if (tm == NULL) { /* no metamethod (from a table)? */
> if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_INDEX)))
> luaG_typeerror(L, t, "index"); /* no metamethod */
173,174d167
< else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_INDEX)))
< luaG_typeerror(L, t, "index"); /* no metamethod */
176c169
< luaT_callTM(L, tm, t, key, val, 1);
> luaT_callTM(L, tm, t, key, val, 1); /* call it */
179a173,177
> if (luaV_fastget(L,t,key,tm,luaH_get)) { /* try fast track */
> setobj2s(L, val, tm); /* done */
> return;
> }
> /* else repeat */
189c187,188
< void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val) {
> void luaV_finishset (lua_State *L, const TValue *t, TValue *key,
> StkId val, const TValue *oldval) {
193,200c192,195
< if (ttistable(t)) { /* 't' is a table? */
< Table *h = hvalue(t);
< TValue *oldval = cast(TValue *, luaH_get(h, key));
< /* if previous value is not nil, there must be a previous entry
< in the table; a metamethod has no relevance */
< if (!ttisnil(oldval) ||
< /* previous value is nil; must check the metamethod */
< ((tm = fasttm(L, h->metatable, TM_NEWINDEX)) == NULL &&
> if (oldval != NULL) {
> lua_assert(ttistable(t) && ttisnil(oldval));
> /* must check the metamethod */
> if ((tm = fasttm(L, hvalue(t)->metatable, TM_NEWINDEX)) == NULL &&
205c200
< (oldval = luaH_newkey(L, h, key), 1)))) {
> (oldval = luaH_newkey(L, hvalue(t), key), 1))) {
207,209c202,204
< setobj2t(L, oldval, val); /* assign new value to that entry */
< invalidateTMcache(h);
< luaC_barrierback(L, h, val);
> setobj2t(L, cast(TValue *, oldval), val);
> invalidateTMcache(hvalue(t));
> luaC_barrierback(L, hvalue(t), val);
214c209
< else /* not a table; check metamethod */
> else { /* not a table; check metamethod */
216a212
> }
222a219,221
> if (luaV_fastset(L, t, key, oldval, luaH_get, val))
> return; /* done */
> /* else loop */
445a445,455
> /* copy strings in stack from top - n up to top - 1 to buffer */
> static void copy2buff (StkId top, int n, char *buff) {
> size_t tl = 0; /* size already copied */
> do {
> size_t l = vslen(top - n); /* length of string being copied */
> memcpy(buff + tl, svalue(top - n), l * sizeof(char));
> tl += l;
> } while (--n > 0);
> }
>
>
465,469c475,478
< char *buffer;
< int i;
< /* collect total length */
< for (i = 1; i < total && tostring(L, top-i-1); i++) {
< size_t l = vslen(top - i - 1);
> TString *ts;
> /* collect total length and number of strings */
> for (n = 1; n < total && tostring(L, top - n - 1); n++) {
> size_t l = vslen(top - n - 1);
474,482c483,492
< buffer = luaZ_openspace(L, &G(L)->buff, tl);
< tl = 0;
< n = i;
< do { /* copy all strings to buffer */
< size_t l = vslen(top - i);
< memcpy(buffer+tl, svalue(top-i), l * sizeof(char));
< tl += l;
< } while (--i > 0);
< setsvalue2s(L, top-n, luaS_newlstr(L, buffer, tl)); /* create result */
> if (tl <= LUAI_MAXSHORTLEN) { /* is result a short string? */
> char buff[LUAI_MAXSHORTLEN];
> copy2buff(top, n, buff); /* copy strings to buffer */
> ts = luaS_newlstr(L, buff, tl);
> }
> else { /* long string; copy strings directly to final result */
> ts = luaS_createlngstrobj(L, tl);
> copy2buff(top, n, getstr(ts));
> }
> setsvalue2s(L, top - n, ts); /* create result */
703,706d712
< #if !defined(luai_runtimecheck)
< #define luai_runtimecheck(L, c) /* void */
< #endif
<
709d714
< /* to be used after possible stack reallocation */
716,717d720
< #define KBx(i) \
< (k + (GETARG_Bx(i) != 0 ? GETARG_Bx(i) - 1 : GETARG_Ax(*ci->u.l.savedpc++)))
723c726
< if (a > 0) luaF_close(L, ci->u.l.base + a - 1); \
> if (a != 0) luaF_close(L, ci->u.l.base + a - 1); \
733,736c736,738
< Protect( luaC_condGC(L,{L->top = (c); /* limit of live values */ \
< luaC_step(L); \
< L->top = ci->top;}) /* restore top */ \
< luai_threadyield(L); )
> { luaC_condGC(L, L->top = (c), /* limit of live values */ \
> Protect(L->top = ci->top)); /* restore top */ \
> luai_threadyield(L); }
742a745,761
>
> /*
> ** copy of 'luaV_gettable', but protecting call to potential metamethod
> ** (which can reallocate the stack)
> */
> #define gettableProtected(L,t,k,v) { const TValue *aux; \
> if (luaV_fastget(L,t,k,aux,luaH_get)) { setobj2s(L, v, aux); } \
> else Protect(luaV_finishget(L,t,k,v,aux)); }
>
>
> /* same for 'luaV_settable' */
> #define settableProtected(L,t,k,v) { const TValue *slot; \
> if (!luaV_fastset(L,t,k,slot,luaH_get,v)) \
> Protect(luaV_finishset(L,t,k,v,slot)); }
>
>
>
747a767
> ci->callstatus |= CIST_FRESH; /* fresh invocation of 'luaV_execute" */
750,752c770,772
< cl = clLvalue(ci->func);
< k = cl->p->k;
< base = ci->u.l.base;
> cl = clLvalue(ci->func); /* local reference to function's closure */
> k = cl->p->k; /* local reference to function's constant table */
> base = ci->u.l.base; /* local copy of function's base */
757,758c777
< if ((L->hookmask & (LUA_MASKLINE | LUA_MASKCOUNT)) &&
< (--L->hookcount == 0 || L->hookmask & LUA_MASKLINE)) {
> if (L->hookmask & (LUA_MASKLINE | LUA_MASKCOUNT))
760d778
< }
800,801c818,820
< int b = GETARG_B(i);
< Protect(luaV_gettable(L, cl->upvals[b]->v, RKC(i), ra));
> TValue *upval = cl->upvals[GETARG_B(i)]->v;
> TValue *rc = RKC(i);
> gettableProtected(L, upval, rc, ra);
805c824,826
< Protect(luaV_gettable(L, RB(i), RKC(i), ra));
> StkId rb = RB(i);
> TValue *rc = RKC(i);
> gettableProtected(L, rb, rc, ra);
809,810c830,833
< int a = GETARG_A(i);
< Protect(luaV_settable(L, cl->upvals[a]->v, RKB(i), RKC(i)));
> TValue *upval = cl->upvals[GETARG_A(i)]->v;
> TValue *rb = RKB(i);
> TValue *rc = RKC(i);
> settableProtected(L, upval, rb, rc);
820c843,845
< Protect(luaV_settable(L, ra, RKB(i), RKC(i)));
> TValue *rb = RKB(i);
> TValue *rc = RKC(i);
> settableProtected(L, ra, rb, rc);
833a859
> const TValue *aux;
835,836c861,867
< setobjs2s(L, ra+1, rb);
< Protect(luaV_gettable(L, rb, RKC(i), ra));
> TValue *rc = RKC(i);
> TString *key = tsvalue(rc); /* key must be a string */
> setobjs2s(L, ra + 1, rb);
> if (luaV_fastget(L, rb, key, aux, luaH_getstr)) {
> setobj2s(L, ra, aux);
> }
> else Protect(luaV_finishget(L, rb, rc, ra, aux));
1023c1054
< ra = RA(i); /* 'luav_concat' may invoke TMs and move the stack */
> ra = RA(i); /* 'luaV_concat' may invoke TMs and move the stack */
1038c1069
< if (cast_int(luaV_equalobj(L, rb, rc)) != GETARG_A(i))
> if (luaV_equalobj(L, rb, rc) != GETARG_A(i))
1085,1086c1116,1118
< if (nresults >= 0) L->top = ci->top; /* adjust results */
< base = ci->u.l.base;
> if (nresults >= 0)
> L->top = ci->top; /* adjust results */
> Protect((void)0); /* update 'base' */
1090d1121
< ci->callstatus |= CIST_REENTRY;
1099,1100c1130,1132
< if (luaD_precall(L, ra, LUA_MULTRET)) /* C function? */
< base = ci->u.l.base;
> if (luaD_precall(L, ra, LUA_MULTRET)) { /* C function? */
> Protect((void)0); /* update 'base' */
> }
1128,1129c1160,1161
< b = luaD_poscall(L, ra, (b != 0 ? b - 1 : L->top - ra));
< if (!(ci->callstatus & CIST_REENTRY)) /* 'ci' still the called one */
> b = luaD_poscall(L, ci, ra, (b != 0 ? b - 1 : cast_int(L->top - ra)));
> if (ci->callstatus & CIST_FRESH) /* local 'ci' still from callee */
1142c1174
< lua_Integer idx = ivalue(ra) + step; /* increment index */
> lua_Integer idx = intop(+, ivalue(ra), step); /* increment index */
1174c1206
< setivalue(init, initv - ivalue(pstep));
> setivalue(init, intop(-, initv, ivalue(pstep)));
1197c1229
< Protect(luaD_call(L, cb, GETARG_C(i), 1));
> Protect(luaD_call(L, cb, GETARG_C(i)));
1222d1253
< luai_runtimecheck(L, ttistable(ra));
1226c1257
< luaH_resizearray(L, h, last); /* pre-allocate it at once */
> luaH_resizearray(L, h, last); /* preallocate it at once */
1246c1277
< int b = GETARG_B(i) - 1;
> int b = GETARG_B(i) - 1; /* required results */
1248a1280,1281
> if (n < 0) /* less arguments than parameters? */
> n = 0; /* no vararg arguments */
1255,1262c1288,1291
< for (j = 0; j < b; j++) {
< if (j < n) {
< setobjs2s(L, ra + j, base - n + j);
< }
< else {
< setnilvalue(ra + j);
< }
< }
> for (j = 0; j < b && j < n; j++)
> setobjs2s(L, ra + j, base - n + j);
> for (; j < b; j++) /* complete required results with nil */
> setnilvalue(ra + j);
src/lvm.h
2c2
< ** $Id: lvm.h,v 2.35 2015/02/20 14:27:53 roberto Exp $
> ** $Id: lvm.h,v 2.39 2015/09/09 13:44:07 roberto Exp $
50a51,96
> /*
> ** fast track for 'gettable': 1 means 'aux' points to resulted value;
> ** 0 means 'aux' is metamethod (if 't' is a table) or NULL. 'f' is
> ** the raw get function to use.
> */
> #define luaV_fastget(L,t,k,aux,f) \
> (!ttistable(t) \
> ? (aux = NULL, 0) /* not a table; 'aux' is NULL and result is 0 */ \
> : (aux = f(hvalue(t), k), /* else, do raw access */ \
> !ttisnil(aux) ? 1 /* result not nil? 'aux' has it */ \
> : (aux = fasttm(L, hvalue(t)->metatable, TM_INDEX), /* get metamethod */\
> aux != NULL ? 0 /* has metamethod? must call it */ \
> : (aux = luaO_nilobject, 1)))) /* else, final result is nil */
>
> /*
> ** standard implementation for 'gettable'
> */
> #define luaV_gettable(L,t,k,v) { const TValue *aux; \
> if (luaV_fastget(L,t,k,aux,luaH_get)) { setobj2s(L, v, aux); } \
> else luaV_finishget(L,t,k,v,aux); }
>
>
> /*
> ** Fast track for set table. If 't' is a table and 't[k]' is not nil,
> ** call GC barrier, do a raw 't[k]=v', and return true; otherwise,
> ** return false with 'slot' equal to NULL (if 't' is not a table) or
> ** 'nil'. (This is needed by 'luaV_finishget'.) Note that, if the macro
> ** returns true, there is no need to 'invalidateTMcache', because the
> ** call is not creating a new entry.
> */
> #define luaV_fastset(L,t,k,slot,f,v) \
> (!ttistable(t) \
> ? (slot = NULL, 0) \
> : (slot = f(hvalue(t), k), \
> ttisnil(slot) ? 0 \
> : (luaC_barrierback(L, hvalue(t), v), \
> setobj2t(L, cast(TValue *,slot), v), \
> 1)))
>
>
> #define luaV_settable(L,t,k,v) { const TValue *slot; \
> if (!luaV_fastset(L,t,k,slot,luaH_get,v)) \
> luaV_finishset(L,t,k,v,slot); }
>
>
>
56,59c102,105
< LUAI_FUNC void luaV_gettable (lua_State *L, const TValue *t, TValue *key,
< StkId val);
< LUAI_FUNC void luaV_settable (lua_State *L, const TValue *t, TValue *key,
< StkId val);
> LUAI_FUNC void luaV_finishget (lua_State *L, const TValue *t, TValue *key,
> StkId val, const TValue *tm);
> LUAI_FUNC void luaV_finishset (lua_State *L, const TValue *t, TValue *key,
> StkId val, const TValue *oldval);
src/lzio.c
2c2
< ** $Id: lzio.c,v 1.36 2014/11/02 19:19:04 roberto Exp $
> ** $Id: lzio.c,v 1.37 2015/09/08 15:41:05 roberto Exp $
69,78d68
< /* ------------------------------------------------------------------------ */
< char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n) {
< if (n > buff->buffsize) {
< if (n < LUA_MINBUFFER) n = LUA_MINBUFFER;
< luaZ_resizebuffer(L, buff, n);
< }
< return buff->buffer;
< }
<
<
src/lzio.h
2c2
< ** $Id: lzio.h,v 1.30 2014/12/19 17:26:14 roberto Exp $
> ** $Id: lzio.h,v 1.31 2015/09/08 15:41:05 roberto Exp $
47d46
< LUAI_FUNC char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n);