forked from boostorg/smart_ptr
BOOST_NO_EXCEPTIONS support added.
[SVN r14835]
This commit is contained in:
@ -17,11 +17,13 @@
|
|||||||
|
|
||||||
#include <boost/assert.hpp>
|
#include <boost/assert.hpp>
|
||||||
#include <boost/checked_delete.hpp>
|
#include <boost/checked_delete.hpp>
|
||||||
|
#include <boost/throw_exception.hpp>
|
||||||
#include <boost/detail/atomic_count.hpp>
|
#include <boost/detail/atomic_count.hpp>
|
||||||
|
|
||||||
#include <cstddef> // for std::ptrdiff_t
|
#include <cstddef> // for std::ptrdiff_t
|
||||||
#include <algorithm> // for std::swap
|
#include <algorithm> // for std::swap
|
||||||
#include <functional> // for std::less
|
#include <functional> // for std::less
|
||||||
|
#include <new> // for std::bad_alloc
|
||||||
|
|
||||||
namespace boost
|
namespace boost
|
||||||
{
|
{
|
||||||
@ -38,22 +40,36 @@ public:
|
|||||||
|
|
||||||
explicit shared_array(T * p = 0): px(p)
|
explicit shared_array(T * p = 0): px(p)
|
||||||
{
|
{
|
||||||
|
#ifndef BOOST_NO_EXCEPTIONS
|
||||||
|
|
||||||
try // prevent leak if new throws
|
try // prevent leak if new throws
|
||||||
{
|
{
|
||||||
pn = new count_type(1);
|
pn = new count_type(1);
|
||||||
}
|
}
|
||||||
catch(...)
|
catch(...)
|
||||||
{
|
{
|
||||||
checked_array_delete(p);
|
boost::checked_array_delete(p);
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
pn = new count_type(1);
|
||||||
|
|
||||||
|
if(pn == 0)
|
||||||
|
{
|
||||||
|
boost::checked_array_delete(p);
|
||||||
|
boost::throw_exception(std::bad_alloc());
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
~shared_array()
|
~shared_array()
|
||||||
{
|
{
|
||||||
if(--*pn == 0)
|
if(--*pn == 0)
|
||||||
{
|
{
|
||||||
checked_array_delete(px);
|
boost::checked_array_delete(px);
|
||||||
delete pn;
|
delete pn;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,10 +23,12 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <boost/checked_delete.hpp>
|
#include <boost/checked_delete.hpp>
|
||||||
|
#include <boost/throw_exception.hpp>
|
||||||
#include <boost/detail/lightweight_mutex.hpp>
|
#include <boost/detail/lightweight_mutex.hpp>
|
||||||
|
|
||||||
#include <functional> // for std::less
|
#include <functional> // for std::less
|
||||||
#include <exception> // for std::exception
|
#include <exception> // for std::exception
|
||||||
|
#include <new> // for std::bad_alloc
|
||||||
|
|
||||||
#ifdef __BORLANDC__
|
#ifdef __BORLANDC__
|
||||||
# pragma warn -8026 // Functions with excep. spec. are not expanded inline
|
# pragma warn -8026 // Functions with excep. spec. are not expanded inline
|
||||||
@ -95,7 +97,7 @@ public:
|
|||||||
#ifdef BOOST_HAS_THREADS
|
#ifdef BOOST_HAS_THREADS
|
||||||
mutex_type::scoped_lock lock(mtx_);
|
mutex_type::scoped_lock lock(mtx_);
|
||||||
#endif
|
#endif
|
||||||
if(use_count_ == 0 && weak_count_ != 0) throw use_count_is_zero();
|
if(use_count_ == 0 && weak_count_ != 0) boost::throw_exception(boost::use_count_is_zero());
|
||||||
++use_count_;
|
++use_count_;
|
||||||
++weak_count_;
|
++weak_count_;
|
||||||
}
|
}
|
||||||
@ -235,6 +237,8 @@ public:
|
|||||||
|
|
||||||
template<class P, class D> shared_count(P p, D d, void const * = 0): pi_(0)
|
template<class P, class D> shared_count(P p, D d, void const * = 0): pi_(0)
|
||||||
{
|
{
|
||||||
|
#ifndef BOOST_NO_EXCEPTIONS
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
pi_ = new counted_base_impl<P, D>(p, d, 1, 1);
|
pi_ = new counted_base_impl<P, D>(p, d, 1, 1);
|
||||||
@ -244,6 +248,18 @@ public:
|
|||||||
d(p); // delete p
|
d(p); // delete p
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
pi_ = new counted_base_impl<P, D>(p, d, 1, 1);
|
||||||
|
|
||||||
|
if(pi_ == 0)
|
||||||
|
{
|
||||||
|
d(p); // delete p
|
||||||
|
boost::throw_exception(std::bad_alloc());
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class P, class D> shared_count(P, D, counted_base * pi): pi_(pi)
|
template<class P, class D> shared_count(P, D, counted_base * pi): pi_(pi)
|
||||||
|
@ -17,14 +17,16 @@
|
|||||||
|
|
||||||
#include <boost/assert.hpp>
|
#include <boost/assert.hpp>
|
||||||
#include <boost/checked_delete.hpp>
|
#include <boost/checked_delete.hpp>
|
||||||
|
#include <boost/throw_exception.hpp>
|
||||||
#include <boost/detail/atomic_count.hpp>
|
#include <boost/detail/atomic_count.hpp>
|
||||||
|
|
||||||
#ifndef BOOST_NO_AUTO_PTR
|
#ifndef BOOST_NO_AUTO_PTR
|
||||||
#include <memory> // for std::auto_ptr
|
# include <memory> // for std::auto_ptr
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <algorithm> // for std::swap
|
#include <algorithm> // for std::swap
|
||||||
#include <functional> // for std::less
|
#include <functional> // for std::less
|
||||||
|
#include <new> // for std::bad_alloc
|
||||||
|
|
||||||
namespace boost
|
namespace boost
|
||||||
{
|
{
|
||||||
@ -38,25 +40,40 @@ private:
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
typedef T element_type;
|
typedef T element_type;
|
||||||
|
typedef T value_type;
|
||||||
|
|
||||||
explicit shared_ptr(T * p = 0): px(p)
|
explicit shared_ptr(T * p = 0): px(p)
|
||||||
{
|
{
|
||||||
|
#ifndef BOOST_NO_EXCEPTIONS
|
||||||
|
|
||||||
try // prevent leak if new throws
|
try // prevent leak if new throws
|
||||||
{
|
{
|
||||||
pn = new count_type(1);
|
pn = new count_type(1);
|
||||||
}
|
}
|
||||||
catch(...)
|
catch(...)
|
||||||
{
|
{
|
||||||
checked_delete(p);
|
boost::checked_delete(p);
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
pn = new count_type(1);
|
||||||
|
|
||||||
|
if(pn == 0)
|
||||||
|
{
|
||||||
|
boost::checked_delete(p);
|
||||||
|
boost::throw_exception(std::bad_alloc());
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
~shared_ptr()
|
~shared_ptr()
|
||||||
{
|
{
|
||||||
if(--*pn == 0)
|
if(--*pn == 0)
|
||||||
{
|
{
|
||||||
checked_delete(px);
|
boost::checked_delete(px);
|
||||||
delete pn;
|
delete pn;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
#include <boost/assert.hpp>
|
#include <boost/assert.hpp>
|
||||||
#include <boost/checked_delete.hpp>
|
#include <boost/checked_delete.hpp>
|
||||||
|
#include <boost/throw_exception.hpp>
|
||||||
#include <boost/detail/shared_count.hpp>
|
#include <boost/detail/shared_count.hpp>
|
||||||
|
|
||||||
#include <memory> // for std::auto_ptr
|
#include <memory> // for std::auto_ptr
|
||||||
@ -90,6 +90,7 @@ private:
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
typedef T element_type;
|
typedef T element_type;
|
||||||
|
typedef T value_type;
|
||||||
|
|
||||||
shared_ptr(): px(0), pn()
|
shared_ptr(): px(0), pn()
|
||||||
{
|
{
|
||||||
@ -146,7 +147,7 @@ public:
|
|||||||
{
|
{
|
||||||
if (px == 0)
|
if (px == 0)
|
||||||
{
|
{
|
||||||
throw std::bad_cast();
|
boost::throw_exception(std::bad_cast());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user