diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index c7011b0929e..fc1fb0d3692 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,49 @@ +2009-05-28 Benjamin Kosnik + + * testsuite/util/testsuite_allocator.h (check_new, check_delete): Move + to ... + * testsuite/util/replacement_memory_operators.h: ...here. New. + * testsuite/util/testsuite_hooks.h (counter): To object_counter. + * testsuite/util/testsuite_hooks.cc: Same. + + * testsuite/ext/mt_allocator/deallocate_local_thread-1.cc: Use + replacement_memory_operators.h. + * testsuite/ext/mt_allocator/deallocate_local_thread-3.cc: Same. + * testsuite/ext/mt_allocator/check_delete.cc: Same. + * testsuite/ext/mt_allocator/deallocate_local_thread-5.cc: Same. + * testsuite/ext/mt_allocator/deallocate_local_thread-7.cc: Same. + * testsuite/ext/mt_allocator/deallocate_global_thread-1.cc: Same. + * testsuite/ext/mt_allocator/deallocate_global_thread-3.cc: Same. + * testsuite/ext/mt_allocator/deallocate_local-2.cc: Same. + * testsuite/ext/mt_allocator/deallocate_local-4.cc: Same. + * testsuite/ext/mt_allocator/deallocate_local-6.cc: Same. + * testsuite/ext/mt_allocator/deallocate_local-8.cc: Same. + * testsuite/ext/mt_allocator/deallocate_global-2.cc: Same. + * testsuite/ext/mt_allocator/deallocate_global-4.cc: Same. + * testsuite/ext/mt_allocator/check_new.cc: Same. + * testsuite/ext/debug_allocator/check_delete.cc: Same. + * testsuite/ext/debug_allocator/check_new.cc: Same. + * testsuite/ext/new_allocator/deallocate_global.cc: Same. + * testsuite/ext/new_allocator/check_delete.cc: Same. + * testsuite/ext/new_allocator/check_new.cc: Same. + * testsuite/ext/new_allocator/deallocate_local.cc: Same. + * testsuite/ext/throw_allocator/deallocate_global.cc: Same. + * testsuite/ext/throw_allocator/check_delete.cc: Same. + * testsuite/ext/throw_allocator/check_new.cc: Same. + * testsuite/ext/throw_allocator/deallocate_local.cc: Same. + * testsuite/ext/malloc_allocator/deallocate_global.cc: Same. + * testsuite/ext/malloc_allocator/check_delete.cc: Same. + * testsuite/ext/malloc_allocator/check_new.cc: Same. + * testsuite/ext/malloc_allocator/deallocate_local.cc: Same. + * testsuite/ext/pool_allocator/check_delete.cc: Same. + * testsuite/ext/pool_allocator/check_new.cc: Same. + * testsuite/ext/bitmap_allocator/check_delete.cc: Same. + * testsuite/ext/bitmap_allocator/check_new.cc: Same. + * testsuite/ext/array_allocator/check_delete.cc: Same. + * testsuite/ext/array_allocator/check_new.cc: Same. + * testsuite/23_containers/deque/cons/1.cc: Same. + * testsuite/23_containers/deque/cons/2.cc: Same. + 2009-05-27 Benjamin Kosnik * libsupc++/initializer_list: Format. diff --git a/libstdc++-v3/testsuite/23_containers/deque/cons/1.cc b/libstdc++-v3/testsuite/23_containers/deque/cons/1.cc index 3d86fd806d3..579521582c7 100644 --- a/libstdc++-v3/testsuite/23_containers/deque/cons/1.cc +++ b/libstdc++-v3/testsuite/23_containers/deque/cons/1.cc @@ -26,7 +26,7 @@ #include #include -typedef std::deque<__gnu_test::counter> gdeque; +typedef std::deque<__gnu_test::object_counter> gdeque; bool test __attribute__((unused)) = true; diff --git a/libstdc++-v3/testsuite/23_containers/deque/cons/2.cc b/libstdc++-v3/testsuite/23_containers/deque/cons/2.cc index 4d6e1308db8..23600284e72 100644 --- a/libstdc++-v3/testsuite/23_containers/deque/cons/2.cc +++ b/libstdc++-v3/testsuite/23_containers/deque/cons/2.cc @@ -31,10 +31,10 @@ using __gnu_test::tracker_allocator_counter; using __gnu_test::tracker_allocator; using __gnu_test::copy_constructor; using __gnu_test::assignment_operator; -using __gnu_test::counter; +using __gnu_test::object_counter; using __gnu_test::destructor; -typedef std::deque gdeque; +typedef std::deque gdeque; bool test __attribute__((unused)) = true; diff --git a/libstdc++-v3/testsuite/ext/array_allocator/check_delete.cc b/libstdc++-v3/testsuite/ext/array_allocator/check_delete.cc index 6a1214e63fe..9e6f32d13fa 100644 --- a/libstdc++-v3/testsuite/ext/array_allocator/check_delete.cc +++ b/libstdc++-v3/testsuite/ext/array_allocator/check_delete.cc @@ -21,40 +21,15 @@ #include #include -#include -#include - -using __gnu_cxx::array_allocator; - -void* -operator new(std::size_t n) throw(std::bad_alloc) -{ - new_called = true; - return std::malloc(n); -} - -void -operator delete(void *v) throw() -{ - delete_called = true; - return std::free(v); -} - -// These just help tracking down error messages. -void test01() -{ - bool test __attribute__((unused)) = true; - typedef unsigned int value_type; - typedef std::tr1::array array_type; - typedef array_allocator allocator_type; - array_type store; - allocator_type a(&store); - VERIFY( bool(__gnu_test::check_delete(a)) ); -} +#include int main() -{ - test01(); +{ + typedef unsigned int value_type; + typedef std::tr1::array array_type; + typedef __gnu_cxx::array_allocator allocator_type; + array_type store; + allocator_type a(&store); + __gnu_test::check_delete(a); return 0; } - diff --git a/libstdc++-v3/testsuite/ext/array_allocator/check_new.cc b/libstdc++-v3/testsuite/ext/array_allocator/check_new.cc index ea75ee75f71..2d51a025064 100644 --- a/libstdc++-v3/testsuite/ext/array_allocator/check_new.cc +++ b/libstdc++-v3/testsuite/ext/array_allocator/check_new.cc @@ -21,40 +21,15 @@ #include #include -#include -#include - -using __gnu_cxx::array_allocator; - -void* -operator new(std::size_t n) throw(std::bad_alloc) -{ - new_called = true; - return std::malloc(n); -} - -void -operator delete(void *v) throw() -{ - delete_called = true; - return std::free(v); -} - -// These just help tracking down error messages. -void test01() -{ - bool test __attribute__((unused)) = true; - typedef unsigned int value_type; - typedef std::tr1::array array_type; - typedef array_allocator allocator_type; - array_type store; - allocator_type a(&store); - VERIFY( bool(__gnu_test::check_new(a)) ); -} +#include int main() -{ - test01(); +{ + typedef unsigned int value_type; + typedef std::tr1::array array_type; + typedef __gnu_cxx::array_allocator allocator_type; + array_type store; + allocator_type a(&store); + __gnu_test::check_new(a); return 0; } - diff --git a/libstdc++-v3/testsuite/ext/bitmap_allocator/check_delete.cc b/libstdc++-v3/testsuite/ext/bitmap_allocator/check_delete.cc index 9cff3851307..a82bcc7f948 100644 --- a/libstdc++-v3/testsuite/ext/bitmap_allocator/check_delete.cc +++ b/libstdc++-v3/testsuite/ext/bitmap_allocator/check_delete.cc @@ -19,35 +19,11 @@ #include #include -#include -#include - -using __gnu_cxx::bitmap_allocator; - -void* -operator new(std::size_t n) throw(std::bad_alloc) -{ - new_called = true; - return std::malloc(n); -} - -void -operator delete(void *v) throw() -{ - delete_called = true; - return std::free(v); -} - -// These just help tracking down error messages. -void test01() -{ - bool test __attribute__((unused)) = true; - typedef bitmap_allocator allocator_type; - VERIFY( bool(__gnu_test::check_delete()) ); -} +#include int main() -{ - test01(); +{ + typedef __gnu_cxx::bitmap_allocator allocator_type; + __gnu_test::check_delete(); return 0; } diff --git a/libstdc++-v3/testsuite/ext/bitmap_allocator/check_new.cc b/libstdc++-v3/testsuite/ext/bitmap_allocator/check_new.cc index 24ee3f08b0c..205fa3a1786 100644 --- a/libstdc++-v3/testsuite/ext/bitmap_allocator/check_new.cc +++ b/libstdc++-v3/testsuite/ext/bitmap_allocator/check_new.cc @@ -19,35 +19,11 @@ #include #include -#include -#include - -using __gnu_cxx::bitmap_allocator; - -void* -operator new(std::size_t n) throw(std::bad_alloc) -{ - new_called = true; - return std::malloc(n); -} - -void -operator delete(void *v) throw() -{ - delete_called = true; - return std::free(v); -} - -// These just help tracking down error messages. -void test01() -{ - bool test __attribute__((unused)) = true; - typedef bitmap_allocator allocator_type; - VERIFY( bool(__gnu_test::check_new()) ); -} +#include int main() -{ - test01(); +{ + typedef __gnu_cxx::bitmap_allocator allocator_type; + __gnu_test::check_new(); return 0; } diff --git a/libstdc++-v3/testsuite/ext/debug_allocator/check_delete.cc b/libstdc++-v3/testsuite/ext/debug_allocator/check_delete.cc index 04f0997cc34..5b9d06142b6 100644 --- a/libstdc++-v3/testsuite/ext/debug_allocator/check_delete.cc +++ b/libstdc++-v3/testsuite/ext/debug_allocator/check_delete.cc @@ -22,37 +22,12 @@ #include #include #include -#include -#include - -using __gnu_cxx::malloc_allocator; -using __gnu_cxx::debug_allocator; - -void* -operator new(std::size_t n) throw(std::bad_alloc) -{ - new_called = true; - return std::malloc(n); -} - -void -operator delete(void *v) throw() -{ - delete_called = true; - return std::free(v); -} - -// These just help tracking down error messages. -void test01() -{ - bool test __attribute__((unused)) = true; - typedef debug_allocator > allocator_type; - VERIFY( bool(__gnu_test::check_delete()) ); -} +#include int main() -{ - test01(); +{ + using namespace __gnu_cxx; + typedef debug_allocator > allocator_type; + __gnu_test::check_delete(); return 0; } - diff --git a/libstdc++-v3/testsuite/ext/debug_allocator/check_new.cc b/libstdc++-v3/testsuite/ext/debug_allocator/check_new.cc index 9169637902a..105bf288912 100644 --- a/libstdc++-v3/testsuite/ext/debug_allocator/check_new.cc +++ b/libstdc++-v3/testsuite/ext/debug_allocator/check_new.cc @@ -22,37 +22,12 @@ #include #include #include -#include -#include - -using __gnu_cxx::malloc_allocator; -using __gnu_cxx::debug_allocator; - -void* -operator new(std::size_t n) throw(std::bad_alloc) -{ - new_called = true; - return std::malloc(n); -} - -void -operator delete(void *v) throw() -{ - delete_called = true; - return std::free(v); -} - -// These just help tracking down error messages. -void test01() -{ - bool test __attribute__((unused)) = true; - typedef debug_allocator > allocator_type; - VERIFY( bool(__gnu_test::check_new()) ); -} +#include int main() -{ - test01(); +{ + using namespace __gnu_cxx; + typedef debug_allocator > allocator_type; + __gnu_test::check_new(); return 0; } - diff --git a/libstdc++-v3/testsuite/ext/malloc_allocator/check_delete.cc b/libstdc++-v3/testsuite/ext/malloc_allocator/check_delete.cc index 2b9f8bcf861..2ed8d0454c0 100644 --- a/libstdc++-v3/testsuite/ext/malloc_allocator/check_delete.cc +++ b/libstdc++-v3/testsuite/ext/malloc_allocator/check_delete.cc @@ -21,36 +21,11 @@ #include #include -#include -#include - -using __gnu_cxx::malloc_allocator; - -void* -operator new(std::size_t n) throw(std::bad_alloc) -{ - new_called = true; - return std::malloc(n); -} - -void -operator delete(void *v) throw() -{ - delete_called = true; - return std::free(v); -} - -// These just help tracking down error messages. -void test01() -{ - bool test __attribute__((unused)) = true; - typedef malloc_allocator allocator_type; - VERIFY( bool(__gnu_test::check_delete()) ); -} +#include int main() -{ - test01(); +{ + typedef __gnu_cxx::malloc_allocator allocator_type; + __gnu_test::check_delete(); return 0; } - diff --git a/libstdc++-v3/testsuite/ext/malloc_allocator/check_new.cc b/libstdc++-v3/testsuite/ext/malloc_allocator/check_new.cc index 51acf697ecb..fac139f2b0c 100644 --- a/libstdc++-v3/testsuite/ext/malloc_allocator/check_new.cc +++ b/libstdc++-v3/testsuite/ext/malloc_allocator/check_new.cc @@ -21,36 +21,11 @@ #include #include -#include -#include - -using __gnu_cxx::malloc_allocator; - -void* -operator new(std::size_t n) throw(std::bad_alloc) -{ - new_called = true; - return std::malloc(n); -} - -void -operator delete(void *v) throw() -{ - delete_called = true; - return std::free(v); -} - -// These just help tracking down error messages. -void test01() -{ - bool test __attribute__((unused)) = true; - typedef malloc_allocator allocator_type; - VERIFY( bool(__gnu_test::check_new()) ); -} +#include int main() -{ - test01(); +{ + typedef __gnu_cxx::malloc_allocator allocator_type; + __gnu_test::check_new(); return 0; } - diff --git a/libstdc++-v3/testsuite/ext/malloc_allocator/deallocate_global.cc b/libstdc++-v3/testsuite/ext/malloc_allocator/deallocate_global.cc index 2d1ded83d3b..67041f5483f 100644 --- a/libstdc++-v3/testsuite/ext/malloc_allocator/deallocate_global.cc +++ b/libstdc++-v3/testsuite/ext/malloc_allocator/deallocate_global.cc @@ -17,56 +17,15 @@ // with this library; see the file COPYING3. If not see // . -// 20.4.1.1 allocator members - #include #include -#include #include -#include - -static size_t count; - -struct count_check -{ - count_check() {} - ~count_check() - { - if (count != 0) - throw std::runtime_error("count isn't zero"); - } -}; - -static count_check check; - -void* operator new(size_t size) throw(std::bad_alloc) -{ - printf("operator new is called \n"); - void* p = malloc(size); - if (p == NULL) - throw std::bad_alloc(); - count++; - return p; -} - -void operator delete(void* p) throw() -{ - printf("operator delete is called \n"); - if (p == NULL) - return; - count--; - if (count == 0) - printf("All memory released \n"); - else - printf("%lu allocations to be released \n", - static_cast(count)); - free(p); -} +#include typedef char char_t; typedef std::char_traits traits_t; typedef __gnu_cxx::malloc_allocator allocator_t; -typedef std::basic_string string_t; +typedef std::basic_string string_t; string_t s("bayou bend"); diff --git a/libstdc++-v3/testsuite/ext/malloc_allocator/deallocate_local.cc b/libstdc++-v3/testsuite/ext/malloc_allocator/deallocate_local.cc index f9cd80d2375..76ae1995f55 100644 --- a/libstdc++-v3/testsuite/ext/malloc_allocator/deallocate_local.cc +++ b/libstdc++-v3/testsuite/ext/malloc_allocator/deallocate_local.cc @@ -1,5 +1,5 @@ // -// Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 +// Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -17,51 +17,23 @@ // with this library; see the file COPYING3. If not see // . -// 20.4.1.1 allocator members - #include -#include #include -#include - -static size_t alloc_cnt; - -void* operator new(size_t size) throw(std::bad_alloc) -{ - printf("operator new is called \n"); - void* p = malloc(size); - if (p == NULL) - throw std::bad_alloc(); - alloc_cnt++; - return p; -} - -void operator delete(void* p) throw() -{ - printf("operator delete is called \n"); - if (p == NULL) - return; - alloc_cnt--; - if (alloc_cnt == 0) - printf("All memory released \n"); - else - printf("%lu allocations to be released \n", - static_cast(alloc_cnt)); - free(p); -} +#include typedef char char_t; typedef std::char_traits traits_t; typedef __gnu_cxx::malloc_allocator allocator_t; -typedef std::basic_string string_t; +typedef std::basic_string string_t; int main() { - bool test __attribute__((unused)) = true; { string_t s; s += "bayou bend"; } - VERIFY( alloc_cnt == 0 ); + + if (__gnu_test::counter::count() != 0) + throw std::runtime_error("count not zero"); return 0; } diff --git a/libstdc++-v3/testsuite/ext/mt_allocator/check_delete.cc b/libstdc++-v3/testsuite/ext/mt_allocator/check_delete.cc index 470b66f5cf6..374c567060a 100644 --- a/libstdc++-v3/testsuite/ext/mt_allocator/check_delete.cc +++ b/libstdc++-v3/testsuite/ext/mt_allocator/check_delete.cc @@ -21,34 +21,11 @@ #include #include -#include -#include - -using __gnu_cxx::__mt_alloc; - -void* -operator new(std::size_t n) throw(std::bad_alloc) -{ - new_called = true; - return std::malloc(n); -} - -void -operator delete(void* v) throw() -{ - delete_called = true; - return std::free(v); -} - -void test01() -{ - bool test __attribute__((unused)) = true; - typedef __mt_alloc allocator_type; - VERIFY( bool(__gnu_test::check_delete()) ); -} +#include int main() -{ - test01(); +{ + typedef __gnu_cxx::__mt_alloc allocator_type; + __gnu_test::check_delete(); return 0; } diff --git a/libstdc++-v3/testsuite/ext/mt_allocator/check_new.cc b/libstdc++-v3/testsuite/ext/mt_allocator/check_new.cc index 171a2073f3c..52793264063 100644 --- a/libstdc++-v3/testsuite/ext/mt_allocator/check_new.cc +++ b/libstdc++-v3/testsuite/ext/mt_allocator/check_new.cc @@ -21,35 +21,12 @@ #include #include -#include -#include - -using __gnu_cxx::__mt_alloc; - -void* -operator new(std::size_t n) throw(std::bad_alloc) -{ - new_called = true; - return std::malloc(n); -} - -void -operator delete(void* v) throw() -{ - delete_called = true; - return std::free(v); -} - -void test01() -{ - // Uses new but delete only optionally. - bool test __attribute__((unused)) = true; - typedef __mt_alloc allocator_type; - VERIFY( bool(__gnu_test::check_new()) ); -} +#include int main() -{ - test01(); +{ + // Uses new but delete only optionally. + typedef __gnu_cxx::__mt_alloc allocator_type; + __gnu_test::check_new(); return 0; } diff --git a/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_global-2.cc b/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_global-2.cc index a75f38a0724..fcc5006bd3c 100644 --- a/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_global-2.cc +++ b/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_global-2.cc @@ -24,43 +24,7 @@ #include #include #include - -static size_t count; - -struct count_check -{ - count_check() { } - ~count_check() - { - // NB: __mt_allocator doesn't clean itself up. Thus, this will not - // be zero. - if (count != 0) - { - //throw std::runtime_error("allocation/deallocation count isn't zero"); - printf("allocation/deallocation count is %zu \n", count); - } - } -}; - -static count_check check; - -void* operator new(size_t size) throw(std::bad_alloc) -{ - printf("operator new is called \n"); - void* p = malloc(size); - if (p == NULL) - throw std::bad_alloc(); - count++; - return p; -} - -void operator delete(void* p) throw() -{ - printf("operator delete is called \n"); - if (p == NULL) - return; - count--; -} +#include typedef std::string value_type; using __gnu_cxx::__pool; @@ -74,6 +38,9 @@ list_type l; int main() { + // NB: __mt_allocator doesn't clean itself up. Thus, the count will + // not be zero. + __gnu_test::counter::exceptions(false); l.push_back("bayou bend"); return 0; } diff --git a/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_global-4.cc b/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_global-4.cc index bc9c2c7d477..cafbffb3494 100644 --- a/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_global-4.cc +++ b/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_global-4.cc @@ -24,43 +24,7 @@ #include #include #include - -static size_t count; - -struct count_check -{ - count_check() { } - ~count_check() - { - // NB: __mt_allocator doesn't clean itself up. Thus, this will not - // be zero. - if (count != 0) - { - //throw std::runtime_error("allocation/deallocation count isn't zero"); - printf("allocation/deallocation count is %zu \n", count); - } - } -}; - -static count_check check; - -void* operator new(size_t size) throw(std::bad_alloc) -{ - printf("operator new is called \n"); - void* p = malloc(size); - if (p == NULL) - throw std::bad_alloc(); - count++; - return p; -} - -void operator delete(void* p) throw() -{ - printf("operator delete is called \n"); - if (p == NULL) - return; - count--; -} +#include typedef std::string value_t; using __gnu_cxx::__pool; @@ -74,6 +38,9 @@ list_type l; int main() { + // NB: __mt_allocator doesn't clean itself up. Thus, the count will + // not be zero. + __gnu_test::counter::exceptions(false); l.push_back("bayou bend"); return 0; } diff --git a/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_global_thread-1.cc b/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_global_thread-1.cc index 6881c9f3d1a..f61cd38b790 100644 --- a/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_global_thread-1.cc +++ b/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_global_thread-1.cc @@ -24,43 +24,7 @@ #include #include #include - -static size_t count; - -struct count_check -{ - count_check() { } - ~count_check() - { - // NB: __mt_allocator doesn't clean itself up. Thus, this will not - // be zero. - if (count != 0) - { - //throw std::runtime_error("allocation/deallocation count isn't zero"); - printf("allocation/deallocation count is %zu \n", count); - } - } -}; - -static count_check check; - -void* operator new(size_t size) throw(std::bad_alloc) -{ - printf("operator new is called \n"); - void* p = malloc(size); - if (p == NULL) - throw std::bad_alloc(); - count++; - return p; -} - -void operator delete(void* p) throw() -{ - printf("operator delete is called \n"); - if (p == NULL) - return; - count--; -} +#include typedef std::string value_type; using __gnu_cxx::__pool; @@ -74,6 +38,9 @@ list_type l; int main() { + // NB: __mt_allocator doesn't clean itself up. Thus, the count will + // not be zero. + __gnu_test::counter::exceptions(false); l.push_back("bayou bend"); return 0; } diff --git a/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_global_thread-3.cc b/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_global_thread-3.cc index 2724d36392f..62074f0a426 100644 --- a/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_global_thread-3.cc +++ b/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_global_thread-3.cc @@ -24,43 +24,7 @@ #include #include #include - -static size_t count; - -struct count_check -{ - count_check() { } - ~count_check() - { - // NB: __mt_allocator doesn't clean itself up. Thus, this will not - // be zero. - if (count != 0) - { - //throw std::runtime_error("allocation/deallocation count isn't zero"); - printf("allocation/deallocation count is %zu \n", count); - } - } -}; - -static count_check check; - -void* operator new(size_t size) throw(std::bad_alloc) -{ - printf("operator new is called \n"); - void* p = malloc(size); - if (p == NULL) - throw std::bad_alloc(); - count++; - return p; -} - -void operator delete(void* p) throw() -{ - printf("operator delete is called \n"); - if (p == NULL) - return; - count--; -} +#include typedef std::string value_type; using __gnu_cxx::__pool; @@ -74,6 +38,9 @@ list_type l; int main() { + // NB: __mt_allocator doesn't clean itself up. Thus, the count will + // not be zero. + __gnu_test::counter::exceptions(false); l.push_back("bayou bend"); return 0; } diff --git a/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_local-2.cc b/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_local-2.cc index eec6dea8c1b..9ccebd57ed0 100644 --- a/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_local-2.cc +++ b/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_local-2.cc @@ -23,43 +23,7 @@ #include #include #include - -static size_t count; - -struct count_check -{ - count_check() { } - ~count_check() - { - // NB: __mt_allocator doesn't clean itself up. Thus, this will not - // be zero. - if (count != 0) - { - //throw std::runtime_error("allocation/deallocation count isn't zero"); - printf("allocation/deallocation count is %zu \n", count); - } - } -}; - -static count_check check; - -void* operator new(size_t size) throw(std::bad_alloc) -{ - printf("operator new is called \n"); - void* p = malloc(size); - if (p == NULL) - throw std::bad_alloc(); - count++; - return p; -} - -void operator delete(void* p) throw() -{ - printf("operator delete is called \n"); - if (p == NULL) - return; - count--; -} +#include typedef char value_type; typedef std::char_traits traits_type; @@ -70,6 +34,9 @@ typedef std::basic_string string_type; int main() { + // NB: __mt_allocator doesn't clean itself up. Thus, the count will + // not be zero. + __gnu_test::counter::exceptions(false); string_type s; s += "bayou bend"; return 0; diff --git a/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_local-4.cc b/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_local-4.cc index 793f6406164..9265a15a98b 100644 --- a/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_local-4.cc +++ b/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_local-4.cc @@ -23,43 +23,7 @@ #include #include #include - -static size_t count; - -struct count_check -{ - count_check() { } - ~count_check() - { - // NB: __mt_allocator doesn't clean itself up. Thus, this will not - // be zero. - if (count != 0) - { - printf("allocation/deallocation count is %zu \n", count); - //throw std::runtime_error("allocation/deallocation count isn't zero"); - } - } -}; - -static count_check check; - -void* operator new(size_t size) throw(std::bad_alloc) -{ - printf("operator new is called \n"); - void* p = malloc(size); - if (p == NULL) - throw std::bad_alloc(); - count++; - return p; -} - -void operator delete(void* p) throw() -{ - printf("operator delete is called \n"); - if (p == NULL) - return; - count--; -} +#include typedef char value_type; typedef std::char_traits traits_type; @@ -71,6 +35,9 @@ typedef std::basic_string string_type; int main() { + // NB: __mt_allocator doesn't clean itself up. Thus, the count will + // not be zero. + __gnu_test::counter::exceptions(false); string_type s; s += "bayou bend"; return 0; diff --git a/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_local-6.cc b/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_local-6.cc index fd1da97a53b..01755713885 100644 --- a/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_local-6.cc +++ b/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_local-6.cc @@ -24,42 +24,7 @@ #include #include #include - -static size_t count; - -struct count_check -{ - count_check() { } - ~count_check() - { - // NB: Using a pool that attempts to clean up resource use. - if (count != 0) - { - printf("allocation/deallocation count is %zu \n", count); - throw std::runtime_error("allocation/deallocation count isn't zero"); - } - } -}; - -static count_check check; - -void* operator new(size_t size) throw(std::bad_alloc) -{ - printf("operator new is called \n"); - void* p = malloc(size); - if (p == NULL) - throw std::bad_alloc(); - count++; - return p; -} - -void operator delete(void* p) throw() -{ - printf("operator delete is called \n"); - if (p == NULL) - return; - count--; -} +#include template struct cleanup_pool : public __gnu_cxx::__pool @@ -81,6 +46,9 @@ typedef std::basic_string string_type; int main() { + // NB: __mt_allocator doesn't clean itself up. Thus, the count will + // not be zero. + __gnu_test::counter::exceptions(false); string_type s; s += "bayou bend"; return 0; diff --git a/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_local-8.cc b/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_local-8.cc index 1574e8cb473..34005e4b091 100644 --- a/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_local-8.cc +++ b/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_local-8.cc @@ -24,42 +24,7 @@ #include #include #include - -static size_t count; - -struct count_check -{ - count_check() { } - ~count_check() - { - // NB: Using a pool that attempts to clean up resource use. - if (count != 0) - { - printf("allocation/deallocation count is %zu \n", count); - throw std::runtime_error("allocation/deallocation count isn't zero"); - } - } -}; - -static count_check check; - -void* operator new(size_t size) throw(std::bad_alloc) -{ - printf("operator new is called \n"); - void* p = malloc(size); - if (p == NULL) - throw std::bad_alloc(); - count++; - return p; -} - -void operator delete(void* p) throw() -{ - printf("operator delete is called \n"); - if (p == NULL) - return; - count--; -} +#include template struct cleanup_pool : public __gnu_cxx::__pool @@ -82,6 +47,9 @@ typedef std::basic_string string_type; int main() { + // NB: __mt_allocator doesn't clean itself up. Thus, the count will + // not be zero. + __gnu_test::counter::exceptions(false); string_type s; s += "bayou bend"; return 0; diff --git a/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_local_thread-1.cc b/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_local_thread-1.cc index 399d57686f1..012a7585acf 100644 --- a/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_local_thread-1.cc +++ b/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_local_thread-1.cc @@ -23,43 +23,7 @@ #include #include #include - -static size_t count; - -struct count_check -{ - count_check() { } - ~count_check() - { - // NB: __mt_allocator doesn't clean itself up. Thus, this will not - // be zero. - if (count != 0) - { - //throw std::runtime_error("allocation/deallocation count isn't zero"); - printf("allocation/deallocation count is %zu \n", count); - } - } -}; - -static count_check check; - -void* operator new(size_t size) throw(std::bad_alloc) -{ - printf("operator new is called \n"); - void* p = malloc(size); - if (p == NULL) - throw std::bad_alloc(); - count++; - return p; -} - -void operator delete(void* p) throw() -{ - printf("operator delete is called \n"); - if (p == NULL) - return; - count--; -} +#include typedef char value_type; typedef std::char_traits traits_type; @@ -70,6 +34,9 @@ typedef std::basic_string string_type; int main() { + // NB: __mt_allocator doesn't clean itself up. Thus, the count will + // not be zero. + __gnu_test::counter::exceptions(false); string_type s; s += "bayou bend"; return 0; diff --git a/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_local_thread-3.cc b/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_local_thread-3.cc index 38977c569dd..0a9fde02b12 100644 --- a/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_local_thread-3.cc +++ b/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_local_thread-3.cc @@ -23,43 +23,7 @@ #include #include #include - -static size_t count; - -struct count_check -{ - count_check() { } - ~count_check() - { - // NB: __mt_allocator doesn't clean itself up. Thus, this will not - // be zero. - if (count != 0) - { - //throw std::runtime_error("allocation/deallocation count isn't zero"); - printf("allocation/deallocation count is %zu \n", count); - } - } -}; - -static count_check check; - -void* operator new(size_t size) throw(std::bad_alloc) -{ - printf("operator new is called \n"); - void* p = malloc(size); - if (p == NULL) - throw std::bad_alloc(); - count++; - return p; -} - -void operator delete(void* p) throw() -{ - printf("operator delete is called \n"); - if (p == NULL) - return; - count--; -} +#include typedef char value_type; typedef std::char_traits traits_type; @@ -71,6 +35,9 @@ typedef std::basic_string string_type; int main() { + // NB: __mt_allocator doesn't clean itself up. Thus, the count will + // not be zero. + __gnu_test::counter::exceptions(false); string_type s; s += "bayou bend"; return 0; diff --git a/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_local_thread-5.cc b/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_local_thread-5.cc index 49701c09bbc..a812aecf26c 100644 --- a/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_local_thread-5.cc +++ b/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_local_thread-5.cc @@ -24,42 +24,7 @@ #include #include #include - -static size_t count; - -struct count_check -{ - count_check() { } - ~count_check() - { - // NB: Using a pool that attempts to clean up resource use. - if (count != 0) - { - printf("allocation/deallocation count is %zu \n", count); - throw std::runtime_error("allocation/deallocation count isn't zero"); - } - } -}; - -static count_check check; - -void* operator new(size_t size) throw(std::bad_alloc) -{ - printf("operator new is called \n"); - void* p = malloc(size); - if (p == NULL) - throw std::bad_alloc(); - count++; - return p; -} - -void operator delete(void* p) throw() -{ - printf("operator delete is called \n"); - if (p == NULL) - return; - count--; -} +#include template struct cleanup_pool : public __gnu_cxx::__pool @@ -72,7 +37,6 @@ template ~cleanup_pool() throw() { this->_M_destroy(); } }; - typedef char value_type; typedef std::char_traits traits_type; typedef __gnu_cxx::__common_pool_policy policy_type; @@ -81,6 +45,9 @@ typedef std::basic_string string_type; int main() { + // NB: __mt_allocator doesn't clean itself up. Thus, the count will + // not be zero. + __gnu_test::counter::exceptions(false); string_type s; s += "bayou bend"; return 0; diff --git a/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_local_thread-7.cc b/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_local_thread-7.cc index 5bdfd0db8bb..ac8426ee9fc 100644 --- a/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_local_thread-7.cc +++ b/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_local_thread-7.cc @@ -24,42 +24,7 @@ #include #include #include - -static size_t count; - -struct count_check -{ - count_check() { } - ~count_check() - { - // NB: Using a pool that attempts to clean up resource use. - if (count != 0) - { - printf("allocation/deallocation count is %zu \n", count); - throw std::runtime_error("allocation/deallocation count isn't zero"); - } - } -}; - -static count_check check; - -void* operator new(size_t size) throw(std::bad_alloc) -{ - printf("operator new is called \n"); - void* p = malloc(size); - if (p == NULL) - throw std::bad_alloc(); - count++; - return p; -} - -void operator delete(void* p) throw() -{ - printf("operator delete is called \n"); - if (p == NULL) - return; - count--; -} +#include template struct cleanup_pool : public __gnu_cxx::__pool @@ -82,6 +47,9 @@ typedef std::basic_string string_type; int main() { + // NB: __mt_allocator doesn't clean itself up. Thus, the count will + // not be zero. + __gnu_test::counter::exceptions(false); string_type s; s += "bayou bend"; return 0; diff --git a/libstdc++-v3/testsuite/ext/new_allocator/check_delete.cc b/libstdc++-v3/testsuite/ext/new_allocator/check_delete.cc index f97903719ed..cff31c8926d 100644 --- a/libstdc++-v3/testsuite/ext/new_allocator/check_delete.cc +++ b/libstdc++-v3/testsuite/ext/new_allocator/check_delete.cc @@ -21,36 +21,11 @@ #include #include -#include -#include - -using __gnu_cxx::new_allocator; - -void* -operator new(std::size_t n) throw(std::bad_alloc) -{ - new_called = true; - return std::malloc(n); -} - -void -operator delete(void *v) throw() -{ - delete_called = true; - return std::free(v); -} - -// These just help tracking down error messages. -void test01() -{ - bool test __attribute__((unused)) = true; - typedef new_allocator allocator_type; - VERIFY( bool(__gnu_test::check_delete()) ); -} +#include int main() -{ - test01(); +{ + typedef __gnu_cxx::new_allocator allocator_type; + __gnu_test::check_delete(); return 0; } - diff --git a/libstdc++-v3/testsuite/ext/new_allocator/check_new.cc b/libstdc++-v3/testsuite/ext/new_allocator/check_new.cc index 9fa0c04d7f2..098b624d146 100644 --- a/libstdc++-v3/testsuite/ext/new_allocator/check_new.cc +++ b/libstdc++-v3/testsuite/ext/new_allocator/check_new.cc @@ -21,36 +21,11 @@ #include #include -#include -#include - -using __gnu_cxx::new_allocator; - -void* -operator new(std::size_t n) throw(std::bad_alloc) -{ - new_called = true; - return std::malloc(n); -} - -void -operator delete(void *v) throw() -{ - delete_called = true; - return std::free(v); -} - -// These just help tracking down error messages. -void test01() -{ - bool test __attribute__((unused)) = true; - typedef new_allocator allocator_type; - VERIFY( bool(__gnu_test::check_new()) ); -} +#include int main() -{ - test01(); +{ + typedef __gnu_cxx::new_allocator allocator_type; + __gnu_test::check_new(); return 0; } - diff --git a/libstdc++-v3/testsuite/ext/new_allocator/deallocate_global.cc b/libstdc++-v3/testsuite/ext/new_allocator/deallocate_global.cc index 014141bf639..783be483da8 100644 --- a/libstdc++-v3/testsuite/ext/new_allocator/deallocate_global.cc +++ b/libstdc++-v3/testsuite/ext/new_allocator/deallocate_global.cc @@ -17,50 +17,15 @@ // with this library; see the file COPYING3. If not see // . -// 20.4.1.1 allocator members - #include #include -#include -#include #include - -static size_t count; - -struct count_check -{ - count_check() { } - ~count_check() - { - if (count != 0) - throw std::runtime_error("allocation/deallocation count isn't zero"); - } -}; - -static count_check check; - -void* operator new(size_t size) throw(std::bad_alloc) -{ - std::printf("operator new is called \n"); - void* p = std::malloc(size); - if (p == NULL) - throw std::bad_alloc(); - count++; - return p; -} - -void operator delete(void* p) throw() -{ - std::printf("operator delete is called \n"); - if (p == NULL) - return; - count--; -} +#include typedef char char_t; typedef std::char_traits traits_t; typedef __gnu_cxx::new_allocator allocator_t; -typedef std::basic_string string_t; +typedef std::basic_string string_t; string_t s("bayou bend"); diff --git a/libstdc++-v3/testsuite/ext/new_allocator/deallocate_local.cc b/libstdc++-v3/testsuite/ext/new_allocator/deallocate_local.cc index 7f224a5cb8a..dd7c634e06c 100644 --- a/libstdc++-v3/testsuite/ext/new_allocator/deallocate_local.cc +++ b/libstdc++-v3/testsuite/ext/new_allocator/deallocate_local.cc @@ -1,5 +1,5 @@ // -// Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 +// Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -17,54 +17,23 @@ // with this library; see the file COPYING3. If not see // . -// 20.4.1.1 allocator members - #include -#include -#include -#include #include - -static size_t count; - -struct count_check -{ - count_check() { } - ~count_check() - { - if (count != 0) - throw std::runtime_error("allocation/deallocation count isn't zero"); - } -}; - -static count_check check; - -void* operator new(size_t size) throw(std::bad_alloc) -{ - std::printf("operator new is called \n"); - void* p = std::malloc(size); - if (p == NULL) - throw std::bad_alloc(); - count++; - return p; -} - -void operator delete(void* p) throw() -{ - std::printf("operator delete is called \n"); - if (p == NULL) - return; - count--; -} +#include typedef char char_t; typedef std::char_traits traits_t; typedef __gnu_cxx::new_allocator allocator_t; -typedef std::basic_string string_t; +typedef std::basic_string string_t; int main() { - string_t s; - s += "bayou bend"; + { + string_t s; + s += "bayou bend"; + } + + if (__gnu_test::counter::count() != 0) + throw std::runtime_error("count not zero"); return 0; } diff --git a/libstdc++-v3/testsuite/ext/pool_allocator/check_delete.cc b/libstdc++-v3/testsuite/ext/pool_allocator/check_delete.cc index b24550ee3de..ecc399df638 100644 --- a/libstdc++-v3/testsuite/ext/pool_allocator/check_delete.cc +++ b/libstdc++-v3/testsuite/ext/pool_allocator/check_delete.cc @@ -21,36 +21,12 @@ #include #include -#include -#include - -using __gnu_cxx::__pool_alloc; - -void* -operator new(std::size_t n) throw(std::bad_alloc) -{ - new_called = true; - return std::malloc(n); -} - -void -operator delete(void *v) throw() -{ - delete_called = true; - return std::free(v); -} - -void test01() -{ - // Uses new, but delete only sometimes. - bool test __attribute__((unused)) = true; - typedef __pool_alloc allocator_type; - VERIFY( bool(__gnu_test::check_delete()) ); -} +#include int main() { - test01(); + // Uses new, but delete only sometimes. + typedef __gnu_cxx::__pool_alloc allocator_type; + __gnu_test::check_delete(); return 0; } - diff --git a/libstdc++-v3/testsuite/ext/pool_allocator/check_new.cc b/libstdc++-v3/testsuite/ext/pool_allocator/check_new.cc index a4fad95d5ad..f1bdb77bb86 100644 --- a/libstdc++-v3/testsuite/ext/pool_allocator/check_new.cc +++ b/libstdc++-v3/testsuite/ext/pool_allocator/check_new.cc @@ -21,35 +21,11 @@ #include #include -#include -#include - -using __gnu_cxx::__pool_alloc; - -void* -operator new(std::size_t n) throw(std::bad_alloc) -{ - new_called = true; - return std::malloc(n); -} - -void -operator delete(void *v) throw() -{ - delete_called = true; - return std::free(v); -} - -void test01() -{ - bool test __attribute__((unused)) = true; - typedef __pool_alloc allocator_type; - VERIFY( bool(__gnu_test::check_new()) ); -} +#include int main() -{ - test01(); +{ + typedef __gnu_cxx::__pool_alloc allocator_type; + __gnu_test::check_new(); return 0; } - diff --git a/libstdc++-v3/testsuite/ext/throw_allocator/check_delete.cc b/libstdc++-v3/testsuite/ext/throw_allocator/check_delete.cc index a33493181bb..cfc38ee02f6 100644 --- a/libstdc++-v3/testsuite/ext/throw_allocator/check_delete.cc +++ b/libstdc++-v3/testsuite/ext/throw_allocator/check_delete.cc @@ -20,36 +20,11 @@ #include #include -#include -#include - -using __gnu_cxx::throw_allocator; - -void* -operator new(std::size_t n) throw(std::bad_alloc) -{ - new_called = true; - return std::malloc(n); -} - -void -operator delete(void *v) throw() -{ - delete_called = true; - return std::free(v); -} - -// These just help tracking down error messages. -void test01() -{ - bool test __attribute__((unused)) = true; - typedef throw_allocator allocator_type; - VERIFY( bool(__gnu_test::check_delete()) ); -} +#include int main() -{ - test01(); +{ + typedef __gnu_cxx::throw_allocator allocator_type; + __gnu_test::check_delete(); return 0; } - diff --git a/libstdc++-v3/testsuite/ext/throw_allocator/check_new.cc b/libstdc++-v3/testsuite/ext/throw_allocator/check_new.cc index f0579fbf642..2d42891766b 100644 --- a/libstdc++-v3/testsuite/ext/throw_allocator/check_new.cc +++ b/libstdc++-v3/testsuite/ext/throw_allocator/check_new.cc @@ -20,36 +20,11 @@ #include #include -#include -#include - -using __gnu_cxx::throw_allocator; - -void* -operator new(std::size_t n) throw(std::bad_alloc) -{ - new_called = true; - return std::malloc(n); -} - -void -operator delete(void *v) throw() -{ - delete_called = true; - return std::free(v); -} - -// These just help tracking down error messages. -void test01() -{ - bool test __attribute__((unused)) = true; - typedef throw_allocator allocator_type; - VERIFY( bool(__gnu_test::check_new()) ); -} +#include int main() -{ - test01(); +{ + typedef __gnu_cxx::throw_allocator allocator_type; + __gnu_test::check_new(); return 0; } - diff --git a/libstdc++-v3/testsuite/ext/throw_allocator/deallocate_global.cc b/libstdc++-v3/testsuite/ext/throw_allocator/deallocate_global.cc index d298fe42b55..c53517ebc13 100644 --- a/libstdc++-v3/testsuite/ext/throw_allocator/deallocate_global.cc +++ b/libstdc++-v3/testsuite/ext/throw_allocator/deallocate_global.cc @@ -21,50 +21,12 @@ #include #include #include -#include - -static size_t count; - -struct count_check -{ - count_check() {} - ~count_check() - { - if (count != 0) - throw std::runtime_error("count isn't zero"); - } -}; - -static count_check check; - -void* operator new(size_t size) throw(std::bad_alloc) -{ - printf("operator new is called \n"); - void* p = malloc(size); - if (p == NULL) - throw std::bad_alloc(); - count++; - return p; -} - -void operator delete(void* p) throw() -{ - printf("operator delete is called \n"); - if (p == NULL) - return; - count--; - if (count == 0) - printf("All memory released \n"); - else - printf("%lu allocations to be released \n", - static_cast(count)); - free(p); -} +#include typedef char char_t; typedef std::char_traits traits_t; typedef __gnu_cxx::throw_allocator allocator_t; -typedef std::basic_string string_t; +typedef std::basic_string string_t; string_t s("bayou bend"); diff --git a/libstdc++-v3/testsuite/ext/throw_allocator/deallocate_local.cc b/libstdc++-v3/testsuite/ext/throw_allocator/deallocate_local.cc index 45fd6dcdde0..c2e918ccc25 100644 --- a/libstdc++-v3/testsuite/ext/throw_allocator/deallocate_local.cc +++ b/libstdc++-v3/testsuite/ext/throw_allocator/deallocate_local.cc @@ -20,46 +20,21 @@ #include #include -#include - -static size_t alloc_cnt; - -void* operator new(size_t size) throw(std::bad_alloc) -{ - printf("operator new is called \n"); - void* p = malloc(size); - if (p == NULL) - throw std::bad_alloc(); - alloc_cnt++; - return p; -} - -void operator delete(void* p) throw() -{ - printf("operator delete is called \n"); - if (p == NULL) - return; - alloc_cnt--; - if (alloc_cnt == 0) - printf("All memory released \n"); - else - printf("%lu allocations to be released \n", - static_cast(alloc_cnt)); - free(p); -} +#include typedef char char_t; typedef std::char_traits traits_t; typedef __gnu_cxx::throw_allocator allocator_t; -typedef std::basic_string string_t; +typedef std::basic_string string_t; int main() { - bool test __attribute__((unused)) = true; { string_t s; s += "bayou bend"; } - VERIFY( alloc_cnt == 0 ); + + if (__gnu_test::counter::count() != 0) + throw std::runtime_error("count not zero"); return 0; } diff --git a/libstdc++-v3/testsuite/util/replacement_memory_operators.h b/libstdc++-v3/testsuite/util/replacement_memory_operators.h new file mode 100644 index 00000000000..91c8fa3d38a --- /dev/null +++ b/libstdc++-v3/testsuite/util/replacement_memory_operators.h @@ -0,0 +1,110 @@ +// +// Copyright (C) 2007, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include + +namespace __gnu_test +{ + struct counter_error : public std::exception { }; + + struct counter + { + size_t _M_count; + bool _M_throw; + + counter() : _M_count(0), _M_throw(true) { } + + ~counter() + { + if (_M_throw && _M_count != 0) + throw counter_error(); + } + + static void + increment() { get()._M_count++; } + + static void + decrement() { get()._M_count--; } + + static counter& + get() + { + static counter g; + return g; + } + + static size_t + count() { return get()._M_count; } + + static void + exceptions(bool __b) { get()._M_throw = __b; } + }; + + template + bool + check_new(Alloc a = Alloc()) + { + __gnu_test::counter::exceptions(false); + a.allocate(10); + const bool __b((__gnu_test::counter::count() > 0) == uses_global_new); + if (!__b) + throw std::logic_error("counter not incremented"); + return __b; + } + + template + bool + check_delete(Alloc a = Alloc()) + { + __gnu_test::counter::exceptions(false); + typename Alloc::pointer p = a.allocate(10); + const std::size_t count1 = __gnu_test::counter::count(); + a.deallocate(p, 10); + const std::size_t count2 = __gnu_test::counter::count(); + const bool __b((count2 < count1) == uses_global_delete); + if (!__b) + throw std::logic_error("counter not decremented"); + return __b; + } +} // namespace __gnu_test + +void* operator new(std::size_t size) throw(std::bad_alloc) +{ + printf("operator new is called \n"); + void* p = std::malloc(size); + if (p == NULL) + throw std::bad_alloc(); + __gnu_test::counter::increment(); + return p; +} + +void operator delete(void* p) throw() +{ + printf("operator delete is called \n"); + if (p != NULL) + { + std::free(p); + __gnu_test::counter::decrement(); + + std::size_t count = __gnu_test::counter::count(); + if (count == 0) + printf("All memory released \n"); + else + printf("%lu allocations to be released \n", count); + } +} diff --git a/libstdc++-v3/testsuite/util/testsuite_allocator.h b/libstdc++-v3/testsuite/util/testsuite_allocator.h index d2759f4653f..96fe546b482 100644 --- a/libstdc++-v3/testsuite/util/testsuite_allocator.h +++ b/libstdc++-v3/testsuite/util/testsuite_allocator.h @@ -32,12 +32,6 @@ #include #include -namespace -{ - bool new_called = false; - bool delete_called = false; -} - namespace __gnu_test { class tracker_allocator_counter @@ -186,27 +180,6 @@ namespace __gnu_test bool check_construct_destroy(const char* tag, int expected_c, int expected_d); - template - bool - check_new(Alloc a = Alloc()) - { - bool test __attribute__((unused)) = true; - a.allocate(10); - test &= ( new_called == uses_global_new ); - return test; - } - - template - bool - check_delete(Alloc a = Alloc()) - { - bool test __attribute__((unused)) = true; - typename Alloc::pointer p = a.allocate(10); - a.deallocate(p, 10); - test &= ( delete_called == uses_global_delete ); - return test; - } - template bool check_deallocate_null() diff --git a/libstdc++-v3/testsuite/util/testsuite_hooks.cc b/libstdc++-v3/testsuite/util/testsuite_hooks.cc index 8fb7e15b5e8..6d77d57672f 100644 --- a/libstdc++-v3/testsuite/util/testsuite_hooks.cc +++ b/libstdc++-v3/testsuite/util/testsuite_hooks.cc @@ -217,7 +217,7 @@ namespace __gnu_test #endif } - counter::size_type counter::count = 0; + object_counter::size_type object_counter::count = 0; unsigned int copy_constructor::count_ = 0; unsigned int copy_constructor::throw_on_ = 0; unsigned int assignment_operator::count_ = 0; diff --git a/libstdc++-v3/testsuite/util/testsuite_hooks.h b/libstdc++-v3/testsuite/util/testsuite_hooks.h index add47b60309..88155fa70a9 100644 --- a/libstdc++-v3/testsuite/util/testsuite_hooks.h +++ b/libstdc++-v3/testsuite/util/testsuite_hooks.h @@ -34,8 +34,8 @@ // limit in megabytes (a floating-point number). If _GLIBCXX_RES_LIMITS is // not #defined before including this header, then no limiting is attempted. // -// 3) counter -// This is a POD with a static data member, gnu_counting_struct::count, +// 3) object_counter +// This is a POD with a static data member, object_counter::count, // which starts at zero, increments on instance construction, and decrements // on instance destruction. "assert_count(n)" can be called to VERIFY() // that the count equals N. @@ -135,19 +135,19 @@ namespace __gnu_test run_tests_wrapped_env(const char*, const char*, const func_callback&); // Counting. - struct counter + struct object_counter { - // Specifically and glaringly-obviously marked 'signed' so that when - // COUNT mistakenly goes negative, we can track the patterns of - // deletions more easily. + // Specifically and glaringly-obviously marked 'signed' so that + // when COUNT mistakenly goes negative, we can track the patterns + // of deletions more easily. typedef signed int size_type; static size_type count; - counter() { ++count; } - counter (const counter&) { ++count; } - ~counter() { --count; } + object_counter() { ++count; } + object_counter (const object_counter&) { ++count; } + ~object_counter() { --count; } }; -#define assert_count(n) VERIFY(__gnu_test::counter::count == n) +#define assert_count(n) VERIFY(__gnu_test::object_counter::count == n) // A (static) class for counting copy constructors and possibly throwing an // exception on a desired count.