From d6816d50df546c5a655a882dd5aee06607bd9a9c Mon Sep 17 00:00:00 2001 From: bkoz Date: Fri, 5 Jun 2009 08:45:26 +0000 Subject: [PATCH] 2009-06-04 Benjamin Kosnik * include/ext/throw_allocator.h: Rework. * include/ext/pb_ds/detail/debug_map_base.hpp: Adjust usage. * include/ext/pb_ds/detail/gp_hash_table_map_/resize_fn_imps.hpp: Same. * include/ext/pb_ds/detail/ov_tree_map_/erase_fn_imps.hpp: Same. * include/ext/pb_ds/detail/ov_tree_map_/ov_tree_map_.hpp: Same. * testsuite/23_containers/list/modifiers/insert/25288.cc: Same. * testsuite/util/regression/rand/priority_queue/ container_rand_regression_test.tcc: Inline functions. * testsuite/util/regression/rand/assoc/ container_rand_regression_test.tcc: Same. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@148204 138bc75d-0d04-0410-961f-82ee72b054a4 --- libstdc++-v3/ChangeLog | 13 + .../include/ext/pb_ds/detail/debug_map_base.hpp | 18 +- .../detail/gp_hash_table_map_/resize_fn_imps.hpp | 2 +- .../pb_ds/detail/ov_tree_map_/erase_fn_imps.hpp | 4 +- .../ext/pb_ds/detail/ov_tree_map_/ov_tree_map_.hpp | 2 +- libstdc++-v3/include/ext/throw_allocator.h | 536 +++++++++++---------- .../23_containers/list/modifiers/insert/25288.cc | 9 +- .../rand/assoc/container_rand_regression_test.tcc | 108 ++--- .../regression/rand/assoc/rand_regression_test.hpp | 4 +- .../container_rand_regression_test.tcc | 48 +- .../rand/priority_queue/rand_regression_test.hpp | 4 +- 11 files changed, 383 insertions(+), 365 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 5aa250d47b4..749779aaf7c 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,16 @@ +2009-06-04 Benjamin Kosnik + + * include/ext/throw_allocator.h: Rework. + * include/ext/pb_ds/detail/debug_map_base.hpp: Adjust usage. + * include/ext/pb_ds/detail/gp_hash_table_map_/resize_fn_imps.hpp: Same. + * include/ext/pb_ds/detail/ov_tree_map_/erase_fn_imps.hpp: Same. + * include/ext/pb_ds/detail/ov_tree_map_/ov_tree_map_.hpp: Same. + * testsuite/23_containers/list/modifiers/insert/25288.cc: Same. + * testsuite/util/regression/rand/priority_queue/ + container_rand_regression_test.tcc: Inline functions. + * testsuite/util/regression/rand/assoc/ + container_rand_regression_test.tcc: Same. + 2009-06-03 Benjamin Kosnik * testsuite/23_containers/list/cons/6.cc: Adjust test name. diff --git a/libstdc++-v3/include/ext/pb_ds/detail/debug_map_base.hpp b/libstdc++-v3/include/ext/pb_ds/detail/debug_map_base.hpp index 6f2defb648e..2227691feb0 100644 --- a/libstdc++-v3/include/ext/pb_ds/detail/debug_map_base.hpp +++ b/libstdc++-v3/include/ext/pb_ds/detail/debug_map_base.hpp @@ -154,8 +154,8 @@ namespace __gnu_pbds { _GLIBCXX_DEBUG_ONLY(assert_valid();) __gnu_cxx::throw_allocator alloc; - const double orig_throw_prob = alloc.get_throw_prob(); - alloc.set_throw_prob(0); + const double orig_throw_prob = alloc.get_probability(); + alloc.set_probability(0); if (find(r_key) != m_key_set.end()) { std::cerr << "insert_new" << r_key << std::endl; @@ -171,7 +171,7 @@ namespace __gnu_pbds std::cerr << "insert_new" << r_key << std::endl; std::abort(); } - alloc.set_throw_prob(orig_throw_prob); + alloc.set_probability(orig_throw_prob); _GLIBCXX_DEBUG_ONLY(assert_valid();) } @@ -315,8 +315,8 @@ namespace __gnu_pbds split(const_key_reference r_key, Cmp_Fn cmp_fn, PB_DS_CLASS_C_DEC& other) { __gnu_cxx::throw_allocator alloc; - const double orig_throw_prob = alloc.get_throw_prob(); - alloc.set_throw_prob(0); + const double orig_throw_prob = alloc.get_probability(); + alloc.set_probability(0); other.clear(); key_set_iterator it = m_key_set.begin(); while (it != m_key_set.end()) @@ -327,7 +327,7 @@ namespace __gnu_pbds } else ++it; - alloc.set_throw_prob(orig_throw_prob); + alloc.set_probability(orig_throw_prob); } PB_DS_CLASS_T_DEC @@ -336,8 +336,8 @@ namespace __gnu_pbds join(PB_DS_CLASS_C_DEC& other) { __gnu_cxx::throw_allocator alloc; - const double orig_throw_prob = alloc.get_throw_prob(); - alloc.set_throw_prob(0); + const double orig_throw_prob = alloc.get_probability(); + alloc.set_probability(0); key_set_iterator it = other.m_key_set.begin(); while (it != other.m_key_set.end()) { @@ -345,7 +345,7 @@ namespace __gnu_pbds it = other.m_key_set.erase(it); } _GLIBCXX_DEBUG_ASSERT(other.m_key_set.empty()); - alloc.set_throw_prob(orig_throw_prob); + alloc.set_probability(orig_throw_prob); } #undef PB_DS_CLASS_T_DEC diff --git a/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/resize_fn_imps.hpp b/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/resize_fn_imps.hpp index 82a8ab0d257..0492a47928b 100644 --- a/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/resize_fn_imps.hpp +++ b/libstdc++-v3/include/ext/pb_ds/detail/gp_hash_table_map_/resize_fn_imps.hpp @@ -79,7 +79,7 @@ PB_DS_CLASS_C_DEC:: resize_imp(size_type new_size) { #ifdef PB_DS_REGRESSION - typename Allocator::group_throw_prob_adjustor adjust(m_num_e); + typename Allocator::group_adjustor adjust(m_num_e); #endif if (new_size == m_num_e) diff --git a/libstdc++-v3/include/ext/pb_ds/detail/ov_tree_map_/erase_fn_imps.hpp b/libstdc++-v3/include/ext/pb_ds/detail/ov_tree_map_/erase_fn_imps.hpp index 618306dce2e..05e7d1a1107 100644 --- a/libstdc++-v3/include/ext/pb_ds/detail/ov_tree_map_/erase_fn_imps.hpp +++ b/libstdc++-v3/include/ext/pb_ds/detail/ov_tree_map_/erase_fn_imps.hpp @@ -71,7 +71,7 @@ erase_if(Pred pred) _GLIBCXX_DEBUG_ONLY(assert_valid();) #ifdef PB_DS_REGRESSION - typename Allocator::group_throw_prob_adjustor adjust(m_size); + typename Allocator::group_adjustor adjust(m_size); #endif size_type new_size = 0; @@ -133,7 +133,7 @@ erase_imp(It it) _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::check_key_exists(PB_DS_V2F(*it));) #ifdef PB_DS_REGRESSION - typename Allocator::group_throw_prob_adjustor adjust(m_size); + typename Allocator::group_adjustor adjust(m_size); #endif _GLIBCXX_DEBUG_ASSERT(m_size > 0); diff --git a/libstdc++-v3/include/ext/pb_ds/detail/ov_tree_map_/ov_tree_map_.hpp b/libstdc++-v3/include/ext/pb_ds/detail/ov_tree_map_/ov_tree_map_.hpp index f331f0fb160..7d2ed3f1aaa 100644 --- a/libstdc++-v3/include/ext/pb_ds/detail/ov_tree_map_/ov_tree_map_.hpp +++ b/libstdc++-v3/include/ext/pb_ds/detail/ov_tree_map_/ov_tree_map_.hpp @@ -414,7 +414,7 @@ namespace __gnu_pbds { _GLIBCXX_DEBUG_ONLY(assert_valid();) #ifdef PB_DS_REGRESSION - typename Allocator::group_throw_prob_adjustor adjust(m_size); + typename Allocator::group_adjustor adjust(m_size); #endif _GLIBCXX_DEBUG_ONLY(debug_base::check_key_does_not_exist(PB_DS_V2F(r_value))); diff --git a/libstdc++-v3/include/ext/throw_allocator.h b/libstdc++-v3/include/ext/throw_allocator.h index a24982fc046..69daa15f5db 100644 --- a/libstdc++-v3/include/ext/throw_allocator.h +++ b/libstdc++-v3/include/ext/throw_allocator.h @@ -51,28 +51,19 @@ #include #include #include -#include #include #include +#ifdef __GXX_EXPERIMENTAL_CXX0X__ +# include +# include +#else +# include +# include +#endif _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) - class twister_rand_gen - { - private: - std::tr1::mt19937 _M_generator; - - public: - twister_rand_gen(unsigned int s = static_cast(std::time(0))); - - void - init(unsigned int); - - double - get_prob(); - }; - - /** + /** * @brief Thown by throw_allocator. * @ingroup exceptions */ @@ -90,102 +81,286 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) #endif } - /// Base class. - class throw_allocator_base + // Base class for checking address and label information about + // allocations. Create a std::map between the allocated address + // (void*) and a datum for annotations, which are a pair of numbers + // corresponding to label and allocated size. + struct annotate_base { - public: + annotate_base() + { + label(); + map(); + } + + static void + set_label(size_t l) + { label() = l; } + + static size_t + get_label() + { return label(); } + void - init(unsigned long seed); + insert(void* p, size_t size) + { + if (p == NULL) + { + std::string error("throw_allocator_base::insert null insert!\n"); + log_to_string(error, make_entry(p, size)); + std::__throw_logic_error(error.c_str()); + } - static void - set_throw_prob(double throw_prob); + const_iterator found = map().find(p); + if (found != map().end()) + { + std::string error("throw_allocator_base::insert double insert!\n"); + log_to_string(error, make_entry(p, size)); + log_to_string(error, *found); + std::__throw_logic_error(error.c_str()); + } - static double - get_throw_prob(); + map().insert(make_entry(p, size)); + } - static void - set_label(size_t l); + void + erase(void* p, size_t size) + { + check_allocated(p, size); + map().erase(p); + } - static bool - empty(); + // See if a particular address and size has been allocated. + inline void + check_allocated(void* p, size_t size) + { + const_iterator found = map().find(p); + if (found == map().end()) + { + std::string error("annotate_base::check_allocated by value " + "null erase!\n"); + log_to_string(error, make_entry(p, size)); + std::__throw_logic_error(error.c_str()); + } + + if (found->second.second != size) + { + std::string error("annotate_base::check_allocated by value " + "wrong-size erase!\n"); + log_to_string(error, make_entry(p, size)); + log_to_string(error, *found); + std::__throw_logic_error(error.c_str()); + } + } - struct group_throw_prob_adjustor + // See if a given label has been allocated. + inline void + check_allocated(size_t label) { - group_throw_prob_adjustor(size_t size) : _M_throw_prob_orig(_S_throw_prob) - { - _S_throw_prob = - 1 - std::pow(double(1 - _S_throw_prob), double(0.5 / (size + 1))); - } + const_iterator beg = map().begin(); + const_iterator end = map().end(); + std::string found; + while (beg != end) + { + if (beg->second.first == label) + log_to_string(found, *beg); + ++beg; + } + + if (!found.empty()) + { + std::string error("annotate_base::check_allocated by label\n"); + error += found; + std::__throw_logic_error(error.c_str()); + } + } + + private: + typedef std::pair data_type; + typedef std::map map_type; + typedef map_type::value_type entry_type; + typedef map_type::const_iterator const_iterator; + typedef map_type::const_reference const_reference; - ~group_throw_prob_adjustor() - { _S_throw_prob = _M_throw_prob_orig; } + friend std::ostream& + operator<<(std::ostream&, const annotate_base&); + entry_type + make_entry(void* p, size_t size) + { return std::make_pair(p, data_type(get_label(), size)); } + + void + log_to_string(std::string& s, const_reference ref) const + { + char buf[40]; + const char tab('\t'); + s += "label: "; + unsigned long l = static_cast(ref.second.first); + __builtin_sprintf(buf, "%lu", l); + s += buf; + s += tab; + s += "size: "; + l = static_cast(ref.second.second); + __builtin_sprintf(buf, "%lu", l); + s += buf; + s += tab; + s += "address: "; + __builtin_sprintf(buf, "%p", ref.first); + s += buf; + s += '\n'; + } + + static size_t& + label() + { + static size_t ll; + return ll; + } + + static map_type& + map() + { + static map_type mp; + return mp; + } + }; + + inline std::ostream& + operator<<(std::ostream& os, const annotate_base& __b) + { + std::string error; + typedef annotate_base base_type; + base_type::const_iterator beg = __b.map().begin(); + base_type::const_iterator end = __b.map().end(); + for (; beg != end; ++beg) + __b.log_to_string(error, *beg); + return os << error; + } + + /// Base class for probability control and throw. + struct probability_base + { + // Scope-level probability adjustor objects: set probability for + // throw at the beginning of a scope block, and restores to + // previous probability when object is destroyed on exiting the + // block. + struct adjustor_base + { private: - const double _M_throw_prob_orig; + const double _M_prob; + + public: + adjustor_base() : _M_prob(get_probability()) { } + + virtual ~adjustor_base() + { set_probability(_M_prob); } }; - struct zero_throw_prob_adjustor + // Group condition. + struct group_adjustor : public adjustor_base { - zero_throw_prob_adjustor() : _M_throw_prob_orig(_S_throw_prob) - { _S_throw_prob = 0; } + group_adjustor(size_t size) + { set_probability(1 - std::pow(double(1 - get_probability()), + double(0.5 / (size + 1)))); + } + }; - ~zero_throw_prob_adjustor() - { _S_throw_prob = _M_throw_prob_orig; } + // Never enter the condition. + struct never_adjustor : public adjustor_base + { + never_adjustor() { set_probability(0); } + }; - private: - const double _M_throw_prob_orig; + // Always enter the condition. + struct always_adjustor : public adjustor_base + { + always_adjustor() { set_probability(1); } }; - protected: - static void - insert(void*, size_t); + probability_base() + { + probability(); + engine(); + } static void - erase(void*, size_t); + set_probability(double __p) + { probability() = __p; } - static void - throw_conditionally(); + static double& + get_probability() + { return probability(); } - // See if a particular address and size has been allocated by this - // allocator. - static void - check_allocated(void*, size_t); + void + throw_conditionally() + { + if (generate() < get_probability()) + __throw_forced_exception_error(); + } - // See if a given label has been allocated by this allocator. - static void - check_allocated(size_t); + void + seed(unsigned long __s) + { engine().seed(__s); } private: - typedef std::pair alloc_data_type; - typedef std::map map_type; - typedef map_type::value_type entry_type; - typedef map_type::const_iterator const_iterator; - typedef map_type::const_reference const_reference; +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + typedef std::uniform_real_distribution distribution_type; + typedef std::mt19937 engine_type; +#else + typedef std::tr1::uniform_real distribution_type; + typedef std::tr1::mt19937 engine_type; +#endif - friend std::ostream& - operator<<(std::ostream&, const throw_allocator_base&); + double + generate() + { +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + const distribution_type distribution(0, 1); + static auto generator = std::bind(distribution, engine()); +#else + // Use variate_generator to get normalized results. + typedef std::tr1::variate_generator gen_t; + distribution_type distribution(0, 1); + static gen_t generator(engine(), distribution); +#endif - static entry_type - make_entry(void*, size_t); + double random = generator(); + if (random < distribution.min() || random > distribution.max()) + { + std::string __s("throw_allocator::throw_conditionally"); + __s += "\n"; + __s += "random number generated is: "; + char buf[40]; + __builtin_sprintf(buf, "%f", random); + __s += buf; + std::__throw_out_of_range(__s.c_str()); + } - static void - print_to_string(std::string&); + return random; + } - static void - print_to_string(std::string&, const_reference); + static double& + probability() + { + static double __p; + return __p; + } - static twister_rand_gen _S_g; - static map_type _S_map; - static double _S_throw_prob; - static size_t _S_label; + static engine_type& + engine() + { + static engine_type __e; + return __e; + } }; - /** + /** * @brief Allocator class with logging and exception control. * @ingroup allocators */ template - class throw_allocator : public throw_allocator_base + class throw_allocator + : public probability_base, public annotate_base { public: typedef size_t size_type; @@ -196,11 +371,14 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) typedef value_type& reference; typedef const value_type& const_reference; + private: + std::allocator _M_allocator; + public: template struct rebind { - typedef throw_allocator other; + typedef throw_allocator other; }; throw_allocator() throw() { } @@ -208,13 +386,13 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) throw_allocator(const throw_allocator&) throw() { } template - throw_allocator(const throw_allocator&) throw() { } + throw_allocator(const throw_allocator&) throw() { } ~throw_allocator() throw() { } size_type max_size() const throw() - { return std::allocator().max_size(); } + { return _M_allocator.max_size(); } pointer allocate(size_type __n, std::allocator::const_pointer hint = 0) @@ -223,43 +401,41 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) std::__throw_bad_alloc(); throw_conditionally(); - value_type* const a = std::allocator().allocate(__n, hint); + pointer const a = _M_allocator.allocate(__n, hint); insert(a, sizeof(value_type) * __n); return a; } void construct(pointer __p, const T& val) - { return std::allocator().construct(__p, val); } + { return _M_allocator.construct(__p, val); } #ifdef __GXX_EXPERIMENTAL_CXX0X__ template - void - construct(pointer __p, _Args&&... __args) - { - return std::allocator(). - construct(__p, std::forward<_Args>(__args)...); - } + void + construct(pointer __p, _Args&&... __args) + { return _M_allocator.construct(__p, std::forward<_Args>(__args)...); } #endif void destroy(pointer __p) - { std::allocator().destroy(__p); } + { _M_allocator.destroy(__p); } void deallocate(pointer __p, size_type __n) { erase(__p, sizeof(value_type) * __n); - std::allocator().deallocate(__p, __n); + _M_allocator.deallocate(__p, __n); } void check_allocated(pointer __p, size_type __n) - { throw_allocator_base::check_allocated(__p, sizeof(value_type) * __n); } + { + size_type __t = sizeof(value_type) * __n; + annotate_base::check_allocated(__p, __t); + } - void - check_allocated(size_type label) - { throw_allocator_base::check_allocated(label); } + using annotate_base::check_allocated; }; template @@ -272,176 +448,6 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) operator!=(const throw_allocator&, const throw_allocator&) { return false; } - std::ostream& - operator<<(std::ostream& os, const throw_allocator_base& alloc) - { - std::string error; - throw_allocator_base::print_to_string(error); - os << error; - return os; - } - - // XXX Should be in .cc. - twister_rand_gen:: - twister_rand_gen(unsigned int seed) : _M_generator(seed) { } - - void - twister_rand_gen:: - init(unsigned int seed) - { _M_generator.seed(seed); } - - double - twister_rand_gen:: - get_prob() - { - const double min = _M_generator.min(); - const double res = static_cast(_M_generator() - min); - const double range = static_cast(_M_generator.max() - min); - const double ret = res / range; - _GLIBCXX_DEBUG_ASSERT(ret >= 0 && ret <= 1); - return ret; - } - - twister_rand_gen throw_allocator_base::_S_g; - - throw_allocator_base::map_type - throw_allocator_base::_S_map; - - double throw_allocator_base::_S_throw_prob; - - size_t throw_allocator_base::_S_label = 0; - - throw_allocator_base::entry_type - throw_allocator_base::make_entry(void* p, size_t size) - { return std::make_pair(p, alloc_data_type(_S_label, size)); } - - void - throw_allocator_base::init(unsigned long seed) - { _S_g.init(seed); } - - void - throw_allocator_base::set_throw_prob(double throw_prob) - { _S_throw_prob = throw_prob; } - - double - throw_allocator_base::get_throw_prob() - { return _S_throw_prob; } - - void - throw_allocator_base::set_label(size_t l) - { _S_label = l; } - - void - throw_allocator_base::insert(void* p, size_t size) - { - const_iterator found_it = _S_map.find(p); - if (found_it != _S_map.end()) - { - std::string error("throw_allocator_base::insert"); - error += "double insert!"; - error += '\n'; - print_to_string(error, make_entry(p, size)); - print_to_string(error, *found_it); - std::__throw_logic_error(error.c_str()); - } - _S_map.insert(make_entry(p, size)); - } - - bool - throw_allocator_base::empty() - { return _S_map.empty(); } - - void - throw_allocator_base::erase(void* p, size_t size) - { - check_allocated(p, size); - _S_map.erase(p); - } - - void - throw_allocator_base::check_allocated(void* p, size_t size) - { - const_iterator found_it = _S_map.find(p); - if (found_it == _S_map.end()) - { - std::string error("throw_allocator_base::check_allocated by value "); - error += "null erase!"; - error += '\n'; - print_to_string(error, make_entry(p, size)); - std::__throw_logic_error(error.c_str()); - } - - if (found_it->second.second != size) - { - std::string error("throw_allocator_base::check_allocated by value "); - error += "wrong-size erase!"; - error += '\n'; - print_to_string(error, make_entry(p, size)); - print_to_string(error, *found_it); - std::__throw_logic_error(error.c_str()); - } - } - - void - throw_allocator_base::check_allocated(size_t label) - { - std::string found; - const_iterator it = _S_map.begin(); - while (it != _S_map.end()) - { - if (it->second.first == label) - { - print_to_string(found, *it); - } - ++it; - } - - if (!found.empty()) - { - std::string error("throw_allocator_base::check_allocated by label "); - error += '\n'; - error += found; - std::__throw_logic_error(error.c_str()); - } - } - - void - throw_allocator_base::throw_conditionally() - { - if (_S_g.get_prob() < _S_throw_prob) - __throw_forced_exception_error(); - } - - void - throw_allocator_base::print_to_string(std::string& s) - { - const_iterator begin = throw_allocator_base::_S_map.begin(); - const_iterator end = throw_allocator_base::_S_map.end(); - for (; begin != end; ++begin) - print_to_string(s, *begin); - } - - void - throw_allocator_base::print_to_string(std::string& s, const_reference ref) - { - char buf[40]; - const char tab('\t'); - s += "address: "; - __builtin_sprintf(buf, "%p", ref.first); - s += buf; - s += tab; - s += "label: "; - unsigned long l = static_cast(ref.second.first); - __builtin_sprintf(buf, "%lu", l); - s += buf; - s += tab; - s += "size: "; - l = static_cast(ref.second.second); - __builtin_sprintf(buf, "%lu", l); - s += buf; - s += '\n'; - } - _GLIBCXX_END_NAMESPACE -#endif +#endif diff --git a/libstdc++-v3/testsuite/23_containers/list/modifiers/insert/25288.cc b/libstdc++-v3/testsuite/23_containers/list/modifiers/insert/25288.cc index a41c6b15a23..e108288586e 100644 --- a/libstdc++-v3/testsuite/23_containers/list/modifiers/insert/25288.cc +++ b/libstdc++-v3/testsuite/23_containers/list/modifiers/insert/25288.cc @@ -38,7 +38,7 @@ void insert1() for (int i = 0; i < 10; ++i) { allocator_type alloc1; - typename allocator_type::zero_throw_prob_adjustor adjust1; + typename allocator_type::never_adjustor adjust1; list_type list1(alloc1); for (int k = 0; k < j; ++k) @@ -46,7 +46,7 @@ void insert1() try { - alloc1.set_throw_prob(1); + typename allocator_type::always_adjustor adjust2; list1.insert(list1.begin(), 10, 99); VERIFY( false ); } @@ -56,7 +56,7 @@ void insert1() } catch (...) { - VERIFY( false ); + __throw_exception_again; } VERIFY( list1.size() == size_type(j) ); @@ -64,7 +64,6 @@ void insert1() VERIFY( list1.size() == 0 || list1.front() == -1 ); allocator_type alloc2; - typename allocator_type::zero_throw_prob_adjustor adjust2; list_type list2(alloc2); const int data[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; @@ -74,7 +73,7 @@ void insert1() try { - alloc2.set_throw_prob(1); + typename allocator_type::always_adjustor adjust3; list2.insert(list2.begin(), data, data + 10); VERIFY( false ); } diff --git a/libstdc++-v3/testsuite/util/regression/rand/assoc/container_rand_regression_test.tcc b/libstdc++-v3/testsuite/util/regression/rand/assoc/container_rand_regression_test.tcc index 9bc0faad89d..d995a049ed6 100644 --- a/libstdc++-v3/testsuite/util/regression/rand/assoc/container_rand_regression_test.tcc +++ b/libstdc++-v3/testsuite/util/regression/rand/assoc/container_rand_regression_test.tcc @@ -60,7 +60,7 @@ default_constructor() { PB_DS_TRACE("default_constructor"); bool done = true; - m_alloc.set_throw_prob(m_tp); + m_alloc.set_probability(m_tp); try { @@ -82,9 +82,9 @@ PB_DS_CLASS_C_DEC:: swap() { PB_DS_TRACE("swap"); - m_alloc.set_throw_prob(0); + m_alloc.set_probability(0); Cntnr* p_c = new Cntnr; - m_alloc.set_throw_prob(1); + m_alloc.set_probability(1); p_c->swap(*m_p_c); std::swap(p_c, m_p_c); delete p_c; @@ -99,8 +99,8 @@ copy_constructor() PB_DS_TRACE("copy_constructor"); bool done = true; Cntnr* p_c = NULL; - m_alloc.set_throw_prob(m_tp); - typename alloc_t::group_throw_prob_adjustor adjust(m_p_c->size()); + m_alloc.set_probability(m_tp); + typename alloc_t::group_adjustor adjust(m_p_c->size()); try { @@ -125,8 +125,8 @@ assignment_operator() PB_DS_TRACE("assignment operator"); bool done = true; Cntnr* p_c = NULL; - m_alloc.set_throw_prob(m_tp); - typename alloc_t::group_throw_prob_adjustor adjust(m_p_c->size()); + m_alloc.set_probability(m_tp); + typename alloc_t::group_adjustor adjust(m_p_c->size()); try { @@ -160,8 +160,8 @@ it_constructor_imp(__gnu_pbds::cc_hash_tag) { bool done = true; Cntnr* p_c = NULL; - m_alloc.set_throw_prob(m_tp); - typename alloc_t::group_throw_prob_adjustor adjust(m_p_c->size()); + m_alloc.set_probability(m_tp); + typename alloc_t::group_adjustor adjust(m_p_c->size()); try { @@ -227,8 +227,8 @@ it_constructor_imp(__gnu_pbds::gp_hash_tag) { bool done = true; Cntnr* p_c = NULL; - m_alloc.set_throw_prob(m_tp); - typename alloc_t::group_throw_prob_adjustor adjust(m_p_c->size()); + m_alloc.set_probability(m_tp); + typename alloc_t::group_adjustor adjust(m_p_c->size()); try { @@ -310,8 +310,8 @@ it_constructor_imp(__gnu_pbds::tree_tag) { bool done = true; Cntnr* p_c = NULL; - m_alloc.set_throw_prob(m_tp); - typename alloc_t::group_throw_prob_adjustor adjust(m_p_c->size()); + m_alloc.set_probability(m_tp); + typename alloc_t::group_adjustor adjust(m_p_c->size()); try { @@ -346,8 +346,8 @@ it_constructor_imp(__gnu_pbds::list_update_tag) { bool done = true; Cntnr* p_c = NULL; - m_alloc.set_throw_prob(m_tp); - typename alloc_t::group_throw_prob_adjustor adjust(m_p_c->size()); + m_alloc.set_probability(m_tp); + typename alloc_t::group_adjustor adjust(m_p_c->size()); try { @@ -371,8 +371,8 @@ it_constructor_imp(__gnu_pbds::pat_trie_tag) { bool done = true; Cntnr* p_c = NULL; - m_alloc.set_throw_prob(m_tp); - typename alloc_t::group_throw_prob_adjustor adjust(m_p_c->size()); + m_alloc.set_probability(m_tp); + typename alloc_t::group_adjustor adjust(m_p_c->size()); try { @@ -409,7 +409,7 @@ PB_DS_CLASS_C_DEC:: cmp(const Cntnr& r_c, const native_type& r_native_c, const std::string& r_call_fn) { - m_alloc.set_throw_prob(1); + m_alloc.set_probability(1); const size_t size = r_c.size(); const size_t native_size = r_native_c.size(); PB_DS_THROW_IF_FAILED(size == native_size, @@ -447,9 +447,9 @@ basic_cmp_(const Cntnr& r_c, const native_type& r_native_c) { typename native_type::key_type native_key = test_traits::extract_native_key(*it); - m_alloc.set_throw_prob(0); + m_alloc.set_probability(0); const key_type k = native_key; - m_alloc.set_throw_prob(1); + m_alloc.set_probability(1); typename cntnr::const_point_iterator found_it = r_c.find(k); PB_DS_THROW_IF_FAILED(found_it != r_c.end(), test_traits::native_val_to_string(*it), @@ -622,9 +622,9 @@ PB_DS_CLASS_C_DEC:: order_statistics_cmp_imp(const Cntnr& r_c, const native_type& r_native_c, __gnu_pbds::detail::true_type) { { - m_alloc.set_throw_prob(0); + m_alloc.set_probability(0); const key_type k = test_traits::generate_key(m_g, m_m); - m_alloc.set_throw_prob(1); + m_alloc.set_probability(1); const size_type order = r_c.order_of_key(k); const size_type native_order = std::distance(r_native_c.begin(), r_native_c.lower_bound(test_traits::native_key(k))); @@ -675,9 +675,9 @@ PB_DS_CLASS_C_DEC:: prefix_search_cmp_imp(const Cntnr& r_c, const native_type& r_native_c, __gnu_pbds::detail::true_type) { PB_DS_SET_DESTRUCT_PRINT - m_alloc.set_throw_prob(0); + m_alloc.set_probability(0); const key_type k = test_traits::generate_key(m_g, m_m); - m_alloc.set_throw_prob(1); + m_alloc.set_probability(1); try { typedef @@ -794,9 +794,9 @@ PB_DS_CLASS_C_DEC:: lower_bound_cmp_imp(const Cntnr& r_c, const native_type& r_native_c, __gnu_pbds::detail::true_type) { PB_DS_SET_DESTRUCT_PRINT - m_alloc.set_throw_prob(0); + m_alloc.set_probability(0); const key_type k = test_traits::generate_key(m_g, m_m); - m_alloc.set_throw_prob(1); + m_alloc.set_probability(1); typename cntnr::const_iterator it = r_c.lower_bound(k); typename native_type::key_type native_k = test_traits::native_key(k); typename native_type::const_iterator native_it = r_native_c.lower_bound(native_k); @@ -833,9 +833,9 @@ PB_DS_CLASS_C_DEC:: upper_bound_cmp_imp(const Cntnr& r_c, const native_type& r_native_c, __gnu_pbds::detail::true_type) { PB_DS_SET_DESTRUCT_PRINT - m_alloc.set_throw_prob(0); + m_alloc.set_probability(0); const key_type k = test_traits::generate_key(m_g, m_m); - m_alloc.set_throw_prob(1); + m_alloc.set_probability(1); typename cntnr::const_iterator it = r_c.upper_bound(k); typename native_type::key_type native_k = test_traits::native_key(k); typename native_type::const_iterator native_it = r_native_c.upper_bound(native_k); @@ -879,7 +879,7 @@ operator()() // Track allocation from this point only. const size_t memory_label = 775; - m_alloc.init(m_seed); + m_alloc.seed(m_seed); m_alloc.set_label(memory_label); prog_bar pb(m_n, std::cout, m_disp); @@ -1012,7 +1012,7 @@ operator()() } // Reset throw probability. - m_alloc.set_throw_prob(0); + m_alloc.set_probability(0); if (m_disp) { @@ -1069,9 +1069,9 @@ insert() PB_DS_SET_DESTRUCT_PRINT try { - m_alloc.set_throw_prob(0); + m_alloc.set_probability(0); value_type v = test_traits::generate_value(m_g, m_m); - m_alloc.set_throw_prob(m_tp); + m_alloc.set_probability(m_tp); const_key_reference r_k = test_traits::extract_key(v); typename cntnr::const_point_iterator found_it = m_p_c->find(r_k); const bool existed = (found_it != m_p_c->end()); @@ -1130,10 +1130,10 @@ subscript_imp(__gnu_pbds::detail::false_type) try { - m_alloc.set_throw_prob(0); + m_alloc.set_probability(0); value_type v = test_traits::generate_value(m_g, m_m); - m_alloc.set_throw_prob(m_tp); + m_alloc.set_probability(m_tp); (*m_p_c)[v.first] = v.second; m_native_c[test_traits::native_value(v).first] = @@ -1158,9 +1158,9 @@ subscript_imp(__gnu_pbds::detail::true_type) PB_DS_SET_DESTRUCT_PRINT try { - m_alloc.set_throw_prob(0); + m_alloc.set_probability(0); value_type v = test_traits::generate_value(m_g, m_m); - m_alloc.set_throw_prob(m_tp); + m_alloc.set_probability(m_tp); (*m_p_c)[v] = __gnu_pbds::null_mapped_type(); m_native_c.insert(test_traits::native_value(v)); } @@ -1195,9 +1195,9 @@ erase() PB_DS_TRACE("erase"); bool done = true; PB_DS_SET_DESTRUCT_PRINT - m_alloc.set_throw_prob(0); + m_alloc.set_probability(0); const key_type k = test_traits::generate_key(m_g, m_m); - m_alloc.set_throw_prob(m_tp); + m_alloc.set_probability(m_tp); try { @@ -1244,7 +1244,7 @@ erase_if() typename test_traits::template erase_if_fn erase_if_fn_t; - m_alloc.set_throw_prob(m_tp); + m_alloc.set_probability(m_tp); const size_t ersd = m_p_c->erase_if(erase_if_fn_t()); const size_t native_ersd = test_traits::erase_if(m_native_c); @@ -1296,9 +1296,9 @@ erase_it_imp(__gnu_pbds::detail::true_type) try { - m_alloc.set_throw_prob(0); + m_alloc.set_probability(0); const key_type k = test_traits::generate_key(m_g, m_m); - m_alloc.set_throw_prob(m_tp); + m_alloc.set_probability(m_tp); typename cntnr::iterator found_it = m_p_c->find(k); @@ -1373,9 +1373,9 @@ erase_rev_it_imp(__gnu_pbds::detail::true_type) try { - m_alloc.set_throw_prob(0); + m_alloc.set_probability(0); const key_type k = test_traits::generate_key(m_g, m_m); - m_alloc.set_throw_prob(m_tp); + m_alloc.set_probability(m_tp); typename cntnr::iterator found_it = m_p_c->find(k); typename native_type::iterator native_it = m_native_c.find(test_traits::native_key(k)); @@ -1728,14 +1728,14 @@ split_join_imp(__gnu_pbds::detail::true_type) try { - m_alloc.set_throw_prob(0); + m_alloc.set_probability(0); Cntnr lhs(*m_p_c); Cntnr rhs; native_type native_lhs(m_native_c); native_type native_rhs; const key_type k = test_traits::generate_key(m_g, m_m); - m_alloc.set_throw_prob(m_tp); + m_alloc.set_probability(m_tp); lhs.split(k, rhs); typename native_type::const_iterator it = @@ -1753,7 +1753,7 @@ split_join_imp(__gnu_pbds::detail::true_type) PB_DS_COND_COMPARE(lhs, native_lhs); PB_DS_COND_COMPARE(rhs, native_rhs); - m_alloc.set_throw_prob(m_tp); + m_alloc.set_probability(m_tp); if (m_g.get_prob() < 0.5) lhs.swap(rhs); @@ -1972,8 +1972,8 @@ resize_imp(__gnu_pbds::detail::true_type) max_new_size = 2000 }; - m_alloc.set_throw_prob(m_tp); - typename alloc_t::group_throw_prob_adjustor adjust(m_p_c->size()); + m_alloc.set_probability(m_tp); + typename alloc_t::group_adjustor adjust(m_p_c->size()); const size_t new_size = m_g.get_unsigned_long(min_new_size, max_new_size); m_p_c->resize(new_size); const size_t actual_new_size = m_p_c->get_actual_size(); @@ -2023,8 +2023,8 @@ get_set_load_imp(__gnu_pbds::detail::true_type) PB_DS_TRACE("get_set_load"); PB_DS_SET_DESTRUCT_PRINT m_p_c->get_load(); - m_alloc.set_throw_prob(1); - typename alloc_t::group_throw_prob_adjustor adjust(m_p_c->size()); + m_alloc.set_probability(1); + typename alloc_t::group_adjustor adjust(m_p_c->size()); const float min_load = static_cast(0.05); const float max_load = static_cast(0.9); @@ -2070,9 +2070,9 @@ get_set_loads_imp(__gnu_pbds::detail::true_type) try { - m_alloc.set_throw_prob(m_tp); + m_alloc.set_probability(m_tp); - typename alloc_t::group_throw_prob_adjustor adjust(m_p_c->size()); + typename alloc_t::group_adjustor adjust(m_p_c->size()); const float min_min_load = static_cast(0.05); const float max_min_load = static_cast(0.2); @@ -2107,7 +2107,7 @@ void PB_DS_CLASS_C_DEC:: print_container(const native_type& r_cnt, std::ostream& r_os) const { - m_alloc.set_throw_prob(0); + m_alloc.set_probability(0); typename native_type::const_iterator it = r_cnt.begin(); while (it != r_cnt.end()) { @@ -2121,7 +2121,7 @@ void PB_DS_CLASS_C_DEC:: print_container(const cntnr& r_cnt, std::ostream& r_os) const { - m_alloc.set_throw_prob(0); + m_alloc.set_probability(0); typename cntnr::const_iterator it = r_cnt.begin(); while (it != r_cnt.end()) { diff --git a/libstdc++-v3/testsuite/util/regression/rand/assoc/rand_regression_test.hpp b/libstdc++-v3/testsuite/util/regression/rand/assoc/rand_regression_test.hpp index 55cd3c0b099..d4b395b126a 100644 --- a/libstdc++-v3/testsuite/util/regression/rand/assoc/rand_regression_test.hpp +++ b/libstdc++-v3/testsuite/util/regression/rand/assoc/rand_regression_test.hpp @@ -148,7 +148,7 @@ namespace detail namespace detail { - void + inline void usage(const std::string& name) { using namespace std; @@ -179,7 +179,7 @@ namespace detail cerr << "'t' or 'f' determine whether progress will be displayed" << endl; } - void + inline void verify_params(size_t& r_seed, size_t& r_n, size_t& r_m, double& r_tp, double& r_ip, double& r_ep, double& r_cp, double& r_mp, bool& r_d) diff --git a/libstdc++-v3/testsuite/util/regression/rand/priority_queue/container_rand_regression_test.tcc b/libstdc++-v3/testsuite/util/regression/rand/priority_queue/container_rand_regression_test.tcc index 643c968847c..fe8ae6ba7ed 100644 --- a/libstdc++-v3/testsuite/util/regression/rand/priority_queue/container_rand_regression_test.tcc +++ b/libstdc++-v3/testsuite/util/regression/rand/priority_queue/container_rand_regression_test.tcc @@ -60,7 +60,7 @@ default_constructor() { PB_DS_TRACE("default_constructor"); bool done = true; - m_alloc.set_throw_prob(m_tp); + m_alloc.set_probability(m_tp); try { @@ -83,9 +83,9 @@ PB_DS_CLASS_C_DEC:: swap() { PB_DS_TRACE("swap"); - m_alloc.set_throw_prob(0); + m_alloc.set_probability(0); Cntnr* p_c = new Cntnr; - m_alloc.set_throw_prob(1); + m_alloc.set_probability(1); p_c->swap(*m_p_c); std::swap(p_c, m_p_c); delete p_c; @@ -100,9 +100,9 @@ copy_constructor() PB_DS_TRACE("copy_constructor"); bool done = true; Cntnr* p_c = NULL; - m_alloc.set_throw_prob(m_tp); + m_alloc.set_probability(m_tp); - typedef typename allocator_type::group_throw_prob_adjustor adjustor; + typedef typename allocator_type::group_adjustor adjustor; adjustor adjust(m_p_c->size()); try @@ -128,9 +128,9 @@ assignment_operator() PB_DS_TRACE("assignment operator"); bool done = true; Cntnr* p_c = NULL; - m_alloc.set_throw_prob(m_tp); + m_alloc.set_probability(m_tp); - typedef typename allocator_type::group_throw_prob_adjustor adjustor; + typedef typename allocator_type::group_adjustor adjustor; adjustor adjust(m_p_c->size()); try @@ -156,8 +156,8 @@ it_constructor() { bool done = true; Cntnr* p_c = NULL; - m_alloc.set_throw_prob(m_tp); - typedef typename allocator_type::group_throw_prob_adjustor adjustor; + m_alloc.set_probability(m_tp); + typedef typename allocator_type::group_adjustor adjustor; adjustor adjust(m_p_c->size()); try @@ -201,7 +201,7 @@ cmp(const Cntnr& c, const native_type& native, const std::string& callfn) try { - m_alloc.set_throw_prob(1); + m_alloc.set_probability(1); const size_t size = c.size(); const size_t native_size = native.size(); @@ -248,7 +248,7 @@ operator()() string_form::desc()); m_g.init(m_seed); - m_alloc.init(m_seed); + m_alloc.seed(m_seed); // The __throw_allocator::_S_label defaults to 0, so to make things // easier and more precise when debugging, start at 1. @@ -363,7 +363,7 @@ operator()() } // Reset throw probability. - m_alloc.set_throw_prob(0); + m_alloc.set_probability(0); if (m_disp) { @@ -425,9 +425,9 @@ push() try { - m_alloc.set_throw_prob(0); + m_alloc.set_probability(0); value_type v = test_traits::generate_value(m_g, m_m); - m_alloc.set_throw_prob(m_tp); + m_alloc.set_probability(m_tp); const typename cntnr::size_type sz = m_p_c->size(); m_p_c->push(v); _GLIBCXX_THROW_IF(sz != m_p_c->size() - 1, sz, m_p_c, &m_native_c); @@ -460,10 +460,10 @@ modify() bool done = true; try { - m_alloc.set_throw_prob(0); + m_alloc.set_probability(0); value_type v = test_traits::generate_value(m_g, m_m); - m_alloc.set_throw_prob(m_tp); + m_alloc.set_probability(m_tp); typename cntnr::iterator it = m_p_c->begin(); std::advance(it, m_g.get_unsigned_long(0, m_p_c->size())); if (it != m_p_c->end()) @@ -510,7 +510,7 @@ pop() bool done = true; try { - m_alloc.set_throw_prob(1); + m_alloc.set_probability(1); if (!m_p_c->empty()) { m_p_c->pop(); @@ -543,7 +543,7 @@ erase_if() typename std::iterator_traits::reference it_const_reference; - m_alloc.set_throw_prob(1); + m_alloc.set_probability(1); typedef typename test_traits::template erase_if_fn @@ -582,7 +582,7 @@ erase_it() bool done = true; try { - m_alloc.set_throw_prob(1); + m_alloc.set_probability(1); typename cntnr::iterator it = m_p_c->begin(); std::advance(it, m_g.get_unsigned_long(0, m_p_c->size())); @@ -689,11 +689,11 @@ split_join() bool done = true; try { - m_alloc.set_throw_prob(0); + m_alloc.set_probability(0); Cntnr lhs(*m_p_c); Cntnr rhs; native_type native_lhs(m_native_c); - m_alloc.set_throw_prob(m_tp); + m_alloc.set_probability(m_tp); typedef typename test_traits::template erase_if_fn split_fn_t; lhs.split(split_fn_t(), rhs); @@ -706,7 +706,7 @@ split_join() PB_DS_COND_COMPARE(lhs, native_lhs); PB_DS_COND_COMPARE(rhs, native_rhs); - m_alloc.set_throw_prob(m_tp); + m_alloc.set_probability(m_tp); if (m_g.get_prob() < 0.5) lhs.swap(rhs); @@ -815,7 +815,7 @@ void PB_DS_CLASS_C_DEC:: print_container(const native_type& cnt, std::ostream& os) const { - m_alloc.set_throw_prob(0); + m_alloc.set_probability(0); native_type cpy(cnt); while (!cpy.empty()) { @@ -830,7 +830,7 @@ PB_DS_CLASS_C_DEC:: print_container(const cntnr& cnt, std::ostream& os) const { typedef typename cntnr::const_iterator const_iterator; - m_alloc.set_throw_prob(0); + m_alloc.set_probability(0); for (const_iterator it = cnt.begin(); it != cnt.end(); ++it) os << *it << std::endl; } diff --git a/libstdc++-v3/testsuite/util/regression/rand/priority_queue/rand_regression_test.hpp b/libstdc++-v3/testsuite/util/regression/rand/priority_queue/rand_regression_test.hpp index 7dc8781bed0..1cf86020d45 100644 --- a/libstdc++-v3/testsuite/util/regression/rand/priority_queue/rand_regression_test.hpp +++ b/libstdc++-v3/testsuite/util/regression/rand/priority_queue/rand_regression_test.hpp @@ -150,7 +150,7 @@ namespace detail namespace detail { - void + inline void usage(const std::string& name) { using namespace std; @@ -182,7 +182,7 @@ namespace detail cerr << "'t' or 'f' determine whether progress will be displayed" << endl; } - void + inline void verify_params(size_t& r_seed, size_t& r_n, size_t& r_m, double& r_tp, double& r_ip, double& r_dp, double& r_ep, double& r_cp, double& r_mp, bool& r_d) -- 2.11.0