Boost logo

Boost-Commit :

From: emil_at_[hidden]
Date: 2008-08-30 21:39:01


Author: emildotchevski
Date: 2008-08-30 21:39:00 EDT (Sat, 30 Aug 2008)
New Revision: 48482
URL: http://svn.boost.org/trac/boost/changeset/48482

Log:
Both enable_error_info.hpp and enable_current_exception.hpp now do not depend on intrusive_ptr or any other Boost lib.
Added:
   trunk/boost/exception/detail/refcount_ptr.hpp (contents, props changed)
   trunk/libs/exception/test/refcount_ptr_test.cpp (contents, props changed)
Text files modified:
   trunk/boost/exception/detail/counted_base.hpp | 9 +--------
   trunk/boost/exception/enable_error_info.hpp | 26 +-------------------------
   trunk/boost/exception/exception.hpp | 24 +++++-------------------
   trunk/boost/exception/get_error_info.hpp | 4 ++--
   trunk/boost/exception/info.hpp | 9 +++++----
   trunk/boost/exception_ptr.hpp | 1 +
   trunk/libs/exception/test/Jamfile.v2 | 1 +
   7 files changed, 16 insertions(+), 58 deletions(-)

Modified: trunk/boost/exception/detail/counted_base.hpp
==============================================================================
--- trunk/boost/exception/detail/counted_base.hpp (original)
+++ trunk/boost/exception/detail/counted_base.hpp 2008-08-30 21:39:00 EDT (Sat, 30 Aug 2008)
@@ -6,8 +6,6 @@
 #ifndef UUID_DBA0D90C930911DCBA7B675A56D89593
 #define UUID_DBA0D90C930911DCBA7B675A56D89593
 
-#include <boost/detail/workaround.hpp>
-
 namespace
 boost
     {
@@ -36,12 +34,7 @@
 
             protected:
 
-#if BOOST_WORKAROUND( __GNUC__, BOOST_TESTED_AT(4) )
-virtual //Disable bogus GCC warning.
-#endif
-#if BOOST_WORKAROUND( BOOST_MSVC, BOOST_TESTED_AT(1500) )
-virtual //Disable bogus msvc warning.
-#endif
+ virtual
             ~counted_base() throw()
                 {
                 }

Added: trunk/boost/exception/detail/refcount_ptr.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/exception/detail/refcount_ptr.hpp 2008-08-30 21:39:00 EDT (Sat, 30 Aug 2008)
@@ -0,0 +1,79 @@
+//Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc.
+
+//Distributed under the Boost Software License, Version 1.0. (See accompanying
+//file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef UUID_490EADC876F011DDA2F00A4756D89593
+#define UUID_490EADC876F011DDA2F00A4756D89593
+
+namespace
+boost
+ {
+ namespace
+ exception_detail
+ {
+ template <class T>
+ class
+ refcount_ptr
+ {
+ public:
+
+ refcount_ptr():
+ px_(0)
+ {
+ }
+
+ ~refcount_ptr()
+ {
+ release();
+ }
+
+ refcount_ptr( refcount_ptr const & x ):
+ px_(x.px_)
+ {
+ add_ref();
+ }
+
+ refcount_ptr &
+ operator=( refcount_ptr const & x )
+ {
+ adopt(x.px_);
+ return *this;
+ }
+
+ void
+ adopt( T * px )
+ {
+ release();
+ px_=px;
+ add_ref();
+ }
+
+ T *
+ get() const
+ {
+ return px_;
+ }
+
+ private:
+
+ T * px_;
+
+ void
+ add_ref()
+ {
+ if( px_ )
+ intrusive_ptr_add_ref(px_);
+ }
+
+ void
+ release()
+ {
+ if( px_ )
+ intrusive_ptr_release(px_);
+ }
+ };
+ }
+ }
+
+#endif

Modified: trunk/boost/exception/enable_error_info.hpp
==============================================================================
--- trunk/boost/exception/enable_error_info.hpp (original)
+++ trunk/boost/exception/enable_error_info.hpp 2008-08-30 21:39:00 EDT (Sat, 30 Aug 2008)
@@ -7,8 +7,6 @@
 #define UUID_0C5D492E909711DCB658AD4556D89593
 
 #include <boost/exception/exception.hpp>
-#include <boost/detail/workaround.hpp>
-#include <boost/config.hpp>
 #include <stddef.h>
 
 namespace
@@ -57,43 +55,21 @@
             typedef error_info_injector<T> type;
             };
 
-#if BOOST_WORKAROUND(__BORLANDC__,BOOST_TESTED_AT(0x582))
- template <class T>
- struct
- sizeof_dispatch
- {
- BOOST_STATIC_CONSTANT(int, value = sizeof(dispatch((T*)0)) );
- };
-
- template <class T>
- struct
- enable_error_info_return_type
- {
- typedef typename enable_error_info_helper<T,sizeof_dispatch<T>::value>::type type;
- };
-#else
         template <class T>
         struct
         enable_error_info_return_type
             {
             typedef typename enable_error_info_helper<T,sizeof(dispatch((T*)0))>::type type;
             };
-#endif
         }
 
     template <class T>
     inline
-#if !BOOST_WORKAROUND(__BORLANDC__,BOOST_TESTED_AT(0x582))
     typename
-#endif
     exception_detail::enable_error_info_return_type<T>::type
     enable_error_info( T const & x )
         {
- return
-#if !BOOST_WORKAROUND(__BORLANDC__,BOOST_TESTED_AT(0x582))
- typename
-#endif
- exception_detail::enable_error_info_return_type<T>::type(x);
+ return typename exception_detail::enable_error_info_return_type<T>::type(x);
         }
     }
 

Modified: trunk/boost/exception/exception.hpp
==============================================================================
--- trunk/boost/exception/exception.hpp (original)
+++ trunk/boost/exception/exception.hpp 2008-08-30 21:39:00 EDT (Sat, 30 Aug 2008)
@@ -7,7 +7,7 @@
 #define UUID_274DA366004E11DCB1DDFE2E56D89593
 
 #include <boost/exception/detail/counted_base.hpp>
-#include <boost/intrusive_ptr.hpp>
+#include <boost/exception/detail/refcount_ptr.hpp>
 
 namespace
 boost
@@ -61,28 +61,16 @@
             {
             }
 
-#if BOOST_WORKAROUND( BOOST_MSVC, BOOST_TESTED_AT(1500) )
- //Force class exception to be abstract.
- //Otherwise, MSVC bug allows throw exception(), even though the copy constructor is protected.
         virtual ~exception() throw()=0;
-#else
-#if BOOST_WORKAROUND( __GNUC__, BOOST_TESTED_AT(4) )
- virtual //Disable bogus GCC warning.
-#endif
- ~exception() throw()
- {
- }
-#endif
 
         char const *
         _diagnostic_information() const throw()
             {
- if( data_ )
+ if( exception_detail::error_info_container * c=data_.get() )
                 try
                     {
- char const * w = data_->diagnostic_information();
- BOOST_ASSERT(w!=0);
- return w;
+ if( char const * w = c->diagnostic_information() )
+ return w;
                     }
                 catch(...)
                     {
@@ -97,16 +85,14 @@
         template <class ErrorInfo>
         friend shared_ptr<typename ErrorInfo::value_type const> exception_detail::get_data( exception const & );
 
- mutable intrusive_ptr<exception_detail::error_info_container> data_;
+ mutable exception_detail::refcount_ptr<exception_detail::error_info_container> data_;
         };
 
-#if BOOST_WORKAROUND( BOOST_MSVC, BOOST_TESTED_AT(1500) ) //See above.
     inline
     exception::
     ~exception() throw()
         {
         }
-#endif
     }
 
 #endif

Modified: trunk/boost/exception/get_error_info.hpp
==============================================================================
--- trunk/boost/exception/get_error_info.hpp (original)
+++ trunk/boost/exception/get_error_info.hpp 2008-08-30 21:39:00 EDT (Sat, 30 Aug 2008)
@@ -22,8 +22,8 @@
         shared_ptr<typename ErrorInfo::value_type const>
         get_data( exception const & x )
             {
- if( x.data_ )
- if( shared_ptr<exception_detail::error_info_base const> eib = x.data_->get(BOOST_EXCEPTION_STATIC_TYPEID(ErrorInfo)) )
+ if( exception_detail::error_info_container * c=x.data_.get() )
+ if( shared_ptr<exception_detail::error_info_base const> eib = c->get(BOOST_EXCEPTION_STATIC_TYPEID(ErrorInfo)) )
                     {
 #ifndef BOOST_NO_RTTI
                     BOOST_ASSERT( 0!=dynamic_cast<ErrorInfo const *>(eib.get()) );

Modified: trunk/boost/exception/info.hpp
==============================================================================
--- trunk/boost/exception/info.hpp (original)
+++ trunk/boost/exception/info.hpp 2008-08-30 21:39:00 EDT (Sat, 30 Aug 2008)
@@ -126,7 +126,7 @@
 
             private:
 
- friend class boost::exception;
+ friend class boost::exception;
 
             typedef std::map< type_info_, shared_ptr<error_info_base const> > error_info_map;
             error_info_map info_;
@@ -151,9 +151,10 @@
         void
         set_data( exception const * e, shared_ptr<exception_detail::error_info_base const> const & x, exception_detail::type_info_ const & typeid_ )
             {
- if( !e->data_ )
- e->data_ = intrusive_ptr<exception_detail::error_info_container>(new exception_detail::error_info_container_impl);
- e->data_->set(x,typeid_);
+ exception_detail::error_info_container * c;
+ if( !(c=e->data_.get()) )
+ e->data_.adopt(c=new exception_detail::error_info_container_impl);
+ c->set(x,typeid_);
             }
         }
 

Modified: trunk/boost/exception_ptr.hpp
==============================================================================
--- trunk/boost/exception_ptr.hpp (original)
+++ trunk/boost/exception_ptr.hpp 2008-08-30 21:39:00 EDT (Sat, 30 Aug 2008)
@@ -9,6 +9,7 @@
 #include <boost/exception/enable_current_exception.hpp>
 #include <boost/exception/detail/type_info.hpp>
 #include <boost/detail/atomic_count.hpp>
+#include <boost/intrusive_ptr.hpp>
 #include <stdexcept>
 #include <new>
 

Modified: trunk/libs/exception/test/Jamfile.v2
==============================================================================
--- trunk/libs/exception/test/Jamfile.v2 (original)
+++ trunk/libs/exception/test/Jamfile.v2 2008-08-30 21:39:00 EDT (Sat, 30 Aug 2008)
@@ -29,6 +29,7 @@
 run errno_test.cpp ;
 run error_info_test.cpp ;
 run diagnostic_information_test.cpp ;
+run refcount_ptr_test.cpp ;
 compile-fail exception_fail.cpp ;
 compile-fail throw_exception_fail.cpp ;
 

Added: trunk/libs/exception/test/refcount_ptr_test.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/exception/test/refcount_ptr_test.cpp 2008-08-30 21:39:00 EDT (Sat, 30 Aug 2008)
@@ -0,0 +1,105 @@
+//Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc.
+
+//Distributed under the Boost Software License, Version 1.0. (See accompanying
+//file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#include <boost/exception/detail/refcount_ptr.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+struct
+test_type
+ {
+ test_type( int & count ):
+ count_(count)
+ {
+ BOOST_TEST(count_==42);
+ count_=0;
+ }
+
+ ~test_type()
+ {
+ BOOST_TEST(!count_);
+ count_=42;
+ }
+
+ friend
+ void
+ intrusive_ptr_add_ref( test_type const * c )
+ {
+ ++c->count_;
+ }
+
+ friend
+ void
+ intrusive_ptr_release( test_type const * c )
+ {
+ if( !--c->count_ )
+ delete c;
+ }
+
+ private:
+
+ test_type( test_type const & );
+ test_type & operator=( test_type const & );
+
+ mutable int & count_;
+ };
+
+int
+main()
+ {
+ using boost::exception_detail::refcount_ptr;
+
+ {
+ refcount_ptr<test_type> x;
+ BOOST_TEST(!x.get());
+ }
+
+ {
+ int count=42;
+ test_type * a=new test_type(count);
+ BOOST_TEST(!count);
+ {
+ refcount_ptr<test_type> p;
+ BOOST_TEST(0==count);
+ p.adopt(a);
+ BOOST_TEST(p.get()==a);
+ BOOST_TEST(1==count);
+ {
+ refcount_ptr<test_type> q;
+ q.adopt(p.get());
+ BOOST_TEST(q.get()==a);
+ BOOST_TEST(2==count);
+ {
+ refcount_ptr<test_type> t(p);
+ BOOST_TEST(t.get()==a);
+ BOOST_TEST(3==count);
+ {
+ refcount_ptr<test_type> n;
+ n=t;
+ BOOST_TEST(n.get()==a);
+ BOOST_TEST(4==count);
+ int cb=42;
+ test_type * b=new test_type(cb);
+ BOOST_TEST(0==cb);
+ n.adopt(b);
+ BOOST_TEST(1==cb);
+ BOOST_TEST(n.get()==b);
+ BOOST_TEST(3==count);
+ n.adopt(0);
+ BOOST_TEST(42==cb);
+ }
+ BOOST_TEST(t.get()==a);
+ BOOST_TEST(3==count);
+ }
+ BOOST_TEST(q.get()==a);
+ BOOST_TEST(2==count);
+ }
+ BOOST_TEST(p.get()==a);
+ BOOST_TEST(1==count);
+ }
+ BOOST_TEST(42==count);
+ }
+
+ return boost::report_errors();
+ }


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