diff options
-rw-r--r-- | ldo.c | 18 | ||||
-rw-r--r-- | llimits.h | 21 | ||||
-rw-r--r-- | lmem.c | 44 | ||||
-rw-r--r-- | lstring.c | 10 | ||||
-rw-r--r-- | ltable.c | 11 | ||||
-rw-r--r-- | lvm.c | 22 |
6 files changed, 78 insertions, 48 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.c,v 2.200 2018/03/16 15:33:34 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 2.201 2018/05/22 12:02:36 roberto Exp roberto $ |
3 | ** Stack and Call structure of Lua | 3 | ** Stack and Call structure of Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -182,7 +182,7 @@ int luaD_reallocstack (lua_State *L, int newsize, int raiseerror) { | |||
182 | StkId newstack = luaM_reallocvector(L, L->stack, lim, newsize, StackValue); | 182 | StkId newstack = luaM_reallocvector(L, L->stack, lim, newsize, StackValue); |
183 | lua_assert(newsize <= LUAI_MAXSTACK || newsize == ERRORSTACKSIZE); | 183 | lua_assert(newsize <= LUAI_MAXSTACK || newsize == ERRORSTACKSIZE); |
184 | lua_assert(L->stack_last - L->stack == L->stacksize - EXTRA_STACK); | 184 | lua_assert(L->stack_last - L->stack == L->stacksize - EXTRA_STACK); |
185 | if (newstack == NULL) { /* reallocation failed? */ | 185 | if (unlikely(newstack == NULL)) { /* reallocation failed? */ |
186 | if (raiseerror) | 186 | if (raiseerror) |
187 | luaM_error(L); | 187 | luaM_error(L); |
188 | else return 0; /* do not raise an error */ | 188 | else return 0; /* do not raise an error */ |
@@ -204,7 +204,7 @@ int luaD_reallocstack (lua_State *L, int newsize, int raiseerror) { | |||
204 | int luaD_growstack (lua_State *L, int n, int raiseerror) { | 204 | int luaD_growstack (lua_State *L, int n, int raiseerror) { |
205 | int size = L->stacksize; | 205 | int size = L->stacksize; |
206 | int newsize = 2 * size; /* tentative new size */ | 206 | int newsize = 2 * size; /* tentative new size */ |
207 | if (size > LUAI_MAXSTACK) { /* need more space after extra size? */ | 207 | if (unlikely(size > LUAI_MAXSTACK)) { /* need more space after extra size? */ |
208 | if (raiseerror) | 208 | if (raiseerror) |
209 | luaD_throw(L, LUA_ERRERR); /* error inside message handler */ | 209 | luaD_throw(L, LUA_ERRERR); /* error inside message handler */ |
210 | else return 0; | 210 | else return 0; |
@@ -215,7 +215,7 @@ int luaD_growstack (lua_State *L, int n, int raiseerror) { | |||
215 | newsize = LUAI_MAXSTACK; | 215 | newsize = LUAI_MAXSTACK; |
216 | if (newsize < needed) /* but must respect what was asked for */ | 216 | if (newsize < needed) /* but must respect what was asked for */ |
217 | newsize = needed; | 217 | newsize = needed; |
218 | if (newsize > LUAI_MAXSTACK) { /* stack overflow? */ | 218 | if (unlikely(newsize > LUAI_MAXSTACK)) { /* stack overflow? */ |
219 | /* add extra size to be able to handle the error message */ | 219 | /* add extra size to be able to handle the error message */ |
220 | luaD_reallocstack(L, ERRORSTACKSIZE, raiseerror); | 220 | luaD_reallocstack(L, ERRORSTACKSIZE, raiseerror); |
221 | if (raiseerror) | 221 | if (raiseerror) |
@@ -350,7 +350,7 @@ static StkId rethook (lua_State *L, CallInfo *ci, StkId firstres, int nres) { | |||
350 | void luaD_tryfuncTM (lua_State *L, StkId func) { | 350 | void luaD_tryfuncTM (lua_State *L, StkId func) { |
351 | const TValue *tm = luaT_gettmbyobj(L, s2v(func), TM_CALL); | 351 | const TValue *tm = luaT_gettmbyobj(L, s2v(func), TM_CALL); |
352 | StkId p; | 352 | StkId p; |
353 | if (!ttisfunction(tm)) | 353 | if (unlikely(!ttisfunction(tm))) |
354 | luaG_typeerror(L, s2v(func), "call"); | 354 | luaG_typeerror(L, s2v(func), "call"); |
355 | for (p = L->top; p > func; p--) | 355 | for (p = L->top; p > func; p--) |
356 | setobjs2s(L, p, p-1); | 356 | setobjs2s(L, p, p-1); |
@@ -660,14 +660,14 @@ LUA_API int lua_resume (lua_State *L, lua_State *from, int nargs, | |||
660 | L->nny = 0; /* allow yields */ | 660 | L->nny = 0; /* allow yields */ |
661 | api_checknelems(L, (L->status == LUA_OK) ? nargs + 1 : nargs); | 661 | api_checknelems(L, (L->status == LUA_OK) ? nargs + 1 : nargs); |
662 | status = luaD_rawrunprotected(L, resume, &nargs); | 662 | status = luaD_rawrunprotected(L, resume, &nargs); |
663 | if (status == -1) /* error calling 'lua_resume'? */ | 663 | if (unlikely(status == -1)) /* error calling 'lua_resume'? */ |
664 | status = LUA_ERRRUN; | 664 | status = LUA_ERRRUN; |
665 | else { /* continue running after recoverable errors */ | 665 | else { /* continue running after recoverable errors */ |
666 | while (errorstatus(status) && recover(L, status)) { | 666 | while (errorstatus(status) && recover(L, status)) { |
667 | /* unroll continuation */ | 667 | /* unroll continuation */ |
668 | status = luaD_rawrunprotected(L, unroll, &status); | 668 | status = luaD_rawrunprotected(L, unroll, &status); |
669 | } | 669 | } |
670 | if (errorstatus(status)) { /* unrecoverable error? */ | 670 | if (unlikely(errorstatus(status))) { /* unrecoverable error? */ |
671 | L->status = cast_byte(status); /* mark thread as 'dead' */ | 671 | L->status = cast_byte(status); /* mark thread as 'dead' */ |
672 | seterrorobj(L, status, L->top); /* push error message */ | 672 | seterrorobj(L, status, L->top); /* push error message */ |
673 | L->ci->top = L->top; | 673 | L->ci->top = L->top; |
@@ -694,7 +694,7 @@ LUA_API int lua_yieldk (lua_State *L, int nresults, lua_KContext ctx, | |||
694 | luai_userstateyield(L, nresults); | 694 | luai_userstateyield(L, nresults); |
695 | lua_lock(L); | 695 | lua_lock(L); |
696 | api_checknelems(L, nresults); | 696 | api_checknelems(L, nresults); |
697 | if (L->nny > 0) { | 697 | if (unlikely(L->nny > 0)) { |
698 | if (L != G(L)->mainthread) | 698 | if (L != G(L)->mainthread) |
699 | luaG_runerror(L, "attempt to yield across a C-call boundary"); | 699 | luaG_runerror(L, "attempt to yield across a C-call boundary"); |
700 | else | 700 | else |
@@ -727,7 +727,7 @@ int luaD_pcall (lua_State *L, Pfunc func, void *u, | |||
727 | ptrdiff_t old_errfunc = L->errfunc; | 727 | ptrdiff_t old_errfunc = L->errfunc; |
728 | L->errfunc = ef; | 728 | L->errfunc = ef; |
729 | status = luaD_rawrunprotected(L, func, u); | 729 | status = luaD_rawrunprotected(L, func, u); |
730 | if (status != LUA_OK) { /* an error occurred? */ | 730 | if (unlikely(status != LUA_OK)) { /* an error occurred? */ |
731 | StkId oldtop = restorestack(L, old_top); | 731 | StkId oldtop = restorestack(L, old_top); |
732 | luaF_close(L, oldtop); /* close possible pending closures */ | 732 | luaF_close(L, oldtop); /* close possible pending closures */ |
733 | seterrorobj(L, status, oldtop); | 733 | seterrorobj(L, status, oldtop); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: llimits.h,v 1.148 2017/12/28 11:51:00 roberto Exp roberto $ | 2 | ** $Id: llimits.h,v 1.149 2018/01/28 15:13:26 roberto Exp roberto $ |
3 | ** Limits, basic types, and some other 'installation-dependent' definitions | 3 | ** Limits, basic types, and some other 'installation-dependent' definitions |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -131,8 +131,26 @@ typedef LUAI_UACINT l_uacInt; | |||
131 | 131 | ||
132 | 132 | ||
133 | /* | 133 | /* |
134 | ** macros to improve jump prediction (used mainly for error handling) | ||
135 | */ | ||
136 | #if !defined(likely) | ||
137 | |||
138 | #if defined(__GNUC__) | ||
139 | #define likely(x) (__builtin_expect(((x) != 0), 1)) | ||
140 | #define unlikely(x) (__builtin_expect(((x) != 0), 0)) | ||
141 | #else | ||
142 | #define likely(x) (x) | ||
143 | #define unlikely(x) (x) | ||
144 | #endif | ||
145 | |||
146 | #endif | ||
147 | |||
148 | |||
149 | /* | ||
134 | ** non-return type | 150 | ** non-return type |
135 | */ | 151 | */ |
152 | #if !defined(l_noret) | ||
153 | |||
136 | #if defined(__GNUC__) | 154 | #if defined(__GNUC__) |
137 | #define l_noret void __attribute__((noreturn)) | 155 | #define l_noret void __attribute__((noreturn)) |
138 | #elif defined(_MSC_VER) && _MSC_VER >= 1200 | 156 | #elif defined(_MSC_VER) && _MSC_VER >= 1200 |
@@ -141,6 +159,7 @@ typedef LUAI_UACINT l_uacInt; | |||
141 | #define l_noret void | 159 | #define l_noret void |
142 | #endif | 160 | #endif |
143 | 161 | ||
162 | #endif | ||
144 | 163 | ||
145 | 164 | ||
146 | /* | 165 | /* |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lmem.c,v 1.95 2017/12/11 12:27:48 roberto Exp roberto $ | 2 | ** $Id: lmem.c,v 1.96 2018/01/28 15:13:26 roberto Exp roberto $ |
3 | ** Interface to Memory Manager | 3 | ** Interface to Memory Manager |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -60,7 +60,7 @@ void *luaM_growaux_ (lua_State *L, void *block, int nelems, int *psize, | |||
60 | if (nelems + 1 <= size) /* does one extra element still fit? */ | 60 | if (nelems + 1 <= size) /* does one extra element still fit? */ |
61 | return block; /* nothing to be done */ | 61 | return block; /* nothing to be done */ |
62 | if (size >= limit / 2) { /* cannot double it? */ | 62 | if (size >= limit / 2) { /* cannot double it? */ |
63 | if (size >= limit) /* cannot grow even a little? */ | 63 | if (unlikely(size >= limit)) /* cannot grow even a little? */ |
64 | luaG_runerror(L, "too many %s (limit is %d)", what, limit); | 64 | luaG_runerror(L, "too many %s (limit is %d)", what, limit); |
65 | size = limit; /* still have at least one free place */ | 65 | size = limit; /* still have at least one free place */ |
66 | } | 66 | } |
@@ -73,7 +73,7 @@ void *luaM_growaux_ (lua_State *L, void *block, int nelems, int *psize, | |||
73 | /* 'limit' ensures that multiplication will not overflow */ | 73 | /* 'limit' ensures that multiplication will not overflow */ |
74 | newblock = luaM_realloc_(L, block, cast_sizet(*psize) * size_elems, | 74 | newblock = luaM_realloc_(L, block, cast_sizet(*psize) * size_elems, |
75 | cast_sizet(size) * size_elems); | 75 | cast_sizet(size) * size_elems); |
76 | if (newblock == NULL) | 76 | if (unlikely(newblock == NULL)) |
77 | luaM_error(L); | 77 | luaM_error(L); |
78 | *psize = size; /* update only when everything else is OK */ | 78 | *psize = size; /* update only when everything else is OK */ |
79 | return newblock; | 79 | return newblock; |
@@ -88,7 +88,7 @@ void *luaM_shrinkvector_ (lua_State *L, void *block, int *size, | |||
88 | size_t newsize = cast_sizet(final_n * size_elem); | 88 | size_t newsize = cast_sizet(final_n * size_elem); |
89 | lua_assert(newsize <= oldsize); | 89 | lua_assert(newsize <= oldsize); |
90 | newblock = (*g->frealloc)(g->ud, block, oldsize, newsize); | 90 | newblock = (*g->frealloc)(g->ud, block, oldsize, newsize); |
91 | if (newblock == NULL && final_n > 0) /* allocation failed? */ | 91 | if (unlikely(newblock == NULL && final_n > 0)) /* allocation failed? */ |
92 | luaM_error(L); | 92 | luaM_error(L); |
93 | else { | 93 | else { |
94 | g->GCdebt += newsize - oldsize; | 94 | g->GCdebt += newsize - oldsize; |
@@ -114,6 +114,22 @@ void luaM_free_ (lua_State *L, void *block, size_t osize) { | |||
114 | } | 114 | } |
115 | 115 | ||
116 | 116 | ||
117 | /* | ||
118 | ** In case of allocation fail, this function will call the GC to try | ||
119 | ** to free some memory and then try the allocation again. | ||
120 | ** (It should not be called when shrinking a block, because then the | ||
121 | ** interpreter may be in the middle of a collection step.) | ||
122 | */ | ||
123 | static void *tryagain (lua_State *L, void *block, | ||
124 | size_t osize, size_t nsize) { | ||
125 | global_State *g = G(L); | ||
126 | if (g->version) { /* is state fully build? */ | ||
127 | luaC_fullgc(L, 1); /* try to free some memory... */ | ||
128 | return (*g->frealloc)(g->ud, block, osize, nsize); /* try again */ | ||
129 | } | ||
130 | else return NULL; /* cannot free any memory without a full state */ | ||
131 | } | ||
132 | |||
117 | 133 | ||
118 | /* | 134 | /* |
119 | ** generic allocation routine. | 135 | ** generic allocation routine. |
@@ -124,13 +140,10 @@ void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) { | |||
124 | lua_assert((osize == 0) == (block == NULL)); | 140 | lua_assert((osize == 0) == (block == NULL)); |
125 | hardtest(L, osize, nsize); | 141 | hardtest(L, osize, nsize); |
126 | newblock = (*g->frealloc)(g->ud, block, osize, nsize); | 142 | newblock = (*g->frealloc)(g->ud, block, osize, nsize); |
127 | if (newblock == NULL && nsize > 0) { | 143 | if (unlikely(newblock == NULL && nsize > 0)) { |
128 | /* Is state fully built? Not shrinking a block? */ | 144 | if (nsize > osize) /* not shrinking a block? */ |
129 | if (g->version && nsize > osize) { | 145 | newblock = tryagain(L, block, osize, nsize); |
130 | luaC_fullgc(L, 1); /* try to free some memory... */ | 146 | if (newblock == NULL) /* still no memory? */ |
131 | newblock = (*g->frealloc)(g->ud, block, osize, nsize); /* try again */ | ||
132 | } | ||
133 | if (newblock == NULL) | ||
134 | return NULL; | 147 | return NULL; |
135 | } | 148 | } |
136 | lua_assert((nsize == 0) == (newblock == NULL)); | 149 | lua_assert((nsize == 0) == (newblock == NULL)); |
@@ -142,7 +155,7 @@ void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) { | |||
142 | void *luaM_saferealloc_ (lua_State *L, void *block, size_t osize, | 155 | void *luaM_saferealloc_ (lua_State *L, void *block, size_t osize, |
143 | size_t nsize) { | 156 | size_t nsize) { |
144 | void *newblock = luaM_realloc_(L, block, osize, nsize); | 157 | void *newblock = luaM_realloc_(L, block, osize, nsize); |
145 | if (newblock == NULL && nsize > 0) /* allocation failed? */ | 158 | if (unlikely(newblock == NULL && nsize > 0)) /* allocation failed? */ |
146 | luaM_error(L); | 159 | luaM_error(L); |
147 | return newblock; | 160 | return newblock; |
148 | } | 161 | } |
@@ -155,11 +168,8 @@ void *luaM_malloc_ (lua_State *L, size_t size, int tag) { | |||
155 | else { | 168 | else { |
156 | global_State *g = G(L); | 169 | global_State *g = G(L); |
157 | void *newblock = (*g->frealloc)(g->ud, NULL, tag, size); | 170 | void *newblock = (*g->frealloc)(g->ud, NULL, tag, size); |
158 | if (newblock == NULL) { | 171 | if (unlikely(newblock == NULL)) { |
159 | if (g->version) { /* is state fully built? */ | 172 | newblock = tryagain(L, NULL, tag, size); |
160 | luaC_fullgc(L, 1); /* try to free some memory... */ | ||
161 | newblock = (*g->frealloc)(g->ud, NULL, tag, size); /* try again */ | ||
162 | } | ||
163 | if (newblock == NULL) | 173 | if (newblock == NULL) |
164 | luaM_error(L); | 174 | luaM_error(L); |
165 | } | 175 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstring.c,v 2.64 2018/02/15 18:06:24 roberto Exp roberto $ | 2 | ** $Id: lstring.c,v 2.65 2018/02/20 16:52:50 roberto Exp roberto $ |
3 | ** String table (keeps all strings handled by Lua) | 3 | ** String table (keeps all strings handled by Lua) |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -99,7 +99,7 @@ void luaS_resize (lua_State *L, int nsize) { | |||
99 | if (nsize < osize) /* shrinking table? */ | 99 | if (nsize < osize) /* shrinking table? */ |
100 | tablerehash(tb->hash, osize, nsize); /* depopulate shrinking part */ | 100 | tablerehash(tb->hash, osize, nsize); /* depopulate shrinking part */ |
101 | newvect = luaM_reallocvector(L, tb->hash, osize, nsize, TString*); | 101 | newvect = luaM_reallocvector(L, tb->hash, osize, nsize, TString*); |
102 | if (newvect == NULL) { /* reallocation failed? */ | 102 | if (unlikely(newvect == NULL)) { /* reallocation failed? */ |
103 | if (nsize < osize) /* was it shrinking table? */ | 103 | if (nsize < osize) /* was it shrinking table? */ |
104 | tablerehash(tb->hash, nsize, osize); /* restore to original size */ | 104 | tablerehash(tb->hash, nsize, osize); /* restore to original size */ |
105 | /* leave table as it was */ | 105 | /* leave table as it was */ |
@@ -182,7 +182,7 @@ void luaS_remove (lua_State *L, TString *ts) { | |||
182 | 182 | ||
183 | 183 | ||
184 | static void growstrtab (lua_State *L, stringtable *tb) { | 184 | static void growstrtab (lua_State *L, stringtable *tb) { |
185 | if (tb->nuse == MAX_INT) { /* too many strings? */ | 185 | if (unlikely(tb->nuse == MAX_INT)) { /* too many strings? */ |
186 | luaC_fullgc(L, 1); /* try to free some... */ | 186 | luaC_fullgc(L, 1); /* try to free some... */ |
187 | if (tb->nuse == MAX_INT) /* still too many? */ | 187 | if (tb->nuse == MAX_INT) /* still too many? */ |
188 | luaM_error(L); /* cannot even create a message... */ | 188 | luaM_error(L); /* cannot even create a message... */ |
@@ -233,7 +233,7 @@ TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { | |||
233 | return internshrstr(L, str, l); | 233 | return internshrstr(L, str, l); |
234 | else { | 234 | else { |
235 | TString *ts; | 235 | TString *ts; |
236 | if (l >= (MAX_SIZE - sizeof(TString))/sizeof(char)) | 236 | if (unlikely(l >= (MAX_SIZE - sizeof(TString))/sizeof(char))) |
237 | luaM_toobig(L); | 237 | luaM_toobig(L); |
238 | ts = luaS_createlngstrobj(L, l); | 238 | ts = luaS_createlngstrobj(L, l); |
239 | memcpy(getstr(ts), str, l * sizeof(char)); | 239 | memcpy(getstr(ts), str, l * sizeof(char)); |
@@ -269,7 +269,7 @@ Udata *luaS_newudata (lua_State *L, size_t s, int nuvalue) { | |||
269 | Udata *u; | 269 | Udata *u; |
270 | int i; | 270 | int i; |
271 | GCObject *o; | 271 | GCObject *o; |
272 | if (s > MAX_SIZE - udatamemoffset(nuvalue)) | 272 | if (unlikely(s > MAX_SIZE - udatamemoffset(nuvalue))) |
273 | luaM_toobig(L); | 273 | luaM_toobig(L); |
274 | o = luaC_newobj(L, LUA_TUSERDATA, sizeudata(nuvalue, s)); | 274 | o = luaC_newobj(L, LUA_TUSERDATA, sizeudata(nuvalue, s)); |
275 | u = gco2u(o); | 275 | u = gco2u(o); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltable.c,v 2.135 2018/02/26 14:16:05 roberto Exp roberto $ | 2 | ** $Id: ltable.c,v 2.136 2018/05/29 18:01:50 roberto Exp roberto $ |
3 | ** Lua tables (hash) | 3 | ** Lua tables (hash) |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -235,7 +235,7 @@ static unsigned int findindex (lua_State *L, Table *t, TValue *key) { | |||
235 | return i; /* yes; that's the index */ | 235 | return i; /* yes; that's the index */ |
236 | else { | 236 | else { |
237 | const TValue *n = getgeneric(t, key); | 237 | const TValue *n = getgeneric(t, key); |
238 | if (n == luaH_emptyobject) | 238 | if (unlikely(n == luaH_emptyobject)) |
239 | luaG_runerror(L, "invalid key to 'next'"); /* key not found */ | 239 | luaG_runerror(L, "invalid key to 'next'"); /* key not found */ |
240 | i = cast_int(nodefromval(n) - gnode(t, 0)); /* key index in hash table */ | 240 | i = cast_int(nodefromval(n) - gnode(t, 0)); /* key index in hash table */ |
241 | /* hash elements are numbered after array ones */ | 241 | /* hash elements are numbered after array ones */ |
@@ -467,7 +467,7 @@ void luaH_resize (lua_State *L, Table *t, unsigned int newasize, | |||
467 | } | 467 | } |
468 | /* allocate new array */ | 468 | /* allocate new array */ |
469 | newarray = luaM_reallocvector(L, t->array, oldasize, newasize, TValue); | 469 | newarray = luaM_reallocvector(L, t->array, oldasize, newasize, TValue); |
470 | if (newarray == NULL && newasize > 0) { /* allocation failed? */ | 470 | if (unlikely(newarray == NULL && newasize > 0)) { /* allocation failed? */ |
471 | freehash(L, &newt); /* release new hash part */ | 471 | freehash(L, &newt); /* release new hash part */ |
472 | luaM_error(L); /* raise error (with array unchanged) */ | 472 | luaM_error(L); /* raise error (with array unchanged) */ |
473 | } | 473 | } |
@@ -560,7 +560,8 @@ static Node *getfreepos (Table *t) { | |||
560 | TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key) { | 560 | TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key) { |
561 | Node *mp; | 561 | Node *mp; |
562 | TValue aux; | 562 | TValue aux; |
563 | if (ttisnil(key)) luaG_runerror(L, "table index is nil"); | 563 | if (unlikely(ttisnil(key))) |
564 | luaG_runerror(L, "table index is nil"); | ||
564 | else if (ttisfloat(key)) { | 565 | else if (ttisfloat(key)) { |
565 | lua_Number f = fltvalue(key); | 566 | lua_Number f = fltvalue(key); |
566 | lua_Integer k; | 567 | lua_Integer k; |
@@ -568,7 +569,7 @@ TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key) { | |||
568 | setivalue(&aux, k); | 569 | setivalue(&aux, k); |
569 | key = &aux; /* insert it as an integer */ | 570 | key = &aux; /* insert it as an integer */ |
570 | } | 571 | } |
571 | else if (luai_numisnan(f)) | 572 | else if (unlikely(luai_numisnan(f))) |
572 | luaG_runerror(L, "table index is NaN"); | 573 | luaG_runerror(L, "table index is NaN"); |
573 | } | 574 | } |
574 | mp = mainpositionTV(t, key); | 575 | mp = mainpositionTV(t, key); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 2.354 2018/05/02 18:17:59 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 2.355 2018/05/22 12:02:36 roberto Exp roberto $ |
3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -196,7 +196,7 @@ void luaV_finishget (lua_State *L, const TValue *t, TValue *key, StkId val, | |||
196 | if (slot == NULL) { /* 't' is not a table? */ | 196 | if (slot == NULL) { /* 't' is not a table? */ |
197 | lua_assert(!ttistable(t)); | 197 | lua_assert(!ttistable(t)); |
198 | tm = luaT_gettmbyobj(L, t, TM_INDEX); | 198 | tm = luaT_gettmbyobj(L, t, TM_INDEX); |
199 | if (notm(tm)) | 199 | if (unlikely(notm(tm))) |
200 | luaG_typeerror(L, t, "index"); /* no metamethod */ | 200 | luaG_typeerror(L, t, "index"); /* no metamethod */ |
201 | /* else will try the metamethod */ | 201 | /* else will try the metamethod */ |
202 | } | 202 | } |
@@ -253,7 +253,7 @@ void luaV_finishset (lua_State *L, const TValue *t, TValue *key, | |||
253 | } | 253 | } |
254 | else { /* not a table; check metamethod */ | 254 | else { /* not a table; check metamethod */ |
255 | tm = luaT_gettmbyobj(L, t, TM_NEWINDEX); | 255 | tm = luaT_gettmbyobj(L, t, TM_NEWINDEX); |
256 | if (notm(tm)) | 256 | if (unlikely(notm(tm))) |
257 | luaG_typeerror(L, t, "index"); | 257 | luaG_typeerror(L, t, "index"); |
258 | } | 258 | } |
259 | /* try the metamethod */ | 259 | /* try the metamethod */ |
@@ -561,7 +561,7 @@ void luaV_concat (lua_State *L, int total) { | |||
561 | /* collect total length and number of strings */ | 561 | /* collect total length and number of strings */ |
562 | for (n = 1; n < total && tostring(L, s2v(top - n - 1)); n++) { | 562 | for (n = 1; n < total && tostring(L, s2v(top - n - 1)); n++) { |
563 | size_t l = vslen(s2v(top - n - 1)); | 563 | size_t l = vslen(s2v(top - n - 1)); |
564 | if (l >= (MAX_SIZE/sizeof(char)) - tl) | 564 | if (unlikely(l >= (MAX_SIZE/sizeof(char)) - tl)) |
565 | luaG_runerror(L, "string length overflow"); | 565 | luaG_runerror(L, "string length overflow"); |
566 | tl += l; | 566 | tl += l; |
567 | } | 567 | } |
@@ -605,7 +605,7 @@ void luaV_objlen (lua_State *L, StkId ra, const TValue *rb) { | |||
605 | } | 605 | } |
606 | default: { /* try metamethod */ | 606 | default: { /* try metamethod */ |
607 | tm = luaT_gettmbyobj(L, rb, TM_LEN); | 607 | tm = luaT_gettmbyobj(L, rb, TM_LEN); |
608 | if (notm(tm)) /* no metamethod? */ | 608 | if (unlikely(notm(tm))) /* no metamethod? */ |
609 | luaG_typeerror(L, rb, "get length of"); | 609 | luaG_typeerror(L, rb, "get length of"); |
610 | break; | 610 | break; |
611 | } | 611 | } |
@@ -622,7 +622,7 @@ void luaV_objlen (lua_State *L, StkId ra, const TValue *rb) { | |||
622 | */ | 622 | */ |
623 | lua_Integer luaV_div (lua_State *L, lua_Integer m, lua_Integer n) { | 623 | lua_Integer luaV_div (lua_State *L, lua_Integer m, lua_Integer n) { |
624 | if (l_castS2U(n) + 1u <= 1u) { /* special cases: -1 or 0 */ | 624 | if (l_castS2U(n) + 1u <= 1u) { /* special cases: -1 or 0 */ |
625 | if (n == 0) | 625 | if (unlikely(n == 0)) |
626 | luaG_runerror(L, "attempt to divide by zero"); | 626 | luaG_runerror(L, "attempt to divide by zero"); |
627 | return intop(-, 0, m); /* n==-1; avoid overflow with 0x80000...//-1 */ | 627 | return intop(-, 0, m); /* n==-1; avoid overflow with 0x80000...//-1 */ |
628 | } | 628 | } |
@@ -642,7 +642,7 @@ lua_Integer luaV_div (lua_State *L, lua_Integer m, lua_Integer n) { | |||
642 | */ | 642 | */ |
643 | lua_Integer luaV_mod (lua_State *L, lua_Integer m, lua_Integer n) { | 643 | lua_Integer luaV_mod (lua_State *L, lua_Integer m, lua_Integer n) { |
644 | if (l_castS2U(n) + 1u <= 1u) { /* special cases: -1 or 0 */ | 644 | if (l_castS2U(n) + 1u <= 1u) { /* special cases: -1 or 0 */ |
645 | if (n == 0) | 645 | if (unlikely(n == 0)) |
646 | luaG_runerror(L, "attempt to perform 'n%%0'"); | 646 | luaG_runerror(L, "attempt to perform 'n%%0'"); |
647 | return 0; /* m % -1 == 0; avoid overflow with 0x80000...%-1 */ | 647 | return 0; /* m % -1 == 0; avoid overflow with 0x80000...%-1 */ |
648 | } | 648 | } |
@@ -1665,7 +1665,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) { | |||
1665 | TValue *plimit = s2v(ra + 1); | 1665 | TValue *plimit = s2v(ra + 1); |
1666 | lua_Integer ilimit, initv; | 1666 | lua_Integer ilimit, initv; |
1667 | int stopnow; | 1667 | int stopnow; |
1668 | if (!forlimit(plimit, &ilimit, 1, &stopnow)) { | 1668 | if (unlikely(!forlimit(plimit, &ilimit, 1, &stopnow))) { |
1669 | savestate(L, ci); /* for the error message */ | 1669 | savestate(L, ci); /* for the error message */ |
1670 | luaG_runerror(L, "'for' limit must be a number"); | 1670 | luaG_runerror(L, "'for' limit must be a number"); |
1671 | } | 1671 | } |
@@ -1717,13 +1717,13 @@ void luaV_execute (lua_State *L, CallInfo *ci) { | |||
1717 | else { /* try making all values floats */ | 1717 | else { /* try making all values floats */ |
1718 | lua_Number ninit; lua_Number nlimit; lua_Number nstep; | 1718 | lua_Number ninit; lua_Number nlimit; lua_Number nstep; |
1719 | savestate(L, ci); /* in case of errors */ | 1719 | savestate(L, ci); /* in case of errors */ |
1720 | if (!tonumber(plimit, &nlimit)) | 1720 | if (unlikely(!tonumber(plimit, &nlimit))) |
1721 | luaG_runerror(L, "'for' limit must be a number"); | 1721 | luaG_runerror(L, "'for' limit must be a number"); |
1722 | setfltvalue(plimit, nlimit); | 1722 | setfltvalue(plimit, nlimit); |
1723 | if (!tonumber(pstep, &nstep)) | 1723 | if (unlikely(!tonumber(pstep, &nstep))) |
1724 | luaG_runerror(L, "'for' step must be a number"); | 1724 | luaG_runerror(L, "'for' step must be a number"); |
1725 | setfltvalue(pstep, nstep); | 1725 | setfltvalue(pstep, nstep); |
1726 | if (!tonumber(init, &ninit)) | 1726 | if (unlikely(!tonumber(init, &ninit))) |
1727 | luaG_runerror(L, "'for' initial value must be a number"); | 1727 | luaG_runerror(L, "'for' initial value must be a number"); |
1728 | setfltvalue(init, luai_numsub(L, ninit, nstep)); | 1728 | setfltvalue(init, luai_numsub(L, ninit, nstep)); |
1729 | } | 1729 | } |