46 #ifndef _THROW_ALLOCATOR_H 47 #define _THROW_ALLOCATOR_H 1 58 #if __cplusplus >= 201103L 62 # include <tr1/functional> 63 # include <tr1/random> 67 #if !__has_builtin(__builtin_sprintf) 71 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
73 _GLIBCXX_BEGIN_NAMESPACE_VERSION
84 __throw_forced_error()
99 typedef map_alloc_type::const_iterator const_iterator;
100 typedef map_alloc_type::const_reference const_reference;
101 #if __cplusplus >= 201103L 121 insert(
void* p,
size_t size)
126 std::string error(
"annotate_base::insert null insert!\n");
127 log_to_string(error, entry);
128 std::__throw_logic_error(error.
c_str());
132 = map_alloc().
insert(entry);
135 std::string error(
"annotate_base::insert double insert!\n");
136 log_to_string(error, entry);
137 log_to_string(error, *inserted.
first);
138 std::__throw_logic_error(error.
c_str());
143 erase(
void* p,
size_t size)
144 { map_alloc().
erase(check_allocated(p,
size)); }
146 #if __cplusplus >= 201103L 148 insert_construct(
void* p)
152 std::string error(
"annotate_base::insert_construct null!\n");
153 std::__throw_logic_error(error.
c_str());
156 auto inserted = map_construct().
insert(std::make_pair(p, get_label()));
157 if (!inserted.second)
159 std::string error(
"annotate_base::insert_construct double insert!\n");
160 log_to_string(error, std::make_pair(p, get_label()));
161 log_to_string(error, *inserted.first);
162 std::__throw_logic_error(error.
c_str());
167 erase_construct(
void* p)
168 { map_construct().
erase(check_constructed(p)); }
172 inline map_alloc_type::iterator
173 check_allocated(
void* p,
size_t size)
175 map_alloc_type::iterator found = map_alloc().
find(p);
176 if (found == map_alloc().
end())
178 std::string error(
"annotate_base::check_allocated by value " 180 log_to_string(error, make_entry(p,
size));
181 std::__throw_logic_error(error.
c_str());
184 if (found->second.second !=
size)
186 std::string error(
"annotate_base::check_allocated by value " 187 "wrong-size erase!\n");
188 log_to_string(error, make_entry(p,
size));
189 log_to_string(error, *found);
190 std::__throw_logic_error(error.
c_str());
202 const_iterator beg = map_alloc().
begin();
203 const_iterator
end = map_alloc().
end();
206 if (beg->second.first == label)
207 log_to_string(found, *beg);
212 #if __cplusplus >= 201103L 214 auto beg = map_construct().
begin();
215 auto end = map_construct().
end();
218 if (beg->second == label)
219 log_to_string(found, *beg);
227 std::string error(
"annotate_base::check by label\n");
229 std::__throw_logic_error(error.
c_str());
239 const_iterator beg = map_alloc().
begin();
240 const_iterator
end = map_alloc().
end();
243 log_to_string(found, *beg);
248 #if __cplusplus >= 201103L 250 auto beg = map_construct().
begin();
251 auto end = map_construct().
end();
254 log_to_string(found, *beg);
264 std::__throw_logic_error(error.
c_str());
268 #if __cplusplus >= 201103L 269 inline map_construct_type::iterator
270 check_constructed(
void* p)
272 auto found = map_construct().
find(p);
273 if (found == map_construct().
end())
275 std::string error(
"annotate_base::check_constructed not " 277 log_to_string(error, std::make_pair(p, get_label()));
278 std::__throw_logic_error(error.
c_str());
285 check_constructed(
size_t label)
287 auto beg = map_construct().
begin();
288 auto end = map_construct().
end();
292 if (beg->second == label)
293 log_to_string(found, *beg);
299 std::string error(
"annotate_base::check_constructed by label\n");
301 std::__throw_logic_error(error.
c_str());
311 make_entry(
void* p,
size_t size)
317 #if ! __has_builtin(__builtin_sprintf) 318 __typeof__(&std::sprintf) __builtin_sprintf = &std::sprintf;
322 const char tab(
'\t');
324 unsigned long l =
static_cast<unsigned long>(ref.second.first);
325 __builtin_sprintf(buf,
"%lu", l);
329 l =
static_cast<unsigned long>(ref.second.second);
330 __builtin_sprintf(buf,
"%lu", l);
334 __builtin_sprintf(buf,
"%p", ref.first);
339 #if __cplusplus >= 201103L 343 #if ! __has_builtin(__builtin_sprintf) 344 auto __builtin_sprintf = &std::sprintf;
348 const char tab(
'\t');
350 unsigned long l =
static_cast<unsigned long>(ref.
second);
351 __builtin_sprintf(buf,
"%lu", l);
355 __builtin_sprintf(buf,
"%p", ref.
first);
375 #if __cplusplus >= 201103L 391 base_type::const_iterator beg = __b.map_alloc().
begin();
392 base_type::const_iterator
end = __b.map_alloc().
end();
393 for (; beg !=
end; ++beg)
394 __b.log_to_string(error, *beg);
396 #if __cplusplus >= 201103L 398 auto beg = __b.map_construct().
begin();
399 auto end = __b.map_construct().
end();
400 for (; beg !=
end; ++beg)
401 __b.log_to_string(error, *beg);
416 #if __cplusplus >= 201103L 436 const size_t _M_orig;
439 adjustor_base() : _M_orig(limit()) { }
442 ~adjustor_base() { set_limit(_M_orig); }
466 throw_conditionally()
468 if (count() == limit())
469 __throw_forced_error();
476 static size_t _S_count(0);
489 set_limit(
const size_t __l)
496 #ifdef _GLIBCXX_USE_C99_STDINT_TR1 508 const double _M_orig;
511 adjustor_base() : _M_orig(probability()) { }
513 virtual ~adjustor_base()
514 { set_probability(_M_orig); }
521 { set_probability(1 -
std::pow(
double(1 - probability()),
522 double(0.5 / (
size + 1))));
545 set_probability(
double __p)
546 { probability() = __p; }
549 throw_conditionally()
551 if (generate() < probability())
552 __throw_forced_error();
556 seed(
unsigned long __s)
557 { engine().seed(__s); }
560 #if __cplusplus >= 201103L 564 typedef std::tr1::uniform_real<double> distribution_type;
571 #if __cplusplus >= 201103L 572 const distribution_type distribution(0, 1);
573 static auto generator =
std::bind(distribution, engine());
576 typedef std::tr1::variate_generator<engine_type, distribution_type> gen_t;
577 distribution_type distribution(0, 1);
578 static gen_t generator(engine(), distribution);
581 #if ! __has_builtin(__builtin_sprintf) 582 __typeof__(&std::sprintf) __builtin_sprintf = &std::sprintf;
585 double random = generator();
586 if (random < distribution.min() || random > distribution.max())
590 __s +=
"random number generated is: ";
592 __builtin_sprintf(buf,
"%f", random);
594 std::__throw_out_of_range(__s.c_str());
610 static engine_type _S_e;
614 #endif // _GLIBCXX_USE_C99_STDINT_TR1 622 template<
typename _Cond>
625 typedef _Cond condition_type;
627 using condition_type::throw_conditionally;
631 #ifndef _GLIBCXX_IS_AGGREGATE 633 { throw_conditionally(); }
636 { throw_conditionally(); }
638 #if __cplusplus >= 201103L 644 { throw_conditionally(); }
650 throw_conditionally();
655 #if __cplusplus >= 201103L 664 throw_conditionally();
670 template<
typename _Cond>
675 throw_value::throw_conditionally();
676 throw_value orig(__a);
682 template<
typename _Cond>
684 operator==(
const throw_value_base<_Cond>& __a,
685 const throw_value_base<_Cond>& __b)
687 typedef throw_value_base<_Cond> throw_value;
688 throw_value::throw_conditionally();
689 bool __ret = __a._M_i == __b._M_i;
693 template<
typename _Cond>
695 operator<(const throw_value_base<_Cond>& __a,
696 const throw_value_base<_Cond>& __b)
698 typedef throw_value_base<_Cond> throw_value;
699 throw_value::throw_conditionally();
700 bool __ret = __a._M_i < __b._M_i;
705 template<
typename _Cond>
706 inline throw_value_base<_Cond>
707 operator+(
const throw_value_base<_Cond>& __a,
708 const throw_value_base<_Cond>& __b)
710 typedef throw_value_base<_Cond> throw_value;
711 throw_value::throw_conditionally();
712 throw_value __ret(__a._M_i + __b._M_i);
716 template<
typename _Cond>
717 inline throw_value_base<_Cond>
718 operator-(
const throw_value_base<_Cond>& __a,
719 const throw_value_base<_Cond>& __b)
721 typedef throw_value_base<_Cond> throw_value;
722 throw_value::throw_conditionally();
723 throw_value __ret(__a._M_i - __b._M_i);
727 template<
typename _Cond>
728 inline throw_value_base<_Cond>
729 operator*(
const throw_value_base<_Cond>& __a,
730 const throw_value_base<_Cond>& __b)
732 typedef throw_value_base<_Cond> throw_value;
733 throw_value::throw_conditionally();
734 throw_value __ret(__a._M_i * __b._M_i);
744 #ifndef _GLIBCXX_IS_AGGREGATE 750 #if __cplusplus >= 201103L 760 base_type::operator=(__other);
764 #if __cplusplus >= 201103L 770 #ifdef _GLIBCXX_USE_C99_STDINT_TR1 776 #ifndef _GLIBCXX_IS_AGGREGATE 782 #if __cplusplus >= 201103L 792 base_type::operator=(__other);
796 #if __cplusplus >= 201103L 801 #endif // _GLIBCXX_USE_C99_STDINT_TR1 810 template<
typename _Tp,
typename _Cond>
815 typedef std::size_t size_type;
816 typedef std::ptrdiff_t difference_type;
817 typedef _Tp value_type;
818 typedef value_type* pointer;
819 typedef const value_type* const_pointer;
820 typedef value_type& reference;
821 typedef const value_type& const_reference;
823 #if __cplusplus >= 201103L 830 typedef _Cond condition_type;
836 using condition_type::throw_conditionally;
840 max_size()
const _GLIBCXX_USE_NOEXCEPT
844 address(reference __x)
const _GLIBCXX_NOEXCEPT
848 address(const_reference __x)
const _GLIBCXX_NOEXCEPT
851 _GLIBCXX_NODISCARD pointer
852 allocate(size_type __n,
const void* hint = 0)
854 if (__n > this->max_size())
855 std::__throw_bad_alloc();
857 throw_conditionally();
859 insert(a,
sizeof(value_type) * __n);
863 #if __cplusplus >= 201103L 864 template<
typename _Up,
typename... _Args>
866 construct(_Up* __p, _Args&&... __args)
868 traits::construct(_M_allocator, __p, std::forward<_Args>(__args)...);
869 insert_construct(__p);
872 template<
typename _Up>
876 erase_construct(__p);
877 traits::destroy(_M_allocator, __p);
881 construct(pointer __p,
const value_type& val)
882 {
return _M_allocator.construct(__p, val); }
886 { _M_allocator.destroy(__p); }
890 deallocate(pointer __p, size_type __n)
892 erase(__p,
sizeof(value_type) * __n);
893 _M_allocator.deallocate(__p, __n);
897 check_allocated(pointer __p, size_type __n)
899 size_type __t =
sizeof(value_type) * __n;
900 annotate_base::check_allocated(__p, __t);
905 { annotate_base::check(__n); }
908 template<
typename _Tp,
typename _Cond>
914 #if __cpp_impl_three_way_comparison < 201907L 915 template<
typename _Tp,
typename _Cond>
917 operator!=(
const throw_allocator_base<_Tp, _Cond>&,
918 const throw_allocator_base<_Tp, _Cond>&)
923 template<
typename _Tp>
927 template<
typename _Tp1>
934 _GLIBCXX_USE_NOEXCEPT { }
936 template<
typename _Tp1>
938 _GLIBCXX_USE_NOEXCEPT { }
942 #if __cplusplus >= 201103L 948 #ifdef _GLIBCXX_USE_C99_STDINT_TR1 950 template<
typename _Tp>
954 template<
typename _Tp1>
961 _GLIBCXX_USE_NOEXCEPT { }
963 template<
typename _Tp1>
965 _GLIBCXX_USE_NOEXCEPT { }
969 #if __cplusplus >= 201103L 974 #endif // _GLIBCXX_USE_C99_STDINT_TR1 976 _GLIBCXX_END_NAMESPACE_VERSION
979 #if __cplusplus >= 201103L 983 namespace std _GLIBCXX_VISIBILITY(default)
993 __gnu_cxx::throw_value_limit::throw_conditionally();
995 size_t __result = __h(__val._M_i);
1000 #ifdef _GLIBCXX_USE_C99_STDINT_TR1 1009 __gnu_cxx::throw_value_random::throw_conditionally();
1011 size_t __result = __h(__val._M_i);
Never enter the condition.
Base struct for condition policy.
constexpr auto size(const _Container &__cont) noexcept(noexcept(__cont.size())) -> decltype(__cont.size())
Return the size of a container.
Base class for checking address and label information about allocations. Create a std::map between th...
Template class basic_ostream.
Always enter the condition.
_Tp * end(valarray< _Tp > &__va)
Return an iterator pointing to one past the last element of the valarray.
Struct holding two objects of arbitrary type.
iterator begin() noexcept
complex< _Tp > pow(const complex< _Tp > &, int)
Return x to the y'th power.
const _CharT * c_str() const noexcept
Return const pointer to null-terminated contents.
Primary class template hash.
_T2 second
The second member.
Class with exception generation control. Intended to be used as a value_type in templatized code...
iterator erase(const_iterator __position)
Erases an element from a map.
constexpr _Bind_helper< __is_socketlike< _Func >::value, _Func, _BoundArgs... >::type bind(_Func &&__f, _BoundArgs &&... __args)
Function template for std::bind.
constexpr complex< _Tp > operator-(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x minus y.
iterator find(const key_type &__x)
Tries to locate an element in a map.
bool empty() const noexcept
static constexpr pointer allocate(_Alloc &__a, size_type __n)
Allocate memory.
_T1 first
The first member.
constexpr complex< _Tp > operator*(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x times y.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
insert_return_type insert(node_type &&__nh)
Re-insert an extracted node.
Type throwing via random condition.
Base class for incremental control and throw.
mersenne_twister_engine< uint_fast32_t, 32, 624, 397, 31, 0x9908b0dfUL, 11, 0xffffffffUL, 7, 0x9d2c5680UL, 15, 0xefc60000UL, 18, 1812433253UL > mt19937
Always enter the condition.
std::mersenne_twister_engine< uint_fast32_t, 32, 624, 397, 31, 0x9908b0dfUL, 11, 0xffffffffUL, 7, 0x9d2c5680UL, 15, 0xefc60000UL, 18, 1812433253UL >
ISO C++ entities toplevel namespace is std.
Base class for random probability control and throw.
Uniform continuous distribution for random numbers.
Uniform interface to C++98 and C++11 allocators.
Allocator throwing via limit condition.
Type throwing via limit condition.
constexpr complex< _Tp > operator+(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x plus y.
Never enter the condition.
Thown by exception safety machinery.
GNU extensions for public use.
static constexpr size_type max_size(const _Alloc &__a) noexcept
The maximum supported allocation size.
Allocator throwing via random condition.
Properties of fundamental types.
A standard container made up of (key,value) pairs, which can be retrieved based on a key...
Allocator class with logging and exception generation control. Intended to be used as an allocator_ty...
Base class for all library exceptions.