Boost logo

Boost-Commit :

From: phil_at_[hidden]
Date: 2008-07-25 05:34:00


Author: pbouchard
Date: 2008-07-25 05:33:59 EDT (Fri, 25 Jul 2008)
New Revision: 47796
URL: http://svn.boost.org/trac/boost/changeset/47796

Log:
Bug fixes & simplified but still more to come.
Text files modified:
   sandbox/shifted_ptr/bits/list.tcc | 12 ++++----
   sandbox/shifted_ptr/bits/stl_list.h | 38 +++++++++++----------------
   sandbox/shifted_ptr/boost/detail/sh_owned_base_nt.hpp | 45 +++++++++++++++++++--------------
   sandbox/shifted_ptr/boost/shifted_allocator.hpp | 31 ++++++++++++++--------
   sandbox/shifted_ptr/boost/shifted_ptr.hpp | 54 ++++++++++++++++++++++++++++-----------
   5 files changed, 106 insertions(+), 74 deletions(-)

Modified: sandbox/shifted_ptr/bits/list.tcc
==============================================================================
--- sandbox/shifted_ptr/bits/list.tcc (original)
+++ sandbox/shifted_ptr/bits/list.tcc 2008-07-25 05:33:59 EDT (Fri, 25 Jul 2008)
@@ -101,8 +101,8 @@
     {
       typedef _List_node<_Tp,_Alloc> _Node;
       typedef _List_node_base<_Alloc> _Node_base;
- _Node* __cur = static_cast<_Node*>(static_cast<_Node_base*>(&*this->_M_impl._M_node._M_next));
- while (__cur != &this->_M_impl._M_node)
+ _Node* __cur = static_cast<_Node*>(static_cast<_Node_base*>(&*this->_M_impl._M_node->_M_next));
+ while (__cur != &*this->_M_impl._M_node)
       {
         _Node* __tmp = __cur;
         __cur = static_cast<_Node*>(static_cast<_Node_base*>(&*__cur->_M_next));
@@ -269,8 +269,8 @@
     sort()
     {
       // Do nothing if the list has length 0 or 1.
- if (this->_M_impl._M_node._M_next != &this->_M_impl._M_node
- && this->_M_impl._M_node._M_next->_M_next != &this->_M_impl._M_node)
+ if (this->_M_impl._M_node->_M_next != this->_M_impl._M_node
+ && this->_M_impl._M_node->_M_next->_M_next != this->_M_impl._M_node)
       {
         list __carry;
         list __tmp[64];
@@ -373,8 +373,8 @@
       sort(_StrictWeakOrdering __comp)
       {
         // Do nothing if the list has length 0 or 1.
- if (this->_M_impl._M_node._M_next != &this->_M_impl._M_node
- && this->_M_impl._M_node._M_next->_M_next != &this->_M_impl._M_node)
+ if (this->_M_impl._M_node->_M_next != this->_M_impl._M_node
+ && this->_M_impl._M_node->_M_next->_M_next != this->_M_impl._M_node)
           {
             list __carry;
             list __tmp[64];

Modified: sandbox/shifted_ptr/bits/stl_list.h
==============================================================================
--- sandbox/shifted_ptr/bits/stl_list.h (original)
+++ sandbox/shifted_ptr/bits/stl_list.h 2008-07-25 05:33:59 EDT (Fri, 25 Jul 2008)
@@ -318,22 +318,16 @@
       // get_allocator, where we use conversions between
       // allocator_type and _Node_Alloc_type. The conversion is
       // required by table 32 in [20.1.5].
- typedef typename _Alloc::template rebind<_List_node<_Tp, _Alloc> >::other
-
+ typedef typename _Alloc::template rebind<_List_node<_Tp, _Alloc> >::other
+
       _Node_Alloc_type;
 
- struct _List_impl
+ struct _List_impl
         : public _Node_Alloc_type {
- _List_base & _M_base;
- _List_node_base<_Alloc> & _M_node;
+ typename _List_node_base<_Alloc>::pointer _M_node;
         _List_impl (const _Node_Alloc_type& __a, _List_base& __b)
- : _Node_Alloc_type(__a), _M_base(__b), _M_node(* new (_M_base._M_get_node()) _List_node_base<_Alloc>())
+ : _Node_Alloc_type(__a), _M_node(new (__b._M_get_node()) _List_node_base<_Alloc>())
         { }
- ~_List_impl ()
- {
- _M_node.~_List_node_base<_Alloc>();
- _M_base._M_put_node(static_cast<_List_node<_Tp, _Alloc> *>(&_M_node));
- }
       };
 
       _List_impl _M_impl;
@@ -341,11 +335,11 @@
       _List_node<_Tp, _Alloc> *
       _M_get_node()
       { return _M_impl._Node_Alloc_type::allocate(1); }
-
+
       void
       _M_put_node(_List_node<_Tp, _Alloc> * __p)
       { _M_impl._Node_Alloc_type::deallocate(__p, 1); }
-
+
   public:
       typedef _Node_Alloc_type allocator_type;
 
@@ -367,8 +361,8 @@
       void
       _M_init()
       {
- this->_M_impl._M_node._M_next = &this->_M_impl._M_node;
- this->_M_impl._M_node._M_prev = &this->_M_impl._M_node;
+ this->_M_impl._M_node->_M_next = this->_M_impl._M_node;
+ this->_M_impl._M_node->_M_prev = this->_M_impl._M_node;
       }
     };
 
@@ -629,7 +623,7 @@
        */
       iterator
       begin()
- { return iterator(&*this->_M_impl._M_node._M_next); }
+ { return iterator(&*this->_M_impl._M_node->_M_next); }
 
       /**
        * Returns a read-only (constant) iterator that points to the
@@ -638,7 +632,7 @@
        */
       const_iterator
       begin() const
- { return const_iterator(&*this->_M_impl._M_node._M_next); }
+ { return const_iterator(&*this->_M_impl._M_node->_M_next); }
 
       /**
        * Returns a read/write iterator that points one past the last
@@ -646,7 +640,7 @@
        * order.
        */
       iterator
- end() { return &this->_M_impl._M_node; }
+ end() { return &*this->_M_impl._M_node; }
 
       /**
        * Returns a read-only (constant) iterator that points one past
@@ -655,7 +649,7 @@
        */
       const_iterator
       end() const
- { return &this->_M_impl._M_node; }
+ { return &*this->_M_impl._M_node; }
 
       /**
        * Returns a read/write reverse iterator that points to the last
@@ -700,7 +694,7 @@
        */
       bool
       empty() const
- { return this->_M_impl._M_node._M_next == &this->_M_impl._M_node; }
+ { return this->_M_impl._M_node->_M_next == this->_M_impl._M_node; }
 
       /** Returns the number of elements in the %list. */
       size_type
@@ -829,7 +823,7 @@
        */
       void
       pop_back()
- { this->_M_erase(this->_M_impl._M_node._M_prev); }
+ { this->_M_erase(this->_M_impl._M_node->_M_prev); }
 
       /**
        * @brief Inserts given value into %list before specified iterator.
@@ -1105,7 +1099,7 @@
        */
       void
       reverse()
- { this->_M_impl._M_node.reverse(); }
+ { this->_M_impl._M_node->reverse(); }
 
       /**
        * @brief Sort the elements.

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-25 05:33:59 EDT (Fri, 25 Jul 2008)
@@ -77,52 +77,57 @@
         alloc_.reset(new lpp());
         constr_.reset(new lpp());
     }
-
+
     /**
         @brief
         This function returns the most recent allocation block that contains p.
-
+
         @note
         Every block allocated after p is discarded.
     */
-
+
     owned_base * top(void * p)
     {
         char * const q = static_cast<char *>(p);
-
+
         lpp::reverse_iterator i;
         for (i = alloc_.get()->rbegin(); i != alloc_.get()->rend(); i ++)
             if (i->first <= q && q <= i->second)
                 break;
 
+//std::cout << __FUNCTION__ << ": " << &* i.base() << " - " << &* alloc_.get()->end() << std::endl;
         alloc_.get()->erase(i.base(), alloc_.get()->end());
-
+
         return (owned_base *)(i->first);
     }
-
+
     lpp & construct()
     {
         return * constr_.get();
     }
-
+
     void * allocate(std::size_t s)
     {
         char * p = static_cast<char *>(ordered_malloc(s));
-
+
         alloc_.get()->push_back(std::make_pair(p, p + s));
-
+
+//std::cout << __FUNCTION__ << ": " << (void *) p << " - " << (void *) (p + s) << std::endl;
+
         return p;
     }
 
     void deallocate(void * p, std::size_t s)
     {
         char * const q = static_cast<char *>(p);
-
+
+//std::cout << __FUNCTION__ << ": " << (void *) q << " - " << (void *) (q + s) << std::endl;
+
         lpp::reverse_iterator i;
         for (i = alloc_.get()->rbegin(); i != alloc_.get()->rend(); i ++)
             if (i->first <= q && q <= i->second)
                 break;
-
+
         alloc_.get()->erase(i.base(), alloc_.get()->end());
         free(p, s);
     }
@@ -149,11 +154,11 @@
 
         intrusive_stack ptrs_;
         intrusive_list inits_;
-
+
 protected:
     owned_base()
     {
- inits_.push_back(& init_tag_);
+ inits_.push_back(& init_tag_);
     }
 
 public:
@@ -166,7 +171,7 @@
     intrusive_list::node * init_tag() { return & init_tag_; }
 
     static pool pool_;
-
+
 private:
     virtual void dispose() {} // dummy
     virtual void * get_deleter( std::type_info const & ti ) {} // dummy
@@ -194,7 +199,7 @@
         typedef T data_type;
 
         data_type e_; // need alignas<long>
-
+
     public:
         class roofof;
         friend class roofof;
@@ -217,15 +222,17 @@
 
         public:
             roofof(data_type * p) : p_(sh::roofof((data_type shifted<data_type>::*)(& shifted<data_type>::e_), p)) {}
-
+
             operator shifted<data_type> * () const { return p_; }
         };
-
+
         void * operator new (size_t s)
         {
+//std::cout << std::hex << __FUNCTION__ << ": " << s << std::endl;
+
             return pool_.allocate(s);
         }
-
+
         void operator delete (void * p)
         {
             pool_.deallocate(p, sizeof(shifted));
@@ -260,7 +267,7 @@
 
         public:
             roofof(data_type * p) : p_(sh::roofof((long shifted<data_type>::*)(& shifted<data_type>::p_), static_cast<long *>(p))) {}
-
+
             operator shifted<data_type> * () const { return p_; }
         };
     };

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-25 05:33:59 EDT (Fri, 25 Jul 2008)
@@ -56,7 +56,7 @@
         template <typename U>
             struct rebind
             {
- typedef shifted_allocator<U> other;
+ typedef shifted_allocator<U> other;
             };
 
         shifted_allocator() throw() {}
@@ -71,46 +71,53 @@
         //! FIXME
         value_type * allocate(size_type s, const void * = 0)
         {
- return static_cast<shifted<T> *>(new (shifted<T>::operator new(s)) owned_base)->element();
+ //return static_cast<shifted<T> *>(::new (shifted<T>::operator new(s)) owned_base)->element();
+ shifted<T> * p = (shifted<T> *) shifted<T>::operator new(sizeof(shifted<T>));
+
+std::cout << __FUNCTION__ << ": " << (void *) p << " - " << (void *)((char *) p + sizeof(shifted<T>)) << ", " << (void *) p->element() << std::endl;
+
+ return static_cast<shifted<T> *>(::new (p) owned_base)->element();
         }
 
         //! FIXME
         void deallocate(value_type * p, size_type)
         {
+/*
             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);
+ shifted<T>::operator delete(q);
+*/
         }
 
         //! FIXME
- size_type max_size() const throw()
+ size_type max_size() const throw()
         {
- return size_t(-1) / sizeof(T);
+ return size_t(-1) / sizeof(T);
         }
 
- void construct(pointer p, const T & x)
+ void construct(pointer p, const T & x)
         {
- ::new (p) T(x);
+ ::new (p) T(x);
         }
 
- void destroy(pointer p)
+ void destroy(pointer p)
         {
- p->~T();
+ p->~T();
         }
     };
 
 template <typename T>
     inline bool operator == (const shifted_allocator<T> &, const shifted_allocator<T> &)
     {
- return true;
+ return true;
     }
 
 template <typename T>
     inline bool operator != (const shifted_allocator<T> &, const shifted_allocator<T> &)
     {
- return false;
+ return false;
     }
 
 

Modified: sandbox/shifted_ptr/boost/shifted_ptr.hpp
==============================================================================
--- sandbox/shifted_ptr/boost/shifted_ptr.hpp (original)
+++ sandbox/shifted_ptr/boost/shifted_ptr.hpp 2008-07-25 05:33:59 EDT (Fri, 25 Jul 2008)
@@ -72,6 +72,8 @@
 
     set() : count_(1), redir_(this)
     {
+std::cout << __FUNCTION__ << ": " << this << std::endl;
+
         includes_.push_back(& tag_);
     }
 
@@ -86,11 +88,11 @@
                 i->add_ref_copy();
                 delete &* i;
             }
-
+
             for (intrusive_list::iterator<set, & set::tag_> i = p->includes_.begin(), j; j = i, ++ j, i != p->includes_.end(); i = j)
                 if (&* i != this && &* i != p)
                     delete &* i;
-
+
             if (p != this)
                 delete p;
 
@@ -102,6 +104,8 @@
 
     set * redir() const
     {
+//std::cout << __FUNCTION__ << ": " << this << std::endl;
+
         if (redir_ == this) return redir_;
         else return redir_ = redir_->redir();
     }
@@ -121,12 +125,16 @@
     {
         return & redir()->elements_;
     }
-
+
     void * operator new (size_t s)
     {
- return pool_.allocate(s);
+ void * p = pool_.allocate(s);
+
+std::cout << __FUNCTION__ << ": " << (void *) p << " - " << (void *)((char *) p + sizeof(set)) << std::endl;
+
+ return p;
     }
-
+
     void * operator new (size_t s, set * p)
     {
         return p;
@@ -134,6 +142,8 @@
 
     void operator delete (void * p)
     {
+//std::cout << __FUNCTION__ << ": " << p << std::endl;
+
         pool_.deallocate(static_cast<set *>(p), sizeof(set));
     }
 };
@@ -167,6 +177,7 @@
 
         shifted_ptr() : ps_(0)
         {
+std::cout << __FUNCTION__ << ": " << this << std::endl;
             if (! owned_base::pool_.is_from(this))
                 ps_ = new set();
             else
@@ -213,8 +224,12 @@
         template <typename V>
             shifted_ptr & operator = (shifted<V> * p)
             {
- release();
- init(p);
+ // initialized yet or not?
+ if (ps_ && ! owned_base::pool_.is_from(ps_))
+ {
+ release();
+ init(p);
+ }
                 base::operator = (p);
 
                 return * this;
@@ -225,10 +240,15 @@
             {
                 if (p.po_ != base::po_)
                 {
- if (ps_->redir() != p.ps_->redir())
+ // initialized yet or not?
+std::cout << ps_ << ": " << p.ps_ << std::endl;
+ if (ps_ && ! owned_base::pool_.is_from(ps_) && p.ps_ && ! owned_base::pool_.is_from(p.ps_))
                     {
- release();
- ps_->redir(p.ps_);
+ if (ps_->redir() != p.ps_->redir())
+ {
+ release();
+ ps_->redir(p.ps_);
+ }
                     }
                     base::operator = (p);
                 }
@@ -267,8 +287,12 @@
             {
                 shifted<element_type> * const q = (typename shifted<element_type>::roofof) static_cast<element_type *>(rootof<is_polymorphic<element_type>::value>::get(p));
 
- release();
- init(q);
+ // initialized yet or not?
+ if (ps_ && ! owned_base::pool_.is_from(ps_))
+ {
+ release();
+ init(q);
+ }
                 base::operator = (q);
 
                 return * this;
@@ -299,7 +323,7 @@
                     else
                         delete ps_;
                 }
- else
+ else
                 {
                     base::reset();
 
@@ -316,11 +340,11 @@
             for (intrusive_list::iterator<owned_base, & owned_base::init_tag_> i = p->inits()->begin(), j; j = i, ++ j, i != p->inits()->end(); i = j)
             {
                 ps_->elements()->push_back(i->set_tag());
-
+
                 for (intrusive_stack::iterator<shifted_ptr, & shifted_ptr::pn_> m = p->ptrs()->begin(), n; n = m, ++ n, m != p->ptrs()->end(); m = n)
                     m->ps_ = ps_;
             }
-
+
             owned_base::pool_.construct().clear();
         }
     };


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