diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-06-20 14:46:06 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-06-20 14:46:06 -0300 |
commit | a08d82eb132bfd9db5b91e0d5ebcb81d7b26dcd0 (patch) | |
tree | 45618815246686a535a28fb4e6f9736a60be00d4 | |
parent | 55ac40f859ad8e28fe71a8801d49f4a4140e8aa3 (diff) | |
download | lua-a08d82eb132bfd9db5b91e0d5ebcb81d7b26dcd0.tar.gz lua-a08d82eb132bfd9db5b91e0d5ebcb81d7b26dcd0.tar.bz2 lua-a08d82eb132bfd9db5b91e0d5ebcb81d7b26dcd0.zip |
llimits.h being used by all Lua code
The definitions in llimits.h are useful not only for the core. That
header only defines types and '#define's, so libs and core still do
not share any real code/data.
-rw-r--r-- | lauxlib.c | 1 | ||||
-rw-r--r-- | lauxlib.h | 15 | ||||
-rw-r--r-- | lbaselib.c | 1 | ||||
-rw-r--r-- | lcorolib.c | 1 | ||||
-rw-r--r-- | ldblib.c | 1 | ||||
-rw-r--r-- | linit.c | 1 | ||||
-rw-r--r-- | liolib.c | 3 | ||||
-rw-r--r-- | lmathlib.c | 21 | ||||
-rw-r--r-- | loadlib.c | 1 | ||||
-rw-r--r-- | loslib.c | 1 | ||||
-rw-r--r-- | lstrlib.c | 49 | ||||
-rw-r--r-- | ltablib.c | 1 | ||||
-rw-r--r-- | lua.c | 1 | ||||
-rw-r--r-- | lutf8lib.c | 24 |
14 files changed, 48 insertions, 73 deletions
@@ -25,6 +25,7 @@ | |||
25 | #include "lua.h" | 25 | #include "lua.h" |
26 | 26 | ||
27 | #include "lauxlib.h" | 27 | #include "lauxlib.h" |
28 | #include "llimits.h" | ||
28 | 29 | ||
29 | 30 | ||
30 | #if !defined(MAX_SIZET) | 31 | #if !defined(MAX_SIZET) |
@@ -168,21 +168,6 @@ LUALIB_API void (luaL_requiref) (lua_State *L, const char *modname, | |||
168 | #define luaL_pushfail(L) lua_pushnil(L) | 168 | #define luaL_pushfail(L) lua_pushnil(L) |
169 | 169 | ||
170 | 170 | ||
171 | /* | ||
172 | ** Internal assertions for in-house debugging | ||
173 | */ | ||
174 | #if !defined(lua_assert) | ||
175 | |||
176 | #if defined LUAI_ASSERT | ||
177 | #include <assert.h> | ||
178 | #define lua_assert(c) assert(c) | ||
179 | #else | ||
180 | #define lua_assert(c) ((void)0) | ||
181 | #endif | ||
182 | |||
183 | #endif | ||
184 | |||
185 | |||
186 | 171 | ||
187 | /* | 172 | /* |
188 | ** {====================================================== | 173 | ** {====================================================== |
@@ -19,6 +19,7 @@ | |||
19 | 19 | ||
20 | #include "lauxlib.h" | 20 | #include "lauxlib.h" |
21 | #include "lualib.h" | 21 | #include "lualib.h" |
22 | #include "llimits.h" | ||
22 | 23 | ||
23 | 24 | ||
24 | static int luaB_print (lua_State *L) { | 25 | static int luaB_print (lua_State *L) { |
@@ -16,6 +16,7 @@ | |||
16 | 16 | ||
17 | #include "lauxlib.h" | 17 | #include "lauxlib.h" |
18 | #include "lualib.h" | 18 | #include "lualib.h" |
19 | #include "llimits.h" | ||
19 | 20 | ||
20 | 21 | ||
21 | static lua_State *getco (lua_State *L) { | 22 | static lua_State *getco (lua_State *L) { |
@@ -18,6 +18,7 @@ | |||
18 | 18 | ||
19 | #include "lauxlib.h" | 19 | #include "lauxlib.h" |
20 | #include "lualib.h" | 20 | #include "lualib.h" |
21 | #include "llimits.h" | ||
21 | 22 | ||
22 | 23 | ||
23 | /* | 24 | /* |
@@ -18,6 +18,7 @@ | |||
18 | 18 | ||
19 | #include "lualib.h" | 19 | #include "lualib.h" |
20 | #include "lauxlib.h" | 20 | #include "lauxlib.h" |
21 | #include "llimits.h" | ||
21 | 22 | ||
22 | 23 | ||
23 | /* | 24 | /* |
@@ -21,8 +21,7 @@ | |||
21 | 21 | ||
22 | #include "lauxlib.h" | 22 | #include "lauxlib.h" |
23 | #include "lualib.h" | 23 | #include "lualib.h" |
24 | 24 | #include "llimits.h" | |
25 | |||
26 | 25 | ||
27 | 26 | ||
28 | /* | 27 | /* |
@@ -20,6 +20,7 @@ | |||
20 | 20 | ||
21 | #include "lauxlib.h" | 21 | #include "lauxlib.h" |
22 | #include "lualib.h" | 22 | #include "lualib.h" |
23 | #include "llimits.h" | ||
23 | 24 | ||
24 | 25 | ||
25 | #undef PI | 26 | #undef PI |
@@ -366,25 +367,17 @@ static lua_Number I2d (Rand64 x) { | |||
366 | 367 | ||
367 | #else /* no 'Rand64' }{ */ | 368 | #else /* no 'Rand64' }{ */ |
368 | 369 | ||
369 | /* get an integer with at least 32 bits */ | ||
370 | #if LUAI_IS32INT | ||
371 | typedef unsigned int lu_int32; | ||
372 | #else | ||
373 | typedef unsigned long lu_int32; | ||
374 | #endif | ||
375 | |||
376 | |||
377 | /* | 370 | /* |
378 | ** Use two 32-bit integers to represent a 64-bit quantity. | 371 | ** Use two 32-bit integers to represent a 64-bit quantity. |
379 | */ | 372 | */ |
380 | typedef struct Rand64 { | 373 | typedef struct Rand64 { |
381 | lu_int32 h; /* higher half */ | 374 | l_uint32 h; /* higher half */ |
382 | lu_int32 l; /* lower half */ | 375 | l_uint32 l; /* lower half */ |
383 | } Rand64; | 376 | } Rand64; |
384 | 377 | ||
385 | 378 | ||
386 | /* | 379 | /* |
387 | ** If 'lu_int32' has more than 32 bits, the extra bits do not interfere | 380 | ** If 'l_uint32' has more than 32 bits, the extra bits do not interfere |
388 | ** with the 32 initial bits, except in a right shift and comparisons. | 381 | ** with the 32 initial bits, except in a right shift and comparisons. |
389 | ** Moreover, the final result has to discard the extra bits. | 382 | ** Moreover, the final result has to discard the extra bits. |
390 | */ | 383 | */ |
@@ -398,7 +391,7 @@ typedef struct Rand64 { | |||
398 | */ | 391 | */ |
399 | 392 | ||
400 | /* build a new Rand64 value */ | 393 | /* build a new Rand64 value */ |
401 | static Rand64 packI (lu_int32 h, lu_int32 l) { | 394 | static Rand64 packI (l_uint32 h, l_uint32 l) { |
402 | Rand64 result; | 395 | Rand64 result; |
403 | result.h = h; | 396 | result.h = h; |
404 | result.l = l; | 397 | result.l = l; |
@@ -471,7 +464,7 @@ static Rand64 nextrand (Rand64 *state) { | |||
471 | */ | 464 | */ |
472 | 465 | ||
473 | /* an unsigned 1 with proper type */ | 466 | /* an unsigned 1 with proper type */ |
474 | #define UONE ((lu_int32)1) | 467 | #define UONE ((l_uint32)1) |
475 | 468 | ||
476 | 469 | ||
477 | #if FIGS <= 32 | 470 | #if FIGS <= 32 |
@@ -522,7 +515,7 @@ static lua_Unsigned I2UInt (Rand64 x) { | |||
522 | 515 | ||
523 | /* convert a 'lua_Unsigned' to a 'Rand64' */ | 516 | /* convert a 'lua_Unsigned' to a 'Rand64' */ |
524 | static Rand64 Int2I (lua_Unsigned n) { | 517 | static Rand64 Int2I (lua_Unsigned n) { |
525 | return packI((lu_int32)((n >> 31) >> 1), (lu_int32)n); | 518 | return packI((l_uint32)((n >> 31) >> 1), (l_uint32)n); |
526 | } | 519 | } |
527 | 520 | ||
528 | #endif /* } */ | 521 | #endif /* } */ |
@@ -22,6 +22,7 @@ | |||
22 | 22 | ||
23 | #include "lauxlib.h" | 23 | #include "lauxlib.h" |
24 | #include "lualib.h" | 24 | #include "lualib.h" |
25 | #include "llimits.h" | ||
25 | 26 | ||
26 | 27 | ||
27 | /* | 28 | /* |
@@ -20,6 +20,7 @@ | |||
20 | 20 | ||
21 | #include "lauxlib.h" | 21 | #include "lauxlib.h" |
22 | #include "lualib.h" | 22 | #include "lualib.h" |
23 | #include "llimits.h" | ||
23 | 24 | ||
24 | 25 | ||
25 | /* | 26 | /* |
@@ -24,6 +24,7 @@ | |||
24 | 24 | ||
25 | #include "lauxlib.h" | 25 | #include "lauxlib.h" |
26 | #include "lualib.h" | 26 | #include "lualib.h" |
27 | #include "llimits.h" | ||
27 | 28 | ||
28 | 29 | ||
29 | /* | 30 | /* |
@@ -36,10 +37,6 @@ | |||
36 | #endif | 37 | #endif |
37 | 38 | ||
38 | 39 | ||
39 | /* macro to 'unsign' a character */ | ||
40 | #define uchar(c) ((unsigned char)(c)) | ||
41 | |||
42 | |||
43 | /* | 40 | /* |
44 | ** Some sizes are better limited to fit in 'int', but must also fit in | 41 | ** Some sizes are better limited to fit in 'int', but must also fit in |
45 | ** 'size_t'. (We assume that 'lua_Integer' cannot be smaller than 'int'.) | 42 | ** 'size_t'. (We assume that 'lua_Integer' cannot be smaller than 'int'.) |
@@ -128,7 +125,7 @@ static int str_lower (lua_State *L) { | |||
128 | const char *s = luaL_checklstring(L, 1, &l); | 125 | const char *s = luaL_checklstring(L, 1, &l); |
129 | char *p = luaL_buffinitsize(L, &b, l); | 126 | char *p = luaL_buffinitsize(L, &b, l); |
130 | for (i=0; i<l; i++) | 127 | for (i=0; i<l; i++) |
131 | p[i] = tolower(uchar(s[i])); | 128 | p[i] = tolower(cast_uchar(s[i])); |
132 | luaL_pushresultsize(&b, l); | 129 | luaL_pushresultsize(&b, l); |
133 | return 1; | 130 | return 1; |
134 | } | 131 | } |
@@ -141,7 +138,7 @@ static int str_upper (lua_State *L) { | |||
141 | const char *s = luaL_checklstring(L, 1, &l); | 138 | const char *s = luaL_checklstring(L, 1, &l); |
142 | char *p = luaL_buffinitsize(L, &b, l); | 139 | char *p = luaL_buffinitsize(L, &b, l); |
143 | for (i=0; i<l; i++) | 140 | for (i=0; i<l; i++) |
144 | p[i] = toupper(uchar(s[i])); | 141 | p[i] = toupper(cast_uchar(s[i])); |
145 | luaL_pushresultsize(&b, l); | 142 | luaL_pushresultsize(&b, l); |
146 | return 1; | 143 | return 1; |
147 | } | 144 | } |
@@ -187,7 +184,7 @@ static int str_byte (lua_State *L) { | |||
187 | n = (int)(pose - posi) + 1; | 184 | n = (int)(pose - posi) + 1; |
188 | luaL_checkstack(L, n, "string slice too long"); | 185 | luaL_checkstack(L, n, "string slice too long"); |
189 | for (i=0; i<n; i++) | 186 | for (i=0; i<n; i++) |
190 | lua_pushinteger(L, uchar(s[posi+i-1])); | 187 | lua_pushinteger(L, cast_uchar(s[posi+i-1])); |
191 | return n; | 188 | return n; |
192 | } | 189 | } |
193 | 190 | ||
@@ -200,7 +197,7 @@ static int str_char (lua_State *L) { | |||
200 | for (i=1; i<=n; i++) { | 197 | for (i=1; i<=n; i++) { |
201 | lua_Unsigned c = (lua_Unsigned)luaL_checkinteger(L, i); | 198 | lua_Unsigned c = (lua_Unsigned)luaL_checkinteger(L, i); |
202 | luaL_argcheck(L, c <= (lua_Unsigned)UCHAR_MAX, i, "value out of range"); | 199 | luaL_argcheck(L, c <= (lua_Unsigned)UCHAR_MAX, i, "value out of range"); |
203 | p[i - 1] = uchar(c); | 200 | p[i - 1] = cast_uchar(c); |
204 | } | 201 | } |
205 | luaL_pushresultsize(&b, n); | 202 | luaL_pushresultsize(&b, n); |
206 | return 1; | 203 | return 1; |
@@ -459,15 +456,15 @@ static int matchbracketclass (int c, const char *p, const char *ec) { | |||
459 | while (++p < ec) { | 456 | while (++p < ec) { |
460 | if (*p == L_ESC) { | 457 | if (*p == L_ESC) { |
461 | p++; | 458 | p++; |
462 | if (match_class(c, uchar(*p))) | 459 | if (match_class(c, cast_uchar(*p))) |
463 | return sig; | 460 | return sig; |
464 | } | 461 | } |
465 | else if ((*(p+1) == '-') && (p+2 < ec)) { | 462 | else if ((*(p+1) == '-') && (p+2 < ec)) { |
466 | p+=2; | 463 | p+=2; |
467 | if (uchar(*(p-2)) <= c && c <= uchar(*p)) | 464 | if (cast_uchar(*(p-2)) <= c && c <= cast_uchar(*p)) |
468 | return sig; | 465 | return sig; |
469 | } | 466 | } |
470 | else if (uchar(*p) == c) return sig; | 467 | else if (cast_uchar(*p) == c) return sig; |
471 | } | 468 | } |
472 | return !sig; | 469 | return !sig; |
473 | } | 470 | } |
@@ -478,12 +475,12 @@ static int singlematch (MatchState *ms, const char *s, const char *p, | |||
478 | if (s >= ms->src_end) | 475 | if (s >= ms->src_end) |
479 | return 0; | 476 | return 0; |
480 | else { | 477 | else { |
481 | int c = uchar(*s); | 478 | int c = cast_uchar(*s); |
482 | switch (*p) { | 479 | switch (*p) { |
483 | case '.': return 1; /* matches any char */ | 480 | case '.': return 1; /* matches any char */ |
484 | case L_ESC: return match_class(c, uchar(*(p+1))); | 481 | case L_ESC: return match_class(c, cast_uchar(*(p+1))); |
485 | case '[': return matchbracketclass(c, p, ep-1); | 482 | case '[': return matchbracketclass(c, p, ep-1); |
486 | default: return (uchar(*p) == c); | 483 | default: return (cast_uchar(*p) == c); |
487 | } | 484 | } |
488 | } | 485 | } |
489 | } | 486 | } |
@@ -612,8 +609,8 @@ static const char *match (MatchState *ms, const char *s, const char *p) { | |||
612 | luaL_error(ms->L, "missing '[' after '%%f' in pattern"); | 609 | luaL_error(ms->L, "missing '[' after '%%f' in pattern"); |
613 | ep = classend(ms, p); /* points to what is next */ | 610 | ep = classend(ms, p); /* points to what is next */ |
614 | previous = (s == ms->src_init) ? '\0' : *(s - 1); | 611 | previous = (s == ms->src_init) ? '\0' : *(s - 1); |
615 | if (!matchbracketclass(uchar(previous), p, ep - 1) && | 612 | if (!matchbracketclass(cast_uchar(previous), p, ep - 1) && |
616 | matchbracketclass(uchar(*s), p, ep - 1)) { | 613 | matchbracketclass(cast_uchar(*s), p, ep - 1)) { |
617 | p = ep; goto init; /* return match(ms, s, ep); */ | 614 | p = ep; goto init; /* return match(ms, s, ep); */ |
618 | } | 615 | } |
619 | s = NULL; /* match failed */ | 616 | s = NULL; /* match failed */ |
@@ -622,7 +619,7 @@ static const char *match (MatchState *ms, const char *s, const char *p) { | |||
622 | case '0': case '1': case '2': case '3': | 619 | case '0': case '1': case '2': case '3': |
623 | case '4': case '5': case '6': case '7': | 620 | case '4': case '5': case '6': case '7': |
624 | case '8': case '9': { /* capture results (%0-%9)? */ | 621 | case '8': case '9': { /* capture results (%0-%9)? */ |
625 | s = match_capture(ms, s, uchar(*(p + 1))); | 622 | s = match_capture(ms, s, cast_uchar(*(p + 1))); |
626 | if (s != NULL) { | 623 | if (s != NULL) { |
627 | p += 2; goto init; /* return match(ms, s, p + 2) */ | 624 | p += 2; goto init; /* return match(ms, s, p + 2) */ |
628 | } | 625 | } |
@@ -887,7 +884,7 @@ static void add_s (MatchState *ms, luaL_Buffer *b, const char *s, | |||
887 | luaL_addchar(b, *p); | 884 | luaL_addchar(b, *p); |
888 | else if (*p == '0') /* '%0' */ | 885 | else if (*p == '0') /* '%0' */ |
889 | luaL_addlstring(b, s, e - s); | 886 | luaL_addlstring(b, s, e - s); |
890 | else if (isdigit(uchar(*p))) { /* '%n' */ | 887 | else if (isdigit(cast_uchar(*p))) { /* '%n' */ |
891 | const char *cap; | 888 | const char *cap; |
892 | ptrdiff_t resl = get_onecapture(ms, *p - '1', s, e, &cap); | 889 | ptrdiff_t resl = get_onecapture(ms, *p - '1', s, e, &cap); |
893 | if (resl == CAP_POSITION) | 890 | if (resl == CAP_POSITION) |
@@ -1065,7 +1062,7 @@ static int lua_number2strx (lua_State *L, char *buff, int sz, | |||
1065 | if (fmt[SIZELENMOD] == 'A') { | 1062 | if (fmt[SIZELENMOD] == 'A') { |
1066 | int i; | 1063 | int i; |
1067 | for (i = 0; i < n; i++) | 1064 | for (i = 0; i < n; i++) |
1068 | buff[i] = toupper(uchar(buff[i])); | 1065 | buff[i] = toupper(cast_uchar(buff[i])); |
1069 | } | 1066 | } |
1070 | else if (l_unlikely(fmt[SIZELENMOD] != 'a')) | 1067 | else if (l_unlikely(fmt[SIZELENMOD] != 'a')) |
1071 | return luaL_error(L, "modifiers for format '%%a'/'%%A' not implemented"); | 1068 | return luaL_error(L, "modifiers for format '%%a'/'%%A' not implemented"); |
@@ -1132,12 +1129,12 @@ static void addquoted (luaL_Buffer *b, const char *s, size_t len) { | |||
1132 | luaL_addchar(b, '\\'); | 1129 | luaL_addchar(b, '\\'); |
1133 | luaL_addchar(b, *s); | 1130 | luaL_addchar(b, *s); |
1134 | } | 1131 | } |
1135 | else if (iscntrl(uchar(*s))) { | 1132 | else if (iscntrl(cast_uchar(*s))) { |
1136 | char buff[10]; | 1133 | char buff[10]; |
1137 | if (!isdigit(uchar(*(s+1)))) | 1134 | if (!isdigit(cast_uchar(*(s+1)))) |
1138 | l_sprintf(buff, sizeof(buff), "\\%d", (int)uchar(*s)); | 1135 | l_sprintf(buff, sizeof(buff), "\\%d", (int)cast_uchar(*s)); |
1139 | else | 1136 | else |
1140 | l_sprintf(buff, sizeof(buff), "\\%03d", (int)uchar(*s)); | 1137 | l_sprintf(buff, sizeof(buff), "\\%03d", (int)cast_uchar(*s)); |
1141 | luaL_addstring(b, buff); | 1138 | luaL_addstring(b, buff); |
1142 | } | 1139 | } |
1143 | else | 1140 | else |
@@ -1214,9 +1211,9 @@ static void addliteral (lua_State *L, luaL_Buffer *b, int arg) { | |||
1214 | 1211 | ||
1215 | 1212 | ||
1216 | static const char *get2digits (const char *s) { | 1213 | static const char *get2digits (const char *s) { |
1217 | if (isdigit(uchar(*s))) { | 1214 | if (isdigit(cast_uchar(*s))) { |
1218 | s++; | 1215 | s++; |
1219 | if (isdigit(uchar(*s))) s++; /* (2 digits at most) */ | 1216 | if (isdigit(cast_uchar(*s))) s++; /* (2 digits at most) */ |
1220 | } | 1217 | } |
1221 | return s; | 1218 | return s; |
1222 | } | 1219 | } |
@@ -1239,7 +1236,7 @@ static void checkformat (lua_State *L, const char *form, const char *flags, | |||
1239 | spec = get2digits(spec); /* skip precision */ | 1236 | spec = get2digits(spec); /* skip precision */ |
1240 | } | 1237 | } |
1241 | } | 1238 | } |
1242 | if (!isalpha(uchar(*spec))) /* did not go to the end? */ | 1239 | if (!isalpha(cast_uchar(*spec))) /* did not go to the end? */ |
1243 | luaL_error(L, "invalid conversion specification: '%s'", form); | 1240 | luaL_error(L, "invalid conversion specification: '%s'", form); |
1244 | } | 1241 | } |
1245 | 1242 | ||
@@ -18,6 +18,7 @@ | |||
18 | 18 | ||
19 | #include "lauxlib.h" | 19 | #include "lauxlib.h" |
20 | #include "lualib.h" | 20 | #include "lualib.h" |
21 | #include "llimits.h" | ||
21 | 22 | ||
22 | 23 | ||
23 | /* | 24 | /* |
@@ -19,6 +19,7 @@ | |||
19 | 19 | ||
20 | #include "lauxlib.h" | 20 | #include "lauxlib.h" |
21 | #include "lualib.h" | 21 | #include "lualib.h" |
22 | #include "llimits.h" | ||
22 | 23 | ||
23 | 24 | ||
24 | #if !defined(LUA_PROGNAME) | 25 | #if !defined(LUA_PROGNAME) |
@@ -19,6 +19,7 @@ | |||
19 | 19 | ||
20 | #include "lauxlib.h" | 20 | #include "lauxlib.h" |
21 | #include "lualib.h" | 21 | #include "lualib.h" |
22 | #include "llimits.h" | ||
22 | 23 | ||
23 | 24 | ||
24 | #define MAXUNICODE 0x10FFFFu | 25 | #define MAXUNICODE 0x10FFFFu |
@@ -28,15 +29,6 @@ | |||
28 | 29 | ||
29 | #define MSGInvalid "invalid UTF-8 code" | 30 | #define MSGInvalid "invalid UTF-8 code" |
30 | 31 | ||
31 | /* | ||
32 | ** Integer type for decoded UTF-8 values; MAXUTF needs 31 bits. | ||
33 | */ | ||
34 | #if (UINT_MAX >> 30) >= 1 | ||
35 | typedef unsigned int utfint; | ||
36 | #else | ||
37 | typedef unsigned long utfint; | ||
38 | #endif | ||
39 | |||
40 | 32 | ||
41 | #define iscont(c) (((c) & 0xC0) == 0x80) | 33 | #define iscont(c) (((c) & 0xC0) == 0x80) |
42 | #define iscontp(p) iscont(*(p)) | 34 | #define iscontp(p) iscont(*(p)) |
@@ -58,11 +50,11 @@ static lua_Integer u_posrelat (lua_Integer pos, size_t len) { | |||
58 | ** entry forces an error for non-ascii bytes with no continuation | 50 | ** entry forces an error for non-ascii bytes with no continuation |
59 | ** bytes (count == 0). | 51 | ** bytes (count == 0). |
60 | */ | 52 | */ |
61 | static const char *utf8_decode (const char *s, utfint *val, int strict) { | 53 | static const char *utf8_decode (const char *s, l_uint32 *val, int strict) { |
62 | static const utfint limits[] = | 54 | static const l_uint32 limits[] = |
63 | {~(utfint)0, 0x80, 0x800, 0x10000u, 0x200000u, 0x4000000u}; | 55 | {~(l_uint32)0, 0x80, 0x800, 0x10000u, 0x200000u, 0x4000000u}; |
64 | unsigned int c = (unsigned char)s[0]; | 56 | unsigned int c = (unsigned char)s[0]; |
65 | utfint res = 0; /* final result */ | 57 | l_uint32 res = 0; /* final result */ |
66 | if (c < 0x80) /* ascii? */ | 58 | if (c < 0x80) /* ascii? */ |
67 | res = c; | 59 | res = c; |
68 | else { | 60 | else { |
@@ -73,7 +65,7 @@ static const char *utf8_decode (const char *s, utfint *val, int strict) { | |||
73 | return NULL; /* invalid byte sequence */ | 65 | return NULL; /* invalid byte sequence */ |
74 | res = (res << 6) | (cc & 0x3F); /* add lower 6 bits from cont. byte */ | 66 | res = (res << 6) | (cc & 0x3F); /* add lower 6 bits from cont. byte */ |
75 | } | 67 | } |
76 | res |= ((utfint)(c & 0x7F) << (count * 5)); /* add first byte */ | 68 | res |= ((l_uint32)(c & 0x7F) << (count * 5)); /* add first byte */ |
77 | if (count > 5 || res > MAXUTF || res < limits[count]) | 69 | if (count > 5 || res > MAXUTF || res < limits[count]) |
78 | return NULL; /* invalid byte sequence */ | 70 | return NULL; /* invalid byte sequence */ |
79 | s += count; /* skip continuation bytes read */ | 71 | s += count; /* skip continuation bytes read */ |
@@ -141,7 +133,7 @@ static int codepoint (lua_State *L) { | |||
141 | n = 0; /* count the number of returns */ | 133 | n = 0; /* count the number of returns */ |
142 | se = s + pose; /* string end */ | 134 | se = s + pose; /* string end */ |
143 | for (s += posi - 1; s < se;) { | 135 | for (s += posi - 1; s < se;) { |
144 | utfint code; | 136 | l_uint32 code; |
145 | s = utf8_decode(s, &code, !lax); | 137 | s = utf8_decode(s, &code, !lax); |
146 | if (s == NULL) | 138 | if (s == NULL) |
147 | return luaL_error(L, MSGInvalid); | 139 | return luaL_error(L, MSGInvalid); |
@@ -243,7 +235,7 @@ static int iter_aux (lua_State *L, int strict) { | |||
243 | if (n >= len) /* (also handles original 'n' being negative) */ | 235 | if (n >= len) /* (also handles original 'n' being negative) */ |
244 | return 0; /* no more codepoints */ | 236 | return 0; /* no more codepoints */ |
245 | else { | 237 | else { |
246 | utfint code; | 238 | l_uint32 code; |
247 | const char *next = utf8_decode(s + n, &code, strict); | 239 | const char *next = utf8_decode(s + n, &code, strict); |
248 | if (next == NULL || iscontp(next)) | 240 | if (next == NULL || iscontp(next)) |
249 | return luaL_error(L, MSGInvalid); | 241 | return luaL_error(L, MSGInvalid); |