diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index d88bef0ca19..f5f792298c6 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,24 @@ +2005-09-01 Benjamin Kosnik + + * testsuite/lib/libstdc++.exp (check_v3_target_cxa_atexit): New. + * testsuite/lib/dg-options.exp (dg-require-cxa-atexit): New. + * testsuite/ext/mt_allocator/deallocate_local-6.cc: New. + * testsuite/ext/mt_allocator/deallocate_local-8.cc: New. + * testsuite/ext/mt_allocator/deallocate_local_thread-5.cc: New. + * testsuite/ext/mt_allocator/deallocate_local_thread-7.cc: New. + * docs/html/ext/mt_allocator.html: Add link to examples. + * testsuite/testsuite_allocator.h: Tweak. + * testsuite/ext/mt_allocator/deallocate_global-2.cc: Same. + * testsuite/ext/mt_allocator/deallocate_global-4.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_thread-1.cc: Same. + * testsuite/ext/mt_allocator/deallocate_local_thread-3.cc: Same. + * testsuite/ext/new_allocator/deallocate_global.cc: Same. + * testsuite/ext/new_allocator/deallocate_local.cc: Same. + 2005-08-31 Paolo Carlini Kaspar Fischer diff --git a/libstdc++-v3/docs/html/ext/mt_allocator.html b/libstdc++-v3/docs/html/ext/mt_allocator.html index 6c3c2700014..e91760e8b48 100644 --- a/libstdc++-v3/docs/html/ext/mt_allocator.html +++ b/libstdc++-v3/docs/html/ext/mt_allocator.html @@ -40,8 +40,8 @@ allocator"] is a fixed size (power of two) allocator that was initially developed specifically to suit the needs of multi threaded applications [hereinafter referred to as an MT application]. Over time -the allocator has evolved and been improved in many ways, one of the -being that it now also does a good job in single threaded applications +the allocator has evolved and been improved in many ways, in +particular it now also does a good job in single threaded applications [hereinafter referred to as a ST application]. (Note: In this document, when referring to single threaded applications this also includes applications that are compiled with gcc without thread @@ -67,13 +67,14 @@ the actual allocator.

The datum describing pools characteristics is -

-  template<bool _Thread>
-    class __pool
-
+
+   template<bool _Thread>
+     class __pool
+ 
This class is parametrized on thread support, and is explicitly specialized for both multiple threads (with bool==true) -and single threads (via bool==false.) +and single threads (via bool==false.) It is possible to +use a custom pool datum instead of the default class that is provided.

There are two distinct policy classes, each of which can be used @@ -280,9 +281,10 @@ release memory. Because of this, memory debugging programs like valgrind or purify may notice leaks: sorry about this inconvenience. Operating systems will reclaim allocated memory at program termination anyway. If sidestepping this kind of noise is -desired, there are two options: use an allocator, like -new_allocator that releases memory while debugging, or -use GLIBCXX_FORCE_NEW to bypass the allocator's internal pools.

+desired, there are three options: use an allocator, like +new_allocator that releases memory while debugging, use +GLIBCXX_FORCE_NEW to bypass the allocator's internal pools, or use a +custom pool datum that releases resources on destruction.

On systems with the function __cxa_atexit, the allocator can be forced to free all memory allocated before program @@ -297,7 +299,10 @@ practice, forcing deallocation can be tricky, as it requires the that uses it is fully constructed. For most (but not all) STL containers, this works, as an instance of the allocator is constructed as part of a container's constructor. However, this assumption is -implementation-specific, and subject to change. +implementation-specific, and subject to change. For an example of a +pool that frees memory, see the following + + example.

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 cbfdcd8cb0c..f04307d4f57 100644 --- a/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_global-2.cc +++ b/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_global-2.cc @@ -1,5 +1,5 @@ // -// Copyright (C) 2004 Free Software Foundation, Inc. +// Copyright (C) 2004, 2005 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 @@ -23,24 +23,24 @@ #include #include #include -#include static size_t count; struct count_check { - count_check() {} + count_check() { } ~count_check() { + // NB: __mt_allocator doesn't clean itself up. Thus, this will not + // be zero. if (count != 0) { - // NB: __mt_allocator doesn't clean itself up. Thus, this will - // not be zero. + //throw std::runtime_error("allocation/deallocation count isn't zero"); + printf("allocation/deallocation count is %zu \n", count); } } }; -// First. static count_check check; void* operator new(size_t size) throw(std::bad_alloc) @@ -59,11 +59,6 @@ void operator delete(void* p) throw() if (p == NULL) return; count--; - if (count == 0) - printf("All memory released \n"); - else - printf("%u allocations to be released \n", count); - free(p); } typedef std::string value_type; @@ -74,7 +69,6 @@ typedef __gnu_cxx::__mt_alloc allocator_type; typedef std::char_traits traits_type; typedef std::list list_type; -// Second. list_type l; int main() 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 fab6035f877..c586903783e 100644 --- a/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_global-4.cc +++ b/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_global-4.cc @@ -1,5 +1,5 @@ // -// Copyright (C) 2004 Free Software Foundation, Inc. +// Copyright (C) 2004, 2005 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 @@ -23,24 +23,24 @@ #include #include #include -#include static size_t count; struct count_check { - count_check() {} + count_check() { } ~count_check() { + // NB: __mt_allocator doesn't clean itself up. Thus, this will not + // be zero. if (count != 0) { - // NB: __mt_allocator doesn't clean itself up. Thus, this will - // not be zero. + //throw std::runtime_error("allocation/deallocation count isn't zero"); + printf("allocation/deallocation count is %zu \n", count); } } }; -// First. static count_check check; void* operator new(size_t size) throw(std::bad_alloc) @@ -59,11 +59,6 @@ void operator delete(void* p) throw() if (p == NULL) return; count--; - if (count == 0) - printf("All memory released \n"); - else - printf("%u allocations to be released \n", count); - free(p); } typedef std::string value_t; @@ -74,7 +69,6 @@ typedef __gnu_cxx::__mt_alloc allocator_type; typedef std::char_traits traits_type; typedef std::list list_type; -// Second. list_type l; int main() 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 be25c556ef5..aee49f822c4 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 @@ -1,5 +1,5 @@ // -// Copyright (C) 2004 Free Software Foundation, Inc. +// Copyright (C) 2004, 2005 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 @@ -23,24 +23,24 @@ #include #include #include -#include static size_t count; struct count_check { - count_check() {} + count_check() { } ~count_check() { + // NB: __mt_allocator doesn't clean itself up. Thus, this will not + // be zero. if (count != 0) { - // NB: __mt_allocator doesn't clean itself up. Thus, this will - // not be zero. + //throw std::runtime_error("allocation/deallocation count isn't zero"); + printf("allocation/deallocation count is %zu \n", count); } } }; -// First. static count_check check; void* operator new(size_t size) throw(std::bad_alloc) @@ -59,11 +59,6 @@ void operator delete(void* p) throw() if (p == NULL) return; count--; - if (count == 0) - printf("All memory released \n"); - else - printf("%u allocations to be released \n", count); - free(p); } typedef std::string value_type; @@ -74,7 +69,6 @@ typedef __gnu_cxx::__mt_alloc allocator_type; typedef std::char_traits traits_type; typedef std::list list_type; -// Second. list_type l; int main() 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 0d6dfc2f694..0f3174c71e0 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 @@ -1,5 +1,5 @@ // -// Copyright (C) 2004 Free Software Foundation, Inc. +// Copyright (C) 2004, 2005 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 @@ -23,24 +23,24 @@ #include #include #include -#include static size_t count; struct count_check { - count_check() {} + count_check() { } ~count_check() { + // NB: __mt_allocator doesn't clean itself up. Thus, this will not + // be zero. if (count != 0) { - // NB: __mt_allocator doesn't clean itself up. Thus, this will - // not be zero. + //throw std::runtime_error("allocation/deallocation count isn't zero"); + printf("allocation/deallocation count is %zu \n", count); } } }; -// First. static count_check check; void* operator new(size_t size) throw(std::bad_alloc) @@ -59,11 +59,6 @@ void operator delete(void* p) throw() if (p == NULL) return; count--; - if (count == 0) - printf("All memory released \n"); - else - printf("%u allocations to be released \n", count); - free(p); } typedef std::string value_type; @@ -74,7 +69,6 @@ typedef __gnu_cxx::__mt_alloc allocator_type; typedef std::char_traits traits_type; typedef std::list list_type; -// Second. list_type l; int main() 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 95df8440c38..40b30e3b442 100644 --- a/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_local-2.cc +++ b/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_local-2.cc @@ -1,5 +1,5 @@ // -// Copyright (C) 2004 Free Software Foundation, Inc. +// Copyright (C) 2004, 2005 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 @@ -22,19 +22,20 @@ #include #include #include -#include static size_t count; struct count_check { - count_check() {} + count_check() { } ~count_check() { + // NB: __mt_allocator doesn't clean itself up. Thus, this will not + // be zero. if (count != 0) { - // NB: __mt_allocator doesn't clean itself up. Thus, this will - // not be zero. + //throw std::runtime_error("allocation/deallocation count isn't zero"); + printf("allocation/deallocation count is %zu \n", count); } } }; @@ -57,11 +58,6 @@ void operator delete(void* p) throw() if (p == NULL) return; count--; - if (count == 0) - printf("All memory released \n"); - else - printf("%u allocations to be released \n", count); - free(p); } typedef char value_type; @@ -73,10 +69,7 @@ typedef std::basic_string string_type; int main() { - bool test __attribute__((unused)) = true; - { - string_type s; - s += "bayou bend"; - } + 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 4437845ba31..ef124bf687f 100644 --- a/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_local-4.cc +++ b/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_local-4.cc @@ -1,5 +1,5 @@ // -// Copyright (C) 2004 Free Software Foundation, Inc. +// Copyright (C) 2004, 2005 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 @@ -22,19 +22,20 @@ #include #include #include -#include static size_t count; struct count_check { - count_check() {} + count_check() { } ~count_check() { + // NB: __mt_allocator doesn't clean itself up. Thus, this will not + // be zero. if (count != 0) { - // NB: __mt_allocator doesn't clean itself up. Thus, this will - // not be zero. + printf("allocation/deallocation count is %zu \n", count); + //throw std::runtime_error("allocation/deallocation count isn't zero"); } } }; @@ -57,11 +58,6 @@ void operator delete(void* p) throw() if (p == NULL) return; count--; - if (count == 0) - printf("All memory released \n"); - else - printf("%u allocations to be released \n", count); - free(p); } typedef char value_type; @@ -74,10 +70,7 @@ typedef std::basic_string string_type; int main() { - bool test __attribute__((unused)) = true; - { - string_type s; - s += "bayou bend"; - } + 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 new file mode 100644 index 00000000000..66ad3063cce --- /dev/null +++ b/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_local-6.cc @@ -0,0 +1,86 @@ +// { dg-require-cxa-atexit "" } + +// Copyright (C) 2004, 2005 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 20.4.1.1 allocator members + +#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--; +} + +template + struct cleanup_pool : public __gnu_cxx::__pool + { + cleanup_pool() : __gnu_cxx::__pool() { } + + cleanup_pool(const __gnu_cxx::__pool_base::_Tune& t) + : __gnu_cxx::__pool(t) { } + + ~cleanup_pool() throw() { this->_M_destroy(); } + }; + + +typedef char value_type; +typedef std::char_traits traits_type; +typedef __gnu_cxx::__common_pool_policy policy_type; +typedef __gnu_cxx::__mt_alloc allocator_type; +typedef std::basic_string string_type; + +int main() +{ + 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 new file mode 100644 index 00000000000..49b6fdcbdd5 --- /dev/null +++ b/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_local-8.cc @@ -0,0 +1,87 @@ +// { dg-require-cxa-atexit "" } + +// Copyright (C) 2004, 2005 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 20.4.1.1 allocator members + +#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--; +} + +template + struct cleanup_pool : public __gnu_cxx::__pool + { + cleanup_pool() : __gnu_cxx::__pool() { } + + cleanup_pool(const __gnu_cxx::__pool_base::_Tune& t) + : __gnu_cxx::__pool(t) { } + + ~cleanup_pool() throw() { this->_M_destroy(); } + }; + +typedef char value_type; +typedef std::char_traits traits_type; +using __gnu_cxx::__pool; +using __gnu_cxx::__per_type_pool_policy; +typedef __per_type_pool_policy policy_type; +typedef __gnu_cxx::__mt_alloc allocator_type; +typedef std::basic_string string_type; + +int main() +{ + 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 a1a7c2390b0..445bf1901ee 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 @@ -1,5 +1,5 @@ // -// Copyright (C) 2004 Free Software Foundation, Inc. +// Copyright (C) 2004, 2005 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 @@ -22,19 +22,20 @@ #include #include #include -#include static size_t count; struct count_check { - count_check() {} + count_check() { } ~count_check() { + // NB: __mt_allocator doesn't clean itself up. Thus, this will not + // be zero. if (count != 0) { - // NB: __mt_allocator doesn't clean itself up. Thus, this will - // not be zero. + //throw std::runtime_error("allocation/deallocation count isn't zero"); + printf("allocation/deallocation count is %zu \n", count); } } }; @@ -57,11 +58,6 @@ void operator delete(void* p) throw() if (p == NULL) return; count--; - if (count == 0) - printf("All memory released \n"); - else - printf("%u allocations to be released \n", count); - free(p); } typedef char value_type; @@ -73,10 +69,7 @@ typedef std::basic_string string_type; int main() { - bool test __attribute__((unused)) = true; - { - string_type s; - s += "bayou bend"; - } + 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 8394218f879..3d923d6146b 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 @@ -1,5 +1,5 @@ // -// Copyright (C) 2004 Free Software Foundation, Inc. +// Copyright (C) 2004, 2005 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 @@ -22,19 +22,20 @@ #include #include #include -#include static size_t count; struct count_check { - count_check() {} + count_check() { } ~count_check() { + // NB: __mt_allocator doesn't clean itself up. Thus, this will not + // be zero. if (count != 0) { - // NB: __mt_allocator doesn't clean itself up. Thus, this will - // not be zero. + //throw std::runtime_error("allocation/deallocation count isn't zero"); + printf("allocation/deallocation count is %zu \n", count); } } }; @@ -57,11 +58,6 @@ void operator delete(void* p) throw() if (p == NULL) return; count--; - if (count == 0) - printf("All memory released \n"); - else - printf("%u allocations to be released \n", count); - free(p); } typedef char value_type; @@ -74,10 +70,7 @@ typedef std::basic_string string_type; int main() { - bool test __attribute__((unused)) = true; - { - string_type s; - s += "bayou bend"; - } + 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 new file mode 100644 index 00000000000..244bae02fa0 --- /dev/null +++ b/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_local_thread-5.cc @@ -0,0 +1,86 @@ +// { dg-require-cxa-atexit "" } + +// Copyright (C) 2004, 2005 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 20.4.1.1 allocator members + +#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--; +} + +template + struct cleanup_pool : public __gnu_cxx::__pool + { + cleanup_pool() : __gnu_cxx::__pool() { } + + cleanup_pool(const __gnu_cxx::__pool_base::_Tune& t) + : __gnu_cxx::__pool(t) { } + + ~cleanup_pool() throw() { this->_M_destroy(); } + }; + + +typedef char value_type; +typedef std::char_traits traits_type; +typedef __gnu_cxx::__common_pool_policy policy_type; +typedef __gnu_cxx::__mt_alloc allocator_type; +typedef std::basic_string string_type; + +int main() +{ + 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 new file mode 100644 index 00000000000..55ff20aa78f --- /dev/null +++ b/libstdc++-v3/testsuite/ext/mt_allocator/deallocate_local_thread-7.cc @@ -0,0 +1,87 @@ +// { dg-require-cxa-atexit "" } + +// Copyright (C) 2004, 2005 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 20.4.1.1 allocator members + +#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--; +} + +template + struct cleanup_pool : public __gnu_cxx::__pool + { + cleanup_pool() : __gnu_cxx::__pool() { } + + cleanup_pool(const __gnu_cxx::__pool_base::_Tune& t) + : __gnu_cxx::__pool(t) { } + + ~cleanup_pool() throw() { this->_M_destroy(); } + }; + +typedef char value_type; +typedef std::char_traits traits_type; +using __gnu_cxx::__pool; +using __gnu_cxx::__per_type_pool_policy; +typedef __per_type_pool_policy policy_type; +typedef __gnu_cxx::__mt_alloc allocator_type; +typedef std::basic_string string_type; + +int main() +{ + string_type s; + s += "bayou bend"; + 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 4a352705c9c..170737db3f4 100644 --- a/libstdc++-v3/testsuite/ext/new_allocator/deallocate_global.cc +++ b/libstdc++-v3/testsuite/ext/new_allocator/deallocate_global.cc @@ -1,5 +1,5 @@ // -// Copyright (C) 2004 Free Software Foundation, Inc. +// Copyright (C) 2004, 2005 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 @@ -22,17 +22,16 @@ #include #include #include -#include static size_t count; struct count_check { - count_check() {} + count_check() { } ~count_check() { if (count != 0) - throw std::runtime_error("count isn't zero"); + throw std::runtime_error("allocation/deallocation count isn't zero"); } }; @@ -54,11 +53,6 @@ void operator delete(void* p) throw() if (p == NULL) return; count--; - if (count == 0) - printf("All memory released \n"); - else - printf("%u allocations to be released \n", count); - free(p); } typedef char char_t; diff --git a/libstdc++-v3/testsuite/ext/new_allocator/deallocate_local.cc b/libstdc++-v3/testsuite/ext/new_allocator/deallocate_local.cc index e62e9eb1ca6..6512f2e8ed1 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 Free Software Foundation, Inc. +// Copyright (C) 2004, 2005 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 @@ -20,18 +20,30 @@ // 20.4.1.1 allocator members #include +#include #include -#include -static size_t alloc_cnt; +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) { printf("operator new is called \n"); void* p = malloc(size); if (p == NULL) throw std::bad_alloc(); - alloc_cnt++; + count++; return p; } @@ -40,12 +52,7 @@ 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("%u allocations to be released \n", alloc_cnt); - free(p); + count--; } typedef char char_t; @@ -55,11 +62,7 @@ typedef std::basic_string string_t; int main() { - bool test __attribute__((unused)) = true; - { - string_t s; - s += "bayou bend"; - } - VERIFY( alloc_cnt == 0 ); + string_t s; + s += "bayou bend"; return 0; } diff --git a/libstdc++-v3/testsuite/lib/dg-options.exp b/libstdc++-v3/testsuite/lib/dg-options.exp index d37711744dd..05d2ff38ba2 100644 --- a/libstdc++-v3/testsuite/lib/dg-options.exp +++ b/libstdc++-v3/testsuite/lib/dg-options.exp @@ -35,3 +35,12 @@ proc dg-require-namedlocale { args } { } return } + +proc dg-require-cxa-atexit { args } { + if { ![ check_v3_target_cxa_atexit ] } { + upvar dg-do-what dg-do-what + set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"] + return + } + return +} diff --git a/libstdc++-v3/testsuite/lib/libstdc++.exp b/libstdc++-v3/testsuite/lib/libstdc++.exp index b2a6f7c80b5..b757b5835b8 100644 --- a/libstdc++-v3/testsuite/lib/libstdc++.exp +++ b/libstdc++-v3/testsuite/lib/libstdc++.exp @@ -454,3 +454,86 @@ proc check_v3_target_namedlocale { } { } return $et_namedlocale_saved } + +proc check_v3_target_cxa_atexit { } { + global et_cxa_atexit + global et_cxa_atexit_target_name + global tool + + if { ![info exists et_cxa_atexit_target_name] } { + set et_cxa_atexit_target_name "" + } + + # If the target has changed since we set the cached value, clear it. + set current_target [current_target_name] + if { $current_target != $et_cxa_atexit_target_name } { + verbose "check_v3_target_cxa_atexit: `$et_cxa_atexit_target_name'" 2 + set et_cxa_atexit_target_name $current_target + if [info exists et_cxa_atexit] { + verbose "check_v3_target_cxa_atexit: removing cached result" 2 + unset et_cxa_atexit + } + } + + if [info exists et_cxa_atexit] { + verbose "check_v3_target_cxa_atexit: using cached result" 2 + } else { + set et_cxa_atexit 0 + + # Set up, compile, and execute a C++ test program that tries to use + # all the required named locales. + set src cxaatexit[pid].cc + set exe cxaatexit[pid].x + + set f [open $src "w"] + puts $f "#include " + puts $f "static unsigned int count;" + puts $f "struct X" + puts $f "{" + puts $f "X() { count = 1; }" + puts $f "~X()" + puts $f "{" + puts $f " if (count != 3)" + puts $f " exit(1);" + puts $f " count = 4;" + puts $f "}" + puts $f "};" + puts $f "void f()" + puts $f "{" + puts $f "static X x;" + puts $f "}" + puts $f "struct Y" + puts $f "{" + puts $f "Y() { f(); count = 2; }" + puts $f "~Y()" + puts $f "{" + puts $f "if (count != 2)" + puts $f " exit(1);" + puts $f "count = 3;" + puts $f "}" + puts $f "};" + puts $f "Y y;" + puts $f "int main()" + puts $f "{ return 0; }" + close $f + + set lines [v3_target_compile $src $exe executable ""] + file delete $src + + if [string match "" $lines] { + # No error message, compilation succeeded. + set result [${tool}_load "./$exe" "" ""] + set status [lindex $result 0] + remote_file build delete $exe + + verbose "check_v3_target_cxa_atexit: status is <$status>" 2 + + if { $status == "pass" } { + set et_cxa_atexit 1 + } + } else { + verbose "check_v3_target_cxa_atexit: compilation failed" 2 + } + } + return $et_cxa_atexit +} diff --git a/libstdc++-v3/testsuite/testsuite_allocator.h b/libstdc++-v3/testsuite/testsuite_allocator.h index b08ee6b62aa..f71a07927da 100644 --- a/libstdc++-v3/testsuite/testsuite_allocator.h +++ b/libstdc++-v3/testsuite/testsuite_allocator.h @@ -229,7 +229,6 @@ namespace __gnu_test } throw; } - }; // namespace __gnu_test #endif // _GLIBCXX_TESTSUITE_ALLOCATOR_H