You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by tr...@apache.org on 2013/10/09 04:01:07 UTC

svn commit: r1530481 - in /qpid/trunk/qpid/extras/dispatch: src/bitmask.c tests/tool_test.c

Author: tross
Date: Wed Oct  9 02:01:06 2013
New Revision: 1530481

URL: http://svn.apache.org/r1530481
Log:
QPID-5216 - Fixed a couple of bugs in the bitmask module.

Modified:
    qpid/trunk/qpid/extras/dispatch/src/bitmask.c
    qpid/trunk/qpid/extras/dispatch/tests/tool_test.c

Modified: qpid/trunk/qpid/extras/dispatch/src/bitmask.c
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/extras/dispatch/src/bitmask.c?rev=1530481&r1=1530480&r2=1530481&view=diff
==============================================================================
--- qpid/trunk/qpid/extras/dispatch/src/bitmask.c (original)
+++ qpid/trunk/qpid/extras/dispatch/src/bitmask.c Wed Oct  9 02:01:06 2013
@@ -33,7 +33,7 @@ ALLOC_DECLARE(dx_bitmask_t);
 ALLOC_DEFINE(dx_bitmask_t);
 
 #define MASK_INDEX(num)  (num / 64)
-#define MASK_ONEHOT(num) (1 << (num % 64))
+#define MASK_ONEHOT(num) (((uint64_t) 1) << (num % 64))
 #define FIRST_NONE    -1
 #define FIRST_UNKNOWN -2
 
@@ -81,7 +81,7 @@ void dx_bitmask_set_bit(dx_bitmask_t *b,
 {
     assert(bitnum < DX_BITMASK_BITS);
     b->array[MASK_INDEX(bitnum)] |= MASK_ONEHOT(bitnum);
-    if (b->first_set > bitnum)
+    if (b->first_set > bitnum || b->first_set < 0)
         b->first_set = bitnum;
 }
 
@@ -108,7 +108,7 @@ int dx_bitmask_first_set(dx_bitmask_t *b
         for (int i = 0; i < DX_BITMASK_LONGS; i++)
             if (b->array[i]) {
                 for (int j = 0; j < 64; j++)
-                    if ((1 << j) & b->array[i]) {
+                    if ((((uint64_t) 1) << j) & b->array[i]) {
                         b->first_set = i * 64 + j;
                         break;
                     }

Modified: qpid/trunk/qpid/extras/dispatch/tests/tool_test.c
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/extras/dispatch/tests/tool_test.c?rev=1530481&r1=1530480&r2=1530481&view=diff
==============================================================================
--- qpid/trunk/qpid/extras/dispatch/tests/tool_test.c (original)
+++ qpid/trunk/qpid/extras/dispatch/tests/tool_test.c Wed Oct  9 02:01:06 2013
@@ -21,6 +21,8 @@
 #include <stdio.h>
 #include <string.h>
 #include <qpid/dispatch/ctools.h>
+#include <qpid/dispatch/bitmask.h>
+#include "alloc_private.h"
 
 typedef struct item_t {
     DEQ_LINKS(struct item_t);
@@ -188,12 +190,43 @@ static char* test_deq_basic2(void *conte
 }
 
 
+static char* test_bitmask(void *context)
+{
+    dx_bitmask_t *bm;
+    int           num;
+
+    bm = dx_bitmask(0);
+    if (!bm)                            return "Can't allocate a bit mask";
+    if (dx_bitmask_first_set(bm, &num)) return "Expected no first set bit";
+
+    dx_bitmask_set_bit(bm, 3);
+    dx_bitmask_set_bit(bm, 500);
+
+    if (!dx_bitmask_first_set(bm, &num)) return "Expected first set bit";
+    if (num != 3)                        return "Expected first set bit to be 3";
+
+    dx_bitmask_clear_bit(bm, num);
+
+    if (!dx_bitmask_first_set(bm, &num)) return "Expected first set bit (2)";
+    if (num != 500)                      return "Expected first set bit to be 500";
+
+    dx_bitmask_clear_bit(bm, num);
+    if (dx_bitmask_first_set(bm, &num)) return "Expected no first set bit (2)";
+
+    dx_bitmask_free(bm);
+
+    return 0;
+}
+
+
 int tool_tests(void)
 {
     int result = 0;
+    dx_alloc_initialize();
 
     TEST_CASE(test_deq_basic, 0);
     TEST_CASE(test_deq_basic2, 0);
+    TEST_CASE(test_bitmask, 0);
 
     return result;
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org