summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles E. Rolke <chug@apache.org>2011-10-17 20:01:44 +0000
committerCharles E. Rolke <chug@apache.org>2011-10-17 20:01:44 +0000
commit94382623428d2e8f11631dff8411fa247014ee65 (patch)
tree5da23d6b3b28cbbc35efd8f0877e46714fd55557
parent6b1898081dd21c42f40e3a0588a39c2a89a6b5a2 (diff)
downloadqpid-python-94382623428d2e8f11631dff8411fa247014ee65.tar.gz
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
-rw-r--r--qpid/cpp/src/qpid/RefCountedBuffer.cpp23
-rw-r--r--qpid/cpp/src/qpid/RefCountedBuffer.h10
2 files changed, 8 insertions, 25 deletions
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 <stdlib.h>
#include <new>
-#include <boost/cstdint.hpp>
namespace qpid {
void RefCountedBuffer::released() const {
this->~RefCountedBuffer();
- uintptr_t binStoreRaw = reinterpret_cast<uintptr_t>(this);
- binStoreRaw -= alignPad;
- ::delete[] reinterpret_cast<const char*>(binStoreRaw);
+ ::free (reinterpret_cast<void *>(const_cast<RefCountedBuffer *>(this)));
}
BufferRef RefCountedBuffer::create(size_t n) {
- 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);
-
+ void* store=::malloc (n + sizeof(RefCountedBuffer));
+ if (NULL == store)
+ throw std::bad_alloc();
new(store) RefCountedBuffer;
-
- reinterpret_cast<RefCountedBuffer*>((void *)store)->alignPad = binStore - binStoreRaw;
-
- char* start = store+sizeof(RefCountedBuffer);
+ char* start = reinterpret_cast<char *>(store) + sizeof(RefCountedBuffer);
return BufferRef(
- boost::intrusive_ptr<RefCounted>(reinterpret_cast<RefCountedBuffer*>((void *)store)),
+ boost::intrusive_ptr<RefCounted>(reinterpret_cast<RefCountedBuffer*>(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