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/08/12 21:56:17 UTC

[1/2] git commit: Make NumUtil decode functions take const pointers

Repository: lucy-clownfish
Updated Branches:
  refs/heads/const_pointers [created] c8f1158d0


Make NumUtil decode functions take const pointers


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

Branch: refs/heads/const_pointers
Commit: 31c25673bebd449b7916fcc9735f8aecd0606826
Parents: d73098d
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Tue Aug 12 20:48:29 2014 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Tue Aug 12 20:49:29 2014 +0200

----------------------------------------------------------------------
 .../core/Clownfish/Test/Util/TestNumberUtils.c  | 44 ++++++++++---------
 runtime/core/Clownfish/Util/NumberUtils.cfh     | 46 ++++++++++----------
 2 files changed, 46 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/31c25673/runtime/core/Clownfish/Test/Util/TestNumberUtils.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Test/Util/TestNumberUtils.c b/runtime/core/Clownfish/Test/Util/TestNumberUtils.c
index 09dc894..adc529a 100644
--- a/runtime/core/Clownfish/Test/Util/TestNumberUtils.c
+++ b/runtime/core/Clownfish/Test/Util/TestNumberUtils.c
@@ -109,25 +109,26 @@ test_c32(TestBatchRunner *runner) {
     char     *encoded   = (char*)CALLOCATE(amount, sizeof(char));
     char     *target    = encoded;
     char     *limit     = target + amount;
+    const char *decode;
 
     for (set_num = 0; set_num < num_sets; set_num++) {
-        char *skip;
+        const char *skip;
         ints = TestUtils_random_u64s(ints, count,
                                      mins[set_num], limits[set_num]);
         target = encoded;
         for (size_t i = 0; i < count; i++) {
             NumUtil_encode_c32((uint32_t)ints[i], &target);
         }
-        target = encoded;
+        decode = encoded;
         skip   = encoded;
         for (size_t i = 0; i < count; i++) {
-            TEST_INT_EQ(runner, NumUtil_decode_c32(&target), (long)ints[i],
+            TEST_INT_EQ(runner, NumUtil_decode_c32(&decode), (long)ints[i],
                         "c32 %lu", (long)ints[i]);
             NumUtil_skip_cint(&skip);
-            if (target > limit) { THROW(ERR, "overrun"); }
+            if (decode > limit) { THROW(ERR, "overrun"); }
         }
-        TEST_TRUE(runner, skip == target, "skip %lu == %lu",
-                  (unsigned long)skip, (unsigned long)target);
+        TEST_TRUE(runner, skip == decode, "skip %lu == %lu",
+                  (unsigned long)skip, (unsigned long)decode);
 
         target = encoded;
         for (size_t i = 0; i < count; i++) {
@@ -136,22 +137,22 @@ test_c32(TestBatchRunner *runner) {
         TEST_TRUE(runner, target == limit,
                   "padded c32 uses 5 bytes (%lu == %lu)", (unsigned long)target,
                   (unsigned long)limit);
-        target = encoded;
+        decode = encoded;
         skip   = encoded;
         for (size_t i = 0; i < count; i++) {
-            TEST_INT_EQ(runner, NumUtil_decode_c32(&target), (long)ints[i],
+            TEST_INT_EQ(runner, NumUtil_decode_c32(&decode), (long)ints[i],
                         "padded c32 %lu", (long)ints[i]);
             NumUtil_skip_cint(&skip);
-            if (target > limit) { THROW(ERR, "overrun"); }
+            if (decode > limit) { THROW(ERR, "overrun"); }
         }
-        TEST_TRUE(runner, skip == target, "skip padded %lu == %lu",
-                  (unsigned long)skip, (unsigned long)target);
+        TEST_TRUE(runner, skip == decode, "skip padded %lu == %lu",
+                  (unsigned long)skip, (unsigned long)decode);
     }
 
     target = encoded;
     NumUtil_encode_c32(UINT32_MAX, &target);
-    target = encoded;
-    TEST_INT_EQ(runner, NumUtil_decode_c32(&target), UINT32_MAX, "c32 UINT32_MAX");
+    decode = encoded;
+    TEST_INT_EQ(runner, NumUtil_decode_c32(&decode), UINT32_MAX, "c32 UINT32_MAX");
 
     FREEMEM(encoded);
     FREEMEM(ints);
@@ -169,33 +170,34 @@ test_c64(TestBatchRunner *runner) {
     char     *encoded   = (char*)CALLOCATE(amount, sizeof(char));
     char     *target    = encoded;
     char     *limit     = target + amount;
+    const char *decode;
 
     for (set_num = 0; set_num < num_sets; set_num++) {
-        char *skip;
+        const char *skip;
         ints = TestUtils_random_u64s(ints, count,
                                      mins[set_num], limits[set_num]);
         target = encoded;
         for (size_t i = 0; i < count; i++) {
             NumUtil_encode_c64(ints[i], &target);
         }
-        target = encoded;
+        decode = encoded;
         skip   = encoded;
         for (size_t i = 0; i < count; i++) {
-            uint64_t got = NumUtil_decode_c64(&target);
+            uint64_t got = NumUtil_decode_c64(&decode);
             TEST_TRUE(runner, got == ints[i],
                       "c64 %" PRIu64 " == %" PRIu64, got, ints[i]);
-            if (target > limit) { THROW(ERR, "overrun"); }
+            if (decode > limit) { THROW(ERR, "overrun"); }
             NumUtil_skip_cint(&skip);
         }
-        TEST_TRUE(runner, skip == target, "skip %lu == %lu",
-                  (unsigned long)skip, (unsigned long)target);
+        TEST_TRUE(runner, skip == decode, "skip %lu == %lu",
+                  (unsigned long)skip, (unsigned long)decode);
     }
 
     target = encoded;
     NumUtil_encode_c64(UINT64_MAX, &target);
-    target = encoded;
 
-    uint64_t got = NumUtil_decode_c64(&target);
+    decode = encoded;
+    uint64_t got = NumUtil_decode_c64(&decode);
     TEST_TRUE(runner, got == UINT64_MAX, "c64 UINT64_MAX");
 
     FREEMEM(encoded);

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/31c25673/runtime/core/Clownfish/Util/NumberUtils.cfh
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Util/NumberUtils.cfh b/runtime/core/Clownfish/Util/NumberUtils.cfh
index 7589f94..b436d90 100644
--- a/runtime/core/Clownfish/Util/NumberUtils.cfh
+++ b/runtime/core/Clownfish/Util/NumberUtils.cfh
@@ -50,17 +50,17 @@ inert class Clownfish::Util::NumberUtils nickname NumUtil {
     /** Interpret a sequence of bytes as a big-endian unsigned 16-bit int.
      */
     inert inline uint16_t
-    decode_bigend_u16(void *source);
+    decode_bigend_u16(const void *source);
 
     /** Interpret a sequence of bytes as a big-endian unsigned 32-bit int.
      */
     inert inline uint32_t
-    decode_bigend_u32(void *source);
+    decode_bigend_u32(const void *source);
 
     /** Interpret a sequence of bytes as a big-endian unsigned 64-bit int.
      */
     inert inline uint64_t
-    decode_bigend_u64(void *source);
+    decode_bigend_u64(const void *source);
 
     /** Encode a 32-bit floating point number as 4 bytes in the buffer
      * provided, using big-endian byte order.
@@ -78,13 +78,13 @@ inert class Clownfish::Util::NumberUtils nickname NumUtil {
      * byte order.
      */
     inert inline float
-    decode_bigend_f32(void *source);
+    decode_bigend_f32(const void *source);
 
     /** Interpret a sequence of bytes as a 64-bit float stored in big-endian
      * byte order.
      */
     inert inline double
-    decode_bigend_f64(void *source);
+    decode_bigend_f64(const void *source);
 
     /** Encode a C32 at the space pointed to by <code>dest</code>. As a side
      * effect, <code>dest</code> will be advanced to immediately after the end
@@ -113,19 +113,19 @@ inert class Clownfish::Util::NumberUtils nickname NumUtil {
      * C32.
      */
     inert inline uint32_t
-    decode_c32(char **source);
+    decode_c32(const char **source);
 
     /** Read a C64 from the buffer pointed to by <code>source</code>.  As a
      * side effect, advance the pointer, consuming the bytes occupied by the
      * C64.
      */
     inert inline uint64_t
-    decode_c64(char **source);
+    decode_c64(const char **source);
 
     /** Advance <code>source</code> past one encoded C32 or C64.
      */
     inert inline void
-    skip_cint(char **source);
+    skip_cint(const char **source);
 
     /** Interpret <code>array</code> as an array of bits; return true if the
      * bit at <code>tick</code> is set, false otherwise.
@@ -225,15 +225,15 @@ cfish_NumUtil_encode_bigend_u64(uint64_t value, void *dest_ptr) {
 }
 
 static CFISH_INLINE uint16_t
-cfish_NumUtil_decode_bigend_u16(void *source) {
-    uint8_t *const buf = (uint8_t*)source;
+cfish_NumUtil_decode_bigend_u16(const void *source) {
+    const uint8_t *const buf = (const uint8_t*)source;
     return  ((uint16_t)buf[0] << 8) |
             ((uint16_t)buf[1]);
 }
 
 static CFISH_INLINE uint32_t
-cfish_NumUtil_decode_bigend_u32(void *source) {
-    uint8_t *const buf = (uint8_t*)source;
+cfish_NumUtil_decode_bigend_u32(const void *source) {
+    const uint8_t *const buf = (const uint8_t*)source;
     return  ((uint32_t)buf[0]  << 24) |
             ((uint32_t)buf[1]  << 16) |
             ((uint32_t)buf[2]  << 8)  |
@@ -241,8 +241,8 @@ cfish_NumUtil_decode_bigend_u32(void *source) {
 }
 
 static CFISH_INLINE uint64_t
-cfish_NumUtil_decode_bigend_u64(void *source) {
-    uint8_t *const buf = (uint8_t*)source;
+cfish_NumUtil_decode_bigend_u64(const void *source) {
+    const uint8_t *const buf = (const uint8_t*)source;
     uint64_t high_bits = ((uint32_t)buf[0]  << 24) |
                          ((uint32_t)buf[1]  << 16) |
                          ((uint32_t)buf[2]  << 8)  |
@@ -281,7 +281,7 @@ cfish_NumUtil_encode_bigend_f64(double value, void *dest_ptr) {
 }
 
 static CFISH_INLINE float
-cfish_NumUtil_decode_bigend_f32(void *source) {
+cfish_NumUtil_decode_bigend_f32(const void *source) {
     union { float f; uint32_t u32; } duo;
     memcpy(&duo, source, sizeof(float));
 #ifdef CFISH_LITTLE_END
@@ -291,7 +291,7 @@ cfish_NumUtil_decode_bigend_f32(void *source) {
 }
 
 static CFISH_INLINE double
-cfish_NumUtil_decode_bigend_f64(void *source) {
+cfish_NumUtil_decode_bigend_f64(const void *source) {
     union { double d; uint64_t u64; } duo;
     memcpy(&duo, source, sizeof(double));
 #ifdef CFISH_LITTLE_END
@@ -369,8 +369,8 @@ cfish_NumUtil_encode_padded_c32(uint32_t value, char **out_buf) {
     } while (0)
 
 static CFISH_INLINE uint32_t
-cfish_NumUtil_decode_c32(char **source_ptr) {
-    char *source = *source_ptr;
+cfish_NumUtil_decode_c32(const char **source_ptr) {
+    const char *source = *source_ptr;
     uint32_t decoded;
     CFISH_NUMUTIL_DECODE_CINT(decoded, source);
     *source_ptr = source;
@@ -378,8 +378,8 @@ cfish_NumUtil_decode_c32(char **source_ptr) {
 }
 
 static CFISH_INLINE uint64_t
-cfish_NumUtil_decode_c64(char **source_ptr) {
-    char *source = *source_ptr;
+cfish_NumUtil_decode_c64(const char **source_ptr) {
+    const char *source = *source_ptr;
     uint64_t decoded;
     CFISH_NUMUTIL_DECODE_CINT(decoded, source);
     *source_ptr = source;
@@ -387,10 +387,10 @@ cfish_NumUtil_decode_c64(char **source_ptr) {
 }
 
 static CFISH_INLINE void
-cfish_NumUtil_skip_cint(char **source_ptr) {
-    uint8_t *ptr = *(uint8_t**)source_ptr;
+cfish_NumUtil_skip_cint(const char **source_ptr) {
+    const uint8_t *ptr = *(const uint8_t**)source_ptr;
     while ((*ptr++ & 0x80) != 0) { }
-    *source_ptr = (char*)ptr;
+    *source_ptr = (const char*)ptr;
 }
 
 static CFISH_INLINE bool


[2/2] git commit: Make NumUtil uXget functions take const pointers

Posted by nw...@apache.org.
Make NumUtil uXget functions take const pointers


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

Branch: refs/heads/const_pointers
Commit: c8f1158d0007e06812d59be0a1292be6b9e44793
Parents: 31c2567
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Tue Aug 12 21:01:23 2014 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Tue Aug 12 21:01:23 2014 +0200

----------------------------------------------------------------------
 runtime/core/Clownfish/Util/NumberUtils.cfh | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/c8f1158d/runtime/core/Clownfish/Util/NumberUtils.cfh
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Util/NumberUtils.cfh b/runtime/core/Clownfish/Util/NumberUtils.cfh
index b436d90..565359d 100644
--- a/runtime/core/Clownfish/Util/NumberUtils.cfh
+++ b/runtime/core/Clownfish/Util/NumberUtils.cfh
@@ -131,7 +131,7 @@ inert class Clownfish::Util::NumberUtils nickname NumUtil {
      * bit at <code>tick</code> is set, false otherwise.
      */
     inert inline bool
-    u1get(void *array, uint32_t tick);
+    u1get(const void *array, uint32_t tick);
 
     /** Interpret <code>array</code> as an array of bits; set the bit at
      * <code>tick</code>.
@@ -155,7 +155,7 @@ inert class Clownfish::Util::NumberUtils nickname NumUtil {
      * the value at <code>tick</code>.
      */
     inert inline uint8_t
-    u2get(void *array, uint32_t tick);
+    u2get(const void *array, uint32_t tick);
 
     /** Interpret <code>array</code> as an array of two-bit integers; set the
      * element at <code>tick</code> to <code>value</code>.
@@ -167,7 +167,7 @@ inert class Clownfish::Util::NumberUtils nickname NumUtil {
      * the value at <code>tick</code>.
      */
     inert inline uint8_t
-    u4get(void *array, uint32_t tick);
+    u4get(const void *array, uint32_t tick);
 
     /** Interpret <code>array</code> as an array of four-bit integers; set the
      * element at <code>tick</code> to <code>value</code>.
@@ -394,7 +394,7 @@ cfish_NumUtil_skip_cint(const char **source_ptr) {
 }
 
 static CFISH_INLINE bool
-cfish_NumUtil_u1get(void *array, uint32_t tick) {
+cfish_NumUtil_u1get(const void *array, uint32_t tick) {
     uint8_t *const u8bits      = (uint8_t*)array;
     const uint32_t byte_offset = tick >> 3;
     const uint8_t  mask        = cfish_NumUtil_u1masks[tick & 0x7];
@@ -426,7 +426,7 @@ cfish_NumUtil_u1flip(void *array, uint32_t tick) {
 }
 
 static CFISH_INLINE uint8_t
-cfish_NumUtil_u2get(void *array, uint32_t tick) {
+cfish_NumUtil_u2get(const void *array, uint32_t tick) {
     uint8_t *ints  = (uint8_t*)array;
     uint8_t  byte  = ints[(tick >> 2)];
     int      shift = cfish_NumUtil_u2shifts[tick & 0x3];
@@ -446,7 +446,7 @@ cfish_NumUtil_u2set(void *array, uint32_t tick, uint8_t value) {
 
 
 static CFISH_INLINE uint8_t
-cfish_NumUtil_u4get(void *array, uint32_t tick) {
+cfish_NumUtil_u4get(const void *array, uint32_t tick) {
     uint8_t *ints  = (uint8_t*)array;
     uint8_t  byte  = ints[(tick >> 1)];
     int      shift = cfish_NumUtil_u4shifts[(tick & 1)];