Skip to content

Commit d3393a8

Browse files
committed
FIX: avoiding some of conversion warnings in VS under 64 bit build
1 parent a1ce4bd commit d3393a8

27 files changed

+69
-44
lines changed

src/core/b-init.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ static void Set_Option_String(REBCHR *str, REBCNT field)
744744
REBVAL *val;
745745
if (str) {
746746
val = Get_System(SYS_OPTIONS, field);
747-
Set_String(val, Copy_OS_Str(str, LEN_STR(str)));
747+
Set_String(val, Copy_OS_Str(str, (REBINT)LEN_STR(str)));
748748
}
749749
}
750750

@@ -756,7 +756,7 @@ static REBCNT Set_Option_Word(REBCHR *str, REBCNT field)
756756
REBCNT n = 0;
757757

758758
if (str) {
759-
n = LEN_STR(str); // WC correct
759+
n = (REBCNT)LEN_STR(str); // WC correct
760760
if (n > 38) return 0;
761761
bp = &buf[0];
762762
while ((*bp++ = (REBYTE)*str++)); // clips unicode
@@ -834,22 +834,22 @@ static REBCNT Set_Option_Word(REBCHR *str, REBCNT field)
834834

835835
if (NZ(data = OS_GET_LOCALE(0))) {
836836
val = Get_System(SYS_LOCALE, LOCALE_LANGUAGE);
837-
Set_String(val, Copy_OS_Str(data, LEN_STR(data)));
837+
Set_String(val, Copy_OS_Str(data, (REBINT)LEN_STR(data)));
838838
}
839839

840840
if (NZ(data = OS_GET_LOCALE(1))) {
841841
val = Get_System(SYS_LOCALE, LOCALE_LANGUAGE_P);
842-
Set_String(val, Copy_OS_Str(data, LEN_STR(data)));
842+
Set_String(val, Copy_OS_Str(data, (REBINT)LEN_STR(data)));
843843
}
844844

845845
if (NZ(data = OS_GET_LOCALE(2))) {
846846
val = Get_System(SYS_LOCALE, LOCALE_LOCALE);
847-
Set_String(val, Copy_OS_Str(data, LEN_STR(data)));
847+
Set_String(val, Copy_OS_Str(data, (REBINT)LEN_STR(data)));
848848
}
849849

850850
if (NZ(data = OS_GET_LOCALE(3))) {
851851
val = Get_System(SYS_LOCALE, LOCALE_LOCALE_P);
852-
Set_String(val, Copy_OS_Str(data, LEN_STR(data)));
852+
Set_String(val, Copy_OS_Str(data, (REBINT)LEN_STR(data)));
853853
}
854854
}
855855

src/core/c-do.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1728,7 +1728,7 @@ x*/ static REBINT Do_Args_Light(REBVAL *func, REBVAL *path, REBSER *block, REBCN
17281728
// Saved_State is safe.
17291729
Saved_State = Halt_State;
17301730

1731-
code = Scan_Source(text, LEN_BYTES(text));
1731+
code = Scan_Source(text, (REBCNT)LEN_BYTES(text));
17321732
SAVE_SERIES(code);
17331733

17341734
// Bind into lib or user spaces?

src/core/c-word.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@
206206

207207
//REBYTE *sss = Get_Sym_Name(1); // (Debugging method)
208208

209-
if (len == 0) len = LEN_BYTES(str);
209+
if (len == 0) len = (REBCNT)LEN_BYTES(str);
210210

211211
// If hash part of word table is too dense, expand it:
212212
if (PG_Word_Table.series->tail > PG_Word_Table.hashes->tail/2)
@@ -381,7 +381,7 @@
381381
if (VAL_WORD_CANON(s) == VAL_WORD_CANON(t)) return 0;
382382

383383
// They must be differ by case:
384-
return Compare_UTF8(sp, tp, LEN_BYTES(tp)) + 2;
384+
return Compare_UTF8(sp, tp, (REBCNT)LEN_BYTES(tp)) + 2;
385385
}
386386

387387

src/core/d-crash.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ enum Crash_Msg_Nums {
9494

9595
// Use the above string or the boot string for the error (in boot.r):
9696
msg = (REBYTE*)(n >= 0 ? Crash_Msgs[n] : BOOT_STR(RS_ERROR, id - RP_STR_BASE - 1));
97-
Form_Var_Args(buf + LEN_BYTES(buf), CRASH_BUF_SIZE - 1 - LEN_BYTES(buf), msg, args);
97+
Form_Var_Args(buf + LEN_BYTES(buf), (REBCNT)(CRASH_BUF_SIZE - 1 - LEN_BYTES(buf)), msg, args);
9898

9999
APPEND_BYTES(buf, Crash_Msgs[CM_CONTACT], CRASH_BUF_SIZE);
100100

src/core/d-print.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ static REBREQ *Req_SIO;
101101
if (!bp) Crash(RP_NO_PRINT_PTR);
102102

103103
// Determine length if not provided:
104-
if (len == UNKNOWN) len = uni ? wcslen(up) : LEN_BYTES(bp);
104+
if (len == UNKNOWN) len = (REBINT)(uni ? wcslen(up) : LEN_BYTES(bp));
105105

106106
SET_FLAG(Req_SIO->flags, RRF_FLUSH);
107107

@@ -223,7 +223,7 @@ static REBREQ *Req_SIO;
223223
if (Trace_Limit > 0) {
224224
if (Trace_Buffer->tail >= Trace_Limit)
225225
Remove_Series(Trace_Buffer, 0, 2000);
226-
if (len == UNKNOWN) len = uni ? wcslen(up) : LEN_BYTES(bp);
226+
if (len == UNKNOWN) len = (REBINT)(uni ? wcslen(up) : LEN_BYTES(bp));
227227
// !!! account for unicode!
228228
for (; len > 0; len--) {
229229
uc = uni ? *up++ : *bp++;
@@ -443,7 +443,7 @@ static REBREQ *Req_SIO;
443443
tail = bp - STR_HEAD(buf);
444444

445445
for (n = 0; n < tail; n += len) {
446-
len = LEN_BYTES(STR_SKIP(buf, n));
446+
len = (REBCNT)LEN_BYTES(STR_SKIP(buf, n));
447447
if (len > 1024) len = 1024;
448448
Debug_String(STR_SKIP(buf, n), len, 0, 0);
449449
}
@@ -717,10 +717,10 @@ static REBREQ *Req_SIO;
717717
case 's':
718718
cp = va_arg(args, REBYTE *);
719719
if ((REBUPT)cp < 100) cp = (REBYTE*)Bad_Ptr;
720-
if (pad == 1) pad = LEN_BYTES(cp);
720+
if (pad == 1) pad = (REBINT)LEN_BYTES(cp);
721721
if (pad < 0) {
722722
pad = -pad;
723-
pad -= LEN_BYTES(cp);
723+
pad -= (REBINT)LEN_BYTES(cp);
724724
for (; pad > 0 && len < max; len++, pad--) *bp++ = ' ';
725725
}
726726
for (; *cp && len < max && pad > 0; pad--, len++) *bp++ = *cp++;

src/core/f-math.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@
231231
***********************************************************************/
232232
{
233233
INT_TO_STR(val, buf);
234-
return LEN_BYTES(buf);
234+
return (REBINT)LEN_BYTES(buf);
235235
}
236236

237237

src/core/f-qsort.c

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
#ifdef _MSC_VER
2+
#pragma warning(push)
3+
#pragma warning(disable:4267) /* conversion from 'size_t' to 'int', possible loss of data */
4+
#endif
15
/* This file was downloaded from
26
* https://raw.github.com/android/platform_bionic/master/libc/upstream-freebsd/lib/libc/stdlib/qsort.c
37
*/
@@ -212,3 +216,7 @@ loop: SWAPINIT(a, es);
212216
}
213217
/* qsort(pn - r, r / es, es, cmp);*/
214218
}
219+
220+
#ifdef _MSC_VER
221+
#pragma warning(pop)
222+
#endif

src/core/f-stubs.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@
869869
REBCHR str[100];
870870

871871
OS_FORM_ERROR(errnum, str, 100);
872-
Set_String(DS_RETURN, Copy_OS_Str(str, LEN_STR(str)));
872+
Set_String(DS_RETURN, Copy_OS_Str(str, (REBINT)LEN_STR(str)));
873873
return DS_RETURN;
874874
}
875875

src/core/l-scan.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1589,7 +1589,7 @@ extern REBSER *Scan_Full_Block(SCAN_STATE *scan_state, REBYTE mode_char);
15891589
SCAN_STATE scan_state;
15901590

15911591
Check_Stack();
1592-
if (!len) len = LEN_BYTES(src);
1592+
if (!len) len = (REBCNT)LEN_BYTES(src);
15931593
Init_Scan_State(&scan_state, src, len);
15941594
return Scan_Code(&scan_state, 0);
15951595
}

src/core/n-io.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -811,15 +811,15 @@ static REBSER *Read_All_File(char *fname)
811811
REBCHR *eq;
812812
REBSER *blk;
813813

814-
while ((n = LEN_STR(str))) {
814+
while ((n = (REBCNT)LEN_STR(str))) {
815815
len++;
816816
str += n + 1; // next
817817
}
818818

819819
blk = Make_Block(len*2);
820820

821821
str = start;
822-
while (NZ(eq = FIND_CHR(str+1, '=')) && NZ(n = LEN_STR(str))) {
822+
while (NZ(eq = FIND_CHR(str+1, '=')) && NZ(n = (REBCNT)LEN_STR(str))) {
823823
Set_Series(REB_STRING, Append_Value(blk), Copy_OS_Str(str, eq-str));
824824
Set_Series(REB_STRING, Append_Value(blk), Copy_OS_Str(eq+1, n-(eq-str)-1));
825825
str += n + 1; // next
@@ -871,7 +871,7 @@ static REBSER *Read_All_File(char *fname)
871871
REBSER *blk;
872872
REBSER *dir;
873873

874-
while (n = LEN_STR(str)) {
874+
while (n = (REBCNT)LEN_STR(str)) {
875875
len++;
876876
str += n + 1; // next
877877
}
@@ -880,7 +880,7 @@ static REBSER *Read_All_File(char *fname)
880880

881881
// First is a dir path or full file path:
882882
str = start;
883-
n = LEN_STR(str);
883+
n = (REBCNT)LEN_STR(str);
884884

885885
if (len == 1) { // First is full file path
886886
dir = To_REBOL_Path(str, n, -1, 0);
@@ -890,7 +890,7 @@ static REBSER *Read_All_File(char *fname)
890890
dir = To_REBOL_Path(str, n, -1, TRUE);
891891
str += n + 1; // next
892892
len = dir->tail;
893-
while (n = LEN_STR(str)) {
893+
while (n = (REBCNT)LEN_STR(str)) {
894894
dir->tail = len;
895895
Append_Uni_Uni(dir, str, n);
896896
Set_Series(REB_FILE, Append_Value(blk), Copy_String(dir, 0, -1));
@@ -948,7 +948,7 @@ static REBSER *Read_All_File(char *fname)
948948
Set_Block(D_RET, ser);
949949
}
950950
else {
951-
ser = To_REBOL_Path(fr.files, LEN_STR(fr.files), OS_WIDE, 0);
951+
ser = To_REBOL_Path(fr.files, (REBCNT)LEN_STR(fr.files), OS_WIDE, 0);
952952
Set_Series(REB_FILE, D_RET, ser);
953953
}
954954
} else
@@ -1015,7 +1015,7 @@ static REBSER *Read_All_File(char *fname)
10151015
success = OS_SET_ENV(cmd, value);
10161016
if (success) {
10171017
// What function could reuse arg2 as-is?
1018-
Set_String(D_RET, Copy_OS_Str(value, LEN_STR(value)));
1018+
Set_String(D_RET, Copy_OS_Str(value, (REBCNT)LEN_STR(value)));
10191019
return R_RET;
10201020
}
10211021
return R_UNSET;

src/core/p-dir.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
dir->data = (REBYTE*)(&file);
6262

6363
while ((result = OS_DO_DEVICE(dir, RDC_READ)) == 0 && !GET_FLAG(dir->flags, RRF_DONE)) {
64-
len = LEN_STR(file.file.path);
64+
len = (REBCNT)LEN_STR(file.file.path);
6565
if (GET_FLAG(file.modes, RFM_DIR)) len++;
6666
name = Copy_OS_Str(file.file.path, len);
6767
if (GET_FLAG(file.modes, RFM_DIR)) {

src/core/s-crc.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ static REBCNT *CRC_Table;
160160
REBINT hash;
161161
REBCNT ulen;
162162

163-
if (len < 0) len = LEN_BYTES(str);
163+
if (len < 0) len = (REBINT)LEN_BYTES(str);
164164

165165
hash = (REBINT)len + (REBINT)((REBYTE)LO_CASE(*str));
166166

src/core/s-file.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
REBCNT i;
5858

5959
if (len == 0)
60-
len = uni ? wcslen((REBUNI*)bp) : LEN_BYTES((REBYTE*)bp);
60+
len = (REBCNT)(uni ? wcslen((REBUNI*)bp) : LEN_BYTES((REBYTE*)bp));
6161

6262
n = 0;
6363
dst = ((uni == -1) || (uni && Is_Wide((REBUNI*)bp, len)))
@@ -133,7 +133,7 @@
133133
REBCNT l = 0;
134134

135135
if (len == 0)
136-
len = uni ? wcslen((REBUNI*)bp) : LEN_BYTES((REBYTE*)bp);
136+
len = (REBCNT)(uni ? wcslen((REBUNI*)bp) : LEN_BYTES((REBYTE*)bp));
137137

138138
// Prescan for: /c/dir = c:/dir, /vol/dir = //vol/dir, //dir = ??
139139
c = GET_CHAR_UNI(uni, bp, i);

src/core/s-find.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@
268268
***********************************************************************/
269269
{
270270
REBINT c1, c2;
271-
REBCNT l1 = LEN_BYTES(s1);
271+
REBCNT l1 = (REBCNT)LEN_BYTES(s1);
272272
REBINT result = 0;
273273

274274
for (; l1 > 0 && l2 > 0; s1++, s2++, l1--, l2--) {

src/core/s-make.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
{
7575
REBSER *dst;
7676

77-
if (len < 0) len = LEN_BYTES(src);
77+
if (len < 0) len = (REBINT)LEN_BYTES(src);
7878

7979
dst = Make_Binary(len);
8080
memcpy(STR_DATA(dst), src, len);
@@ -426,7 +426,7 @@ x*/ REBCNT Insert_Value(REBSER *series, REBCNT index, REBVAL *item, REBCNT type,
426426
**
427427
***********************************************************************/
428428
{
429-
return Append_Bytes_Len(dst, src, LEN_BYTES(src));
429+
return Append_Bytes_Len(dst, src, (REBCNT)LEN_BYTES(src));
430430
}
431431

432432

@@ -580,7 +580,7 @@ x*/ REBCNT Insert_Value(REBSER *series, REBCNT index, REBVAL *item, REBCNT type,
580580
{
581581
REBSER *ser = BUF_UTF8; // buffer is Unicode width
582582

583-
if (len < 0) len = LEN_BYTES(src);
583+
if (len < 0) len = (REBINT)LEN_BYTES(src);
584584

585585
Resize_Series(ser, len+1); // needs at most this much
586586

src/core/s-ops.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ static REBYTE seed_str[SEED_LEN] = {
324324
break;
325325
case REB_INTEGER:
326326
INT_TO_STR(VAL_INT64(val), dst);
327-
klen = LEN_BYTES(dst);
327+
klen = (REBCNT)LEN_BYTES(dst);
328328
as_is = FALSE;
329329
break;
330330
}

src/core/s-unicode.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ ConversionResult ConvertUTF8toUTF32 (
10521052

10531053
if (len) cnt = *len;
10541054
else {
1055-
cnt = uni ? wcslen((REBUNI*)bp) : LEN_BYTES((REBYTE*)bp);
1055+
cnt = (REBCNT)(uni ? wcslen((REBUNI*)bp) : LEN_BYTES((REBYTE*)bp));
10561056
}
10571057

10581058
for (; max > 0 && cnt > 0; cnt--) {

src/core/t-integer.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@
211211
REBYTE *bp;
212212
REBCNT len;
213213
bp = Get_Word_Name(val);
214-
len = strlen(bp);
214+
len = (REBCNT)strlen(bp);
215215
n = MIN(MAX_HEX_LEN, len);
216216
if (Scan_Hex(bp, &num, n, n) == 0) goto is_bad;
217217
}

src/core/t-tuple.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@
351351
if (IS_ISSUE(arg)) {
352352
REBUNI c;
353353
ap = Get_Word_Name(arg);
354-
len = LEN_BYTES(ap); // UTF-8 len
354+
len = (REBINT)LEN_BYTES(ap); // UTF-8 len
355355
if (len & 1) goto bad_arg; // must have even # of chars
356356
len /= 2;
357357
if (len > MAX_TUPLE) goto bad_arg; // valid even for UTF-8

src/core/t-word.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484

8585
switch (action) {
8686
case A_LENGTHQ:
87-
diff = LEN_BYTES(Get_Sym_Name(VAL_WORD_SYM(val)));
87+
diff = (REBINT)LEN_BYTES(Get_Sym_Name(VAL_WORD_SYM(val)));
8888
if (type != REB_WORD) diff++;
8989
DS_Ret_Int(diff);
9090
break;

src/core/u-jpg.c

+9
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@
4646
//#include "jpeglib.h"
4747
//#include "jerror.h"
4848

49+
#ifdef _MSC_VER
50+
#pragma warning(push)
51+
#pragma warning(disable:4267) /* conversion from 'size_t' to 'long', possible loss of data */
52+
#endif
53+
4954
typedef u32 uinteger32;
5055

5156
/* Expanded data source object for stdio input */
@@ -10848,4 +10853,8 @@ extern void Register_Codec(char *name, codo dispatcher);
1084810853
Register_Codec("jpeg", Codec_JPEG_Image);
1084910854
}
1085010855

10856+
#ifdef _MSC_VER
10857+
#pragma warning(pop)
10858+
#endif
10859+
1085110860
#endif //USE_JPG_CODEC

src/core/u-sha1.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ size_t len;
342342
l=(c->Nl+((SHA_LONG)len<<3))&(SHA_LONG)-1;
343343
if (l < c->Nl) /* overflow */
344344
c->Nh++;
345-
c->Nh+=(len>>29);
345+
c->Nh+=((SHA_LONG)len>>29);
346346
c->Nl=l;
347347

348348
if (c->num != 0)

src/core/u-zlib.c

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
#ifdef _MSC_VER
2+
#pragma warning(push)
3+
#pragma warning(disable:4244) /* conversion from '__int64' to 'Z_uLong', possible loss of data */
4+
#endif
5+
16
#include "sys-zlib.h"
27
#include <stdlib.h>
38

@@ -4283,3 +4288,6 @@ int f;
42834288
/* return Z_OK; */
42844289
/* } */
42854290

4291+
#ifdef _MSC_VER
4292+
#pragma warning(push)
4293+
#endif

0 commit comments

Comments
 (0)