You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by nw...@apache.org on 2014/11/11 21:01:38 UTC

[1/5] lucy-clownfish git commit: Remove unused variables

Repository: lucy-clownfish
Updated Branches:
  refs/heads/master 92efcd663 -> 79c0784ab


Remove unused variables


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

Branch: refs/heads/master
Commit: aa73df7cd34617c651617d953a9e7f407f568f55
Parents: 92efcd6
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Tue Nov 11 18:47:46 2014 +0100
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Tue Nov 11 18:47:46 2014 +0100

----------------------------------------------------------------------
 compiler/src/CFCPerlClass.c                    | 1 -
 compiler/src/CFCPerlSub.c                      | 3 +--
 compiler/src/CFCPerlTypeMap.c                  | 1 -
 runtime/core/Clownfish/Test/TestHashIterator.c | 2 --
 4 files changed, 1 insertion(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/aa73df7c/compiler/src/CFCPerlClass.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPerlClass.c b/compiler/src/CFCPerlClass.c
index b35b29c..aa3d738 100644
--- a/compiler/src/CFCPerlClass.c
+++ b/compiler/src/CFCPerlClass.c
@@ -229,7 +229,6 @@ CFCPerlClass_exclude_constructor(CFCPerlClass *self) {
 
 CFCPerlMethod**
 CFCPerlClass_method_bindings(CFCClass *klass) {
-    CFCClass       *parent        = CFCClass_get_parent(klass);
     size_t          num_bound     = 0;
     CFCMethod     **fresh_methods = CFCClass_fresh_methods(klass);
     CFCPerlMethod **bound 

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/aa73df7c/compiler/src/CFCPerlSub.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPerlSub.c b/compiler/src/CFCPerlSub.c
index fd508cc..8028882 100644
--- a/compiler/src/CFCPerlSub.c
+++ b/compiler/src/CFCPerlSub.c
@@ -230,8 +230,7 @@ CFCPerlSub_arg_name_list(CFCPerlSub *self) {
     char          *name_list  = CFCUtil_strdup("arg_self");
 
     for (int i = 1; i < num_vars; i++) {
-        CFCVariable *arg_var  = arg_vars[i];
-        const char  *var_name = CFCVariable_micro_sym(arg_vars[i]);
+        const char *var_name = CFCVariable_micro_sym(arg_vars[i]);
         name_list = CFCUtil_cat(name_list, ", arg_", var_name, NULL);
     }
 

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/aa73df7c/compiler/src/CFCPerlTypeMap.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPerlTypeMap.c b/compiler/src/CFCPerlTypeMap.c
index 2a87f43..4189213 100644
--- a/compiler/src/CFCPerlTypeMap.c
+++ b/compiler/src/CFCPerlTypeMap.c
@@ -118,7 +118,6 @@ CFCPerlTypeMap_from_perl(CFCType *type, const char *xs_var) {
 
 char*
 CFCPerlTypeMap_to_perl(CFCType *type, const char *cf_var) {
-    const char *type_str = CFCType_to_c(type);
     char *result = NULL;
 
     if (CFCType_is_object(type)) {

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/aa73df7c/runtime/core/Clownfish/Test/TestHashIterator.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Test/TestHashIterator.c b/runtime/core/Clownfish/Test/TestHashIterator.c
index 0f37be9..4d73f9a 100644
--- a/runtime/core/Clownfish/Test/TestHashIterator.c
+++ b/runtime/core/Clownfish/Test/TestHashIterator.c
@@ -53,8 +53,6 @@ test_Next(TestBatchRunner *runner) {
     VA_Sort(expected, NULL, NULL);
 
     {
-        Obj *key;
-        Obj *value;
         HashIterator *iter = HashIter_new(hash);
         while (HashIter_Next(iter)) {
             Obj *key = HashIter_Get_Key(iter);


[5/5] lucy-clownfish git commit: Check for overflow of VArray size

Posted by nw...@apache.org.
Check for overflow of VArray size


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

Branch: refs/heads/master
Commit: 79c0784ab0b37d384b7d6830579f2f80f7c47a97
Parents: b3132fb
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Tue Nov 11 20:52:03 2014 +0100
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Tue Nov 11 20:54:35 2014 +0100

----------------------------------------------------------------------
 runtime/core/Clownfish/Test/TestVArray.c | 61 ++++++++++++++++++++++++++-
 runtime/core/Clownfish/VArray.c          | 34 +++++++++++----
 2 files changed, 85 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/79c0784a/runtime/core/Clownfish/Test/TestVArray.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Test/TestVArray.c b/runtime/core/Clownfish/Test/TestVArray.c
index f817944..923d637 100644
--- a/runtime/core/Clownfish/Test/TestVArray.c
+++ b/runtime/core/Clownfish/Test/TestVArray.c
@@ -16,6 +16,7 @@
 
 #include <string.h>
 
+#define C_CFISH_VARRAY
 #define CFISH_USE_SHORT_NAMES
 #define TESTCFISH_USE_SHORT_NAMES
 
@@ -293,9 +294,66 @@ test_Clone_and_Shallow_Copy(TestBatchRunner *runner) {
     DECREF(twin);
 }
 
+static void
+S_overflow_Push(void *context) {
+    UNUSED_VAR(context);
+    VArray *array = VA_new(0);
+    array->cap  = UINT32_MAX;
+    array->size = array->cap;
+    VA_Push(array, (Obj*)CFISH_TRUE);
+}
+
+static void
+S_overflow_Unshift(void *context) {
+    UNUSED_VAR(context);
+    VArray *array = VA_new(0);
+    array->cap  = UINT32_MAX;
+    array->size = array->cap;
+    VA_Unshift(array, (Obj*)CFISH_TRUE);
+}
+
+static void
+S_overflow_Push_VArray(void *context) {
+    UNUSED_VAR(context);
+    VArray *array = VA_new(0);
+    array->cap  = 1000000000;
+    array->size = array->cap;
+    VArray *other = VA_new(0);
+    other->cap  = UINT32_MAX - array->cap + 1;
+    other->size = other->cap;
+    VA_Push_VArray(array, other);
+}
+
+static void
+S_overflow_Store(void *context) {
+    UNUSED_VAR(context);
+    VArray *array = VA_new(0);
+    VA_Store(array, UINT32_MAX, (Obj*)CFISH_TRUE);
+}
+
+static void
+S_test_exception(TestBatchRunner *runner, Err_Attempt_t func,
+                 const char *test_name) {
+    Err *error = Err_trap(func, NULL);
+    TEST_TRUE(runner, error != NULL, test_name);
+    DECREF(error);
+}
+
+static void
+test_exceptions(TestBatchRunner *runner) {
+    S_test_exception(runner, S_overflow_Push,
+                     "Push throws on overflow");
+    S_test_exception(runner, S_overflow_Unshift,
+                     "Unshift throws on overflow");
+    S_test_exception(runner, S_overflow_Push_VArray,
+                     "Push_VArray throws on overflow");
+    S_test_exception(runner, S_overflow_Store,
+                     "Store throws on overflow");
+}
+
 void
 TestVArray_Run_IMP(TestVArray *self, TestBatchRunner *runner) {
-    TestBatchRunner_Plan(runner, (TestBatch*)self, 43);
+    TestBatchRunner_Plan(runner, (TestBatch*)self, 47);
     test_Equals(runner);
     test_Store_Fetch(runner);
     test_Push_Pop_Shift_Unshift(runner);
@@ -305,6 +363,7 @@ TestVArray_Run_IMP(TestVArray *self, TestBatchRunner *runner) {
     test_Push_VArray(runner);
     test_Slice(runner);
     test_Clone_and_Shallow_Copy(runner);
+    test_exceptions(runner);
 }
 
 

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/79c0784a/runtime/core/Clownfish/VArray.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/VArray.c b/runtime/core/Clownfish/VArray.c
index 2472084..b6170d3 100644
--- a/runtime/core/Clownfish/VArray.c
+++ b/runtime/core/Clownfish/VArray.c
@@ -26,6 +26,9 @@
 #include "Clownfish/Util/Memory.h"
 #include "Clownfish/Util/SortUtils.h"
 
+static CFISH_INLINE void
+SI_grow_by(VArray *self, uint32_t add_size);
+
 VArray*
 VA_new(uint32_t capacity) {
     VArray *self = (VArray*)Class_Make_Obj(VARRAY);
@@ -97,7 +100,7 @@ VA_Shallow_Copy_IMP(VArray *self) {
 void
 VA_Push_IMP(VArray *self, Obj *element) {
     if (self->size == self->cap) {
-        VA_Grow(self, Memory_oversize(self->size + 1, sizeof(Obj*)));
+        SI_grow_by(self, 1);
     }
     self->elems[self->size] = element;
     self->size++;
@@ -105,18 +108,16 @@ VA_Push_IMP(VArray *self, Obj *element) {
 
 void
 VA_Push_VArray_IMP(VArray *self, VArray *other) {
-    uint32_t tick = self->size;
-    uint32_t new_size = self->size + other->size;
-    if (new_size > self->cap) {
-        VA_Grow(self, Memory_oversize(new_size, sizeof(Obj*)));
+    if (other->size > self->cap - self->size) {
+        SI_grow_by(self, other->size);
     }
-    for (uint32_t i = 0; i < other->size; i++, tick++) {
+    for (uint32_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);
         }
     }
-    self->size = new_size;
+    self->size += other->size;
 }
 
 Obj*
@@ -131,7 +132,7 @@ VA_Pop_IMP(VArray *self) {
 void
 VA_Unshift_IMP(VArray *self, Obj *elem) {
     if (self->size == self->cap) {
-        VA_Grow(self, Memory_oversize(self->size + 1, sizeof(Obj*)));
+        SI_grow_by(self, 1);
     }
     memmove(self->elems + 1, self->elems, self->size * sizeof(Obj*));
     self->elems[0] = elem;
@@ -166,7 +167,10 @@ VA_Fetch_IMP(VArray *self, uint32_t num) {
 void
 VA_Store_IMP(VArray *self, uint32_t tick, Obj *elem) {
     if (tick >= self->cap) {
-        VA_Grow(self, Memory_oversize(tick + 1, sizeof(Obj*)));
+        if (tick == UINT32_MAX) {
+            THROW(ERR, "Invalid tick");
+        }
+        SI_grow_by(self, tick + 1 - self->size);
     }
     if (tick < self->size) { DECREF(self->elems[tick]); }
     else                   { self->size = tick + 1; }
@@ -307,3 +311,15 @@ VA_Slice_IMP(VArray *self, uint32_t offset, uint32_t length) {
     return slice;
 }
 
+static void
+SI_grow_by(VArray *self, uint32_t add_size) {
+    size_t min_size = self->size + add_size;
+    // Check for overflow.
+    if ((uint32_t)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);
+}
+


[3/5] lucy-clownfish git commit: Update .gitignore

Posted by nw...@apache.org.
Update .gitignore


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

Branch: refs/heads/master
Commit: 264a3f3faa67334d54f458dc59b1eebdc2e32435
Parents: 8870dca
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Tue Nov 11 18:59:58 2014 +0100
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Tue Nov 11 20:53:44 2014 +0100

----------------------------------------------------------------------
 runtime/c/.gitignore | 2 ++
 1 file changed, 2 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/264a3f3f/runtime/c/.gitignore
----------------------------------------------------------------------
diff --git a/runtime/c/.gitignore b/runtime/c/.gitignore
index be4fa86..641de1e 100644
--- a/runtime/c/.gitignore
+++ b/runtime/c/.gitignore
@@ -9,6 +9,8 @@
 /cygcfish-*.dll
 /libcfish-*.dll
 /libcfish.*.dylib
+/libcfish.a
+/libcfish.a.*
 /libcfish.dylib
 /libcfish.so
 /libcfish.so.*


[4/5] lucy-clownfish git commit: Use int32_t for HashIterator ticks

Posted by nw...@apache.org.
Use int32_t for HashIterator ticks


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

Branch: refs/heads/master
Commit: b3132fb16145d764107b9c12e3394b271cb2921e
Parents: 264a3f3
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Tue Nov 11 20:51:22 2014 +0100
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Tue Nov 11 20:54:28 2014 +0100

----------------------------------------------------------------------
 runtime/core/Clownfish/Hash.c           | 5 +++++
 runtime/core/Clownfish/HashIterator.cfh | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/b3132fb1/runtime/core/Clownfish/Hash.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Hash.c b/runtime/core/Clownfish/Hash.c
index 403ee1e..ac04562 100644
--- a/runtime/core/Clownfish/Hash.c
+++ b/runtime/core/Clownfish/Hash.c
@@ -320,6 +320,11 @@ Hash_Get_Size_IMP(Hash *self) {
 
 static CFISH_INLINE HashEntry*
 SI_rebuild_hash(Hash *self) {
+    // HashIterator ticks are int32_t.
+    if (self->capacity > INT32_MAX / 2) {
+        THROW(ERR, "Hash grew too large");
+    }
+
     HashEntry *old_entries = (HashEntry*)self->entries;
     HashEntry *entry       = old_entries;
     HashEntry *limit       = old_entries + self->capacity;

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/b3132fb1/runtime/core/Clownfish/HashIterator.cfh
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/HashIterator.cfh b/runtime/core/Clownfish/HashIterator.cfh
index a636504..3e9e1f1 100644
--- a/runtime/core/Clownfish/HashIterator.cfh
+++ b/runtime/core/Clownfish/HashIterator.cfh
@@ -22,7 +22,7 @@ parcel Clownfish;
 
 class Clownfish::HashIterator nickname HashIter inherits Clownfish::Obj {
     Hash    *hash;
-    size_t   tick;
+    int32_t  tick;
     uint32_t capacity;
 
     inert void


[2/5] lucy-clownfish git commit: Fix signed/unsigned comparisons

Posted by nw...@apache.org.
Fix signed/unsigned comparisons


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

Branch: refs/heads/master
Commit: 8870dca9e8c3f1c189301ebe9f769a742cfdabe7
Parents: aa73df7
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Tue Nov 11 18:54:44 2014 +0100
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Tue Nov 11 20:53:37 2014 +0100

----------------------------------------------------------------------
 compiler/src/CFCPerlSub.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/8870dca9/compiler/src/CFCPerlSub.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPerlSub.c b/compiler/src/CFCPerlSub.c
index 8028882..d114521 100644
--- a/compiler/src/CFCPerlSub.c
+++ b/compiler/src/CFCPerlSub.c
@@ -226,10 +226,10 @@ char*
 CFCPerlSub_arg_name_list(CFCPerlSub *self) {
     CFCParamList  *param_list = self->param_list;
     CFCVariable  **arg_vars   = CFCParamList_get_variables(param_list);
-    size_t        num_vars   = CFCParamList_num_vars(param_list);
+    size_t         num_vars   = CFCParamList_num_vars(param_list);
     char          *name_list  = CFCUtil_strdup("arg_self");
 
-    for (int i = 1; i < num_vars; i++) {
+    for (size_t i = 1; i < num_vars; i++) {
         const char *var_name = CFCVariable_micro_sym(arg_vars[i]);
         name_list = CFCUtil_cat(name_list, ", arg_", var_name, NULL);
     }