diff options
author | Benjamin Kosnik <bkoz@redhat.com> | 2004-10-29 21:03:07 +0000 |
---|---|---|
committer | Benjamin Kosnik <bkoz@gcc.gnu.org> | 2004-10-29 21:03:07 +0000 |
commit | a53f986f9139c883ba0ae6eb1c39f8b15f59d693 (patch) | |
tree | b03f7587a49d63a83a5aa7c190af64d53825a220 | |
parent | bd004fefff18c7219c6654a4ed681ee47cd5c8d3 (diff) | |
download | gcc-a53f986f9139c883ba0ae6eb1c39f8b15f59d693.zip gcc-a53f986f9139c883ba0ae6eb1c39f8b15f59d693.tar.gz gcc-a53f986f9139c883ba0ae6eb1c39f8b15f59d693.tar.bz2 |
testsuite_allocator.h (check_delete): New.
2004-10-29 Benjamin Kosnik <bkoz@redhat.com>
* testsuite/testsuite_allocator.h (check_delete): New.
(check_new): Simplify.
* testsuite/ext/array_allocator/check_delete.cc: New.
* testsuite/ext/array_allocator/check_new.cc: Simplify.
* testsuite/ext/debug_allocator/check_delete.cc: New.
* testsuite/ext/debug_allocator/check_new.cc: Simplify.
* testsuite/ext/malloc_allocator/check_delete.cc: New.
* testsuite/ext/malloc_allocator/check_new.cc: Simplify.
* testsuite/ext/mt_allocator/check_delete.cc: New.
* testsuite/ext/mt_allocator/check_new.cc: Simplify.
* testsuite/ext/new_allocator/check_delete.cc: New.
* testsuite/ext/new_allocator/check_new.cc: Simplify.
* testsuite/ext/pool_allocator/check_delete.cc: New.
* testsuite/ext/pool_allocator/check_new.cc: Simplify.
From-SVN: r89850
14 files changed, 416 insertions, 36 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 81f88ff..f716244 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,20 @@ +2004-10-29 Benjamin Kosnik <bkoz@redhat.com> + + * testsuite/testsuite_allocator.h (check_delete): New. + (check_new): Simplify. + * testsuite/ext/array_allocator/check_delete.cc: New. + * testsuite/ext/array_allocator/check_new.cc: Simplify. + * testsuite/ext/debug_allocator/check_delete.cc: New. + * testsuite/ext/debug_allocator/check_new.cc: Simplify. + * testsuite/ext/malloc_allocator/check_delete.cc: New. + * testsuite/ext/malloc_allocator/check_new.cc: Simplify. + * testsuite/ext/mt_allocator/check_delete.cc: New. + * testsuite/ext/mt_allocator/check_new.cc: Simplify. + * testsuite/ext/new_allocator/check_delete.cc: New. + * testsuite/ext/new_allocator/check_new.cc: Simplify. + * testsuite/ext/pool_allocator/check_delete.cc: New. + * testsuite/ext/pool_allocator/check_new.cc: Simplify. + 2004-10-28 Chris Jefferson <chris@bubblescope.net> PR libstdc++/18159 diff --git a/libstdc++-v3/testsuite/ext/array_allocator/check_delete.cc b/libstdc++-v3/testsuite/ext/array_allocator/check_delete.cc new file mode 100644 index 0000000..fa35f33 --- /dev/null +++ b/libstdc++-v3/testsuite/ext/array_allocator/check_delete.cc @@ -0,0 +1,61 @@ +// 2001-11-25 Phil Edwards <pme@gcc.gnu.org> +// +// Copyright (C) 2001, 2003, 2004 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 20.4.1.1 allocator members + +#include <cstdlib> +#include <ext/array_allocator.h> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +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<value_type, 15> array_type; + typedef array_allocator<value_type, array_type> allocator_type; + array_type store; + allocator_type a(&store); + VERIFY( bool(__gnu_test::check_delete<allocator_type, false>(a)) ); +} + +int main() +{ + test01(); + 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 2d15972..5978904 100644 --- a/libstdc++-v3/testsuite/ext/array_allocator/check_new.cc +++ b/libstdc++-v3/testsuite/ext/array_allocator/check_new.cc @@ -22,6 +22,7 @@ #include <cstdlib> #include <ext/array_allocator.h> +#include <testsuite_hooks.h> #include <testsuite_allocator.h> using __gnu_cxx::array_allocator; @@ -30,7 +31,6 @@ void* operator new(std::size_t n) throw(std::bad_alloc) { new_called = true; - requested = n; return std::malloc(n); } @@ -42,18 +42,20 @@ operator delete(void *v) throw() } // These just help tracking down error messages. -bool test01() +void test01() { + bool test __attribute__((unused)) = true; typedef unsigned int value_type; typedef std::tr1::array<value_type, 15> array_type; typedef array_allocator<value_type, array_type> allocator_type; array_type store; allocator_type a(&store); - return (__gnu_test::check_new<allocator_type, false>(a) == false); + VERIFY( bool(__gnu_test::check_new<allocator_type, false>(a)) ); } int main() { - return test01(); + test01(); + return 0; } diff --git a/libstdc++-v3/testsuite/ext/debug_allocator/check_delete.cc b/libstdc++-v3/testsuite/ext/debug_allocator/check_delete.cc new file mode 100644 index 0000000..25cf731 --- /dev/null +++ b/libstdc++-v3/testsuite/ext/debug_allocator/check_delete.cc @@ -0,0 +1,59 @@ +// 2001-11-25 Phil Edwards <pme@gcc.gnu.org> +// +// Copyright (C) 2001, 2003, 2004 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 20.4.1.1 allocator members + +#include <cstdlib> +#include <ext/debug_allocator.h> +#include <ext/malloc_allocator.h> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +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<malloc_allocator<unsigned int> > allocator_type; + VERIFY( bool(__gnu_test::check_delete<allocator_type, false>()) ); +} + +int main() +{ + test01(); + 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 04358f2..3fe4598 100644 --- a/libstdc++-v3/testsuite/ext/debug_allocator/check_new.cc +++ b/libstdc++-v3/testsuite/ext/debug_allocator/check_new.cc @@ -23,6 +23,7 @@ #include <cstdlib> #include <ext/debug_allocator.h> #include <ext/malloc_allocator.h> +#include <testsuite_hooks.h> #include <testsuite_allocator.h> using __gnu_cxx::malloc_allocator; @@ -32,7 +33,6 @@ void* operator new(std::size_t n) throw(std::bad_alloc) { new_called = true; - requested = n; return std::malloc(n); } @@ -43,14 +43,17 @@ operator delete(void *v) throw() return std::free(v); } -bool test02() +// These just help tracking down error messages. +void test01() { + bool test __attribute__((unused)) = true; typedef debug_allocator<malloc_allocator<unsigned int> > allocator_type; - return (__gnu_test::check_new<allocator_type, false>() == false); + VERIFY( bool(__gnu_test::check_new<allocator_type, false>()) ); } int main() { - return test02(); + test01(); + return 0; } diff --git a/libstdc++-v3/testsuite/ext/malloc_allocator/check_delete.cc b/libstdc++-v3/testsuite/ext/malloc_allocator/check_delete.cc new file mode 100644 index 0000000..ea40e3c --- /dev/null +++ b/libstdc++-v3/testsuite/ext/malloc_allocator/check_delete.cc @@ -0,0 +1,57 @@ +// 2001-11-25 Phil Edwards <pme@gcc.gnu.org> +// +// Copyright (C) 2001, 2003, 2004 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 20.4.1.1 allocator members + +#include <cstdlib> +#include <ext/malloc_allocator.h> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +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<unsigned int> allocator_type; + VERIFY( bool(__gnu_test::check_delete<allocator_type, false>()) ); +} + +int main() +{ + test01(); + 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 544839a..e6e159c 100644 --- a/libstdc++-v3/testsuite/ext/malloc_allocator/check_new.cc +++ b/libstdc++-v3/testsuite/ext/malloc_allocator/check_new.cc @@ -22,6 +22,7 @@ #include <cstdlib> #include <ext/malloc_allocator.h> +#include <testsuite_hooks.h> #include <testsuite_allocator.h> using __gnu_cxx::malloc_allocator; @@ -30,7 +31,6 @@ void* operator new(std::size_t n) throw(std::bad_alloc) { new_called = true; - requested = n; return std::malloc(n); } @@ -42,14 +42,16 @@ operator delete(void *v) throw() } // These just help tracking down error messages. -bool test01() +void test01() { + bool test __attribute__((unused)) = true; typedef malloc_allocator<unsigned int> allocator_type; - return (__gnu_test::check_new<allocator_type, false>() == false); + VERIFY( bool(__gnu_test::check_new<allocator_type, false>()) ); } int main() { - return test01(); + test01(); + return 0; } diff --git a/libstdc++-v3/testsuite/ext/mt_allocator/check_delete.cc b/libstdc++-v3/testsuite/ext/mt_allocator/check_delete.cc new file mode 100644 index 0000000..81fde66 --- /dev/null +++ b/libstdc++-v3/testsuite/ext/mt_allocator/check_delete.cc @@ -0,0 +1,55 @@ +// 2001-11-25 Phil Edwards <pme@gcc.gnu.org> +// +// Copyright (C) 2001, 2003, 2004 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 20.4.1.1 allocator members + +#include <cstdlib> +#include <ext/mt_allocator.h> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +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<unsigned int> allocator_type; + VERIFY( bool(__gnu_test::check_delete<allocator_type, false>()) ); +} + +int main() +{ + test01(); + 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 9e08821..e3a08f3 100644 --- a/libstdc++-v3/testsuite/ext/mt_allocator/check_new.cc +++ b/libstdc++-v3/testsuite/ext/mt_allocator/check_new.cc @@ -22,6 +22,7 @@ #include <cstdlib> #include <ext/mt_allocator.h> +#include <testsuite_hooks.h> #include <testsuite_allocator.h> using __gnu_cxx::__mt_alloc; @@ -30,25 +31,26 @@ void* operator new(std::size_t n) throw(std::bad_alloc) { new_called = true; - requested = n; return std::malloc(n); } void -operator delete(void *v) throw() +operator delete(void* v) throw() { delete_called = true; return std::free(v); } -bool test03() +void test01() { + // Uses new but delete only optionally. + bool test __attribute__((unused)) = true; typedef __mt_alloc<unsigned int> allocator_type; - return (__gnu_test::check_new<allocator_type, true>() == true); + VERIFY( bool(__gnu_test::check_new<allocator_type, true>()) ); } int main() { - return test03(); + test01(); + return 0; } - diff --git a/libstdc++-v3/testsuite/ext/new_allocator/check_delete.cc b/libstdc++-v3/testsuite/ext/new_allocator/check_delete.cc new file mode 100644 index 0000000..49ce3ad --- /dev/null +++ b/libstdc++-v3/testsuite/ext/new_allocator/check_delete.cc @@ -0,0 +1,57 @@ +// 2001-11-25 Phil Edwards <pme@gcc.gnu.org> +// +// Copyright (C) 2001, 2003, 2004 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 20.4.1.1 allocator members + +#include <cstdlib> +#include <ext/new_allocator.h> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +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<unsigned int> allocator_type; + VERIFY( bool(__gnu_test::check_delete<allocator_type, true>()) ); +} + +int main() +{ + test01(); + 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 e2be574..39ab08e 100644 --- a/libstdc++-v3/testsuite/ext/new_allocator/check_new.cc +++ b/libstdc++-v3/testsuite/ext/new_allocator/check_new.cc @@ -22,6 +22,7 @@ #include <cstdlib> #include <ext/new_allocator.h> +#include <testsuite_hooks.h> #include <testsuite_allocator.h> using __gnu_cxx::new_allocator; @@ -30,7 +31,6 @@ void* operator new(std::size_t n) throw(std::bad_alloc) { new_called = true; - requested = n; return std::malloc(n); } @@ -42,14 +42,16 @@ operator delete(void *v) throw() } // These just help tracking down error messages. -bool test01() +void test01() { + bool test __attribute__((unused)) = true; typedef new_allocator<unsigned int> allocator_type; - return (__gnu_test::check_new<allocator_type, true>() == true); + VERIFY( bool(__gnu_test::check_new<allocator_type, true>()) ); } int main() { - return test01(); + test01(); + return 0; } diff --git a/libstdc++-v3/testsuite/ext/pool_allocator/check_delete.cc b/libstdc++-v3/testsuite/ext/pool_allocator/check_delete.cc new file mode 100644 index 0000000..79ce858 --- /dev/null +++ b/libstdc++-v3/testsuite/ext/pool_allocator/check_delete.cc @@ -0,0 +1,57 @@ +// 2001-11-25 Phil Edwards <pme@gcc.gnu.org> +// +// Copyright (C) 2001, 2003, 2004 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 20.4.1.1 allocator members + +#include <cstdlib> +#include <ext/pool_allocator.h> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +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<unsigned int> allocator_type; + VERIFY( bool(__gnu_test::check_delete<allocator_type, false>()) ); +} + +int main() +{ + test01(); + 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 ba6c751..be37b86 100644 --- a/libstdc++-v3/testsuite/ext/pool_allocator/check_new.cc +++ b/libstdc++-v3/testsuite/ext/pool_allocator/check_new.cc @@ -22,6 +22,7 @@ #include <cstdlib> #include <ext/pool_allocator.h> +#include <testsuite_hooks.h> #include <testsuite_allocator.h> using __gnu_cxx::__pool_alloc; @@ -30,7 +31,6 @@ void* operator new(std::size_t n) throw(std::bad_alloc) { new_called = true; - requested = n; return std::malloc(n); } @@ -41,14 +41,16 @@ operator delete(void *v) throw() return std::free(v); } -bool test03() +void test01() { + bool test __attribute__((unused)) = true; typedef __pool_alloc<unsigned int> allocator_type; - return (__gnu_test::check_new<allocator_type, true>() == true); + VERIFY( bool(__gnu_test::check_new<allocator_type, true>()) ); } int main() { - return test03(); + test01(); + return 0; } diff --git a/libstdc++-v3/testsuite/testsuite_allocator.h b/libstdc++-v3/testsuite/testsuite_allocator.h index a13df80..7be830e 100644 --- a/libstdc++-v3/testsuite/testsuite_allocator.h +++ b/libstdc++-v3/testsuite/testsuite_allocator.h @@ -40,9 +40,8 @@ namespace { - bool new_called = false; - bool delete_called = false; - std::size_t requested = 0; + bool new_called = false; + bool delete_called = false; }; namespace __gnu_test @@ -180,19 +179,24 @@ namespace __gnu_test bool check_construct_destroy(const char* tag, int expected_c, int expected_d); - template<typename Alloc, bool uses_global_new_and_delete> + template<typename Alloc, bool uses_global_new> bool check_new(Alloc a = Alloc()) { bool test __attribute__((unused)) = true; typename Alloc::pointer p = a.allocate(10); - if (uses_global_new_and_delete) - test &= ( requested >= (10 * 15 * sizeof(long)) ); - - test &= ( new_called == uses_global_new_and_delete ); + test &= ( new_called == uses_global_new ); + return test; + } + + template<typename Alloc, bool uses_global_delete> + 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_new_and_delete ); - + test &= ( delete_called == uses_global_delete ); return test; } |