From 214e4f8fe625ad54aac3b215909e0b994a5768ec Mon Sep 17 00:00:00 2001 From: theraven Date: Wed, 10 Jul 2013 16:28:24 +0000 Subject: Import new libcxxrt / libc++. This brings some bug fixes, including a potential race condition for static initialisers. --- contrib/libc++/include/vector | 92 +++++++++++++++++++------------------------ 1 file changed, 40 insertions(+), 52 deletions(-) (limited to 'contrib/libc++/include/vector') diff --git a/contrib/libc++/include/vector b/contrib/libc++/include/vector index e04c267..046d92d 100644 --- a/contrib/libc++/include/vector +++ b/contrib/libc++/include/vector @@ -365,12 +365,7 @@ protected: {return static_cast(__end_cap() - __begin_);} _LIBCPP_INLINE_VISIBILITY - void __destruct_at_end(const_pointer __new_last) _NOEXCEPT - {__destruct_at_end(__new_last, false_type());} - _LIBCPP_INLINE_VISIBILITY - void __destruct_at_end(const_pointer __new_last, false_type) _NOEXCEPT; - _LIBCPP_INLINE_VISIBILITY - void __destruct_at_end(const_pointer __new_last, true_type) _NOEXCEPT; + void __destruct_at_end(pointer __new_last) _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY void __copy_assign_alloc(const __vector_base& __c) @@ -437,43 +432,35 @@ private: template _LIBCPP_INLINE_VISIBILITY inline void -__vector_base<_Tp, _Allocator>::__destruct_at_end(const_pointer __new_last, false_type) _NOEXCEPT +__vector_base<_Tp, _Allocator>::__destruct_at_end(pointer __new_last) _NOEXCEPT { while (__new_last != __end_) - __alloc_traits::destroy(__alloc(), const_cast(--__end_)); -} - -template -_LIBCPP_INLINE_VISIBILITY inline -void -__vector_base<_Tp, _Allocator>::__destruct_at_end(const_pointer __new_last, true_type) _NOEXCEPT -{ - __end_ = const_cast(__new_last); + __alloc_traits::destroy(__alloc(), _VSTD::__to_raw_pointer(--__end_)); } template _LIBCPP_INLINE_VISIBILITY inline __vector_base<_Tp, _Allocator>::__vector_base() _NOEXCEPT_(is_nothrow_default_constructible::value) - : __begin_(0), - __end_(0), - __end_cap_(0) + : __begin_(nullptr), + __end_(nullptr), + __end_cap_(nullptr) { } template _LIBCPP_INLINE_VISIBILITY inline __vector_base<_Tp, _Allocator>::__vector_base(const allocator_type& __a) - : __begin_(0), - __end_(0), - __end_cap_(0, __a) + : __begin_(nullptr), + __end_(nullptr), + __end_cap_(nullptr, __a) { } template __vector_base<_Tp, _Allocator>::~__vector_base() { - if (__begin_ != 0) + if (__begin_ != nullptr) { clear(); __alloc_traits::deallocate(__alloc(), __begin_, capacity()); @@ -797,7 +784,7 @@ private: _NOEXCEPT_(is_nothrow_move_assignable::value); void __move_assign(vector& __c, false_type); _LIBCPP_INLINE_VISIBILITY - void __destruct_at_end(const_pointer __new_last) _NOEXCEPT + void __destruct_at_end(pointer __new_last) _NOEXCEPT { #if _LIBCPP_DEBUG_LEVEL >= 2 __c_node* __c = __get_db()->__find_c_and_lock(this); @@ -878,11 +865,11 @@ template void vector<_Tp, _Allocator>::deallocate() _NOEXCEPT { - if (this->__begin_ != 0) + if (this->__begin_ != nullptr) { clear(); __alloc_traits::deallocate(this->__alloc(), this->__begin_, capacity()); - this->__begin_ = this->__end_ = this->__end_cap() = 0; + this->__begin_ = this->__end_ = this->__end_cap() = nullptr; } } @@ -1171,7 +1158,7 @@ vector<_Tp, _Allocator>::vector(vector&& __x) this->__begin_ = __x.__begin_; this->__end_ = __x.__end_; this->__end_cap() = __x.__end_cap(); - __x.__begin_ = __x.__end_ = __x.__end_cap() = 0; + __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr; } template @@ -1597,7 +1584,8 @@ vector<_Tp, _Allocator>::erase(const_iterator __position) #endif _LIBCPP_ASSERT(__position != end(), "vector::erase(iterator) called with a non-dereferenceable iterator"); - pointer __p = const_cast(&*__position); + difference_type __ps = __position - cbegin(); + pointer __p = this->__begin_ + __ps; iterator __r = __make_iter(__p); this->__destruct_at_end(_VSTD::move(__p + 1, this->__end_, __p)); return __r; @@ -1943,9 +1931,9 @@ template bool vector<_Tp, _Allocator>::__invariants() const { - if (this->__begin_ == 0) + if (this->__begin_ == nullptr) { - if (this->__end_ != 0 || this->__end_cap() != 0) + if (this->__end_ != nullptr || this->__end_cap() != nullptr) return false; } else @@ -2307,7 +2295,7 @@ private: {return const_iterator(__begin_ + __pos / __bits_per_word, static_cast(__pos % __bits_per_word));} _LIBCPP_INLINE_VISIBILITY iterator __const_iterator_cast(const_iterator __p) _NOEXCEPT - {return iterator(const_cast<__storage_pointer>(__p.__seg_), __p.__ctz_);} + {return begin() + (__p - cbegin());} #endif // _LIBCPP_DEBUG _LIBCPP_INLINE_VISIBILITY @@ -2414,11 +2402,11 @@ template void vector::deallocate() _NOEXCEPT { - if (this->__begin_ != 0) + if (this->__begin_ != nullptr) { __storage_traits::deallocate(this->__alloc(), this->__begin_, __cap()); __invalidate_all_iterators(); - this->__begin_ = 0; + this->__begin_ = nullptr; this->__size_ = this->__cap() = 0; } } @@ -2481,7 +2469,7 @@ template _LIBCPP_INLINE_VISIBILITY inline vector::vector() _NOEXCEPT_(is_nothrow_default_constructible::value) - : __begin_(0), + : __begin_(nullptr), __size_(0), __cap_alloc_(0) { @@ -2490,7 +2478,7 @@ vector::vector() template _LIBCPP_INLINE_VISIBILITY inline vector::vector(const allocator_type& __a) - : __begin_(0), + : __begin_(nullptr), __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) { @@ -2498,7 +2486,7 @@ vector::vector(const allocator_type& __a) template vector::vector(size_type __n) - : __begin_(0), + : __begin_(nullptr), __size_(0), __cap_alloc_(0) { @@ -2511,7 +2499,7 @@ vector::vector(size_type __n) template vector::vector(size_type __n, const value_type& __x) - : __begin_(0), + : __begin_(nullptr), __size_(0), __cap_alloc_(0) { @@ -2524,7 +2512,7 @@ vector::vector(size_type __n, const value_type& __x) template vector::vector(size_type __n, const value_type& __x, const allocator_type& __a) - : __begin_(0), + : __begin_(nullptr), __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) { @@ -2540,7 +2528,7 @@ template vector::vector(_InputIterator __first, _InputIterator __last, typename enable_if<__is_input_iterator <_InputIterator>::value && !__is_forward_iterator<_InputIterator>::value>::type*) - : __begin_(0), + : __begin_(nullptr), __size_(0), __cap_alloc_(0) { @@ -2554,7 +2542,7 @@ vector::vector(_InputIterator __first, _InputIterator __last, } catch (...) { - if (__begin_ != 0) + if (__begin_ != nullptr) __storage_traits::deallocate(__alloc(), __begin_, __cap()); __invalidate_all_iterators(); throw; @@ -2567,7 +2555,7 @@ template vector::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a, typename enable_if<__is_input_iterator <_InputIterator>::value && !__is_forward_iterator<_InputIterator>::value>::type*) - : __begin_(0), + : __begin_(nullptr), __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) { @@ -2581,7 +2569,7 @@ vector::vector(_InputIterator __first, _InputIterator __last, } catch (...) { - if (__begin_ != 0) + if (__begin_ != nullptr) __storage_traits::deallocate(__alloc(), __begin_, __cap()); __invalidate_all_iterators(); throw; @@ -2593,7 +2581,7 @@ template template vector::vector(_ForwardIterator __first, _ForwardIterator __last, typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*) - : __begin_(0), + : __begin_(nullptr), __size_(0), __cap_alloc_(0) { @@ -2609,7 +2597,7 @@ template template vector::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a, typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*) - : __begin_(0), + : __begin_(nullptr), __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) { @@ -2625,7 +2613,7 @@ vector::vector(_ForwardIterator __first, _ForwardIterator __la template vector::vector(initializer_list __il) - : __begin_(0), + : __begin_(nullptr), __size_(0), __cap_alloc_(0) { @@ -2639,7 +2627,7 @@ vector::vector(initializer_list __il) template vector::vector(initializer_list __il, const allocator_type& __a) - : __begin_(0), + : __begin_(nullptr), __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) { @@ -2656,7 +2644,7 @@ vector::vector(initializer_list __il, const alloca template vector::~vector() { - if (__begin_ != 0) + if (__begin_ != nullptr) __storage_traits::deallocate(__alloc(), __begin_, __cap()); #ifdef _LIBCPP_DEBUG __invalidate_all_iterators(); @@ -2665,7 +2653,7 @@ vector::~vector() template vector::vector(const vector& __v) - : __begin_(0), + : __begin_(nullptr), __size_(0), __cap_alloc_(0, __storage_traits::select_on_container_copy_construction(__v.__alloc())) { @@ -2678,7 +2666,7 @@ vector::vector(const vector& __v) template vector::vector(const vector& __v, const allocator_type& __a) - : __begin_(0), + : __begin_(nullptr), __size_(0), __cap_alloc_(0, __a) { @@ -2720,14 +2708,14 @@ vector::vector(vector&& __v) __size_(__v.__size_), __cap_alloc_(__v.__cap_alloc_) { - __v.__begin_ = 0; + __v.__begin_ = nullptr; __v.__size_ = 0; __v.__cap() = 0; } template vector::vector(vector&& __v, const allocator_type& __a) - : __begin_(0), + : __begin_(nullptr), __size_(0), __cap_alloc_(0, __a) { @@ -3123,7 +3111,7 @@ template bool vector::__invariants() const { - if (this->__begin_ == 0) + if (this->__begin_ == nullptr) { if (this->__size_ != 0 || this->__cap() != 0) return false; -- cgit v1.1