From 94382623428d2e8f11631dff8411fa247014ee65 Mon Sep 17 00:00:00 2001 From: "Charles E. Rolke" Date: Mon, 17 Oct 2011 20:01:44 +0000 Subject: QPID-3540 align issues in Solaris Restore original code. Then: 1. Change new/delete to malloc/free. Malloc guarantees alignment for any struct. 2. Change store from char* to void*, solving Solaris complaint. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1185350 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/cpp/src/qpid/RefCountedBuffer.cpp | 23 +++++++---------------- qpid/cpp/src/qpid/RefCountedBuffer.h | 10 +--------- 2 files changed, 8 insertions(+), 25 deletions(-) (limited to 'qpid/cpp/src') diff --git a/qpid/cpp/src/qpid/RefCountedBuffer.cpp b/qpid/cpp/src/qpid/RefCountedBuffer.cpp index 72475f823e..a82e1a02ab 100644 --- a/qpid/cpp/src/qpid/RefCountedBuffer.cpp +++ b/qpid/cpp/src/qpid/RefCountedBuffer.cpp @@ -20,33 +20,24 @@ */ #include "qpid/RefCountedBuffer.h" +#include #include -#include namespace qpid { void RefCountedBuffer::released() const { this->~RefCountedBuffer(); - uintptr_t binStoreRaw = reinterpret_cast(this); - binStoreRaw -= alignPad; - ::delete[] reinterpret_cast(binStoreRaw); + ::free (reinterpret_cast(const_cast(this))); } BufferRef RefCountedBuffer::create(size_t n) { - char * storeRaw = ::new char[n + sizeof(RefCountedBuffer) + - refCountedBufferStructAlign]; - uintptr_t binStoreRaw = reinterpret_cast(storeRaw); - uintptr_t binStore = (binStoreRaw + - refCountedBufferStructAlign-1) & ~(refCountedBufferStructAlign-1); - char * store = reinterpret_cast(binStore); - + void* store=::malloc (n + sizeof(RefCountedBuffer)); + if (NULL == store) + throw std::bad_alloc(); new(store) RefCountedBuffer; - - reinterpret_cast((void *)store)->alignPad = binStore - binStoreRaw; - - char* start = store+sizeof(RefCountedBuffer); + char* start = reinterpret_cast(store) + sizeof(RefCountedBuffer); return BufferRef( - boost::intrusive_ptr(reinterpret_cast((void *)store)), + boost::intrusive_ptr(reinterpret_cast(store)), start, start+n); } diff --git a/qpid/cpp/src/qpid/RefCountedBuffer.h b/qpid/cpp/src/qpid/RefCountedBuffer.h index 67a512d938..f0ea86130b 100644 --- a/qpid/cpp/src/qpid/RefCountedBuffer.h +++ b/qpid/cpp/src/qpid/RefCountedBuffer.h @@ -28,14 +28,8 @@ namespace qpid { /** - * 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. + * Reference-counted byte buffer. No alignment guarantees. */ - -static const size_t refCountedBufferStructAlign = 8; - class RefCountedBuffer : public RefCounted { public: /** Create a reference counted buffer of size n */ @@ -43,8 +37,6 @@ class RefCountedBuffer : public RefCounted { protected: void released() const; - - size_t alignPad; }; } // namespace qpid -- cgit v1.2.1