diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-07-27 13:32:59 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-07-27 13:32:59 -0300 |
commit | 0acd55898d0aaae8dbc14c8a1bc1e3bdffc8701b (patch) | |
tree | 0ac634fed90877130b1f102bf4075af999de2158 | |
parent | 15231d4fb2f6984b25e0353ff46eda1a180b686d (diff) | |
download | lua-0acd55898d0aaae8dbc14c8a1bc1e3bdffc8701b.tar.gz lua-0acd55898d0aaae8dbc14c8a1bc1e3bdffc8701b.tar.bz2 lua-0acd55898d0aaae8dbc14c8a1bc1e3bdffc8701b.zip |
Added gcc option '-Wconversion'
No warnings for standard numerical types. Still pending alternative
numerical types.
-rw-r--r-- | lapi.c | 26 | ||||
-rw-r--r-- | lauxlib.c | 8 | ||||
-rw-r--r-- | lbaselib.c | 15 | ||||
-rw-r--r-- | lcode.c | 34 | ||||
-rw-r--r-- | lcode.h | 2 | ||||
-rw-r--r-- | ldebug.c | 4 | ||||
-rw-r--r-- | ldo.c | 10 | ||||
-rw-r--r-- | ldump.c | 18 | ||||
-rw-r--r-- | lfunc.c | 14 | ||||
-rw-r--r-- | lfunc.h | 8 | ||||
-rw-r--r-- | lgc.c | 14 | ||||
-rw-r--r-- | lgc.h | 4 | ||||
-rw-r--r-- | liolib.c | 8 | ||||
-rw-r--r-- | llex.c | 2 | ||||
-rw-r--r-- | llimits.h | 11 | ||||
-rw-r--r-- | lmathlib.c | 12 | ||||
-rw-r--r-- | lmem.c | 6 | ||||
-rw-r--r-- | lmem.h | 2 | ||||
-rw-r--r-- | loadlib.c | 8 | ||||
-rw-r--r-- | lobject.c | 68 | ||||
-rw-r--r-- | lobject.h | 20 | ||||
-rw-r--r-- | lopcodes.h | 7 | ||||
-rw-r--r-- | loslib.c | 2 | ||||
-rw-r--r-- | lparser.c | 34 | ||||
-rw-r--r-- | lparser.h | 2 | ||||
-rw-r--r-- | lstate.c | 5 | ||||
-rw-r--r-- | lstate.h | 2 | ||||
-rw-r--r-- | lstring.c | 8 | ||||
-rw-r--r-- | lstring.h | 3 | ||||
-rw-r--r-- | lstrlib.c | 132 | ||||
-rw-r--r-- | ltable.c | 67 | ||||
-rw-r--r-- | ltable.h | 10 | ||||
-rw-r--r-- | ltablib.c | 4 | ||||
-rw-r--r-- | ltests.c | 62 | ||||
-rw-r--r-- | ltm.c | 4 | ||||
-rw-r--r-- | ltm.h | 6 | ||||
-rw-r--r-- | lua.c | 2 | ||||
-rw-r--r-- | lundump.c | 62 | ||||
-rw-r--r-- | lutf8lib.c | 4 | ||||
-rw-r--r-- | lvm.c | 37 | ||||
-rw-r--r-- | lvm.h | 4 | ||||
-rw-r--r-- | lzio.h | 2 | ||||
-rw-r--r-- | makefile | 2 | ||||
-rw-r--r-- | manual/manual.of | 2 |
44 files changed, 398 insertions, 359 deletions
@@ -58,7 +58,7 @@ static void advancegc (lua_State *L, size_t delta) { | |||
58 | delta >>= 5; /* one object for each 32 bytes (empirical) */ | 58 | delta >>= 5; /* one object for each 32 bytes (empirical) */ |
59 | if (delta > 0) { | 59 | if (delta > 0) { |
60 | global_State *g = G(L); | 60 | global_State *g = G(L); |
61 | luaE_setdebt(g, g->GCdebt - delta); | 61 | luaE_setdebt(g, g->GCdebt - cast(l_obj, delta)); |
62 | } | 62 | } |
63 | } | 63 | } |
64 | 64 | ||
@@ -437,9 +437,9 @@ LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) { | |||
437 | LUA_API lua_Unsigned lua_rawlen (lua_State *L, int idx) { | 437 | LUA_API lua_Unsigned lua_rawlen (lua_State *L, int idx) { |
438 | const TValue *o = index2value(L, idx); | 438 | const TValue *o = index2value(L, idx); |
439 | switch (ttypetag(o)) { | 439 | switch (ttypetag(o)) { |
440 | case LUA_VSHRSTR: return tsvalue(o)->shrlen; | 440 | case LUA_VSHRSTR: return cast(lua_Unsigned, tsvalue(o)->shrlen); |
441 | case LUA_VLNGSTR: return tsvalue(o)->u.lnglen; | 441 | case LUA_VLNGSTR: return cast(lua_Unsigned, tsvalue(o)->u.lnglen); |
442 | case LUA_VUSERDATA: return uvalue(o)->len; | 442 | case LUA_VUSERDATA: return cast(lua_Unsigned, uvalue(o)->len); |
443 | case LUA_VTABLE: return luaH_getn(hvalue(o)); | 443 | case LUA_VTABLE: return luaH_getn(hvalue(o)); |
444 | default: return 0; | 444 | default: return 0; |
445 | } | 445 | } |
@@ -667,7 +667,7 @@ LUA_API int lua_pushthread (lua_State *L) { | |||
667 | 667 | ||
668 | 668 | ||
669 | static int auxgetstr (lua_State *L, const TValue *t, const char *k) { | 669 | static int auxgetstr (lua_State *L, const TValue *t, const char *k) { |
670 | int tag; | 670 | lu_byte tag; |
671 | TString *str = luaS_new(L, k); | 671 | TString *str = luaS_new(L, k); |
672 | luaV_fastget(t, str, s2v(L->top.p), luaH_getstr, tag); | 672 | luaV_fastget(t, str, s2v(L->top.p), luaH_getstr, tag); |
673 | if (!tagisempty(tag)) { | 673 | if (!tagisempty(tag)) { |
@@ -685,7 +685,7 @@ static int auxgetstr (lua_State *L, const TValue *t, const char *k) { | |||
685 | 685 | ||
686 | static void getGlobalTable (lua_State *L, TValue *gt) { | 686 | static void getGlobalTable (lua_State *L, TValue *gt) { |
687 | Table *registry = hvalue(&G(L)->l_registry); | 687 | Table *registry = hvalue(&G(L)->l_registry); |
688 | int tag = luaH_getint(registry, LUA_RIDX_GLOBALS, gt); | 688 | lu_byte tag = luaH_getint(registry, LUA_RIDX_GLOBALS, gt); |
689 | (void)tag; /* avoid not-used warnings when checks are off */ | 689 | (void)tag; /* avoid not-used warnings when checks are off */ |
690 | api_check(L, novariant(tag) == LUA_TTABLE, "global table must exist"); | 690 | api_check(L, novariant(tag) == LUA_TTABLE, "global table must exist"); |
691 | } | 691 | } |
@@ -700,7 +700,7 @@ LUA_API int lua_getglobal (lua_State *L, const char *name) { | |||
700 | 700 | ||
701 | 701 | ||
702 | LUA_API int lua_gettable (lua_State *L, int idx) { | 702 | LUA_API int lua_gettable (lua_State *L, int idx) { |
703 | int tag; | 703 | lu_byte tag; |
704 | TValue *t; | 704 | TValue *t; |
705 | lua_lock(L); | 705 | lua_lock(L); |
706 | api_checkpop(L, 1); | 706 | api_checkpop(L, 1); |
@@ -721,7 +721,7 @@ LUA_API int lua_getfield (lua_State *L, int idx, const char *k) { | |||
721 | 721 | ||
722 | LUA_API int lua_geti (lua_State *L, int idx, lua_Integer n) { | 722 | LUA_API int lua_geti (lua_State *L, int idx, lua_Integer n) { |
723 | TValue *t; | 723 | TValue *t; |
724 | int tag; | 724 | lu_byte tag; |
725 | lua_lock(L); | 725 | lua_lock(L); |
726 | t = index2value(L, idx); | 726 | t = index2value(L, idx); |
727 | luaV_fastgeti(t, n, s2v(L->top.p), tag); | 727 | luaV_fastgeti(t, n, s2v(L->top.p), tag); |
@@ -736,7 +736,7 @@ LUA_API int lua_geti (lua_State *L, int idx, lua_Integer n) { | |||
736 | } | 736 | } |
737 | 737 | ||
738 | 738 | ||
739 | static int finishrawget (lua_State *L, int tag) { | 739 | static int finishrawget (lua_State *L, lu_byte tag) { |
740 | if (tagisempty(tag)) /* avoid copying empty items to the stack */ | 740 | if (tagisempty(tag)) /* avoid copying empty items to the stack */ |
741 | setnilvalue(s2v(L->top.p)); | 741 | setnilvalue(s2v(L->top.p)); |
742 | api_incr_top(L); | 742 | api_incr_top(L); |
@@ -754,7 +754,7 @@ l_sinline Table *gettable (lua_State *L, int idx) { | |||
754 | 754 | ||
755 | LUA_API int lua_rawget (lua_State *L, int idx) { | 755 | LUA_API int lua_rawget (lua_State *L, int idx) { |
756 | Table *t; | 756 | Table *t; |
757 | int tag; | 757 | lu_byte tag; |
758 | lua_lock(L); | 758 | lua_lock(L); |
759 | api_checkpop(L, 1); | 759 | api_checkpop(L, 1); |
760 | t = gettable(L, idx); | 760 | t = gettable(L, idx); |
@@ -766,7 +766,7 @@ LUA_API int lua_rawget (lua_State *L, int idx) { | |||
766 | 766 | ||
767 | LUA_API int lua_rawgeti (lua_State *L, int idx, lua_Integer n) { | 767 | LUA_API int lua_rawgeti (lua_State *L, int idx, lua_Integer n) { |
768 | Table *t; | 768 | Table *t; |
769 | int tag; | 769 | lu_byte tag; |
770 | lua_lock(L); | 770 | lua_lock(L); |
771 | t = gettable(L, idx); | 771 | t = gettable(L, idx); |
772 | luaH_fastgeti(t, n, s2v(L->top.p), tag); | 772 | luaH_fastgeti(t, n, s2v(L->top.p), tag); |
@@ -1231,7 +1231,7 @@ LUA_API int lua_gc (lua_State *L, int what, ...) { | |||
1231 | api_check(L, 0 <= param && param < LUA_GCPN, "invalid parameter"); | 1231 | api_check(L, 0 <= param && param < LUA_GCPN, "invalid parameter"); |
1232 | res = cast_int(luaO_applyparam(g->gcparams[param], 100)); | 1232 | res = cast_int(luaO_applyparam(g->gcparams[param], 100)); |
1233 | if (value >= 0) | 1233 | if (value >= 0) |
1234 | g->gcparams[param] = luaO_codeparam(value); | 1234 | g->gcparams[param] = luaO_codeparam(cast_uint(value)); |
1235 | break; | 1235 | break; |
1236 | } | 1236 | } |
1237 | default: res = -1; /* invalid option */ | 1237 | default: res = -1; /* invalid option */ |
@@ -1353,7 +1353,7 @@ LUA_API void *lua_newuserdatauv (lua_State *L, size_t size, int nuvalue) { | |||
1353 | Udata *u; | 1353 | Udata *u; |
1354 | lua_lock(L); | 1354 | lua_lock(L); |
1355 | api_check(L, 0 <= nuvalue && nuvalue < USHRT_MAX, "invalid value"); | 1355 | api_check(L, 0 <= nuvalue && nuvalue < USHRT_MAX, "invalid value"); |
1356 | u = luaS_newudata(L, size, nuvalue); | 1356 | u = luaS_newudata(L, size, cast(unsigned short, nuvalue)); |
1357 | setuvalue(L, s2v(L->top.p), u); | 1357 | setuvalue(L, s2v(L->top.p), u); |
1358 | api_incr_top(L); | 1358 | api_incr_top(L); |
1359 | advancegc(L, size); | 1359 | advancegc(L, size); |
@@ -539,7 +539,7 @@ static void newbox (lua_State *L) { | |||
539 | static size_t newbuffsize (luaL_Buffer *B, size_t sz) { | 539 | static size_t newbuffsize (luaL_Buffer *B, size_t sz) { |
540 | size_t newsize = (B->size / 2) * 3; /* buffer size * 1.5 */ | 540 | size_t newsize = (B->size / 2) * 3; /* buffer size * 1.5 */ |
541 | if (l_unlikely(sz > MAX_SIZE - B->n - 1)) | 541 | if (l_unlikely(sz > MAX_SIZE - B->n - 1)) |
542 | return luaL_error(B->L, "resulting string too large"); | 542 | return cast_sizet(luaL_error(B->L, "resulting string too large")); |
543 | if (newsize < B->n + sz + 1 || newsize > MAX_SIZE) { | 543 | if (newsize < B->n + sz + 1 || newsize > MAX_SIZE) { |
544 | /* newsize was not big enough or too big */ | 544 | /* newsize was not big enough or too big */ |
545 | newsize = B->n + sz + 1; | 545 | newsize = B->n + sz + 1; |
@@ -725,7 +725,7 @@ LUALIB_API void luaL_unref (lua_State *L, int t, int ref) { | |||
725 | */ | 725 | */ |
726 | 726 | ||
727 | typedef struct LoadF { | 727 | typedef struct LoadF { |
728 | int n; /* number of pre-read characters */ | 728 | unsigned n; /* number of pre-read characters */ |
729 | FILE *f; /* file being read */ | 729 | FILE *f; /* file being read */ |
730 | char buff[BUFSIZ]; /* area for reading file */ | 730 | char buff[BUFSIZ]; /* area for reading file */ |
731 | } LoadF; | 731 | } LoadF; |
@@ -825,7 +825,7 @@ LUALIB_API int luaL_loadfilex (lua_State *L, const char *filename, | |||
825 | } | 825 | } |
826 | } | 826 | } |
827 | if (c != EOF) | 827 | if (c != EOF) |
828 | lf.buff[lf.n++] = c; /* 'c' is the first character of the stream */ | 828 | lf.buff[lf.n++] = cast_char(c); /* 'c' is the first character */ |
829 | status = lua_load(L, getF, &lf, lua_tostring(L, -1), mode); | 829 | status = lua_load(L, getF, &lf, lua_tostring(L, -1), mode); |
830 | readstatus = ferror(lf.f); | 830 | readstatus = ferror(lf.f); |
831 | errno = 0; /* no useful error number until here */ | 831 | errno = 0; /* no useful error number until here */ |
@@ -1020,7 +1020,7 @@ LUALIB_API void luaL_addgsub (luaL_Buffer *b, const char *s, | |||
1020 | const char *wild; | 1020 | const char *wild; |
1021 | size_t l = strlen(p); | 1021 | size_t l = strlen(p); |
1022 | while ((wild = strstr(s, p)) != NULL) { | 1022 | while ((wild = strstr(s, p)) != NULL) { |
1023 | luaL_addlstring(b, s, wild - s); /* push prefix */ | 1023 | luaL_addlstring(b, s, ct_diff2sz(wild - s)); /* push prefix */ |
1024 | luaL_addstring(b, r); /* push replacement in place of pattern */ | 1024 | luaL_addstring(b, r); /* push replacement in place of pattern */ |
1025 | s = wild + l; /* continue after 'p' */ | 1025 | s = wild + l; /* continue after 'p' */ |
1026 | } | 1026 | } |
@@ -58,21 +58,22 @@ static int luaB_warn (lua_State *L) { | |||
58 | 58 | ||
59 | #define SPACECHARS " \f\n\r\t\v" | 59 | #define SPACECHARS " \f\n\r\t\v" |
60 | 60 | ||
61 | static const char *b_str2int (const char *s, int base, lua_Integer *pn) { | 61 | static const char *b_str2int (const char *s, unsigned base, lua_Integer *pn) { |
62 | lua_Unsigned n = 0; | 62 | lua_Unsigned n = 0; |
63 | int neg = 0; | 63 | int neg = 0; |
64 | s += strspn(s, SPACECHARS); /* skip initial spaces */ | 64 | s += strspn(s, SPACECHARS); /* skip initial spaces */ |
65 | if (*s == '-') { s++; neg = 1; } /* handle sign */ | 65 | if (*s == '-') { s++; neg = 1; } /* handle sign */ |
66 | else if (*s == '+') s++; | 66 | else if (*s == '+') s++; |
67 | if (!isalnum((unsigned char)*s)) /* no digit? */ | 67 | if (!isalnum(cast_uchar(*s))) /* no digit? */ |
68 | return NULL; | 68 | return NULL; |
69 | do { | 69 | do { |
70 | int digit = (isdigit((unsigned char)*s)) ? *s - '0' | 70 | unsigned digit = cast_uint(isdigit(cast_uchar(*s)) |
71 | : (toupper((unsigned char)*s) - 'A') + 10; | 71 | ? *s - '0' |
72 | : (toupper(cast_uchar(*s)) - 'A') + 10); | ||
72 | if (digit >= base) return NULL; /* invalid numeral */ | 73 | if (digit >= base) return NULL; /* invalid numeral */ |
73 | n = n * base + digit; | 74 | n = n * base + digit; |
74 | s++; | 75 | s++; |
75 | } while (isalnum((unsigned char)*s)); | 76 | } while (isalnum(cast_uchar(*s))); |
76 | s += strspn(s, SPACECHARS); /* skip trailing spaces */ | 77 | s += strspn(s, SPACECHARS); /* skip trailing spaces */ |
77 | *pn = (lua_Integer)((neg) ? (0u - n) : n); | 78 | *pn = (lua_Integer)((neg) ? (0u - n) : n); |
78 | return s; | 79 | return s; |
@@ -102,7 +103,7 @@ static int luaB_tonumber (lua_State *L) { | |||
102 | luaL_checktype(L, 1, LUA_TSTRING); /* no numbers as strings */ | 103 | luaL_checktype(L, 1, LUA_TSTRING); /* no numbers as strings */ |
103 | s = lua_tolstring(L, 1, &l); | 104 | s = lua_tolstring(L, 1, &l); |
104 | luaL_argcheck(L, 2 <= base && base <= 36, 2, "base out of range"); | 105 | luaL_argcheck(L, 2 <= base && base <= 36, 2, "base out of range"); |
105 | if (b_str2int(s, (int)base, &n) == s + l) { | 106 | if (b_str2int(s, cast_uint(base), &n) == s + l) { |
106 | lua_pushinteger(L, n); | 107 | lua_pushinteger(L, n); |
107 | return 1; | 108 | return 1; |
108 | } /* else not a number */ | 109 | } /* else not a number */ |
@@ -159,7 +160,7 @@ static int luaB_rawlen (lua_State *L) { | |||
159 | int t = lua_type(L, 1); | 160 | int t = lua_type(L, 1); |
160 | luaL_argexpected(L, t == LUA_TTABLE || t == LUA_TSTRING, 1, | 161 | luaL_argexpected(L, t == LUA_TTABLE || t == LUA_TSTRING, 1, |
161 | "table or string"); | 162 | "table or string"); |
162 | lua_pushinteger(L, lua_rawlen(L, 1)); | 163 | lua_pushinteger(L, l_castU2S(lua_rawlen(L, 1))); |
163 | return 1; | 164 | return 1; |
164 | } | 165 | } |
165 | 166 | ||
@@ -335,7 +335,7 @@ static void savelineinfo (FuncState *fs, Proto *f, int line) { | |||
335 | } | 335 | } |
336 | luaM_growvector(fs->ls->L, f->lineinfo, pc, f->sizelineinfo, ls_byte, | 336 | luaM_growvector(fs->ls->L, f->lineinfo, pc, f->sizelineinfo, ls_byte, |
337 | INT_MAX, "opcodes"); | 337 | INT_MAX, "opcodes"); |
338 | f->lineinfo[pc] = linedif; | 338 | f->lineinfo[pc] = cast(ls_byte, linedif); |
339 | fs->previousline = line; /* last line saved */ | 339 | fs->previousline = line; /* last line saved */ |
340 | } | 340 | } |
341 | 341 | ||
@@ -409,7 +409,7 @@ int luaK_codevABCk (FuncState *fs, OpCode o, int A, int B, int C, int k) { | |||
409 | /* | 409 | /* |
410 | ** Format and emit an 'iABx' instruction. | 410 | ** Format and emit an 'iABx' instruction. |
411 | */ | 411 | */ |
412 | int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bc) { | 412 | int luaK_codeABx (FuncState *fs, OpCode o, int A, int Bc) { |
413 | lua_assert(getOpMode(o) == iABx); | 413 | lua_assert(getOpMode(o) == iABx); |
414 | lua_assert(A <= MAXARG_A && Bc <= MAXARG_Bx); | 414 | lua_assert(A <= MAXARG_A && Bc <= MAXARG_Bx); |
415 | return luaK_code(fs, CREATE_ABx(o, A, Bc)); | 415 | return luaK_code(fs, CREATE_ABx(o, A, Bc)); |
@@ -420,7 +420,7 @@ int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bc) { | |||
420 | ** Format and emit an 'iAsBx' instruction. | 420 | ** Format and emit an 'iAsBx' instruction. |
421 | */ | 421 | */ |
422 | static int codeAsBx (FuncState *fs, OpCode o, int A, int Bc) { | 422 | static int codeAsBx (FuncState *fs, OpCode o, int A, int Bc) { |
423 | unsigned int b = cast_uint(Bc) + OFFSET_sBx; | 423 | int b = Bc + OFFSET_sBx; |
424 | lua_assert(getOpMode(o) == iAsBx); | 424 | lua_assert(getOpMode(o) == iAsBx); |
425 | lua_assert(A <= MAXARG_A && b <= MAXARG_Bx); | 425 | lua_assert(A <= MAXARG_A && b <= MAXARG_Bx); |
426 | return luaK_code(fs, CREATE_ABx(o, A, b)); | 426 | return luaK_code(fs, CREATE_ABx(o, A, b)); |
@@ -431,7 +431,7 @@ static int codeAsBx (FuncState *fs, OpCode o, int A, int Bc) { | |||
431 | ** Format and emit an 'isJ' instruction. | 431 | ** Format and emit an 'isJ' instruction. |
432 | */ | 432 | */ |
433 | static int codesJ (FuncState *fs, OpCode o, int sj, int k) { | 433 | static int codesJ (FuncState *fs, OpCode o, int sj, int k) { |
434 | unsigned int j = cast_uint(sj) + OFFSET_sJ; | 434 | int j = sj + OFFSET_sJ; |
435 | lua_assert(getOpMode(o) == isJ); | 435 | lua_assert(getOpMode(o) == isJ); |
436 | lua_assert(j <= MAXARG_sJ && (k & ~1) == 0); | 436 | lua_assert(j <= MAXARG_sJ && (k & ~1) == 0); |
437 | return luaK_code(fs, CREATE_sJ(o, j, k)); | 437 | return luaK_code(fs, CREATE_sJ(o, j, k)); |
@@ -483,7 +483,7 @@ void luaK_checkstack (FuncState *fs, int n) { | |||
483 | */ | 483 | */ |
484 | void luaK_reserveregs (FuncState *fs, int n) { | 484 | void luaK_reserveregs (FuncState *fs, int n) { |
485 | luaK_checkstack(fs, n); | 485 | luaK_checkstack(fs, n); |
486 | fs->freereg += n; | 486 | fs->freereg = cast_byte(fs->freereg + n); |
487 | } | 487 | } |
488 | 488 | ||
489 | 489 | ||
@@ -1290,25 +1290,25 @@ void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) { | |||
1290 | if (t->k == VUPVAL && !isKstr(fs, k)) /* upvalue indexed by non 'Kstr'? */ | 1290 | if (t->k == VUPVAL && !isKstr(fs, k)) /* upvalue indexed by non 'Kstr'? */ |
1291 | luaK_exp2anyreg(fs, t); /* put it in a register */ | 1291 | luaK_exp2anyreg(fs, t); /* put it in a register */ |
1292 | if (t->k == VUPVAL) { | 1292 | if (t->k == VUPVAL) { |
1293 | int temp = t->u.info; /* upvalue index */ | 1293 | lu_byte temp = cast_byte(t->u.info); /* upvalue index */ |
1294 | lua_assert(isKstr(fs, k)); | 1294 | lua_assert(isKstr(fs, k)); |
1295 | t->u.ind.t = temp; /* (can't do a direct assignment; values overlap) */ | 1295 | t->u.ind.t = temp; /* (can't do a direct assignment; values overlap) */ |
1296 | t->u.ind.idx = k->u.info; /* literal short string */ | 1296 | t->u.ind.idx = cast(short, k->u.info); /* literal short string */ |
1297 | t->k = VINDEXUP; | 1297 | t->k = VINDEXUP; |
1298 | } | 1298 | } |
1299 | else { | 1299 | else { |
1300 | /* register index of the table */ | 1300 | /* register index of the table */ |
1301 | t->u.ind.t = (t->k == VLOCAL) ? t->u.var.ridx: t->u.info; | 1301 | t->u.ind.t = cast_byte((t->k == VLOCAL) ? t->u.var.ridx: t->u.info); |
1302 | if (isKstr(fs, k)) { | 1302 | if (isKstr(fs, k)) { |
1303 | t->u.ind.idx = k->u.info; /* literal short string */ | 1303 | t->u.ind.idx = cast(short, k->u.info); /* literal short string */ |
1304 | t->k = VINDEXSTR; | 1304 | t->k = VINDEXSTR; |
1305 | } | 1305 | } |
1306 | else if (isCint(k)) { | 1306 | else if (isCint(k)) { /* int. constant in proper range? */ |
1307 | t->u.ind.idx = cast_int(k->u.ival); /* int. constant in proper range */ | 1307 | t->u.ind.idx = cast(short, k->u.ival); |
1308 | t->k = VINDEXI; | 1308 | t->k = VINDEXI; |
1309 | } | 1309 | } |
1310 | else { | 1310 | else { |
1311 | t->u.ind.idx = luaK_exp2anyreg(fs, k); /* register */ | 1311 | t->u.ind.idx = cast(short, luaK_exp2anyreg(fs, k)); /* register */ |
1312 | t->k = VINDEXED; | 1312 | t->k = VINDEXED; |
1313 | } | 1313 | } |
1314 | } | 1314 | } |
@@ -1623,7 +1623,7 @@ void luaK_prefix (FuncState *fs, UnOpr opr, expdesc *e, int line) { | |||
1623 | luaK_dischargevars(fs, e); | 1623 | luaK_dischargevars(fs, e); |
1624 | switch (opr) { | 1624 | switch (opr) { |
1625 | case OPR_MINUS: case OPR_BNOT: /* use 'ef' as fake 2nd operand */ | 1625 | case OPR_MINUS: case OPR_BNOT: /* use 'ef' as fake 2nd operand */ |
1626 | if (constfolding(fs, opr + LUA_OPUNM, e, &ef)) | 1626 | if (constfolding(fs, cast_int(opr + LUA_OPUNM), e, &ef)) |
1627 | break; | 1627 | break; |
1628 | /* else */ /* FALLTHROUGH */ | 1628 | /* else */ /* FALLTHROUGH */ |
1629 | case OPR_LEN: | 1629 | case OPR_LEN: |
@@ -1711,7 +1711,7 @@ static void codeconcat (FuncState *fs, expdesc *e1, expdesc *e2, int line) { | |||
1711 | void luaK_posfix (FuncState *fs, BinOpr opr, | 1711 | void luaK_posfix (FuncState *fs, BinOpr opr, |
1712 | expdesc *e1, expdesc *e2, int line) { | 1712 | expdesc *e1, expdesc *e2, int line) { |
1713 | luaK_dischargevars(fs, e2); | 1713 | luaK_dischargevars(fs, e2); |
1714 | if (foldbinop(opr) && constfolding(fs, opr + LUA_OPADD, e1, e2)) | 1714 | if (foldbinop(opr) && constfolding(fs, cast_int(opr + LUA_OPADD), e1, e2)) |
1715 | return; /* done by folding */ | 1715 | return; /* done by folding */ |
1716 | switch (opr) { | 1716 | switch (opr) { |
1717 | case OPR_AND: { | 1717 | case OPR_AND: { |
@@ -1797,11 +1797,11 @@ void luaK_fixline (FuncState *fs, int line) { | |||
1797 | 1797 | ||
1798 | void luaK_settablesize (FuncState *fs, int pc, int ra, int asize, int hsize) { | 1798 | void luaK_settablesize (FuncState *fs, int pc, int ra, int asize, int hsize) { |
1799 | Instruction *inst = &fs->f->code[pc]; | 1799 | Instruction *inst = &fs->f->code[pc]; |
1800 | int rb = (hsize != 0) ? luaO_ceillog2(hsize) + 1 : 0; /* hash size */ | ||
1801 | int extra = asize / (MAXARG_vC + 1); /* higher bits of array size */ | 1800 | int extra = asize / (MAXARG_vC + 1); /* higher bits of array size */ |
1802 | int rc = asize % (MAXARG_vC + 1); /* lower bits of array size */ | 1801 | int rc = asize % (MAXARG_vC + 1); /* lower bits of array size */ |
1803 | int k = (extra > 0); /* true iff needs extra argument */ | 1802 | int k = (extra > 0); /* true iff needs extra argument */ |
1804 | *inst = CREATE_vABCk(OP_NEWTABLE, ra, rb, rc, k); | 1803 | hsize = (hsize != 0) ? luaO_ceillog2(cast_uint(hsize)) + 1 : 0; |
1804 | *inst = CREATE_vABCk(OP_NEWTABLE, ra, hsize, rc, k); | ||
1805 | *(inst + 1) = CREATE_Ax(OP_EXTRAARG, extra); | 1805 | *(inst + 1) = CREATE_Ax(OP_EXTRAARG, extra); |
1806 | } | 1806 | } |
1807 | 1807 | ||
@@ -1825,7 +1825,7 @@ void luaK_setlist (FuncState *fs, int base, int nelems, int tostore) { | |||
1825 | luaK_codevABCk(fs, OP_SETLIST, base, tostore, nelems, 1); | 1825 | luaK_codevABCk(fs, OP_SETLIST, base, tostore, nelems, 1); |
1826 | codeextraarg(fs, extra); | 1826 | codeextraarg(fs, extra); |
1827 | } | 1827 | } |
1828 | fs->freereg = base + 1; /* free registers with list values */ | 1828 | fs->freereg = cast_byte(base + 1); /* free registers with list values */ |
1829 | } | 1829 | } |
1830 | 1830 | ||
1831 | 1831 | ||
@@ -60,7 +60,7 @@ typedef enum UnOpr { OPR_MINUS, OPR_BNOT, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr; | |||
60 | #define luaK_jumpto(fs,t) luaK_patchlist(fs, luaK_jump(fs), t) | 60 | #define luaK_jumpto(fs,t) luaK_patchlist(fs, luaK_jump(fs), t) |
61 | 61 | ||
62 | LUAI_FUNC int luaK_code (FuncState *fs, Instruction i); | 62 | LUAI_FUNC int luaK_code (FuncState *fs, Instruction i); |
63 | LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned Bx); | 63 | LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, int Bx); |
64 | LUAI_FUNC int luaK_codeABCk (FuncState *fs, OpCode o, int A, int B, int C, | 64 | LUAI_FUNC int luaK_codeABCk (FuncState *fs, OpCode o, int A, int B, int C, |
65 | int k); | 65 | int k); |
66 | LUAI_FUNC int luaK_codevABCk (FuncState *fs, OpCode o, int A, int B, int C, | 66 | LUAI_FUNC int luaK_codevABCk (FuncState *fs, OpCode o, int A, int B, int C, |
@@ -63,7 +63,7 @@ static int getbaseline (const Proto *f, int pc, int *basepc) { | |||
63 | return f->linedefined; | 63 | return f->linedefined; |
64 | } | 64 | } |
65 | else { | 65 | else { |
66 | int i = cast_uint(pc) / MAXIWTHABS - 1; /* get an estimate */ | 66 | int i = pc / MAXIWTHABS - 1; /* get an estimate */ |
67 | /* estimate must be a lower bound of the correct base */ | 67 | /* estimate must be a lower bound of the correct base */ |
68 | lua_assert(i < 0 || | 68 | lua_assert(i < 0 || |
69 | (i < f->sizeabslineinfo && f->abslineinfo[i].pc <= pc)); | 69 | (i < f->sizeabslineinfo && f->abslineinfo[i].pc <= pc)); |
@@ -921,7 +921,7 @@ int luaG_tracecall (lua_State *L) { | |||
921 | */ | 921 | */ |
922 | int luaG_traceexec (lua_State *L, const Instruction *pc) { | 922 | int luaG_traceexec (lua_State *L, const Instruction *pc) { |
923 | CallInfo *ci = L->ci; | 923 | CallInfo *ci = L->ci; |
924 | lu_byte mask = L->hookmask; | 924 | lu_byte mask = cast_byte(L->hookmask); |
925 | const Proto *p = ci_func(ci)->p; | 925 | const Proto *p = ci_func(ci)->p; |
926 | int counthook; | 926 | int counthook; |
927 | if (!(mask & (LUA_MASKLINE | LUA_MASKCOUNT))) { /* no hooks? */ | 927 | if (!(mask & (LUA_MASKLINE | LUA_MASKCOUNT))) { /* no hooks? */ |
@@ -241,7 +241,7 @@ int luaD_reallocstack (lua_State *L, int newsize, int raiseerror) { | |||
241 | int oldsize = stacksize(L); | 241 | int oldsize = stacksize(L); |
242 | int i; | 242 | int i; |
243 | StkId newstack; | 243 | StkId newstack; |
244 | int oldgcstop = G(L)->gcstopem; | 244 | lu_byte oldgcstop = G(L)->gcstopem; |
245 | lua_assert(newsize <= MAXSTACK || newsize == ERRORSTACKSIZE); | 245 | lua_assert(newsize <= MAXSTACK || newsize == ERRORSTACKSIZE); |
246 | relstack(L); /* change pointers to offsets */ | 246 | relstack(L); /* change pointers to offsets */ |
247 | G(L)->gcstopem = 1; /* stop emergency collection */ | 247 | G(L)->gcstopem = 1; /* stop emergency collection */ |
@@ -357,7 +357,7 @@ void luaD_hook (lua_State *L, int event, int line, | |||
357 | int ftransfer, int ntransfer) { | 357 | int ftransfer, int ntransfer) { |
358 | lua_Hook hook = L->hook; | 358 | lua_Hook hook = L->hook; |
359 | if (hook && L->allowhook) { /* make sure there is a hook */ | 359 | if (hook && L->allowhook) { /* make sure there is a hook */ |
360 | int mask = CIST_HOOKED; | 360 | unsigned mask = CIST_HOOKED; |
361 | CallInfo *ci = L->ci; | 361 | CallInfo *ci = L->ci; |
362 | ptrdiff_t top = savestack(L, L->top.p); /* preserve original 'top' */ | 362 | ptrdiff_t top = savestack(L, L->top.p); /* preserve original 'top' */ |
363 | ptrdiff_t ci_top = savestack(L, ci->top.p); /* idem for 'ci->top' */ | 363 | ptrdiff_t ci_top = savestack(L, ci->top.p); /* idem for 'ci->top' */ |
@@ -1058,9 +1058,9 @@ int luaD_protectedparser (lua_State *L, ZIO *z, const char *name, | |||
1058 | luaZ_initbuffer(L, &p.buff); | 1058 | luaZ_initbuffer(L, &p.buff); |
1059 | status = luaD_pcall(L, f_parser, &p, savestack(L, L->top.p), L->errfunc); | 1059 | status = luaD_pcall(L, f_parser, &p, savestack(L, L->top.p), L->errfunc); |
1060 | luaZ_freebuffer(L, &p.buff); | 1060 | luaZ_freebuffer(L, &p.buff); |
1061 | luaM_freearray(L, p.dyd.actvar.arr, p.dyd.actvar.size); | 1061 | luaM_freearray(L, p.dyd.actvar.arr, cast_sizet(p.dyd.actvar.size)); |
1062 | luaM_freearray(L, p.dyd.gt.arr, p.dyd.gt.size); | 1062 | luaM_freearray(L, p.dyd.gt.arr, cast_sizet(p.dyd.gt.size)); |
1063 | luaM_freearray(L, p.dyd.label.arr, p.dyd.label.size); | 1063 | luaM_freearray(L, p.dyd.label.arr, cast_sizet(p.dyd.label.size)); |
1064 | decnny(L); | 1064 | decnny(L); |
1065 | return status; | 1065 | return status; |
1066 | } | 1066 | } |
@@ -27,7 +27,7 @@ typedef struct { | |||
27 | lua_State *L; | 27 | lua_State *L; |
28 | lua_Writer writer; | 28 | lua_Writer writer; |
29 | void *data; | 29 | void *data; |
30 | lu_mem offset; /* current position relative to beginning of dump */ | 30 | size_t offset; /* current position relative to beginning of dump */ |
31 | int strip; | 31 | int strip; |
32 | int status; | 32 | int status; |
33 | Table *h; /* table to track saved strings */ | 33 | Table *h; /* table to track saved strings */ |
@@ -63,11 +63,11 @@ static void dumpBlock (DumpState *D, const void *b, size_t size) { | |||
63 | ** Dump enough zeros to ensure that current position is a multiple of | 63 | ** Dump enough zeros to ensure that current position is a multiple of |
64 | ** 'align'. | 64 | ** 'align'. |
65 | */ | 65 | */ |
66 | static void dumpAlign (DumpState *D, int align) { | 66 | static void dumpAlign (DumpState *D, unsigned align) { |
67 | int padding = align - (D->offset % align); | 67 | unsigned padding = align - cast_uint(D->offset % align); |
68 | if (padding < align) { /* padding == align means no padding */ | 68 | if (padding < align) { /* padding == align means no padding */ |
69 | static lua_Integer paddingContent = 0; | 69 | static lua_Integer paddingContent = 0; |
70 | lua_assert(cast_uint(align) <= sizeof(lua_Integer)); | 70 | lua_assert(align <= sizeof(lua_Integer)); |
71 | dumpBlock(D, &paddingContent, padding); | 71 | dumpBlock(D, &paddingContent, padding); |
72 | } | 72 | } |
73 | lua_assert(D->offset % align == 0); | 73 | lua_assert(D->offset % align == 0); |
@@ -94,10 +94,10 @@ static void dumpByte (DumpState *D, int y) { | |||
94 | */ | 94 | */ |
95 | static void dumpVarint (DumpState *D, size_t x) { | 95 | static void dumpVarint (DumpState *D, size_t x) { |
96 | lu_byte buff[DIBS]; | 96 | lu_byte buff[DIBS]; |
97 | int n = 1; | 97 | unsigned n = 1; |
98 | buff[DIBS - 1] = x & 0x7f; /* fill least-significant byte */ | 98 | buff[DIBS - 1] = x & 0x7f; /* fill least-significant byte */ |
99 | while ((x >>= 7) != 0) /* fill other bytes in reverse order */ | 99 | while ((x >>= 7) != 0) /* fill other bytes in reverse order */ |
100 | buff[DIBS - (++n)] = (x & 0x7f) | 0x80; | 100 | buff[DIBS - (++n)] = cast_byte((x & 0x7f) | 0x80); |
101 | dumpVector(D, buff + DIBS - n, n); | 101 | dumpVector(D, buff + DIBS - n, n); |
102 | } | 102 | } |
103 | 103 | ||
@@ -159,7 +159,7 @@ static void dumpCode (DumpState *D, const Proto *f) { | |||
159 | dumpInt(D, f->sizecode); | 159 | dumpInt(D, f->sizecode); |
160 | dumpAlign(D, sizeof(f->code[0])); | 160 | dumpAlign(D, sizeof(f->code[0])); |
161 | lua_assert(f->code != NULL); | 161 | lua_assert(f->code != NULL); |
162 | dumpVector(D, f->code, f->sizecode); | 162 | dumpVector(D, f->code, cast_uint(f->sizecode)); |
163 | } | 163 | } |
164 | 164 | ||
165 | 165 | ||
@@ -216,13 +216,13 @@ static void dumpDebug (DumpState *D, const Proto *f) { | |||
216 | n = (D->strip) ? 0 : f->sizelineinfo; | 216 | n = (D->strip) ? 0 : f->sizelineinfo; |
217 | dumpInt(D, n); | 217 | dumpInt(D, n); |
218 | if (f->lineinfo != NULL) | 218 | if (f->lineinfo != NULL) |
219 | dumpVector(D, f->lineinfo, n); | 219 | dumpVector(D, f->lineinfo, cast_uint(n)); |
220 | n = (D->strip) ? 0 : f->sizeabslineinfo; | 220 | n = (D->strip) ? 0 : f->sizeabslineinfo; |
221 | dumpInt(D, n); | 221 | dumpInt(D, n); |
222 | if (n > 0) { | 222 | if (n > 0) { |
223 | /* 'abslineinfo' is an array of structures of int's */ | 223 | /* 'abslineinfo' is an array of structures of int's */ |
224 | dumpAlign(D, sizeof(int)); | 224 | dumpAlign(D, sizeof(int)); |
225 | dumpVector(D, f->abslineinfo, n); | 225 | dumpVector(D, f->abslineinfo, cast_uint(n)); |
226 | } | 226 | } |
227 | n = (D->strip) ? 0 : f->sizelocvars; | 227 | n = (D->strip) ? 0 : f->sizelocvars; |
228 | dumpInt(D, n); | 228 | dumpInt(D, n); |
@@ -266,14 +266,14 @@ Proto *luaF_newproto (lua_State *L) { | |||
266 | 266 | ||
267 | void luaF_freeproto (lua_State *L, Proto *f) { | 267 | void luaF_freeproto (lua_State *L, Proto *f) { |
268 | if (!(f->flag & PF_FIXED)) { | 268 | if (!(f->flag & PF_FIXED)) { |
269 | luaM_freearray(L, f->code, f->sizecode); | 269 | luaM_freearray(L, f->code, cast_sizet(f->sizecode)); |
270 | luaM_freearray(L, f->lineinfo, f->sizelineinfo); | 270 | luaM_freearray(L, f->lineinfo, cast_sizet(f->sizelineinfo)); |
271 | luaM_freearray(L, f->abslineinfo, f->sizeabslineinfo); | 271 | luaM_freearray(L, f->abslineinfo, cast_sizet(f->sizeabslineinfo)); |
272 | } | 272 | } |
273 | luaM_freearray(L, f->p, f->sizep); | 273 | luaM_freearray(L, f->p, cast_sizet(f->sizep)); |
274 | luaM_freearray(L, f->k, f->sizek); | 274 | luaM_freearray(L, f->k, cast_sizet(f->sizek)); |
275 | luaM_freearray(L, f->locvars, f->sizelocvars); | 275 | luaM_freearray(L, f->locvars, cast_sizet(f->sizelocvars)); |
276 | luaM_freearray(L, f->upvalues, f->sizeupvalues); | 276 | luaM_freearray(L, f->upvalues, cast_sizet(f->sizeupvalues)); |
277 | luaM_free(L, f); | 277 | luaM_free(L, f); |
278 | } | 278 | } |
279 | 279 | ||
@@ -11,11 +11,11 @@ | |||
11 | #include "lobject.h" | 11 | #include "lobject.h" |
12 | 12 | ||
13 | 13 | ||
14 | #define sizeCclosure(n) (cast_int(offsetof(CClosure, upvalue)) + \ | 14 | #define sizeCclosure(n) \ |
15 | cast_int(sizeof(TValue)) * (n)) | 15 | (offsetof(CClosure, upvalue) + sizeof(TValue) * cast_uint(n)) |
16 | 16 | ||
17 | #define sizeLclosure(n) (cast_int(offsetof(LClosure, upvals)) + \ | 17 | #define sizeLclosure(n) \ |
18 | cast_int(sizeof(TValue *)) * (n)) | 18 | (offsetof(LClosure, upvals) + sizeof(TValue *) * cast_uint(n)) |
19 | 19 | ||
20 | 20 | ||
21 | /* test whether thread is in 'twups' list */ | 21 | /* test whether thread is in 'twups' list */ |
@@ -246,7 +246,7 @@ void luaC_fix (lua_State *L, GCObject *o) { | |||
246 | ** create a new collectable object (with given type, size, and offset) | 246 | ** create a new collectable object (with given type, size, and offset) |
247 | ** and link it to 'allgc' list. | 247 | ** and link it to 'allgc' list. |
248 | */ | 248 | */ |
249 | GCObject *luaC_newobjdt (lua_State *L, int tt, size_t sz, size_t offset) { | 249 | GCObject *luaC_newobjdt (lua_State *L, lu_byte tt, size_t sz, size_t offset) { |
250 | global_State *g = G(L); | 250 | global_State *g = G(L); |
251 | char *p = cast_charp(luaM_newobject(L, novariant(tt), sz)); | 251 | char *p = cast_charp(luaM_newobject(L, novariant(tt), sz)); |
252 | GCObject *o = cast(GCObject *, p + offset); | 252 | GCObject *o = cast(GCObject *, p + offset); |
@@ -262,7 +262,7 @@ GCObject *luaC_newobjdt (lua_State *L, int tt, size_t sz, size_t offset) { | |||
262 | /* | 262 | /* |
263 | ** create a new collectable object with no offset. | 263 | ** create a new collectable object with no offset. |
264 | */ | 264 | */ |
265 | GCObject *luaC_newobj (lua_State *L, int tt, size_t sz) { | 265 | GCObject *luaC_newobj (lua_State *L, lu_byte tt, size_t sz) { |
266 | return luaC_newobjdt(L, tt, sz, 0); | 266 | return luaC_newobjdt(L, tt, sz, 0); |
267 | } | 267 | } |
268 | 268 | ||
@@ -813,7 +813,7 @@ static void freeobj (lua_State *L, GCObject *o) { | |||
813 | case LUA_VSHRSTR: { | 813 | case LUA_VSHRSTR: { |
814 | TString *ts = gco2ts(o); | 814 | TString *ts = gco2ts(o); |
815 | luaS_remove(L, ts); /* remove it from hash table */ | 815 | luaS_remove(L, ts); /* remove it from hash table */ |
816 | luaM_freemem(L, ts, sizestrshr(ts->shrlen)); | 816 | luaM_freemem(L, ts, sizestrshr(cast_uint(ts->shrlen))); |
817 | break; | 817 | break; |
818 | } | 818 | } |
819 | case LUA_VLNGSTR: { | 819 | case LUA_VLNGSTR: { |
@@ -922,7 +922,7 @@ static void GCTM (lua_State *L) { | |||
922 | if (!notm(tm)) { /* is there a finalizer? */ | 922 | if (!notm(tm)) { /* is there a finalizer? */ |
923 | int status; | 923 | int status; |
924 | lu_byte oldah = L->allowhook; | 924 | lu_byte oldah = L->allowhook; |
925 | int oldgcstp = g->gcstp; | 925 | lu_byte oldgcstp = g->gcstp; |
926 | g->gcstp |= GCSTPGC; /* avoid GC steps */ | 926 | g->gcstp |= GCSTPGC; /* avoid GC steps */ |
927 | L->allowhook = 0; /* stop debug hooks during GC metamethod */ | 927 | L->allowhook = 0; /* stop debug hooks during GC metamethod */ |
928 | setobj2s(L, L->top.p++, tm); /* push finalizer... */ | 928 | setobj2s(L, L->top.p++, tm); /* push finalizer... */ |
@@ -1235,7 +1235,7 @@ static void finishgencycle (lua_State *L, global_State *g) { | |||
1235 | ** the "sweep all" state to clear all objects, which are mostly black | 1235 | ** the "sweep all" state to clear all objects, which are mostly black |
1236 | ** in generational mode. | 1236 | ** in generational mode. |
1237 | */ | 1237 | */ |
1238 | static void minor2inc (lua_State *L, global_State *g, int kind) { | 1238 | static void minor2inc (lua_State *L, global_State *g, lu_byte kind) { |
1239 | g->GCmajorminor = g->marked; /* number of live objects */ | 1239 | g->GCmajorminor = g->marked; /* number of live objects */ |
1240 | g->gckind = kind; | 1240 | g->gckind = kind; |
1241 | g->reallyold = g->old1 = g->survival = NULL; | 1241 | g->reallyold = g->old1 = g->survival = NULL; |
@@ -1522,7 +1522,7 @@ static l_obj atomic (lua_State *L) { | |||
1522 | ** elements. The fast case sweeps the whole list. | 1522 | ** elements. The fast case sweeps the whole list. |
1523 | */ | 1523 | */ |
1524 | static void sweepstep (lua_State *L, global_State *g, | 1524 | static void sweepstep (lua_State *L, global_State *g, |
1525 | int nextstate, GCObject **nextlist, int fast) { | 1525 | lu_byte nextstate, GCObject **nextlist, int fast) { |
1526 | if (g->sweepgc) | 1526 | if (g->sweepgc) |
1527 | g->sweepgc = sweeplist(L, g->sweepgc, fast ? MAX_LOBJ : GCSWEEPMAX); | 1527 | g->sweepgc = sweeplist(L, g->sweepgc, fast ? MAX_LOBJ : GCSWEEPMAX); |
1528 | else { /* enter next state */ | 1528 | else { /* enter next state */ |
@@ -1706,7 +1706,7 @@ static void fullinc (lua_State *L, global_State *g) { | |||
1706 | void luaC_fullgc (lua_State *L, int isemergency) { | 1706 | void luaC_fullgc (lua_State *L, int isemergency) { |
1707 | global_State *g = G(L); | 1707 | global_State *g = G(L); |
1708 | lua_assert(!g->gcemergency); | 1708 | lua_assert(!g->gcemergency); |
1709 | g->gcemergency = isemergency; /* set flag */ | 1709 | g->gcemergency = cast_byte(isemergency); /* set flag */ |
1710 | switch (g->gckind) { | 1710 | switch (g->gckind) { |
1711 | case KGC_GENMINOR: fullgen(L, g); break; | 1711 | case KGC_GENMINOR: fullgen(L, g); break; |
1712 | case KGC_INC: fullinc(L, g); break; | 1712 | case KGC_INC: fullinc(L, g); break; |
@@ -245,8 +245,8 @@ LUAI_FUNC void luaC_freeallobjects (lua_State *L); | |||
245 | LUAI_FUNC void luaC_step (lua_State *L); | 245 | LUAI_FUNC void luaC_step (lua_State *L); |
246 | LUAI_FUNC void luaC_runtilstate (lua_State *L, int state, int fast); | 246 | LUAI_FUNC void luaC_runtilstate (lua_State *L, int state, int fast); |
247 | LUAI_FUNC void luaC_fullgc (lua_State *L, int isemergency); | 247 | LUAI_FUNC void luaC_fullgc (lua_State *L, int isemergency); |
248 | LUAI_FUNC GCObject *luaC_newobj (lua_State *L, int tt, size_t sz); | 248 | LUAI_FUNC GCObject *luaC_newobj (lua_State *L, lu_byte tt, size_t sz); |
249 | LUAI_FUNC GCObject *luaC_newobjdt (lua_State *L, int tt, size_t sz, | 249 | LUAI_FUNC GCObject *luaC_newobjdt (lua_State *L, lu_byte tt, size_t sz, |
250 | size_t offset); | 250 | size_t offset); |
251 | LUAI_FUNC void luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v); | 251 | LUAI_FUNC void luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v); |
252 | LUAI_FUNC void luaC_barrierback_ (lua_State *L, GCObject *o); | 252 | LUAI_FUNC void luaC_barrierback_ (lua_State *L, GCObject *o); |
@@ -443,7 +443,7 @@ static int nextc (RN *rn) { | |||
443 | return 0; /* fail */ | 443 | return 0; /* fail */ |
444 | } | 444 | } |
445 | else { | 445 | else { |
446 | rn->buff[rn->n++] = rn->c; /* save current char */ | 446 | rn->buff[rn->n++] = cast_char(rn->c); /* save current char */ |
447 | rn->c = l_getc(rn->f); /* read next one */ | 447 | rn->c = l_getc(rn->f); /* read next one */ |
448 | return 1; | 448 | return 1; |
449 | } | 449 | } |
@@ -524,15 +524,15 @@ static int read_line (lua_State *L, FILE *f, int chop) { | |||
524 | luaL_buffinit(L, &b); | 524 | luaL_buffinit(L, &b); |
525 | do { /* may need to read several chunks to get whole line */ | 525 | do { /* may need to read several chunks to get whole line */ |
526 | char *buff = luaL_prepbuffer(&b); /* preallocate buffer space */ | 526 | char *buff = luaL_prepbuffer(&b); /* preallocate buffer space */ |
527 | int i = 0; | 527 | unsigned i = 0; |
528 | l_lockfile(f); /* no memory errors can happen inside the lock */ | 528 | l_lockfile(f); /* no memory errors can happen inside the lock */ |
529 | while (i < LUAL_BUFFERSIZE && (c = l_getc(f)) != EOF && c != '\n') | 529 | while (i < LUAL_BUFFERSIZE && (c = l_getc(f)) != EOF && c != '\n') |
530 | buff[i++] = c; /* read up to end of line or buffer limit */ | 530 | buff[i++] = cast_char(c); /* read up to end of line or buffer limit */ |
531 | l_unlockfile(f); | 531 | l_unlockfile(f); |
532 | luaL_addsize(&b, i); | 532 | luaL_addsize(&b, i); |
533 | } while (c != EOF && c != '\n'); /* repeat until end of line */ | 533 | } while (c != EOF && c != '\n'); /* repeat until end of line */ |
534 | if (!chop && c == '\n') /* want a newline and have one? */ | 534 | if (!chop && c == '\n') /* want a newline and have one? */ |
535 | luaL_addchar(&b, c); /* add ending newline to result */ | 535 | luaL_addchar(&b, '\n'); /* add ending newline to result */ |
536 | luaL_pushresult(&b); /* close buffer */ | 536 | luaL_pushresult(&b); /* close buffer */ |
537 | /* return ok if read something (either a newline or something else) */ | 537 | /* return ok if read something (either a newline or something else) */ |
538 | return (c == '\n' || lua_rawlen(L, -1) > 0); | 538 | return (c == '\n' || lua_rawlen(L, -1) > 0); |
@@ -350,7 +350,7 @@ static unsigned long readutf8esc (LexState *ls) { | |||
350 | int i = 4; /* chars to be removed: '\', 'u', '{', and first digit */ | 350 | int i = 4; /* chars to be removed: '\', 'u', '{', and first digit */ |
351 | save_and_next(ls); /* skip 'u' */ | 351 | save_and_next(ls); /* skip 'u' */ |
352 | esccheck(ls, ls->current == '{', "missing '{'"); | 352 | esccheck(ls, ls->current == '{', "missing '{'"); |
353 | r = gethexa(ls); /* must have at least one digit */ | 353 | r = cast_ulong(gethexa(ls)); /* must have at least one digit */ |
354 | while (cast_void(save_and_next(ls)), lisxdigit(ls->current)) { | 354 | while (cast_void(save_and_next(ls)), lisxdigit(ls->current)) { |
355 | i++; | 355 | i++; |
356 | esccheck(ls, r <= (0x7FFFFFFFu >> 4), "UTF-8 value too large"); | 356 | esccheck(ls, r <= (0x7FFFFFFFu >> 4), "UTF-8 value too large"); |
@@ -130,6 +130,7 @@ typedef LUAI_UACINT l_uacInt; | |||
130 | #define cast_num(i) cast(lua_Number, (i)) | 130 | #define cast_num(i) cast(lua_Number, (i)) |
131 | #define cast_int(i) cast(int, (i)) | 131 | #define cast_int(i) cast(int, (i)) |
132 | #define cast_uint(i) cast(unsigned int, (i)) | 132 | #define cast_uint(i) cast(unsigned int, (i)) |
133 | #define cast_ulong(i) cast(unsigned long, (i)) | ||
133 | #define cast_byte(i) cast(lu_byte, (i)) | 134 | #define cast_byte(i) cast(lu_byte, (i)) |
134 | #define cast_uchar(i) cast(unsigned char, (i)) | 135 | #define cast_uchar(i) cast(unsigned char, (i)) |
135 | #define cast_char(i) cast(char, (i)) | 136 | #define cast_char(i) cast(char, (i)) |
@@ -151,6 +152,16 @@ typedef LUAI_UACINT l_uacInt; | |||
151 | #define l_castU2S(i) ((lua_Integer)(i)) | 152 | #define l_castU2S(i) ((lua_Integer)(i)) |
152 | #endif | 153 | #endif |
153 | 154 | ||
155 | /* | ||
156 | ** cast a size_t to lua_Integer: These casts are always valid for | ||
157 | ** sizes of Lua objects (see MAX_SIZE) | ||
158 | */ | ||
159 | #define cast_st2S(sz) ((lua_Integer)(sz)) | ||
160 | |||
161 | /* Cast a ptrdiff_t to size_t, when it is known that the minuend | ||
162 | ** comes from the subtraend (the base) | ||
163 | */ | ||
164 | #define ct_diff2sz(df) ((size_t)(df)) | ||
154 | 165 | ||
155 | /* | 166 | /* |
156 | ** Special type equivalent to '(void*)' for functions (to suppress some | 167 | ** Special type equivalent to '(void*)' for functions (to suppress some |
@@ -578,7 +578,7 @@ static int math_random (lua_State *L) { | |||
578 | low = 1; | 578 | low = 1; |
579 | up = luaL_checkinteger(L, 1); | 579 | up = luaL_checkinteger(L, 1); |
580 | if (up == 0) { /* single 0 as argument? */ | 580 | if (up == 0) { /* single 0 as argument? */ |
581 | lua_pushinteger(L, I2UInt(rv)); /* full random integer */ | 581 | lua_pushinteger(L, l_castU2S(I2UInt(rv))); /* full random integer */ |
582 | return 1; | 582 | return 1; |
583 | } | 583 | } |
584 | break; | 584 | break; |
@@ -594,7 +594,7 @@ static int math_random (lua_State *L) { | |||
594 | luaL_argcheck(L, low <= up, 1, "interval is empty"); | 594 | luaL_argcheck(L, low <= up, 1, "interval is empty"); |
595 | /* project random integer into the interval [0, up - low] */ | 595 | /* project random integer into the interval [0, up - low] */ |
596 | p = project(I2UInt(rv), (lua_Unsigned)up - (lua_Unsigned)low, state); | 596 | p = project(I2UInt(rv), (lua_Unsigned)up - (lua_Unsigned)low, state); |
597 | lua_pushinteger(L, p + (lua_Unsigned)low); | 597 | lua_pushinteger(L, l_castU2S(p) + low); |
598 | return 1; | 598 | return 1; |
599 | } | 599 | } |
600 | 600 | ||
@@ -608,8 +608,8 @@ static void setseed (lua_State *L, Rand64 *state, | |||
608 | state[3] = Int2I(0); | 608 | state[3] = Int2I(0); |
609 | for (i = 0; i < 16; i++) | 609 | for (i = 0; i < 16; i++) |
610 | nextrand(state); /* discard initial values to "spread" seed */ | 610 | nextrand(state); /* discard initial values to "spread" seed */ |
611 | lua_pushinteger(L, n1); | 611 | lua_pushinteger(L, l_castU2S(n1)); |
612 | lua_pushinteger(L, n2); | 612 | lua_pushinteger(L, l_castU2S(n2)); |
613 | } | 613 | } |
614 | 614 | ||
615 | 615 | ||
@@ -621,8 +621,8 @@ static int math_randomseed (lua_State *L) { | |||
621 | n2 = I2UInt(nextrand(state->s)); /* in case seed is not that random... */ | 621 | n2 = I2UInt(nextrand(state->s)); /* in case seed is not that random... */ |
622 | } | 622 | } |
623 | else { | 623 | else { |
624 | n1 = luaL_checkinteger(L, 1); | 624 | n1 = l_castS2U(luaL_checkinteger(L, 1)); |
625 | n2 = luaL_optinteger(L, 2, 0); | 625 | n2 = l_castS2U(luaL_optinteger(L, 2, 0)); |
626 | } | 626 | } |
627 | setseed(L, state->s, n1, n2); | 627 | setseed(L, state->s, n1, n2); |
628 | return 2; /* return seeds */ | 628 | return 2; /* return seeds */ |
@@ -95,7 +95,7 @@ static void *firsttry (global_State *g, void *block, size_t os, size_t ns) { | |||
95 | 95 | ||
96 | 96 | ||
97 | void *luaM_growaux_ (lua_State *L, void *block, int nelems, int *psize, | 97 | void *luaM_growaux_ (lua_State *L, void *block, int nelems, int *psize, |
98 | int size_elems, int limit, const char *what) { | 98 | unsigned size_elems, int limit, const char *what) { |
99 | void *newblock; | 99 | void *newblock; |
100 | int size = *psize; | 100 | int size = *psize; |
101 | if (nelems + 1 <= size) /* does one extra element still fit? */ | 101 | if (nelems + 1 <= size) /* does one extra element still fit? */ |
@@ -203,9 +203,9 @@ void *luaM_malloc_ (lua_State *L, size_t size, int tag) { | |||
203 | return NULL; /* that's all */ | 203 | return NULL; /* that's all */ |
204 | else { | 204 | else { |
205 | global_State *g = G(L); | 205 | global_State *g = G(L); |
206 | void *newblock = firsttry(g, NULL, tag, size); | 206 | void *newblock = firsttry(g, NULL, cast_sizet(tag), size); |
207 | if (l_unlikely(newblock == NULL)) { | 207 | if (l_unlikely(newblock == NULL)) { |
208 | newblock = tryagain(L, NULL, tag, size); | 208 | newblock = tryagain(L, NULL, cast_sizet(tag), size); |
209 | if (newblock == NULL) | 209 | if (newblock == NULL) |
210 | luaM_error(L); | 210 | luaM_error(L); |
211 | } | 211 | } |
@@ -85,7 +85,7 @@ LUAI_FUNC void *luaM_saferealloc_ (lua_State *L, void *block, size_t oldsize, | |||
85 | size_t size); | 85 | size_t size); |
86 | LUAI_FUNC void luaM_free_ (lua_State *L, void *block, size_t osize); | 86 | LUAI_FUNC void luaM_free_ (lua_State *L, void *block, size_t osize); |
87 | LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int nelems, | 87 | LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int nelems, |
88 | int *size, int size_elem, int limit, | 88 | int *size, unsigned size_elem, int limit, |
89 | const char *what); | 89 | const char *what); |
90 | LUAI_FUNC void *luaM_shrinkvector_ (lua_State *L, void *block, int *nelem, | 90 | LUAI_FUNC void *luaM_shrinkvector_ (lua_State *L, void *block, int *nelem, |
91 | int final_n, int size_elem); | 91 | int final_n, int size_elem); |
@@ -288,13 +288,13 @@ static void setpath (lua_State *L, const char *fieldname, | |||
288 | luaL_Buffer b; | 288 | luaL_Buffer b; |
289 | luaL_buffinit(L, &b); | 289 | luaL_buffinit(L, &b); |
290 | if (path < dftmark) { /* is there a prefix before ';;'? */ | 290 | if (path < dftmark) { /* is there a prefix before ';;'? */ |
291 | luaL_addlstring(&b, path, dftmark - path); /* add it */ | 291 | luaL_addlstring(&b, path, ct_diff2sz(dftmark - path)); /* add it */ |
292 | luaL_addchar(&b, *LUA_PATH_SEP); | 292 | luaL_addchar(&b, *LUA_PATH_SEP); |
293 | } | 293 | } |
294 | luaL_addstring(&b, dft); /* add default */ | 294 | luaL_addstring(&b, dft); /* add default */ |
295 | if (dftmark < path + len - 2) { /* is there a suffix after ';;'? */ | 295 | if (dftmark < path + len - 2) { /* is there a suffix after ';;'? */ |
296 | luaL_addchar(&b, *LUA_PATH_SEP); | 296 | luaL_addchar(&b, *LUA_PATH_SEP); |
297 | luaL_addlstring(&b, dftmark + 2, (path + len - 2) - dftmark); | 297 | luaL_addlstring(&b, dftmark + 2, ct_diff2sz((path + len - 2) - dftmark)); |
298 | } | 298 | } |
299 | luaL_pushresult(&b); | 299 | luaL_pushresult(&b); |
300 | } | 300 | } |
@@ -543,7 +543,7 @@ static int loadfunc (lua_State *L, const char *filename, const char *modname) { | |||
543 | mark = strchr(modname, *LUA_IGMARK); | 543 | mark = strchr(modname, *LUA_IGMARK); |
544 | if (mark) { | 544 | if (mark) { |
545 | int stat; | 545 | int stat; |
546 | openfunc = lua_pushlstring(L, modname, mark - modname); | 546 | openfunc = lua_pushlstring(L, modname, ct_diff2sz(mark - modname)); |
547 | openfunc = lua_pushfstring(L, LUA_POF"%s", openfunc); | 547 | openfunc = lua_pushfstring(L, LUA_POF"%s", openfunc); |
548 | stat = lookforfunc(L, filename, openfunc); | 548 | stat = lookforfunc(L, filename, openfunc); |
549 | if (stat != ERRFUNC) return stat; | 549 | if (stat != ERRFUNC) return stat; |
@@ -568,7 +568,7 @@ static int searcher_Croot (lua_State *L) { | |||
568 | const char *p = strchr(name, '.'); | 568 | const char *p = strchr(name, '.'); |
569 | int stat; | 569 | int stat; |
570 | if (p == NULL) return 0; /* is root */ | 570 | if (p == NULL) return 0; /* is root */ |
571 | lua_pushlstring(L, name, p - name); | 571 | lua_pushlstring(L, name, ct_diff2sz(p - name)); |
572 | filename = findfile(L, lua_tostring(L, -1), "cpath", LUA_CSUBSEP); | 572 | filename = findfile(L, lua_tostring(L, -1), "cpath", LUA_CSUBSEP); |
573 | if (filename == NULL) return 1; /* root not found */ | 573 | if (filename == NULL) return 1; /* root not found */ |
574 | if ((stat = loadfunc(L, filename, name)) != 0) { | 574 | if ((stat = loadfunc(L, filename, name)) != 0) { |
@@ -32,7 +32,7 @@ | |||
32 | /* | 32 | /* |
33 | ** Computes ceil(log2(x)) | 33 | ** Computes ceil(log2(x)) |
34 | */ | 34 | */ |
35 | int luaO_ceillog2 (unsigned int x) { | 35 | lu_byte luaO_ceillog2 (unsigned int x) { |
36 | static const lu_byte log_2[256] = { /* log_2[i - 1] = ceil(log2(i)) */ | 36 | static const lu_byte log_2[256] = { /* log_2[i - 1] = ceil(log2(i)) */ |
37 | 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, | 37 | 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, |
38 | 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, | 38 | 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, |
@@ -46,7 +46,7 @@ int luaO_ceillog2 (unsigned int x) { | |||
46 | int l = 0; | 46 | int l = 0; |
47 | x--; | 47 | x--; |
48 | while (x >= 256) { l += 8; x >>= 8; } | 48 | while (x >= 256) { l += 8; x >>= 8; } |
49 | return l + log_2[x]; | 49 | return cast_byte(l + log_2[x]); |
50 | } | 50 | } |
51 | 51 | ||
52 | /* | 52 | /* |
@@ -57,16 +57,19 @@ int luaO_ceillog2 (unsigned int x) { | |||
57 | ** to signal that. So, the real value is (1xxxx) * 2^(eeee - 7 - 1) if | 57 | ** to signal that. So, the real value is (1xxxx) * 2^(eeee - 7 - 1) if |
58 | ** eeee != 0, and (xxxx) * 2^-7 otherwise (subnormal numbers). | 58 | ** eeee != 0, and (xxxx) * 2^-7 otherwise (subnormal numbers). |
59 | */ | 59 | */ |
60 | unsigned int luaO_codeparam (unsigned int p) { | 60 | lu_byte luaO_codeparam (unsigned int p) { |
61 | if (p >= (cast(lu_mem, 0x1F) << (0xF - 7 - 1)) * 100u) /* overflow? */ | 61 | if (p >= (cast(lu_mem, 0x1F) << (0xF - 7 - 1)) * 100u) /* overflow? */ |
62 | return 0xFF; /* return maximum value */ | 62 | return 0xFF; /* return maximum value */ |
63 | else { | 63 | else { |
64 | p = (cast(l_uint32, p) * 128 + 99) / 100; /* round up the division */ | 64 | p = (cast(l_uint32, p) * 128 + 99) / 100; /* round up the division */ |
65 | if (p < 0x10) /* subnormal number? */ | 65 | if (p < 0x10) { /* subnormal number? */ |
66 | return p; /* exponent bits are already zero; nothing else to do */ | 66 | /* exponent bits are already zero; nothing else to do */ |
67 | else { | 67 | return cast_byte(p); |
68 | int log = luaO_ceillog2(p + 1) - 5; /* preserve 5 bits */ | 68 | } |
69 | return ((p >> log) - 0x10) | ((log + 1) << 4); | 69 | else { /* p >= 0x10 implies ceil(log2(p + 1)) >= 5 */ |
70 | /* preserve 5 bits in 'p' */ | ||
71 | unsigned log = luaO_ceillog2(p + 1) - 5u; | ||
72 | return cast_byte(((p >> log) - 0x10) | ((log + 1) << 4)); | ||
70 | } | 73 | } |
71 | } | 74 | } |
72 | } | 75 | } |
@@ -81,7 +84,7 @@ unsigned int luaO_codeparam (unsigned int p) { | |||
81 | ** more significant bits, as long as the multiplication does not | 84 | ** more significant bits, as long as the multiplication does not |
82 | ** overflow, so we check which order is best. | 85 | ** overflow, so we check which order is best. |
83 | */ | 86 | */ |
84 | l_obj luaO_applyparam (unsigned int p, l_obj x) { | 87 | l_obj luaO_applyparam (lu_byte p, l_obj x) { |
85 | unsigned int m = p & 0xF; /* mantissa */ | 88 | unsigned int m = p & 0xF; /* mantissa */ |
86 | int e = (p >> 4); /* exponent */ | 89 | int e = (p >> 4); /* exponent */ |
87 | if (e > 0) { /* normalized? */ | 90 | if (e > 0) { /* normalized? */ |
@@ -189,9 +192,9 @@ void luaO_arith (lua_State *L, int op, const TValue *p1, const TValue *p2, | |||
189 | } | 192 | } |
190 | 193 | ||
191 | 194 | ||
192 | int luaO_hexavalue (int c) { | 195 | lu_byte luaO_hexavalue (int c) { |
193 | if (lisdigit(c)) return c - '0'; | 196 | if (lisdigit(c)) return cast_byte(c - '0'); |
194 | else return (ltolower(c) - 'a') + 10; | 197 | else return cast_byte((ltolower(c) - 'a') + 10); |
195 | } | 198 | } |
196 | 199 | ||
197 | 200 | ||
@@ -349,7 +352,7 @@ static const char *l_str2int (const char *s, lua_Integer *result) { | |||
349 | int d = *s - '0'; | 352 | int d = *s - '0'; |
350 | if (a >= MAXBY10 && (a > MAXBY10 || d > MAXLASTD + neg)) /* overflow? */ | 353 | if (a >= MAXBY10 && (a > MAXBY10 || d > MAXLASTD + neg)) /* overflow? */ |
351 | return NULL; /* do not accept it (as integer) */ | 354 | return NULL; /* do not accept it (as integer) */ |
352 | a = a * 10 + d; | 355 | a = a * 10 + cast_uint(d); |
353 | empty = 0; | 356 | empty = 0; |
354 | } | 357 | } |
355 | } | 358 | } |
@@ -373,7 +376,7 @@ size_t luaO_str2num (const char *s, TValue *o) { | |||
373 | } | 376 | } |
374 | else | 377 | else |
375 | return 0; /* conversion failed */ | 378 | return 0; /* conversion failed */ |
376 | return (e - s) + 1; /* success; return string size */ | 379 | return ct_diff2sz(e - s) + 1; /* success; return string size */ |
377 | } | 380 | } |
378 | 381 | ||
379 | 382 | ||
@@ -409,7 +412,7 @@ int luaO_utf8esc (char *buff, unsigned long x) { | |||
409 | /* | 412 | /* |
410 | ** Convert a number object to a string, adding it to a buffer | 413 | ** Convert a number object to a string, adding it to a buffer |
411 | */ | 414 | */ |
412 | static int tostringbuff (TValue *obj, char *buff) { | 415 | static unsigned tostringbuff (TValue *obj, char *buff) { |
413 | int len; | 416 | int len; |
414 | lua_assert(ttisnumber(obj)); | 417 | lua_assert(ttisnumber(obj)); |
415 | if (ttisinteger(obj)) | 418 | if (ttisinteger(obj)) |
@@ -421,7 +424,7 @@ static int tostringbuff (TValue *obj, char *buff) { | |||
421 | buff[len++] = '0'; /* adds '.0' to result */ | 424 | buff[len++] = '0'; /* adds '.0' to result */ |
422 | } | 425 | } |
423 | } | 426 | } |
424 | return len; | 427 | return cast_uint(len); |
425 | } | 428 | } |
426 | 429 | ||
427 | 430 | ||
@@ -430,7 +433,7 @@ static int tostringbuff (TValue *obj, char *buff) { | |||
430 | */ | 433 | */ |
431 | void luaO_tostring (lua_State *L, TValue *obj) { | 434 | void luaO_tostring (lua_State *L, TValue *obj) { |
432 | char buff[MAXNUMBER2STR]; | 435 | char buff[MAXNUMBER2STR]; |
433 | int len = tostringbuff(obj, buff); | 436 | unsigned len = tostringbuff(obj, buff); |
434 | setsvalue(L, obj, luaS_newlstr(L, buff, len)); | 437 | setsvalue(L, obj, luaS_newlstr(L, buff, len)); |
435 | } | 438 | } |
436 | 439 | ||
@@ -448,13 +451,13 @@ void luaO_tostring (lua_State *L, TValue *obj) { | |||
448 | ** (LUA_IDSIZE + MAXNUMBER2STR) + a minimal space for basic messages, | 451 | ** (LUA_IDSIZE + MAXNUMBER2STR) + a minimal space for basic messages, |
449 | ** so that 'luaG_addinfo' can work directly on the buffer. | 452 | ** so that 'luaG_addinfo' can work directly on the buffer. |
450 | */ | 453 | */ |
451 | #define BUFVFS (LUA_IDSIZE + MAXNUMBER2STR + 95) | 454 | #define BUFVFS cast_uint(LUA_IDSIZE + MAXNUMBER2STR + 95) |
452 | 455 | ||
453 | /* buffer used by 'luaO_pushvfstring' */ | 456 | /* buffer used by 'luaO_pushvfstring' */ |
454 | typedef struct BuffFS { | 457 | typedef struct BuffFS { |
455 | lua_State *L; | 458 | lua_State *L; |
456 | int pushed; /* true if there is a part of the result on the stack */ | 459 | int pushed; /* true if there is a part of the result on the stack */ |
457 | int blen; /* length of partial string in 'space' */ | 460 | unsigned blen; /* length of partial string in 'space' */ |
458 | char space[BUFVFS]; /* holds last part of the result */ | 461 | char space[BUFVFS]; /* holds last part of the result */ |
459 | } BuffFS; | 462 | } BuffFS; |
460 | 463 | ||
@@ -492,7 +495,7 @@ static void clearbuff (BuffFS *buff) { | |||
492 | ** Get a space of size 'sz' in the buffer. If buffer has not enough | 495 | ** Get a space of size 'sz' in the buffer. If buffer has not enough |
493 | ** space, empty it. 'sz' must fit in an empty buffer. | 496 | ** space, empty it. 'sz' must fit in an empty buffer. |
494 | */ | 497 | */ |
495 | static char *getbuff (BuffFS *buff, int sz) { | 498 | static char *getbuff (BuffFS *buff, unsigned sz) { |
496 | lua_assert(buff->blen <= BUFVFS); lua_assert(sz <= BUFVFS); | 499 | lua_assert(buff->blen <= BUFVFS); lua_assert(sz <= BUFVFS); |
497 | if (sz > BUFVFS - buff->blen) /* not enough space? */ | 500 | if (sz > BUFVFS - buff->blen) /* not enough space? */ |
498 | clearbuff(buff); | 501 | clearbuff(buff); |
@@ -509,9 +512,9 @@ static char *getbuff (BuffFS *buff, int sz) { | |||
509 | */ | 512 | */ |
510 | static void addstr2buff (BuffFS *buff, const char *str, size_t slen) { | 513 | static void addstr2buff (BuffFS *buff, const char *str, size_t slen) { |
511 | if (slen <= BUFVFS) { /* does string fit into buffer? */ | 514 | if (slen <= BUFVFS) { /* does string fit into buffer? */ |
512 | char *bf = getbuff(buff, cast_int(slen)); | 515 | char *bf = getbuff(buff, cast_uint(slen)); |
513 | memcpy(bf, str, slen); /* add string to buffer */ | 516 | memcpy(bf, str, slen); /* add string to buffer */ |
514 | addsize(buff, cast_int(slen)); | 517 | addsize(buff, cast_uint(slen)); |
515 | } | 518 | } |
516 | else { /* string larger than buffer */ | 519 | else { /* string larger than buffer */ |
517 | clearbuff(buff); /* string comes after buffer's content */ | 520 | clearbuff(buff); /* string comes after buffer's content */ |
@@ -525,7 +528,7 @@ static void addstr2buff (BuffFS *buff, const char *str, size_t slen) { | |||
525 | */ | 528 | */ |
526 | static void addnum2buff (BuffFS *buff, TValue *num) { | 529 | static void addnum2buff (BuffFS *buff, TValue *num) { |
527 | char *numbuff = getbuff(buff, MAXNUMBER2STR); | 530 | char *numbuff = getbuff(buff, MAXNUMBER2STR); |
528 | int len = tostringbuff(num, numbuff); /* format number into 'numbuff' */ | 531 | unsigned len = tostringbuff(num, numbuff); /* format number into 'numbuff' */ |
529 | addsize(buff, len); | 532 | addsize(buff, len); |
530 | } | 533 | } |
531 | 534 | ||
@@ -537,10 +540,10 @@ static void addnum2buff (BuffFS *buff, TValue *num) { | |||
537 | const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) { | 540 | const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) { |
538 | BuffFS buff; /* holds last part of the result */ | 541 | BuffFS buff; /* holds last part of the result */ |
539 | const char *e; /* points to next '%' */ | 542 | const char *e; /* points to next '%' */ |
540 | buff.pushed = buff.blen = 0; | 543 | buff.pushed = 0; buff.blen = 0; |
541 | buff.L = L; | 544 | buff.L = L; |
542 | while ((e = strchr(fmt, '%')) != NULL) { | 545 | while ((e = strchr(fmt, '%')) != NULL) { |
543 | addstr2buff(&buff, fmt, e - fmt); /* add 'fmt' up to '%' */ | 546 | addstr2buff(&buff, fmt, ct_diff2sz(e - fmt)); /* add 'fmt' up to '%' */ |
544 | switch (*(e + 1)) { /* conversion specifier */ | 547 | switch (*(e + 1)) { /* conversion specifier */ |
545 | case 's': { /* zero-terminated string */ | 548 | case 's': { /* zero-terminated string */ |
546 | const char *s = va_arg(argp, char *); | 549 | const char *s = va_arg(argp, char *); |
@@ -549,7 +552,7 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) { | |||
549 | break; | 552 | break; |
550 | } | 553 | } |
551 | case 'c': { /* an 'int' as a character */ | 554 | case 'c': { /* an 'int' as a character */ |
552 | char c = cast_uchar(va_arg(argp, int)); | 555 | char c = cast_char(va_arg(argp, int)); |
553 | addstr2buff(&buff, &c, sizeof(char)); | 556 | addstr2buff(&buff, &c, sizeof(char)); |
554 | break; | 557 | break; |
555 | } | 558 | } |
@@ -572,17 +575,17 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) { | |||
572 | break; | 575 | break; |
573 | } | 576 | } |
574 | case 'p': { /* a pointer */ | 577 | case 'p': { /* a pointer */ |
575 | const int sz = 3 * sizeof(void*) + 8; /* enough space for '%p' */ | 578 | const unsigned sz = 3 * sizeof(void*) + 8; /* enough space for '%p' */ |
576 | char *bf = getbuff(&buff, sz); | 579 | char *bf = getbuff(&buff, sz); |
577 | void *p = va_arg(argp, void *); | 580 | void *p = va_arg(argp, void *); |
578 | int len = lua_pointer2str(bf, sz, p); | 581 | int len = lua_pointer2str(bf, sz, p); |
579 | addsize(&buff, len); | 582 | addsize(&buff, cast_uint(len)); |
580 | break; | 583 | break; |
581 | } | 584 | } |
582 | case 'U': { /* a 'long' as a UTF-8 sequence */ | 585 | case 'U': { /* an 'unsigned long' as a UTF-8 sequence */ |
583 | char bf[UTF8BUFFSZ]; | 586 | char bf[UTF8BUFFSZ]; |
584 | int len = luaO_utf8esc(bf, va_arg(argp, long)); | 587 | int len = luaO_utf8esc(bf, va_arg(argp, unsigned long)); |
585 | addstr2buff(&buff, bf + UTF8BUFFSZ - len, len); | 588 | addstr2buff(&buff, bf + UTF8BUFFSZ - len, cast_uint(len)); |
586 | break; | 589 | break; |
587 | } | 590 | } |
588 | case '%': { | 591 | case '%': { |
@@ -648,7 +651,8 @@ void luaO_chunkid (char *out, const char *source, size_t srclen) { | |||
648 | addstr(out, source, srclen); /* keep it */ | 651 | addstr(out, source, srclen); /* keep it */ |
649 | } | 652 | } |
650 | else { | 653 | else { |
651 | if (nl != NULL) srclen = nl - source; /* stop at first newline */ | 654 | if (nl != NULL) |
655 | srclen = ct_diff2sz(nl - source); /* stop at first newline */ | ||
652 | if (srclen > bufflen) srclen = bufflen; | 656 | if (srclen > bufflen) srclen = bufflen; |
653 | addstr(out, source, srclen); | 657 | addstr(out, source, srclen); |
654 | addstr(out, RETS, LL(RETS)); | 658 | addstr(out, RETS, LL(RETS)); |
@@ -432,13 +432,13 @@ typedef struct TString { | |||
432 | 432 | ||
433 | /* get string length from 'TString *ts' */ | 433 | /* get string length from 'TString *ts' */ |
434 | #define tsslen(ts) \ | 434 | #define tsslen(ts) \ |
435 | (strisshr(ts) ? cast_uint((ts)->shrlen) : (ts)->u.lnglen) | 435 | (strisshr(ts) ? cast_sizet((ts)->shrlen) : (ts)->u.lnglen) |
436 | 436 | ||
437 | /* | 437 | /* |
438 | ** Get string and length */ | 438 | ** Get string and length */ |
439 | #define getlstr(ts, len) \ | 439 | #define getlstr(ts, len) \ |
440 | (strisshr(ts) \ | 440 | (strisshr(ts) \ |
441 | ? (cast_void((len) = (ts)->shrlen), rawgetshrstr(ts)) \ | 441 | ? (cast_void((len) = cast_sizet((ts)->shrlen)), rawgetshrstr(ts)) \ |
442 | : (cast_void((len) = (ts)->u.lnglen), (ts)->contents)) | 442 | : (cast_void((len) = (ts)->u.lnglen), (ts)->contents)) |
443 | 443 | ||
444 | /* }================================================================== */ | 444 | /* }================================================================== */ |
@@ -517,8 +517,8 @@ typedef struct Udata0 { | |||
517 | 517 | ||
518 | /* compute the offset of the memory area of a userdata */ | 518 | /* compute the offset of the memory area of a userdata */ |
519 | #define udatamemoffset(nuv) \ | 519 | #define udatamemoffset(nuv) \ |
520 | ((nuv) == 0 ? offsetof(Udata0, bindata) \ | 520 | ((nuv) == 0 ? offsetof(Udata0, bindata) \ |
521 | : offsetof(Udata, uv) + (sizeof(UValue) * (nuv))) | 521 | : offsetof(Udata, uv) + (sizeof(UValue) * (nuv))) |
522 | 522 | ||
523 | /* get the address of the memory block inside 'Udata' */ | 523 | /* get the address of the memory block inside 'Udata' */ |
524 | #define getudatamem(u) (cast_charp(u) + udatamemoffset((u)->nuvalue)) | 524 | #define getudatamem(u) (cast_charp(u) + udatamemoffset((u)->nuvalue)) |
@@ -825,10 +825,10 @@ typedef struct Table { | |||
825 | ** 'module' operation for hashing (size is always a power of 2) | 825 | ** 'module' operation for hashing (size is always a power of 2) |
826 | */ | 826 | */ |
827 | #define lmod(s,size) \ | 827 | #define lmod(s,size) \ |
828 | (check_exp((size&(size-1))==0, (cast_int((s) & ((size)-1))))) | 828 | (check_exp((size&(size-1))==0, (cast_uint(s) & cast_uint((size)-1)))) |
829 | 829 | ||
830 | 830 | ||
831 | #define twoto(x) (1<<(x)) | 831 | #define twoto(x) (1u<<(x)) |
832 | #define sizenode(t) (twoto((t)->lsizenode)) | 832 | #define sizenode(t) (twoto((t)->lsizenode)) |
833 | 833 | ||
834 | 834 | ||
@@ -836,16 +836,16 @@ typedef struct Table { | |||
836 | #define UTF8BUFFSZ 8 | 836 | #define UTF8BUFFSZ 8 |
837 | 837 | ||
838 | LUAI_FUNC int luaO_utf8esc (char *buff, unsigned long x); | 838 | LUAI_FUNC int luaO_utf8esc (char *buff, unsigned long x); |
839 | LUAI_FUNC int luaO_ceillog2 (unsigned int x); | 839 | LUAI_FUNC lu_byte luaO_ceillog2 (unsigned int x); |
840 | LUAI_FUNC unsigned int luaO_codeparam (unsigned int p); | 840 | LUAI_FUNC lu_byte luaO_codeparam (unsigned int p); |
841 | LUAI_FUNC l_obj luaO_applyparam (unsigned int p, l_obj x); | 841 | LUAI_FUNC l_obj luaO_applyparam (lu_byte p, l_obj x); |
842 | 842 | ||
843 | LUAI_FUNC int luaO_rawarith (lua_State *L, int op, const TValue *p1, | 843 | LUAI_FUNC int luaO_rawarith (lua_State *L, int op, const TValue *p1, |
844 | const TValue *p2, TValue *res); | 844 | const TValue *p2, TValue *res); |
845 | LUAI_FUNC void luaO_arith (lua_State *L, int op, const TValue *p1, | 845 | LUAI_FUNC void luaO_arith (lua_State *L, int op, const TValue *p1, |
846 | const TValue *p2, StkId res); | 846 | const TValue *p2, StkId res); |
847 | LUAI_FUNC size_t luaO_str2num (const char *s, TValue *o); | 847 | LUAI_FUNC size_t luaO_str2num (const char *s, TValue *o); |
848 | LUAI_FUNC int luaO_hexavalue (int c); | 848 | LUAI_FUNC lu_byte luaO_hexavalue (int c); |
849 | LUAI_FUNC void luaO_tostring (lua_State *L, TValue *obj); | 849 | LUAI_FUNC void luaO_tostring (lua_State *L, TValue *obj); |
850 | LUAI_FUNC const char *luaO_pushvfstring (lua_State *L, const char *fmt, | 850 | LUAI_FUNC const char *luaO_pushvfstring (lua_State *L, const char *fmt, |
851 | va_list argp); | 851 | va_list argp); |
@@ -72,8 +72,11 @@ enum OpMode {iABC, ivABC, iABx, iAsBx, iAx, isJ}; | |||
72 | ** so they must fit in ints. | 72 | ** so they must fit in ints. |
73 | */ | 73 | */ |
74 | 74 | ||
75 | /* Check whether type 'int' has at least 'b' bits ('b' < 32) */ | 75 | /* |
76 | #define L_INTHASBITS(b) ((UINT_MAX >> ((b) - 1)) >= 1) | 76 | ** Check whether type 'int' has at least 'b' + 1 bits. |
77 | ** 'b' < 32; +1 for the sign bit. | ||
78 | */ | ||
79 | #define L_INTHASBITS(b) ((UINT_MAX >> (b)) >= 1) | ||
77 | 80 | ||
78 | 81 | ||
79 | #if L_INTHASBITS(SIZE_Bx) | 82 | #if L_INTHASBITS(SIZE_Bx) |
@@ -275,7 +275,7 @@ static int getfield (lua_State *L, const char *key, int d, int delta) { | |||
275 | static const char *checkoption (lua_State *L, const char *conv, | 275 | static const char *checkoption (lua_State *L, const char *conv, |
276 | ptrdiff_t convlen, char *buff) { | 276 | ptrdiff_t convlen, char *buff) { |
277 | const char *option = LUA_STRFTIMEOPTIONS; | 277 | const char *option = LUA_STRFTIMEOPTIONS; |
278 | int oplen = 1; /* length of options being checked */ | 278 | unsigned oplen = 1; /* length of options being checked */ |
279 | for (; *option != '\0' && oplen <= convlen; option += oplen) { | 279 | for (; *option != '\0' && oplen <= convlen; option += oplen) { |
280 | if (*option == '|') /* next block? */ | 280 | if (*option == '|') /* next block? */ |
281 | oplen++; /* will check options with next length (+1) */ | 281 | oplen++; /* will check options with next length (+1) */ |
@@ -172,7 +172,8 @@ static void codename (LexState *ls, expdesc *e) { | |||
172 | ** Register a new local variable in the active 'Proto' (for debug | 172 | ** Register a new local variable in the active 'Proto' (for debug |
173 | ** information). | 173 | ** information). |
174 | */ | 174 | */ |
175 | static int registerlocalvar (LexState *ls, FuncState *fs, TString *varname) { | 175 | static short registerlocalvar (LexState *ls, FuncState *fs, |
176 | TString *varname) { | ||
176 | Proto *f = fs->f; | 177 | Proto *f = fs->f; |
177 | int oldsize = f->sizelocvars; | 178 | int oldsize = f->sizelocvars; |
178 | luaM_growvector(ls->L, f->locvars, fs->ndebugvars, f->sizelocvars, | 179 | luaM_growvector(ls->L, f->locvars, fs->ndebugvars, f->sizelocvars, |
@@ -190,7 +191,7 @@ static int registerlocalvar (LexState *ls, FuncState *fs, TString *varname) { | |||
190 | ** Create a new local variable with the given 'name' and given 'kind'. | 191 | ** Create a new local variable with the given 'name' and given 'kind'. |
191 | ** Return its index in the function. | 192 | ** Return its index in the function. |
192 | */ | 193 | */ |
193 | static int new_localvarkind (LexState *ls, TString *name, int kind) { | 194 | static int new_localvarkind (LexState *ls, TString *name, lu_byte kind) { |
194 | lua_State *L = ls->L; | 195 | lua_State *L = ls->L; |
195 | FuncState *fs = ls->fs; | 196 | FuncState *fs = ls->fs; |
196 | Dyndata *dyd = ls->dyd; | 197 | Dyndata *dyd = ls->dyd; |
@@ -234,11 +235,11 @@ static Vardesc *getlocalvardesc (FuncState *fs, int vidx) { | |||
234 | ** register. For that, search for the highest variable below that level | 235 | ** register. For that, search for the highest variable below that level |
235 | ** that is in a register and uses its register index ('ridx') plus one. | 236 | ** that is in a register and uses its register index ('ridx') plus one. |
236 | */ | 237 | */ |
237 | static int reglevel (FuncState *fs, int nvar) { | 238 | static lu_byte reglevel (FuncState *fs, int nvar) { |
238 | while (nvar-- > 0) { | 239 | while (nvar-- > 0) { |
239 | Vardesc *vd = getlocalvardesc(fs, nvar); /* get previous variable */ | 240 | Vardesc *vd = getlocalvardesc(fs, nvar); /* get previous variable */ |
240 | if (vd->vd.kind != RDKCTC) /* is in a register? */ | 241 | if (vd->vd.kind != RDKCTC) /* is in a register? */ |
241 | return vd->vd.ridx + 1; | 242 | return cast_byte(vd->vd.ridx + 1); |
242 | } | 243 | } |
243 | return 0; /* no variables in registers */ | 244 | return 0; /* no variables in registers */ |
244 | } | 245 | } |
@@ -248,7 +249,7 @@ static int reglevel (FuncState *fs, int nvar) { | |||
248 | ** Return the number of variables in the register stack for the given | 249 | ** Return the number of variables in the register stack for the given |
249 | ** function. | 250 | ** function. |
250 | */ | 251 | */ |
251 | int luaY_nvarstack (FuncState *fs) { | 252 | lu_byte luaY_nvarstack (FuncState *fs) { |
252 | return reglevel(fs, fs->nactvar); | 253 | return reglevel(fs, fs->nactvar); |
253 | } | 254 | } |
254 | 255 | ||
@@ -274,7 +275,7 @@ static LocVar *localdebuginfo (FuncState *fs, int vidx) { | |||
274 | static void init_var (FuncState *fs, expdesc *e, int vidx) { | 275 | static void init_var (FuncState *fs, expdesc *e, int vidx) { |
275 | e->f = e->t = NO_JUMP; | 276 | e->f = e->t = NO_JUMP; |
276 | e->k = VLOCAL; | 277 | e->k = VLOCAL; |
277 | e->u.var.vidx = vidx; | 278 | e->u.var.vidx = cast(unsigned short, vidx); |
278 | e->u.var.ridx = getlocalvardesc(fs, vidx)->vd.ridx; | 279 | e->u.var.ridx = getlocalvardesc(fs, vidx)->vd.ridx; |
279 | } | 280 | } |
280 | 281 | ||
@@ -323,7 +324,7 @@ static void adjustlocalvars (LexState *ls, int nvars) { | |||
323 | for (i = 0; i < nvars; i++) { | 324 | for (i = 0; i < nvars; i++) { |
324 | int vidx = fs->nactvar++; | 325 | int vidx = fs->nactvar++; |
325 | Vardesc *var = getlocalvardesc(fs, vidx); | 326 | Vardesc *var = getlocalvardesc(fs, vidx); |
326 | var->vd.ridx = reglevel++; | 327 | var->vd.ridx = cast_byte(reglevel++); |
327 | var->vd.pidx = registerlocalvar(ls, fs, var->vd.name); | 328 | var->vd.pidx = registerlocalvar(ls, fs, var->vd.name); |
328 | } | 329 | } |
329 | } | 330 | } |
@@ -505,7 +506,7 @@ static void adjust_assign (LexState *ls, int nvars, int nexps, expdesc *e) { | |||
505 | if (needed > 0) | 506 | if (needed > 0) |
506 | luaK_reserveregs(fs, needed); /* registers for extra values */ | 507 | luaK_reserveregs(fs, needed); /* registers for extra values */ |
507 | else /* adding 'needed' is actually a subtraction */ | 508 | else /* adding 'needed' is actually a subtraction */ |
508 | fs->freereg += needed; /* remove extra values */ | 509 | fs->freereg = cast_byte(fs->freereg + needed); /* remove extra values */ |
509 | } | 510 | } |
510 | 511 | ||
511 | 512 | ||
@@ -682,7 +683,7 @@ static void leaveblock (FuncState *fs) { | |||
682 | BlockCnt *bl = fs->bl; | 683 | BlockCnt *bl = fs->bl; |
683 | LexState *ls = fs->ls; | 684 | LexState *ls = fs->ls; |
684 | int hasclose = 0; | 685 | int hasclose = 0; |
685 | int stklevel = reglevel(fs, bl->nactvar); /* level outside the block */ | 686 | lu_byte stklevel = reglevel(fs, bl->nactvar); /* level outside the block */ |
686 | removevars(fs, bl->nactvar); /* remove block locals */ | 687 | removevars(fs, bl->nactvar); /* remove block locals */ |
687 | lua_assert(bl->nactvar == fs->nactvar); /* back to level on entry */ | 688 | lua_assert(bl->nactvar == fs->nactvar); /* back to level on entry */ |
688 | if (bl->isloop) /* has to fix pending breaks? */ | 689 | if (bl->isloop) /* has to fix pending breaks? */ |
@@ -856,7 +857,7 @@ typedef struct ConsControl { | |||
856 | static void recfield (LexState *ls, ConsControl *cc) { | 857 | static void recfield (LexState *ls, ConsControl *cc) { |
857 | /* recfield -> (NAME | '['exp']') = exp */ | 858 | /* recfield -> (NAME | '['exp']') = exp */ |
858 | FuncState *fs = ls->fs; | 859 | FuncState *fs = ls->fs; |
859 | int reg = ls->fs->freereg; | 860 | lu_byte reg = ls->fs->freereg; |
860 | expdesc tab, key, val; | 861 | expdesc tab, key, val; |
861 | if (ls->t.token == TK_NAME) { | 862 | if (ls->t.token == TK_NAME) { |
862 | checklimit(fs, cc->nh, INT_MAX, "items in a constructor"); | 863 | checklimit(fs, cc->nh, INT_MAX, "items in a constructor"); |
@@ -939,7 +940,7 @@ static void field (LexState *ls, ConsControl *cc) { | |||
939 | static int maxtostore (FuncState *fs) { | 940 | static int maxtostore (FuncState *fs) { |
940 | int numfreeregs = MAX_FSTACK - fs->freereg; | 941 | int numfreeregs = MAX_FSTACK - fs->freereg; |
941 | if (numfreeregs >= 160) /* "lots" of registers? */ | 942 | if (numfreeregs >= 160) /* "lots" of registers? */ |
942 | return numfreeregs / 5u; /* use up to 1/5 of them */ | 943 | return numfreeregs / 5; /* use up to 1/5 of them */ |
943 | else if (numfreeregs >= 80) /* still "enough" registers? */ | 944 | else if (numfreeregs >= 80) /* still "enough" registers? */ |
944 | return 10; /* one 'SETLIST' instruction for each 10 values */ | 945 | return 10; /* one 'SETLIST' instruction for each 10 values */ |
945 | else /* save registers for potential more nesting */ | 946 | else /* save registers for potential more nesting */ |
@@ -1090,8 +1091,9 @@ static void funcargs (LexState *ls, expdesc *f) { | |||
1090 | } | 1091 | } |
1091 | init_exp(f, VCALL, luaK_codeABC(fs, OP_CALL, base, nparams+1, 2)); | 1092 | init_exp(f, VCALL, luaK_codeABC(fs, OP_CALL, base, nparams+1, 2)); |
1092 | luaK_fixline(fs, line); | 1093 | luaK_fixline(fs, line); |
1093 | fs->freereg = base+1; /* call removes function and arguments and leaves | 1094 | /* call removes function and arguments and leaves one result (unless |
1094 | one result (unless changed later) */ | 1095 | changed later) */ |
1096 | fs->freereg = cast_byte(base + 1); | ||
1095 | } | 1097 | } |
1096 | 1098 | ||
1097 | 1099 | ||
@@ -1356,7 +1358,7 @@ struct LHS_assign { | |||
1356 | */ | 1358 | */ |
1357 | static void check_conflict (LexState *ls, struct LHS_assign *lh, expdesc *v) { | 1359 | static void check_conflict (LexState *ls, struct LHS_assign *lh, expdesc *v) { |
1358 | FuncState *fs = ls->fs; | 1360 | FuncState *fs = ls->fs; |
1359 | int extra = fs->freereg; /* eventual position to save local variable */ | 1361 | lu_byte extra = fs->freereg; /* eventual position to save local variable */ |
1360 | int conflict = 0; | 1362 | int conflict = 0; |
1361 | for (; lh; lh = lh->prev) { /* check all previous assignments */ | 1363 | for (; lh; lh = lh->prev) { /* check all previous assignments */ |
1362 | if (vkisindexed(lh->v.k)) { /* assignment to table field? */ | 1364 | if (vkisindexed(lh->v.k)) { /* assignment to table field? */ |
@@ -1723,7 +1725,7 @@ static void localfunc (LexState *ls) { | |||
1723 | } | 1725 | } |
1724 | 1726 | ||
1725 | 1727 | ||
1726 | static int getlocalattribute (LexState *ls) { | 1728 | static lu_byte getlocalattribute (LexState *ls) { |
1727 | /* ATTRIB -> ['<' Name '>'] */ | 1729 | /* ATTRIB -> ['<' Name '>'] */ |
1728 | if (testnext(ls, '<')) { | 1730 | if (testnext(ls, '<')) { |
1729 | TString *ts = str_checkname(ls); | 1731 | TString *ts = str_checkname(ls); |
@@ -1760,7 +1762,7 @@ static void localstat (LexState *ls) { | |||
1760 | expdesc e; | 1762 | expdesc e; |
1761 | do { | 1763 | do { |
1762 | TString *vname = str_checkname(ls); | 1764 | TString *vname = str_checkname(ls); |
1763 | int kind = getlocalattribute(ls); | 1765 | lu_byte kind = getlocalattribute(ls); |
1764 | vidx = new_localvarkind(ls, vname, kind); | 1766 | vidx = new_localvarkind(ls, vname, kind); |
1765 | if (kind == RDKTOCLOSE) { /* to-be-closed? */ | 1767 | if (kind == RDKTOCLOSE) { /* to-be-closed? */ |
1766 | if (toclose != -1) /* one already present? */ | 1768 | if (toclose != -1) /* one already present? */ |
@@ -163,7 +163,7 @@ typedef struct FuncState { | |||
163 | } FuncState; | 163 | } FuncState; |
164 | 164 | ||
165 | 165 | ||
166 | LUAI_FUNC int luaY_nvarstack (FuncState *fs); | 166 | LUAI_FUNC lu_byte luaY_nvarstack (FuncState *fs); |
167 | LUAI_FUNC LClosure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, | 167 | LUAI_FUNC LClosure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, |
168 | Dyndata *dyd, const char *name, int firstchar); | 168 | Dyndata *dyd, const char *name, int firstchar); |
169 | 169 | ||
@@ -190,7 +190,8 @@ static void freestack (lua_State *L) { | |||
190 | L->ci = &L->base_ci; /* free the entire 'ci' list */ | 190 | L->ci = &L->base_ci; /* free the entire 'ci' list */ |
191 | freeCI(L); | 191 | freeCI(L); |
192 | lua_assert(L->nci == 0); | 192 | lua_assert(L->nci == 0); |
193 | luaM_freearray(L, L->stack.p, stacksize(L) + EXTRA_STACK); /* free stack */ | 193 | /* free stack */ |
194 | luaM_freearray(L, L->stack.p, cast_sizet(stacksize(L) + EXTRA_STACK)); | ||
194 | } | 195 | } |
195 | 196 | ||
196 | 197 | ||
@@ -266,7 +267,7 @@ static void close_state (lua_State *L) { | |||
266 | luaC_freeallobjects(L); /* collect all objects */ | 267 | luaC_freeallobjects(L); /* collect all objects */ |
267 | luai_userstateclose(L); | 268 | luai_userstateclose(L); |
268 | } | 269 | } |
269 | luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size); | 270 | luaM_freearray(L, G(L)->strt.hash, cast_sizet(G(L)->strt.size)); |
270 | freestack(L); | 271 | freestack(L); |
271 | lua_assert(g->totalbytes == sizeof(LG)); | 272 | lua_assert(g->totalbytes == sizeof(LG)); |
272 | lua_assert(gettotalobjs(g) == 1); | 273 | lua_assert(gettotalobjs(g) == 1); |
@@ -259,7 +259,7 @@ struct CallInfo { | |||
259 | #define getcistrecst(ci) (((ci)->callstatus >> CIST_RECST) & 7) | 259 | #define getcistrecst(ci) (((ci)->callstatus >> CIST_RECST) & 7) |
260 | #define setcistrecst(ci,st) \ | 260 | #define setcistrecst(ci,st) \ |
261 | check_exp(((st) & 7) == (st), /* status must fit in three bits */ \ | 261 | check_exp(((st) & 7) == (st), /* status must fit in three bits */ \ |
262 | ((ci)->callstatus = ((ci)->callstatus & ~(7 << CIST_RECST)) \ | 262 | ((ci)->callstatus = ((ci)->callstatus & ~(7u << CIST_RECST)) \ |
263 | | (cast(l_uint32, st) << CIST_RECST))) | 263 | | (cast(l_uint32, st) << CIST_RECST))) |
264 | 264 | ||
265 | 265 | ||
@@ -164,7 +164,7 @@ size_t luaS_sizelngstr (size_t len, int kind) { | |||
164 | /* | 164 | /* |
165 | ** creates a new string object | 165 | ** creates a new string object |
166 | */ | 166 | */ |
167 | static TString *createstrobj (lua_State *L, size_t totalsize, int tag, | 167 | static TString *createstrobj (lua_State *L, size_t totalsize, lu_byte tag, |
168 | unsigned h) { | 168 | unsigned h) { |
169 | TString *ts; | 169 | TString *ts; |
170 | GCObject *o; | 170 | GCObject *o; |
@@ -233,7 +233,7 @@ static TString *internshrstr (lua_State *L, const char *str, size_t l) { | |||
233 | list = &tb->hash[lmod(h, tb->size)]; /* rehash with new size */ | 233 | list = &tb->hash[lmod(h, tb->size)]; /* rehash with new size */ |
234 | } | 234 | } |
235 | ts = createstrobj(L, sizestrshr(l), LUA_VSHRSTR, h); | 235 | ts = createstrobj(L, sizestrshr(l), LUA_VSHRSTR, h); |
236 | ts->shrlen = cast_byte(l); | 236 | ts->shrlen = cast(ls_byte, l); |
237 | getshrstr(ts)[l] = '\0'; /* ending 0 */ | 237 | getshrstr(ts)[l] = '\0'; /* ending 0 */ |
238 | memcpy(getshrstr(ts), str, l * sizeof(char)); | 238 | memcpy(getshrstr(ts), str, l * sizeof(char)); |
239 | ts->u.hnext = *list; | 239 | ts->u.hnext = *list; |
@@ -283,7 +283,7 @@ TString *luaS_new (lua_State *L, const char *str) { | |||
283 | } | 283 | } |
284 | 284 | ||
285 | 285 | ||
286 | Udata *luaS_newudata (lua_State *L, size_t s, int nuvalue) { | 286 | Udata *luaS_newudata (lua_State *L, size_t s, unsigned short nuvalue) { |
287 | Udata *u; | 287 | Udata *u; |
288 | int i; | 288 | int i; |
289 | GCObject *o; | 289 | GCObject *o; |
@@ -301,7 +301,7 @@ Udata *luaS_newudata (lua_State *L, size_t s, int nuvalue) { | |||
301 | 301 | ||
302 | 302 | ||
303 | struct NewExt { | 303 | struct NewExt { |
304 | int kind; | 304 | ls_byte kind; |
305 | const char *s; | 305 | const char *s; |
306 | size_t len; | 306 | size_t len; |
307 | TString *ts; /* output */ | 307 | TString *ts; /* output */ |
@@ -61,7 +61,8 @@ LUAI_FUNC void luaS_resize (lua_State *L, int newsize); | |||
61 | LUAI_FUNC void luaS_clearcache (global_State *g); | 61 | LUAI_FUNC void luaS_clearcache (global_State *g); |
62 | LUAI_FUNC void luaS_init (lua_State *L); | 62 | LUAI_FUNC void luaS_init (lua_State *L); |
63 | LUAI_FUNC void luaS_remove (lua_State *L, TString *ts); | 63 | LUAI_FUNC void luaS_remove (lua_State *L, TString *ts); |
64 | LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, int nuvalue); | 64 | LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, |
65 | unsigned short nuvalue); | ||
65 | LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l); | 66 | LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l); |
66 | LUAI_FUNC TString *luaS_new (lua_State *L, const char *str); | 67 | LUAI_FUNC TString *luaS_new (lua_State *L, const char *str); |
67 | LUAI_FUNC TString *luaS_createlngstrobj (lua_State *L, size_t l); | 68 | LUAI_FUNC TString *luaS_createlngstrobj (lua_State *L, size_t l); |
@@ -113,7 +113,7 @@ static int str_lower (lua_State *L) { | |||
113 | const char *s = luaL_checklstring(L, 1, &l); | 113 | const char *s = luaL_checklstring(L, 1, &l); |
114 | char *p = luaL_buffinitsize(L, &b, l); | 114 | char *p = luaL_buffinitsize(L, &b, l); |
115 | for (i=0; i<l; i++) | 115 | for (i=0; i<l; i++) |
116 | p[i] = tolower(cast_uchar(s[i])); | 116 | p[i] = cast_char(tolower(cast_uchar(s[i]))); |
117 | luaL_pushresultsize(&b, l); | 117 | luaL_pushresultsize(&b, l); |
118 | return 1; | 118 | return 1; |
119 | } | 119 | } |
@@ -126,7 +126,7 @@ static int str_upper (lua_State *L) { | |||
126 | const char *s = luaL_checklstring(L, 1, &l); | 126 | const char *s = luaL_checklstring(L, 1, &l); |
127 | char *p = luaL_buffinitsize(L, &b, l); | 127 | char *p = luaL_buffinitsize(L, &b, l); |
128 | for (i=0; i<l; i++) | 128 | for (i=0; i<l; i++) |
129 | p[i] = toupper(cast_uchar(s[i])); | 129 | p[i] = cast_char(toupper(cast_uchar(s[i]))); |
130 | luaL_pushresultsize(&b, l); | 130 | luaL_pushresultsize(&b, l); |
131 | return 1; | 131 | return 1; |
132 | } | 132 | } |
@@ -139,7 +139,7 @@ static int str_rep (lua_State *L) { | |||
139 | const char *sep = luaL_optlstring(L, 3, "", &lsep); | 139 | const char *sep = luaL_optlstring(L, 3, "", &lsep); |
140 | if (n <= 0) | 140 | if (n <= 0) |
141 | lua_pushliteral(L, ""); | 141 | lua_pushliteral(L, ""); |
142 | else if (l_unlikely(l + lsep < l || l + lsep > MAX_SIZE / n)) | 142 | else if (l_unlikely(l + lsep < l || l + lsep > MAX_SIZE / cast_sizet(n))) |
143 | return luaL_error(L, "resulting string too large"); | 143 | return luaL_error(L, "resulting string too large"); |
144 | else { | 144 | else { |
145 | size_t totallen = ((size_t)n * (l + lsep)) - lsep; | 145 | size_t totallen = ((size_t)n * (l + lsep)) - lsep; |
@@ -172,7 +172,7 @@ static int str_byte (lua_State *L) { | |||
172 | n = (int)(pose - posi) + 1; | 172 | n = (int)(pose - posi) + 1; |
173 | luaL_checkstack(L, n, "string slice too long"); | 173 | luaL_checkstack(L, n, "string slice too long"); |
174 | for (i=0; i<n; i++) | 174 | for (i=0; i<n; i++) |
175 | lua_pushinteger(L, cast_uchar(s[posi+i-1])); | 175 | lua_pushinteger(L, cast_uchar(s[posi + cast_uint(i) - 1])); |
176 | return n; | 176 | return n; |
177 | } | 177 | } |
178 | 178 | ||
@@ -181,13 +181,13 @@ static int str_char (lua_State *L) { | |||
181 | int n = lua_gettop(L); /* number of arguments */ | 181 | int n = lua_gettop(L); /* number of arguments */ |
182 | int i; | 182 | int i; |
183 | luaL_Buffer b; | 183 | luaL_Buffer b; |
184 | char *p = luaL_buffinitsize(L, &b, n); | 184 | char *p = luaL_buffinitsize(L, &b, cast_uint(n)); |
185 | for (i=1; i<=n; i++) { | 185 | for (i=1; i<=n; i++) { |
186 | lua_Unsigned c = (lua_Unsigned)luaL_checkinteger(L, i); | 186 | lua_Unsigned c = (lua_Unsigned)luaL_checkinteger(L, i); |
187 | luaL_argcheck(L, c <= (lua_Unsigned)UCHAR_MAX, i, "value out of range"); | 187 | luaL_argcheck(L, c <= (lua_Unsigned)UCHAR_MAX, i, "value out of range"); |
188 | p[i - 1] = cast_uchar(c); | 188 | p[i - 1] = cast_char(cast_uchar(c)); |
189 | } | 189 | } |
190 | luaL_pushresultsize(&b, n); | 190 | luaL_pushresultsize(&b, cast_uint(n)); |
191 | return 1; | 191 | return 1; |
192 | } | 192 | } |
193 | 193 | ||
@@ -352,10 +352,10 @@ typedef struct MatchState { | |||
352 | const char *p_end; /* end ('\0') of pattern */ | 352 | const char *p_end; /* end ('\0') of pattern */ |
353 | lua_State *L; | 353 | lua_State *L; |
354 | int matchdepth; /* control for recursive depth (to avoid C stack overflow) */ | 354 | int matchdepth; /* control for recursive depth (to avoid C stack overflow) */ |
355 | unsigned char level; /* total number of captures (finished or unfinished) */ | 355 | int level; /* total number of captures (finished or unfinished) */ |
356 | struct { | 356 | struct { |
357 | const char *init; | 357 | const char *init; |
358 | ptrdiff_t len; | 358 | ptrdiff_t len; /* length or special value (CAP_*) */ |
359 | } capture[LUA_MAXCAPTURES]; | 359 | } capture[LUA_MAXCAPTURES]; |
360 | } MatchState; | 360 | } MatchState; |
361 | 361 | ||
@@ -550,7 +550,7 @@ static const char *end_capture (MatchState *ms, const char *s, | |||
550 | static const char *match_capture (MatchState *ms, const char *s, int l) { | 550 | static const char *match_capture (MatchState *ms, const char *s, int l) { |
551 | size_t len; | 551 | size_t len; |
552 | l = check_capture(ms, l); | 552 | l = check_capture(ms, l); |
553 | len = ms->capture[l].len; | 553 | len = cast_sizet(ms->capture[l].len); |
554 | if ((size_t)(ms->src_end-s) >= len && | 554 | if ((size_t)(ms->src_end-s) >= len && |
555 | memcmp(ms->capture[l].init, s, len) == 0) | 555 | memcmp(ms->capture[l].init, s, len) == 0) |
556 | return s+len; | 556 | return s+len; |
@@ -674,7 +674,7 @@ static const char *lmemfind (const char *s1, size_t l1, | |||
674 | if (memcmp(init, s2+1, l2) == 0) | 674 | if (memcmp(init, s2+1, l2) == 0) |
675 | return init-1; | 675 | return init-1; |
676 | else { /* correct 'l1' and 's1' to try again */ | 676 | else { /* correct 'l1' and 's1' to try again */ |
677 | l1 -= init-s1; | 677 | l1 -= ct_diff2sz(init - s1); |
678 | s1 = init; | 678 | s1 = init; |
679 | } | 679 | } |
680 | } | 680 | } |
@@ -690,13 +690,13 @@ static const char *lmemfind (const char *s1, size_t l1, | |||
690 | ** its length and put its address in '*cap'. If it is an integer | 690 | ** its length and put its address in '*cap'. If it is an integer |
691 | ** (a position), push it on the stack and return CAP_POSITION. | 691 | ** (a position), push it on the stack and return CAP_POSITION. |
692 | */ | 692 | */ |
693 | static size_t get_onecapture (MatchState *ms, int i, const char *s, | 693 | static ptrdiff_t get_onecapture (MatchState *ms, int i, const char *s, |
694 | const char *e, const char **cap) { | 694 | const char *e, const char **cap) { |
695 | if (i >= ms->level) { | 695 | if (i >= ms->level) { |
696 | if (l_unlikely(i != 0)) | 696 | if (l_unlikely(i != 0)) |
697 | luaL_error(ms->L, "invalid capture index %%%d", i + 1); | 697 | luaL_error(ms->L, "invalid capture index %%%d", i + 1); |
698 | *cap = s; | 698 | *cap = s; |
699 | return e - s; | 699 | return (e - s); |
700 | } | 700 | } |
701 | else { | 701 | else { |
702 | ptrdiff_t capl = ms->capture[i].len; | 702 | ptrdiff_t capl = ms->capture[i].len; |
@@ -718,7 +718,7 @@ static void push_onecapture (MatchState *ms, int i, const char *s, | |||
718 | const char *cap; | 718 | const char *cap; |
719 | ptrdiff_t l = get_onecapture(ms, i, s, e, &cap); | 719 | ptrdiff_t l = get_onecapture(ms, i, s, e, &cap); |
720 | if (l != CAP_POSITION) | 720 | if (l != CAP_POSITION) |
721 | lua_pushlstring(ms->L, cap, l); | 721 | lua_pushlstring(ms->L, cap, cast_sizet(l)); |
722 | /* else position was already pushed */ | 722 | /* else position was already pushed */ |
723 | } | 723 | } |
724 | 724 | ||
@@ -776,7 +776,7 @@ static int str_find_aux (lua_State *L, int find) { | |||
776 | const char *s2 = lmemfind(s + init, ls - init, p, lp); | 776 | const char *s2 = lmemfind(s + init, ls - init, p, lp); |
777 | if (s2) { | 777 | if (s2) { |
778 | lua_pushinteger(L, (s2 - s) + 1); | 778 | lua_pushinteger(L, (s2 - s) + 1); |
779 | lua_pushinteger(L, (s2 - s) + lp); | 779 | lua_pushinteger(L, cast_st2S(ct_diff2sz(s2 - s) + lp)); |
780 | return 2; | 780 | return 2; |
781 | } | 781 | } |
782 | } | 782 | } |
@@ -866,23 +866,23 @@ static void add_s (MatchState *ms, luaL_Buffer *b, const char *s, | |||
866 | const char *news = lua_tolstring(L, 3, &l); | 866 | const char *news = lua_tolstring(L, 3, &l); |
867 | const char *p; | 867 | const char *p; |
868 | while ((p = (char *)memchr(news, L_ESC, l)) != NULL) { | 868 | while ((p = (char *)memchr(news, L_ESC, l)) != NULL) { |
869 | luaL_addlstring(b, news, p - news); | 869 | luaL_addlstring(b, news, ct_diff2sz(p - news)); |
870 | p++; /* skip ESC */ | 870 | p++; /* skip ESC */ |
871 | if (*p == L_ESC) /* '%%' */ | 871 | if (*p == L_ESC) /* '%%' */ |
872 | luaL_addchar(b, *p); | 872 | luaL_addchar(b, *p); |
873 | else if (*p == '0') /* '%0' */ | 873 | else if (*p == '0') /* '%0' */ |
874 | luaL_addlstring(b, s, e - s); | 874 | luaL_addlstring(b, s, ct_diff2sz(e - s)); |
875 | else if (isdigit(cast_uchar(*p))) { /* '%n' */ | 875 | else if (isdigit(cast_uchar(*p))) { /* '%n' */ |
876 | const char *cap; | 876 | const char *cap; |
877 | ptrdiff_t resl = get_onecapture(ms, *p - '1', s, e, &cap); | 877 | ptrdiff_t resl = get_onecapture(ms, *p - '1', s, e, &cap); |
878 | if (resl == CAP_POSITION) | 878 | if (resl == CAP_POSITION) |
879 | luaL_addvalue(b); /* add position to accumulated result */ | 879 | luaL_addvalue(b); /* add position to accumulated result */ |
880 | else | 880 | else |
881 | luaL_addlstring(b, cap, resl); | 881 | luaL_addlstring(b, cap, cast_sizet(resl)); |
882 | } | 882 | } |
883 | else | 883 | else |
884 | luaL_error(L, "invalid use of '%c' in replacement string", L_ESC); | 884 | luaL_error(L, "invalid use of '%c' in replacement string", L_ESC); |
885 | l -= p + 1 - news; | 885 | l -= ct_diff2sz(p + 1 - news); |
886 | news = p + 1; | 886 | news = p + 1; |
887 | } | 887 | } |
888 | luaL_addlstring(b, news, l); | 888 | luaL_addlstring(b, news, l); |
@@ -917,7 +917,7 @@ static int add_value (MatchState *ms, luaL_Buffer *b, const char *s, | |||
917 | } | 917 | } |
918 | if (!lua_toboolean(L, -1)) { /* nil or false? */ | 918 | if (!lua_toboolean(L, -1)) { /* nil or false? */ |
919 | lua_pop(L, 1); /* remove value */ | 919 | lua_pop(L, 1); /* remove value */ |
920 | luaL_addlstring(b, s, e - s); /* keep original text */ | 920 | luaL_addlstring(b, s, ct_diff2sz(e - s)); /* keep original text */ |
921 | return 0; /* no changes */ | 921 | return 0; /* no changes */ |
922 | } | 922 | } |
923 | else if (l_unlikely(!lua_isstring(L, -1))) | 923 | else if (l_unlikely(!lua_isstring(L, -1))) |
@@ -936,7 +936,8 @@ static int str_gsub (lua_State *L) { | |||
936 | const char *p = luaL_checklstring(L, 2, &lp); /* pattern */ | 936 | const char *p = luaL_checklstring(L, 2, &lp); /* pattern */ |
937 | const char *lastmatch = NULL; /* end of last match */ | 937 | const char *lastmatch = NULL; /* end of last match */ |
938 | int tr = lua_type(L, 3); /* replacement type */ | 938 | int tr = lua_type(L, 3); /* replacement type */ |
939 | lua_Integer max_s = luaL_optinteger(L, 4, srcl + 1); /* max replacements */ | 939 | /* max replacements */ |
940 | lua_Integer max_s = luaL_optinteger(L, 4, cast_st2S(srcl) + 1); | ||
940 | int anchor = (*p == '^'); | 941 | int anchor = (*p == '^'); |
941 | lua_Integer n = 0; /* replacement count */ | 942 | lua_Integer n = 0; /* replacement count */ |
942 | int changed = 0; /* change flag */ | 943 | int changed = 0; /* change flag */ |
@@ -966,7 +967,7 @@ static int str_gsub (lua_State *L) { | |||
966 | if (!changed) /* no changes? */ | 967 | if (!changed) /* no changes? */ |
967 | lua_pushvalue(L, 1); /* return original string */ | 968 | lua_pushvalue(L, 1); /* return original string */ |
968 | else { /* something changed */ | 969 | else { /* something changed */ |
969 | luaL_addlstring(&b, src, ms.src_end-src); | 970 | luaL_addlstring(&b, src, ct_diff2sz(ms.src_end - src)); |
970 | luaL_pushresult(&b); /* create and return new string */ | 971 | luaL_pushresult(&b); /* create and return new string */ |
971 | } | 972 | } |
972 | lua_pushinteger(L, n); /* number of substitutions */ | 973 | lua_pushinteger(L, n); /* number of substitutions */ |
@@ -1004,15 +1005,15 @@ static int str_gsub (lua_State *L) { | |||
1004 | /* | 1005 | /* |
1005 | ** Add integer part of 'x' to buffer and return new 'x' | 1006 | ** Add integer part of 'x' to buffer and return new 'x' |
1006 | */ | 1007 | */ |
1007 | static lua_Number adddigit (char *buff, int n, lua_Number x) { | 1008 | static lua_Number adddigit (char *buff, unsigned n, lua_Number x) { |
1008 | lua_Number dd = l_mathop(floor)(x); /* get integer part from 'x' */ | 1009 | lua_Number dd = l_mathop(floor)(x); /* get integer part from 'x' */ |
1009 | int d = (int)dd; | 1010 | int d = (int)dd; |
1010 | buff[n] = (d < 10 ? d + '0' : d - 10 + 'a'); /* add to buffer */ | 1011 | buff[n] = cast_char(d < 10 ? d + '0' : d - 10 + 'a'); /* add to buffer */ |
1011 | return x - dd; /* return what is left */ | 1012 | return x - dd; /* return what is left */ |
1012 | } | 1013 | } |
1013 | 1014 | ||
1014 | 1015 | ||
1015 | static int num2straux (char *buff, int sz, lua_Number x) { | 1016 | static int num2straux (char *buff, unsigned sz, lua_Number x) { |
1016 | /* if 'inf' or 'NaN', format it like '%g' */ | 1017 | /* if 'inf' or 'NaN', format it like '%g' */ |
1017 | if (x != x || x == (lua_Number)HUGE_VAL || x == -(lua_Number)HUGE_VAL) | 1018 | if (x != x || x == (lua_Number)HUGE_VAL || x == -(lua_Number)HUGE_VAL) |
1018 | return l_sprintf(buff, sz, LUA_NUMBER_FMT, (LUAI_UACNUMBER)x); | 1019 | return l_sprintf(buff, sz, LUA_NUMBER_FMT, (LUAI_UACNUMBER)x); |
@@ -1023,7 +1024,7 @@ static int num2straux (char *buff, int sz, lua_Number x) { | |||
1023 | else { | 1024 | else { |
1024 | int e; | 1025 | int e; |
1025 | lua_Number m = l_mathop(frexp)(x, &e); /* 'x' fraction and exponent */ | 1026 | lua_Number m = l_mathop(frexp)(x, &e); /* 'x' fraction and exponent */ |
1026 | int n = 0; /* character count */ | 1027 | unsigned n = 0; /* character count */ |
1027 | if (m < 0) { /* is number negative? */ | 1028 | if (m < 0) { /* is number negative? */ |
1028 | buff[n++] = '-'; /* add sign */ | 1029 | buff[n++] = '-'; /* add sign */ |
1029 | m = -m; /* make it positive */ | 1030 | m = -m; /* make it positive */ |
@@ -1037,20 +1038,20 @@ static int num2straux (char *buff, int sz, lua_Number x) { | |||
1037 | m = adddigit(buff, n++, m * 16); | 1038 | m = adddigit(buff, n++, m * 16); |
1038 | } while (m > 0); | 1039 | } while (m > 0); |
1039 | } | 1040 | } |
1040 | n += l_sprintf(buff + n, sz - n, "p%+d", e); /* add exponent */ | 1041 | n += cast_uint(l_sprintf(buff + n, sz - n, "p%+d", e)); /* add exponent */ |
1041 | lua_assert(n < sz); | 1042 | lua_assert(n < sz); |
1042 | return n; | 1043 | return cast_int(n); |
1043 | } | 1044 | } |
1044 | } | 1045 | } |
1045 | 1046 | ||
1046 | 1047 | ||
1047 | static int lua_number2strx (lua_State *L, char *buff, int sz, | 1048 | static int lua_number2strx (lua_State *L, char *buff, unsigned sz, |
1048 | const char *fmt, lua_Number x) { | 1049 | const char *fmt, lua_Number x) { |
1049 | int n = num2straux(buff, sz, x); | 1050 | int n = num2straux(buff, sz, x); |
1050 | if (fmt[SIZELENMOD] == 'A') { | 1051 | if (fmt[SIZELENMOD] == 'A') { |
1051 | int i; | 1052 | int i; |
1052 | for (i = 0; i < n; i++) | 1053 | for (i = 0; i < n; i++) |
1053 | buff[i] = toupper(cast_uchar(buff[i])); | 1054 | buff[i] = cast_char(toupper(cast_uchar(buff[i]))); |
1054 | } | 1055 | } |
1055 | else if (l_unlikely(fmt[SIZELENMOD] != 'a')) | 1056 | else if (l_unlikely(fmt[SIZELENMOD] != 'a')) |
1056 | return luaL_error(L, "modifiers for format '%%a'/'%%A' not implemented"); | 1057 | return luaL_error(L, "modifiers for format '%%a'/'%%A' not implemented"); |
@@ -1151,9 +1152,9 @@ static int quotefloat (lua_State *L, char *buff, lua_Number n) { | |||
1151 | int nb = lua_number2strx(L, buff, MAX_ITEM, | 1152 | int nb = lua_number2strx(L, buff, MAX_ITEM, |
1152 | "%" LUA_NUMBER_FRMLEN "a", n); | 1153 | "%" LUA_NUMBER_FRMLEN "a", n); |
1153 | /* ensures that 'buff' string uses a dot as the radix character */ | 1154 | /* ensures that 'buff' string uses a dot as the radix character */ |
1154 | if (memchr(buff, '.', nb) == NULL) { /* no dot? */ | 1155 | if (memchr(buff, '.', cast_uint(nb)) == NULL) { /* no dot? */ |
1155 | char point = lua_getlocaledecpoint(); /* try locale point */ | 1156 | char point = lua_getlocaledecpoint(); /* try locale point */ |
1156 | char *ppoint = (char *)memchr(buff, point, nb); | 1157 | char *ppoint = (char *)memchr(buff, point, cast_uint(nb)); |
1157 | if (ppoint) *ppoint = '.'; /* change it to a dot */ | 1158 | if (ppoint) *ppoint = '.'; /* change it to a dot */ |
1158 | } | 1159 | } |
1159 | return nb; | 1160 | return nb; |
@@ -1183,7 +1184,7 @@ static void addliteral (lua_State *L, luaL_Buffer *b, int arg) { | |||
1183 | : LUA_INTEGER_FMT; /* else use default format */ | 1184 | : LUA_INTEGER_FMT; /* else use default format */ |
1184 | nb = l_sprintf(buff, MAX_ITEM, format, (LUAI_UACINT)n); | 1185 | nb = l_sprintf(buff, MAX_ITEM, format, (LUAI_UACINT)n); |
1185 | } | 1186 | } |
1186 | luaL_addsize(b, nb); | 1187 | luaL_addsize(b, cast_uint(nb)); |
1187 | break; | 1188 | break; |
1188 | } | 1189 | } |
1189 | case LUA_TNIL: case LUA_TBOOLEAN: { | 1190 | case LUA_TNIL: case LUA_TBOOLEAN: { |
@@ -1277,7 +1278,7 @@ static int str_format (lua_State *L) { | |||
1277 | luaL_addchar(&b, *strfrmt++); /* %% */ | 1278 | luaL_addchar(&b, *strfrmt++); /* %% */ |
1278 | else { /* format item */ | 1279 | else { /* format item */ |
1279 | char form[MAX_FORMAT]; /* to store the format ('%...') */ | 1280 | char form[MAX_FORMAT]; /* to store the format ('%...') */ |
1280 | int maxitem = MAX_ITEM; /* maximum length for the result */ | 1281 | unsigned maxitem = MAX_ITEM; /* maximum length for the result */ |
1281 | char *buff = luaL_prepbuffsize(&b, maxitem); /* to put result */ | 1282 | char *buff = luaL_prepbuffsize(&b, maxitem); /* to put result */ |
1282 | int nb = 0; /* number of bytes in result */ | 1283 | int nb = 0; /* number of bytes in result */ |
1283 | if (++arg > top) | 1284 | if (++arg > top) |
@@ -1360,8 +1361,8 @@ static int str_format (lua_State *L) { | |||
1360 | return luaL_error(L, "invalid conversion '%s' to 'format'", form); | 1361 | return luaL_error(L, "invalid conversion '%s' to 'format'", form); |
1361 | } | 1362 | } |
1362 | } | 1363 | } |
1363 | lua_assert(nb < maxitem); | 1364 | lua_assert(cast_uint(nb) < maxitem); |
1364 | luaL_addsize(&b, nb); | 1365 | luaL_addsize(&b, cast_uint(nb)); |
1365 | } | 1366 | } |
1366 | } | 1367 | } |
1367 | luaL_pushresult(&b); | 1368 | luaL_pushresult(&b); |
@@ -1409,7 +1410,7 @@ static const union { | |||
1409 | typedef struct Header { | 1410 | typedef struct Header { |
1410 | lua_State *L; | 1411 | lua_State *L; |
1411 | int islittle; | 1412 | int islittle; |
1412 | int maxalign; | 1413 | unsigned maxalign; |
1413 | } Header; | 1414 | } Header; |
1414 | 1415 | ||
1415 | 1416 | ||
@@ -1443,7 +1444,7 @@ static size_t getnum (const char **fmt, size_t df) { | |||
1443 | else { | 1444 | else { |
1444 | size_t a = 0; | 1445 | size_t a = 0; |
1445 | do { | 1446 | do { |
1446 | a = a*10 + (*((*fmt)++) - '0'); | 1447 | a = a*10 + cast_uint(*((*fmt)++) - '0'); |
1447 | } while (digit(**fmt) && a <= (MAX_SIZE - 9)/10); | 1448 | } while (digit(**fmt) && a <= (MAX_SIZE - 9)/10); |
1448 | return a; | 1449 | return a; |
1449 | } | 1450 | } |
@@ -1454,12 +1455,12 @@ static size_t getnum (const char **fmt, size_t df) { | |||
1454 | ** Read an integer numeral and raises an error if it is larger | 1455 | ** Read an integer numeral and raises an error if it is larger |
1455 | ** than the maximum size of integers. | 1456 | ** than the maximum size of integers. |
1456 | */ | 1457 | */ |
1457 | static int getnumlimit (Header *h, const char **fmt, int df) { | 1458 | static unsigned getnumlimit (Header *h, const char **fmt, size_t df) { |
1458 | size_t sz = getnum(fmt, df); | 1459 | size_t sz = getnum(fmt, df); |
1459 | if (l_unlikely((sz - 1u) >= MAXINTSIZE)) | 1460 | if (l_unlikely((sz - 1u) >= MAXINTSIZE)) |
1460 | return luaL_error(h->L, "integral size (%d) out of limits [1,%d]", | 1461 | return cast_uint(luaL_error(h->L, |
1461 | sz, MAXINTSIZE); | 1462 | "integral size (%d) out of limits [1,%d]", sz, MAXINTSIZE)); |
1462 | return cast_int(sz); | 1463 | return cast_uint(sz); |
1463 | } | 1464 | } |
1464 | 1465 | ||
1465 | 1466 | ||
@@ -1510,7 +1511,7 @@ static KOption getoption (Header *h, const char **fmt, size_t *size) { | |||
1510 | case '>': h->islittle = 0; break; | 1511 | case '>': h->islittle = 0; break; |
1511 | case '=': h->islittle = nativeendian.little; break; | 1512 | case '=': h->islittle = nativeendian.little; break; |
1512 | case '!': { | 1513 | case '!': { |
1513 | const int maxalign = offsetof(struct cD, u); | 1514 | const size_t maxalign = offsetof(struct cD, u); |
1514 | h->maxalign = getnumlimit(h, fmt, maxalign); | 1515 | h->maxalign = getnumlimit(h, fmt, maxalign); |
1515 | break; | 1516 | break; |
1516 | } | 1517 | } |
@@ -1529,8 +1530,8 @@ static KOption getoption (Header *h, const char **fmt, size_t *size) { | |||
1529 | ** the maximum alignment ('maxalign'). Kchar option needs no alignment | 1530 | ** the maximum alignment ('maxalign'). Kchar option needs no alignment |
1530 | ** despite its size. | 1531 | ** despite its size. |
1531 | */ | 1532 | */ |
1532 | static KOption getdetails (Header *h, size_t totalsize, | 1533 | static KOption getdetails (Header *h, size_t totalsize, const char **fmt, |
1533 | const char **fmt, size_t *psize, int *ntoalign) { | 1534 | size_t *psize, unsigned *ntoalign) { |
1534 | KOption opt = getoption(h, fmt, psize); | 1535 | KOption opt = getoption(h, fmt, psize); |
1535 | size_t align = *psize; /* usually, alignment follows size */ | 1536 | size_t align = *psize; /* usually, alignment follows size */ |
1536 | if (opt == Kpaddalign) { /* 'X' gets alignment from following option */ | 1537 | if (opt == Kpaddalign) { /* 'X' gets alignment from following option */ |
@@ -1540,11 +1541,15 @@ static KOption getdetails (Header *h, size_t totalsize, | |||
1540 | if (align <= 1 || opt == Kchar) /* need no alignment? */ | 1541 | if (align <= 1 || opt == Kchar) /* need no alignment? */ |
1541 | *ntoalign = 0; | 1542 | *ntoalign = 0; |
1542 | else { | 1543 | else { |
1543 | if (align > cast_sizet(h->maxalign)) /* enforce maximum alignment */ | 1544 | if (align > h->maxalign) /* enforce maximum alignment */ |
1544 | align = h->maxalign; | 1545 | align = h->maxalign; |
1545 | if (l_unlikely(!ispow2(align))) /* not a power of 2? */ | 1546 | if (l_unlikely(!ispow2(align))) /* not a power of 2? */ |
1546 | luaL_argerror(h->L, 1, "format asks for alignment not power of 2"); | 1547 | luaL_argerror(h->L, 1, "format asks for alignment not power of 2"); |
1547 | *ntoalign = (align - (int)(totalsize & (align - 1))) & (align - 1); | 1548 | else { |
1549 | /* 'szmoda' = totalsize % align */ | ||
1550 | unsigned szmoda = cast_uint(totalsize & (align - 1)); | ||
1551 | *ntoalign = cast_uint((align - szmoda) & (align - 1)); | ||
1552 | } | ||
1548 | } | 1553 | } |
1549 | return opt; | 1554 | return opt; |
1550 | } | 1555 | } |
@@ -1557,9 +1562,9 @@ static KOption getdetails (Header *h, size_t totalsize, | |||
1557 | ** bytes if necessary (by default they would be zeros). | 1562 | ** bytes if necessary (by default they would be zeros). |
1558 | */ | 1563 | */ |
1559 | static void packint (luaL_Buffer *b, lua_Unsigned n, | 1564 | static void packint (luaL_Buffer *b, lua_Unsigned n, |
1560 | int islittle, int size, int neg) { | 1565 | int islittle, unsigned size, int neg) { |
1561 | char *buff = luaL_prepbuffsize(b, size); | 1566 | char *buff = luaL_prepbuffsize(b, size); |
1562 | int i; | 1567 | unsigned i; |
1563 | buff[islittle ? 0 : size - 1] = (char)(n & MC); /* first byte */ | 1568 | buff[islittle ? 0 : size - 1] = (char)(n & MC); /* first byte */ |
1564 | for (i = 1; i < size; i++) { | 1569 | for (i = 1; i < size; i++) { |
1565 | n >>= NB; | 1570 | n >>= NB; |
@@ -1578,7 +1583,7 @@ static void packint (luaL_Buffer *b, lua_Unsigned n, | |||
1578 | ** given 'islittle' is different from native endianness. | 1583 | ** given 'islittle' is different from native endianness. |
1579 | */ | 1584 | */ |
1580 | static void copywithendian (char *dest, const char *src, | 1585 | static void copywithendian (char *dest, const char *src, |
1581 | int size, int islittle) { | 1586 | unsigned size, int islittle) { |
1582 | if (islittle == nativeendian.little) | 1587 | if (islittle == nativeendian.little) |
1583 | memcpy(dest, src, size); | 1588 | memcpy(dest, src, size); |
1584 | else { | 1589 | else { |
@@ -1599,7 +1604,7 @@ static int str_pack (lua_State *L) { | |||
1599 | lua_pushnil(L); /* mark to separate arguments from string buffer */ | 1604 | lua_pushnil(L); /* mark to separate arguments from string buffer */ |
1600 | luaL_buffinit(L, &b); | 1605 | luaL_buffinit(L, &b); |
1601 | while (*fmt != '\0') { | 1606 | while (*fmt != '\0') { |
1602 | int ntoalign; | 1607 | unsigned ntoalign; |
1603 | size_t size; | 1608 | size_t size; |
1604 | KOption opt = getdetails(&h, totalsize, &fmt, &size, &ntoalign); | 1609 | KOption opt = getdetails(&h, totalsize, &fmt, &size, &ntoalign); |
1605 | luaL_argcheck(L, size + ntoalign <= MAX_SIZE - totalsize, arg, | 1610 | luaL_argcheck(L, size + ntoalign <= MAX_SIZE - totalsize, arg, |
@@ -1615,7 +1620,7 @@ static int str_pack (lua_State *L) { | |||
1615 | lua_Integer lim = (lua_Integer)1 << ((size * NB) - 1); | 1620 | lua_Integer lim = (lua_Integer)1 << ((size * NB) - 1); |
1616 | luaL_argcheck(L, -lim <= n && n < lim, arg, "integer overflow"); | 1621 | luaL_argcheck(L, -lim <= n && n < lim, arg, "integer overflow"); |
1617 | } | 1622 | } |
1618 | packint(&b, (lua_Unsigned)n, h.islittle, size, (n < 0)); | 1623 | packint(&b, (lua_Unsigned)n, h.islittle, cast_uint(size), (n < 0)); |
1619 | break; | 1624 | break; |
1620 | } | 1625 | } |
1621 | case Kuint: { /* unsigned integers */ | 1626 | case Kuint: { /* unsigned integers */ |
@@ -1623,7 +1628,7 @@ static int str_pack (lua_State *L) { | |||
1623 | if (size < SZINT) /* need overflow check? */ | 1628 | if (size < SZINT) /* need overflow check? */ |
1624 | luaL_argcheck(L, (lua_Unsigned)n < ((lua_Unsigned)1 << (size * NB)), | 1629 | luaL_argcheck(L, (lua_Unsigned)n < ((lua_Unsigned)1 << (size * NB)), |
1625 | arg, "unsigned overflow"); | 1630 | arg, "unsigned overflow"); |
1626 | packint(&b, (lua_Unsigned)n, h.islittle, size, 0); | 1631 | packint(&b, (lua_Unsigned)n, h.islittle, cast_uint(size), 0); |
1627 | break; | 1632 | break; |
1628 | } | 1633 | } |
1629 | case Kfloat: { /* C float */ | 1634 | case Kfloat: { /* C float */ |
@@ -1669,7 +1674,8 @@ static int str_pack (lua_State *L) { | |||
1669 | luaL_argcheck(L, size >= sizeof(lua_Unsigned) || | 1674 | luaL_argcheck(L, size >= sizeof(lua_Unsigned) || |
1670 | len < ((lua_Unsigned)1 << (size * NB)), | 1675 | len < ((lua_Unsigned)1 << (size * NB)), |
1671 | arg, "string length does not fit in given size"); | 1676 | arg, "string length does not fit in given size"); |
1672 | packint(&b, (lua_Unsigned)len, h.islittle, size, 0); /* pack length */ | 1677 | /* pack length */ |
1678 | packint(&b, (lua_Unsigned)len, h.islittle, cast_uint(size), 0); | ||
1673 | luaL_addlstring(&b, s, len); | 1679 | luaL_addlstring(&b, s, len); |
1674 | totalsize += len; | 1680 | totalsize += len; |
1675 | break; | 1681 | break; |
@@ -1697,20 +1703,20 @@ static int str_pack (lua_State *L) { | |||
1697 | static int str_packsize (lua_State *L) { | 1703 | static int str_packsize (lua_State *L) { |
1698 | Header h; | 1704 | Header h; |
1699 | const char *fmt = luaL_checkstring(L, 1); /* format string */ | 1705 | const char *fmt = luaL_checkstring(L, 1); /* format string */ |
1700 | lua_Integer totalsize = 0; /* accumulate total size of result */ | 1706 | size_t totalsize = 0; /* accumulate total size of result */ |
1701 | initheader(L, &h); | 1707 | initheader(L, &h); |
1702 | while (*fmt != '\0') { | 1708 | while (*fmt != '\0') { |
1703 | int ntoalign; | 1709 | unsigned ntoalign; |
1704 | size_t size; | 1710 | size_t size; |
1705 | KOption opt = getdetails(&h, totalsize, &fmt, &size, &ntoalign); | 1711 | KOption opt = getdetails(&h, totalsize, &fmt, &size, &ntoalign); |
1706 | luaL_argcheck(L, opt != Kstring && opt != Kzstr, 1, | 1712 | luaL_argcheck(L, opt != Kstring && opt != Kzstr, 1, |
1707 | "variable-length format"); | 1713 | "variable-length format"); |
1708 | size += ntoalign; /* total space used by option */ | 1714 | size += ntoalign; /* total space used by option */ |
1709 | luaL_argcheck(L, totalsize <= LUA_MAXINTEGER - cast(lua_Integer, size), | 1715 | luaL_argcheck(L, totalsize <= LUA_MAXINTEGER - size, |
1710 | 1, "format result too large"); | 1716 | 1, "format result too large"); |
1711 | totalsize += size; | 1717 | totalsize += size; |
1712 | } | 1718 | } |
1713 | lua_pushinteger(L, totalsize); | 1719 | lua_pushinteger(L, cast_st2S(totalsize)); |
1714 | return 1; | 1720 | return 1; |
1715 | } | 1721 | } |
1716 | 1722 | ||
@@ -1759,7 +1765,7 @@ static int str_unpack (lua_State *L) { | |||
1759 | luaL_argcheck(L, pos <= ld, 3, "initial position out of string"); | 1765 | luaL_argcheck(L, pos <= ld, 3, "initial position out of string"); |
1760 | initheader(L, &h); | 1766 | initheader(L, &h); |
1761 | while (*fmt != '\0') { | 1767 | while (*fmt != '\0') { |
1762 | int ntoalign; | 1768 | unsigned ntoalign; |
1763 | size_t size; | 1769 | size_t size; |
1764 | KOption opt = getdetails(&h, pos, &fmt, &size, &ntoalign); | 1770 | KOption opt = getdetails(&h, pos, &fmt, &size, &ntoalign); |
1765 | luaL_argcheck(L, ntoalign + size <= ld - pos, 2, | 1771 | luaL_argcheck(L, ntoalign + size <= ld - pos, 2, |
@@ -1771,8 +1777,8 @@ static int str_unpack (lua_State *L) { | |||
1771 | switch (opt) { | 1777 | switch (opt) { |
1772 | case Kint: | 1778 | case Kint: |
1773 | case Kuint: { | 1779 | case Kuint: { |
1774 | lua_Integer res = unpackint(L, data + pos, h.islittle, size, | 1780 | lua_Integer res = unpackint(L, data + pos, h.islittle, |
1775 | (opt == Kint)); | 1781 | cast_int(size), (opt == Kint)); |
1776 | lua_pushinteger(L, res); | 1782 | lua_pushinteger(L, res); |
1777 | break; | 1783 | break; |
1778 | } | 1784 | } |
@@ -1800,7 +1806,7 @@ static int str_unpack (lua_State *L) { | |||
1800 | } | 1806 | } |
1801 | case Kstring: { | 1807 | case Kstring: { |
1802 | lua_Unsigned len = (lua_Unsigned)unpackint(L, data + pos, | 1808 | lua_Unsigned len = (lua_Unsigned)unpackint(L, data + pos, |
1803 | h.islittle, size, 0); | 1809 | h.islittle, cast_int(size), 0); |
1804 | luaL_argcheck(L, len <= ld - pos - size, 2, "data string too short"); | 1810 | luaL_argcheck(L, len <= ld - pos - size, 2, "data string too short"); |
1805 | lua_pushlstring(L, data + pos + size, len); | 1811 | lua_pushlstring(L, data + pos + size, len); |
1806 | pos += len; /* skip string */ | 1812 | pos += len; /* skip string */ |
@@ -1820,7 +1826,7 @@ static int str_unpack (lua_State *L) { | |||
1820 | } | 1826 | } |
1821 | pos += size; | 1827 | pos += size; |
1822 | } | 1828 | } |
1823 | lua_pushinteger(L, pos + 1); /* next position */ | 1829 | lua_pushinteger(L, cast_st2S(pos) + 1); /* next position */ |
1824 | return n + 1; | 1830 | return n + 1; |
1825 | } | 1831 | } |
1826 | 1832 | ||
@@ -109,7 +109,7 @@ typedef union { | |||
109 | ** for other types, it is better to avoid modulo by power of 2, as | 109 | ** for other types, it is better to avoid modulo by power of 2, as |
110 | ** they can have many 2 factors. | 110 | ** they can have many 2 factors. |
111 | */ | 111 | */ |
112 | #define hashmod(t,n) (gnode(t, ((n) % ((sizenode(t)-1)|1)))) | 112 | #define hashmod(t,n) (gnode(t, ((n) % ((sizenode(t)-1u)|1u)))) |
113 | 113 | ||
114 | 114 | ||
115 | #define hashstr(t,str) hashpow2(t, (str)->hash) | 115 | #define hashstr(t,str) hashpow2(t, (str)->hash) |
@@ -139,7 +139,7 @@ static const TValue absentkey = {ABSTKEYCONSTANT}; | |||
139 | static Node *hashint (const Table *t, lua_Integer i) { | 139 | static Node *hashint (const Table *t, lua_Integer i) { |
140 | lua_Unsigned ui = l_castS2U(i); | 140 | lua_Unsigned ui = l_castS2U(i); |
141 | if (ui <= cast_uint(INT_MAX)) | 141 | if (ui <= cast_uint(INT_MAX)) |
142 | return hashmod(t, cast_int(ui)); | 142 | return gnode(t, cast_int(ui) % cast_int((sizenode(t)-1) | 1)); |
143 | else | 143 | else |
144 | return hashmod(t, ui); | 144 | return hashmod(t, ui); |
145 | } | 145 | } |
@@ -159,7 +159,7 @@ static Node *hashint (const Table *t, lua_Integer i) { | |||
159 | ** INT_MIN. | 159 | ** INT_MIN. |
160 | */ | 160 | */ |
161 | #if !defined(l_hashfloat) | 161 | #if !defined(l_hashfloat) |
162 | static int l_hashfloat (lua_Number n) { | 162 | static unsigned l_hashfloat (lua_Number n) { |
163 | int i; | 163 | int i; |
164 | lua_Integer ni; | 164 | lua_Integer ni; |
165 | n = l_mathop(frexp)(n, &i) * -cast_num(INT_MIN); | 165 | n = l_mathop(frexp)(n, &i) * -cast_num(INT_MIN); |
@@ -169,7 +169,7 @@ static int l_hashfloat (lua_Number n) { | |||
169 | } | 169 | } |
170 | else { /* normal case */ | 170 | else { /* normal case */ |
171 | unsigned int u = cast_uint(i) + cast_uint(ni); | 171 | unsigned int u = cast_uint(i) + cast_uint(ni); |
172 | return cast_int(u <= cast_uint(INT_MAX) ? u : ~u); | 172 | return (u <= cast_uint(INT_MAX) ? u : ~u); |
173 | } | 173 | } |
174 | } | 174 | } |
175 | #endif | 175 | #endif |
@@ -370,7 +370,7 @@ static unsigned findindex (lua_State *L, Table *t, TValue *key, | |||
370 | const TValue *n = getgeneric(t, key, 1); | 370 | const TValue *n = getgeneric(t, key, 1); |
371 | if (l_unlikely(isabstkey(n))) | 371 | if (l_unlikely(isabstkey(n))) |
372 | luaG_runerror(L, "invalid key to 'next'"); /* key not found */ | 372 | luaG_runerror(L, "invalid key to 'next'"); /* key not found */ |
373 | i = cast_int(nodefromval(n) - gnode(t, 0)); /* key index in hash table */ | 373 | i = cast_uint(nodefromval(n) - gnode(t, 0)); /* key index in hash table */ |
374 | /* hash elements are numbered after array ones */ | 374 | /* hash elements are numbered after array ones */ |
375 | return (i + 1) + asize; | 375 | return (i + 1) + asize; |
376 | } | 376 | } |
@@ -381,14 +381,14 @@ int luaH_next (lua_State *L, Table *t, StkId key) { | |||
381 | unsigned int asize = luaH_realasize(t); | 381 | unsigned int asize = luaH_realasize(t); |
382 | unsigned int i = findindex(L, t, s2v(key), asize); /* find original key */ | 382 | unsigned int i = findindex(L, t, s2v(key), asize); /* find original key */ |
383 | for (; i < asize; i++) { /* try first array part */ | 383 | for (; i < asize; i++) { /* try first array part */ |
384 | int tag = *getArrTag(t, i); | 384 | lu_byte tag = *getArrTag(t, i); |
385 | if (!tagisempty(tag)) { /* a non-empty entry? */ | 385 | if (!tagisempty(tag)) { /* a non-empty entry? */ |
386 | setivalue(s2v(key), i + 1); | 386 | setivalue(s2v(key), cast_int(i) + 1); |
387 | farr2val(t, i, tag, s2v(key + 1)); | 387 | farr2val(t, i, tag, s2v(key + 1)); |
388 | return 1; | 388 | return 1; |
389 | } | 389 | } |
390 | } | 390 | } |
391 | for (i -= asize; cast_int(i) < sizenode(t); i++) { /* hash part */ | 391 | for (i -= asize; i < sizenode(t); i++) { /* hash part */ |
392 | if (!isempty(gval(gnode(t, i)))) { /* a non-empty entry? */ | 392 | if (!isempty(gval(gnode(t, i)))) { /* a non-empty entry? */ |
393 | Node *n = gnode(t, i); | 393 | Node *n = gnode(t, i); |
394 | getnodekey(L, s2v(key), n); | 394 | getnodekey(L, s2v(key), n); |
@@ -485,7 +485,7 @@ static unsigned computesizes (unsigned nums[], unsigned *pna) { | |||
485 | } | 485 | } |
486 | 486 | ||
487 | 487 | ||
488 | static int countint (lua_Integer key, unsigned int *nums) { | 488 | static unsigned countint (lua_Integer key, unsigned int *nums) { |
489 | unsigned int k = arrayindex(key); | 489 | unsigned int k = arrayindex(key); |
490 | if (k != 0) { /* is 'key' an appropriate array index? */ | 490 | if (k != 0) { /* is 'key' an appropriate array index? */ |
491 | nums[luaO_ceillog2(k)]++; /* count as such */ | 491 | nums[luaO_ceillog2(k)]++; /* count as such */ |
@@ -496,7 +496,7 @@ static int countint (lua_Integer key, unsigned int *nums) { | |||
496 | } | 496 | } |
497 | 497 | ||
498 | 498 | ||
499 | l_sinline int arraykeyisempty (const Table *t, lua_Integer key) { | 499 | l_sinline int arraykeyisempty (const Table *t, lua_Unsigned key) { |
500 | int tag = *getArrTag(t, key - 1); | 500 | int tag = *getArrTag(t, key - 1); |
501 | return tagisempty(tag); | 501 | return tagisempty(tag); |
502 | } | 502 | } |
@@ -534,10 +534,10 @@ static unsigned numusearray (const Table *t, unsigned *nums) { | |||
534 | } | 534 | } |
535 | 535 | ||
536 | 536 | ||
537 | static int numusehash (const Table *t, unsigned *nums, unsigned *pna) { | 537 | static unsigned numusehash (const Table *t, unsigned *nums, unsigned *pna) { |
538 | int totaluse = 0; /* total number of elements */ | 538 | unsigned totaluse = 0; /* total number of elements */ |
539 | int ause = 0; /* elements added to 'nums' (can go to array part) */ | 539 | unsigned ause = 0; /* elements added to 'nums' (can go to array part) */ |
540 | int i = sizenode(t); | 540 | unsigned i = sizenode(t); |
541 | while (i--) { | 541 | while (i--) { |
542 | Node *n = &t->node[i]; | 542 | Node *n = &t->node[i]; |
543 | if (!isempty(gval(n))) { | 543 | if (!isempty(gval(n))) { |
@@ -646,8 +646,8 @@ static void setnodevector (lua_State *L, Table *t, unsigned size) { | |||
646 | ** (Re)insert all elements from the hash part of 'ot' into table 't'. | 646 | ** (Re)insert all elements from the hash part of 'ot' into table 't'. |
647 | */ | 647 | */ |
648 | static void reinsert (lua_State *L, Table *ot, Table *t) { | 648 | static void reinsert (lua_State *L, Table *ot, Table *t) { |
649 | int j; | 649 | unsigned j; |
650 | int size = sizenode(ot); | 650 | unsigned size = sizenode(ot); |
651 | for (j = 0; j < size; j++) { | 651 | for (j = 0; j < size; j++) { |
652 | Node *old = gnode(ot, j); | 652 | Node *old = gnode(ot, j); |
653 | if (!isempty(gval(old))) { | 653 | if (!isempty(gval(old))) { |
@@ -673,10 +673,10 @@ static void exchangehashpart (Table *t1, Table *t2) { | |||
673 | int bitdummy1 = t1->flags & BITDUMMY; | 673 | int bitdummy1 = t1->flags & BITDUMMY; |
674 | t1->lsizenode = t2->lsizenode; | 674 | t1->lsizenode = t2->lsizenode; |
675 | t1->node = t2->node; | 675 | t1->node = t2->node; |
676 | t1->flags = (t1->flags & NOTBITDUMMY) | (t2->flags & BITDUMMY); | 676 | t1->flags = cast_byte((t1->flags & NOTBITDUMMY) | (t2->flags & BITDUMMY)); |
677 | t2->lsizenode = lsizenode; | 677 | t2->lsizenode = lsizenode; |
678 | t2->node = node; | 678 | t2->node = node; |
679 | t2->flags = (t2->flags & NOTBITDUMMY) | bitdummy1; | 679 | t2->flags = cast_byte((t2->flags & NOTBITDUMMY) | bitdummy1); |
680 | } | 680 | } |
681 | 681 | ||
682 | 682 | ||
@@ -689,11 +689,12 @@ static void reinsertOldSlice (lua_State *L, Table *t, unsigned oldasize, | |||
689 | unsigned i; | 689 | unsigned i; |
690 | t->alimit = newasize; /* pretend array has new size... */ | 690 | t->alimit = newasize; /* pretend array has new size... */ |
691 | for (i = newasize; i < oldasize; i++) { /* traverse vanishing slice */ | 691 | for (i = newasize; i < oldasize; i++) { /* traverse vanishing slice */ |
692 | int tag = *getArrTag(t, i); | 692 | lu_byte tag = *getArrTag(t, i); |
693 | if (!tagisempty(tag)) { /* a non-empty entry? */ | 693 | if (!tagisempty(tag)) { /* a non-empty entry? */ |
694 | TValue aux; | 694 | TValue aux; |
695 | farr2val(t, i, tag, &aux); /* copy entry into 'aux' */ | 695 | farr2val(t, i, tag, &aux); /* copy entry into 'aux' */ |
696 | luaH_setint(L, t, i + 1, &aux); /* re-insert it into the table */ | 696 | /* re-insert it into the table */ |
697 | luaH_setint(L, t, cast_int(i) + 1, &aux); | ||
697 | } | 698 | } |
698 | } | 699 | } |
699 | t->alimit = oldasize; /* restore current size... */ | 700 | t->alimit = oldasize; /* restore current size... */ |
@@ -756,7 +757,7 @@ void luaH_resize (lua_State *L, Table *t, unsigned newasize, | |||
756 | 757 | ||
757 | 758 | ||
758 | void luaH_resizearray (lua_State *L, Table *t, unsigned int nasize) { | 759 | void luaH_resizearray (lua_State *L, Table *t, unsigned int nasize) { |
759 | int nsize = allocsizenode(t); | 760 | unsigned nsize = allocsizenode(t); |
760 | luaH_resize(L, t, nasize, nsize); | 761 | luaH_resize(L, t, nasize, nsize); |
761 | } | 762 | } |
762 | 763 | ||
@@ -768,7 +769,7 @@ static void rehash (lua_State *L, Table *t, const TValue *ek) { | |||
768 | unsigned int na; /* number of keys in the array part */ | 769 | unsigned int na; /* number of keys in the array part */ |
769 | unsigned int nums[MAXABITS + 1]; | 770 | unsigned int nums[MAXABITS + 1]; |
770 | int i; | 771 | int i; |
771 | int totaluse; | 772 | unsigned totaluse; |
772 | for (i = 0; i <= MAXABITS; i++) nums[i] = 0; /* reset counts */ | 773 | for (i = 0; i <= MAXABITS; i++) nums[i] = 0; /* reset counts */ |
773 | setlimittosize(t); | 774 | setlimittosize(t); |
774 | na = numusearray(t, nums); /* count keys in array part */ | 775 | na = numusearray(t, nums); /* count keys in array part */ |
@@ -795,7 +796,7 @@ Table *luaH_new (lua_State *L) { | |||
795 | GCObject *o = luaC_newobj(L, LUA_VTABLE, sizeof(Table)); | 796 | GCObject *o = luaC_newobj(L, LUA_VTABLE, sizeof(Table)); |
796 | Table *t = gco2t(o); | 797 | Table *t = gco2t(o); |
797 | t->metatable = NULL; | 798 | t->metatable = NULL; |
798 | t->flags = cast_byte(maskflags); /* table has no metamethod fields */ | 799 | t->flags = maskflags; /* table has no metamethod fields */ |
799 | t->array = NULL; | 800 | t->array = NULL; |
800 | t->alimit = 0; | 801 | t->alimit = 0; |
801 | setnodevector(L, t, 0); | 802 | setnodevector(L, t, 0); |
@@ -825,7 +826,7 @@ static Node *getfreepos (Table *t) { | |||
825 | } | 826 | } |
826 | else { /* no 'lastfree' information */ | 827 | else { /* no 'lastfree' information */ |
827 | if (!isdummy(t)) { | 828 | if (!isdummy(t)) { |
828 | int i = sizenode(t); | 829 | unsigned i = sizenode(t); |
829 | while (i--) { /* do a linear search */ | 830 | while (i--) { /* do a linear search */ |
830 | Node *free = gnode(t, i); | 831 | Node *free = gnode(t, i); |
831 | if (keyisnil(free)) | 832 | if (keyisnil(free)) |
@@ -919,13 +920,13 @@ static const TValue *getintfromhash (Table *t, lua_Integer key) { | |||
919 | } | 920 | } |
920 | 921 | ||
921 | 922 | ||
922 | static int hashkeyisempty (Table *t, lua_Integer key) { | 923 | static int hashkeyisempty (Table *t, lua_Unsigned key) { |
923 | const TValue *val = getintfromhash(t, key); | 924 | const TValue *val = getintfromhash(t, l_castU2S(key)); |
924 | return isempty(val); | 925 | return isempty(val); |
925 | } | 926 | } |
926 | 927 | ||
927 | 928 | ||
928 | static int finishnodeget (const TValue *val, TValue *res) { | 929 | static lu_byte finishnodeget (const TValue *val, TValue *res) { |
929 | if (!ttisnil(val)) { | 930 | if (!ttisnil(val)) { |
930 | setobj(((lua_State*)NULL), res, val); | 931 | setobj(((lua_State*)NULL), res, val); |
931 | } | 932 | } |
@@ -933,9 +934,9 @@ static int finishnodeget (const TValue *val, TValue *res) { | |||
933 | } | 934 | } |
934 | 935 | ||
935 | 936 | ||
936 | int luaH_getint (Table *t, lua_Integer key, TValue *res) { | 937 | lu_byte luaH_getint (Table *t, lua_Integer key, TValue *res) { |
937 | if (keyinarray(t, key)) { | 938 | if (keyinarray(t, key)) { |
938 | int tag = *getArrTag(t, key - 1); | 939 | lu_byte tag = *getArrTag(t, key - 1); |
939 | if (!tagisempty(tag)) | 940 | if (!tagisempty(tag)) |
940 | farr2val(t, key - 1, tag, res); | 941 | farr2val(t, key - 1, tag, res); |
941 | return tag; | 942 | return tag; |
@@ -964,7 +965,7 @@ const TValue *luaH_Hgetshortstr (Table *t, TString *key) { | |||
964 | } | 965 | } |
965 | 966 | ||
966 | 967 | ||
967 | int luaH_getshortstr (Table *t, TString *key, TValue *res) { | 968 | lu_byte luaH_getshortstr (Table *t, TString *key, TValue *res) { |
968 | return finishnodeget(luaH_Hgetshortstr(t, key), res); | 969 | return finishnodeget(luaH_Hgetshortstr(t, key), res); |
969 | } | 970 | } |
970 | 971 | ||
@@ -980,7 +981,7 @@ static const TValue *Hgetstr (Table *t, TString *key) { | |||
980 | } | 981 | } |
981 | 982 | ||
982 | 983 | ||
983 | int luaH_getstr (Table *t, TString *key, TValue *res) { | 984 | lu_byte luaH_getstr (Table *t, TString *key, TValue *res) { |
984 | return finishnodeget(Hgetstr(t, key), res); | 985 | return finishnodeget(Hgetstr(t, key), res); |
985 | } | 986 | } |
986 | 987 | ||
@@ -997,7 +998,7 @@ TString *luaH_getstrkey (Table *t, TString *key) { | |||
997 | /* | 998 | /* |
998 | ** main search function | 999 | ** main search function |
999 | */ | 1000 | */ |
1000 | int luaH_get (Table *t, const TValue *key, TValue *res) { | 1001 | lu_byte luaH_get (Table *t, const TValue *key, TValue *res) { |
1001 | const TValue *slot; | 1002 | const TValue *slot; |
1002 | switch (ttypetag(key)) { | 1003 | switch (ttypetag(key)) { |
1003 | case LUA_VSHRSTR: | 1004 | case LUA_VSHRSTR: |
@@ -1259,7 +1260,7 @@ lua_Unsigned luaH_getn (Table *t) { | |||
1259 | /* (3) 'limit' is the last element and either is zero or present in table */ | 1260 | /* (3) 'limit' is the last element and either is zero or present in table */ |
1260 | lua_assert(limit == luaH_realasize(t) && | 1261 | lua_assert(limit == luaH_realasize(t) && |
1261 | (limit == 0 || !arraykeyisempty(t, limit))); | 1262 | (limit == 0 || !arraykeyisempty(t, limit))); |
1262 | if (isdummy(t) || hashkeyisempty(t, cast(lua_Integer, limit + 1))) | 1263 | if (isdummy(t) || hashkeyisempty(t, limit + 1)) |
1263 | return limit; /* 'limit + 1' is absent */ | 1264 | return limit; /* 'limit + 1' is absent */ |
1264 | else /* 'limit + 1' is also present */ | 1265 | else /* 'limit + 1' is also present */ |
1265 | return hash_search(t, limit); | 1266 | return hash_search(t, limit); |
@@ -20,7 +20,7 @@ | |||
20 | ** may have any of these metamethods. (First access that fails after the | 20 | ** may have any of these metamethods. (First access that fails after the |
21 | ** clearing will set the bit again.) | 21 | ** clearing will set the bit again.) |
22 | */ | 22 | */ |
23 | #define invalidateTMcache(t) ((t)->flags &= ~maskflags) | 23 | #define invalidateTMcache(t) ((t)->flags &= cast_byte(~maskflags)) |
24 | 24 | ||
25 | 25 | ||
26 | /* | 26 | /* |
@@ -137,10 +137,10 @@ | |||
137 | (*tag = (val)->tt_, *getArrVal(h,(k)) = (val)->value_) | 137 | (*tag = (val)->tt_, *getArrVal(h,(k)) = (val)->value_) |
138 | 138 | ||
139 | 139 | ||
140 | LUAI_FUNC int luaH_get (Table *t, const TValue *key, TValue *res); | 140 | LUAI_FUNC lu_byte luaH_get (Table *t, const TValue *key, TValue *res); |
141 | LUAI_FUNC int luaH_getshortstr (Table *t, TString *key, TValue *res); | 141 | LUAI_FUNC lu_byte luaH_getshortstr (Table *t, TString *key, TValue *res); |
142 | LUAI_FUNC int luaH_getstr (Table *t, TString *key, TValue *res); | 142 | LUAI_FUNC lu_byte luaH_getstr (Table *t, TString *key, TValue *res); |
143 | LUAI_FUNC int luaH_getint (Table *t, lua_Integer key, TValue *res); | 143 | LUAI_FUNC lu_byte luaH_getint (Table *t, lua_Integer key, TValue *res); |
144 | 144 | ||
145 | /* Special get for metamethods */ | 145 | /* Special get for metamethods */ |
146 | LUAI_FUNC const TValue *luaH_Hgetshortstr (Table *t, TString *key); | 146 | LUAI_FUNC const TValue *luaH_Hgetshortstr (Table *t, TString *key); |
@@ -192,7 +192,7 @@ static int tconcat (lua_State *L) { | |||
192 | static int tpack (lua_State *L) { | 192 | static int tpack (lua_State *L) { |
193 | int i; | 193 | int i; |
194 | int n = lua_gettop(L); /* number of elements to pack */ | 194 | int n = lua_gettop(L); /* number of elements to pack */ |
195 | lua_createtable(L, n, 1); /* create result table */ | 195 | lua_createtable(L, cast_uint(n), 1); /* create result table */ |
196 | lua_insert(L, 1); /* put it at index 1 */ | 196 | lua_insert(L, 1); /* put it at index 1 */ |
197 | for (i = n; i >= 1; i--) /* assign elements */ | 197 | for (i = n; i >= 1; i--) /* assign elements */ |
198 | lua_seti(L, 1, i); | 198 | lua_seti(L, 1, i); |
@@ -207,7 +207,7 @@ static int tunpack (lua_State *L) { | |||
207 | lua_Integer i = luaL_optinteger(L, 2, 1); | 207 | lua_Integer i = luaL_optinteger(L, 2, 1); |
208 | lua_Integer e = luaL_opt(L, luaL_checkinteger, 3, luaL_len(L, 1)); | 208 | lua_Integer e = luaL_opt(L, luaL_checkinteger, 3, luaL_len(L, 1)); |
209 | if (i > e) return 0; /* empty range */ | 209 | if (i > e) return 0; /* empty range */ |
210 | n = (lua_Unsigned)e - i; /* number of elements minus 1 (avoid overflows) */ | 210 | n = l_castS2U(e) - l_castS2U(i); /* number of elements minus 1 */ |
211 | if (l_unlikely(n >= (unsigned int)INT_MAX || | 211 | if (l_unlikely(n >= (unsigned int)INT_MAX || |
212 | !lua_checkstack(L, (int)(++n)))) | 212 | !lua_checkstack(L, (int)(++n)))) |
213 | return luaL_error(L, "too many results to unpack"); | 213 | return luaL_error(L, "too many results to unpack"); |
@@ -217,7 +217,7 @@ void *debug_realloc (void *ud, void *b, size_t oldsize, size_t size) { | |||
217 | mc->memlimit = limit ? strtoul(limit, NULL, 10) : ULONG_MAX; | 217 | mc->memlimit = limit ? strtoul(limit, NULL, 10) : ULONG_MAX; |
218 | } | 218 | } |
219 | if (block == NULL) { | 219 | if (block == NULL) { |
220 | type = (oldsize < LUA_NUMTYPES) ? oldsize : 0; | 220 | type = (oldsize < LUA_NUMTYPES) ? cast_int(oldsize) : 0; |
221 | oldsize = 0; | 221 | oldsize = 0; |
222 | } | 222 | } |
223 | else { | 223 | else { |
@@ -567,7 +567,7 @@ static l_obj checkgraylist (global_State *g, GCObject *o) { | |||
567 | ** Check objects in gray lists. | 567 | ** Check objects in gray lists. |
568 | */ | 568 | */ |
569 | static l_obj checkgrays (global_State *g) { | 569 | static l_obj checkgrays (global_State *g) { |
570 | int total = 0; /* count number of elements in all lists */ | 570 | l_obj total = 0; /* count number of elements in all lists */ |
571 | if (!keepinvariant(g)) return total; | 571 | if (!keepinvariant(g)) return total; |
572 | total += checkgraylist(g, g->gray); | 572 | total += checkgraylist(g, g->gray); |
573 | total += checkgraylist(g, g->grayagain); | 573 | total += checkgraylist(g, g->grayagain); |
@@ -778,7 +778,7 @@ static int listk (lua_State *L) { | |||
778 | luaL_argcheck(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), | 778 | luaL_argcheck(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), |
779 | 1, "Lua function expected"); | 779 | 1, "Lua function expected"); |
780 | p = getproto(obj_at(L, 1)); | 780 | p = getproto(obj_at(L, 1)); |
781 | lua_createtable(L, p->sizek, 0); | 781 | lua_createtable(L, cast_uint(p->sizek), 0); |
782 | for (i=0; i<p->sizek; i++) { | 782 | for (i=0; i<p->sizek; i++) { |
783 | pushobject(L, p->k+i); | 783 | pushobject(L, p->k+i); |
784 | lua_rawseti(L, -2, i+1); | 784 | lua_rawseti(L, -2, i+1); |
@@ -794,7 +794,7 @@ static int listabslineinfo (lua_State *L) { | |||
794 | 1, "Lua function expected"); | 794 | 1, "Lua function expected"); |
795 | p = getproto(obj_at(L, 1)); | 795 | p = getproto(obj_at(L, 1)); |
796 | luaL_argcheck(L, p->abslineinfo != NULL, 1, "function has no debug info"); | 796 | luaL_argcheck(L, p->abslineinfo != NULL, 1, "function has no debug info"); |
797 | lua_createtable(L, 2 * p->sizeabslineinfo, 0); | 797 | lua_createtable(L, 2u * cast_uint(p->sizeabslineinfo), 0); |
798 | for (i=0; i < p->sizeabslineinfo; i++) { | 798 | for (i=0; i < p->sizeabslineinfo; i++) { |
799 | lua_pushinteger(L, p->abslineinfo[i].pc); | 799 | lua_pushinteger(L, p->abslineinfo[i].pc); |
800 | lua_rawseti(L, -2, 2 * i + 1); | 800 | lua_rawseti(L, -2, 2 * i + 1); |
@@ -847,9 +847,9 @@ static int get_limits (lua_State *L) { | |||
847 | 847 | ||
848 | static int mem_query (lua_State *L) { | 848 | static int mem_query (lua_State *L) { |
849 | if (lua_isnone(L, 1)) { | 849 | if (lua_isnone(L, 1)) { |
850 | lua_pushinteger(L, l_memcontrol.total); | 850 | lua_pushinteger(L, cast(lua_Integer, l_memcontrol.total)); |
851 | lua_pushinteger(L, l_memcontrol.numblocks); | 851 | lua_pushinteger(L, cast(lua_Integer, l_memcontrol.numblocks)); |
852 | lua_pushinteger(L, l_memcontrol.maxmem); | 852 | lua_pushinteger(L, cast(lua_Integer, l_memcontrol.maxmem)); |
853 | return 3; | 853 | return 3; |
854 | } | 854 | } |
855 | else if (lua_isnumber(L, 1)) { | 855 | else if (lua_isnumber(L, 1)) { |
@@ -863,7 +863,7 @@ static int mem_query (lua_State *L) { | |||
863 | int i; | 863 | int i; |
864 | for (i = LUA_NUMTYPES - 1; i >= 0; i--) { | 864 | for (i = LUA_NUMTYPES - 1; i >= 0; i--) { |
865 | if (strcmp(t, ttypename(i)) == 0) { | 865 | if (strcmp(t, ttypename(i)) == 0) { |
866 | lua_pushinteger(L, l_memcontrol.objcount[i]); | 866 | lua_pushinteger(L, cast(lua_Integer, l_memcontrol.objcount[i])); |
867 | return 1; | 867 | return 1; |
868 | } | 868 | } |
869 | } | 869 | } |
@@ -874,9 +874,9 @@ static int mem_query (lua_State *L) { | |||
874 | 874 | ||
875 | static int alloc_count (lua_State *L) { | 875 | static int alloc_count (lua_State *L) { |
876 | if (lua_isnone(L, 1)) | 876 | if (lua_isnone(L, 1)) |
877 | l_memcontrol.countlimit = ~0L; | 877 | l_memcontrol.countlimit = cast(unsigned long, ~0L); |
878 | else | 878 | else |
879 | l_memcontrol.countlimit = luaL_checkinteger(L, 1); | 879 | l_memcontrol.countlimit = cast(unsigned long, luaL_checkinteger(L, 1)); |
880 | return 0; | 880 | return 0; |
881 | } | 881 | } |
882 | 882 | ||
@@ -975,26 +975,26 @@ static int gc_state (lua_State *L) { | |||
975 | static int hash_query (lua_State *L) { | 975 | static int hash_query (lua_State *L) { |
976 | if (lua_isnone(L, 2)) { | 976 | if (lua_isnone(L, 2)) { |
977 | luaL_argcheck(L, lua_type(L, 1) == LUA_TSTRING, 1, "string expected"); | 977 | luaL_argcheck(L, lua_type(L, 1) == LUA_TSTRING, 1, "string expected"); |
978 | lua_pushinteger(L, tsvalue(obj_at(L, 1))->hash); | 978 | lua_pushinteger(L, cast_int(tsvalue(obj_at(L, 1))->hash)); |
979 | } | 979 | } |
980 | else { | 980 | else { |
981 | TValue *o = obj_at(L, 1); | 981 | TValue *o = obj_at(L, 1); |
982 | Table *t; | 982 | Table *t; |
983 | luaL_checktype(L, 2, LUA_TTABLE); | 983 | luaL_checktype(L, 2, LUA_TTABLE); |
984 | t = hvalue(obj_at(L, 2)); | 984 | t = hvalue(obj_at(L, 2)); |
985 | lua_pushinteger(L, luaH_mainposition(t, o) - t->node); | 985 | lua_pushinteger(L, cast(lua_Integer, luaH_mainposition(t, o) - t->node)); |
986 | } | 986 | } |
987 | return 1; | 987 | return 1; |
988 | } | 988 | } |
989 | 989 | ||
990 | 990 | ||
991 | static int stacklevel (lua_State *L) { | 991 | static int stacklevel (lua_State *L) { |
992 | unsigned long a = 0; | 992 | int a = 0; |
993 | lua_pushinteger(L, (L->top.p - L->stack.p)); | 993 | lua_pushinteger(L, cast(lua_Integer, L->top.p - L->stack.p)); |
994 | lua_pushinteger(L, stacksize(L)); | 994 | lua_pushinteger(L, stacksize(L)); |
995 | lua_pushinteger(L, L->nCcalls); | 995 | lua_pushinteger(L, cast(lua_Integer, L->nCcalls)); |
996 | lua_pushinteger(L, L->nci); | 996 | lua_pushinteger(L, L->nci); |
997 | lua_pushinteger(L, (unsigned long)&a); | 997 | lua_pushinteger(L, (lua_Integer)(size_t)&a); |
998 | return 5; | 998 | return 5; |
999 | } | 999 | } |
1000 | 1000 | ||
@@ -1007,9 +1007,9 @@ static int table_query (lua_State *L) { | |||
1007 | t = hvalue(obj_at(L, 1)); | 1007 | t = hvalue(obj_at(L, 1)); |
1008 | asize = luaH_realasize(t); | 1008 | asize = luaH_realasize(t); |
1009 | if (i == -1) { | 1009 | if (i == -1) { |
1010 | lua_pushinteger(L, asize); | 1010 | lua_pushinteger(L, cast(lua_Integer, asize)); |
1011 | lua_pushinteger(L, allocsizenode(t)); | 1011 | lua_pushinteger(L, cast(lua_Integer, allocsizenode(t))); |
1012 | lua_pushinteger(L, t->alimit); | 1012 | lua_pushinteger(L, cast(lua_Integer, t->alimit)); |
1013 | return 3; | 1013 | return 3; |
1014 | } | 1014 | } |
1015 | else if (cast_uint(i) < asize) { | 1015 | else if (cast_uint(i) < asize) { |
@@ -1018,7 +1018,7 @@ static int table_query (lua_State *L) { | |||
1018 | api_incr_top(L); | 1018 | api_incr_top(L); |
1019 | lua_pushnil(L); | 1019 | lua_pushnil(L); |
1020 | } | 1020 | } |
1021 | else if ((i -= asize) < sizenode(t)) { | 1021 | else if (cast_uint(i -= cast_int(asize)) < sizenode(t)) { |
1022 | TValue k; | 1022 | TValue k; |
1023 | getnodekey(L, &k, gnode(t, i)); | 1023 | getnodekey(L, &k, gnode(t, i)); |
1024 | if (!isempty(gval(gnode(t, i))) || | 1024 | if (!isempty(gval(gnode(t, i))) || |
@@ -1054,7 +1054,7 @@ static int query_GCparams (lua_State *L) { | |||
1054 | 1054 | ||
1055 | static int test_codeparam (lua_State *L) { | 1055 | static int test_codeparam (lua_State *L) { |
1056 | lua_Integer p = luaL_checkinteger(L, 1); | 1056 | lua_Integer p = luaL_checkinteger(L, 1); |
1057 | lua_pushinteger(L, luaO_codeparam(p)); | 1057 | lua_pushinteger(L, luaO_codeparam(cast_uint(p))); |
1058 | return 1; | 1058 | return 1; |
1059 | } | 1059 | } |
1060 | 1060 | ||
@@ -1062,7 +1062,7 @@ static int test_codeparam (lua_State *L) { | |||
1062 | static int test_applyparam (lua_State *L) { | 1062 | static int test_applyparam (lua_State *L) { |
1063 | lua_Integer p = luaL_checkinteger(L, 1); | 1063 | lua_Integer p = luaL_checkinteger(L, 1); |
1064 | lua_Integer x = luaL_checkinteger(L, 2); | 1064 | lua_Integer x = luaL_checkinteger(L, 2); |
1065 | lua_pushinteger(L, luaO_applyparam(p, x)); | 1065 | lua_pushinteger(L, luaO_applyparam(cast_byte(p), x)); |
1066 | return 1; | 1066 | return 1; |
1067 | } | 1067 | } |
1068 | 1068 | ||
@@ -1147,7 +1147,7 @@ static int upvalue (lua_State *L) { | |||
1147 | 1147 | ||
1148 | static int newuserdata (lua_State *L) { | 1148 | static int newuserdata (lua_State *L) { |
1149 | size_t size = cast_sizet(luaL_optinteger(L, 1, 0)); | 1149 | size_t size = cast_sizet(luaL_optinteger(L, 1, 0)); |
1150 | int nuv = luaL_optinteger(L, 2, 0); | 1150 | int nuv = cast_int(luaL_optinteger(L, 2, 0)); |
1151 | char *p = cast_charp(lua_newuserdatauv(L, size, nuv)); | 1151 | char *p = cast_charp(lua_newuserdatauv(L, size, nuv)); |
1152 | while (size--) *p++ = '\0'; | 1152 | while (size--) *p++ = '\0'; |
1153 | return 1; | 1153 | return 1; |
@@ -1227,8 +1227,8 @@ static lua_State *getstate (lua_State *L) { | |||
1227 | 1227 | ||
1228 | static int loadlib (lua_State *L) { | 1228 | static int loadlib (lua_State *L) { |
1229 | lua_State *L1 = getstate(L); | 1229 | lua_State *L1 = getstate(L); |
1230 | int load = luaL_checkinteger(L, 2); | 1230 | int load = cast_int(luaL_checkinteger(L, 2)); |
1231 | int preload = luaL_checkinteger(L, 3); | 1231 | int preload = cast_int(luaL_checkinteger(L, 3)); |
1232 | luaL_openselectedlibs(L1, load, preload); | 1232 | luaL_openselectedlibs(L1, load, preload); |
1233 | luaL_requiref(L1, "T", luaB_opentests, 0); | 1233 | luaL_requiref(L1, "T", luaB_opentests, 0); |
1234 | lua_assert(lua_type(L1, -1) == LUA_TTABLE); | 1234 | lua_assert(lua_type(L1, -1) == LUA_TTABLE); |
@@ -1490,13 +1490,13 @@ static int runC (lua_State *L, lua_State *L1, const char *pc) { | |||
1490 | } | 1490 | } |
1491 | else if EQ("append") { | 1491 | else if EQ("append") { |
1492 | int t = getindex; | 1492 | int t = getindex; |
1493 | int i = lua_rawlen(L1, t); | 1493 | int i = cast_int(lua_rawlen(L1, t)); |
1494 | lua_rawseti(L1, t, i + 1); | 1494 | lua_rawseti(L1, t, i + 1); |
1495 | } | 1495 | } |
1496 | else if EQ("arith") { | 1496 | else if EQ("arith") { |
1497 | int op; | 1497 | int op; |
1498 | skip(&pc); | 1498 | skip(&pc); |
1499 | op = strchr(ops, *pc++) - ops; | 1499 | op = cast_int(strchr(ops, *pc++) - ops); |
1500 | lua_arith(L1, op); | 1500 | lua_arith(L1, op); |
1501 | } | 1501 | } |
1502 | else if EQ("call") { | 1502 | else if EQ("call") { |
@@ -1538,7 +1538,7 @@ static int runC (lua_State *L, lua_State *L1, const char *pc) { | |||
1538 | } | 1538 | } |
1539 | else if EQ("func2num") { | 1539 | else if EQ("func2num") { |
1540 | lua_CFunction func = lua_tocfunction(L1, getindex); | 1540 | lua_CFunction func = lua_tocfunction(L1, getindex); |
1541 | lua_pushnumber(L1, cast_sizet(func)); | 1541 | lua_pushinteger(L1, cast(lua_Integer, func)); |
1542 | } | 1542 | } |
1543 | else if EQ("getfield") { | 1543 | else if EQ("getfield") { |
1544 | int t = getindex; | 1544 | int t = getindex; |
@@ -1624,13 +1624,13 @@ static int runC (lua_State *L, lua_State *L1, const char *pc) { | |||
1624 | lua_pushinteger(L1, lua_resetthread(L1)); /* deprecated */ | 1624 | lua_pushinteger(L1, lua_resetthread(L1)); /* deprecated */ |
1625 | } | 1625 | } |
1626 | else if EQ("newuserdata") { | 1626 | else if EQ("newuserdata") { |
1627 | lua_newuserdata(L1, getnum); | 1627 | lua_newuserdata(L1, cast_sizet(getnum)); |
1628 | } | 1628 | } |
1629 | else if EQ("next") { | 1629 | else if EQ("next") { |
1630 | lua_next(L1, -2); | 1630 | lua_next(L1, -2); |
1631 | } | 1631 | } |
1632 | else if EQ("objsize") { | 1632 | else if EQ("objsize") { |
1633 | lua_pushinteger(L1, lua_rawlen(L1, getindex)); | 1633 | lua_pushinteger(L1, l_castU2S(lua_rawlen(L1, getindex))); |
1634 | } | 1634 | } |
1635 | else if EQ("pcall") { | 1635 | else if EQ("pcall") { |
1636 | int narg = getnum; | 1636 | int narg = getnum; |
@@ -1903,7 +1903,7 @@ static int Cfunck (lua_State *L, int status, lua_KContext ctx) { | |||
1903 | lua_setglobal(L, "status"); | 1903 | lua_setglobal(L, "status"); |
1904 | lua_pushinteger(L, ctx); | 1904 | lua_pushinteger(L, ctx); |
1905 | lua_setglobal(L, "ctx"); | 1905 | lua_setglobal(L, "ctx"); |
1906 | return runC(L, L, lua_tostring(L, ctx)); | 1906 | return runC(L, L, lua_tostring(L, cast_int(ctx))); |
1907 | } | 1907 | } |
1908 | 1908 | ||
1909 | 1909 | ||
@@ -116,8 +116,8 @@ void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1, | |||
116 | } | 116 | } |
117 | 117 | ||
118 | 118 | ||
119 | int luaT_callTMres (lua_State *L, const TValue *f, const TValue *p1, | 119 | lu_byte luaT_callTMres (lua_State *L, const TValue *f, const TValue *p1, |
120 | const TValue *p2, StkId res) { | 120 | const TValue *p2, StkId res) { |
121 | ptrdiff_t result = savestack(L, res); | 121 | ptrdiff_t result = savestack(L, res); |
122 | StkId func = L->top.p; | 122 | StkId func = L->top.p; |
123 | setobj2s(L, func, f); /* push function (assume EXTRA_STACK) */ | 123 | setobj2s(L, func, f); /* push function (assume EXTRA_STACK) */ |
@@ -51,7 +51,7 @@ typedef enum { | |||
51 | ** corresponding metamethod field. (Bit 6 of the flag indicates that | 51 | ** corresponding metamethod field. (Bit 6 of the flag indicates that |
52 | ** the table is using the dummy node; bit 7 is used for 'isrealasize'.) | 52 | ** the table is using the dummy node; bit 7 is used for 'isrealasize'.) |
53 | */ | 53 | */ |
54 | #define maskflags (~(~0u << (TM_EQ + 1))) | 54 | #define maskflags cast_byte(~(~0u << (TM_EQ + 1))) |
55 | 55 | ||
56 | 56 | ||
57 | /* | 57 | /* |
@@ -81,8 +81,8 @@ LUAI_FUNC void luaT_init (lua_State *L); | |||
81 | 81 | ||
82 | LUAI_FUNC void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1, | 82 | LUAI_FUNC void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1, |
83 | const TValue *p2, const TValue *p3); | 83 | const TValue *p2, const TValue *p3); |
84 | LUAI_FUNC int luaT_callTMres (lua_State *L, const TValue *f, | 84 | LUAI_FUNC lu_byte luaT_callTMres (lua_State *L, const TValue *f, |
85 | const TValue *p1, const TValue *p2, StkId p3); | 85 | const TValue *p1, const TValue *p2, StkId p3); |
86 | LUAI_FUNC void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2, | 86 | LUAI_FUNC void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2, |
87 | StkId res, TMS event); | 87 | StkId res, TMS event); |
88 | LUAI_FUNC void luaT_tryconcatTM (lua_State *L); | 88 | LUAI_FUNC void luaT_tryconcatTM (lua_State *L); |
@@ -185,7 +185,7 @@ static void print_version (void) { | |||
185 | static void createargtable (lua_State *L, char **argv, int argc, int script) { | 185 | static void createargtable (lua_State *L, char **argv, int argc, int script) { |
186 | int i, narg; | 186 | int i, narg; |
187 | narg = argc - (script + 1); /* number of positive indices */ | 187 | narg = argc - (script + 1); /* number of positive indices */ |
188 | lua_createtable(L, narg, script + 1); | 188 | lua_createtable(L, cast_uint(narg), cast_uint(script + 1)); |
189 | for (i = 0; i < argc; i++) { | 189 | for (i = 0; i < argc; i++) { |
190 | lua_pushstring(L, argv[i]); | 190 | lua_pushstring(L, argv[i]); |
191 | lua_rawseti(L, -2, i - script); | 191 | lua_rawseti(L, -2, i - script); |
@@ -36,7 +36,7 @@ typedef struct { | |||
36 | ZIO *Z; | 36 | ZIO *Z; |
37 | const char *name; | 37 | const char *name; |
38 | Table *h; /* list for string reuse */ | 38 | Table *h; /* list for string reuse */ |
39 | lu_mem offset; /* current position relative to beginning of dump */ | 39 | size_t offset; /* current position relative to beginning of dump */ |
40 | lua_Integer nstr; /* number of strings in the list */ | 40 | lua_Integer nstr; /* number of strings in the list */ |
41 | lu_byte fixed; /* dump is fixed in memory */ | 41 | lu_byte fixed; /* dump is fixed in memory */ |
42 | } LoadState; | 42 | } LoadState; |
@@ -61,8 +61,8 @@ static void loadBlock (LoadState *S, void *b, size_t size) { | |||
61 | } | 61 | } |
62 | 62 | ||
63 | 63 | ||
64 | static void loadAlign (LoadState *S, int align) { | 64 | static void loadAlign (LoadState *S, unsigned align) { |
65 | int padding = align - (S->offset % align); | 65 | unsigned padding = align - cast_uint(S->offset % align); |
66 | if (padding < align) { /* apd == align means no padding */ | 66 | if (padding < align) { /* apd == align means no padding */ |
67 | lua_Integer paddingContent; | 67 | lua_Integer paddingContent; |
68 | loadBlock(S, &paddingContent, padding); | 68 | loadBlock(S, &paddingContent, padding); |
@@ -113,11 +113,19 @@ static size_t loadSize (LoadState *S) { | |||
113 | } | 113 | } |
114 | 114 | ||
115 | 115 | ||
116 | /* | ||
117 | ** Read an non-negative int */ | ||
118 | static unsigned loadUint (LoadState *S) { | ||
119 | return cast_uint(loadVarint(S, cast_sizet(INT_MAX))); | ||
120 | } | ||
121 | |||
122 | |||
116 | static int loadInt (LoadState *S) { | 123 | static int loadInt (LoadState *S) { |
117 | return cast_int(loadVarint(S, cast_sizet(INT_MAX))); | 124 | return cast_int(loadVarint(S, cast_sizet(INT_MAX))); |
118 | } | 125 | } |
119 | 126 | ||
120 | 127 | ||
128 | |||
121 | static lua_Number loadNumber (LoadState *S) { | 129 | static lua_Number loadNumber (LoadState *S) { |
122 | lua_Number x; | 130 | lua_Number x; |
123 | loadVar(S, x); | 131 | loadVar(S, x); |
@@ -180,15 +188,15 @@ static void loadString (LoadState *S, Proto *p, TString **sl) { | |||
180 | 188 | ||
181 | 189 | ||
182 | static void loadCode (LoadState *S, Proto *f) { | 190 | static void loadCode (LoadState *S, Proto *f) { |
183 | int n = loadInt(S); | 191 | unsigned n = loadUint(S); |
184 | loadAlign(S, sizeof(f->code[0])); | 192 | loadAlign(S, sizeof(f->code[0])); |
185 | if (S->fixed) { | 193 | if (S->fixed) { |
186 | f->code = getaddr(S, n, Instruction); | 194 | f->code = getaddr(S, n, Instruction); |
187 | f->sizecode = n; | 195 | f->sizecode = cast_int(n); |
188 | } | 196 | } |
189 | else { | 197 | else { |
190 | f->code = luaM_newvectorchecked(S->L, n, Instruction); | 198 | f->code = luaM_newvectorchecked(S->L, n, Instruction); |
191 | f->sizecode = n; | 199 | f->sizecode = cast_int(n); |
192 | loadVector(S, f->code, n); | 200 | loadVector(S, f->code, n); |
193 | } | 201 | } |
194 | } | 202 | } |
@@ -198,10 +206,10 @@ static void loadFunction(LoadState *S, Proto *f); | |||
198 | 206 | ||
199 | 207 | ||
200 | static void loadConstants (LoadState *S, Proto *f) { | 208 | static void loadConstants (LoadState *S, Proto *f) { |
201 | int i; | 209 | unsigned i; |
202 | int n = loadInt(S); | 210 | unsigned n = loadUint(S); |
203 | f->k = luaM_newvectorchecked(S->L, n, TValue); | 211 | f->k = luaM_newvectorchecked(S->L, n, TValue); |
204 | f->sizek = n; | 212 | f->sizek = cast_int(n); |
205 | for (i = 0; i < n; i++) | 213 | for (i = 0; i < n; i++) |
206 | setnilvalue(&f->k[i]); | 214 | setnilvalue(&f->k[i]); |
207 | for (i = 0; i < n; i++) { | 215 | for (i = 0; i < n; i++) { |
@@ -240,10 +248,10 @@ static void loadConstants (LoadState *S, Proto *f) { | |||
240 | 248 | ||
241 | 249 | ||
242 | static void loadProtos (LoadState *S, Proto *f) { | 250 | static void loadProtos (LoadState *S, Proto *f) { |
243 | int i; | 251 | unsigned i; |
244 | int n = loadInt(S); | 252 | unsigned n = loadUint(S); |
245 | f->p = luaM_newvectorchecked(S->L, n, Proto *); | 253 | f->p = luaM_newvectorchecked(S->L, n, Proto *); |
246 | f->sizep = n; | 254 | f->sizep = cast_int(n); |
247 | for (i = 0; i < n; i++) | 255 | for (i = 0; i < n; i++) |
248 | f->p[i] = NULL; | 256 | f->p[i] = NULL; |
249 | for (i = 0; i < n; i++) { | 257 | for (i = 0; i < n; i++) { |
@@ -261,10 +269,10 @@ static void loadProtos (LoadState *S, Proto *f) { | |||
261 | ** in that case all prototypes must be consistent for the GC. | 269 | ** in that case all prototypes must be consistent for the GC. |
262 | */ | 270 | */ |
263 | static void loadUpvalues (LoadState *S, Proto *f) { | 271 | static void loadUpvalues (LoadState *S, Proto *f) { |
264 | int i, n; | 272 | unsigned i; |
265 | n = loadInt(S); | 273 | unsigned n = loadUint(S); |
266 | f->upvalues = luaM_newvectorchecked(S->L, n, Upvaldesc); | 274 | f->upvalues = luaM_newvectorchecked(S->L, n, Upvaldesc); |
267 | f->sizeupvalues = n; | 275 | f->sizeupvalues = cast_int(n); |
268 | for (i = 0; i < n; i++) /* make array valid for GC */ | 276 | for (i = 0; i < n; i++) /* make array valid for GC */ |
269 | f->upvalues[i].name = NULL; | 277 | f->upvalues[i].name = NULL; |
270 | for (i = 0; i < n; i++) { /* following calls can raise errors */ | 278 | for (i = 0; i < n; i++) { /* following calls can raise errors */ |
@@ -276,33 +284,33 @@ static void loadUpvalues (LoadState *S, Proto *f) { | |||
276 | 284 | ||
277 | 285 | ||
278 | static void loadDebug (LoadState *S, Proto *f) { | 286 | static void loadDebug (LoadState *S, Proto *f) { |
279 | int i, n; | 287 | unsigned i; |
280 | n = loadInt(S); | 288 | unsigned n = loadUint(S); |
281 | if (S->fixed) { | 289 | if (S->fixed) { |
282 | f->lineinfo = getaddr(S, n, ls_byte); | 290 | f->lineinfo = getaddr(S, n, ls_byte); |
283 | f->sizelineinfo = n; | 291 | f->sizelineinfo = cast_int(n); |
284 | } | 292 | } |
285 | else { | 293 | else { |
286 | f->lineinfo = luaM_newvectorchecked(S->L, n, ls_byte); | 294 | f->lineinfo = luaM_newvectorchecked(S->L, n, ls_byte); |
287 | f->sizelineinfo = n; | 295 | f->sizelineinfo = cast_int(n); |
288 | loadVector(S, f->lineinfo, n); | 296 | loadVector(S, f->lineinfo, n); |
289 | } | 297 | } |
290 | n = loadInt(S); | 298 | n = loadUint(S); |
291 | if (n > 0) { | 299 | if (n > 0) { |
292 | loadAlign(S, sizeof(int)); | 300 | loadAlign(S, sizeof(int)); |
293 | if (S->fixed) { | 301 | if (S->fixed) { |
294 | f->abslineinfo = getaddr(S, n, AbsLineInfo); | 302 | f->abslineinfo = getaddr(S, n, AbsLineInfo); |
295 | f->sizeabslineinfo = n; | 303 | f->sizeabslineinfo = cast_int(n); |
296 | } | 304 | } |
297 | else { | 305 | else { |
298 | f->abslineinfo = luaM_newvectorchecked(S->L, n, AbsLineInfo); | 306 | f->abslineinfo = luaM_newvectorchecked(S->L, n, AbsLineInfo); |
299 | f->sizeabslineinfo = n; | 307 | f->sizeabslineinfo = cast_int(n); |
300 | loadVector(S, f->abslineinfo, n); | 308 | loadVector(S, f->abslineinfo, n); |
301 | } | 309 | } |
302 | } | 310 | } |
303 | n = loadInt(S); | 311 | n = loadUint(S); |
304 | f->locvars = luaM_newvectorchecked(S->L, n, LocVar); | 312 | f->locvars = luaM_newvectorchecked(S->L, n, LocVar); |
305 | f->sizelocvars = n; | 313 | f->sizelocvars = cast_int(n); |
306 | for (i = 0; i < n; i++) | 314 | for (i = 0; i < n; i++) |
307 | f->locvars[i].varname = NULL; | 315 | f->locvars[i].varname = NULL; |
308 | for (i = 0; i < n; i++) { | 316 | for (i = 0; i < n; i++) { |
@@ -310,9 +318,9 @@ static void loadDebug (LoadState *S, Proto *f) { | |||
310 | f->locvars[i].startpc = loadInt(S); | 318 | f->locvars[i].startpc = loadInt(S); |
311 | f->locvars[i].endpc = loadInt(S); | 319 | f->locvars[i].endpc = loadInt(S); |
312 | } | 320 | } |
313 | n = loadInt(S); | 321 | n = loadUint(S); |
314 | if (n != 0) /* does it have debug information? */ | 322 | if (n != 0) /* does it have debug information? */ |
315 | n = f->sizeupvalues; /* must be this many */ | 323 | n = cast_uint(f->sizeupvalues); /* must be this many */ |
316 | for (i = 0; i < n; i++) | 324 | for (i = 0; i < n; i++) |
317 | loadString(S, f, &f->upvalues[i].name); | 325 | loadString(S, f, &f->upvalues[i].name); |
318 | } | 326 | } |
@@ -384,7 +392,7 @@ LClosure *luaU_undump (lua_State *L, ZIO *Z, const char *name, int fixed) { | |||
384 | S.name = name; | 392 | S.name = name; |
385 | S.L = L; | 393 | S.L = L; |
386 | S.Z = Z; | 394 | S.Z = Z; |
387 | S.fixed = fixed; | 395 | S.fixed = cast_byte(fixed); |
388 | S.offset = 1; /* fist byte was already read */ | 396 | S.offset = 1; /* fist byte was already read */ |
389 | checkHeader(&S); | 397 | checkHeader(&S); |
390 | cl = luaF_newLclosure(L, loadByte(&S)); | 398 | cl = luaF_newLclosure(L, loadByte(&S)); |
@@ -180,7 +180,7 @@ static int byteoffset (lua_State *L) { | |||
180 | size_t len; | 180 | size_t len; |
181 | const char *s = luaL_checklstring(L, 1, &len); | 181 | const char *s = luaL_checklstring(L, 1, &len); |
182 | lua_Integer n = luaL_checkinteger(L, 2); | 182 | lua_Integer n = luaL_checkinteger(L, 2); |
183 | lua_Integer posi = (n >= 0) ? 1 : len + 1; | 183 | lua_Integer posi = (n >= 0) ? 1 : cast_st2S(len) + 1; |
184 | posi = u_posrelat(luaL_optinteger(L, 3, posi), len); | 184 | posi = u_posrelat(luaL_optinteger(L, 3, posi), len); |
185 | luaL_argcheck(L, 1 <= posi && --posi <= (lua_Integer)len, 3, | 185 | luaL_argcheck(L, 1 <= posi && --posi <= (lua_Integer)len, 3, |
186 | "position out of bounds"); | 186 | "position out of bounds"); |
@@ -239,7 +239,7 @@ static int iter_aux (lua_State *L, int strict) { | |||
239 | const char *next = utf8_decode(s + n, &code, strict); | 239 | const char *next = utf8_decode(s + n, &code, strict); |
240 | if (next == NULL || iscontp(next)) | 240 | if (next == NULL || iscontp(next)) |
241 | return luaL_error(L, MSGInvalid); | 241 | return luaL_error(L, MSGInvalid); |
242 | lua_pushinteger(L, n + 1); | 242 | lua_pushinteger(L, l_castU2S(n + 1)); |
243 | lua_pushinteger(L, code); | 243 | lua_pushinteger(L, code); |
244 | return 2; | 244 | return 2; |
245 | } | 245 | } |
@@ -288,8 +288,8 @@ static int floatforloop (StkId ra) { | |||
288 | /* | 288 | /* |
289 | ** Finish the table access 'val = t[key]' and return the tag of the result. | 289 | ** Finish the table access 'val = t[key]' and return the tag of the result. |
290 | */ | 290 | */ |
291 | int luaV_finishget (lua_State *L, const TValue *t, TValue *key, StkId val, | 291 | lu_byte luaV_finishget (lua_State *L, const TValue *t, TValue *key, |
292 | int tag) { | 292 | StkId val, lu_byte tag) { |
293 | int loop; /* counter to avoid infinite loops */ | 293 | int loop; /* counter to avoid infinite loops */ |
294 | const TValue *tm; /* metamethod */ | 294 | const TValue *tm; /* metamethod */ |
295 | for (loop = 0; loop < MAXTAGLOOP; loop++) { | 295 | for (loop = 0; loop < MAXTAGLOOP; loop++) { |
@@ -690,7 +690,7 @@ void luaV_objlen (lua_State *L, StkId ra, const TValue *rb) { | |||
690 | Table *h = hvalue(rb); | 690 | Table *h = hvalue(rb); |
691 | tm = fasttm(L, h->metatable, TM_LEN); | 691 | tm = fasttm(L, h->metatable, TM_LEN); |
692 | if (tm) break; /* metamethod? break switch to call it */ | 692 | if (tm) break; /* metamethod? break switch to call it */ |
693 | setivalue(s2v(ra), luaH_getn(h)); /* else primitive len */ | 693 | setivalue(s2v(ra), l_castU2S(luaH_getn(h))); /* else primitive len */ |
694 | return; | 694 | return; |
695 | } | 695 | } |
696 | case LUA_VSHRSTR: { | 696 | case LUA_VSHRSTR: { |
@@ -698,7 +698,7 @@ void luaV_objlen (lua_State *L, StkId ra, const TValue *rb) { | |||
698 | return; | 698 | return; |
699 | } | 699 | } |
700 | case LUA_VLNGSTR: { | 700 | case LUA_VLNGSTR: { |
701 | setivalue(s2v(ra), tsvalue(rb)->u.lnglen); | 701 | setivalue(s2v(ra), cast_st2S(tsvalue(rb)->u.lnglen)); |
702 | return; | 702 | return; |
703 | } | 703 | } |
704 | default: { /* try metamethod */ | 704 | default: { /* try metamethod */ |
@@ -1255,7 +1255,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) { | |||
1255 | TValue *upval = cl->upvals[GETARG_B(i)]->v.p; | 1255 | TValue *upval = cl->upvals[GETARG_B(i)]->v.p; |
1256 | TValue *rc = KC(i); | 1256 | TValue *rc = KC(i); |
1257 | TString *key = tsvalue(rc); /* key must be a short string */ | 1257 | TString *key = tsvalue(rc); /* key must be a short string */ |
1258 | int tag; | 1258 | lu_byte tag; |
1259 | luaV_fastget(upval, key, s2v(ra), luaH_getshortstr, tag); | 1259 | luaV_fastget(upval, key, s2v(ra), luaH_getshortstr, tag); |
1260 | if (tagisempty(tag)) | 1260 | if (tagisempty(tag)) |
1261 | Protect(luaV_finishget(L, upval, rc, ra, tag)); | 1261 | Protect(luaV_finishget(L, upval, rc, ra, tag)); |
@@ -1265,7 +1265,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) { | |||
1265 | StkId ra = RA(i); | 1265 | StkId ra = RA(i); |
1266 | TValue *rb = vRB(i); | 1266 | TValue *rb = vRB(i); |
1267 | TValue *rc = vRC(i); | 1267 | TValue *rc = vRC(i); |
1268 | int tag; | 1268 | lu_byte tag; |
1269 | if (ttisinteger(rc)) { /* fast track for integers? */ | 1269 | if (ttisinteger(rc)) { /* fast track for integers? */ |
1270 | luaV_fastgeti(rb, ivalue(rc), s2v(ra), tag); | 1270 | luaV_fastgeti(rb, ivalue(rc), s2v(ra), tag); |
1271 | } | 1271 | } |
@@ -1279,7 +1279,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) { | |||
1279 | StkId ra = RA(i); | 1279 | StkId ra = RA(i); |
1280 | TValue *rb = vRB(i); | 1280 | TValue *rb = vRB(i); |
1281 | int c = GETARG_C(i); | 1281 | int c = GETARG_C(i); |
1282 | int tag; | 1282 | lu_byte tag; |
1283 | luaV_fastgeti(rb, c, s2v(ra), tag); | 1283 | luaV_fastgeti(rb, c, s2v(ra), tag); |
1284 | if (tagisempty(tag)) { | 1284 | if (tagisempty(tag)) { |
1285 | TValue key; | 1285 | TValue key; |
@@ -1293,7 +1293,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) { | |||
1293 | TValue *rb = vRB(i); | 1293 | TValue *rb = vRB(i); |
1294 | TValue *rc = KC(i); | 1294 | TValue *rc = KC(i); |
1295 | TString *key = tsvalue(rc); /* key must be a short string */ | 1295 | TString *key = tsvalue(rc); /* key must be a short string */ |
1296 | int tag; | 1296 | lu_byte tag; |
1297 | luaV_fastget(rb, key, s2v(ra), luaH_getshortstr, tag); | 1297 | luaV_fastget(rb, key, s2v(ra), luaH_getshortstr, tag); |
1298 | if (tagisempty(tag)) | 1298 | if (tagisempty(tag)) |
1299 | Protect(luaV_finishget(L, rb, rc, ra, tag)); | 1299 | Protect(luaV_finishget(L, rb, rc, ra, tag)); |
@@ -1359,14 +1359,15 @@ void luaV_execute (lua_State *L, CallInfo *ci) { | |||
1359 | } | 1359 | } |
1360 | vmcase(OP_NEWTABLE) { | 1360 | vmcase(OP_NEWTABLE) { |
1361 | StkId ra = RA(i); | 1361 | StkId ra = RA(i); |
1362 | int b = GETARG_vB(i); /* log2(hash size) + 1 */ | 1362 | unsigned b = cast_uint(GETARG_vB(i)); /* log2(hash size) + 1 */ |
1363 | int c = GETARG_vC(i); /* array size */ | 1363 | unsigned c = cast_uint(GETARG_vC(i)); /* array size */ |
1364 | Table *t; | 1364 | Table *t; |
1365 | if (b > 0) | 1365 | if (b > 0) |
1366 | b = 1 << (b - 1); /* hash size is 2^(b - 1) */ | 1366 | b = 1u << (b - 1); /* hash size is 2^(b - 1) */ |
1367 | if (TESTARG_k(i)) { /* non-zero extra argument? */ | 1367 | if (TESTARG_k(i)) { /* non-zero extra argument? */ |
1368 | lua_assert(GETARG_Ax(*pc) != 0); | 1368 | lua_assert(GETARG_Ax(*pc) != 0); |
1369 | c += GETARG_Ax(*pc) * (MAXARG_vC + 1); /* add it to array size */ | 1369 | /* add it to array size */ |
1370 | c += cast_uint(GETARG_Ax(*pc)) * (MAXARG_vC + 1); | ||
1370 | } | 1371 | } |
1371 | pc++; /* skip extra argument */ | 1372 | pc++; /* skip extra argument */ |
1372 | L->top.p = ra + 1; /* correct top in case of emergency GC */ | 1373 | L->top.p = ra + 1; /* correct top in case of emergency GC */ |
@@ -1379,7 +1380,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) { | |||
1379 | } | 1380 | } |
1380 | vmcase(OP_SELF) { | 1381 | vmcase(OP_SELF) { |
1381 | StkId ra = RA(i); | 1382 | StkId ra = RA(i); |
1382 | int tag; | 1383 | lu_byte tag; |
1383 | TValue *rb = vRB(i); | 1384 | TValue *rb = vRB(i); |
1384 | TValue *rc = RKC(i); | 1385 | TValue *rc = RKC(i); |
1385 | TString *key = tsvalue(rc); /* key must be a string */ | 1386 | TString *key = tsvalue(rc); /* key must be a string */ |
@@ -1786,7 +1787,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) { | |||
1786 | if (count > 0) { /* still more iterations? */ | 1787 | if (count > 0) { /* still more iterations? */ |
1787 | lua_Integer step = ivalue(s2v(ra + 1)); | 1788 | lua_Integer step = ivalue(s2v(ra + 1)); |
1788 | lua_Integer idx = ivalue(s2v(ra + 2)); /* control variable */ | 1789 | lua_Integer idx = ivalue(s2v(ra + 2)); /* control variable */ |
1789 | chgivalue(s2v(ra), count - 1); /* update counter */ | 1790 | chgivalue(s2v(ra), l_castU2S(count - 1)); /* update counter */ |
1790 | idx = intop(+, idx, step); /* add step to index */ | 1791 | idx = intop(+, idx, step); /* add step to index */ |
1791 | chgivalue(s2v(ra + 2), idx); /* update control variable */ | 1792 | chgivalue(s2v(ra + 2), idx); /* update control variable */ |
1792 | pc -= GETARG_Bx(i); /* jump back */ | 1793 | pc -= GETARG_Bx(i); /* jump back */ |
@@ -1851,16 +1852,16 @@ void luaV_execute (lua_State *L, CallInfo *ci) { | |||
1851 | }} | 1852 | }} |
1852 | vmcase(OP_SETLIST) { | 1853 | vmcase(OP_SETLIST) { |
1853 | StkId ra = RA(i); | 1854 | StkId ra = RA(i); |
1854 | int n = GETARG_vB(i); | 1855 | unsigned n = cast_uint(GETARG_vB(i)); |
1855 | unsigned int last = GETARG_vC(i); | 1856 | unsigned int last = cast_uint(GETARG_vC(i)); |
1856 | Table *h = hvalue(s2v(ra)); | 1857 | Table *h = hvalue(s2v(ra)); |
1857 | if (n == 0) | 1858 | if (n == 0) |
1858 | n = cast_int(L->top.p - ra) - 1; /* get up to the top */ | 1859 | n = cast_uint(L->top.p - ra) - 1; /* get up to the top */ |
1859 | else | 1860 | else |
1860 | L->top.p = ci->top.p; /* correct top in case of emergency GC */ | 1861 | L->top.p = ci->top.p; /* correct top in case of emergency GC */ |
1861 | last += n; | 1862 | last += n; |
1862 | if (TESTARG_k(i)) { | 1863 | if (TESTARG_k(i)) { |
1863 | last += GETARG_Ax(*pc) * (MAXARG_vC + 1); | 1864 | last += cast_uint(GETARG_Ax(*pc)) * (MAXARG_vC + 1); |
1864 | pc++; | 1865 | pc++; |
1865 | } | 1866 | } |
1866 | /* when 'n' is known, table should have proper size */ | 1867 | /* when 'n' is known, table should have proper size */ |
@@ -120,8 +120,8 @@ LUAI_FUNC int luaV_tointeger (const TValue *obj, lua_Integer *p, F2Imod mode); | |||
120 | LUAI_FUNC int luaV_tointegerns (const TValue *obj, lua_Integer *p, | 120 | LUAI_FUNC int luaV_tointegerns (const TValue *obj, lua_Integer *p, |
121 | F2Imod mode); | 121 | F2Imod mode); |
122 | LUAI_FUNC int luaV_flttointeger (lua_Number n, lua_Integer *p, F2Imod mode); | 122 | LUAI_FUNC int luaV_flttointeger (lua_Number n, lua_Integer *p, F2Imod mode); |
123 | LUAI_FUNC int luaV_finishget (lua_State *L, const TValue *t, TValue *key, | 123 | LUAI_FUNC lu_byte luaV_finishget (lua_State *L, const TValue *t, TValue *key, |
124 | StkId val, int tag); | 124 | StkId val, lu_byte tag); |
125 | LUAI_FUNC void luaV_finishset (lua_State *L, const TValue *t, TValue *key, | 125 | LUAI_FUNC void luaV_finishset (lua_State *L, const TValue *t, TValue *key, |
126 | TValue *val, int aux); | 126 | TValue *val, int aux); |
127 | LUAI_FUNC void luaV_finishOp (lua_State *L); | 127 | LUAI_FUNC void luaV_finishOp (lua_State *L); |
@@ -32,7 +32,7 @@ typedef struct Mbuffer { | |||
32 | #define luaZ_sizebuffer(buff) ((buff)->buffsize) | 32 | #define luaZ_sizebuffer(buff) ((buff)->buffsize) |
33 | #define luaZ_bufflen(buff) ((buff)->n) | 33 | #define luaZ_bufflen(buff) ((buff)->n) |
34 | 34 | ||
35 | #define luaZ_buffremove(buff,i) ((buff)->n -= (i)) | 35 | #define luaZ_buffremove(buff,i) ((buff)->n -= cast_sizet(i)) |
36 | #define luaZ_resetbuffer(buff) ((buff)->n = 0) | 36 | #define luaZ_resetbuffer(buff) ((buff)->n = 0) |
37 | 37 | ||
38 | 38 | ||
@@ -14,11 +14,11 @@ CWARNSCPP= \ | |||
14 | -Wdisabled-optimization \ | 14 | -Wdisabled-optimization \ |
15 | -Wdouble-promotion \ | 15 | -Wdouble-promotion \ |
16 | -Wmissing-declarations \ | 16 | -Wmissing-declarations \ |
17 | -Wconversion \ | ||
17 | # the next warnings might be useful sometimes, | 18 | # the next warnings might be useful sometimes, |
18 | # but usually they generate too much noise | 19 | # but usually they generate too much noise |
19 | # -Werror \ | 20 | # -Werror \ |
20 | # -pedantic # warns if we use jump tables \ | 21 | # -pedantic # warns if we use jump tables \ |
21 | # -Wconversion \ | ||
22 | # -Wsign-conversion \ | 22 | # -Wsign-conversion \ |
23 | # -Wstrict-overflow=2 \ | 23 | # -Wstrict-overflow=2 \ |
24 | # -Wformat=2 \ | 24 | # -Wformat=2 \ |
diff --git a/manual/manual.of b/manual/manual.of index c7f6904a..93e3a114 100644 --- a/manual/manual.of +++ b/manual/manual.of | |||
@@ -3995,7 +3995,7 @@ The conversion specifiers can only be | |||
3995 | @Char{%p} (inserts a pointer), | 3995 | @Char{%p} (inserts a pointer), |
3996 | @Char{%d} (inserts an @T{int}), | 3996 | @Char{%d} (inserts an @T{int}), |
3997 | @Char{%c} (inserts an @T{int} as a one-byte character), and | 3997 | @Char{%c} (inserts an @T{int} as a one-byte character), and |
3998 | @Char{%U} (inserts a @T{long int} as a @x{UTF-8} byte sequence). | 3998 | @Char{%U} (inserts an @T{unsigned long} as a @x{UTF-8} byte sequence). |
3999 | 3999 | ||
4000 | This function may raise errors due to memory overflow | 4000 | This function may raise errors due to memory overflow |
4001 | or an invalid conversion specifier. | 4001 | or an invalid conversion specifier. |