diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 81f88ffda31..f716244fe18 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,20 @@ +2004-10-29 Benjamin Kosnik + + * 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 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 00000000000..fa35f33afbd --- /dev/null +++ b/libstdc++-v3/testsuite/ext/array_allocator/check_delete.cc @@ -0,0 +1,61 @@ +// 2001-11-25 Phil Edwards +// +// 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 +#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)) ); +} + +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 2d15972f6a7..59789049298 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 #include +#include #include 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 array_type; typedef array_allocator allocator_type; array_type store; allocator_type a(&store); - return (__gnu_test::check_new(a) == false); + VERIFY( bool(__gnu_test::check_new(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 00000000000..25cf731cd2b --- /dev/null +++ b/libstdc++-v3/testsuite/ext/debug_allocator/check_delete.cc @@ -0,0 +1,59 @@ +// 2001-11-25 Phil Edwards +// +// 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 +#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()) ); +} + +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 04358f2d4a0..3fe45989076 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 #include #include +#include #include 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 > allocator_type; - return (__gnu_test::check_new() == false); + VERIFY( bool(__gnu_test::check_new()) ); } 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 00000000000..ea40e3c0803 --- /dev/null +++ b/libstdc++-v3/testsuite/ext/malloc_allocator/check_delete.cc @@ -0,0 +1,57 @@ +// 2001-11-25 Phil Edwards +// +// 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 +#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()) ); +} + +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 544839aaad7..e6e159ca510 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 #include +#include #include 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 allocator_type; - return (__gnu_test::check_new() == false); + VERIFY( bool(__gnu_test::check_new()) ); } 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 00000000000..81fde66bbc8 --- /dev/null +++ b/libstdc++-v3/testsuite/ext/mt_allocator/check_delete.cc @@ -0,0 +1,55 @@ +// 2001-11-25 Phil Edwards +// +// 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 +#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()) ); +} + +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 9e088214602..e3a08f33adb 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 #include +#include #include 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 allocator_type; - return (__gnu_test::check_new() == true); + VERIFY( bool(__gnu_test::check_new()) ); } 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 00000000000..49ce3addff0 --- /dev/null +++ b/libstdc++-v3/testsuite/ext/new_allocator/check_delete.cc @@ -0,0 +1,57 @@ +// 2001-11-25 Phil Edwards +// +// 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 +#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()) ); +} + +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 e2be5743fdb..39ab08e7d81 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 #include +#include #include 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 allocator_type; - return (__gnu_test::check_new() == true); + VERIFY( bool(__gnu_test::check_new()) ); } 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 00000000000..79ce85832e7 --- /dev/null +++ b/libstdc++-v3/testsuite/ext/pool_allocator/check_delete.cc @@ -0,0 +1,57 @@ +// 2001-11-25 Phil Edwards +// +// 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 +#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()) ); +} + +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 ba6c75118ee..be37b8658e3 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 #include +#include #include 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 allocator_type; - return (__gnu_test::check_new() == true); + VERIFY( bool(__gnu_test::check_new()) ); } int main() { - return test03(); + test01(); + return 0; } diff --git a/libstdc++-v3/testsuite/testsuite_allocator.h b/libstdc++-v3/testsuite/testsuite_allocator.h index a13df804ed3..7be830e83aa 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 + template 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 + 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; }