46 #ifndef _THROW_ALLOCATOR_H 47 #define _THROW_ALLOCATOR_H 1 61 #if __cplusplus >= 201103L 65 # include <tr1/functional> 66 # include <tr1/random> 70 #if !__has_builtin(__builtin_sprintf) 74 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
76 _GLIBCXX_BEGIN_NAMESPACE_VERSION
87 __throw_forced_error()
102 typedef map_alloc_type::const_iterator const_iterator;
103 typedef map_alloc_type::const_reference const_reference;
104 #if __cplusplus >= 201103L 124 insert(
void* p,
size_t size)
129 std::string error(
"annotate_base::insert null insert!\n");
130 log_to_string(error, entry);
131 std::__throw_logic_error(error.
c_str());
135 = map_alloc().
insert(entry);
138 std::string error(
"annotate_base::insert double insert!\n");
139 log_to_string(error, entry);
140 log_to_string(error, *inserted.
first);
141 std::__throw_logic_error(error.
c_str());
146 erase(
void* p,
size_t size)
147 { map_alloc().
erase(check_allocated(p, size)); }
149 #if __cplusplus >= 201103L 151 insert_construct(
void* p)
155 std::string error(
"annotate_base::insert_construct null!\n");
156 std::__throw_logic_error(error.
c_str());
159 auto inserted = map_construct().
insert(std::make_pair(p, get_label()));
160 if (!inserted.second)
162 std::string error(
"annotate_base::insert_construct double insert!\n");
163 log_to_string(error, std::make_pair(p, get_label()));
164 log_to_string(error, *inserted.first);
165 std::__throw_logic_error(error.
c_str());
170 erase_construct(
void* p)
171 { map_construct().
erase(check_constructed(p)); }
175 inline map_alloc_type::iterator
176 check_allocated(
void* p,
size_t size)
178 map_alloc_type::iterator found = map_alloc().
find(p);
179 if (found == map_alloc().end())
181 std::string error(
"annotate_base::check_allocated by value " 183 log_to_string(error, make_entry(p, size));
184 std::__throw_logic_error(error.
c_str());
187 if (found->second.second != size)
189 std::string error(
"annotate_base::check_allocated by value " 190 "wrong-size erase!\n");
191 log_to_string(error, make_entry(p, size));
192 log_to_string(error, *found);
193 std::__throw_logic_error(error.
c_str());
205 const_iterator beg = map_alloc().
begin();
206 const_iterator end = map_alloc().
end();
209 if (beg->second.first == label)
210 log_to_string(found, *beg);
215 #if __cplusplus >= 201103L 217 auto beg = map_construct().
begin();
218 auto end = map_construct().
end();
221 if (beg->second == label)
222 log_to_string(found, *beg);
230 std::string error(
"annotate_base::check by label\n");
232 std::__throw_logic_error(error.
c_str());
242 const_iterator beg = map_alloc().
begin();
243 const_iterator end = map_alloc().
end();
246 log_to_string(found, *beg);
251 #if __cplusplus >= 201103L 253 auto beg = map_construct().
begin();
254 auto end = map_construct().
end();
257 log_to_string(found, *beg);
267 std::__throw_logic_error(error.
c_str());
271 #if __cplusplus >= 201103L 272 inline map_construct_type::iterator
273 check_constructed(
void* p)
275 auto found = map_construct().
find(p);
276 if (found == map_construct().end())
278 std::string error(
"annotate_base::check_constructed not " 280 log_to_string(error, std::make_pair(p, get_label()));
281 std::__throw_logic_error(error.
c_str());
288 check_constructed(
size_t label)
290 auto beg = map_construct().
begin();
291 auto end = map_construct().
end();
295 if (beg->second == label)
296 log_to_string(found, *beg);
302 std::string error(
"annotate_base::check_constructed by label\n");
304 std::__throw_logic_error(error.
c_str());
314 make_entry(
void* p,
size_t size)
315 {
return std::make_pair(p,
data_type(get_label(), size)); }
320 #if ! __has_builtin(__builtin_sprintf) 321 __typeof__(&std::sprintf) __builtin_sprintf = &std::sprintf;
325 const char tab(
'\t');
327 unsigned long l =
static_cast<unsigned long>(ref.second.first);
328 __builtin_sprintf(buf,
"%lu", l);
332 l =
static_cast<unsigned long>(ref.second.second);
333 __builtin_sprintf(buf,
"%lu", l);
337 __builtin_sprintf(buf,
"%p", ref.first);
342 #if __cplusplus >= 201103L 346 #if ! __has_builtin(__builtin_sprintf) 347 auto __builtin_sprintf = &std::sprintf;
351 const char tab(
'\t');
353 unsigned long l =
static_cast<unsigned long>(ref.
second);
354 __builtin_sprintf(buf,
"%lu", l);
358 __builtin_sprintf(buf,
"%p", ref.
first);
378 #if __cplusplus >= 201103L 394 base_type::const_iterator beg = __b.map_alloc().begin();
395 base_type::const_iterator end = __b.map_alloc().end();
396 for (; beg != end; ++beg)
397 __b.log_to_string(error, *beg);
399 #if __cplusplus >= 201103L 401 auto beg = __b.map_construct().begin();
402 auto end = __b.map_construct().end();
403 for (; beg != end; ++beg)
404 __b.log_to_string(error, *beg);
419 #if __cplusplus >= 201103L 439 const size_t _M_orig;
442 adjustor_base() : _M_orig(limit()) { }
445 ~adjustor_base() { set_limit(_M_orig); }
469 throw_conditionally()
471 if (count() == limit())
472 __throw_forced_error();
479 static size_t _S_count(0);
492 set_limit(
const size_t __l)
510 const double _M_orig;
513 adjustor_base() : _M_orig(probability()) { }
515 virtual ~adjustor_base()
516 { set_probability(_M_orig); }
523 { set_probability(1 -
std::pow(
double(1 - probability()),
524 double(0.5 / (size + 1))));
547 set_probability(
double __p)
548 { probability() = __p; }
551 throw_conditionally()
553 if (generate() < probability())
554 __throw_forced_error();
558 seed(
unsigned long __s)
559 { engine().seed(__s); }
562 #if __cplusplus >= 201103L 566 typedef std::tr1::uniform_real<double> distribution_type;
573 #if __cplusplus >= 201103L 574 const distribution_type distribution(0, 1);
575 static auto generator =
std::bind(distribution, engine());
578 typedef std::tr1::variate_generator<engine_type, distribution_type> gen_t;
579 distribution_type distribution(0, 1);
580 static gen_t generator(engine(), distribution);
583 #if ! __has_builtin(__builtin_sprintf) 584 __typeof__(&std::sprintf) __builtin_sprintf = &std::sprintf;
587 double random = generator();
588 if (random < distribution.min() || random > distribution.max())
592 __s +=
"random number generated is: ";
594 __builtin_sprintf(buf,
"%f", random);
596 std::__throw_out_of_range(__s.c_str());
612 static engine_type _S_e;
623 template<
typename _Cond>
626 typedef _Cond condition_type;
628 using condition_type::throw_conditionally;
632 #ifndef _GLIBCXX_IS_AGGREGATE 634 { throw_conditionally(); }
637 { throw_conditionally(); }
639 #if __cplusplus >= 201103L 645 { throw_conditionally(); }
651 throw_conditionally();
656 #if __cplusplus >= 201103L 665 throw_conditionally();
671 template<
typename _Cond>
676 throw_value::throw_conditionally();
677 throw_value orig(__a);
683 template<
typename _Cond>
685 operator==(
const throw_value_base<_Cond>& __a,
686 const throw_value_base<_Cond>& __b)
688 typedef throw_value_base<_Cond> throw_value;
689 throw_value::throw_conditionally();
690 bool __ret = __a._M_i == __b._M_i;
694 template<
typename _Cond>
696 operator<(const throw_value_base<_Cond>& __a,
697 const throw_value_base<_Cond>& __b)
699 typedef throw_value_base<_Cond> throw_value;
700 throw_value::throw_conditionally();
701 bool __ret = __a._M_i < __b._M_i;
706 template<
typename _Cond>
707 inline throw_value_base<_Cond>
708 operator+(
const throw_value_base<_Cond>& __a,
709 const throw_value_base<_Cond>& __b)
711 typedef throw_value_base<_Cond> throw_value;
712 throw_value::throw_conditionally();
713 throw_value __ret(__a._M_i + __b._M_i);
717 template<
typename _Cond>
718 inline throw_value_base<_Cond>
719 operator-(
const throw_value_base<_Cond>& __a,
720 const throw_value_base<_Cond>& __b)
722 typedef throw_value_base<_Cond> throw_value;
723 throw_value::throw_conditionally();
724 throw_value __ret(__a._M_i - __b._M_i);
728 template<
typename _Cond>
729 inline throw_value_base<_Cond>
730 operator*(
const throw_value_base<_Cond>& __a,
731 const throw_value_base<_Cond>& __b)
733 typedef throw_value_base<_Cond> throw_value;
734 throw_value::throw_conditionally();
735 throw_value __ret(__a._M_i * __b._M_i);
745 #ifndef _GLIBCXX_IS_AGGREGATE 751 #if __cplusplus >= 201103L 761 base_type::operator=(__other);
765 #if __cplusplus >= 201103L 776 #ifndef _GLIBCXX_IS_AGGREGATE 782 #if __cplusplus >= 201103L 792 base_type::operator=(__other);
796 #if __cplusplus >= 201103L 809 template<
typename _Tp,
typename _Cond>
814 typedef std::size_t size_type;
815 typedef std::ptrdiff_t difference_type;
816 typedef _Tp value_type;
817 typedef value_type* pointer;
818 typedef const value_type* const_pointer;
819 typedef value_type& reference;
820 typedef const value_type& const_reference;
822 #if __cplusplus >= 201103L 829 typedef _Cond condition_type;
835 using condition_type::throw_conditionally;
839 max_size()
const _GLIBCXX_USE_NOEXCEPT
843 address(reference __x)
const _GLIBCXX_NOEXCEPT
847 address(const_reference __x)
const _GLIBCXX_NOEXCEPT
850 _GLIBCXX_NODISCARD pointer
851 allocate(size_type __n,
const void* __hint = 0)
853 if (__n > this->max_size())
854 std::__throw_bad_alloc();
856 throw_conditionally();
858 insert(a,
sizeof(value_type) * __n);
862 #if __cplusplus >= 201103L 863 template<
typename _Up,
typename... _Args>
865 construct(_Up* __p, _Args&&... __args)
867 traits::construct(_M_allocator, __p, std::forward<_Args>(__args)...);
868 insert_construct(__p);
871 template<
typename _Up>
875 erase_construct(__p);
876 traits::destroy(_M_allocator, __p);
880 construct(pointer __p,
const value_type& __val)
881 {
return _M_allocator.construct(__p, __val); }
885 { _M_allocator.destroy(__p); }
889 deallocate(pointer __p, size_type __n)
891 erase(__p,
sizeof(value_type) * __n);
892 _M_allocator.deallocate(__p, __n);
896 check_allocated(pointer __p, size_type __n)
898 size_type __t =
sizeof(value_type) * __n;
899 annotate_base::check_allocated(__p, __t);
904 { annotate_base::check(__n); }
907 template<
typename _Tp,
typename _Cond>
913 #if __cpp_impl_three_way_comparison < 201907L 914 template<
typename _Tp,
typename _Cond>
916 operator!=(
const throw_allocator_base<_Tp, _Cond>&,
917 const throw_allocator_base<_Tp, _Cond>&)
922 template<
typename _Tp>
926 template<
typename _Tp1>
933 _GLIBCXX_USE_NOEXCEPT { }
935 template<
typename _Tp1>
937 _GLIBCXX_USE_NOEXCEPT { }
941 #if __cplusplus >= 201103L 948 template<
typename _Tp>
952 template<
typename _Tp1>
959 _GLIBCXX_USE_NOEXCEPT { }
961 template<
typename _Tp1>
963 _GLIBCXX_USE_NOEXCEPT { }
967 #if __cplusplus >= 201103L 973 _GLIBCXX_END_NAMESPACE_VERSION
976 #if __cplusplus >= 201103L 980 namespace std _GLIBCXX_VISIBILITY(default)
982 #pragma GCC diagnostic push 983 #pragma GCC diagnostic ignored "-Wdeprecated-declarations" 993 __gnu_cxx::throw_value_limit::throw_conditionally();
995 size_t __result = __h(__val._M_i);
1008 __gnu_cxx::throw_value_random::throw_conditionally();
1010 size_t __result = __h(__val._M_i);
1015 #pragma GCC diagnostic pop
Type throwing via limit condition.
Properties of fundamental types.
Never enter the condition.
static constexpr size_type max_size(const _Alloc &__a) noexcept
The maximum supported allocation size.
constexpr complex< _Tp > operator-(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x minus y.
static constexpr pointer allocate(_Alloc &__a, size_type __n)
Allocate memory.
iterator erase(const_iterator __position)
Erases an element from a map.
Type throwing via random condition.
GNU extensions for public use.
Struct holding two objects (or references) of arbitrary type.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
_T2 second
The second member.
Base class for incremental control and throw.
__bool_constant< true > true_type
The type used as a compile-time boolean with true value.
Thrown by utilities for testing exception safety.
constexpr complex< _Tp > operator+(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x plus y.
Base class for random probability control and throw.
Allocator throwing via limit condition.
Never enter the condition.
Class with exception generation control. Intended to be used as a value_type in templatized code...
const _CharT * c_str() const noexcept
Return const pointer to null-terminated contents.
std::mersenne_twister_engine< uint_fast32_t, 32, 624, 397, 31, 0x9908b0dfUL, 11, 0xffffffffUL, 7, 0x9d2c5680UL, 15, 0xefc60000UL, 18, 1812433253UL >
constexpr complex< _Tp > operator*(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x times y.
complex< _Tp > pow(const complex< _Tp > &, int)
Return x to the y'th power.
Uniform interface to C++98 and C++11 allocators.
Allocator throwing via random condition.
Allocator class with logging and exception generation control. Intended to be used as an allocator_ty...
bool empty() const noexcept
A standard container made up of (key,value) pairs, which can be retrieved based on a key...
Base struct for condition policy.
constexpr _Bind_helper< __is_socketlike< _Func >::value, _Func, _BoundArgs... >::type bind(_Func &&__f, _BoundArgs &&... __args)
Function template for std::bind.
insert_return_type insert(node_type &&__nh)
Re-insert an extracted node.
Base class for all library exceptions.
mersenne_twister_engine< uint_fast32_t, 32, 624, 397, 31, 0x9908b0dfUL, 11, 0xffffffffUL, 7, 0x9d2c5680UL, 15, 0xefc60000UL, 18, 1812433253UL > mt19937
iterator find(const key_type &__x)
Tries to locate an element in a map.
Base class for checking address and label information about allocations. Create a std::map between th...
iterator begin() noexcept
Always enter the condition.
_T1 first
The first member.
Always enter the condition.
Uniform continuous distribution for random numbers.
Primary class template hash.
ISO C++ entities toplevel namespace is std.