You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2012/08/06 23:59:07 UTC

svn commit: r1370038 - in /activemq/activemq-cpp/trunk/activemq-cpp/src: main/decaf/util/BitSet.cpp main/decaf/util/BitSet.h test/decaf/util/BitSetTest.cpp

Author: tabish
Date: Mon Aug  6 21:59:06 2012
New Revision: 1370038

URL: http://svn.apache.org/viewvc?rev=1370038&view=rev
Log:
Fix issues with windows because shift right logical is undefined for sizes greater than or equal to the size of the thing being shifted. 

Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/BitSet.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/BitSet.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/BitSetTest.cpp

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/BitSet.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/BitSet.cpp?rev=1370038&r1=1370037&r2=1370038&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/BitSet.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/BitSet.cpp Mon Aug  6 21:59:06 2012
@@ -189,7 +189,7 @@ void BitSet::AND(const BitSet& set) {
 
 ////////////////////////////////////////////////////////////////////////////////
 void BitSet::andNot(const BitSet& set) {
-	unsigned long long* bsBits = set.bits;
+    unsigned long long* bsBits = set.bits;
 
     if (!needClear) {
         return;
@@ -275,7 +275,8 @@ void BitSet::clear(int fromIndex, int to
     int idx1 = fromIndex >> OFFSET;
     int idx2 = (toIndex - 1) >> OFFSET;
     unsigned long long factor1 = (~0ULL) << (fromIndex & RIGHT_BITS);
-    unsigned long long factor2 = (~0ULL) >> (ELM_SIZE - (toIndex & RIGHT_BITS));
+    int shift = (ELM_SIZE - (toIndex & RIGHT_BITS));
+    unsigned long long factor2 = shift < 64 ? (~0ULL) >> shift : (~0ULL);
 
     if (idx1 == idx2) {
         bits[idx1] &= ~(factor1 & factor2);
@@ -396,7 +397,8 @@ void BitSet::flip(int fromIndex, int toI
     int idx1 = fromIndex >> OFFSET;
     int idx2 = (toIndex - 1) >> OFFSET;
     unsigned long long factor1 = (~0ULL) << (fromIndex & RIGHT_BITS);
-    unsigned long long factor2 = (~0ULL) >> (ELM_SIZE - (toIndex & RIGHT_BITS));
+    int shift = (ELM_SIZE - (toIndex & RIGHT_BITS));
+    unsigned long long factor2 = shift < 64 ? (~0ULL) >> shift : (~0ULL);
 
     if (idx1 == idx2) {
         bits[idx1] ^= (factor1 & factor2);
@@ -445,7 +447,8 @@ BitSet BitSet::get(int fromIndex, int to
     int idx1 = fromIndex >> OFFSET;
     int idx2 = (toIndex - 1) >> OFFSET;
     unsigned long long factor1 = (~0ULL) << (fromIndex & RIGHT_BITS);
-    unsigned long long factor2 = (~0ULL) >> (ELM_SIZE - (toIndex & RIGHT_BITS));
+    int shift = (ELM_SIZE - (toIndex & RIGHT_BITS));
+    unsigned long long factor2 = shift < 64 ? (~0ULL) >> shift : (~0ULL);
 
     if (idx1 == idx2) {
         unsigned long long result = (bits[idx1] & (factor1 & factor2)) >> (fromIndex % ELM_SIZE);
@@ -494,7 +497,7 @@ BitSet BitSet::get(int fromIndex, int to
 
 ////////////////////////////////////////////////////////////////////////////////
 bool BitSet::intersects(const BitSet& set) const {
-	unsigned long long* bsBits = set.bits;
+    unsigned long long* bsBits = set.bits;
     int length1 = actualArrayLength;
     int length2 = set.actualArrayLength;
 
@@ -675,7 +678,8 @@ void BitSet::set(int fromIndex, int toIn
     int idx1 = fromIndex >> OFFSET;
     int idx2 = (toIndex - 1) >> OFFSET;
     unsigned long long factor1 = (~0ULL) << (fromIndex & RIGHT_BITS);
-    unsigned long long factor2 = (~0ULL) >> (ELM_SIZE - (toIndex & RIGHT_BITS));
+    int shift = (ELM_SIZE - (toIndex & RIGHT_BITS));
+    unsigned long long factor2 = shift < 64 ? (~0ULL) >> shift : (~0ULL);
 
     if (idx1 == idx2) {
         bits[idx1] |= (factor1 & factor2);
@@ -740,7 +744,7 @@ std::string BitSet::toString() const {
 void BitSet::XOR(const BitSet& set) {
     int setActualLength = set.getActualArrayLength();
     if (setActualLength > bitsSize) {
-    	unsigned long long* tempBits = new unsigned long long[setActualLength];
+        unsigned long long* tempBits = new unsigned long long[setActualLength];
         System::arraycopy(set.bits, 0, tempBits, 0, set.actualArrayLength);
         for (int i = 0; i < actualArrayLength; i++) {
             tempBits[i] ^= bits[i];
@@ -750,7 +754,7 @@ void BitSet::XOR(const BitSet& set) {
         actualArrayLength = setActualLength;
         isLengthActual = !((actualArrayLength > 0) && (bits[actualArrayLength - 1] == 0));
     } else {
-    	unsigned long long* bsBits = set.bits;
+        unsigned long long* bsBits = set.bits;
         for (int i = 0; i < setActualLength; i++) {
             bits[i] ^= bsBits[i];
         }

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/BitSet.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/BitSet.h?rev=1370038&r1=1370037&r2=1370038&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/BitSet.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/BitSet.h Mon Aug  6 21:59:06 2012
@@ -39,9 +39,6 @@ namespace util {
      * bit set, so it may change with implementation. The length of a bit set relates to
      * logical length of a bit set and is defined independently of implementation.
      *
-     * Unless otherwise noted, passing a null parameter to any of the methods in a
-     * BitSet will result in a NullPointerException.
-     *
      * A BitSet is not safe for multi-threaded use without external synchronization.
      *
      * @since 1.0

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/BitSetTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/BitSetTest.cpp?rev=1370038&r1=1370037&r2=1370038&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/BitSetTest.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/BitSetTest.cpp Mon Aug  6 21:59:06 2012
@@ -62,7 +62,7 @@ BitSetTest::~BitSetTest() {
 ////////////////////////////////////////////////////////////////////////////////
 void BitSetTest::setUp() {
 
-	eightbs = BitSet(1);
+    eightbs = BitSet(1);
 
     for (int i = 0; i < 8; i++) {
         eightbs.set(i);
@@ -451,6 +451,11 @@ void BitSetTest::testGetI() {
     CPPUNIT_ASSERT_EQUAL_MESSAGE("Test3: Wrong length,", 0, bs3.length());
     CPPUNIT_ASSERT_EQUAL_MESSAGE("Test3: Wrong size,", 0, bs3.size());
 
+    bs3.set(70);
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("Test3: Wrong length,", 71, bs3.length());
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("Test3: Wrong size,", 128, bs3.size());
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("Test3: Wrong value,", true, bs3.get(70));
+
     BitSet bs4;
     try {
         bs4.get(Integer::MIN_VALUE);
@@ -893,17 +898,17 @@ void BitSetTest::testSetII() {
     bitset.set(29, 29);
 
     {
-        // Test for method void java.util.BitSet.set(int, int)
         // pos1 and pos2 are in the same bitset element
         BitSet bs(16);
         bs.set(5);
         bs.set(15);
         bs.set(7, 11);
         for (int i = 0; i < 7; i++) {
-            if (i == 5)
+            if (i == 5) {
                 CPPUNIT_ASSERT_MESSAGE("Shouldn't have flipped bit " + Integer::toString(i), bs.get(i));
-            else
+            } else {
                 CPPUNIT_ASSERT_MESSAGE("Shouldn't have set bit " + Integer::toString(i), !bs.get(i));
+            }
         }
         for (int i = 7; i < 11; i++) {
             CPPUNIT_ASSERT_MESSAGE("Failed to set bit " + Integer::toString(i), bs.get(i));