You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2016/03/20 06:54:03 UTC

[09/14] lucy-clownfish git commit: Address int warnings in Clownfish core.

Address int warnings in Clownfish core.

Clean up after adding `-Wconversion`.


Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/840567ed
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/840567ed
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/840567ed

Branch: refs/heads/master
Commit: 840567edd83fc137692fb7f4c1661ffca7f33ad0
Parents: 91f0005
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Sat Mar 19 01:17:18 2016 +0000
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sat Mar 19 22:34:21 2016 -0700

----------------------------------------------------------------------
 runtime/core/Clownfish/ByteBuf.c               |  8 +++----
 runtime/core/Clownfish/CharBuf.c               | 25 ++++++++++-----------
 runtime/core/Clownfish/Class.c                 |  6 ++---
 runtime/core/Clownfish/Obj.c                   |  2 +-
 runtime/core/Clownfish/PtrHash.c               |  2 +-
 runtime/core/Clownfish/String.c                |  6 ++---
 runtime/core/Clownfish/Test/TestHash.c         |  6 ++---
 runtime/core/Clownfish/TestHarness/TestUtils.c | 16 ++++++-------
 runtime/core/Clownfish/Util/SortUtils.c        |  8 +++----
 runtime/core/Clownfish/Util/StringHelper.c     |  3 ++-
 10 files changed, 41 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/840567ed/runtime/core/Clownfish/ByteBuf.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/ByteBuf.c b/runtime/core/Clownfish/ByteBuf.c
index 14ede6f..96d31b6 100644
--- a/runtime/core/Clownfish/ByteBuf.c
+++ b/runtime/core/Clownfish/ByteBuf.c
@@ -54,7 +54,7 @@ BB_new(size_t capacity) {
 ByteBuf*
 BB_init(ByteBuf *self, size_t min_cap) {
     // Round up to next multiple of eight.
-    size_t capacity = (min_cap + 7) & ~7;
+    size_t capacity = (min_cap + 7) & ((size_t)~7);
     // Check for overflow.
     if (capacity < min_cap) { capacity = SIZE_MAX; }
 
@@ -73,7 +73,7 @@ BB_new_bytes(const void *bytes, size_t size) {
 ByteBuf*
 BB_init_bytes(ByteBuf *self, const void *bytes, size_t size) {
     // Round up to next multiple of eight.
-    size_t capacity = (size + 7) & ~7;
+    size_t capacity = (size + 7) & ((size_t)~7);
     // Check for overflow.
     if (capacity < size) { capacity = SIZE_MAX; }
 
@@ -174,7 +174,7 @@ char*
 BB_Grow_IMP(ByteBuf *self, size_t min_cap) {
     if (min_cap > self->cap) {
         // Round up to next multiple of eight.
-        size_t capacity = (min_cap + 7) & ~7;
+        size_t capacity = (min_cap + 7) & ((size_t)~7);
         // Check for overflow.
         if (capacity < min_cap) { capacity = SIZE_MAX; }
 
@@ -236,7 +236,7 @@ S_grow_and_oversize(ByteBuf *self, size_t min_size) {
     // Oversize by 25%, but at least eight bytes.
     size_t extra = min_size / 4;
     // Round up to next multiple of eight.
-    extra = (extra + 7) & ~7;
+    extra = (extra + 7) & ((size_t)~7);
 
     size_t capacity = min_size + extra;
     // Check for overflow.

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/840567ed/runtime/core/Clownfish/CharBuf.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/CharBuf.c b/runtime/core/Clownfish/CharBuf.c
index 53541c2..3867249 100644
--- a/runtime/core/Clownfish/CharBuf.c
+++ b/runtime/core/Clownfish/CharBuf.c
@@ -20,6 +20,7 @@
 
 #include "charmony.h"
 
+#include <stddef.h>
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -143,8 +144,8 @@ CB_VCatF_IMP(CharBuf *self, const char *pattern, va_list args) {
         // Consume all characters leading up to a '%'.
         while (slice_end < pattern_end && *slice_end != '%') { slice_end++; }
         if (pattern != slice_end) {
-            size_t size = slice_end - pattern;
-            S_cat_utf8(self, pattern, size);
+            ptrdiff_t size = slice_end - pattern;
+            S_cat_utf8(self, pattern, (size_t)size);
             pattern = slice_end;
         }
 
@@ -173,7 +174,6 @@ CB_VCatF_IMP(CharBuf *self, const char *pattern, va_list args) {
                     break;
                 case 'i': {
                         int64_t val = 0;
-                        size_t size;
                         if (pattern[1] == '8') {
                             val = va_arg(args, int32_t);
                             pattern++;
@@ -189,13 +189,12 @@ CB_VCatF_IMP(CharBuf *self, const char *pattern, va_list args) {
                         else {
                             S_die_invalid_pattern(pattern_start);
                         }
-                        size = sprintf(buf, "%" PRId64, val);
-                        S_cat_utf8(self, buf, size);
+                        int size = sprintf(buf, "%" PRId64, val);
+                        S_cat_utf8(self, buf, (size_t)size);
                     }
                     break;
                 case 'u': {
                         uint64_t val = 0;
-                        size_t size;
                         if (pattern[1] == '8') {
                             val = va_arg(args, uint32_t);
                             pattern += 1;
@@ -211,16 +210,16 @@ CB_VCatF_IMP(CharBuf *self, const char *pattern, va_list args) {
                         else {
                             S_die_invalid_pattern(pattern_start);
                         }
-                        size = sprintf(buf, "%" PRIu64, val);
-                        S_cat_utf8(self, buf, size);
+                        int size = sprintf(buf, "%" PRIu64, val);
+                        S_cat_utf8(self, buf, (size_t)size);
                     }
                     break;
                 case 'f': {
                         if (pattern[1] == '6' && pattern[2] == '4') {
                             double num  = va_arg(args, double);
                             char bigbuf[512];
-                            size_t size = sprintf(bigbuf, "%g", num);
-                            S_cat_utf8(self, bigbuf, size);
+                            int size = sprintf(bigbuf, "%g", num);
+                            S_cat_utf8(self, bigbuf, (size_t)size);
                             pattern += 2;
                         }
                         else {
@@ -231,8 +230,8 @@ CB_VCatF_IMP(CharBuf *self, const char *pattern, va_list args) {
                 case 'x': {
                         if (pattern[1] == '3' && pattern[2] == '2') {
                             unsigned long val = va_arg(args, uint32_t);
-                            size_t size = sprintf(buf, "%.8lx", val);
-                            S_cat_utf8(self, buf, size);
+                            int size = sprintf(buf, "%.8lx", val);
+                            S_cat_utf8(self, buf, (size_t)size);
                             pattern += 2;
                         }
                         else {
@@ -362,7 +361,7 @@ S_grow_and_oversize(CharBuf *self, size_t min_size) {
     // Oversize by 25%, but at least eight bytes.
     size_t extra = min_size / 4;
     // Round up to next multiple of eight.
-    extra = (extra + 7) & ~7;
+    extra = (extra + 7) & ((size_t)(~7));
 
     size_t capacity = min_size + extra;
     if (capacity < min_size) {

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/840567ed/runtime/core/Clownfish/Class.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Class.c b/runtime/core/Clownfish/Class.c
index 60434d2..8c5cdfe 100644
--- a/runtime/core/Clownfish/Class.c
+++ b/runtime/core/Clownfish/Class.c
@@ -84,7 +84,7 @@ Class_bootstrap(const cfish_ParcelSpec *parcel_spec) {
                                 : offsetof(Class, vtable);
         uint32_t class_alloc_size = novel_offset
                                     + spec->num_novel_meths
-                                      * sizeof(cfish_method_t);
+                                      * (uint32_t)sizeof(cfish_method_t);
 
         Class *klass = (Class*)CALLOCATE(class_alloc_size, 1);
 
@@ -158,7 +158,7 @@ Class_bootstrap(const cfish_ParcelSpec *parcel_spec) {
         if (parent) {
             // Copy parent vtable.
             uint32_t parent_vt_size = parent->class_alloc_size
-                                      - offsetof(Class, vtable);
+                                      - (uint32_t)offsetof(Class, vtable);
             memcpy(klass->vtable, parent->vtable, parent_vt_size);
         }
 
@@ -181,7 +181,7 @@ Class_bootstrap(const cfish_ParcelSpec *parcel_spec) {
         for (size_t i = 0; i < spec->num_novel_meths; ++i) {
             const NovelMethSpec *mspec = &novel_specs[num_novel++];
             *mspec->offset = novel_offset;
-            novel_offset += sizeof(cfish_method_t);
+            novel_offset += (uint32_t)sizeof(cfish_method_t);
             Class_Override_IMP(klass, mspec->func, *mspec->offset);
         }
     }

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/840567ed/runtime/core/Clownfish/Obj.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Obj.c b/runtime/core/Clownfish/Obj.c
index 888ebf4..cd52115 100644
--- a/runtime/core/Clownfish/Obj.c
+++ b/runtime/core/Clownfish/Obj.c
@@ -68,7 +68,7 @@ Obj_To_String_IMP(Obj *self) {
 #elif (CHY_SIZEOF_PTR == 8)
     int64_t   iaddress   = CHY_PTR_TO_I64(self);
     uint64_t  address    = (uint64_t)iaddress;
-    uint32_t  address_hi = address >> 32;
+    uint32_t  address_hi = (uint32_t)(address >> 32);
     uint32_t  address_lo = address & 0xFFFFFFFF;
     return Str_newf("%o@0x%x32%x32", Obj_get_class_name(self), address_hi,
                     address_lo);

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/840567ed/runtime/core/Clownfish/PtrHash.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/PtrHash.c b/runtime/core/Clownfish/PtrHash.c
index 9d42622..f1f91b2 100644
--- a/runtime/core/Clownfish/PtrHash.c
+++ b/runtime/core/Clownfish/PtrHash.c
@@ -169,7 +169,7 @@ PtrHash_Fetch(PtrHash *self, void *key) {
 
 static void
 S_resize(PtrHash *self) {
-    size_t old_size = self->end - self->entries;
+    size_t old_size = (size_t)(self->end - self->entries);
     if (old_size > SIZE_MAX / 2 || self->shift == 0) {
         THROW(ERR, "PtrHash size overflow");
     }

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/840567ed/runtime/core/Clownfish/String.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/String.c b/runtime/core/Clownfish/String.c
index ac17bad..f619673 100644
--- a/runtime/core/Clownfish/String.c
+++ b/runtime/core/Clownfish/String.c
@@ -202,7 +202,7 @@ Str_Hash_Sum_IMP(String *self) {
     const StrIter_Next_t next = METHOD_PTR(STRINGITERATOR, CFISH_StrIter_Next);
     int32_t code_point;
     while (STR_OOB != (code_point = next(iter))) {
-        hashvalue = ((hashvalue << 5) + hashvalue) ^ code_point;
+        hashvalue = ((hashvalue << 5) + hashvalue) ^ (size_t)code_point;
     }
 
     return hashvalue;
@@ -404,7 +404,7 @@ Str_Find_IMP(String *self, String *substring) {
 StringIterator*
 Str_Find_Utf8_IMP(String *self, const char *substring, size_t size) {
     const char *ptr = S_memmem(self, substring, size);
-    return ptr ? StrIter_new(self, ptr - self->ptr) : NULL;
+    return ptr ? StrIter_new(self, (size_t)(ptr - self->ptr)) : NULL;
 }
 
 static const char*
@@ -417,7 +417,7 @@ S_memmem(String *self, const char *substring, size_t size) {
     char first_char = substring[0];
 
     // Naive string search.
-    while (NULL != (ptr = (const char*)memchr(ptr, first_char, end - ptr))) {
+    while (NULL != (ptr = (const char*)memchr(ptr, first_char, (size_t)(end - ptr)))) {
         if (memcmp(ptr, substring, size) == 0) { break; }
         ptr++;
     }

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/840567ed/runtime/core/Clownfish/Test/TestHash.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Test/TestHash.c b/runtime/core/Clownfish/Test/TestHash.c
index e3fb0d7..c5c9c1f 100644
--- a/runtime/core/Clownfish/Test/TestHash.c
+++ b/runtime/core/Clownfish/Test/TestHash.c
@@ -83,7 +83,7 @@ test_Store_and_Fetch(TestBatchRunner *runner) {
     TEST_INT_EQ(runner, Hash_Get_Capacity(hash), starting_cap,
                 "Initial capacity sufficient (no rebuilds)");
 
-    for (int32_t i = 0; i < 100; i++) {
+    for (size_t i = 0; i < 100; i++) {
         String *key  = (String*)Vec_Fetch(expected, i);
         Obj    *elem = Hash_Fetch(hash, key);
         Vec_Push(got, (Obj*)INCREF(elem));
@@ -182,10 +182,10 @@ test_stress(TestBatchRunner *runner) {
     Vector   *values;
 
     for (uint32_t i = 0; i < 1000; i++) {
-        String *str = TestUtils_random_string(rand() % 1200);
+        String *str = TestUtils_random_string((size_t)(rand() % 1200));
         while (Hash_Fetch(hash, str)) {
             DECREF(str);
-            str = TestUtils_random_string(rand() % 1200);
+            str = TestUtils_random_string((size_t)(rand() % 1200));
         }
         Hash_Store(hash, str, (Obj*)str);
         Vec_Push(expected, INCREF(str));

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/840567ed/runtime/core/Clownfish/TestHarness/TestUtils.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/TestHarness/TestUtils.c b/runtime/core/Clownfish/TestHarness/TestUtils.c
index b71461d..556d301 100644
--- a/runtime/core/Clownfish/TestHarness/TestUtils.c
+++ b/runtime/core/Clownfish/TestHarness/TestUtils.c
@@ -44,7 +44,7 @@ TestUtils_random_i64s(int64_t *buf, size_t count, int64_t min,
     uint64_t  range = min < limit ? (uint64_t)limit - (uint64_t)min : 0;
     int64_t *ints = buf ? buf : (int64_t*)CALLOCATE(count, sizeof(int64_t));
     for (size_t i = 0; i < count; i++) {
-        ints[i] = min + TestUtils_random_u64() % range;
+        ints[i] = min + (int64_t)(TestUtils_random_u64() % range);
     }
     return ints;
 }
@@ -65,7 +65,7 @@ TestUtils_random_f64s(double *buf, size_t count) {
     double *f64s = buf ? buf : (double*)CALLOCATE(count, sizeof(double));
     for (size_t i = 0; i < count; i++) {
         uint64_t num = TestUtils_random_u64();
-        f64s[i] = CHY_U64_TO_DOUBLE(num) / UINT64_MAX;
+        f64s[i] = CHY_U64_TO_DOUBLE(num) / (double)UINT64_MAX;
     }
     return f64s;
 }
@@ -74,7 +74,7 @@ static int32_t
 S_random_code_point(void) {
     int32_t code_point = 0;
     while (1) {
-        uint8_t chance = (rand() % 9) + 1;
+        uint8_t chance = (uint8_t)((rand() % 9) + 1);
         switch (chance) {
             case 1: case 2: case 3:
                 code_point = rand() % 0x80;
@@ -87,7 +87,7 @@ S_random_code_point(void) {
                 break;
             case 9: {
                     uint64_t num = TestUtils_random_u64();
-                    code_point = (num % (0x10FFFF - 0x10000)) + 0x10000;
+                    code_point = (int32_t)(num % (0x10FFFF - 0x10000)) + 0x10000;
                 }
         }
         if (code_point > 0x10FFFF) {
@@ -148,7 +148,7 @@ TestUtils_time() {
     struct timeval t;
     gettimeofday(&t, NULL);
 
-    return (uint64_t)t.tv_sec * 1000000 + t.tv_usec;
+    return (uint64_t)(t.tv_sec * 1000000 + t.tv_usec);
 }
 
 #else
@@ -172,10 +172,10 @@ TestUtils_usleep(uint64_t microseconds) {
 
 void
 TestUtils_usleep(uint64_t microseconds) {
-    uint32_t seconds = microseconds / 1000000;
+    uint64_t seconds = microseconds / 1000000;
     microseconds %= 1000000;
-    sleep(seconds);
-    usleep(microseconds);
+    sleep((unsigned)seconds);
+    usleep((useconds_t)microseconds);
 }
 
 #else

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/840567ed/runtime/core/Clownfish/Util/SortUtils.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Util/SortUtils.c b/runtime/core/Clownfish/Util/SortUtils.c
index d620098..1fe8b29 100644
--- a/runtime/core/Clownfish/Util/SortUtils.c
+++ b/runtime/core/Clownfish/Util/SortUtils.c
@@ -161,11 +161,11 @@ SI_merge(void *left_vptr,  size_t left_size,
         }
     }
 
-    const size_t left_remaining = left_limit - left_ptr;
-    memcpy(dest, left_ptr, left_remaining);
+    const ptrdiff_t left_remaining = left_limit - left_ptr;
+    memcpy(dest, left_ptr, (size_t)left_remaining);
     dest += left_remaining;
-    const size_t right_remaining = right_limit - right_ptr;
-    memcpy(dest, right_ptr, right_remaining);
+    const ptrdiff_t right_remaining = right_limit - right_ptr;
+    memcpy(dest, right_ptr, (size_t)right_remaining);
 }
 
 

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/840567ed/runtime/core/Clownfish/Util/StringHelper.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Util/StringHelper.c b/runtime/core/Clownfish/Util/StringHelper.c
index 085d8a5..59418b2 100644
--- a/runtime/core/Clownfish/Util/StringHelper.c
+++ b/runtime/core/Clownfish/Util/StringHelper.c
@@ -16,6 +16,7 @@
 
 #define C_CFISH_STRINGHELPER
 #include <string.h>
+#include <stddef.h>
 
 #define CFISH_USE_SHORT_NAMES
 
@@ -70,7 +71,7 @@ StrHelp_to_base36(uint64_t num, void *buffer) {
         num /= 36;
     } while (num > 0);
 
-    size_t size = end - buf;
+    size_t size = (size_t)(end - buf);
     memcpy(buffer, buf, size + 1);
     return size;
 }