Boost logo

Boost-Commit :

From: phil_at_[hidden]
Date: 2008-07-22 05:18:23


Author: pbouchard
Date: 2008-07-22 05:18:23 EDT (Tue, 22 Jul 2008)
New Revision: 47680
URL: http://svn.boost.org/trac/boost/changeset/47680

Log:
Fixed shifted_allocator::(de)allocate.
Removed:
   sandbox/shifted_ptr/bits/bits.zip
Text files modified:
   sandbox/shifted_ptr/boost/detail/sh_owned_base_nt.hpp | 4 ++--
   sandbox/shifted_ptr/boost/shifted_allocator.hpp | 28 +++++++++++++++++-----------
   2 files changed, 19 insertions(+), 13 deletions(-)

Deleted: sandbox/shifted_ptr/bits/bits.zip
==============================================================================
Binary file. No diff available.

Modified: sandbox/shifted_ptr/boost/detail/sh_owned_base_nt.hpp
==============================================================================
--- sandbox/shifted_ptr/boost/detail/sh_owned_base_nt.hpp (original)
+++ sandbox/shifted_ptr/boost/detail/sh_owned_base_nt.hpp 2008-07-22 05:18:23 EDT (Tue, 22 Jul 2008)
@@ -223,12 +223,12 @@
         
         void * operator new (size_t s)
         {
- return (char *) pool_.allocate(s) + sizeof(owned_base);
+ return pool_.allocate(s);
         }
         
         void operator delete (void * p)
         {
- pool_.deallocate((char *) p - sizeof(owned_base), sizeof(shifted));
+ pool_.deallocate(p, sizeof(shifted));
         }
     };
 

Modified: sandbox/shifted_ptr/boost/shifted_allocator.hpp
==============================================================================
--- sandbox/shifted_ptr/boost/shifted_allocator.hpp (original)
+++ sandbox/shifted_ptr/boost/shifted_allocator.hpp 2008-07-22 05:18:23 EDT (Tue, 22 Jul 2008)
@@ -49,7 +49,7 @@
         {
         }
 
- //! TODO
+ //! FIXME
         shifted_ptr_stl(T * p) : base((shifted<element_type> *) (typename shifted<element_type>::roofof) static_cast<element_type *>(rootof<is_polymorphic<element_type>::value>::get(p)))
         {
         }
@@ -85,7 +85,7 @@
 
         template <typename U>
             struct rebind
- {
+ {
                 typedef shifted_allocator<U> other;
             };
 
@@ -98,42 +98,48 @@
         pointer address(reference x) const { return & x; }
         const_pointer address(const_reference x) const { return & x; }
 
+ //! FIXME
         value_type * allocate(size_type s, const void * = 0)
- {
- return (value_type *) shifted<T>::operator new(s);
+ {
+ return static_cast<shifted<T> *>(new (shifted<T>::operator new(s)) owned_base)->element();
         }
 
+ //! FIXME
         void deallocate(value_type * p, size_type)
- {
- shifted<T>::operator delete(p);
+ {
+ owned_base * const q = (typename shifted<value_type>::roofof) static_cast<value_type *>(rootof<is_polymorphic<value_type>::value>::get(p));
+
+ q->~owned_base();
+
+ shifted<T>::operator delete(q);
         }
 
         //! FIXME
         size_type max_size() const throw()
- {
+ {
             return size_t(-1) / sizeof(T);
         }
 
         void construct(pointer p, const T & x)
- {
+ {
             ::new (p) T(x);
         }
 
         void destroy(pointer p)
- {
+ {
             p->~T();
         }
     };
 
 template <typename T>
     inline bool operator == (const shifted_allocator<T> &, const shifted_allocator<T> &)
- {
+ {
         return true;
     }
 
 template <typename T>
     inline bool operator != (const shifted_allocator<T> &, const shifted_allocator<T> &)
- {
+ {
         return false;
     }
 


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk