Author: chug Date: Fri Oct 14 14:57:58 2011 New Revision: 1183378 URL: http://svn.apache.org/viewvc?rev=1183378&view=rev Log: QPID-3540 Typecasting and alignment requirements for various platforms
In RefCountedBuffer: 1. Pad the instantiantion address of RefCountedBuffer class up to an 8-byte boundary. 2. Add (void *) casts to 'store' pointer to prevent warnings about alignment. In qpid-perftest: 1. Don't pull a size_t object from an arbitrary buffer address. Instead, memcopy the object by bytes. Modified: qpid/trunk/qpid/cpp/src/qpid/RefCountedBuffer.cpp qpid/trunk/qpid/cpp/src/qpid/RefCountedBuffer.h qpid/trunk/qpid/cpp/src/tests/qpid-perftest.cpp Modified: qpid/trunk/qpid/cpp/src/qpid/RefCountedBuffer.cpp URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/RefCountedBuffer.cpp?rev=1183378&r1=1183377&r2=1183378&view=diff ============================================================================== --- qpid/trunk/qpid/cpp/src/qpid/RefCountedBuffer.cpp (original) +++ qpid/trunk/qpid/cpp/src/qpid/RefCountedBuffer.cpp Fri Oct 14 14:57:58 2011 @@ -26,15 +26,26 @@ namespace qpid { void RefCountedBuffer::released() const { this->~RefCountedBuffer(); - ::delete[] reinterpret_cast<const char*>(this); + uintptr_t binStoreRaw = reinterpret_cast<uintptr_t>(this); + binStoreRaw -= alignPad; + ::delete[] reinterpret_cast<const char*>(binStoreRaw); } BufferRef RefCountedBuffer::create(size_t n) { - char* store=::new char[n+sizeof(RefCountedBuffer)]; + char * storeRaw = ::new char[n + sizeof(RefCountedBuffer) + + refCountedBufferStructAlign]; + uintptr_t binStoreRaw = reinterpret_cast<uintptr_t>(storeRaw); + uintptr_t binStore = (binStoreRaw + + refCountedBufferStructAlign-1) & ~(refCountedBufferStructAlign-1); + char * store = reinterpret_cast<char*>(binStore); + new(store) RefCountedBuffer; + + reinterpret_cast<RefCountedBuffer*>((void *)store)->alignPad = binStore - binStoreRaw; + char* start = store+sizeof(RefCountedBuffer); return BufferRef( - boost::intrusive_ptr<RefCounted>(reinterpret_cast<RefCountedBuffer*>(store)), + boost::intrusive_ptr<RefCounted>(reinterpret_cast<RefCountedBuffer*>((void *)store)), start, start+n); } Modified: qpid/trunk/qpid/cpp/src/qpid/RefCountedBuffer.h URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/RefCountedBuffer.h?rev=1183378&r1=1183377&r2=1183378&view=diff ============================================================================== --- qpid/trunk/qpid/cpp/src/qpid/RefCountedBuffer.h (original) +++ qpid/trunk/qpid/cpp/src/qpid/RefCountedBuffer.h Fri Oct 14 14:57:58 2011 @@ -28,8 +28,14 @@ namespace qpid { /** - * Reference-counted byte buffer. No alignment guarantees. + * Reference-counted byte buffer. Alignment guarantees: + * The RefCountedBuffer structure is aligned to the + * refCountedBUfferStructAlign byte boundary specified here. + * The buffer itself has no alignment guarantees. */ + +static const size_t refCountedBufferStructAlign = 8; + class RefCountedBuffer : public RefCounted { public: /** Create a reference counted buffer of size n */ @@ -37,6 +43,8 @@ class RefCountedBuffer : public RefCount protected: void released() const; + + size_t alignPad; }; } // namespace qpid Modified: qpid/trunk/qpid/cpp/src/tests/qpid-perftest.cpp URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/tests/qpid-perftest.cpp?rev=1183378&r1=1183377&r2=1183378&view=diff ============================================================================== --- qpid/trunk/qpid/cpp/src/tests/qpid-perftest.cpp (original) +++ qpid/trunk/qpid/cpp/src/tests/qpid-perftest.cpp Fri Oct 14 14:57:58 2011 @@ -644,7 +644,9 @@ struct SubscribeThread : public Client { // // For now verify order only for a single publisher. size_t offset = opts.uniqueData ? 5 /*marker is 'data:'*/ : 0; - size_t n = *reinterpret_cast<const size_t*>(msg.getData().data() + offset); + size_t n; + memcpy (&n, reinterpret_cast<const char*>(msg.getData().data() + offset), + sizeof(n)); if (opts.pubs == 1) { if (opts.subs == 1 || opts.mode == FANOUT) verify(n==expect, "==", expect, n); else verify(n>=expect, ">=", expect, n); --------------------------------------------------------------------- Apache Qpid - AMQP Messaging Implementation Project: http://qpid.apache.org Use/Interact: mailto:commits-subscr...@qpid.apache.org