Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r55574 - in sandbox/fmhess/boost/generic_ptr: . detail
From: fmhess_at_[hidden]
Date: 2009-08-13 15:13:53


Author: fmhess
Date: 2009-08-13 15:13:52 EDT (Thu, 13 Aug 2009)
New Revision: 55574
URL: http://svn.boost.org/trac/boost/changeset/55574

Log:
Added assertions that wrapped pointers are non-null iff
the wrapped pointer type is a plain old pointer.

Text files modified:
   sandbox/fmhess/boost/generic_ptr/asserting.hpp | 4 ++--
   sandbox/fmhess/boost/generic_ptr/cloning.hpp | 2 ++
   sandbox/fmhess/boost/generic_ptr/detail/util.hpp | 11 +++++++++++
   sandbox/fmhess/boost/generic_ptr/intrusive.hpp | 2 ++
   sandbox/fmhess/boost/generic_ptr/monitor.hpp | 4 ++++
   sandbox/fmhess/boost/generic_ptr/monitor_locks.hpp | 32 ++++++++++++++++++++++++--------
   sandbox/fmhess/boost/generic_ptr/shared.hpp | 2 ++
   sandbox/fmhess/boost/generic_ptr/throwing.hpp | 4 ++--
   8 files changed, 49 insertions(+), 12 deletions(-)

Modified: sandbox/fmhess/boost/generic_ptr/asserting.hpp
==============================================================================
--- sandbox/fmhess/boost/generic_ptr/asserting.hpp (original)
+++ sandbox/fmhess/boost/generic_ptr/asserting.hpp 2009-08-13 15:13:52 EDT (Thu, 13 Aug 2009)
@@ -126,13 +126,13 @@
 
       pointer operator->() const
       {
- BOOST_ASSERT(get_plain_old_pointer(px));
+ BOOST_ASSERT(px);
         return px;
       }
 
       reference operator*() const
       {
- BOOST_ASSERT(get_plain_old_pointer(px));
+ BOOST_ASSERT(px);
         return *px;
       }
 

Modified: sandbox/fmhess/boost/generic_ptr/cloning.hpp
==============================================================================
--- sandbox/fmhess/boost/generic_ptr/cloning.hpp (original)
+++ sandbox/fmhess/boost/generic_ptr/cloning.hpp 2009-08-13 15:13:52 EDT (Thu, 13 Aug 2009)
@@ -406,11 +406,13 @@
 
       pointer operator->() const
       {
+ detail::assert_plain_old_pointer_not_null(px);
         return px;
       }
 
       reference operator*() const
       {
+ detail::assert_plain_old_pointer_not_null(px);
         return *px;
       }
 

Modified: sandbox/fmhess/boost/generic_ptr/detail/util.hpp
==============================================================================
--- sandbox/fmhess/boost/generic_ptr/detail/util.hpp (original)
+++ sandbox/fmhess/boost/generic_ptr/detail/util.hpp 2009-08-13 15:13:52 EDT (Thu, 13 Aug 2009)
@@ -10,6 +10,8 @@
 #ifndef BOOST_GENERIC_PTR_DETAIL_UTIL_HPP_INCLUDED
 #define BOOST_GENERIC_PTR_DETAIL_UTIL_HPP_INCLUDED
 
+#include <boost/assert.hpp>
+
 namespace boost
 {
   namespace generic_ptr
@@ -28,6 +30,15 @@
       template<typename T>
       void set_plain_old_pointer_to_null(const T&)
       {}
+
+ template<typename T>
+ void assert_plain_old_pointer_not_null(T * &p)
+ {
+ BOOST_ASSERT(p != 0);
+ }
+ template<typename T>
+ void assert_plain_old_pointer_not_null(const T&)
+ {}
     } // namespace detail
   } // namespace generic_ptr
 } // namespace boost

Modified: sandbox/fmhess/boost/generic_ptr/intrusive.hpp
==============================================================================
--- sandbox/fmhess/boost/generic_ptr/intrusive.hpp (original)
+++ sandbox/fmhess/boost/generic_ptr/intrusive.hpp 2009-08-13 15:13:52 EDT (Thu, 13 Aug 2009)
@@ -188,11 +188,13 @@
 
     reference operator*() const
     {
+ detail::assert_plain_old_pointer_not_null(px);
         return *px;
     }
 
     pointer operator->() const
     {
+ detail::assert_plain_old_pointer_not_null(px);
         return px;
     }
 

Modified: sandbox/fmhess/boost/generic_ptr/monitor.hpp
==============================================================================
--- sandbox/fmhess/boost/generic_ptr/monitor.hpp (original)
+++ sandbox/fmhess/boost/generic_ptr/monitor.hpp 2009-08-13 15:13:52 EDT (Thu, 13 Aug 2009)
@@ -43,6 +43,7 @@
         {}
         T operator->() const
         {
+ detail::assert_plain_old_pointer_not_null(_object_p);
           return _object_p;
         }
       private:
@@ -159,6 +160,9 @@
     template<typename T, typename Mutex>
     T get_pointer(const monitor<T, Mutex> &mp)
     {
+ //FIXME: should get_pointer return a monitor lock?
+ // if it does not, it will not be safe to use monitor as "this" pointer with bind.
+ // if it does, the monitor lock types will need to support generic pointer concepts better
       return mp.get();
     }
 

Modified: sandbox/fmhess/boost/generic_ptr/monitor_locks.hpp
==============================================================================
--- sandbox/fmhess/boost/generic_ptr/monitor_locks.hpp (original)
+++ sandbox/fmhess/boost/generic_ptr/monitor_locks.hpp 2009-08-13 15:13:52 EDT (Thu, 13 Aug 2009)
@@ -119,7 +119,9 @@
           {
             throw boost::lock_error();
           }
- return _mon.get();
+ typename pointer_traits<MonitorPtr>::pointer p = _mon.get();
+ detail::assert_plain_old_pointer_not_null(p);
+ return p;
         }
         reference operator*() const
         {
@@ -127,7 +129,9 @@
           {
             throw boost::lock_error();
           }
- return *_mon;
+ typename pointer_traits<MonitorPtr>::pointer p = _mon.get();
+ detail::assert_plain_old_pointer_not_null(p);
+ return *p;
         }
   #ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
       protected:
@@ -279,7 +283,9 @@
         {
           throw boost::lock_error();
         }
- return this->_mon.get();
+ typename pointer_traits<MonitorPtr>::pointer p = this->_mon.get();
+ detail::assert_plain_old_pointer_not_null(p);
+ return p;
       }
       typename pointer_traits<typename base_class::const_wrapped_pointer_type>::reference operator*() const
       {
@@ -287,7 +293,9 @@
         {
           throw boost::lock_error();
         }
- return *this->_mon.get();
+ typename pointer_traits<MonitorPtr>::pointer p = this->_mon.get();
+ detail::assert_plain_old_pointer_not_null(p);
+ return *p;
       }
 
       // move emulation
@@ -368,7 +376,9 @@
         {
           throw boost::lock_error();
         }
- return this->_mon.get();
+ typename pointer_traits<MonitorPtr>::pointer p = this->_mon.get();
+ detail::assert_plain_old_pointer_not_null(p);
+ return p;
       }
       const typename pointer_traits<typename base_class::const_wrapped_pointer_type>::reference operator*() const
       {
@@ -376,7 +386,9 @@
         {
           throw boost::lock_error();
         }
- return *this->_mon.get();
+ typename pointer_traits<MonitorPtr>::pointer p = this->_mon.get();
+ detail::assert_plain_old_pointer_not_null(p);
+ return *p;
       }
 
 #ifdef BOOST_NO_RVALUE_REFERENCES
@@ -464,7 +476,9 @@
         {
           throw boost::lock_error();
         }
- return _mon.get();
+ typename pointer_traits<MonitorPtr>::pointer p = _mon.get();
+ detail::assert_plain_old_pointer_not_null(p);
+ return p;
       }
       typename MonitorPtr::reference operator*() const
       {
@@ -472,7 +486,9 @@
         {
           throw boost::lock_error();
         }
- return *_mon.get();
+ typename pointer_traits<MonitorPtr>::pointer p = _mon.get();
+ detail::assert_plain_old_pointer_not_null(p);
+ return *p;
       }
 
       // move emulation

Modified: sandbox/fmhess/boost/generic_ptr/shared.hpp
==============================================================================
--- sandbox/fmhess/boost/generic_ptr/shared.hpp (original)
+++ sandbox/fmhess/boost/generic_ptr/shared.hpp 2009-08-13 15:13:52 EDT (Thu, 13 Aug 2009)
@@ -387,11 +387,13 @@
 
     reference operator* () const // never throws
     {
+ detail::assert_plain_old_pointer_not_null(px);
         return *px;
     }
 
     pointer operator-> () const // never throws
     {
+ detail::assert_plain_old_pointer_not_null(px);
         return px;
     }
 

Modified: sandbox/fmhess/boost/generic_ptr/throwing.hpp
==============================================================================
--- sandbox/fmhess/boost/generic_ptr/throwing.hpp (original)
+++ sandbox/fmhess/boost/generic_ptr/throwing.hpp 2009-08-13 15:13:52 EDT (Thu, 13 Aug 2009)
@@ -126,7 +126,7 @@
 
       pointer operator->() const
       {
- if(get_plain_old_pointer(px) == 0)
+ if(!px)
         {
           throw std::invalid_argument("Attempted to access object through null pointer.");
         }
@@ -135,7 +135,7 @@
 
       reference operator*() const
       {
- if(get_plain_old_pointer(px) == 0)
+ if(!px)
         {
           throw std::invalid_argument("Attempted to dereference null pointer.");
         }


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