Author: chug Date: Fri Oct 14 18:29:57 2011 New Revision: 1183456 URL: http://svn.apache.org/viewvc?rev=1183456&view=rev Log: QPID-3540 Typecasting and alignment requirements for various platforms
On sparc platform: SchemaHash::update() fails when the hash byte array is cast as two quadwords in a union. This fix uses the union in the definition of the hash byte array to coerce the compiler to place them in quadword alignment when they are created. Modified: qpid/trunk/qpid/cpp/src/qmf/engine/SchemaImpl.cpp qpid/trunk/qpid/cpp/src/qmf/engine/SchemaImpl.h Modified: qpid/trunk/qpid/cpp/src/qmf/engine/SchemaImpl.cpp URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qmf/engine/SchemaImpl.cpp?rev=1183456&r1=1183455&r2=1183456&view=diff ============================================================================== --- qpid/trunk/qpid/cpp/src/qmf/engine/SchemaImpl.cpp (original) +++ qpid/trunk/qpid/cpp/src/qmf/engine/SchemaImpl.cpp Fri Oct 14 18:29:57 2011 @@ -35,17 +35,17 @@ using qpid::framing::Uuid; SchemaHash::SchemaHash() { for (int idx = 0; idx < 16; idx++) - hash[idx] = 0x5A; + hash.b[idx] = 0x5A; } void SchemaHash::encode(Buffer& buffer) const { - buffer.putBin128(hash); + buffer.putBin128(hash.b); } void SchemaHash::decode(Buffer& buffer) { - buffer.getBin128(hash); + buffer.getBin128(hash.b); } void SchemaHash::update(uint8_t data) @@ -55,12 +55,8 @@ void SchemaHash::update(uint8_t data) void SchemaHash::update(const char* data, uint32_t len) { - union h { - uint8_t b[16]; - uint64_t q[2]; - }* h = reinterpret_cast<union h*>(&hash[0]); - uint64_t* first = &h->q[0]; - uint64_t* second = &h->q[1]; + uint64_t* first = &hash.q[0]; + uint64_t* second = &hash.q[1]; for (uint32_t idx = 0; idx < len; idx++) { *first = *first ^ (uint64_t) data[idx]; *second = *second << 1; Modified: qpid/trunk/qpid/cpp/src/qmf/engine/SchemaImpl.h URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qmf/engine/SchemaImpl.h?rev=1183456&r1=1183455&r2=1183456&view=diff ============================================================================== --- qpid/trunk/qpid/cpp/src/qmf/engine/SchemaImpl.h (original) +++ qpid/trunk/qpid/cpp/src/qmf/engine/SchemaImpl.h Fri Oct 14 18:29:57 2011 @@ -35,7 +35,10 @@ namespace engine { // they've been registered. class SchemaHash { - uint8_t hash[16]; + union h { + uint8_t b[16]; + uint64_t q[2]; + } hash; public: SchemaHash(); void encode(qpid::framing::Buffer& buffer) const; @@ -47,7 +50,7 @@ namespace engine { void update(Direction d) { update((uint8_t) d); } void update(Access a) { update((uint8_t) a); } void update(bool b) { update((uint8_t) (b ? 1 : 0)); } - const uint8_t* get() const { return hash; } + const uint8_t* get() const { return hash.b; } bool operator==(const SchemaHash& other) const; bool operator<(const SchemaHash& other) const; bool operator>(const SchemaHash& other) const; --------------------------------------------------------------------- Apache Qpid - AMQP Messaging Implementation Project: http://qpid.apache.org Use/Interact: mailto:commits-subscr...@qpid.apache.org