aboutsummaryrefslogtreecommitdiff
path: root/src/3rdParty
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2022-09-30 11:29:41 +0800
committerLi Jin <dragon-fly@qq.com>2022-09-30 11:29:41 +0800
commit5aa41b436b3fdf29f5a0046c68cb60b16fa09eb2 (patch)
tree5c5c0ecdab0d19544652bc05b70d8131e1645337 /src/3rdParty
parenta6b6753fda9745f316f3236462b74794b35b85c9 (diff)
downloadyuescript-5aa41b436b3fdf29f5a0046c68cb60b16fa09eb2.tar.gz
yuescript-5aa41b436b3fdf29f5a0046c68cb60b16fa09eb2.tar.bz2
yuescript-5aa41b436b3fdf29f5a0046c68cb60b16fa09eb2.zip
fix issue #81, refactor continue with gotos.
Diffstat (limited to 'src/3rdParty')
-rw-r--r--src/3rdParty/lua/lauxlib.c8
-rw-r--r--src/3rdParty/lua/lobject.c2
-rw-r--r--src/3rdParty/lua/loslib.c4
-rw-r--r--src/3rdParty/lua/ltablib.c2
-rw-r--r--src/3rdParty/lua/luaconf.h5
-rw-r--r--src/3rdParty/lua/lutf8lib.c27
-rw-r--r--src/3rdParty/lua/lvm.c4
-rw-r--r--src/3rdParty/lua/lvm.h5
8 files changed, 32 insertions, 25 deletions
diff --git a/src/3rdParty/lua/lauxlib.c b/src/3rdParty/lua/lauxlib.c
index cba5df9..4ca6c65 100644
--- a/src/3rdParty/lua/lauxlib.c
+++ b/src/3rdParty/lua/lauxlib.c
@@ -526,14 +526,14 @@ static void newbox (lua_State *L) {
526 526
527/* 527/*
528** Compute new size for buffer 'B', enough to accommodate extra 'sz' 528** Compute new size for buffer 'B', enough to accommodate extra 'sz'
529** bytes. (The test for "double is not big enough" also gets the 529** bytes. (The test for "not big enough" also gets the case when the
530** case when the multiplication by 2 overflows.) 530** computation of 'newsize' overflows.)
531*/ 531*/
532static size_t newbuffsize (luaL_Buffer *B, size_t sz) { 532static size_t newbuffsize (luaL_Buffer *B, size_t sz) {
533 size_t newsize = B->size * 2; /* double buffer size */ 533 size_t newsize = (B->size / 2) * 3; /* buffer size * 1.5 */
534 if (l_unlikely(MAX_SIZET - sz < B->n)) /* overflow in (B->n + sz)? */ 534 if (l_unlikely(MAX_SIZET - sz < B->n)) /* overflow in (B->n + sz)? */
535 return luaL_error(B->L, "buffer too large"); 535 return luaL_error(B->L, "buffer too large");
536 if (newsize < B->n + sz) /* double is not big enough? */ 536 if (newsize < B->n + sz) /* not big enough? */
537 newsize = B->n + sz; 537 newsize = B->n + sz;
538 return newsize; 538 return newsize;
539} 539}
diff --git a/src/3rdParty/lua/lobject.c b/src/3rdParty/lua/lobject.c
index a2c0060..03e2798 100644
--- a/src/3rdParty/lua/lobject.c
+++ b/src/3rdParty/lua/lobject.c
@@ -62,7 +62,7 @@ static lua_Integer intarith (lua_State *L, int op, lua_Integer v1,
62 case LUA_OPBOR: return intop(|, v1, v2); 62 case LUA_OPBOR: return intop(|, v1, v2);
63 case LUA_OPBXOR: return intop(^, v1, v2); 63 case LUA_OPBXOR: return intop(^, v1, v2);
64 case LUA_OPSHL: return luaV_shiftl(v1, v2); 64 case LUA_OPSHL: return luaV_shiftl(v1, v2);
65 case LUA_OPSHR: return luaV_shiftl(v1, -v2); 65 case LUA_OPSHR: return luaV_shiftr(v1, v2);
66 case LUA_OPUNM: return intop(-, 0, v1); 66 case LUA_OPUNM: return intop(-, 0, v1);
67 case LUA_OPBNOT: return intop(^, ~l_castS2U(0), v1); 67 case LUA_OPBNOT: return intop(^, ~l_castS2U(0), v1);
68 default: lua_assert(0); return 0; 68 default: lua_assert(0); return 0;
diff --git a/src/3rdParty/lua/loslib.c b/src/3rdParty/lua/loslib.c
index 3e20d62..854dcf6 100644
--- a/src/3rdParty/lua/loslib.c
+++ b/src/3rdParty/lua/loslib.c
@@ -260,9 +260,7 @@ static int getfield (lua_State *L, const char *key, int d, int delta) {
260 res = d; 260 res = d;
261 } 261 }
262 else { 262 else {
263 /* unsigned avoids overflow when lua_Integer has 32 bits */ 263 if (!(res >= 0 ? res - delta <= INT_MAX : INT_MIN + delta <= res))
264 if (!(res >= 0 ? (lua_Unsigned)res <= (lua_Unsigned)INT_MAX + delta
265 : (lua_Integer)INT_MIN + delta <= res))
266 return luaL_error(L, "field '%s' is out-of-bound", key); 264 return luaL_error(L, "field '%s' is out-of-bound", key);
267 res -= delta; 265 res -= delta;
268 } 266 }
diff --git a/src/3rdParty/lua/ltablib.c b/src/3rdParty/lua/ltablib.c
index 868d78f..e6bc4d0 100644
--- a/src/3rdParty/lua/ltablib.c
+++ b/src/3rdParty/lua/ltablib.c
@@ -93,7 +93,7 @@ static int tremove (lua_State *L) {
93 lua_Integer pos = luaL_optinteger(L, 2, size); 93 lua_Integer pos = luaL_optinteger(L, 2, size);
94 if (pos != size) /* validate 'pos' if given */ 94 if (pos != size) /* validate 'pos' if given */
95 /* check whether 'pos' is in [1, size + 1] */ 95 /* check whether 'pos' is in [1, size + 1] */
96 luaL_argcheck(L, (lua_Unsigned)pos - 1u <= (lua_Unsigned)size, 1, 96 luaL_argcheck(L, (lua_Unsigned)pos - 1u <= (lua_Unsigned)size, 2,
97 "position out of bounds"); 97 "position out of bounds");
98 lua_geti(L, 1, pos); /* result = t[pos] */ 98 lua_geti(L, 1, pos); /* result = t[pos] */
99 for ( ; pos < size; pos++) { 99 for ( ; pos < size; pos++) {
diff --git a/src/3rdParty/lua/luaconf.h b/src/3rdParty/lua/luaconf.h
index fcc0018..e4650fb 100644
--- a/src/3rdParty/lua/luaconf.h
+++ b/src/3rdParty/lua/luaconf.h
@@ -747,14 +747,15 @@
747 747
748/* 748/*
749@@ LUA_IDSIZE gives the maximum size for the description of the source 749@@ LUA_IDSIZE gives the maximum size for the description of the source
750@@ of a function in debug information. 750** of a function in debug information.
751** CHANGE it if you want a different size. 751** CHANGE it if you want a different size.
752*/ 752*/
753#define LUA_IDSIZE 60 753#define LUA_IDSIZE 60
754 754
755 755
756/* 756/*
757@@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system. 757@@ LUAL_BUFFERSIZE is the initial buffer size used by the lauxlib
758** buffer system.
758*/ 759*/
759#define LUAL_BUFFERSIZE ((int)(16 * sizeof(void*) * sizeof(lua_Number))) 760#define LUAL_BUFFERSIZE ((int)(16 * sizeof(void*) * sizeof(lua_Number)))
760 761
diff --git a/src/3rdParty/lua/lutf8lib.c b/src/3rdParty/lua/lutf8lib.c
index e7bf098..3a5b9bc 100644
--- a/src/3rdParty/lua/lutf8lib.c
+++ b/src/3rdParty/lua/lutf8lib.c
@@ -25,6 +25,9 @@
25 25
26#define MAXUTF 0x7FFFFFFFu 26#define MAXUTF 0x7FFFFFFFu
27 27
28
29#define MSGInvalid "invalid UTF-8 code"
30
28/* 31/*
29** Integer type for decoded UTF-8 values; MAXUTF needs 31 bits. 32** Integer type for decoded UTF-8 values; MAXUTF needs 31 bits.
30*/ 33*/
@@ -35,7 +38,8 @@ typedef unsigned long utfint;
35#endif 38#endif
36 39
37 40
38#define iscont(p) ((*(p) & 0xC0) == 0x80) 41#define iscont(c) (((c) & 0xC0) == 0x80)
42#define iscontp(p) iscont(*(p))
39 43
40 44
41/* from strlib */ 45/* from strlib */
@@ -65,7 +69,7 @@ static const char *utf8_decode (const char *s, utfint *val, int strict) {
65 int count = 0; /* to count number of continuation bytes */ 69 int count = 0; /* to count number of continuation bytes */
66 for (; c & 0x40; c <<= 1) { /* while it needs continuation bytes... */ 70 for (; c & 0x40; c <<= 1) { /* while it needs continuation bytes... */
67 unsigned int cc = (unsigned char)s[++count]; /* read next byte */ 71 unsigned int cc = (unsigned char)s[++count]; /* read next byte */
68 if ((cc & 0xC0) != 0x80) /* not a continuation byte? */ 72 if (!iscont(cc)) /* not a continuation byte? */
69 return NULL; /* invalid byte sequence */ 73 return NULL; /* invalid byte sequence */
70 res = (res << 6) | (cc & 0x3F); /* add lower 6 bits from cont. byte */ 74 res = (res << 6) | (cc & 0x3F); /* add lower 6 bits from cont. byte */
71 } 75 }
@@ -140,7 +144,7 @@ static int codepoint (lua_State *L) {
140 utfint code; 144 utfint code;
141 s = utf8_decode(s, &code, !lax); 145 s = utf8_decode(s, &code, !lax);
142 if (s == NULL) 146 if (s == NULL)
143 return luaL_error(L, "invalid UTF-8 code"); 147 return luaL_error(L, MSGInvalid);
144 lua_pushinteger(L, code); 148 lua_pushinteger(L, code);
145 n++; 149 n++;
146 } 150 }
@@ -190,16 +194,16 @@ static int byteoffset (lua_State *L) {
190 "position out of bounds"); 194 "position out of bounds");
191 if (n == 0) { 195 if (n == 0) {
192 /* find beginning of current byte sequence */ 196 /* find beginning of current byte sequence */
193 while (posi > 0 && iscont(s + posi)) posi--; 197 while (posi > 0 && iscontp(s + posi)) posi--;
194 } 198 }
195 else { 199 else {
196 if (iscont(s + posi)) 200 if (iscontp(s + posi))
197 return luaL_error(L, "initial position is a continuation byte"); 201 return luaL_error(L, "initial position is a continuation byte");
198 if (n < 0) { 202 if (n < 0) {
199 while (n < 0 && posi > 0) { /* move back */ 203 while (n < 0 && posi > 0) { /* move back */
200 do { /* find beginning of previous character */ 204 do { /* find beginning of previous character */
201 posi--; 205 posi--;
202 } while (posi > 0 && iscont(s + posi)); 206 } while (posi > 0 && iscontp(s + posi));
203 n++; 207 n++;
204 } 208 }
205 } 209 }
@@ -208,7 +212,7 @@ static int byteoffset (lua_State *L) {
208 while (n > 0 && posi < (lua_Integer)len) { 212 while (n > 0 && posi < (lua_Integer)len) {
209 do { /* find beginning of next character */ 213 do { /* find beginning of next character */
210 posi++; 214 posi++;
211 } while (iscont(s + posi)); /* (cannot pass final '\0') */ 215 } while (iscontp(s + posi)); /* (cannot pass final '\0') */
212 n--; 216 n--;
213 } 217 }
214 } 218 }
@@ -226,15 +230,15 @@ static int iter_aux (lua_State *L, int strict) {
226 const char *s = luaL_checklstring(L, 1, &len); 230 const char *s = luaL_checklstring(L, 1, &len);
227 lua_Unsigned n = (lua_Unsigned)lua_tointeger(L, 2); 231 lua_Unsigned n = (lua_Unsigned)lua_tointeger(L, 2);
228 if (n < len) { 232 if (n < len) {
229 while (iscont(s + n)) n++; /* skip continuation bytes */ 233 while (iscontp(s + n)) n++; /* go to next character */
230 } 234 }
231 if (n >= len) /* (also handles original 'n' being negative) */ 235 if (n >= len) /* (also handles original 'n' being negative) */
232 return 0; /* no more codepoints */ 236 return 0; /* no more codepoints */
233 else { 237 else {
234 utfint code; 238 utfint code;
235 const char *next = utf8_decode(s + n, &code, strict); 239 const char *next = utf8_decode(s + n, &code, strict);
236 if (next == NULL) 240 if (next == NULL || iscontp(next))
237 return luaL_error(L, "invalid UTF-8 code"); 241 return luaL_error(L, MSGInvalid);
238 lua_pushinteger(L, n + 1); 242 lua_pushinteger(L, n + 1);
239 lua_pushinteger(L, code); 243 lua_pushinteger(L, code);
240 return 2; 244 return 2;
@@ -253,7 +257,8 @@ static int iter_auxlax (lua_State *L) {
253 257
254static int iter_codes (lua_State *L) { 258static int iter_codes (lua_State *L) {
255 int lax = lua_toboolean(L, 2); 259 int lax = lua_toboolean(L, 2);
256 luaL_checkstring(L, 1); 260 const char *s = luaL_checkstring(L, 1);
261 luaL_argcheck(L, !iscontp(s), 1, MSGInvalid);
257 lua_pushcfunction(L, lax ? iter_auxlax : iter_auxstrict); 262 lua_pushcfunction(L, lax ? iter_auxlax : iter_auxstrict);
258 lua_pushvalue(L, 1); 263 lua_pushvalue(L, 1);
259 lua_pushinteger(L, 0); 264 lua_pushinteger(L, 0);
diff --git a/src/3rdParty/lua/lvm.c b/src/3rdParty/lua/lvm.c
index 614df05..73a19ba 100644
--- a/src/3rdParty/lua/lvm.c
+++ b/src/3rdParty/lua/lvm.c
@@ -765,12 +765,10 @@ lua_Number luaV_modf (lua_State *L, lua_Number m, lua_Number n) {
765/* number of bits in an integer */ 765/* number of bits in an integer */
766#define NBITS cast_int(sizeof(lua_Integer) * CHAR_BIT) 766#define NBITS cast_int(sizeof(lua_Integer) * CHAR_BIT)
767 767
768
768/* 769/*
769** Shift left operation. (Shift right just negates 'y'.) 770** Shift left operation. (Shift right just negates 'y'.)
770*/ 771*/
771#define luaV_shiftr(x,y) luaV_shiftl(x,intop(-, 0, y))
772
773
774lua_Integer luaV_shiftl (lua_Integer x, lua_Integer y) { 772lua_Integer luaV_shiftl (lua_Integer x, lua_Integer y) {
775 if (y < 0) { /* shift right? */ 773 if (y < 0) { /* shift right? */
776 if (y <= -NBITS) return 0; 774 if (y <= -NBITS) return 0;
diff --git a/src/3rdParty/lua/lvm.h b/src/3rdParty/lua/lvm.h
index 1bc16f3..dba1ad2 100644
--- a/src/3rdParty/lua/lvm.h
+++ b/src/3rdParty/lua/lvm.h
@@ -110,6 +110,11 @@ typedef enum {
110 luaC_barrierback(L, gcvalue(t), v); } 110 luaC_barrierback(L, gcvalue(t), v); }
111 111
112 112
113/*
114** Shift right is the same as shift left with a negative 'y'
115*/
116#define luaV_shiftr(x,y) luaV_shiftl(x,intop(-, 0, y))
117
113 118
114 119
115LUAI_FUNC int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2); 120LUAI_FUNC int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2);