46 #ifndef _THROW_ALLOCATOR_H 47 #define _THROW_ALLOCATOR_H 1 58 #if __cplusplus >= 201103L 62 # include <tr1/functional> 63 # include <tr1/random> 66 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
68 _GLIBCXX_BEGIN_NAMESPACE_VERSION
79 __throw_forced_error()
94 typedef map_alloc_type::const_iterator const_iterator;
95 typedef map_alloc_type::const_reference const_reference;
96 #if __cplusplus >= 201103L 116 insert(
void* p,
size_t size)
121 std::string error(
"annotate_base::insert null insert!\n");
122 log_to_string(error, entry);
123 std::__throw_logic_error(error.c_str());
127 = map_alloc().
insert(entry);
130 std::string error(
"annotate_base::insert double insert!\n");
131 log_to_string(error, entry);
132 log_to_string(error, *inserted.
first);
133 std::__throw_logic_error(error.c_str());
138 erase(
void* p,
size_t size)
139 { map_alloc().
erase(check_allocated(p, size)); }
141 #if __cplusplus >= 201103L 143 insert_construct(
void* p)
147 std::string error(
"annotate_base::insert_construct null!\n");
148 std::__throw_logic_error(error.c_str());
152 if (!inserted.second)
154 std::string error(
"annotate_base::insert_construct double insert!\n");
156 log_to_string(error, *inserted.first);
157 std::__throw_logic_error(error.c_str());
162 erase_construct(
void* p)
163 { map_construct().
erase(check_constructed(p)); }
167 inline map_alloc_type::iterator
168 check_allocated(
void* p,
size_t size)
170 map_alloc_type::iterator found = map_alloc().
find(p);
171 if (found == map_alloc().
end())
173 std::string error(
"annotate_base::check_allocated by value " 175 log_to_string(error, make_entry(p, size));
176 std::__throw_logic_error(error.c_str());
179 if (found->second.second != size)
181 std::string error(
"annotate_base::check_allocated by value " 182 "wrong-size erase!\n");
183 log_to_string(error, make_entry(p, size));
184 log_to_string(error, *found);
185 std::__throw_logic_error(error.c_str());
197 const_iterator beg = map_alloc().
begin();
198 const_iterator
end = map_alloc().
end();
201 if (beg->second.first == label)
202 log_to_string(found, *beg);
207 #if __cplusplus >= 201103L 209 auto beg = map_construct().
begin();
210 auto end = map_construct().
end();
213 if (beg->second == label)
214 log_to_string(found, *beg);
222 std::string error(
"annotate_base::check by label\n");
224 std::__throw_logic_error(error.c_str());
234 const_iterator beg = map_alloc().
begin();
235 const_iterator
end = map_alloc().
end();
238 log_to_string(found, *beg);
243 #if __cplusplus >= 201103L 245 auto beg = map_construct().
begin();
246 auto end = map_construct().
end();
249 log_to_string(found, *beg);
259 std::__throw_logic_error(error.c_str());
263 #if __cplusplus >= 201103L 264 inline map_construct_type::iterator
265 check_constructed(
void* p)
267 auto found = map_construct().
find(p);
268 if (found == map_construct().
end())
270 std::string error(
"annotate_base::check_constructed not " 273 std::__throw_logic_error(error.c_str());
280 check_constructed(
size_t label)
282 auto beg = map_construct().
begin();
283 auto end = map_construct().
end();
287 if (beg->second == label)
288 log_to_string(found, *beg);
294 std::string error(
"annotate_base::check_constructed by label\n");
296 std::__throw_logic_error(error.c_str());
306 make_entry(
void* p,
size_t size)
313 const char tab(
'\t');
315 unsigned long l =
static_cast<unsigned long>(
ref.second.first);
316 __builtin_sprintf(buf,
"%lu", l);
320 l =
static_cast<unsigned long>(
ref.second.second);
321 __builtin_sprintf(buf,
"%lu", l);
325 __builtin_sprintf(buf,
"%p",
ref.first);
330 #if __cplusplus >= 201103L 335 const char tab(
'\t');
337 unsigned long l =
static_cast<unsigned long>(
ref.second);
338 __builtin_sprintf(buf,
"%lu", l);
342 __builtin_sprintf(buf,
"%p",
ref.first);
362 #if __cplusplus >= 201103L 378 base_type::const_iterator beg = __b.map_alloc().
begin();
379 base_type::const_iterator
end = __b.map_alloc().
end();
380 for (; beg !=
end; ++beg)
381 __b.log_to_string(error, *beg);
383 #if __cplusplus >= 201103L 385 auto beg = __b.map_construct().
begin();
386 auto end = __b.map_construct().
end();
387 for (; beg !=
end; ++beg)
388 __b.log_to_string(error, *beg);
403 #if __cplusplus >= 201103L 423 const size_t _M_orig;
426 adjustor_base() : _M_orig(limit()) { }
429 ~adjustor_base() { set_limit(_M_orig); }
453 throw_conditionally()
455 if (count() == limit())
456 __throw_forced_error();
463 static size_t _S_count(0);
476 set_limit(
const size_t __l)
483 #ifdef _GLIBCXX_USE_C99_STDINT_TR1 495 const double _M_orig;
498 adjustor_base() : _M_orig(probability()) { }
500 virtual ~adjustor_base()
501 { set_probability(_M_orig); }
508 { set_probability(1 -
std::pow(
double(1 - probability()),
509 double(0.5 / (size + 1))));
532 set_probability(
double __p)
533 { probability() = __p; }
536 throw_conditionally()
538 if (generate() < probability())
539 __throw_forced_error();
543 seed(
unsigned long __s)
544 { engine().seed(__s); }
547 #if __cplusplus >= 201103L 551 typedef std::tr1::uniform_real<double> distribution_type;
558 #if __cplusplus >= 201103L 559 const distribution_type distribution(0, 1);
560 static auto generator =
std::bind(distribution, engine());
563 typedef std::tr1::variate_generator<engine_type, distribution_type> gen_t;
564 distribution_type distribution(0, 1);
565 static gen_t generator(engine(), distribution);
568 double random = generator();
569 if (random < distribution.min() || random > distribution.max())
573 __s +=
"random number generated is: ";
575 __builtin_sprintf(buf,
"%f", random);
577 std::__throw_out_of_range(__s.c_str());
593 static engine_type _S_e;
597 #endif // _GLIBCXX_USE_C99_STDINT_TR1 605 template<
typename _Cond>
608 typedef _Cond condition_type;
610 using condition_type::throw_conditionally;
614 #ifndef _GLIBCXX_IS_AGGREGATE 616 { throw_conditionally(); }
619 { throw_conditionally(); }
621 #if __cplusplus >= 201103L 627 { throw_conditionally(); }
633 throw_conditionally();
638 #if __cplusplus >= 201103L 647 throw_conditionally();
653 template<
typename _Cond>
658 throw_value::throw_conditionally();
659 throw_value orig(__a);
665 template<
typename _Cond>
667 operator==(
const throw_value_base<_Cond>& __a,
668 const throw_value_base<_Cond>& __b)
670 typedef throw_value_base<_Cond> throw_value;
671 throw_value::throw_conditionally();
672 bool __ret = __a._M_i == __b._M_i;
676 template<
typename _Cond>
678 operator<(const throw_value_base<_Cond>& __a,
679 const throw_value_base<_Cond>& __b)
681 typedef throw_value_base<_Cond> throw_value;
682 throw_value::throw_conditionally();
683 bool __ret = __a._M_i < __b._M_i;
688 template<
typename _Cond>
689 inline throw_value_base<_Cond>
690 operator+(
const throw_value_base<_Cond>& __a,
691 const throw_value_base<_Cond>& __b)
693 typedef throw_value_base<_Cond> throw_value;
694 throw_value::throw_conditionally();
695 throw_value __ret(__a._M_i + __b._M_i);
699 template<
typename _Cond>
700 inline throw_value_base<_Cond>
701 operator-(
const throw_value_base<_Cond>& __a,
702 const throw_value_base<_Cond>& __b)
704 typedef throw_value_base<_Cond> throw_value;
705 throw_value::throw_conditionally();
706 throw_value __ret(__a._M_i - __b._M_i);
710 template<
typename _Cond>
711 inline throw_value_base<_Cond>
712 operator*(
const throw_value_base<_Cond>& __a,
713 const throw_value_base<_Cond>& __b)
715 typedef throw_value_base<_Cond> throw_value;
716 throw_value::throw_conditionally();
717 throw_value __ret(__a._M_i * __b._M_i);
727 #ifndef _GLIBCXX_IS_AGGREGATE 733 #if __cplusplus >= 201103L 743 base_type::operator=(__other);
747 #if __cplusplus >= 201103L 753 #ifdef _GLIBCXX_USE_C99_STDINT_TR1 759 #ifndef _GLIBCXX_IS_AGGREGATE 765 #if __cplusplus >= 201103L 775 base_type::operator=(__other);
779 #if __cplusplus >= 201103L 784 #endif // _GLIBCXX_USE_C99_STDINT_TR1 793 template<
typename _Tp,
typename _Cond>
798 typedef size_t size_type;
799 typedef ptrdiff_t difference_type;
800 typedef _Tp value_type;
801 typedef value_type* pointer;
802 typedef const value_type* const_pointer;
803 typedef value_type& reference;
804 typedef const value_type& const_reference;
806 #if __cplusplus >= 201103L 813 typedef _Cond condition_type;
817 using condition_type::throw_conditionally;
821 max_size()
const _GLIBCXX_USE_NOEXCEPT
822 {
return _M_allocator.max_size(); }
825 address(reference __x)
const _GLIBCXX_NOEXCEPT
829 address(const_reference __x)
const _GLIBCXX_NOEXCEPT
832 _GLIBCXX_NODISCARD pointer
835 if (__n > this->max_size())
836 std::__throw_bad_alloc();
838 throw_conditionally();
839 pointer
const a = _M_allocator.allocate(__n, hint);
840 insert(a,
sizeof(value_type) * __n);
844 #if __cplusplus >= 201103L 845 template<
typename _Up,
typename... _Args>
847 construct(_Up* __p, _Args&&... __args)
849 _M_allocator.construct(__p, std::forward<_Args>(__args)...);
850 insert_construct(__p);
853 template<
typename _Up>
857 erase_construct(__p);
858 _M_allocator.destroy(__p);
862 construct(pointer __p,
const value_type& val)
863 {
return _M_allocator.construct(__p, val); }
867 { _M_allocator.destroy(__p); }
871 deallocate(pointer __p, size_type __n)
873 erase(__p,
sizeof(value_type) * __n);
874 _M_allocator.deallocate(__p, __n);
878 check_allocated(pointer __p, size_type __n)
880 size_type __t =
sizeof(value_type) * __n;
881 annotate_base::check_allocated(__p, __t);
886 { annotate_base::check(__n); }
889 template<
typename _Tp,
typename _Cond>
895 template<
typename _Tp,
typename _Cond>
897 operator!=(
const throw_allocator_base<_Tp, _Cond>&,
898 const throw_allocator_base<_Tp, _Cond>&)
902 template<
typename _Tp>
906 template<
typename _Tp1>
913 _GLIBCXX_USE_NOEXCEPT { }
915 template<
typename _Tp1>
917 _GLIBCXX_USE_NOEXCEPT { }
922 #ifdef _GLIBCXX_USE_C99_STDINT_TR1 924 template<
typename _Tp>
928 template<
typename _Tp1>
935 _GLIBCXX_USE_NOEXCEPT { }
937 template<
typename _Tp1>
939 _GLIBCXX_USE_NOEXCEPT { }
943 #endif // _GLIBCXX_USE_C99_STDINT_TR1 945 _GLIBCXX_END_NAMESPACE_VERSION
948 #if __cplusplus >= 201103L 952 namespace std _GLIBCXX_VISIBILITY(default)
962 __gnu_cxx::throw_value_limit::throw_conditionally();
964 size_t __result = __h(__val._M_i);
969 #ifdef _GLIBCXX_USE_C99_STDINT_TR1 978 __gnu_cxx::throw_value_random::throw_conditionally();
980 size_t __result = __h(__val._M_i);
constexpr const _Tp * end(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to one past the last element of the initializer_list. ...
_T2 second
first is a copy of the first object
std::mersenne_twister_engine< uint_fast32_t, 32, 624, 397, 31, 0x9908b0dfUL, 11, 0xffffffffUL, 7, 0x9d2c5680UL, 15, 0xefc60000UL, 18, 1812433253UL >
Never enter the condition.
mersenne_twister_engine< uint_fast32_t, 32, 624, 397, 31, 0x9908b0dfUL, 11, 0xffffffffUL, 7, 0x9d2c5680UL, 15, 0xefc60000UL, 18, 1812433253UL > mt19937
ISO C++ entities toplevel namespace is std.
iterator erase(const_iterator __position)
Erases an element from a map.
_GLIBCXX_END_NAMESPACE_CXX11 typedef basic_string< char > string
A string of char.
Base struct for condition policy.
Properties of fundamental types.
A standard container made up of (key,value) pairs, which can be retrieved based on a key...
Base class for all library exceptions.
Uniform continuous distribution for random numbers.
_T1 first
second_type is the second bound type
Template class basic_ostream.
Type throwing via limit condition.
Primary class template hash.
Allocator throwing via random condition.
Never enter the condition.
iterator find(const key_type &__x)
Tries to locate an element in a map.
Base class for random probability control and throw.
std::pair< iterator, bool > insert(const value_type &__x)
Attempts to insert a std::pair into the map.
Allocator class with logging and exception generation control. Intended to be used as an allocator_ty...
complex< _Tp > pow(const complex< _Tp > &, int)
Return x to the y'th power.
Class with exception generation control. Intended to be used as a value_type in templatized code...
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
iterator begin() noexcept
GNU extensions for public use.
Type throwing via random condition.
Always enter the condition.
constexpr pair< typename __decay_and_strip< _T1 >::__type, typename __decay_and_strip< _T2 >::__type > make_pair(_T1 &&__x, _T2 &&__y)
A convenience wrapper for creating a pair from two objects.
Base class for checking address and label information about allocations. Create a std::map between th...
_Bind_helper< __is_socketlike< _Func >::value, _Func, _BoundArgs... >::type bind(_Func &&__f, _BoundArgs &&... __args)
Function template for std::bind.
Struct holding two objects of arbitrary type.
Allocator throwing via limit condition.
reference_wrapper< _Tp > ref(_Tp &__t) noexcept
Denotes a reference should be taken to a variable.
Always enter the condition.
Base class for incremental control and throw.
Thown by exception safety machinery.