2005-09-01 Benjamin Kosnik <bkoz@redhat.com>
authorbkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 1 Sep 2005 07:06:05 +0000 (07:06 +0000)
committerbkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 1 Sep 2005 07:06:05 +0000 (07:06 +0000)
        * 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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@103721 138bc75d-0d04-0410-961f-82ee72b054a4

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 d88bef0..f5f7922 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 6c3c270..e91760e 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 cbfdcd8..f04307d 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 fab6035..c586903 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 be25c55..aee49f8 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 0d6dfc2..0f3174c 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 95df844..40b30e3 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 4437845..ef124bf 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 a1a7c23..445bf19 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 8394218..3d923d6 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 4a35270..170737d 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 e62e9eb..6512f2e 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 d377117..05d2ff3 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 b2a6f7c..b757b58 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 b08ee6b..f71a079 100644 (file)
@@ -229,7 +229,6 @@ namespace __gnu_test
        }
       throw;
     }
-
 }; // namespace __gnu_test
 
 #endif // _GLIBCXX_TESTSUITE_ALLOCATOR_H