lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject git commit: refs/heads/win_fixes_for_0.4 - Fix some minor numerical precision issues.
Date Sun, 20 Jul 2014 00:44:33 GMT
Repository: lucy
Updated Branches:
  refs/heads/win_fixes_for_0.4 [created] 32fd52c86


Fix some minor numerical precision issues.

Casts, type issues, theoretical truncation, sign comparisons... exposed
courtesy of MSVC's warnings.


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

Branch: refs/heads/win_fixes_for_0.4
Commit: 32fd52c861e74095a5772c9a6689e8c90203a9aa
Parents: f8631ab
Author: Marvin Humphrey <marvin@rectangular.com>
Authored: Sun Jul 20 01:42:01 2014 +0100
Committer: Marvin Humphrey <marvin@rectangular.com>
Committed: Sun Jul 20 01:42:01 2014 +0100

----------------------------------------------------------------------
 core/Lucy/Analysis/Normalizer.c        |  4 ++--
 core/Lucy/Search/RangeQuery.c          |  4 ++--
 core/Lucy/Search/SortRule.c            |  2 +-
 core/Lucy/Test/Index/TestTermInfo.c    | 12 ++++++------
 core/Lucy/Test/Search/TestSortSpec.c   |  7 ++++---
 core/Lucy/Test/Search/TestSpan.c       |  8 ++++----
 core/Lucy/Test/Util/TestSortExternal.c |  4 ++--
 core/Lucy/Util/Freezer.c               |  2 +-
 core/Lucy/Util/Json.c                  |  5 ++++-
 9 files changed, 26 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/32fd52c8/core/Lucy/Analysis/Normalizer.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Analysis/Normalizer.c b/core/Lucy/Analysis/Normalizer.c
index 8b5032d..8ea50ba 100644
--- a/core/Lucy/Analysis/Normalizer.c
+++ b/core/Lucy/Analysis/Normalizer.c
@@ -135,10 +135,10 @@ Normalizer_Dump_IMP(Normalizer *self) {
 
     Hash_Store_Utf8(dump, "normalization_form", 18, (Obj*)form);
 
-    BoolNum *case_fold = Bool_singleton(options & UTF8PROC_CASEFOLD);
+    BoolNum *case_fold = Bool_singleton(!!(options & UTF8PROC_CASEFOLD));
     Hash_Store_Utf8(dump, "case_fold", 9, (Obj*)case_fold);
 
-    BoolNum *strip_accents = Bool_singleton(options & UTF8PROC_STRIPMARK);
+    BoolNum *strip_accents = Bool_singleton(!!(options & UTF8PROC_STRIPMARK));
     Hash_Store_Utf8(dump, "strip_accents", 13, (Obj*)strip_accents);
 
     return dump;

http://git-wip-us.apache.org/repos/asf/lucy/blob/32fd52c8/core/Lucy/Search/RangeQuery.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Search/RangeQuery.c b/core/Lucy/Search/RangeQuery.c
index 9b9bbb3..a2c3699 100644
--- a/core/Lucy/Search/RangeQuery.c
+++ b/core/Lucy/Search/RangeQuery.c
@@ -146,8 +146,8 @@ RangeQuery_Deserialize_IMP(RangeQuery *self, InStream *instream) {
     String *field = Freezer_read_string(instream);
     Obj *lower_term = InStream_Read_U8(instream) ? THAW(instream) : NULL;
     Obj *upper_term = InStream_Read_U8(instream) ? THAW(instream) : NULL;
-    bool include_lower = InStream_Read_U8(instream);
-    bool include_upper = InStream_Read_U8(instream);
+    bool include_lower = !!InStream_Read_U8(instream);
+    bool include_upper = !!InStream_Read_U8(instream);
 
     // Init object.
     RangeQuery_init(self, field, lower_term, upper_term, include_lower,

http://git-wip-us.apache.org/repos/asf/lucy/blob/32fd52c8/core/Lucy/Search/SortRule.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Search/SortRule.c b/core/Lucy/Search/SortRule.c
index d904cfb..736205c 100644
--- a/core/Lucy/Search/SortRule.c
+++ b/core/Lucy/Search/SortRule.c
@@ -67,7 +67,7 @@ SortRule_Deserialize_IMP(SortRule *self, InStream *instream) {
     if (ivars->type == SortRule_FIELD) {
         ivars->field = Freezer_read_string(instream);
     }
-    ivars->reverse = InStream_Read_C32(instream);
+    ivars->reverse = !!InStream_Read_C32(instream);
     return self;
 }
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/32fd52c8/core/Lucy/Test/Index/TestTermInfo.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Test/Index/TestTermInfo.c b/core/Lucy/Test/Index/TestTermInfo.c
index 06defd5..fe33c4a 100644
--- a/core/Lucy/Test/Index/TestTermInfo.c
+++ b/core/Lucy/Test/Index/TestTermInfo.c
@@ -40,22 +40,22 @@ test_freqfilepos(TestBatchRunner *runner) {
     TEST_FALSE(runner, LUCY_TInfo_Equals(tinfo, (Obj*)cloned_tinfo),"the clone should be
a separate C struct");
     TEST_INT_EQ(runner, TInfo_Get_Doc_Freq(tinfo), 10, "new sets doc_freq correctly" );
     TEST_INT_EQ(runner, TInfo_Get_Doc_Freq(tinfo), 10, "... doc_freq cloned" );
-    TEST_INT_EQ(runner, TInfo_Get_Post_FilePos(tinfo), 20, "... post_filepos cloned" );
-    TEST_INT_EQ(runner, TInfo_Get_Skip_FilePos(tinfo), 40, "... skip_filepos cloned" );
-    TEST_INT_EQ(runner, TInfo_Get_Lex_FilePos(tinfo),  50, "... lex_filepos cloned" );
+    TEST_INT_EQ(runner, (int)TInfo_Get_Post_FilePos(tinfo), 20, "... post_filepos cloned"
);
+    TEST_INT_EQ(runner, (int)TInfo_Get_Skip_FilePos(tinfo), 40, "... skip_filepos cloned"
);
+    TEST_INT_EQ(runner, (int)TInfo_Get_Lex_FilePos(tinfo),  50, "... lex_filepos cloned"
);
 
     TInfo_Set_Doc_Freq(tinfo, 5);
     TEST_INT_EQ(runner, TInfo_Get_Doc_Freq(tinfo), 5,  "set/get doc_freq" );
     TEST_INT_EQ(runner, TInfo_Get_Doc_Freq(cloned_tinfo), 10, "setting orig doesn't affect
clone" );
 
     TInfo_Set_Post_FilePos(tinfo, 15);
-    TEST_INT_EQ(runner, TInfo_Get_Post_FilePos(tinfo), 15, "set/get post_filepos" );
+    TEST_INT_EQ(runner, (int)TInfo_Get_Post_FilePos(tinfo), 15, "set/get post_filepos" );
 
     TInfo_Set_Skip_FilePos(tinfo, 35);
-    TEST_INT_EQ(runner, TInfo_Get_Skip_FilePos(tinfo), 35, "set/get skip_filepos" );
+    TEST_INT_EQ(runner, (int)TInfo_Get_Skip_FilePos(tinfo), 35, "set/get skip_filepos" );
 
     TInfo_Set_Lex_FilePos(tinfo, 45);
-    TEST_INT_EQ(runner, TInfo_Get_Lex_FilePos(tinfo), 45, "set/get lex_filepos" );
+    TEST_INT_EQ(runner, (int)TInfo_Get_Lex_FilePos(tinfo), 45, "set/get lex_filepos" );
 
     DECREF(tinfo);
     DECREF(cloned_tinfo);

http://git-wip-us.apache.org/repos/asf/lucy/blob/32fd52c8/core/Lucy/Test/Search/TestSortSpec.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Test/Search/TestSortSpec.c b/core/Lucy/Test/Search/TestSortSpec.c
index 46a43d2..1baea47 100644
--- a/core/Lucy/Test/Search/TestSortSpec.c
+++ b/core/Lucy/Test/Search/TestSortSpec.c
@@ -297,7 +297,8 @@ S_random_int64() {
 static Obj*
 S_random_float32() {
     uint64_t num = TestUtils_random_u64();
-    return (Obj*)Float32_new(CHY_U64_TO_DOUBLE(num) * (10.0 / UINT64_MAX));
+    double d = CHY_U64_TO_DOUBLE(num) * (10.0 / UINT64_MAX);
+    return (Obj*)Float32_new((float)d);
 }
 
 static Obj*
@@ -341,8 +342,8 @@ S_test_sorted_search(IndexSearcher *searcher, String *query,
 
     va_start(args, num_wanted);
     while (NULL != (field = va_arg(args, String*))) {
-        bool        reverse = va_arg(args, int);
-        SortRule *rule    = SortRule_new(SortRule_FIELD, field, reverse);
+        int       reverse = va_arg(args, int);
+        SortRule *rule    = SortRule_new(SortRule_FIELD, field, !!reverse);
         VA_Push(rules, (Obj*)rule);
     }
     va_end(args);

http://git-wip-us.apache.org/repos/asf/lucy/blob/32fd52c8/core/Lucy/Test/Search/TestSpan.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Test/Search/TestSpan.c b/core/Lucy/Test/Search/TestSpan.c
index 520add2..6743f22 100644
--- a/core/Lucy/Test/Search/TestSpan.c
+++ b/core/Lucy/Test/Search/TestSpan.c
@@ -30,18 +30,18 @@ TestSpan_new() {
 
 void 
 test_span_init_values(TestBatchRunner *runner) {
-    Span* span = Span_new(2,3,7);
+    Span* span = Span_new(2,3,7.0);
     TEST_INT_EQ(runner, Span_Get_Offset(span), 2, "get_offset" );
     TEST_INT_EQ(runner, Span_Get_Length(span), 3, "get_length" );
-    TEST_INT_EQ(runner, Span_Get_Weight(span), 7, "get_weight" );
+    TEST_FLOAT_EQ(runner, Span_Get_Weight(span), 7.0, "get_weight" );
 
     Span_Set_Offset(span, 10);
     Span_Set_Length(span, 1);
-    Span_Set_Weight(span, 4);
+    Span_Set_Weight(span, 4.0);
 
     TEST_INT_EQ(runner, Span_Get_Offset(span), 10, "set_offset" );
     TEST_INT_EQ(runner, Span_Get_Length(span), 1, "set_length" );
-    TEST_INT_EQ(runner, Span_Get_Weight(span), 4, "set_weight" );
+    TEST_FLOAT_EQ(runner, Span_Get_Weight(span), 4.0, "set_weight" );
 
     DECREF(span);
 }

http://git-wip-us.apache.org/repos/asf/lucy/blob/32fd52c8/core/Lucy/Test/Util/TestSortExternal.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Test/Util/TestSortExternal.c b/core/Lucy/Test/Util/TestSortExternal.c
index e14de9c..04bf030 100644
--- a/core/Lucy/Test/Util/TestSortExternal.c
+++ b/core/Lucy/Test/Util/TestSortExternal.c
@@ -156,7 +156,7 @@ test_clear_buffer(TestBatchRunner *runner) {
 static void
 S_test_sort(TestBatchRunner *runner, VArray *bytebufs, uint32_t mem_thresh,
             const char *test_name) {
-    uint32_t   size     = VA_Get_Size(bytebufs);
+    int        size     = (int)VA_Get_Size(bytebufs);
     BBSortEx  *sortex   = BBSortEx_new(mem_thresh, NULL);
     ByteBuf  **shuffled = (ByteBuf**)MALLOCATE(size * sizeof(ByteBuf*));
 
@@ -192,7 +192,7 @@ S_test_sort_letters(TestBatchRunner *runner, const char *letters,
     size_t  num_letters = strlen(letters);
     VArray *bytebufs    = VA_new(num_letters);
 
-    for (int i = 0; i < num_letters; ++i) {
+    for (size_t i = 0; i < num_letters; ++i) {
         char ch = letters[i];
         size_t size = ch == '_' ? 0 : 1;
         ByteBuf *bytebuf = BB_new_bytes(&ch, size);

http://git-wip-us.apache.org/repos/asf/lucy/blob/32fd52c8/core/Lucy/Util/Freezer.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/Freezer.c b/core/Lucy/Util/Freezer.c
index 3d3d923..8ad41e5 100644
--- a/core/Lucy/Util/Freezer.c
+++ b/core/Lucy/Util/Freezer.c
@@ -138,7 +138,7 @@ Freezer_deserialize(Obj *obj, InStream *instream) {
     else if (Obj_Is_A(obj, NUM)) {
         if (Obj_Is_A(obj, INTNUM)) {
             if (Obj_Is_A(obj, BOOLNUM)) {
-                bool value = (bool)InStream_Read_U8(instream);
+                bool value = !!InStream_Read_U8(instream);
                 BoolNum *self = (BoolNum*)obj;
                 if (self && self != CFISH_TRUE && self != CFISH_FALSE) {
                     Bool_Dec_RefCount_t super_decref

http://git-wip-us.apache.org/repos/asf/lucy/blob/32fd52c8/core/Lucy/Util/Json.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/Json.c b/core/Lucy/Util/Json.c
index 34ec936..cb8625c 100644
--- a/core/Lucy/Util/Json.c
+++ b/core/Lucy/Util/Json.c
@@ -687,7 +687,10 @@ S_set_error(CharBuf *buf, const char *json, const char *limit, int line,
         const char *end = StrHelp_back_utf8_char(json + 32, json);
         len = end - json;
     }
-    StackString *snippet = SSTR_WRAP_UTF8(json, len);
+    else if (len < 0) {
+        len = 0; // sanity check
+    }
+    StackString *snippet = SSTR_WRAP_UTF8(json, (size_t)len);
     S_append_json_string((String*)snippet, buf);
 
     String *mess = CB_Yield_String(buf);


Mime
View raw message