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 2014/08/05 22:48:37 UTC

[1/2] git commit: https://issues.apache.org/jira/browse/AMQCPP-548 Conflicts: activemq-cpp/src/main/decaf/lang/Integer.cpp

Repository: activemq-cpp
Updated Branches:
  refs/heads/3.8.x 64173c3fc -> 857c9129b


https://issues.apache.org/jira/browse/AMQCPP-548
Conflicts:
	activemq-cpp/src/main/decaf/lang/Integer.cpp


Project: http://git-wip-us.apache.org/repos/asf/activemq-cpp/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-cpp/commit/a5815be1
Tree: http://git-wip-us.apache.org/repos/asf/activemq-cpp/tree/a5815be1
Diff: http://git-wip-us.apache.org/repos/asf/activemq-cpp/diff/a5815be1

Branch: refs/heads/3.8.x
Commit: a5815be1d7afc39842654731bc71523c936dbd43
Parents: 64173c3
Author: Timothy Bish <ta...@gmail.com>
Authored: Tue Aug 5 16:20:56 2014 -0400
Committer: Timothy Bish <ta...@gmail.com>
Committed: Tue Aug 5 16:47:49 2014 -0400

----------------------------------------------------------------------
 activemq-cpp/src/main/decaf/lang/Integer.cpp    | 221 +++++++++----------
 .../src/main/decaf/util/concurrent/Mutex.cpp    |  10 +-
 2 files changed, 108 insertions(+), 123 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/a5815be1/activemq-cpp/src/main/decaf/lang/Integer.cpp
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/main/decaf/lang/Integer.cpp b/activemq-cpp/src/main/decaf/lang/Integer.cpp
index 4d3a11f..fadf6d0 100644
--- a/activemq-cpp/src/main/decaf/lang/Integer.cpp
+++ b/activemq-cpp/src/main/decaf/lang/Integer.cpp
@@ -22,6 +22,7 @@
 #include <decaf/lang/Integer.h>
 #include <decaf/lang/Character.h>
 #include <sstream>
+#include <vector>
 
 using namespace decaf;
 using namespace decaf::lang;
@@ -33,26 +34,26 @@ const int Integer::MAX_VALUE = (int)0x7FFFFFFF;
 const int Integer::MIN_VALUE = (int)0x80000000;
 
 ////////////////////////////////////////////////////////////////////////////////
-Integer::Integer( int value ) :value(value) {
+Integer::Integer(int value) : value(value) {
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-Integer::Integer( const std::string& value ) : value() {
-    this->value = parseInt( value );
+Integer::Integer(const std::string& value) : value() {
+    this->value = parseInt(value);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-int Integer::compareTo( const Integer& i ) const {
+int Integer::compareTo(const Integer& i) const {
     return this->value < i.value ? -1 : this->value == i.value ? 0 : 1;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-int Integer::compareTo( const int& i ) const {
+int Integer::compareTo(const int& i) const {
     return this->value < i ? -1 : this->value == i ? 0 : 1;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-int Integer::bitCount( int value ) {
+int Integer::bitCount(int value) {
 
     if( value == 0 ) {
         return 0;
@@ -72,7 +73,7 @@ int Integer::bitCount( int value ) {
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-int Integer::reverseBytes( int value ) {
+int Integer::reverseBytes(int value) {
 
     if( value == 0 ) {
         return 0;
@@ -88,9 +89,9 @@ int Integer::reverseBytes( int value ) {
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-int Integer::reverse( int value ) {
+int Integer::reverse(int value) {
 
-    if( value == 0 ) {
+    if (value == 0) {
         return 0;
     }
 
@@ -105,73 +106,68 @@ int Integer::reverse( int value ) {
 
 ////////////////////////////////////////////////////////////////////////////////
 std::string Integer::toString() const {
-    return Integer::toString( this->value, 10 );
+    return Integer::toString(this->value, 10);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-std::string Integer::toString( int value ) {
-    return Integer::toString( value, 10 );
+std::string Integer::toString(int value) {
+    return Integer::toString(value, 10);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-std::string Integer::toString( int value, int radix ) {
+std::string Integer::toString(int value, int radix) {
 
-    if( radix < Character::MIN_RADIX || radix > Character::MAX_RADIX ) {
+    if (radix < Character::MIN_RADIX || radix > Character::MAX_RADIX) {
         radix = 10;
     }
 
-    if( value == 0 ) {
+    if (value == 0) {
         return "0";
     }
 
     int count = 2, j = value;
     bool negative = value < 0;
-    if( !negative ) {
+    if (!negative) {
         count = 1;
         j = -value;
     }
 
-    while( (value /= radix) != 0 ) {
+    while ((value /= radix) != 0) {
         count++;
     }
 
     // Save length and allocate a new buffer for the string, add one
     // more for the null character.
     int length = count;
-    char* buffer = new char[length + 1];
+    std::vector<char> buffer(length);
 
     do {
-        int ch = 0 - ( j % radix );
-        if( ch > 9 ) {
+        int ch = 0 - (j % radix);
+        if (ch > 9) {
             ch = ch - 10 + 'a';
         } else {
             ch += '0';
         }
-        buffer[--count] = (char)ch;
-    } while( (j /= radix) != 0 );
+        buffer[--count] = (char) ch;
+    } while ((j /= radix) != 0);
 
-    if( negative ) {
+    if (negative) {
         buffer[0] = '-';
     }
 
-    // Ensure there's a null
-    buffer[length] = 0;
-    std::string result( &buffer[0] );
-    delete [] buffer;
-
-    return result;
+    return std::string(&buffer[0], length);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-std::string Integer::toBinaryString( int value ) {
+std::string Integer::toBinaryString(int value) {
 
     int count = 1;
     int j = value;
 
-    if( value < 0 ) {
+    if (value < 0) {
         count = 32;
     } else {
-        while ( (j >>= 1) != 0) {
+        while ((j >>= 1) != 0) {
             count++;
         }
     }
@@ -179,31 +175,26 @@ std::string Integer::toBinaryString( int value ) {
     // Save length and allocate a new buffer for the string, add one
     // more for the null character.
     int length = count;
-    char* buffer = new char[length + 1];
+    std::vector<char> buffer(length);
 
     do {
-        buffer[--count] = (char)( (value & 1) + '0' );
+        buffer[--count] = (char) ((value & 1) + '0');
         value >>= 1;
-    } while( count > 0 );
-
-    // Ensure there's a null
-    buffer[length] = 0;
-    std::string result( &buffer[0] );
-    delete [] buffer;
+    } while (count > 0);
 
-    return result;
+    return std::string(&buffer[0], length);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-std::string Integer::toOctalString( int value ) {
+std::string Integer::toOctalString(int value) {
 
     int count = 1, j = value;
     unsigned int uvalue = (unsigned int) value;
 
-    if( value < 0 ) {
+    if (value < 0) {
         count = 11;  // (8 * sizeof(value) + 2) / 3;
     } else {
-        while ( (j >>= 3) != 0 ) {
+        while ((j >>= 3) != 0) {
             count++;
         }
     }
@@ -211,31 +202,26 @@ std::string Integer::toOctalString( int value ) {
     // Save length and allocate a new buffer for the string, add one
     // more for the null character.
     int length = count;
-    char* buffer = new char[length + 1];
+    std::vector<char> buffer(length);
 
     do {
-        buffer[--count] = (char)( (uvalue & 7) + '0' );
+        buffer[--count] = (char) ((uvalue & 7) + '0');
         uvalue >>= 3;
-    } while( count > 0 );
+    } while (count > 0);
 
-    // Ensure there's a null
-    buffer[length] = 0;
-    std::string result( &buffer[0] );
-    delete [] buffer;
-
-    return result;
+    return std::string(&buffer[0], length);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-std::string Integer::toHexString( int value ) {
+std::string Integer::toHexString(int value) {
 
     int count = 1;
     int j = value;
 
-    if( value < 0 ) {
+    if (value < 0) {
         count = 8;
     } else {
-        while( (j >>= 4) != 0 ) {
+        while ((j >>= 4) != 0) {
             count++;
         }
     }
@@ -243,36 +229,31 @@ std::string Integer::toHexString( int value ) {
     // Save length and allocate a new buffer for the string, add one
     // more for the null character.
     int length = count;
-    char* buffer = new char[length + 1];
+    std::vector<char> buffer(length);
 
     do {
         int t = value & 15;
-        if( t > 9 ) {
+        if (t > 9) {
             t = t - 10 + 'a';
         } else {
             t += '0';
         }
-        buffer[--count] = (char)t;
+        buffer[--count] = (char) t;
         value >>= 4;
-    } while( count > 0 );
-
-    // Ensure there's a null
-    buffer[length] = 0;
-    std::string result( &buffer[0] );
-    delete [] buffer;
+    } while (count > 0);
 
-    return result;
+    return std::string(&buffer[0], length);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-int Integer::parseInt( const std::string& value ) {
+int Integer::parseInt(const std::string& value) {
     return Integer::parseInt( value, 10 );
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-int Integer::parseInt( const std::string& value, int radix ) {
+int Integer::parseInt(const std::string& value, int radix) {
 
-    if( radix < Character::MIN_RADIX ||
+    if (radix < Character::MIN_RADIX ||
         radix > Character::MAX_RADIX ) {
         throw NumberFormatException(
             __FILE__, __LINE__,
@@ -280,14 +261,14 @@ int Integer::parseInt( const std::string& value, int radix ) {
     }
 
     int length = (int)value.length(), i = 0;
-    if( length == 0 ) {
+    if (length == 0) {
         throw NumberFormatException(
             __FILE__, __LINE__,
             "Integer:decode - Invalid: zero length string");
     }
 
     bool negative = value[i] == '-';
-    if( negative && ++i == length ) {
+    if (negative && ++i == length) {
         throw NumberFormatException(
             __FILE__, __LINE__,
             "Integer:decode - Invalid only a minus sign given");
@@ -297,22 +278,20 @@ int Integer::parseInt( const std::string& value, int radix ) {
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-Integer Integer::valueOf( const std::string& value ) {
-
-    return Integer( Integer::parseInt( value ) );
+Integer Integer::valueOf(const std::string& value) {
+    return Integer(Integer::parseInt(value));
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-Integer Integer::valueOf( const std::string& value, int radix ) {
-
-    return Integer( Integer::parseInt( value, radix ) );
+Integer Integer::valueOf(const std::string& value, int radix) {
+    return Integer(Integer::parseInt(value, radix));
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-Integer Integer::decode( const std::string& value ) {
+Integer Integer::decode(const std::string& value) {
 
     int length = (int)value.length(), i = 0;
-    if( length == 0 ) {
+    if (length == 0) {
         throw NumberFormatException(
             __FILE__, __LINE__,
             "Integer:decode - Invalid zero size string");
@@ -320,8 +299,8 @@ Integer Integer::decode( const std::string& value ) {
 
     char firstDigit = value[i];
     bool negative = firstDigit == '-';
-    if( negative ) {
-        if( length == 1 ) {
+    if (negative) {
+        if (length == 1) {
             throw NumberFormatException(
                 __FILE__, __LINE__,
                 "Integer:decode - Invalid zero string, minus only");
@@ -331,12 +310,12 @@ Integer Integer::decode( const std::string& value ) {
     }
 
     int base = 10;
-    if( firstDigit == '0' ) {
-        if( ++i == length ) {
-            return valueOf( 0 );
+    if (firstDigit == '0') {
+        if (++i == length) {
+            return valueOf(0);
         }
 
-        if( ( firstDigit = value[i] ) == 'x' || firstDigit == 'X' ) {
+        if ((firstDigit = value[i]) == 'x' || firstDigit == 'X') {
             if( i == length ) {
                 throw NumberFormatException(
                     __FILE__, __LINE__,
@@ -347,7 +326,7 @@ Integer Integer::decode( const std::string& value ) {
         } else {
             base = 8;
         }
-    } else if( firstDigit == '#' ) {
+    } else if (firstDigit == '#') {
         if( i == length ) {
             throw NumberFormatException(
                 __FILE__, __LINE__,
@@ -357,32 +336,32 @@ Integer Integer::decode( const std::string& value ) {
         base = 16;
     }
 
-    int result = parse( value, i, base, negative );
-    return valueOf( result );
+    int result = parse(value, i, base, negative);
+    return valueOf(result);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-int Integer::parse( const std::string& value, int offset, int radix, bool negative ) {
+int Integer::parse(const std::string& value, int offset, int radix, bool negative) {
 
     int max = Integer::MIN_VALUE / radix;
-    int result = 0, length = (int)value.size();
+    int result = 0, length = (int) value.size();
 
-    while( offset < length ) {
-        int digit = Character::digit( value[offset++], radix );
-        if( digit == -1 ) {
+    while (offset < length) {
+        int digit = Character::digit(value[offset++], radix);
+        if (digit == -1) {
             throw NumberFormatException(
                 __FILE__, __LINE__,
                 "Integer::parse - number string is invalid: ",
                 value.c_str() );
         }
-        if( max > result ) {
+        if (max > result) {
             throw NumberFormatException(
                 __FILE__, __LINE__,
                 "Integer::parse - number string is invalid: ",
                 value.c_str() );
         }
         int next = result * radix - digit;
-        if( next > result ) {
+        if (next > result) {
             throw NumberFormatException(
                 __FILE__, __LINE__,
                 "Integer::parse - number string is invalid: ",
@@ -390,9 +369,9 @@ int Integer::parse( const std::string& value, int offset, int radix, bool negati
         }
         result = next;
     }
-    if( !negative ) {
+    if (!negative) {
         result = -result;
-        if( result < 0 ) {
+        if (result < 0) {
             throw NumberFormatException(
                 __FILE__, __LINE__,
                 "Integer::parse - number string is invalid: ",
@@ -403,74 +382,74 @@ int Integer::parse( const std::string& value, int offset, int radix, bool negati
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-int Integer::highestOneBit( int value ) {
+int Integer::highestOneBit(int value) {
 
-    if( value == 0 ) {
+    if (value == 0) {
         return 0;
     }
 
-    unsigned int uvalue = (unsigned int)value;
+    unsigned int uvalue = (unsigned int) value;
 
     uvalue |= (uvalue >> 1);
     uvalue |= (uvalue >> 2);
     uvalue |= (uvalue >> 4);
     uvalue |= (uvalue >> 8);
     uvalue |= (uvalue >> 16);
-    return ( uvalue & ~(uvalue >> 1));
+    return (uvalue & ~(uvalue >> 1));
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-int Integer::lowestOneBit( int value ) {
-    if( value == 0 ) {
+int Integer::lowestOneBit(int value) {
+    if (value == 0) {
         return 0;
     }
 
-    unsigned int uvalue = (unsigned int)value;
-    return ( uvalue & (-uvalue) );
+    unsigned int uvalue = (unsigned int) value;
+    return (uvalue & (-uvalue));
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-int Integer::numberOfLeadingZeros( int value ) {
+int Integer::numberOfLeadingZeros(int value) {
 
-    if( value == 0 ) {
+    if (value == 0) {
         return 0;
     }
 
-    unsigned int uvalue = (unsigned int)value;
+    unsigned int uvalue = (unsigned int) value;
 
     value |= value >> 1;
     value |= value >> 2;
     value |= value >> 4;
     value |= value >> 8;
     value |= value >> 16;
-    return Integer::bitCount( ~uvalue );
+    return Integer::bitCount(~uvalue);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-int Integer::numberOfTrailingZeros( int value ) {
-    if( value == 0 ) {
+int Integer::numberOfTrailingZeros(int value) {
+    if (value == 0) {
         return 0;
     }
 
-    unsigned int uvalue = (unsigned int)value;
-    return bitCount( (uvalue & -uvalue) - 1 );
+    unsigned int uvalue = (unsigned int) value;
+    return bitCount((uvalue & -uvalue) - 1);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-int Integer::rotateLeft( int value, int distance ) {
-    unsigned int i = (unsigned int)value;
+int Integer::rotateLeft(int value, int distance) {
+    unsigned int i = (unsigned int) value;
     int j = distance & 0x1F;
-    return ( i << j ) | ( i >> (-j & 0x1F ) );
+    return (i << j) | (i >> (-j & 0x1F));
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-int Integer::rotateRight( int value, int distance ) {
-    unsigned int i = (unsigned int)value;
+int Integer::rotateRight(int value, int distance) {
+    unsigned int i = (unsigned int) value;
     int j = distance & 0x1F;
-    return ( i >> j ) | ( i << (-j & 0x1F ) );
+    return (i >> j) | (i << (-j & 0x1F));
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-int Integer::signum( int value ) {
-    return ( value == 0 ? 0 : ( value < 0 ? -1 : 1 ) );
+int Integer::signum(int value) {
+    return (value == 0 ? 0 : (value < 0 ? -1 : 1));
 }

http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/a5815be1/activemq-cpp/src/main/decaf/util/concurrent/Mutex.cpp
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/main/decaf/util/concurrent/Mutex.cpp b/activemq-cpp/src/main/decaf/util/concurrent/Mutex.cpp
index 284cae7..3d74383 100644
--- a/activemq-cpp/src/main/decaf/util/concurrent/Mutex.cpp
+++ b/activemq-cpp/src/main/decaf/util/concurrent/Mutex.cpp
@@ -45,12 +45,18 @@ namespace concurrent {
     public:
 
         MutexProperties() : monitor(NULL), name() {
-            this->name = DEFAULT_NAME_PREFIX + Integer::toString( ++id );
+            std::string idStr = Integer::toString(++id);
+            this->name.reserve(DEFAULT_NAME_PREFIX.length() + idStr.length());
+            this->name.append(DEFAULT_NAME_PREFIX);
+            this->name.append(idStr);
         }
 
         MutexProperties(const std::string& name) : monitor(NULL), name(name) {
             if (this->name.empty()) {
-                this->name = DEFAULT_NAME_PREFIX + Integer::toString(++id);
+                std::string idStr = Integer::toString(++id);
+                this->name.reserve(DEFAULT_NAME_PREFIX.length() + idStr.length());
+                this->name.append(DEFAULT_NAME_PREFIX);
+                this->name.append(idStr);
             }
         }
 


[2/2] git commit: Remove tests that can deadlock.

Posted by ta...@apache.org.
Remove tests that can deadlock.

Project: http://git-wip-us.apache.org/repos/asf/activemq-cpp/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-cpp/commit/857c9129
Tree: http://git-wip-us.apache.org/repos/asf/activemq-cpp/tree/857c9129
Diff: http://git-wip-us.apache.org/repos/asf/activemq-cpp/diff/857c9129

Branch: refs/heads/3.8.x
Commit: 857c9129b1a1f2e1e9bb1d08ac1293953776b141
Parents: a5815be
Author: Timothy Bish <ta...@gmail.com>
Authored: Tue Aug 5 16:48:19 2014 -0400
Committer: Timothy Bish <ta...@gmail.com>
Committed: Tue Aug 5 16:48:19 2014 -0400

----------------------------------------------------------------------
 activemq-cpp/src/test/decaf/lang/ThreadTest.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/857c9129/activemq-cpp/src/test/decaf/lang/ThreadTest.h
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/test/decaf/lang/ThreadTest.h b/activemq-cpp/src/test/decaf/lang/ThreadTest.h
index 7a2db16..e1318d1 100644
--- a/activemq-cpp/src/test/decaf/lang/ThreadTest.h
+++ b/activemq-cpp/src/test/decaf/lang/ThreadTest.h
@@ -48,7 +48,7 @@ namespace lang{
       CPPUNIT_TEST( testCurrentThread );
       CPPUNIT_TEST( testInterrupt );
       CPPUNIT_TEST( testInterrupted );
-      CPPUNIT_TEST( testIsInterrupted );
+      //CPPUNIT_TEST( testIsInterrupted );
       CPPUNIT_TEST( testSetName );
       CPPUNIT_TEST( testInterruptSleep );
       CPPUNIT_TEST( testInterruptJoin );