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/10/04 16:49:02 UTC
svn commit: r1394099 - in
/activemq/activemq-cpp/branches/activemq-cpp-3.4.x/activemq-cpp/src/main/activemq/wireformat/openwire:
OpenWireFormat.cpp marshal/BaseDataStreamMarshaller.cpp
Author: tabish
Date: Thu Oct 4 14:49:01 2012
New Revision: 1394099
URL: http://svn.apache.org/viewvc?rev=1394099&view=rev
Log:
fix for: https://issues.apache.org/jira/browse/AMQCPP-431
Modified:
activemq/activemq-cpp/branches/activemq-cpp-3.4.x/activemq-cpp/src/main/activemq/wireformat/openwire/OpenWireFormat.cpp
activemq/activemq-cpp/branches/activemq-cpp-3.4.x/activemq-cpp/src/main/activemq/wireformat/openwire/marshal/BaseDataStreamMarshaller.cpp
Modified: activemq/activemq-cpp/branches/activemq-cpp-3.4.x/activemq-cpp/src/main/activemq/wireformat/openwire/OpenWireFormat.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/branches/activemq-cpp-3.4.x/activemq-cpp/src/main/activemq/wireformat/openwire/OpenWireFormat.cpp?rev=1394099&r1=1394098&r2=1394099&view=diff
==============================================================================
--- activemq/activemq-cpp/branches/activemq-cpp-3.4.x/activemq-cpp/src/main/activemq/wireformat/openwire/OpenWireFormat.cpp (original)
+++ activemq/activemq-cpp/branches/activemq-cpp-3.4.x/activemq-cpp/src/main/activemq/wireformat/openwire/OpenWireFormat.cpp Thu Oct 4 14:49:01 2012
@@ -83,7 +83,6 @@ OpenWireFormat::~OpenWireFormat() {
try {
this->destroyMarshalers();
}
- AMQ_CATCH_NOTHROW( ActiveMQException )
AMQ_CATCHALL_NOTHROW()
}
@@ -193,30 +192,34 @@ void OpenWireFormat::marshal( const Poin
dsm->tightMarshal2( this, dataStructure, dataOut, &bs );
} else {
- DataOutputStream* looseOut = dataOut;
- ByteArrayOutputStream* baos = NULL;
- if( !sizePrefixDisabled ) {
- baos = new ByteArrayOutputStream();
- looseOut = new DataOutputStream( baos );
- }
+ if (sizePrefixDisabled) {
+ dataOut->writeByte(type);
+ dsm->looseMarshal(this, dataStructure, dataOut);
+ } else {
- looseOut->writeByte( type );
- dsm->looseMarshal( this, dataStructure, looseOut );
+ ByteArrayOutputStream* baos = new ByteArrayOutputStream();
+ std::auto_ptr<DataOutputStream> looseOut(new DataOutputStream(baos, true));
- if( !sizePrefixDisabled ) {
+ looseOut->writeByte(type);
+ dsm->looseMarshal(this, dataStructure, looseOut.get());
looseOut->close();
- dataOut->writeInt( (int)baos->size() );
- if( baos->size() > 0 ) {
+ // Now the data goes to the transport from out byte buffer.
+ dataOut->writeInt((int) baos->size());
+
+ if (baos->size() > 0) {
std::pair<unsigned char*, int> array = baos->toByteArray();
- dataOut->write( array.first, array.second );
- delete [] array.first;
- }
- // Delete allocated resource
- delete baos;
- delete looseOut;
+ try {
+ dataOut->write(array.first, array.second);
+ } catch (Exception& ex) {
+ delete[] array.first;
+ throw;
+ }
+
+ delete[] array.first;
+ }
}
}
} else {
@@ -311,17 +314,17 @@ commands::DataStructure* OpenWireFormat:
// Ask the DataStreamMarshaller to create a new instance of its
// command so that we can fill in its data.
- DataStructure* data = dsm->createObject();
+ std::auto_ptr<DataStructure> data(dsm->createObject());
if( this->tightEncodingEnabled ) {
BooleanStream bs;
bs.unmarshal( dis );
- dsm->tightUnmarshal( this, data, dis, &bs );
+ dsm->tightUnmarshal( this, data.get(), dis, &bs );
} else {
- dsm->looseUnmarshal( this, data, dis );
+ dsm->looseUnmarshal( this, data.get(), dis );
}
- return data;
+ return data.release();
}
return NULL;
@@ -437,22 +440,20 @@ DataStructure* OpenWireFormat::tightUnma
Integer::toString( dataType ) ).c_str() );
}
- DataStructure* data = dsm->createObject();
+ std::auto_ptr<DataStructure> data(dsm->createObject());
if( data->isMarshalAware() && bs->readBoolean() ) {
-
dis->readInt();
dis->readByte();
BooleanStream bs2;
bs2.unmarshal( dis );
- dsm->tightUnmarshal( this, data, dis, &bs2 );
-
+ dsm->tightUnmarshal( this, data.get(), dis, &bs2 );
} else {
- dsm->tightUnmarshal( this, data, dis, bs );
+ dsm->tightUnmarshal( this, data.get(), dis, bs );
}
- return data;
+ return data.release();
} else {
return NULL;
}
@@ -481,10 +482,9 @@ DataStructure* OpenWireFormat::looseUnma
Integer::toString( dataType ) ).c_str() );
}
- DataStructure* data = dsm->createObject();
- dsm->looseUnmarshal( this, data, dis );
-
- return data;
+ std::auto_ptr<DataStructure> data(dsm->createObject());
+ dsm->looseUnmarshal( this, data.get(), dis );
+ return data.release();
} else {
return NULL;
Modified: activemq/activemq-cpp/branches/activemq-cpp-3.4.x/activemq-cpp/src/main/activemq/wireformat/openwire/marshal/BaseDataStreamMarshaller.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/branches/activemq-cpp-3.4.x/activemq-cpp/src/main/activemq/wireformat/openwire/marshal/BaseDataStreamMarshaller.cpp?rev=1394099&r1=1394098&r2=1394099&view=diff
==============================================================================
--- activemq/activemq-cpp/branches/activemq-cpp-3.4.x/activemq-cpp/src/main/activemq/wireformat/openwire/marshal/BaseDataStreamMarshaller.cpp (original)
+++ activemq/activemq-cpp/branches/activemq-cpp-3.4.x/activemq-cpp/src/main/activemq/wireformat/openwire/marshal/BaseDataStreamMarshaller.cpp Thu Oct 4 14:49:01 2012
@@ -447,7 +447,7 @@ commands::DataStructure* BaseDataStreamM
if( bs->readBoolean() ) {
- BrokerError* answer = new BrokerError();
+ std::auto_ptr<BrokerError> answer(new BrokerError());
answer->setExceptionClass( tightUnmarshalString( dataIn, bs ) );
answer->setMessage( tightUnmarshalString( dataIn, bs ) );
@@ -473,7 +473,7 @@ commands::DataStructure* BaseDataStreamM
tightUnmarshalBrokerError( wireFormat, dataIn, bs ) ) ) );
}
- return answer;
+ return answer.release();
} else {
return NULL;
@@ -581,7 +581,7 @@ commands::DataStructure* BaseDataStreamM
if( dataIn->readBoolean() ) {
- BrokerError* answer = new BrokerError();
+ std::auto_ptr<BrokerError> answer(new BrokerError());
answer->setExceptionClass( looseUnmarshalString( dataIn ) );
answer->setMessage( looseUnmarshalString( dataIn ) );
@@ -608,7 +608,7 @@ commands::DataStructure* BaseDataStreamM
looseUnmarshalBrokerError( wireFormat, dataIn ) ) ) );
}
- return answer;
+ return answer.release();
} else {
return NULL;