Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r57206 - in trunk: boost/smart_ptr libs/smart_ptr/test
From: fmhess_at_[hidden]
Date: 2009-10-28 18:42:22


Author: fmhess
Date: 2009-10-28 18:42:21 EDT (Wed, 28 Oct 2009)
New Revision: 57206
URL: http://svn.boost.org/trac/boost/changeset/57206

Log:
Brought back code which fixes get_deleter when it is called on a deleter
which has been wrapped inside a deleter_wrapper by "shared_from_raw() in
constructors" support.

Text files modified:
   trunk/boost/smart_ptr/enable_shared_from_raw.hpp | 24 -------------------
   trunk/boost/smart_ptr/shared_ptr.hpp | 49 ++++++++++++++++++++++++++++++++++++++-
   trunk/libs/smart_ptr/test/esft_constructor_test.cpp | 4 +-
   3 files changed, 49 insertions(+), 28 deletions(-)

Modified: trunk/boost/smart_ptr/enable_shared_from_raw.hpp
==============================================================================
--- trunk/boost/smart_ptr/enable_shared_from_raw.hpp (original)
+++ trunk/boost/smart_ptr/enable_shared_from_raw.hpp 2009-10-28 18:42:21 EDT (Wed, 28 Oct 2009)
@@ -26,30 +26,6 @@
 {
 template< class X, class Y > inline void sp_enable_shared_from_this( boost::shared_ptr<X> * ppx, Y const * py, boost::enable_shared_from_raw const * pe );
 
-class esft2_deleter_wrapper
-{
-private:
-
- shared_ptr<void> deleter_;
-
-public:
-
- esft2_deleter_wrapper()
- {
- }
-
- template< class T > void set_deleter( shared_ptr<T> const & deleter )
- {
- deleter_ = deleter;
- }
-
- template< class T> void operator()( T* )
- {
- BOOST_ASSERT( deleter_.use_count() <= 1 );
- deleter_.reset();
- }
-};
-
 } // namespace detail
 
 class enable_shared_from_raw

Modified: trunk/boost/smart_ptr/shared_ptr.hpp
==============================================================================
--- trunk/boost/smart_ptr/shared_ptr.hpp (original)
+++ trunk/boost/smart_ptr/shared_ptr.hpp 2009-10-28 18:42:21 EDT (Wed, 28 Oct 2009)
@@ -583,6 +583,9 @@
 
 // get_deleter
 
+namespace detail
+{
+
 #if ( defined(__GNUC__) && BOOST_WORKAROUND(__GNUC__, < 3) ) || \
     ( defined(__EDG_VERSION__) && BOOST_WORKAROUND(__EDG_VERSION__, <= 238) ) || \
     ( defined(__HP_aCC) && BOOST_WORKAROUND(__HP_aCC, <= 33500) )
@@ -590,7 +593,7 @@
 // g++ 2.9x doesn't allow static_cast<X const *>(void *)
 // apparently EDG 2.38 and HP aCC A.03.35 also don't accept it
 
-template<class D, class T> D * get_deleter(shared_ptr<T> const & p)
+template<class D, class T> D * basic_get_deleter(shared_ptr<T> const & p)
 {
     void const * q = p._internal_get_deleter(BOOST_SP_TYPEID(D));
     return const_cast<D *>(static_cast<D const *>(q));
@@ -598,13 +601,55 @@
 
 #else
 
-template<class D, class T> D * get_deleter(shared_ptr<T> const & p)
+template<class D, class T> D * basic_get_deleter(shared_ptr<T> const & p)
 {
     return static_cast<D *>(p._internal_get_deleter(BOOST_SP_TYPEID(D)));
 }
 
 #endif
 
+class esft2_deleter_wrapper
+{
+private:
+
+ shared_ptr<void> deleter_;
+
+public:
+
+ esft2_deleter_wrapper()
+ {
+ }
+
+ template< class T > void set_deleter( shared_ptr<T> const & deleter )
+ {
+ deleter_ = deleter;
+ }
+ template<typename D> D* get_deleter() const
+ {
+ return boost::detail::basic_get_deleter<D>(deleter_);
+ }
+ template< class T> void operator()( T* )
+ {
+ BOOST_ASSERT( deleter_.use_count() <= 1 );
+ deleter_.reset();
+ }
+};
+
+} // namespace detail
+
+template<class D, class T> D * get_deleter(shared_ptr<T> const & p)
+{
+ D *del = detail::basic_get_deleter<D>(p);
+ if(del == 0)
+ {
+ detail::esft2_deleter_wrapper *del_wrapper = detail::basic_get_deleter<detail::esft2_deleter_wrapper>(p);
+// The following get_deleter method call is fully qualified because
+// older versions of gcc (2.95, 3.2.3) fail to compile it when written del_wrapper->get_deleter<D>()
+ if(del_wrapper) del = del_wrapper->::boost::detail::esft2_deleter_wrapper::get_deleter<D>();
+ }
+ return del;
+}
+
 // atomic access
 
 #if !defined(BOOST_SP_NO_ATOMIC_ACCESS)

Modified: trunk/libs/smart_ptr/test/esft_constructor_test.cpp
==============================================================================
--- trunk/libs/smart_ptr/test/esft_constructor_test.cpp (original)
+++ trunk/libs/smart_ptr/test/esft_constructor_test.cpp 2009-10-28 18:42:21 EDT (Wed, 28 Oct 2009)
@@ -93,8 +93,8 @@
         px.reset();
         BOOST_TEST( early_px.use_count() == 1 );
         BOOST_TEST( X::instances == 1 );
- // X::deleter_type *pd = boost::get_deleter<X::deleter_type>(early_px);
- // BOOST_TEST(pd && *pd == &X::deleter2 );
+ X::deleter_type *pd = boost::get_deleter<X::deleter_type>(early_px);
+ BOOST_TEST(pd && *pd == &X::deleter2 );
     }
 
     BOOST_TEST( X::instances == 0 );


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