From 0e3531d5da3a1de2cbde54c07c37e56a1315faf7 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/qpid@1185350 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/qpid/RefCountedBuffer.cpp | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) (limited to 'cpp/src/qpid/RefCountedBuffer.cpp') diff --git a/cpp/src/qpid/RefCountedBuffer.cpp b/cpp/src/qpid/RefCountedBuffer.cpp index 72475f823e..a82e1a02ab 100644 --- a/cpp/src/qpid/RefCountedBuffer.cpp +++ b/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); } -- cgit v1.2.1