Create multilevel debug mode

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@139913 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Howard Hinnant 2011-09-16 17:29:17 +00:00
parent 7a563db09a
commit abe2628b43
5 changed files with 82 additions and 57 deletions

View File

@ -309,6 +309,16 @@ template <unsigned> struct __static_assert_check {};
#define _LIBCPP_WCTYPE_IS_MASK #define _LIBCPP_WCTYPE_IS_MASK
#endif #endif
#ifdef _LIBCPP_DEBUG2
# if _LIBCPP_DEBUG2 == 0
# define _LIBCPP_DEBUG_LEVEL 1
# elif _LIBCPP_DEBUG2 == 1
# define _LIBCPP_DEBUG_LEVEL 2
# else
# error Supported values for _LIBCPP_DEBUG2 are 0 and 1
# endif
#endif
#ifdef _LIBCPP_DEBUG2 #ifdef _LIBCPP_DEBUG2
# include <__debug> # include <__debug>
#else #else

View File

@ -11,11 +11,17 @@
#ifndef _LIBCPP_DEBUG_H #ifndef _LIBCPP_DEBUG_H
#define _LIBCPP_DEBUG_H #define _LIBCPP_DEBUG_H
#if _LIBCPP_DEBUG_LEVEL >= 1
# include <cstdlib> # include <cstdlib>
# include <cstdio> # include <cstdio>
# include <cstddef> # include <cstddef>
# define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : (_VSTD::printf("%s\n", m), _VSTD::abort())) # define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : (_VSTD::printf("%s\n", m), _VSTD::abort()))
#endif
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
struct _LIBCPP_VISIBLE __c_node; struct _LIBCPP_VISIBLE __c_node;
@ -177,5 +183,7 @@ _LIBCPP_VISIBLE const __libcpp_db* __get_const_db();
_LIBCPP_END_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD
#endif
#endif // _LIBCPP_DEBUG_H #endif // _LIBCPP_DEBUG_H

View File

@ -1068,11 +1068,11 @@ public:
typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = 0) _NOEXCEPT typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = 0) _NOEXCEPT
: __i(__u.base()) : __i(__u.base())
{ {
#ifdef _LIBCPP_DEBUG2 #if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__iterator_copy(this, &__u); __get_db()->__iterator_copy(this, &__u);
#endif #endif
} }
#ifdef _LIBCPP_DEBUG2 #if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_INLINE_VISIBILITY _LIBCPP_INLINE_VISIBILITY
__wrap_iter(const __wrap_iter& __x) __wrap_iter(const __wrap_iter& __x)
: __i(__x.base()) : __i(__x.base())
@ -1097,15 +1097,19 @@ public:
#endif #endif
_LIBCPP_INLINE_VISIBILITY reference operator*() const _NOEXCEPT _LIBCPP_INLINE_VISIBILITY reference operator*() const _NOEXCEPT
{ {
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
"Attempted to dereference a non-dereferenceable iterator"); "Attempted to dereference a non-dereferenceable iterator");
#endif
return *__i; return *__i;
} }
_LIBCPP_INLINE_VISIBILITY pointer operator->() const _NOEXCEPT {return &(operator*());} _LIBCPP_INLINE_VISIBILITY pointer operator->() const _NOEXCEPT {return &(operator*());}
_LIBCPP_INLINE_VISIBILITY __wrap_iter& operator++() _NOEXCEPT _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator++() _NOEXCEPT
{ {
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
"Attempted to increment non-incrementable iterator"); "Attempted to increment non-incrementable iterator");
#endif
++__i; ++__i;
return *this; return *this;
} }
@ -1113,8 +1117,10 @@ public:
{__wrap_iter __tmp(*this); ++(*this); return __tmp;} {__wrap_iter __tmp(*this); ++(*this); return __tmp;}
_LIBCPP_INLINE_VISIBILITY __wrap_iter& operator--() _NOEXCEPT _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator--() _NOEXCEPT
{ {
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__decrementable(this), _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
"Attempted to decrement non-decrementable iterator"); "Attempted to decrement non-decrementable iterator");
#endif
--__i; --__i;
return *this; return *this;
} }
@ -1124,8 +1130,10 @@ public:
{__wrap_iter __w(*this); __w += __n; return __w;} {__wrap_iter __w(*this); __w += __n; return __w;}
_LIBCPP_INLINE_VISIBILITY __wrap_iter& operator+=(difference_type __n) _NOEXCEPT _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator+=(difference_type __n) _NOEXCEPT
{ {
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__addable(this, __n), _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n),
"Attempted to add/subtract iterator outside of valid range"); "Attempted to add/subtract iterator outside of valid range");
#endif
__i += __n; __i += __n;
return *this; return *this;
} }
@ -1135,8 +1143,10 @@ public:
{*this += -__n; return *this;} {*this += -__n; return *this;}
_LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const _NOEXCEPT _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const _NOEXCEPT
{ {
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n), _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n),
"Attempted to subscript iterator outside of valid range"); "Attempted to subscript iterator outside of valid range");
#endif
return __i[__n]; return __i[__n];
} }
@ -1144,7 +1154,7 @@ public:
private: private:
_LIBCPP_INLINE_VISIBILITY __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {} _LIBCPP_INLINE_VISIBILITY __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {}
#ifdef _LIBCPP_DEBUG2 #if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_INLINE_VISIBILITY __wrap_iter(const void* __p, iterator_type __x) : __i(__x) _LIBCPP_INLINE_VISIBILITY __wrap_iter(const void* __p, iterator_type __x) : __i(__x)
{ {
__get_db()->__insert_ic(this, __p); __get_db()->__insert_ic(this, __p);
@ -1215,8 +1225,10 @@ inline _LIBCPP_INLINE_VISIBILITY
bool bool
operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
{ {
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__comparable(&__x, &__y), _LIBCPP_ASSERT(__get_const_db()->__comparable(&__x, &__y),
"Attempted to compare incomparable iterators"); "Attempted to compare incomparable iterators");
#endif
return __x.base() == __y.base(); return __x.base() == __y.base();
} }
@ -1225,8 +1237,10 @@ inline _LIBCPP_INLINE_VISIBILITY
bool bool
operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
{ {
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__comparable(&__x, &__y), _LIBCPP_ASSERT(__get_const_db()->__comparable(&__x, &__y),
"Attempted to compare incomparable iterators"); "Attempted to compare incomparable iterators");
#endif
return __x.base() < __y.base(); return __x.base() < __y.base();
} }
@ -1267,8 +1281,10 @@ inline _LIBCPP_INLINE_VISIBILITY
typename __wrap_iter<_Iter1>::difference_type typename __wrap_iter<_Iter1>::difference_type
operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
{ {
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__comparable(&__x, &__y), _LIBCPP_ASSERT(__get_const_db()->__comparable(&__x, &__y),
"Attempted to subtract incompatible iterators"); "Attempted to subtract incompatible iterators");
#endif
return __x.base() - __y.base(); return __x.base() - __y.base();
} }

View File

@ -269,9 +269,6 @@ void swap(vector<T,Allocator>& x, vector<T,Allocator>& y)
#include <cstring> #include <cstring>
#include <__split_buffer> #include <__split_buffer>
#include <__functional_base> #include <__functional_base>
#if defined(_LIBCPP_DEBUG) || defined(_LIBCPP_NO_EXCEPTIONS)
#include <cassert>
#endif
#pragma GCC system_header #pragma GCC system_header
@ -489,24 +486,8 @@ public:
typedef typename __base::difference_type difference_type; typedef typename __base::difference_type difference_type;
typedef typename __base::pointer pointer; typedef typename __base::pointer pointer;
typedef typename __base::const_pointer const_pointer; typedef typename __base::const_pointer const_pointer;
#ifdef _LIBCPP_DEBUG
typedef __debug_iter<vector, pointer> iterator;
typedef __debug_iter<vector, const_pointer> const_iterator;
friend class __debug_iter<vector, pointer>;
friend class __debug_iter<vector, const_pointer>;
pair<iterator*, const_iterator*> __iterator_list_;
_LIBCPP_INLINE_VISIBILITY iterator*& __get_iterator_list(iterator*) {return __iterator_list_.first;}
_LIBCPP_INLINE_VISIBILITY const_iterator*& __get_iterator_list(const_iterator*) {return __iterator_list_.second;}
#elif defined(_LIBCPP_RAW_ITERATORS)
typedef pointer iterator;
typedef const_pointer const_iterator;
#else // defined(_LIBCPP_RAW_ITERATORS)
typedef __wrap_iter<pointer> iterator; typedef __wrap_iter<pointer> iterator;
typedef __wrap_iter<const_pointer> const_iterator; typedef __wrap_iter<const_pointer> const_iterator;
#endif // defined(_LIBCPP_RAW_ITERATORS)
typedef _VSTD::reverse_iterator<iterator> reverse_iterator; typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
@ -514,14 +495,14 @@ public:
vector() vector()
_NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
{ {
#ifdef _LIBCPP_DEBUG2 #if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this); __get_db()->__insert_c(this);
#endif #endif
} }
_LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a) _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a)
: __base(__a) : __base(__a)
{ {
#ifdef _LIBCPP_DEBUG2 #if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this); __get_db()->__insert_c(this);
#endif #endif
} }
@ -548,7 +529,7 @@ public:
_LIBCPP_INLINE_VISIBILITY _LIBCPP_INLINE_VISIBILITY
vector(initializer_list<value_type> __il, const allocator_type& __a); vector(initializer_list<value_type> __il, const allocator_type& __a);
#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
#ifdef _LIBCPP_DEBUG2 #if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_INLINE_VISIBILITY _LIBCPP_INLINE_VISIBILITY
~vector() ~vector()
{ {
@ -741,14 +722,14 @@ public:
bool __invariants() const; bool __invariants() const;
#ifdef _LIBCPP_DEBUG2 #if _LIBCPP_DEBUG_LEVEL >= 2
bool __dereferenceable(const const_iterator* __i) const; bool __dereferenceable(const const_iterator* __i) const;
bool __decrementable(const const_iterator* __i) const; bool __decrementable(const const_iterator* __i) const;
bool __addable(const const_iterator* __i, ptrdiff_t __n) const; bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const; bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
#endif // _LIBCPP_DEBUG2 #endif // _LIBCPP_DEBUG_LEVEL >= 2
private: private:
_LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators(); _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
@ -780,7 +761,7 @@ private:
_LIBCPP_INLINE_VISIBILITY _LIBCPP_INLINE_VISIBILITY
void __destruct_at_end(const_pointer __new_last) _NOEXCEPT void __destruct_at_end(const_pointer __new_last) _NOEXCEPT
{ {
#ifdef _LIBCPP_DEBUG2 #if _LIBCPP_DEBUG_LEVEL >= 2
__c_node* __c = __get_db()->__find_c_and_lock(this); __c_node* __c = __get_db()->__find_c_and_lock(this);
for (__i_node** __p = __c->end_; __p != __c->beg_; ) for (__i_node** __p = __c->end_; __p != __c->beg_; )
{ {
@ -994,7 +975,7 @@ vector<_Tp, _Allocator>::vector(size_type __n)
allocate(__n); allocate(__n);
__construct_at_end(__n); __construct_at_end(__n);
} }
#ifdef _LIBCPP_DEBUG2 #if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this); __get_db()->__insert_c(this);
#endif #endif
} }
@ -1007,7 +988,7 @@ vector<_Tp, _Allocator>::vector(size_type __n, const_reference __x)
allocate(__n); allocate(__n);
__construct_at_end(__n, __x); __construct_at_end(__n, __x);
} }
#ifdef _LIBCPP_DEBUG2 #if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this); __get_db()->__insert_c(this);
#endif #endif
} }
@ -1021,7 +1002,7 @@ vector<_Tp, _Allocator>::vector(size_type __n, const_reference __x, const alloca
allocate(__n); allocate(__n);
__construct_at_end(__n, __x); __construct_at_end(__n, __x);
} }
#ifdef _LIBCPP_DEBUG2 #if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this); __get_db()->__insert_c(this);
#endif #endif
} }
@ -1034,7 +1015,7 @@ vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
{ {
for (; __first != __last; ++__first) for (; __first != __last; ++__first)
push_back(*__first); push_back(*__first);
#ifdef _LIBCPP_DEBUG2 #if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this); __get_db()->__insert_c(this);
#endif #endif
} }
@ -1048,7 +1029,7 @@ vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, c
{ {
for (; __first != __last; ++__first) for (; __first != __last; ++__first)
push_back(*__first); push_back(*__first);
#ifdef _LIBCPP_DEBUG2 #if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this); __get_db()->__insert_c(this);
#endif #endif
} }
@ -1064,7 +1045,7 @@ vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __las
allocate(__n); allocate(__n);
__construct_at_end(__first, __last); __construct_at_end(__first, __last);
} }
#ifdef _LIBCPP_DEBUG2 #if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this); __get_db()->__insert_c(this);
#endif #endif
} }
@ -1081,7 +1062,7 @@ vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __las
allocate(__n); allocate(__n);
__construct_at_end(__first, __last); __construct_at_end(__first, __last);
} }
#ifdef _LIBCPP_DEBUG2 #if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this); __get_db()->__insert_c(this);
#endif #endif
} }
@ -1096,7 +1077,7 @@ vector<_Tp, _Allocator>::vector(const vector& __x)
allocate(__n); allocate(__n);
__construct_at_end(__x.__begin_, __x.__end_); __construct_at_end(__x.__begin_, __x.__end_);
} }
#ifdef _LIBCPP_DEBUG2 #if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this); __get_db()->__insert_c(this);
#endif #endif
} }
@ -1111,7 +1092,7 @@ vector<_Tp, _Allocator>::vector(const vector& __x, const allocator_type& __a)
allocate(__n); allocate(__n);
__construct_at_end(__x.__begin_, __x.__end_); __construct_at_end(__x.__begin_, __x.__end_);
} }
#ifdef _LIBCPP_DEBUG2 #if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this); __get_db()->__insert_c(this);
#endif #endif
} }
@ -1128,7 +1109,7 @@ vector<_Tp, _Allocator>::vector(vector&& __x)
this->__end_ = __x.__end_; this->__end_ = __x.__end_;
this->__end_cap() = __x.__end_cap(); this->__end_cap() = __x.__end_cap();
__x.__begin_ = __x.__end_ = __x.__end_cap() = 0; __x.__begin_ = __x.__end_ = __x.__end_cap() = 0;
#ifdef _LIBCPP_DEBUG2 #if _LIBCPP_DEBUG_LEVEL >= 2
__x.__invalidate_all_iterators(); __x.__invalidate_all_iterators();
__get_db()->__insert_c(this); __get_db()->__insert_c(this);
#endif #endif
@ -1152,7 +1133,7 @@ vector<_Tp, _Allocator>::vector(vector&& __x, const allocator_type& __a)
typedef move_iterator<iterator> _I; typedef move_iterator<iterator> _I;
assign(_I(__x.begin()), _I(__x.end())); assign(_I(__x.begin()), _I(__x.end()));
} }
#ifdef _LIBCPP_DEBUG2 #if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this); __get_db()->__insert_c(this);
#endif #endif
} }
@ -1168,7 +1149,7 @@ vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il)
allocate(__il.size()); allocate(__il.size());
__construct_at_end(__il.begin(), __il.end()); __construct_at_end(__il.begin(), __il.end());
} }
#ifdef _LIBCPP_DEBUG2 #if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this); __get_db()->__insert_c(this);
#endif #endif
} }
@ -1183,7 +1164,7 @@ vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocat
allocate(__il.size()); allocate(__il.size());
__construct_at_end(__il.begin(), __il.end()); __construct_at_end(__il.begin(), __il.end());
} }
#ifdef _LIBCPP_DEBUG2 #if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this); __get_db()->__insert_c(this);
#endif #endif
} }
@ -1319,7 +1300,7 @@ _LIBCPP_INLINE_VISIBILITY inline
typename vector<_Tp, _Allocator>::iterator typename vector<_Tp, _Allocator>::iterator
vector<_Tp, _Allocator>::__make_iter(pointer __p) _NOEXCEPT vector<_Tp, _Allocator>::__make_iter(pointer __p) _NOEXCEPT
{ {
#ifdef _LIBCPP_DEBUG2 #if _LIBCPP_DEBUG_LEVEL >= 2
return iterator(this, __p); return iterator(this, __p);
#else #else
return iterator(__p); return iterator(__p);
@ -1331,7 +1312,7 @@ _LIBCPP_INLINE_VISIBILITY inline
typename vector<_Tp, _Allocator>::const_iterator typename vector<_Tp, _Allocator>::const_iterator
vector<_Tp, _Allocator>::__make_iter(const_pointer __p) const _NOEXCEPT vector<_Tp, _Allocator>::__make_iter(const_pointer __p) const _NOEXCEPT
{ {
#ifdef _LIBCPP_DEBUG2 #if _LIBCPP_DEBUG_LEVEL >= 2
return const_iterator(this, __p); return const_iterator(this, __p);
#else #else
return const_iterator(__p); return const_iterator(__p);
@ -1521,9 +1502,11 @@ _LIBCPP_INLINE_VISIBILITY inline
typename vector<_Tp, _Allocator>::iterator typename vector<_Tp, _Allocator>::iterator
vector<_Tp, _Allocator>::erase(const_iterator __position) vector<_Tp, _Allocator>::erase(const_iterator __position)
{ {
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
"vector::erase(iterator) called with an iterator not" "vector::erase(iterator) called with an iterator not"
" referring to this vector"); " referring to this vector");
#endif
pointer __p = const_cast<pointer>(&*__position); pointer __p = const_cast<pointer>(&*__position);
iterator __r = __make_iter(__p); iterator __r = __make_iter(__p);
this->__destruct_at_end(_VSTD::move(__p + 1, this->__end_, __p)); this->__destruct_at_end(_VSTD::move(__p + 1, this->__end_, __p));
@ -1534,9 +1517,11 @@ template <class _Tp, class _Allocator>
typename vector<_Tp, _Allocator>::iterator typename vector<_Tp, _Allocator>::iterator
vector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last) vector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last)
{ {
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this, _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
"vector::erase(iterator, iterator) called with an iterator not" "vector::erase(iterator, iterator) called with an iterator not"
" referring to this vector"); " referring to this vector");
#endif
_LIBCPP_ASSERT(__first <= __last, "vector::erase(first, last) called with invalid range"); _LIBCPP_ASSERT(__first <= __last, "vector::erase(first, last) called with invalid range");
pointer __p = this->__begin_ + (__first - begin()); pointer __p = this->__begin_ + (__first - begin());
iterator __r = __make_iter(__p); iterator __r = __make_iter(__p);
@ -1561,9 +1546,11 @@ template <class _Tp, class _Allocator>
typename vector<_Tp, _Allocator>::iterator typename vector<_Tp, _Allocator>::iterator
vector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x) vector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x)
{ {
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
"vector::insert(iterator, x) called with an iterator not" "vector::insert(iterator, x) called with an iterator not"
" referring to this vector"); " referring to this vector");
#endif
pointer __p = this->__begin_ + (__position - begin()); pointer __p = this->__begin_ + (__position - begin());
if (this->__end_ < this->__end_cap()) if (this->__end_ < this->__end_cap())
{ {
@ -1598,9 +1585,11 @@ template <class _Tp, class _Allocator>
typename vector<_Tp, _Allocator>::iterator typename vector<_Tp, _Allocator>::iterator
vector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x) vector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x)
{ {
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
"vector::insert(iterator, x) called with an iterator not" "vector::insert(iterator, x) called with an iterator not"
" referring to this vector"); " referring to this vector");
#endif
pointer __p = this->__begin_ + (__position - begin()); pointer __p = this->__begin_ + (__position - begin());
if (this->__end_ < this->__end_cap()) if (this->__end_ < this->__end_cap())
{ {
@ -1634,9 +1623,11 @@ template <class... _Args>
typename vector<_Tp, _Allocator>::iterator typename vector<_Tp, _Allocator>::iterator
vector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args) vector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args)
{ {
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
"vector::emplace(iterator, x) called with an iterator not" "vector::emplace(iterator, x) called with an iterator not"
" referring to this vector"); " referring to this vector");
#endif
pointer __p = this->__begin_ + (__position - begin()); pointer __p = this->__begin_ + (__position - begin());
if (this->__end_ < this->__end_cap()) if (this->__end_ < this->__end_cap())
{ {
@ -1670,9 +1661,11 @@ template <class _Tp, class _Allocator>
typename vector<_Tp, _Allocator>::iterator typename vector<_Tp, _Allocator>::iterator
vector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x) vector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x)
{ {
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
"vector::insert(iterator, n, x) called with an iterator not" "vector::insert(iterator, n, x) called with an iterator not"
" referring to this vector"); " referring to this vector");
#endif
pointer __p = this->__begin_ + (__position - begin()); pointer __p = this->__begin_ + (__position - begin());
if (__n > 0) if (__n > 0)
{ {
@ -1716,9 +1709,11 @@ typename enable_if
>::type >::type
vector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last) vector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
{ {
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
"vector::insert(iterator, range) called with an iterator not" "vector::insert(iterator, range) called with an iterator not"
" referring to this vector"); " referring to this vector");
#endif
difference_type __off = __position - begin(); difference_type __off = __position - begin();
pointer __p = this->__begin_ + __off; pointer __p = this->__begin_ + __off;
allocator_type& __a = this->__alloc(); allocator_type& __a = this->__alloc();
@ -1766,9 +1761,11 @@ typename enable_if
>::type >::type
vector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last) vector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
{ {
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
"vector::insert(iterator, range) called with an iterator not" "vector::insert(iterator, range) called with an iterator not"
" referring to this vector"); " referring to this vector");
#endif
pointer __p = this->__begin_ + (__position - begin()); pointer __p = this->__begin_ + (__position - begin());
difference_type __n = _VSTD::distance(__first, __last); difference_type __n = _VSTD::distance(__first, __last);
if (__n > 0) if (__n > 0)
@ -1839,9 +1836,9 @@ vector<_Tp, _Allocator>::swap(vector& __x)
_VSTD::swap(this->__end_, __x.__end_); _VSTD::swap(this->__end_, __x.__end_);
_VSTD::swap(this->__end_cap(), __x.__end_cap()); _VSTD::swap(this->__end_cap(), __x.__end_cap());
__base::__swap_alloc(this->__alloc(), __x.__alloc()); __base::__swap_alloc(this->__alloc(), __x.__alloc());
#ifdef _LIBCPP_DEBUG2 #if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->swap(this, &__x); __get_db()->swap(this, &__x);
#endif // _LIBCPP_DEBUG #endif // _LIBCPP_DEBUG_LEVEL >= 2
} }
template <class _Tp, class _Allocator> template <class _Tp, class _Allocator>
@ -1865,7 +1862,7 @@ vector<_Tp, _Allocator>::__invariants() const
return true; return true;
} }
#ifdef _LIBCPP_DEBUG2 #if _LIBCPP_DEBUG_LEVEL >= 2
template <class _Tp, class _Allocator> template <class _Tp, class _Allocator>
bool bool
@ -1897,18 +1894,16 @@ vector<_Tp, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __
return this->__begin_ <= __p && __p < this->__end_; return this->__begin_ <= __p && __p < this->__end_;
} }
#endif // LIBCPP_DEBUG2 #endif // _LIBCPP_DEBUG_LEVEL >= 2
template <class _Tp, class _Allocator> template <class _Tp, class _Allocator>
_LIBCPP_INLINE_VISIBILITY inline _LIBCPP_INLINE_VISIBILITY inline
void void
vector<_Tp, _Allocator>::__invalidate_all_iterators() vector<_Tp, _Allocator>::__invalidate_all_iterators()
{ {
#ifdef _LIBCPP_DEBUG2 #if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__invalidate_all(this); __get_db()->__invalidate_all(this);
// iterator::__remove_all(this); #endif // _LIBCPP_DEBUG_LEVEL >= 2
// const_iterator::__remove_all(this);
#endif // _LIBCPP_DEBUG
} }
// vector<bool> // vector<bool>

View File

@ -7,7 +7,8 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#define _LIBCPP_DEBUG2 #define _LIBCPP_DEBUG2 1
#include "__config"
#include "__debug" #include "__debug"
#include "functional" #include "functional"
#include "algorithm" #include "algorithm"
@ -35,11 +36,6 @@ namespace
{ {
typedef mutex mutex_type; typedef mutex mutex_type;
// struct mutex_type
// {
// void lock() {}
// void unlock() {};
// };
typedef lock_guard<mutex_type> WLock; typedef lock_guard<mutex_type> WLock;
typedef lock_guard<mutex_type> RLock; typedef lock_guard<mutex_type> RLock;