lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nwelln...@apache.org
Subject [1/6] lucy-clownfish git commit: Use size_t for VArray indices
Date Sun, 26 Apr 2015 09:51:30 GMT
Repository: lucy-clownfish
Updated Branches:
  refs/heads/master 36f36eafa -> ba2150d96


Use size_t for VArray indices


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

Branch: refs/heads/master
Commit: 2db62be359d2fb2ab72bc515bbdcb0d9f65362ac
Parents: 36f36ea
Author: Nick Wellnhofer <wellnhofer@aevum.de>
Authored: Thu Apr 23 14:29:16 2015 +0200
Committer: Nick Wellnhofer <wellnhofer@aevum.de>
Committed: Thu Apr 23 14:29:16 2015 +0200

----------------------------------------------------------------------
 runtime/core/Clownfish/Test/TestVArray.c | 10 +++---
 runtime/core/Clownfish/VArray.c          | 51 +++++++++++++--------------
 runtime/core/Clownfish/VArray.cfh        | 28 +++++++--------
 3 files changed, 44 insertions(+), 45 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/2db62be3/runtime/core/Clownfish/Test/TestVArray.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Test/TestVArray.c b/runtime/core/Clownfish/Test/TestVArray.c
index 2e47a67..551121a 100644
--- a/runtime/core/Clownfish/Test/TestVArray.c
+++ b/runtime/core/Clownfish/Test/TestVArray.c
@@ -263,7 +263,7 @@ test_Slice(TestBatchRunner *runner) {
     {
         VArray *wanted = VA_new(0);
         VA_Push(wanted, (Obj*)Str_newf("9"));
-        VArray *slice = VA_Slice(array, 9, UINT32_MAX - 1);
+        VArray *slice = VA_Slice(array, 9, SIZE_MAX - 1);
         TEST_TRUE(runner, VA_Get_Size(slice) == 1, "guard against overflow");
         DECREF(slice);
         DECREF(wanted);
@@ -299,7 +299,7 @@ static void
 S_overflow_Push(void *context) {
     UNUSED_VAR(context);
     VArray *array = VA_new(0);
-    array->cap  = UINT32_MAX;
+    array->cap  = SIZE_MAX;
     array->size = array->cap;
     VA_Push(array, (Obj*)CFISH_TRUE);
 }
@@ -308,7 +308,7 @@ static void
 S_overflow_Unshift(void *context) {
     UNUSED_VAR(context);
     VArray *array = VA_new(0);
-    array->cap  = UINT32_MAX;
+    array->cap  = SIZE_MAX;
     array->size = array->cap;
     VA_Unshift(array, (Obj*)CFISH_TRUE);
 }
@@ -320,7 +320,7 @@ S_overflow_Push_VArray(void *context) {
     array->cap  = 1000000000;
     array->size = array->cap;
     VArray *other = VA_new(0);
-    other->cap  = UINT32_MAX - array->cap + 1;
+    other->cap  = SIZE_MAX - array->cap + 1;
     other->size = other->cap;
     VA_Push_VArray(array, other);
 }
@@ -329,7 +329,7 @@ static void
 S_overflow_Store(void *context) {
     UNUSED_VAR(context);
     VArray *array = VA_new(0);
-    VA_Store(array, UINT32_MAX, (Obj*)CFISH_TRUE);
+    VA_Store(array, SIZE_MAX, (Obj*)CFISH_TRUE);
 }
 
 static void

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/2db62be3/runtime/core/Clownfish/VArray.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/VArray.c b/runtime/core/Clownfish/VArray.c
index b6170d3..f395c6d 100644
--- a/runtime/core/Clownfish/VArray.c
+++ b/runtime/core/Clownfish/VArray.c
@@ -27,17 +27,17 @@
 #include "Clownfish/Util/SortUtils.h"
 
 static CFISH_INLINE void
-SI_grow_by(VArray *self, uint32_t add_size);
+SI_grow_by(VArray *self, size_t add_size);
 
 VArray*
-VA_new(uint32_t capacity) {
+VA_new(size_t capacity) {
     VArray *self = (VArray*)Class_Make_Obj(VARRAY);
     VA_init(self, capacity);
     return self;
 }
 
 VArray*
-VA_init(VArray *self, uint32_t capacity) {
+VA_init(VArray *self, size_t capacity) {
     // Init.
     self->size = 0;
 
@@ -68,7 +68,7 @@ VA_Clone_IMP(VArray *self) {
     VArray *twin = VA_new(self->size);
 
     // Clone each element.
-    for (uint32_t i = 0; i < self->size; i++) {
+    for (size_t i = 0; i < self->size; i++) {
         Obj *elem = self->elems[i];
         if (elem) {
             twin->elems[i] = Obj_Clone(elem);
@@ -88,7 +88,7 @@ VA_Shallow_Copy_IMP(VArray *self) {
     Obj **elems = twin->elems;
     memcpy(elems, self->elems, self->size * sizeof(Obj*));
     twin->size = self->size;
-    for (uint32_t i = 0; i < self->size; i++) {
+    for (size_t i = 0; i < self->size; i++) {
         if (elems[i] != NULL) {
             (void)INCREF(elems[i]);
         }
@@ -111,7 +111,7 @@ VA_Push_VArray_IMP(VArray *self, VArray *other) {
     if (other->size > self->cap - self->size) {
         SI_grow_by(self, other->size);
     }
-    for (uint32_t i = 0, tick = self->size; i < other->size; i++, tick++) {
+    for (size_t i = 0, tick = self->size; i < other->size; i++, tick++) {
         Obj *elem = VA_Fetch(other, i);
         if (elem != NULL) {
             self->elems[tick] = INCREF(elem);
@@ -156,7 +156,7 @@ VA_Shift_IMP(VArray *self) {
 }
 
 Obj*
-VA_Fetch_IMP(VArray *self, uint32_t num) {
+VA_Fetch_IMP(VArray *self, size_t num) {
     if (num >= self->size) {
         return NULL;
     }
@@ -165,9 +165,9 @@ VA_Fetch_IMP(VArray *self, uint32_t num) {
 }
 
 void
-VA_Store_IMP(VArray *self, uint32_t tick, Obj *elem) {
+VA_Store_IMP(VArray *self, size_t tick, Obj *elem) {
     if (tick >= self->cap) {
-        if (tick == UINT32_MAX) {
+        if (tick == SIZE_MAX) {
             THROW(ERR, "Invalid tick");
         }
         SI_grow_by(self, tick + 1 - self->size);
@@ -178,7 +178,7 @@ VA_Store_IMP(VArray *self, uint32_t tick, Obj *elem) {
 }
 
 void
-VA_Grow_IMP(VArray *self, uint32_t capacity) {
+VA_Grow_IMP(VArray *self, size_t capacity) {
     if (capacity > self->cap) {
         self->elems = (Obj**)REALLOCATE(self->elems, capacity * sizeof(Obj*));
         self->cap   = capacity;
@@ -188,7 +188,7 @@ VA_Grow_IMP(VArray *self, uint32_t capacity) {
 }
 
 Obj*
-VA_Delete_IMP(VArray *self, uint32_t num) {
+VA_Delete_IMP(VArray *self, size_t num) {
     Obj *elem = NULL;
     if (num < self->size) {
         elem = self->elems[num];
@@ -198,15 +198,15 @@ VA_Delete_IMP(VArray *self, uint32_t num) {
 }
 
 void
-VA_Excise_IMP(VArray *self, uint32_t offset, uint32_t length) {
+VA_Excise_IMP(VArray *self, size_t offset, size_t length) {
     if (self->size <= offset)              { return; }
     else if (self->size < offset + length) { length = self->size - offset; }
 
-    for (uint32_t i = 0; i < length; i++) {
+    for (size_t i = 0; i < length; i++) {
         DECREF(self->elems[offset + i]);
     }
 
-    uint32_t num_to_move = self->size - (offset + length);
+    size_t num_to_move = self->size - (offset + length);
     memmove(self->elems + offset, self->elems + offset + length,
             num_to_move * sizeof(Obj*));
     self->size -= length;
@@ -218,7 +218,7 @@ VA_Clear_IMP(VArray *self) {
 }
 
 void
-VA_Resize_IMP(VArray *self, uint32_t size) {
+VA_Resize_IMP(VArray *self, size_t size) {
     if (size < self->size) {
         VA_Excise(self, size, self->size - size);
     }
@@ -228,12 +228,12 @@ VA_Resize_IMP(VArray *self, uint32_t size) {
     self->size = size;
 }
 
-uint32_t
+size_t
 VA_Get_Size_IMP(VArray *self) {
     return self->size;
 }
 
-uint32_t
+size_t
 VA_Get_Capacity_IMP(VArray *self) {
     return self->cap;
 }
@@ -264,7 +264,7 @@ VA_Equals_IMP(VArray *self, Obj *other) {
         return false;
     }
     else {
-        for (uint32_t i = 0, max = self->size; i < max; i++) {
+        for (size_t i = 0, max = self->size; i < max; i++) {
             Obj *val       = self->elems[i];
             Obj *other_val = twin->elems[i];
             if ((val && !other_val) || (other_val && !val)) { return false;
}
@@ -277,7 +277,7 @@ VA_Equals_IMP(VArray *self, Obj *other) {
 VArray*
 VA_Gather_IMP(VArray *self, VA_Gather_Test_t test, void *data) {
     VArray *gathered = VA_new(self->size);
-    for (uint32_t i = 0, max = self->size; i < max; i++) {
+    for (size_t i = 0, max = self->size; i < max; i++) {
         if (test(self, i, data)) {
             Obj *elem = self->elems[i];
             VA_Push(gathered, elem ? INCREF(elem) : NULL);
@@ -287,13 +287,13 @@ VA_Gather_IMP(VArray *self, VA_Gather_Test_t test, void *data) {
 }
 
 VArray*
-VA_Slice_IMP(VArray *self, uint32_t offset, uint32_t length) {
+VA_Slice_IMP(VArray *self, size_t offset, size_t length) {
     // Adjust ranges if necessary.
     if (offset >= self->size) {
         offset = 0;
         length = 0;
     }
-    else if (length > UINT32_MAX - offset
+    else if (length > SIZE_MAX - offset
              || offset + length > self->size
             ) {
         length = self->size - offset;
@@ -304,7 +304,7 @@ VA_Slice_IMP(VArray *self, uint32_t offset, uint32_t length) {
     slice->size = length;
     Obj **slice_elems = slice->elems;
     Obj **my_elems    = self->elems;
-    for (uint32_t i = 0; i < length; i++) {
+    for (size_t i = 0; i < length; i++) {
         slice_elems[i] = INCREF(my_elems[offset + i]);
     }
 
@@ -312,14 +312,13 @@ VA_Slice_IMP(VArray *self, uint32_t offset, uint32_t length) {
 }
 
 static void
-SI_grow_by(VArray *self, uint32_t add_size) {
+SI_grow_by(VArray *self, size_t add_size) {
     size_t min_size = self->size + add_size;
     // Check for overflow.
-    if ((uint32_t)min_size < add_size) {
+    if (min_size < add_size) {
         THROW(ERR, "Array grew too large");
     }
     size_t new_size = Memory_oversize(min_size, sizeof(Obj*));
-    if (new_size > UINT32_MAX) { new_size = UINT32_MAX; }
-    VA_Grow(self, (uint32_t)new_size);
+    VA_Grow(self, new_size);
 }
 

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/2db62be3/runtime/core/Clownfish/VArray.cfh
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/VArray.cfh b/runtime/core/Clownfish/VArray.cfh
index 69cc71e..a502b12 100644
--- a/runtime/core/Clownfish/VArray.cfh
+++ b/runtime/core/Clownfish/VArray.cfh
@@ -20,7 +20,7 @@ __C__
 #include "Clownfish/Util/SortUtils.h"
 
 typedef bool
-(*CFISH_VA_Gather_Test_t)(cfish_VArray *self, uint32_t tick, void *data);
+(*CFISH_VA_Gather_Test_t)(cfish_VArray *self, size_t tick, void *data);
 
 #ifdef CFISH_USE_SHORT_NAMES
   #define VA_Gather_Test_t CFISH_VA_Gather_Test_t
@@ -32,18 +32,18 @@ __END_C__
 class Clownfish::VArray nickname VA inherits Clownfish::Obj {
 
     Obj      **elems;
-    uint32_t   size;
-    uint32_t   cap;
+    size_t     size;
+    size_t     cap;
 
     inert incremented VArray*
-    new(uint32_t capacity = 0);
+    new(size_t capacity = 0);
 
     /**
      * @param capacity Initial number of elements that the object will be able
      * to hold before reallocation.
      */
     inert VArray*
-    init(VArray *self, uint32_t capacity = 0);
+    init(VArray *self, size_t capacity = 0);
 
     /** Push an item onto the end of a VArray.
      */
@@ -74,31 +74,31 @@ class Clownfish::VArray nickname VA inherits Clownfish::Obj {
      * elements.
      */
     void
-    Grow(VArray *self, uint32_t capacity);
+    Grow(VArray *self, size_t capacity);
 
     /** Fetch the element at <code>tick</tick>.
      */
     nullable Obj*
-    Fetch(VArray *self, uint32_t tick);
+    Fetch(VArray *self, size_t tick);
 
     /** Store an element at index `tick`, possibly displacing an
      * existing element.
      */
     void
-    Store(VArray *self, uint32_t tick, decremented Obj *elem = NULL);
+    Store(VArray *self, size_t tick, decremented Obj *elem = NULL);
 
     /** Replace an element in the VArray with NULL and return it.
      *
      * @return whatever was stored at `tick`.
      */
     incremented nullable Obj*
-    Delete(VArray *self, uint32_t tick);
+    Delete(VArray *self, size_t tick);
 
     /** Remove `length` elements from the array, starting at
      * `offset`. Move elements over to fill in the gap.
      */
     void
-    Excise(VArray *self, uint32_t offset, uint32_t length);
+    Excise(VArray *self, size_t offset, size_t length);
 
     /** Clone the VArray but merely increment the refcounts of its elements
      * rather than clone them.
@@ -127,7 +127,7 @@ class Clownfish::VArray nickname VA inherits Clownfish::Obj {
      * than the current size, decrement and discard truncated elements.
      */
     void
-    Resize(VArray *self, uint32_t size);
+    Resize(VArray *self, size_t size);
 
     /** Empty the VArray.
      */
@@ -136,12 +136,12 @@ class Clownfish::VArray nickname VA inherits Clownfish::Obj {
 
     /** Accessor for `size` member.
      */
-    public uint32_t
+    public size_t
     Get_Size(VArray *self);
 
     /** Accessor for `capacity` member.
      */
-    uint32_t
+    size_t
     Get_Capacity(VArray *self);
 
     /** Return all elements for which `test` returns true.
@@ -157,7 +157,7 @@ class Clownfish::VArray nickname VA inherits Clownfish::Obj {
      * @param length The maximum number of elements to slice.
      */
     public incremented VArray*
-    Slice(VArray *self, uint32_t offset, uint32_t length);
+    Slice(VArray *self, size_t offset, size_t length);
 
     public bool
     Equals(VArray *self, Obj *other);


Mime
View raw message