summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles E. Rolke <chug@apache.org>2011-10-14 14:57:58 +0000
committerCharles E. Rolke <chug@apache.org>2011-10-14 14:57:58 +0000
commit0f5ffd82663317aa73602cda7a55470d6d659567 (patch)
tree497bb09f45e0a686692d78d88054cd5aa85029b8
parent0d410c6aa9ad565f93221691123a5b3c45b42ec3 (diff)
downloadqpid-python-0f5ffd82663317aa73602cda7a55470d6d659567.tar.gz
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. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1183378 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--qpid/cpp/src/qpid/RefCountedBuffer.cpp17
-rw-r--r--qpid/cpp/src/qpid/RefCountedBuffer.h10
-rw-r--r--qpid/cpp/src/tests/qpid-perftest.cpp4
3 files changed, 26 insertions, 5 deletions
diff --git a/qpid/cpp/src/qpid/RefCountedBuffer.cpp b/qpid/cpp/src/qpid/RefCountedBuffer.cpp
index 40d620f7ad..7e15eefeea 100644
--- a/qpid/cpp/src/qpid/RefCountedBuffer.cpp
+++ b/qpid/cpp/src/qpid/RefCountedBuffer.cpp
@@ -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);
}
diff --git a/qpid/cpp/src/qpid/RefCountedBuffer.h b/qpid/cpp/src/qpid/RefCountedBuffer.h
index f0ea86130b..67a512d938 100644
--- a/qpid/cpp/src/qpid/RefCountedBuffer.h
+++ b/qpid/cpp/src/qpid/RefCountedBuffer.h
@@ -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 RefCounted {
protected:
void released() const;
+
+ size_t alignPad;
};
} // namespace qpid
diff --git a/qpid/cpp/src/tests/qpid-perftest.cpp b/qpid/cpp/src/tests/qpid-perftest.cpp
index 3aff742c62..dd81354adb 100644
--- a/qpid/cpp/src/tests/qpid-perftest.cpp
+++ b/qpid/cpp/src/tests/qpid-perftest.cpp
@@ -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);