libstdc++.exp (check_v3_target_cxa_atexit): New.
authorBenjamin Kosnik <bkoz@redhat.com>
Thu, 1 Sep 2005 07:06:05 +0000 (07:06 +0000)
committerBenjamin Kosnik <bkoz@gcc.gnu.org>
Thu, 1 Sep 2005 07:06:05 +0000 (07:06 +0000)
2005-09-01  Benjamin Kosnik  <bkoz@redhat.com>

        * 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.

From-SVN: r103721

19 files changed:
libstdc++-v3/ChangeLog
libstdc++-v3/docs/html/ext/mt_allocator.html
libstdc++-v3/testsuite/ext/mt_allocator/deallocate_global-2.cc
libstdc++-v3/testsuite/ext/mt_allocator/deallocate_global-4.cc
libstdc++-v3/testsuite/ext/mt_allocator/deallocate_global_thread-1.cc
libstdc++-v3/testsuite/ext/mt_allocator/deallocate_global_thread-3.cc
libstdc++-v3/testsuite/ext/mt_allocator/deallocate_local-2.cc
libstdc++-v3/testsuite/ext/mt_allocator/deallocate_local-4.cc
libstdc++-v3/testsuite/ext/mt_allocator/deallocate_local-6.cc [new file with mode: 0644]
libstdc++-v3/testsuite/ext/mt_allocator/deallocate_local-8.cc [new file with mode: 0644]
libstdc++-v3/testsuite/ext/mt_allocator/deallocate_local_thread-1.cc
libstdc++-v3/testsuite/ext/mt_allocator/deallocate_local_thread-3.cc
libstdc++-v3/testsuite/ext/mt_allocator/deallocate_local_thread-5.cc [new file with mode: 0644]
libstdc++-v3/testsuite/ext/mt_allocator/deallocate_local_thread-7.cc [new file with mode: 0644]
libstdc++-v3/testsuite/ext/new_allocator/deallocate_global.cc
libstdc++-v3/testsuite/ext/new_allocator/deallocate_local.cc
libstdc++-v3/testsuite/lib/dg-options.exp
libstdc++-v3/testsuite/lib/libstdc++.exp
libstdc++-v3/testsuite/testsuite_allocator.h

index d88bef0ca193132731372c79ab02567bb41cb797..f5f792298c66e864d6fadda4ceae5d6093271154 100644 (file)
@@ -1,3 +1,24 @@
+2005-09-01  Benjamin Kosnik  <bkoz@redhat.com>
+
+        * 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  <pcarlini@suse.de>
            Kaspar Fischer <fischerk@inf.ethz.ch> 
 
index 6c3c27000143cbe4fb84224293ce4b72581353c9..e91760e8b4863af042742f61607b226794268772 100644 (file)
@@ -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.
 </p>
 
 <p>The datum describing pools characteristics is 
-<pre>
-  template&lt;bool _Thread&gt;
-    class __pool
-</pre>
+ <pre>
+   template&lt;bool _Thread&gt;
+     class __pool
+ </pre>
 This class is parametrized on thread support, and is explicitly
 specialized for both multiple threads (with <code>bool==true</code>)
-and single threads (via <code>bool==false</code>.)
+and single threads (via <code>bool==false</code>.) It is possible to
+use a custom pool datum instead of the default class that is provided.
 </p>
 
 <p> 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
-<code>new_allocator</code> that releases memory while debugging, or
-use GLIBCXX_FORCE_NEW to bypass the allocator's internal pools.</p>
+desired, there are three options: use an allocator, like
+<code>new_allocator</code> 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.</p>
 
 <p>On systems with the function <code>__cxa_atexit</code>, 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
+    <a href="http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc%2b%2b-v3/testsuite/ext/mt_allocator/deallocate_local-6.cc"> 
+    example.</a>
 </p>
 
 <h3 class="left">
index cbfdcd8cb0c96539b38bf62ed13a4c3c75539a0a..f04307d4f57b8cf20f3c556081f46b972fa892f2 100644 (file)
@@ -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
 #include <string>
 #include <stdexcept>
 #include <ext/mt_allocator.h>
-#include <testsuite_hooks.h>
 
 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<value_type, policy_type> allocator_type;
 typedef std::char_traits<value_type> traits_type;
 typedef std::list<value_type, allocator_type> list_type;
 
-// Second.
 list_type l;
 
 int main()
index fab6035f87751c7f222c529117db3afdd42a60c3..c586903783e4f1ac68bdfaa46943cdcfb795f6e7 100644 (file)
@@ -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
 #include <string>
 #include <stdexcept>
 #include <ext/mt_allocator.h>
-#include <testsuite_hooks.h>
 
 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<value_t, policy_type> allocator_type;
 typedef std::char_traits<value_t> traits_type;
 typedef std::list<value_t, allocator_type> list_type;
 
-// Second.
 list_type l;
 
 int main()
index be25c556ef5c12523fe4bd8ad55ded5ea2276099..aee49f822c473aa91218879ab2413320a8b23e78 100644 (file)
@@ -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
 #include <string>
 #include <stdexcept>
 #include <ext/mt_allocator.h>
-#include <testsuite_hooks.h>
 
 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<value_type, policy_type> allocator_type;
 typedef std::char_traits<value_type> traits_type;
 typedef std::list<value_type, allocator_type> list_type;
 
-// Second.
 list_type l;
 
 int main()
index 0d6dfc2f694e98bc540b94f45995cc9f80c076d0..0f3174c71e0a0c53ef030b1a9e2330df51afbb47 100644 (file)
@@ -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
 #include <string>
 #include <stdexcept>
 #include <ext/mt_allocator.h>
-#include <testsuite_hooks.h>
 
 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<value_type, policy_type> allocator_type;
 typedef std::char_traits<value_type> traits_type;
 typedef std::list<value_type, allocator_type> list_type;
 
-// Second.
 list_type l;
 
 int main()
index 95df8440c3899b7b4ee0817ac529a8fa46a7f815..40b30e3b442b9ddc3f2374b31629c40d8d1f9cdf 100644 (file)
@@ -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
 #include <string>
 #include <stdexcept>
 #include <ext/mt_allocator.h>
-#include <testsuite_hooks.h>
 
 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<value_type, traits_type, allocator_type> string_type;
 
 int main()
 {
-  bool test __attribute__((unused)) = true;
-  {
-    string_type s;
-    s += "bayou bend";
-  }
+  string_type s;
+  s += "bayou bend";
   return 0;
 }
index 4437845ba318fa7ab9c9db3a4045ecc8ac0d0d3d..ef124bf687fbbbf3bf185cf54d6324f701de1cdb 100644 (file)
@@ -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
 #include <string>
 #include <stdexcept>
 #include <ext/mt_allocator.h>
-#include <testsuite_hooks.h>
 
 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<value_type, traits_type, allocator_type> 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 (file)
index 0000000..66ad306
--- /dev/null
@@ -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 <string>
+#include <stdexcept>
+#include <ext/mt_allocator.h>
+
+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<bool _Thread>
+  struct cleanup_pool : public __gnu_cxx::__pool<false>
+  {
+    cleanup_pool() : __gnu_cxx::__pool<false>() { }
+
+    cleanup_pool(const __gnu_cxx::__pool_base::_Tune& t) 
+    : __gnu_cxx::__pool<false>(t) { }
+
+    ~cleanup_pool() throw() { this->_M_destroy(); }
+  };
+
+
+typedef char value_type;
+typedef std::char_traits<value_type> traits_type;
+typedef __gnu_cxx::__common_pool_policy<cleanup_pool, false> policy_type;
+typedef __gnu_cxx::__mt_alloc<value_type, policy_type> allocator_type;
+typedef std::basic_string<value_type, traits_type, allocator_type> 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 (file)
index 0000000..49b6fdc
--- /dev/null
@@ -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 <string>
+#include <stdexcept>
+#include <ext/mt_allocator.h>
+
+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<bool _Thread>
+  struct cleanup_pool : public __gnu_cxx::__pool<false>
+  {
+    cleanup_pool() : __gnu_cxx::__pool<false>() { }
+
+    cleanup_pool(const __gnu_cxx::__pool_base::_Tune& t) 
+    : __gnu_cxx::__pool<false>(t) { }
+
+    ~cleanup_pool() throw() { this->_M_destroy(); }
+  };
+
+typedef char value_type;
+typedef std::char_traits<value_type> traits_type;
+using __gnu_cxx::__pool;
+using __gnu_cxx::__per_type_pool_policy;
+typedef __per_type_pool_policy<value_type, cleanup_pool, false> policy_type;
+typedef __gnu_cxx::__mt_alloc<value_type, policy_type> allocator_type;
+typedef std::basic_string<value_type, traits_type, allocator_type> string_type;
+
+int main()
+{
+  string_type s;
+  s += "bayou bend";
+  return 0;
+}
index a1a7c2390b05557e851a2a008eaeb1d1c36f63e7..445bf1901ee151d53de395d594042b569060da35 100644 (file)
@@ -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
 #include <string>
 #include <stdexcept>
 #include <ext/mt_allocator.h>
-#include <testsuite_hooks.h>
 
 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<value_type, traits_type, allocator_type> string_type;
 
 int main()
 {
-  bool test __attribute__((unused)) = true;
-  {
-    string_type s;
-    s += "bayou bend";
-  }
+  string_type s;
+  s += "bayou bend";
   return 0;
 }
index 8394218f8790ebfb87cda17705fee9ade9fae522..3d923d6146b0b02cb6e27cda93b77d0f8fa4f0f7 100644 (file)
@@ -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
 #include <string>
 #include <stdexcept>
 #include <ext/mt_allocator.h>
-#include <testsuite_hooks.h>
 
 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<value_type, traits_type, allocator_type> 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 (file)
index 0000000..244bae0
--- /dev/null
@@ -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 <string>
+#include <stdexcept>
+#include <ext/mt_allocator.h>
+
+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<bool _Thread>
+  struct cleanup_pool : public __gnu_cxx::__pool<true>
+  {
+    cleanup_pool() : __gnu_cxx::__pool<true>() { }
+
+    cleanup_pool(const __gnu_cxx::__pool_base::_Tune& t) 
+    : __gnu_cxx::__pool<true>(t) { }
+
+    ~cleanup_pool() throw() { this->_M_destroy(); }
+  };
+
+
+typedef char value_type;
+typedef std::char_traits<value_type> traits_type;
+typedef __gnu_cxx::__common_pool_policy<cleanup_pool, true> policy_type;
+typedef __gnu_cxx::__mt_alloc<value_type, policy_type> allocator_type;
+typedef std::basic_string<value_type, traits_type, allocator_type> 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 (file)
index 0000000..55ff20a
--- /dev/null
@@ -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 <string>
+#include <stdexcept>
+#include <ext/mt_allocator.h>
+
+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<bool _Thread>
+  struct cleanup_pool : public __gnu_cxx::__pool<true>
+  {
+    cleanup_pool() : __gnu_cxx::__pool<true>() { }
+
+    cleanup_pool(const __gnu_cxx::__pool_base::_Tune& t) 
+    : __gnu_cxx::__pool<true>(t) { }
+
+    ~cleanup_pool() throw() { this->_M_destroy(); }
+  };
+
+typedef char value_type;
+typedef std::char_traits<value_type> traits_type;
+using __gnu_cxx::__pool;
+using __gnu_cxx::__per_type_pool_policy;
+typedef __per_type_pool_policy<value_type, cleanup_pool, true> policy_type;
+typedef __gnu_cxx::__mt_alloc<value_type, policy_type> allocator_type;
+typedef std::basic_string<value_type, traits_type, allocator_type> string_type;
+
+int main()
+{
+  string_type s;
+  s += "bayou bend";
+  return 0;
+}
index 4a352705c9cdead76e27a423beb2a4d1fad24147..170737db3f4fa2fdfbe9cca50b531748d0300ba4 100644 (file)
@@ -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
 #include <string>
 #include <stdexcept>
 #include <ext/new_allocator.h>
-#include <testsuite_hooks.h>
 
 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;
index e62e9eb1ca6ae47b25644c4fb4d7961351265272..6512f2e8ed11ebd67bd6ede11ff25db301d87eb1 100644 (file)
@@ -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.4.1.1 allocator members
 
 #include <string>
+#include <stdexcept>
 #include <ext/new_allocator.h>
-#include <testsuite_hooks.h>
 
-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<char_t, traits_t, allocator_t> 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;
 }
index d37711744dd96a250b07dd7cb372d92521269a61..05d2ff38ba2a6537aa8859804ddf3bf53c36ce3c 100644 (file)
@@ -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
+}
index b2a6f7c80b5f964434bc1c8008659eb22fc7dae2..b757b5835b87674eaca8b0c0a4a7599fac504910 100644 (file)
@@ -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 <stdlib.h>"
+       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
+}
index b08ee6b62aa5a6e19f83f333d4d1375ff678a9f3..f71a07927dab1084d4cd7bbd4cb90cec234ea580 100644 (file)
@@ -229,7 +229,6 @@ namespace __gnu_test
        }
       throw;
     }
-
 }; // namespace __gnu_test
 
 #endif // _GLIBCXX_TESTSUITE_ALLOCATOR_H