From 1c2550a2ae826c422cf6d34f1c5c3e687474929d Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Sun, 30 Mar 2014 00:49:23 +0100 Subject: [PATCH] boost::shared_ptr -> std::shared_ptr --- Makefile | 2 + src/boost/checked_delete.hpp | 71 ---- src/boost/detail/shared_count.hpp | 555 -------------------------- src/boost/detail/workaround.hpp | 74 ---- src/boost/enable_shared_from_this.hpp | 68 ---- src/boost/shared_ptr.hpp | 474 ---------------------- src/boost/weak_ptr.hpp | 193 --------- src/libexpr/eval.cc | 1 + src/libstore/build.cc | 46 ++- src/libstore/gc.cc | 4 +- src/libstore/store-api.cc | 8 +- src/libstore/store-api.hh | 7 +- src/nix-daemon/nix-daemon.cc | 2 +- 13 files changed, 38 insertions(+), 1467 deletions(-) delete mode 100644 src/boost/checked_delete.hpp delete mode 100644 src/boost/detail/shared_count.hpp delete mode 100644 src/boost/detail/workaround.hpp delete mode 100644 src/boost/enable_shared_from_this.hpp delete mode 100644 src/boost/shared_ptr.hpp delete mode 100644 src/boost/weak_ptr.hpp diff --git a/Makefile b/Makefile index 78d85ebc5..bcfa89dd2 100644 --- a/Makefile +++ b/Makefile @@ -20,6 +20,8 @@ makefiles = \ doc/manual/local.mk \ tests/local.mk +GLOBAL_CXXFLAGS += -std=c++0x + include Makefile.config include mk/lib.mk diff --git a/src/boost/checked_delete.hpp b/src/boost/checked_delete.hpp deleted file mode 100644 index d7f52122d..000000000 --- a/src/boost/checked_delete.hpp +++ /dev/null @@ -1,71 +0,0 @@ -#ifndef BOOST_CHECKED_DELETE_HPP_INCLUDED -#define BOOST_CHECKED_DELETE_HPP_INCLUDED - -// MS compatible compilers support #pragma once - -#if defined(_MSC_VER) && (_MSC_VER >= 1020) -# pragma once -#endif - -// -// boost/checked_delete.hpp -// -// Copyright (c) 1999, 2000, 2001, 2002 boost.org -// Copyright (c) 2002, 2003 Peter Dimov -// Copyright (c) 2003 Daniel Frey -// Copyright (c) 2003 Howard Hinnant -// -// Permission to copy, use, modify, sell and distribute this software -// is granted provided this copyright notice appears in all copies. -// This software is provided "as is" without express or implied -// warranty, and with no claim as to its suitability for any purpose. -// -// See http://www.boost.org/libs/utility/checked_delete.html for documentation. -// - -namespace boost -{ - -// verify that types are complete for increased safety - -template inline void checked_delete(T * x) -{ - // intentionally complex - simplification causes regressions - typedef char type_must_be_complete[ sizeof(T)? 1: -1 ]; - (void) sizeof(type_must_be_complete); - delete x; -} - -template inline void checked_array_delete(T * x) -{ - typedef char type_must_be_complete[ sizeof(T)? 1: -1 ]; - (void) sizeof(type_must_be_complete); - delete [] x; -} - -template struct checked_deleter -{ - typedef void result_type; - typedef T * argument_type; - - void operator()(T * x) const - { - // boost:: disables ADL - boost::checked_delete(x); - } -}; - -template struct checked_array_deleter -{ - typedef void result_type; - typedef T * argument_type; - - void operator()(T * x) const - { - boost::checked_array_delete(x); - } -}; - -} // namespace boost - -#endif // #ifndef BOOST_CHECKED_DELETE_HPP_INCLUDED diff --git a/src/boost/detail/shared_count.hpp b/src/boost/detail/shared_count.hpp deleted file mode 100644 index 23e78413f..000000000 --- a/src/boost/detail/shared_count.hpp +++ /dev/null @@ -1,555 +0,0 @@ -#ifndef BOOST_DETAIL_SHARED_COUNT_HPP_INCLUDED -#define BOOST_DETAIL_SHARED_COUNT_HPP_INCLUDED - -// MS compatible compilers support #pragma once - -#if defined(_MSC_VER) && (_MSC_VER >= 1020) -# pragma once -#endif - -// -// detail/shared_count.hpp -// -// Copyright (c) 2001, 2002, 2003 Peter Dimov and Multi Media Ltd. -// -// Permission to copy, use, modify, sell and distribute this software -// is granted provided this copyright notice appears in all copies. -// This software is provided "as is" without express or implied -// warranty, and with no claim as to its suitability for any purpose. -// - -//#include - -#if defined(BOOST_SP_USE_STD_ALLOCATOR) && defined(BOOST_SP_USE_QUICK_ALLOCATOR) -# error BOOST_SP_USE_STD_ALLOCATOR and BOOST_SP_USE_QUICK_ALLOCATOR are incompatible. -#endif - -#include -#include -//#include - -#if defined(BOOST_SP_USE_QUICK_ALLOCATOR) -#include -#endif - -#include // std::auto_ptr, std::allocator -#include // std::less -#include // std::exception -#include // std::bad_alloc -#include // std::type_info in get_deleter -#include // std::size_t - -#ifdef __BORLANDC__ -# pragma warn -8026 // Functions with excep. spec. are not expanded inline -# pragma warn -8027 // Functions containing try are not expanded inline -#endif - -namespace boost -{ - -// Debug hooks - -#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS) - -void sp_scalar_constructor_hook(void * px, std::size_t size, void * pn); -void sp_array_constructor_hook(void * px); -void sp_scalar_destructor_hook(void * px, std::size_t size, void * pn); -void sp_array_destructor_hook(void * px); - -#endif - - -// The standard library that comes with Borland C++ 5.5.1 -// defines std::exception and its members as having C calling -// convention (-pc). When the definition of bad_weak_ptr -// is compiled with -ps, the compiler issues an error. -// Hence, the temporary #pragma option -pc below. The version -// check is deliberately conservative. - -#if defined(__BORLANDC__) && __BORLANDC__ == 0x551 -# pragma option push -pc -#endif - -class bad_weak_ptr: public std::exception -{ -public: - - virtual char const * what() const throw() - { - return "boost::bad_weak_ptr"; - } -}; - -#if defined(__BORLANDC__) && __BORLANDC__ == 0x551 -# pragma option pop -#endif - -namespace detail -{ - -class sp_counted_base -{ -private: - - // typedef detail::lightweight_mutex mutex_type; - -public: - - sp_counted_base(): use_count_(1), weak_count_(1) - { - } - - virtual ~sp_counted_base() // nothrow - { - } - - // dispose() is called when use_count_ drops to zero, to release - // the resources managed by *this. - - virtual void dispose() = 0; // nothrow - - // destruct() is called when weak_count_ drops to zero. - - virtual void destruct() // nothrow - { - delete this; - } - - virtual void * get_deleter(std::type_info const & ti) = 0; - - void add_ref_copy() - { -#if defined(BOOST_HAS_THREADS) - mutex_type::scoped_lock lock(mtx_); -#endif - ++use_count_; - } - - void add_ref_lock() - { -#if defined(BOOST_HAS_THREADS) - mutex_type::scoped_lock lock(mtx_); -#endif - if(use_count_ == 0) boost::throw_exception(boost::bad_weak_ptr()); - ++use_count_; - } - - void release() // nothrow - { - { -#if defined(BOOST_HAS_THREADS) - mutex_type::scoped_lock lock(mtx_); -#endif - long new_use_count = --use_count_; - - if(new_use_count != 0) return; - } - - dispose(); - weak_release(); - } - - void weak_add_ref() // nothrow - { -#if defined(BOOST_HAS_THREADS) - mutex_type::scoped_lock lock(mtx_); -#endif - ++weak_count_; - } - - void weak_release() // nothrow - { - long new_weak_count; - - { -#if defined(BOOST_HAS_THREADS) - mutex_type::scoped_lock lock(mtx_); -#endif - new_weak_count = --weak_count_; - } - - if(new_weak_count == 0) - { - destruct(); - } - } - - long use_count() const // nothrow - { -#if defined(BOOST_HAS_THREADS) - mutex_type::scoped_lock lock(mtx_); -#endif - return use_count_; - } - -private: - - sp_counted_base(sp_counted_base const &); - sp_counted_base & operator= (sp_counted_base const &); - - long use_count_; // #shared - long weak_count_; // #weak + (#shared != 0) - -#if defined(BOOST_HAS_THREADS) || defined(BOOST_LWM_WIN32) - mutable mutex_type mtx_; -#endif -}; - -#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS) - -template void cbi_call_constructor_hook(sp_counted_base * pn, T * px, checked_deleter const &, int) -{ - boost::sp_scalar_constructor_hook(px, sizeof(T), pn); -} - -template void cbi_call_constructor_hook(sp_counted_base *, T * px, checked_array_deleter const &, int) -{ - boost::sp_array_constructor_hook(px); -} - -template void cbi_call_constructor_hook(sp_counted_base *, P const &, D const &, long) -{ -} - -template void cbi_call_destructor_hook(sp_counted_base * pn, T * px, checked_deleter const &, int) -{ - boost::sp_scalar_destructor_hook(px, sizeof(T), pn); -} - -template void cbi_call_destructor_hook(sp_counted_base *, T * px, checked_array_deleter const &, int) -{ - boost::sp_array_destructor_hook(px); -} - -template void cbi_call_destructor_hook(sp_counted_base *, P const &, D const &, long) -{ -} - -#endif - -// -// Borland's Codeguard trips up over the -Vx- option here: -// -#ifdef __CODEGUARD__ -# pragma option push -Vx- -#endif - -template class sp_counted_base_impl: public sp_counted_base -{ -private: - - P ptr; // copy constructor must not throw - D del; // copy constructor must not throw - - sp_counted_base_impl(sp_counted_base_impl const &); - sp_counted_base_impl & operator= (sp_counted_base_impl const &); - - typedef sp_counted_base_impl this_type; - -public: - - // pre: initial_use_count <= initial_weak_count, d(p) must not throw - - sp_counted_base_impl(P p, D d): ptr(p), del(d) - { -#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS) - detail::cbi_call_constructor_hook(this, p, d, 0); -#endif - } - - virtual void dispose() // nothrow - { -#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS) - detail::cbi_call_destructor_hook(this, ptr, del, 0); -#endif - del(ptr); - } - - virtual void * get_deleter(std::type_info const & ti) - { - return ti == typeid(D)? &del: 0; - } - -#if defined(BOOST_SP_USE_STD_ALLOCATOR) - - void * operator new(std::size_t) - { - return std::allocator().allocate(1, static_cast(0)); - } - - void operator delete(void * p) - { - std::allocator().deallocate(static_cast(p), 1); - } - -#endif - -#if defined(BOOST_SP_USE_QUICK_ALLOCATOR) - - void * operator new(std::size_t) - { - return quick_allocator::alloc(); - } - - void operator delete(void * p) - { - quick_allocator::dealloc(p); - } - -#endif -}; - -#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS) - -int const shared_count_id = 0x2C35F101; -int const weak_count_id = 0x298C38A4; - -#endif - -class weak_count; - -class shared_count -{ -private: - - sp_counted_base * pi_; - -#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS) - int id_; -#endif - - friend class weak_count; - -public: - - shared_count(): pi_(0) // nothrow -#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS) - , id_(shared_count_id) -#endif - { - } - - template shared_count(P p, D d): pi_(0) -#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS) - , id_(shared_count_id) -#endif - { -#ifndef BOOST_NO_EXCEPTIONS - - try - { - pi_ = new sp_counted_base_impl(p, d); - } - catch(...) - { - d(p); // delete p - throw; - } - -#else - - pi_ = new sp_counted_base_impl(p, d); - - if(pi_ == 0) - { - d(p); // delete p - boost::throw_exception(std::bad_alloc()); - } - -#endif - } - -#ifndef BOOST_NO_AUTO_PTR - - // auto_ptr is special cased to provide the strong guarantee - - template - explicit shared_count(std::auto_ptr & r): pi_(new sp_counted_base_impl< Y *, checked_deleter >(r.get(), checked_deleter())) -#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS) - , id_(shared_count_id) -#endif - { - r.release(); - } - -#endif - - ~shared_count() // nothrow - { - if(pi_ != 0) pi_->release(); -#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS) - id_ = 0; -#endif - } - - shared_count(shared_count const & r): pi_(r.pi_) // nothrow -#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS) - , id_(shared_count_id) -#endif - { - if(pi_ != 0) pi_->add_ref_copy(); - } - - explicit shared_count(weak_count const & r); // throws bad_weak_ptr when r.use_count() == 0 - - shared_count & operator= (shared_count const & r) // nothrow - { - sp_counted_base * tmp = r.pi_; - if(tmp != 0) tmp->add_ref_copy(); - if(pi_ != 0) pi_->release(); - pi_ = tmp; - - return *this; - } - - void swap(shared_count & r) // nothrow - { - sp_counted_base * tmp = r.pi_; - r.pi_ = pi_; - pi_ = tmp; - } - - long use_count() const // nothrow - { - return pi_ != 0? pi_->use_count(): 0; - } - - bool unique() const // nothrow - { - return use_count() == 1; - } - - friend inline bool operator==(shared_count const & a, shared_count const & b) - { - return a.pi_ == b.pi_; - } - - friend inline bool operator<(shared_count const & a, shared_count const & b) - { - return std::less()(a.pi_, b.pi_); - } - - void * get_deleter(std::type_info const & ti) const - { - return pi_? pi_->get_deleter(ti): 0; - } -}; - -#ifdef __CODEGUARD__ -# pragma option pop -#endif - - -class weak_count -{ -private: - - sp_counted_base * pi_; - -#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS) - int id_; -#endif - - friend class shared_count; - -public: - - weak_count(): pi_(0) // nothrow -#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS) - , id_(weak_count_id) -#endif - { - } - - weak_count(shared_count const & r): pi_(r.pi_) // nothrow -#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS) - , id_(shared_count_id) -#endif - { - if(pi_ != 0) pi_->weak_add_ref(); - } - - weak_count(weak_count const & r): pi_(r.pi_) // nothrow -#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS) - , id_(shared_count_id) -#endif - { - if(pi_ != 0) pi_->weak_add_ref(); - } - - ~weak_count() // nothrow - { - if(pi_ != 0) pi_->weak_release(); -#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS) - id_ = 0; -#endif - } - - weak_count & operator= (shared_count const & r) // nothrow - { - sp_counted_base * tmp = r.pi_; - if(tmp != 0) tmp->weak_add_ref(); - if(pi_ != 0) pi_->weak_release(); - pi_ = tmp; - - return *this; - } - - weak_count & operator= (weak_count const & r) // nothrow - { - sp_counted_base * tmp = r.pi_; - if(tmp != 0) tmp->weak_add_ref(); - if(pi_ != 0) pi_->weak_release(); - pi_ = tmp; - - return *this; - } - - void swap(weak_count & r) // nothrow - { - sp_counted_base * tmp = r.pi_; - r.pi_ = pi_; - pi_ = tmp; - } - - long use_count() const // nothrow - { - return pi_ != 0? pi_->use_count(): 0; - } - - friend inline bool operator==(weak_count const & a, weak_count const & b) - { - return a.pi_ == b.pi_; - } - - friend inline bool operator<(weak_count const & a, weak_count const & b) - { - return std::less()(a.pi_, b.pi_); - } -}; - -inline shared_count::shared_count(weak_count const & r): pi_(r.pi_) -#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS) - , id_(shared_count_id) -#endif -{ - if(pi_ != 0) - { - pi_->add_ref_lock(); - } - else - { - boost::throw_exception(boost::bad_weak_ptr()); - } -} - -} // namespace detail - -} // namespace boost - -#ifdef __BORLANDC__ -# pragma warn .8027 // Functions containing try are not expanded inline -# pragma warn .8026 // Functions with excep. spec. are not expanded inline -#endif - -#endif // #ifndef BOOST_DETAIL_SHARED_COUNT_HPP_INCLUDED diff --git a/src/boost/detail/workaround.hpp b/src/boost/detail/workaround.hpp deleted file mode 100644 index 0d5a2b2bc..000000000 --- a/src/boost/detail/workaround.hpp +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef WORKAROUND_DWA2002126_HPP -# define WORKAROUND_DWA2002126_HPP - -// Compiler/library version workaround macro -// -// Usage: -// -// #if BOOST_WORKAROUND(BOOST_MSVC, <= 1200) -// ... // workaround code here -// #endif -// -// When BOOST_STRICT_CONFIG is defined, expands to 0. Otherwise, the -// first argument must be undefined or expand to a numeric -// value. The above expands to: -// -// (BOOST_MSVC) != 0 && (BOOST_MSVC) <= 1200 -// -// When used for workarounds that apply to the latest known version -// and all earlier versions of a compiler, the following convention -// should be observed: -// -// #if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1301)) -// -// The version number in this case corresponds to the last version in -// which the workaround was known to have been required. When -// BOOST_DETECT_OUTDATED_WORKAROUNDS is not the defined, the macro -// BOOST_TESTED_AT(x) expands to "!= 0", which effectively activates -// the workaround for any version of the compiler. When -// BOOST_DETECT_OUTDATED_WORKAROUNDS is defined, a compiler warning or -// error will be issued if the compiler version exceeds the argument -// to BOOST_TESTED_AT(). This can be used to locate workarounds which -// may be obsoleted by newer versions. - -# ifndef BOOST_STRICT_CONFIG - -# define BOOST_WORKAROUND(symbol, test) \ - ((symbol != 0) && (1 % (( (symbol test) ) + 1))) -// ^ ^ ^ ^ -// The extra level of parenthesis nesting above, along with the -// BOOST_OPEN_PAREN indirection below, is required to satisfy the -// broken preprocessor in MWCW 8.3 and earlier. -// -// The basic mechanism works as follows: -// (symbol test) + 1 => if (symbol test) then 2 else 1 -// 1 % ((symbol test) + 1) => if (symbol test) then 1 else 0 -// -// The complication with % is for cooperation with BOOST_TESTED_AT(). -// When "test" is BOOST_TESTED_AT(x) and -// BOOST_DETECT_OUTDATED_WORKAROUNDS is #defined, -// -// symbol test => if (symbol <= x) then 1 else -1 -// (symbol test) + 1 => if (symbol <= x) then 2 else 0 -// 1 % ((symbol test) + 1) => if (symbol <= x) then 1 else divide-by-zero -// - -# ifdef BOOST_DETECT_OUTDATED_WORKAROUNDS -# define BOOST_OPEN_PAREN ( -# define BOOST_TESTED_AT(value) > value) ?(-1): BOOST_OPEN_PAREN 1 -# else -# define BOOST_TESTED_AT(value) != ((value)-(value)) -# endif - -# else - -# define BOOST_WORKAROUND(symbol, test) 0 - -# endif - -#endif // WORKAROUND_DWA2002126_HPP diff --git a/src/boost/enable_shared_from_this.hpp b/src/boost/enable_shared_from_this.hpp deleted file mode 100644 index 1d52e72c2..000000000 --- a/src/boost/enable_shared_from_this.hpp +++ /dev/null @@ -1,68 +0,0 @@ -#ifndef BOOST_ENABLE_SHARED_FROM_THIS_HPP_INCLUDED -#define BOOST_ENABLE_SHARED_FROM_THIS_HPP_INCLUDED - -// -// enable_shared_from_this.hpp -// -// Copyright (c) 2002 Peter Dimov -// -// Permission to copy, use, modify, sell and distribute this software -// is granted provided this copyright notice appears in all copies. -// This software is provided "as is" without express or implied -// warranty, and with no claim as to its suitability for any purpose. -// -// http://www.boost.org/libs/smart_ptr/enable_shared_from_this.html -// - -#include -#include -#include -//#include - -namespace boost -{ - -template class enable_shared_from_this -{ -protected: - - enable_shared_from_this() - { - } - - enable_shared_from_this(enable_shared_from_this const &) - { - } - - enable_shared_from_this & operator=(enable_shared_from_this const &) - { - return *this; - } - - ~enable_shared_from_this() - { - } - -public: - - shared_ptr shared_from_this() - { - shared_ptr p(_internal_weak_this); - BOOST_ASSERT(p.get() == this); - return p; - } - - shared_ptr shared_from_this() const - { - shared_ptr p(_internal_weak_this); - BOOST_ASSERT(p.get() == this); - return p; - } - - typedef T _internal_element_type; // for bcc 5.5.1 - weak_ptr<_internal_element_type> _internal_weak_this; -}; - -} // namespace boost - -#endif // #ifndef BOOST_ENABLE_SHARED_FROM_THIS_HPP_INCLUDED diff --git a/src/boost/shared_ptr.hpp b/src/boost/shared_ptr.hpp deleted file mode 100644 index 1702ad268..000000000 --- a/src/boost/shared_ptr.hpp +++ /dev/null @@ -1,474 +0,0 @@ -#ifndef BOOST_SHARED_PTR_HPP_INCLUDED -#define BOOST_SHARED_PTR_HPP_INCLUDED - -// -// shared_ptr.hpp -// -// (C) Copyright Greg Colvin and Beman Dawes 1998, 1999. -// Copyright (c) 2001, 2002, 2003 Peter Dimov -// -// Permission to copy, use, modify, sell and distribute this software -// is granted provided this copyright notice appears in all copies. -// This software is provided "as is" without express or implied -// warranty, and with no claim as to its suitability for any purpose. -// -// See http://www.boost.org/libs/smart_ptr/shared_ptr.htm for documentation. -// - -//#include // for broken compiler workarounds - -#if defined(BOOST_NO_MEMBER_TEMPLATES) && !defined(BOOST_MSVC6_MEMBER_TEMPLATES) -#include -#else - -#include -#include -#include -#include -#include - -#include // for std::auto_ptr -#include // for std::swap -#include // for std::less -#include // for std::bad_cast -#include // for std::basic_ostream - -#ifdef BOOST_MSVC // moved here to work around VC++ compiler crash -# pragma warning(push) -# pragma warning(disable:4284) // odd return type for operator-> -#endif - -namespace boost -{ - -template class weak_ptr; -template class enable_shared_from_this; - -namespace detail -{ - -struct static_cast_tag {}; -struct const_cast_tag {}; -struct dynamic_cast_tag {}; -struct polymorphic_cast_tag {}; - -template struct shared_ptr_traits -{ - typedef T & reference; -}; - -template<> struct shared_ptr_traits -{ - typedef void reference; -}; - -#if !defined(BOOST_NO_CV_VOID_SPECIALIZATIONS) - -template<> struct shared_ptr_traits -{ - typedef void reference; -}; - -template<> struct shared_ptr_traits -{ - typedef void reference; -}; - -template<> struct shared_ptr_traits -{ - typedef void reference; -}; - -#endif - -// enable_shared_from_this support - -template void sp_enable_shared_from_this(boost::enable_shared_from_this * pe, Y * px, shared_count const & pn) -{ - if(pe != 0) pe->_internal_weak_this._internal_assign(px, pn); -} - -inline void sp_enable_shared_from_this(void const volatile *, void const volatile *, shared_count const &) -{ -} - -} // namespace detail - - -// -// shared_ptr -// -// An enhanced relative of scoped_ptr with reference counted copy semantics. -// The object pointed to is deleted when the last shared_ptr pointing to it -// is destroyed or reset. -// - -template class shared_ptr -{ -private: - - // Borland 5.5.1 specific workaround - typedef shared_ptr this_type; - -public: - - typedef T element_type; - typedef T value_type; - typedef T * pointer; - typedef typename detail::shared_ptr_traits::reference reference; - - shared_ptr(): px(0), pn() // never throws in 1.30+ - { - } - - template - explicit shared_ptr(Y * p): px(p), pn(p, checked_deleter()) // Y must be complete - { - detail::sp_enable_shared_from_this(p, p, pn); - } - - // - // Requirements: D's copy constructor must not throw - // - // shared_ptr will release p by calling d(p) - // - - template shared_ptr(Y * p, D d): px(p), pn(p, d) - { - detail::sp_enable_shared_from_this(p, p, pn); - } - -// generated copy constructor, assignment, destructor are fine... - -// except that Borland C++ has a bug, and g++ with -Wsynth warns -#if defined(__BORLANDC__) || defined(__GNUC__) - - shared_ptr & operator=(shared_ptr const & r) // never throws - { - px = r.px; - pn = r.pn; // shared_count::op= doesn't throw - return *this; - } - -#endif - - template - explicit shared_ptr(weak_ptr const & r): pn(r.pn) // may throw - { - // it is now safe to copy r.px, as pn(r.pn) did not throw - px = r.px; - } - - template - shared_ptr(shared_ptr const & r): px(r.px), pn(r.pn) // never throws - { - } - - template - shared_ptr(shared_ptr const & r, detail::static_cast_tag): px(static_cast(r.px)), pn(r.pn) - { - } - - template - shared_ptr(shared_ptr const & r, detail::const_cast_tag): px(const_cast(r.px)), pn(r.pn) - { - } - - template - shared_ptr(shared_ptr const & r, detail::dynamic_cast_tag): px(dynamic_cast(r.px)), pn(r.pn) - { - if(px == 0) // need to allocate new counter -- the cast failed - { - pn = detail::shared_count(); - } - } - - template - shared_ptr(shared_ptr const & r, detail::polymorphic_cast_tag): px(dynamic_cast(r.px)), pn(r.pn) - { - if(px == 0) - { - boost::throw_exception(std::bad_cast()); - } - } - -#ifndef BOOST_NO_AUTO_PTR - - template - explicit shared_ptr(std::auto_ptr & r): px(r.get()), pn() - { - Y * tmp = r.get(); - pn = detail::shared_count(r); - detail::sp_enable_shared_from_this(tmp, tmp, pn); - } - -#endif - -#if !defined(BOOST_MSVC) || (BOOST_MSVC > 1200) - - template - shared_ptr & operator=(shared_ptr const & r) // never throws - { - px = r.px; - pn = r.pn; // shared_count::op= doesn't throw - return *this; - } - -#endif - -#ifndef BOOST_NO_AUTO_PTR - - template - shared_ptr & operator=(std::auto_ptr & r) - { - this_type(r).swap(*this); - return *this; - } - -#endif - - void reset() // never throws in 1.30+ - { - this_type().swap(*this); - } - - template void reset(Y * p) // Y must be complete - { - BOOST_ASSERT(p == 0 || p != px); // catch self-reset errors - this_type(p).swap(*this); - } - - template void reset(Y * p, D d) - { - this_type(p, d).swap(*this); - } - - reference operator* () const // never throws - { - BOOST_ASSERT(px != 0); - return *px; - } - - T * operator-> () const // never throws - { - BOOST_ASSERT(px != 0); - return px; - } - - T * get() const // never throws - { - return px; - } - - // implicit conversion to "bool" - -#if defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, <= 0x530) - - operator bool () const - { - return px != 0; - } - -#elif defined(__MWERKS__) && BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003)) - typedef T * (this_type::*unspecified_bool_type)() const; - - operator unspecified_bool_type() const // never throws - { - return px == 0? 0: &this_type::get; - } - -#else - - typedef T * this_type::*unspecified_bool_type; - - operator unspecified_bool_type() const // never throws - { - return px == 0? 0: &this_type::px; - } - -#endif - - // operator! is redundant, but some compilers need it - - bool operator! () const // never throws - { - return px == 0; - } - - bool unique() const // never throws - { - return pn.unique(); - } - - long use_count() const // never throws - { - return pn.use_count(); - } - - void swap(shared_ptr & other) // never throws - { - std::swap(px, other.px); - pn.swap(other.pn); - } - - template bool _internal_less(shared_ptr const & rhs) const - { - return pn < rhs.pn; - } - - void * _internal_get_deleter(std::type_info const & ti) const - { - return pn.get_deleter(ti); - } - -// Tasteless as this may seem, making all members public allows member templates -// to work in the absence of member template friends. (Matthew Langston) - -#if 0 - -private: - - template friend class shared_ptr; - template friend class weak_ptr; - - -#endif - - T * px; // contained pointer - detail::shared_count pn; // reference counter - -}; // shared_ptr - -template inline bool operator==(shared_ptr const & a, shared_ptr const & b) -{ - return a.get() == b.get(); -} - -template inline bool operator!=(shared_ptr const & a, shared_ptr const & b) -{ - return a.get() != b.get(); -} - -#if __GNUC__ == 2 && __GNUC_MINOR__ <= 96 - -// Resolve the ambiguity between our op!= and the one in rel_ops - -template inline bool operator!=(shared_ptr const & a, shared_ptr const & b) -{ - return a.get() != b.get(); -} - -#endif - -template inline bool operator<(shared_ptr const & a, shared_ptr const & b) -{ - return a._internal_less(b); -} - -template inline void swap(shared_ptr & a, shared_ptr & b) -{ - a.swap(b); -} - -template shared_ptr static_pointer_cast(shared_ptr const & r) -{ - return shared_ptr(r, detail::static_cast_tag()); -} - -template shared_ptr const_pointer_cast(shared_ptr const & r) -{ - return shared_ptr(r, detail::const_cast_tag()); -} - -template shared_ptr dynamic_pointer_cast(shared_ptr const & r) -{ - return shared_ptr(r, detail::dynamic_cast_tag()); -} - -// shared_*_cast names are deprecated. Use *_pointer_cast instead. - -template shared_ptr shared_static_cast(shared_ptr const & r) -{ - return shared_ptr(r, detail::static_cast_tag()); -} - -template shared_ptr shared_dynamic_cast(shared_ptr const & r) -{ - return shared_ptr(r, detail::dynamic_cast_tag()); -} - -template shared_ptr shared_polymorphic_cast(shared_ptr const & r) -{ - return shared_ptr(r, detail::polymorphic_cast_tag()); -} - -template shared_ptr shared_polymorphic_downcast(shared_ptr const & r) -{ - BOOST_ASSERT(dynamic_cast(r.get()) == r.get()); - return shared_static_cast(r); -} - -// get_pointer() enables boost::mem_fn to recognize shared_ptr - -template inline T * get_pointer(shared_ptr const & p) -{ - return p.get(); -} - -// operator<< - -#if defined(__GNUC__) && (__GNUC__ < 3) - -template std::ostream & operator<< (std::ostream & os, shared_ptr const & p) -{ - os << p.get(); - return os; -} - -#else - -# if defined(BOOST_MSVC) && BOOST_WORKAROUND(BOOST_MSVC, <= 1200 && __SGI_STL_PORT) -// MSVC6 has problems finding std::basic_ostream through the using declaration in namespace _STL -using std::basic_ostream; -template basic_ostream & operator<< (basic_ostream & os, shared_ptr const & p) -# else -template std::basic_ostream & operator<< (std::basic_ostream & os, shared_ptr const & p) -# endif -{ - os << p.get(); - return os; -} - -#endif - -// get_deleter (experimental) - -#if (defined(__GNUC__) && (__GNUC__ < 3)) || (defined(__EDG_VERSION__) && (__EDG_VERSION__ <= 238)) - -// g++ 2.9x doesn't allow static_cast(void *) -// apparently EDG 2.38 also doesn't accept it - -template D * get_deleter(shared_ptr const & p) -{ - void const * q = p._internal_get_deleter(typeid(D)); - return const_cast(static_cast(q)); -} - -#else - -template D * get_deleter(shared_ptr const & p) -{ - return static_cast(p._internal_get_deleter(typeid(D))); -} - -#endif - -} // namespace boost - -#ifdef BOOST_MSVC -# pragma warning(pop) -#endif - -#endif // #if defined(BOOST_NO_MEMBER_TEMPLATES) && !defined(BOOST_MSVC6_MEMBER_TEMPLATES) - -#endif // #ifndef BOOST_SHARED_PTR_HPP_INCLUDED diff --git a/src/boost/weak_ptr.hpp b/src/boost/weak_ptr.hpp deleted file mode 100644 index 3d3b3eb79..000000000 --- a/src/boost/weak_ptr.hpp +++ /dev/null @@ -1,193 +0,0 @@ -#ifndef BOOST_WEAK_PTR_HPP_INCLUDED -#define BOOST_WEAK_PTR_HPP_INCLUDED - -// -// weak_ptr.hpp -// -// Copyright (c) 2001, 2002, 2003 Peter Dimov -// -// Permission to copy, use, modify, sell and distribute this software -// is granted provided this copyright notice appears in all copies. -// This software is provided "as is" without express or implied -// warranty, and with no claim as to its suitability for any purpose. -// -// See http://www.boost.org/libs/smart_ptr/weak_ptr.htm for documentation. -// - -#include - -#ifdef BOOST_MSVC // moved here to work around VC++ compiler crash -# pragma warning(push) -# pragma warning(disable:4284) // odd return type for operator-> -#endif - -namespace boost -{ - -template class weak_ptr -{ -private: - - // Borland 5.5.1 specific workarounds - typedef weak_ptr this_type; - -public: - - typedef T element_type; - - weak_ptr(): px(0), pn() // never throws in 1.30+ - { - } - -// generated copy constructor, assignment, destructor are fine - - -// -// The "obvious" converting constructor implementation: -// -// template -// weak_ptr(weak_ptr const & r): px(r.px), pn(r.pn) // never throws -// { -// } -// -// has a serious problem. -// -// r.px may already have been invalidated. The px(r.px) -// conversion may require access to *r.px (virtual inheritance). -// -// It is not possible to avoid spurious access violations since -// in multithreaded programs r.px may be invalidated at any point. -// - - template - weak_ptr(weak_ptr const & r): pn(r.pn) // never throws - { - px = r.lock().get(); - } - - template - weak_ptr(shared_ptr const & r): px(r.px), pn(r.pn) // never throws - { - } - -#if !defined(BOOST_MSVC) || (BOOST_MSVC > 1200) - - template - weak_ptr & operator=(weak_ptr const & r) // never throws - { - px = r.lock().get(); - pn = r.pn; - return *this; - } - - template - weak_ptr & operator=(shared_ptr const & r) // never throws - { - px = r.px; - pn = r.pn; - return *this; - } - -#endif - - shared_ptr lock() const // never throws - { -#if defined(BOOST_HAS_THREADS) - - // optimization: avoid throw overhead - if(expired()) - { - return shared_ptr(); - } - - try - { - return shared_ptr(*this); - } - catch(bad_weak_ptr const &) - { - // Q: how can we get here? - // A: another thread may have invalidated r after the use_count test above. - return shared_ptr(); - } - -#else - - // optimization: avoid try/catch overhead when single threaded - return expired()? shared_ptr(): shared_ptr(*this); - -#endif - } - - long use_count() const // never throws - { - return pn.use_count(); - } - - bool expired() const // never throws - { - return pn.use_count() == 0; - } - - void reset() // never throws in 1.30+ - { - this_type().swap(*this); - } - - void swap(this_type & other) // never throws - { - std::swap(px, other.px); - pn.swap(other.pn); - } - - void _internal_assign(T * px2, detail::shared_count const & pn2) - { - px = px2; - pn = pn2; - } - - template bool _internal_less(weak_ptr const & rhs) const - { - return pn < rhs.pn; - } - -// Tasteless as this may seem, making all members public allows member templates -// to work in the absence of member template friends. (Matthew Langston) - -#if 0 - -private: - - template friend class weak_ptr; - template friend class shared_ptr; - -#endif - - T * px; // contained pointer - detail::weak_count pn; // reference counter - -}; // weak_ptr - -template inline bool operator<(weak_ptr const & a, weak_ptr const & b) -{ - return a._internal_less(b); -} - -template void swap(weak_ptr & a, weak_ptr & b) -{ - a.swap(b); -} - -// deprecated, provided for backward compatibility -template shared_ptr make_shared(weak_ptr const & r) -{ - return r.lock(); -} - -} // namespace boost - -#ifdef BOOST_MSVC -# pragma warning(pop) -#endif - -#endif // #ifndef BOOST_WEAK_PTR_HPP_INCLUDED diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 04c3418a0..bbf494387 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -6,6 +6,7 @@ #include "globals.hh" #include "eval-inline.hh" +#include #include #include #include diff --git a/src/libstore/build.cc b/src/libstore/build.cc index 5c3307507..b3d2796d8 100644 --- a/src/libstore/build.cc +++ b/src/libstore/build.cc @@ -12,9 +12,6 @@ #include #include #include -#include -#include -#include #include #include @@ -84,19 +81,19 @@ struct HookInstance; /* A pointer to a goal. */ class Goal; -typedef boost::shared_ptr GoalPtr; -typedef boost::weak_ptr WeakGoalPtr; +typedef std::shared_ptr GoalPtr; +typedef std::weak_ptr WeakGoalPtr; /* Set of goals. */ typedef set Goals; -typedef set WeakGoals; +typedef list WeakGoals; /* A map of paths to goals (and the other way around). */ typedef map WeakGoalMap; -class Goal : public boost::enable_shared_from_this +class Goal : public std::enable_shared_from_this { public: typedef enum {ecBusy, ecSuccess, ecFailed, ecNoSubstituters, ecIncompleteClosure} ExitCode; @@ -242,7 +239,7 @@ public: LocalStore & store; - boost::shared_ptr hook; + std::shared_ptr hook; Worker(LocalStore & store); ~Worker(); @@ -300,10 +297,19 @@ public: ////////////////////////////////////////////////////////////////////// +void addToWeakGoals(WeakGoals & goals, GoalPtr p) +{ + // FIXME: necessary? + foreach (WeakGoals::iterator, i, goals) + if (i->lock() == p) return; + goals.push_back(p); +} + + void Goal::addWaitee(GoalPtr waitee) { waitees.insert(waitee); - waitee->waiters.insert(shared_from_this()); + addToWeakGoals(waitee->waiters, shared_from_this()); } @@ -329,7 +335,7 @@ void Goal::waiteeDone(GoalPtr waitee, ExitCode result) GoalPtr goal = *i; WeakGoals waiters2; foreach (WeakGoals::iterator, j, goal->waiters) - if (j->lock() != shared_from_this()) waiters2.insert(*j); + if (j->lock() != shared_from_this()) waiters2.push_back(*j); goal->waiters = waiters2; } waitees.clear(); @@ -735,7 +741,7 @@ private: Pipe builderOut; /* The build hook. */ - boost::shared_ptr hook; + std::shared_ptr hook; /* Whether we're currently doing a chroot build. */ bool useChroot; @@ -743,7 +749,7 @@ private: Path chrootRootDir; /* RAII object to delete the chroot directory. */ - boost::shared_ptr autoDelChroot; + std::shared_ptr autoDelChroot; /* All inputs that are regular files. */ PathSet regularInputPaths; @@ -1512,7 +1518,7 @@ HookReply DerivationGoal::tryBuildHook() if (!settings.useBuildHook || getEnv("NIX_BUILD_HOOK") == "") return rpDecline; if (!worker.hook) - worker.hook = boost::shared_ptr(new HookInstance); + worker.hook = std::shared_ptr(new HookInstance); /* Tell the hook about system features (beyond the system type) required from the build machine. (The hook could parse the @@ -1784,7 +1790,7 @@ void DerivationGoal::startBuilder() if (pathExists(chrootRootDir)) deletePath(chrootRootDir); /* Clean up the chroot directory automatically. */ - autoDelChroot = boost::shared_ptr(new AutoDelete(chrootRootDir)); + autoDelChroot = std::shared_ptr(new AutoDelete(chrootRootDir)); printMsg(lvlChatty, format("setting up chroot environment in `%1%'") % chrootRootDir); @@ -2557,7 +2563,7 @@ private: Pid pid; /* Lock on the store path. */ - boost::shared_ptr outputLock; + std::shared_ptr outputLock; /* Whether to try to repair a valid path. */ bool repair; @@ -2734,7 +2740,7 @@ void SubstitutionGoal::tryToRun() } /* Acquire a lock on the output path. */ - outputLock = boost::shared_ptr(new PathLocks); + outputLock = std::shared_ptr(new PathLocks); if (!outputLock->lockPaths(singleton(storePath), "", false)) { worker.waitForAWhile(shared_from_this()); return; @@ -3012,7 +3018,7 @@ void Worker::removeGoal(GoalPtr goal) void Worker::wakeUp(GoalPtr goal) { goal->trace("woken up"); - awake.insert(goal); + addToWeakGoals(awake, goal); } @@ -3070,21 +3076,21 @@ void Worker::waitForBuildSlot(GoalPtr goal) if (getNrLocalBuilds() < settings.maxBuildJobs) wakeUp(goal); /* we can do it right away */ else - wantingToBuild.insert(goal); + addToWeakGoals(wantingToBuild, goal); } void Worker::waitForAnyGoal(GoalPtr goal) { debug("wait for any goal"); - waitingForAnyGoal.insert(goal); + addToWeakGoals(waitingForAnyGoal, goal); } void Worker::waitForAWhile(GoalPtr goal) { debug("wait for a while"); - waitingForAWhile.insert(goal); + addToWeakGoals(waitingForAWhile, goal); } diff --git a/src/libstore/gc.cc b/src/libstore/gc.cc index e855e8685..96e891f87 100644 --- a/src/libstore/gc.cc +++ b/src/libstore/gc.cc @@ -2,8 +2,6 @@ #include "misc.hh" #include "local-store.hh" -#include - #include #include #include @@ -224,7 +222,7 @@ struct RemoveTempRoots static RemoveTempRoots autoRemoveTempRoots __attribute__((unused)); -typedef boost::shared_ptr FDPtr; +typedef std::shared_ptr FDPtr; typedef list FDs; diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc index 0f250a3c7..0238e5b0b 100644 --- a/src/libstore/store-api.cc +++ b/src/libstore/store-api.cc @@ -316,15 +316,15 @@ void exportPaths(StoreAPI & store, const Paths & paths, namespace nix { -boost::shared_ptr store; +std::shared_ptr store; -boost::shared_ptr openStore(bool reserveSpace) +std::shared_ptr openStore(bool reserveSpace) { if (getEnv("NIX_REMOTE") == "") - return boost::shared_ptr(new LocalStore(reserveSpace)); + return std::shared_ptr(new LocalStore(reserveSpace)); else - return boost::shared_ptr(new RemoteStore()); + return std::shared_ptr(new RemoteStore()); } diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh index 047ccf4aa..b635fee2c 100644 --- a/src/libstore/store-api.hh +++ b/src/libstore/store-api.hh @@ -5,8 +5,7 @@ #include #include - -#include +#include namespace nix { @@ -337,12 +336,12 @@ Paths topoSortPaths(StoreAPI & store, const PathSet & paths); /* For now, there is a single global store API object, but we'll purify that in the future. */ -extern boost::shared_ptr store; +extern std::shared_ptr store; /* Factory method: open the Nix database, either through the local or remote implementation. */ -boost::shared_ptr openStore(bool reserveSpace = true); +std::shared_ptr openStore(bool reserveSpace = true); /* Display a set of paths in human-readable form (i.e., between quotes diff --git a/src/nix-daemon/nix-daemon.cc b/src/nix-daemon/nix-daemon.cc index 2181ecfef..8814fe315 100644 --- a/src/nix-daemon/nix-daemon.cc +++ b/src/nix-daemon/nix-daemon.cc @@ -702,7 +702,7 @@ static void processConnection(bool trusted) #endif /* Open the store. */ - store = boost::shared_ptr(new LocalStore(reserveSpace)); + store = std::shared_ptr(new LocalStore(reserveSpace)); stopWork(); to.flush();