qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c...@apache.org
Subject svn commit: r1185350 - in /qpid/trunk/qpid/cpp/src/qpid: RefCountedBuffer.cpp RefCountedBuffer.h
Date Mon, 17 Oct 2011 20:01:45 GMT
Author: chug
Date: Mon Oct 17 20:01:44 2011
New Revision: 1185350

URL: http://svn.apache.org/viewvc?rev=1185350&view=rev
Log:
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.

Modified:
    qpid/trunk/qpid/cpp/src/qpid/RefCountedBuffer.cpp
    qpid/trunk/qpid/cpp/src/qpid/RefCountedBuffer.h

Modified: qpid/trunk/qpid/cpp/src/qpid/RefCountedBuffer.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/RefCountedBuffer.cpp?rev=1185350&r1=1185349&r2=1185350&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/RefCountedBuffer.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/RefCountedBuffer.cpp Mon Oct 17 20:01:44 2011
@@ -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);
 }
 

Modified: qpid/trunk/qpid/cpp/src/qpid/RefCountedBuffer.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/RefCountedBuffer.h?rev=1185350&r1=1185349&r2=1185350&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/RefCountedBuffer.h (original)
+++ qpid/trunk/qpid/cpp/src/qpid/RefCountedBuffer.h Mon Oct 17 20:01:44 2011
@@ -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 RefCount
 
   protected:
     void released() const;
-
-    size_t alignPad;
 };
 
 } // namespace qpid



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org


Mime
View raw message