Compare commits

..

16 Commits

Author SHA1 Message Date
Peter Dimov
4db7219c32 Merge branch 'develop' 2015-10-27 20:12:16 +02:00
Ion Gaztañaga
3f17244225 Removed the intrin.h-related part
Removed the commented part as the comment clearly says that VC9 has problems when intrin.h is included.
2015-10-18 19:44:17 +02:00
Ion Gaztañaga
ca93749614 Support MSVC-7.1/ intrin.h available >= MSVC-8.0
-> MSVC 7.1 has no intrin.h and needs to use "#pragma intrinsic".
-> intrin.h available since Visual 2005
2015-10-18 12:51:13 +02:00
Peter Dimov
a06123eb87 Merge branch 'develop' 2015-09-28 15:51:01 +03:00
Peter Dimov
df90496583 Disable deprecation warnings on g++/clang 2015-09-10 23:45:47 +03:00
Peter Dimov
20ead68473 Merge branch 'develop' 2015-08-18 21:09:05 +03:00
Peter Dimov
79cde147c9 Merge pull request #17 from jzmaddock/patch-1
Disable explicit operator bool on Oracle C++
2015-08-18 20:54:50 +03:00
jzmaddock
abbe975e8f Disable explicit operator bool on Oracle C++
Although Oracle supports this syntax, advanced usage such as:

if(my_shared_ptr && x)

Fail.  Attempts to wokaround by adding additional operator overloads have so far failed.
2015-08-18 18:14:50 +01:00
Peter Dimov
8ba0730686 Merge pull request #16 from eldiener/sleep_fix_2
Change to Sleep declaration for clang on Windows to match Windows imp…
2015-07-23 01:52:03 +03:00
Edward Diener
686efe100b Updated Sleep declaration only includes _mingw.h when needed. 2015-07-22 18:23:43 -04:00
Edward Diener
acb880d8c2 Change to Sleep declaration for clang on Windows to match Windows implementation being used 2015-07-22 06:51:49 -04:00
Edward Diener
1712b87cb6 Added __declspec(dllimport) for Sleep using clang on Windows. 2015-07-21 15:41:35 -04:00
Peter Dimov
f8943703f8 Merge branch 'develop' 2015-06-06 01:40:42 +03:00
Peter Dimov
a42dda0af4 Apply fix for errata 754327 for ARM Cortex-A9 suggested in ticket #11362 2015-06-06 01:40:01 +03:00
Peter Dimov
9b9b6d3ca6 Merge branch 'develop' 2015-05-12 20:13:50 +03:00
Peter Dimov
d875a68ceb Add constructor/assignment taking boost::movelib::unique_ptr 2015-05-04 01:06:42 +03:00
10 changed files with 403 additions and 7 deletions

View File

@@ -6,7 +6,8 @@
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
#if !defined( BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS ) && !defined( BOOST_NO_CXX11_NULLPTR )
#if !defined( BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS ) && !defined( BOOST_NO_CXX11_NULLPTR )\
&& !(defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, <= 0x5130))
explicit operator bool () const BOOST_NOEXCEPT
{

View File

@@ -28,6 +28,7 @@
#include <boost/smart_ptr/bad_weak_ptr.hpp>
#include <boost/smart_ptr/detail/sp_counted_base.hpp>
#include <boost/smart_ptr/detail/sp_counted_impl.hpp>
#include <boost/smart_ptr/detail/sp_disable_deprecated.hpp>
#include <boost/detail/workaround.hpp>
// In order to avoid circular dependencies with Boost.TR1
// we make sure that our include of <memory> doesn't try to
@@ -40,13 +41,23 @@
# include <new> // std::bad_alloc
#endif
#if !defined( BOOST_NO_CXX11_SMART_PTR )
# include <boost/utility/addressof.hpp>
#include <boost/core/addressof.hpp>
#if defined( BOOST_SP_DISABLE_DEPRECATED )
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
namespace boost
{
namespace movelib
{
template< class T, class D > class unique_ptr;
} // namespace movelib
namespace detail
{
@@ -63,8 +74,6 @@ template< class D > struct sp_inplace_tag
{
};
#if !defined( BOOST_NO_CXX11_SMART_PTR )
template< class T > class sp_reference_wrapper
{
public:
@@ -93,8 +102,6 @@ template< class D > struct sp_convert_reference< D& >
typedef sp_reference_wrapper< D > type;
};
#endif
class weak_count;
class shared_count
@@ -438,6 +445,29 @@ public:
#endif
template<class Y, class D>
explicit shared_count( boost::movelib::unique_ptr<Y, D> & r ): pi_( 0 )
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
, id_(shared_count_id)
#endif
{
typedef typename sp_convert_reference<D>::type D2;
D2 d2( r.get_deleter() );
pi_ = new sp_counted_impl_pd< typename boost::movelib::unique_ptr<Y, D>::pointer, D2 >( r.get(), d2 );
#ifdef BOOST_NO_EXCEPTIONS
if( pi_ == 0 )
{
boost::throw_exception( std::bad_alloc() );
}
#endif
r.release();
}
~shared_count() // nothrow
{
if( pi_ != 0 ) pi_->release();
@@ -668,6 +698,10 @@ inline shared_count::shared_count( weak_count const & r, sp_nothrow_tag ): pi_(
} // namespace boost
#if defined( BOOST_SP_DISABLE_DEPRECATED )
#pragma GCC diagnostic pop
#endif
#ifdef __BORLANDC__
# pragma warn .8027 // Functions containing try are not expanded inline
#endif

View File

@@ -0,0 +1,40 @@
#ifndef BOOST_SMART_PTR_DETAIL_SP_DISABLE_DEPRECATED_HPP_INCLUDED
#define BOOST_SMART_PTR_DETAIL_SP_DISABLE_DEPRECATED_HPP_INCLUDED
// MS compatible compilers support #pragma once
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
# pragma once
#endif
//
// boost/smart_ptr/detail/sp_disable_deprecated.hpp
//
// Copyright 2015 Peter Dimov
//
// 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/config.hpp>
#if defined( __GNUC__ ) && ( defined( __GXX_EXPERIMENTAL_CXX0X__ ) || ( __cplusplus >= 201103L ) )
# if defined( BOOST_GCC )
# if BOOST_GCC >= 40600
# define BOOST_SP_DISABLE_DEPRECATED
# endif
# elif defined( __clang__ ) && defined( __has_warning )
# if __has_warning( "-Wdeprecated-declarations" )
# define BOOST_SP_DISABLE_DEPRECATED
# endif
# endif
#endif
#endif // #ifndef BOOST_SMART_PTR_DETAIL_SP_DISABLE_DEPRECATED_HPP_INCLUDED

View File

@@ -111,6 +111,17 @@ extern "C" long __cdecl _InterlockedCompareExchange( long volatile *, long, long
extern "C" long __cdecl _InterlockedExchange( long volatile *, long );
extern "C" long __cdecl _InterlockedExchangeAdd( long volatile *, long );
# if defined( BOOST_MSVC ) && BOOST_MSVC == 1310
//From MSDN, Visual Studio .NET 2003 spedific: To declare one of the interlocked functions
//for use as an intrinsic, the function must be declared with the leading underscore and
//the new function must appear in a #pragma intrinsic statement.
# pragma intrinsic( _InterlockedIncrement )
# pragma intrinsic( _InterlockedDecrement )
# pragma intrinsic( _InterlockedCompareExchange )
# pragma intrinsic( _InterlockedExchange )
# pragma intrinsic( _InterlockedExchangeAdd )
# endif
#endif
# define BOOST_SP_INTERLOCKED_INCREMENT _InterlockedIncrement

View File

@@ -82,6 +82,7 @@ public:
{
__asm__ __volatile__( BOOST_SP_ARM_BARRIER ::: "memory" );
*const_cast< int volatile* >( &v_ ) = 0;
__asm__ __volatile__( BOOST_SP_ARM_BARRIER ::: "memory" );
}
public:

View File

@@ -60,7 +60,16 @@ namespace detail
{
#if !defined( BOOST_USE_WINDOWS_H ) && !BOOST_PLAT_WINDOWS_RUNTIME
#if !BOOST_COMP_CLANG || !defined __MINGW32__
extern "C" void __stdcall Sleep( unsigned long ms );
#else
#include <_mingw.h>
#if !defined __MINGW64_VERSION_MAJOR
extern "C" void __stdcall Sleep( unsigned long ms );
#else
extern "C" __declspec(dllimport) void __stdcall Sleep( unsigned long ms );
#endif
#endif
#endif
inline void yield( unsigned k )

View File

@@ -15,12 +15,18 @@
#include <boost/assert.hpp>
#include <boost/checked_delete.hpp>
#include <boost/smart_ptr/detail/sp_nullptr_t.hpp>
#include <boost/smart_ptr/detail/sp_disable_deprecated.hpp>
#include <boost/detail/workaround.hpp>
#ifndef BOOST_NO_AUTO_PTR
# include <memory> // for std::auto_ptr
#endif
#if defined( BOOST_SP_DISABLE_DEPRECATED )
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
namespace boost
{
@@ -154,4 +160,8 @@ template<class T> inline T * get_pointer(scoped_ptr<T> const & p) BOOST_NOEXCEPT
} // namespace boost
#if defined( BOOST_SP_DISABLE_DEPRECATED )
#pragma GCC diagnostic pop
#endif
#endif // #ifndef BOOST_SMART_PTR_SCOPED_PTR_HPP_INCLUDED

View File

@@ -29,6 +29,7 @@
#include <boost/detail/workaround.hpp>
#include <boost/smart_ptr/detail/sp_convertible.hpp>
#include <boost/smart_ptr/detail/sp_nullptr_t.hpp>
#include <boost/smart_ptr/detail/sp_disable_deprecated.hpp>
#if !defined(BOOST_SP_NO_ATOMIC_ACCESS)
#include <boost/smart_ptr/detail/spinlock_pool.hpp>
@@ -47,6 +48,11 @@
#endif
#endif
#if defined( BOOST_SP_DISABLE_DEPRECATED )
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
namespace boost
{
@@ -55,6 +61,13 @@ template<class T> class weak_ptr;
template<class T> class enable_shared_from_this;
class enable_shared_from_raw;
namespace movelib
{
template< class T, class D > class unique_ptr;
} // namespace movelib
namespace detail
{
@@ -495,6 +508,17 @@ public:
#endif
template< class Y, class D >
shared_ptr( boost::movelib::unique_ptr< Y, D > r ): px( r.get() ), pn()
{
boost::detail::sp_assert_convertible< Y, T >();
typename boost::movelib::unique_ptr< Y, D >::pointer tmp = r.get();
pn = boost::detail::shared_count( r );
boost::detail::sp_deleter_construct( this, tmp );
}
// assignment
shared_ptr & operator=( shared_ptr const & r ) BOOST_NOEXCEPT
@@ -556,6 +580,27 @@ public:
#endif
template<class Y, class D>
shared_ptr & operator=( boost::movelib::unique_ptr<Y, D> r )
{
// this_type( static_cast< unique_ptr<Y, D> && >( r ) ).swap( *this );
boost::detail::sp_assert_convertible< Y, T >();
typename boost::movelib::unique_ptr< Y, D >::pointer p = r.get();
shared_ptr tmp;
tmp.px = p;
tmp.pn = boost::detail::shared_count( r );
boost::detail::sp_deleter_construct( &tmp, p );
tmp.swap( *this );
return *this;
}
// Move support
#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
@@ -1025,4 +1070,8 @@ template< class T > std::size_t hash_value( boost::shared_ptr<T> const & p ) BOO
} // namespace boost
#if defined( BOOST_SP_DISABLE_DEPRECATED )
#pragma GCC diagnostic pop
#endif
#endif // #ifndef BOOST_SMART_PTR_SHARED_PTR_HPP_INCLUDED

View File

@@ -179,5 +179,7 @@ import testing ;
[ run weak_from_this_test.cpp ]
[ run weak_from_this_test2.cpp ]
[ run sp_bml_unique_ptr_test.cpp ]
;
}

View File

@@ -0,0 +1,239 @@
//
// sp_bml_unique_ptr_test.cpp
//
// Copyright (c) 2012, 2015 Peter Dimov
//
// 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/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <boost/move/unique_ptr.hpp>
#include <memory>
#include <utility>
struct X: public boost::enable_shared_from_this< X >
{
static int instances;
X()
{
++instances;
}
~X()
{
--instances;
}
private:
X( X const & );
X & operator=( X const & );
};
int X::instances = 0;
struct Y
{
static int instances;
bool deleted_;
Y(): deleted_( false )
{
++instances;
}
~Y()
{
BOOST_TEST( deleted_ );
--instances;
}
private:
Y( Y const & );
Y & operator=( Y const & );
};
int Y::instances = 0;
struct YD
{
void operator()( Y* p ) const
{
p->deleted_ = true;
delete p;
}
};
int main()
{
{
BOOST_TEST( X::instances == 0 );
boost::movelib::unique_ptr<X> p( new X );
BOOST_TEST( X::instances == 1 );
boost::shared_ptr<X> p2( boost::move( p ) );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( p.get() == 0 );
boost::shared_ptr<X> p3 = p2->shared_from_this();
BOOST_TEST( p2 == p3 );
BOOST_TEST( !(p2 < p3) && !(p3 < p2) );
p2.reset();
p3.reset();
BOOST_TEST( X::instances == 0 );
p2 = boost::movelib::unique_ptr<X>( new X );
BOOST_TEST( X::instances == 1 );
p2 = boost::movelib::unique_ptr<X>( new X );
BOOST_TEST( X::instances == 1 );
p3 = p2->shared_from_this();
BOOST_TEST( p2 == p3 );
BOOST_TEST( !(p2 < p3) && !(p3 < p2) );
p2.reset();
p3.reset();
BOOST_TEST( X::instances == 0 );
}
{
BOOST_TEST( X::instances == 0 );
boost::movelib::unique_ptr<X> p( new X );
BOOST_TEST( X::instances == 1 );
boost::shared_ptr<X const> p2( boost::move( p ) );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( p.get() == 0 );
boost::shared_ptr<X const> p3 = p2->shared_from_this();
BOOST_TEST( p2 == p3 );
BOOST_TEST( !(p2 < p3) && !(p3 < p2) );
p2.reset();
p3.reset();
BOOST_TEST( X::instances == 0 );
p2 = boost::movelib::unique_ptr<X>( new X );
BOOST_TEST( X::instances == 1 );
p2 = boost::movelib::unique_ptr<X>( new X );
BOOST_TEST( X::instances == 1 );
p3 = p2->shared_from_this();
BOOST_TEST( p2 == p3 );
BOOST_TEST( !(p2 < p3) && !(p3 < p2) );
p2.reset();
p3.reset();
BOOST_TEST( X::instances == 0 );
}
{
BOOST_TEST( X::instances == 0 );
boost::movelib::unique_ptr<X> p( new X );
BOOST_TEST( X::instances == 1 );
boost::shared_ptr<void> p2( boost::move( p ) );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( p.get() == 0 );
p2.reset();
BOOST_TEST( X::instances == 0 );
p2 = boost::movelib::unique_ptr<X>( new X );
BOOST_TEST( X::instances == 1 );
p2 = boost::movelib::unique_ptr<X>( new X );
BOOST_TEST( X::instances == 1 );
p2.reset();
BOOST_TEST( X::instances == 0 );
}
{
BOOST_TEST( Y::instances == 0 );
boost::movelib::unique_ptr<Y, YD> p( new Y, YD() );
BOOST_TEST( Y::instances == 1 );
boost::shared_ptr<Y> p2( boost::move( p ) );
BOOST_TEST( Y::instances == 1 );
BOOST_TEST( p.get() == 0 );
p2.reset();
BOOST_TEST( Y::instances == 0 );
p2 = boost::movelib::unique_ptr<Y, YD>( new Y, YD() );
BOOST_TEST( Y::instances == 1 );
p2 = boost::movelib::unique_ptr<Y, YD>( new Y, YD() );
BOOST_TEST( Y::instances == 1 );
p2.reset();
BOOST_TEST( Y::instances == 0 );
}
{
BOOST_TEST( Y::instances == 0 );
YD yd;
boost::movelib::unique_ptr<Y, YD&> p( new Y, yd );
BOOST_TEST( Y::instances == 1 );
boost::shared_ptr<Y> p2( boost::move( p ) );
BOOST_TEST( Y::instances == 1 );
BOOST_TEST( p.get() == 0 );
p2.reset();
BOOST_TEST( Y::instances == 0 );
p2 = boost::movelib::unique_ptr<Y, YD&>( new Y, yd );
BOOST_TEST( Y::instances == 1 );
p2 = boost::movelib::unique_ptr<Y, YD&>( new Y, yd );
BOOST_TEST( Y::instances == 1 );
p2.reset();
BOOST_TEST( Y::instances == 0 );
}
{
BOOST_TEST( Y::instances == 0 );
YD yd;
boost::movelib::unique_ptr<Y, YD const&> p( new Y, yd );
BOOST_TEST( Y::instances == 1 );
boost::shared_ptr<Y> p2( boost::move( p ) );
BOOST_TEST( Y::instances == 1 );
BOOST_TEST( p.get() == 0 );
p2.reset();
BOOST_TEST( Y::instances == 0 );
p2 = boost::movelib::unique_ptr<Y, YD const&>( new Y, yd );
BOOST_TEST( Y::instances == 1 );
p2 = boost::movelib::unique_ptr<Y, YD const&>( new Y, yd );
BOOST_TEST( Y::instances == 1 );
p2.reset();
BOOST_TEST( Y::instances == 0 );
}
return boost::report_errors();
}