OSDN Git Service

2009-05-28 Benjamin Kosnik <bkoz@redhat.com>
authorbkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 28 May 2009 00:17:00 +0000 (00:17 +0000)
committerbkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 28 May 2009 00:17:00 +0000 (00:17 +0000)
* testsuite/util/testsuite_allocator.h (check_new, check_delete): Move
to ...
* testsuite/util/replacement_memory_operators.h: ...here. New.
* testsuite/util/testsuite_hooks.h (counter): To object_counter.
* testsuite/util/testsuite_hooks.cc: Same.

* testsuite/ext/mt_allocator/deallocate_local_thread-1.cc: Use
replacement_memory_operators.h.
* testsuite/ext/mt_allocator/deallocate_local_thread-3.cc: Same.
* testsuite/ext/mt_allocator/check_delete.cc: Same.
* testsuite/ext/mt_allocator/deallocate_local_thread-5.cc: Same.
* testsuite/ext/mt_allocator/deallocate_local_thread-7.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-6.cc: Same.
* testsuite/ext/mt_allocator/deallocate_local-8.cc: Same.
* testsuite/ext/mt_allocator/deallocate_global-2.cc: Same.
* testsuite/ext/mt_allocator/deallocate_global-4.cc: Same.
* testsuite/ext/mt_allocator/check_new.cc: Same.
* testsuite/ext/debug_allocator/check_delete.cc: Same.
* testsuite/ext/debug_allocator/check_new.cc: Same.
* testsuite/ext/new_allocator/deallocate_global.cc: Same.
* testsuite/ext/new_allocator/check_delete.cc: Same.
* testsuite/ext/new_allocator/check_new.cc: Same.
* testsuite/ext/new_allocator/deallocate_local.cc: Same.
* testsuite/ext/throw_allocator/deallocate_global.cc: Same.
* testsuite/ext/throw_allocator/check_delete.cc: Same.
* testsuite/ext/throw_allocator/check_new.cc: Same.
* testsuite/ext/throw_allocator/deallocate_local.cc: Same.
* testsuite/ext/malloc_allocator/deallocate_global.cc: Same.
* testsuite/ext/malloc_allocator/check_delete.cc: Same.
* testsuite/ext/malloc_allocator/check_new.cc: Same.
* testsuite/ext/malloc_allocator/deallocate_local.cc: Same.
* testsuite/ext/pool_allocator/check_delete.cc: Same.
* testsuite/ext/pool_allocator/check_new.cc: Same.
* testsuite/ext/bitmap_allocator/check_delete.cc: Same.
* testsuite/ext/bitmap_allocator/check_new.cc: Same.
* testsuite/ext/array_allocator/check_delete.cc: Same.
* testsuite/ext/array_allocator/check_new.cc: Same.
* testsuite/23_containers/deque/cons/1.cc: Same.
* testsuite/23_containers/deque/cons/2.cc: Same.

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

41 files changed:
libstdc++-v3/ChangeLog
libstdc++-v3/testsuite/23_containers/deque/cons/1.cc
libstdc++-v3/testsuite/23_containers/deque/cons/2.cc
libstdc++-v3/testsuite/ext/array_allocator/check_delete.cc
libstdc++-v3/testsuite/ext/array_allocator/check_new.cc
libstdc++-v3/testsuite/ext/bitmap_allocator/check_delete.cc
libstdc++-v3/testsuite/ext/bitmap_allocator/check_new.cc
libstdc++-v3/testsuite/ext/debug_allocator/check_delete.cc
libstdc++-v3/testsuite/ext/debug_allocator/check_new.cc
libstdc++-v3/testsuite/ext/malloc_allocator/check_delete.cc
libstdc++-v3/testsuite/ext/malloc_allocator/check_new.cc
libstdc++-v3/testsuite/ext/malloc_allocator/deallocate_global.cc
libstdc++-v3/testsuite/ext/malloc_allocator/deallocate_local.cc
libstdc++-v3/testsuite/ext/mt_allocator/check_delete.cc
libstdc++-v3/testsuite/ext/mt_allocator/check_new.cc
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
libstdc++-v3/testsuite/ext/mt_allocator/deallocate_local-8.cc
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
libstdc++-v3/testsuite/ext/mt_allocator/deallocate_local_thread-7.cc
libstdc++-v3/testsuite/ext/new_allocator/check_delete.cc
libstdc++-v3/testsuite/ext/new_allocator/check_new.cc
libstdc++-v3/testsuite/ext/new_allocator/deallocate_global.cc
libstdc++-v3/testsuite/ext/new_allocator/deallocate_local.cc
libstdc++-v3/testsuite/ext/pool_allocator/check_delete.cc
libstdc++-v3/testsuite/ext/pool_allocator/check_new.cc
libstdc++-v3/testsuite/ext/throw_allocator/check_delete.cc
libstdc++-v3/testsuite/ext/throw_allocator/check_new.cc
libstdc++-v3/testsuite/ext/throw_allocator/deallocate_global.cc
libstdc++-v3/testsuite/ext/throw_allocator/deallocate_local.cc
libstdc++-v3/testsuite/util/replacement_memory_operators.h [new file with mode: 0644]
libstdc++-v3/testsuite/util/testsuite_allocator.h
libstdc++-v3/testsuite/util/testsuite_hooks.cc
libstdc++-v3/testsuite/util/testsuite_hooks.h

index c7011b0..fc1fb0d 100644 (file)
@@ -1,3 +1,49 @@
+2009-05-28  Benjamin Kosnik  <bkoz@redhat.com>
+
+       * testsuite/util/testsuite_allocator.h (check_new, check_delete): Move
+       to ...
+       * testsuite/util/replacement_memory_operators.h: ...here. New.
+       * testsuite/util/testsuite_hooks.h (counter): To object_counter.
+       * testsuite/util/testsuite_hooks.cc: Same.
+
+       * testsuite/ext/mt_allocator/deallocate_local_thread-1.cc: Use
+       replacement_memory_operators.h.
+       * testsuite/ext/mt_allocator/deallocate_local_thread-3.cc: Same.
+       * testsuite/ext/mt_allocator/check_delete.cc: Same.
+       * testsuite/ext/mt_allocator/deallocate_local_thread-5.cc: Same.
+       * testsuite/ext/mt_allocator/deallocate_local_thread-7.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-6.cc: Same.
+       * testsuite/ext/mt_allocator/deallocate_local-8.cc: Same.
+       * testsuite/ext/mt_allocator/deallocate_global-2.cc: Same.
+       * testsuite/ext/mt_allocator/deallocate_global-4.cc: Same.
+       * testsuite/ext/mt_allocator/check_new.cc: Same.
+       * testsuite/ext/debug_allocator/check_delete.cc: Same.
+       * testsuite/ext/debug_allocator/check_new.cc: Same.
+       * testsuite/ext/new_allocator/deallocate_global.cc: Same.
+       * testsuite/ext/new_allocator/check_delete.cc: Same.
+       * testsuite/ext/new_allocator/check_new.cc: Same.
+       * testsuite/ext/new_allocator/deallocate_local.cc: Same.
+       * testsuite/ext/throw_allocator/deallocate_global.cc: Same.
+       * testsuite/ext/throw_allocator/check_delete.cc: Same.
+       * testsuite/ext/throw_allocator/check_new.cc: Same.
+       * testsuite/ext/throw_allocator/deallocate_local.cc: Same.
+       * testsuite/ext/malloc_allocator/deallocate_global.cc: Same.
+       * testsuite/ext/malloc_allocator/check_delete.cc: Same.
+       * testsuite/ext/malloc_allocator/check_new.cc: Same.
+       * testsuite/ext/malloc_allocator/deallocate_local.cc: Same.
+       * testsuite/ext/pool_allocator/check_delete.cc: Same.
+       * testsuite/ext/pool_allocator/check_new.cc: Same.
+       * testsuite/ext/bitmap_allocator/check_delete.cc: Same.
+       * testsuite/ext/bitmap_allocator/check_new.cc: Same.
+       * testsuite/ext/array_allocator/check_delete.cc: Same.
+       * testsuite/ext/array_allocator/check_new.cc: Same.
+       * testsuite/23_containers/deque/cons/1.cc: Same.
+       * testsuite/23_containers/deque/cons/2.cc: Same.
+
 2009-05-27  Benjamin Kosnik  <bkoz@redhat.com>
 
        * libsupc++/initializer_list: Format.
index 3d86fd8..5795215 100644 (file)
@@ -26,7 +26,7 @@
 #include <testsuite_allocator.h>
 #include <testsuite_hooks.h>
 
-typedef std::deque<__gnu_test::counter>   gdeque;
+typedef std::deque<__gnu_test::object_counter>   gdeque;
 
 bool test __attribute__((unused)) = true;
 
index 4d6e130..2360028 100644 (file)
@@ -31,10 +31,10 @@ using __gnu_test::tracker_allocator_counter;
 using __gnu_test::tracker_allocator;
 using __gnu_test::copy_constructor;
 using __gnu_test::assignment_operator;
-using __gnu_test::counter;
+using __gnu_test::object_counter;
 using __gnu_test::destructor;
 
-typedef std::deque<counter>   gdeque;
+typedef std::deque<object_counter>   gdeque;
 
 bool test __attribute__((unused)) = true;
 
index 6a1214e..9e6f32d 100644 (file)
 
 #include <cstdlib>
 #include <ext/array_allocator.h>
-#include <testsuite_hooks.h>
-#include <testsuite_allocator.h>
+#include <replacement_memory_operators.h>
 
-using __gnu_cxx::array_allocator;
-
-void* 
-operator new(std::size_t n) throw(std::bad_alloc)
-{
-  new_called = true;
-  return std::malloc(n);
-}
-
-void
-operator delete(void *v) throw()
-{
-  delete_called = true;
-  return std::free(v);
-}
-
-// These just help tracking down error messages.
-void test01() 
+int main()
 { 
-  bool test __attribute__((unused)) = true;
   typedef unsigned int value_type;
   typedef std::tr1::array<value_type, 15> array_type;
-  typedef array_allocator<value_type, array_type> allocator_type;
+  typedef __gnu_cxx::array_allocator<value_type, array_type> allocator_type;
   array_type store;
   allocator_type a(&store);
-  VERIFY( bool(__gnu_test::check_delete<allocator_type, false>(a)) ); 
-}
-
-int main()
-{
-  test01();
+  __gnu_test::check_delete<allocator_type, false>(a); 
   return 0;
 }
-
index ea75ee7..2d51a02 100644 (file)
 
 #include <cstdlib>
 #include <ext/array_allocator.h>
-#include <testsuite_hooks.h>
-#include <testsuite_allocator.h>
+#include <replacement_memory_operators.h>
 
-using __gnu_cxx::array_allocator;
-
-void* 
-operator new(std::size_t n) throw(std::bad_alloc)
-{
-  new_called = true;
-  return std::malloc(n);
-}
-
-void
-operator delete(void *v) throw()
-{
-  delete_called = true;
-  return std::free(v);
-}
-
-// These just help tracking down error messages.
-void test01() 
+int main()
 { 
-  bool test __attribute__((unused)) = true;
   typedef unsigned int value_type;
   typedef std::tr1::array<value_type, 15> array_type;
-  typedef array_allocator<value_type, array_type> allocator_type;
+  typedef __gnu_cxx::array_allocator<value_type, array_type> allocator_type;
   array_type store;
   allocator_type a(&store);
-  VERIFY( bool(__gnu_test::check_new<allocator_type, false>(a)) ); 
-}
-
-int main()
-{
-  test01();
+  __gnu_test::check_new<allocator_type, false>(a); 
   return 0;
 }
-
index 9cff385..a82bcc7 100644 (file)
 
 #include <cstdlib>
 #include <ext/bitmap_allocator.h>
-#include <testsuite_hooks.h>
-#include <testsuite_allocator.h>
-
-using __gnu_cxx::bitmap_allocator;
-
-void* 
-operator new(std::size_t n) throw(std::bad_alloc)
-{
-  new_called = true;
-  return std::malloc(n);
-}
-
-void
-operator delete(void *v) throw()
-{
-  delete_called = true;
-  return std::free(v);
-}
-
-// These just help tracking down error messages.
-void test01() 
-{ 
-  bool test __attribute__((unused)) = true;
-  typedef bitmap_allocator<unsigned int> allocator_type;
-  VERIFY( bool(__gnu_test::check_delete<allocator_type, true>()) ); 
-}
+#include <replacement_memory_operators.h>
 
 int main()
-{
-  test01();
+{ 
+  typedef __gnu_cxx::bitmap_allocator<unsigned int> allocator_type;
+  __gnu_test::check_delete<allocator_type, true>(); 
   return 0;
 }
index 24ee3f0..205fa3a 100644 (file)
 
 #include <cstdlib>
 #include <ext/bitmap_allocator.h>
-#include <testsuite_hooks.h>
-#include <testsuite_allocator.h>
-
-using __gnu_cxx::bitmap_allocator;
-
-void* 
-operator new(std::size_t n) throw(std::bad_alloc)
-{
-  new_called = true;
-  return std::malloc(n);
-}
-
-void
-operator delete(void *v) throw()
-{
-  delete_called = true;
-  return std::free(v);
-}
-
-// These just help tracking down error messages.
-void test01() 
-{ 
-  bool test __attribute__((unused)) = true;
-  typedef bitmap_allocator<unsigned int> allocator_type;
-  VERIFY( bool(__gnu_test::check_new<allocator_type, true>()) ); 
-}
+#include <replacement_memory_operators.h>
 
 int main()
-{
-  test01();
+{ 
+  typedef __gnu_cxx::bitmap_allocator<unsigned int> allocator_type;
+  __gnu_test::check_new<allocator_type, true>(); 
   return 0;
 }
index 04f0997..5b9d061 100644 (file)
 #include <cstdlib>
 #include <ext/debug_allocator.h>
 #include <ext/malloc_allocator.h>
-#include <testsuite_hooks.h>
-#include <testsuite_allocator.h>
+#include <replacement_memory_operators.h>
 
-using __gnu_cxx::malloc_allocator;
-using __gnu_cxx::debug_allocator;
-
-void* 
-operator new(std::size_t n) throw(std::bad_alloc)
-{
-  new_called = true;
-  return std::malloc(n);
-}
-
-void
-operator delete(void *v) throw()
-{
-  delete_called = true;
-  return std::free(v);
-}
-
-// These just help tracking down error messages.
-void test01() 
+int main()
 { 
-  bool test __attribute__((unused)) = true;
+  using namespace __gnu_cxx;
   typedef debug_allocator<malloc_allocator<unsigned int> > allocator_type;
-  VERIFY( bool(__gnu_test::check_delete<allocator_type, false>()) ); 
-}
-
-int main()
-{
-  test01();
+  __gnu_test::check_delete<allocator_type, false>();
   return 0;
 }
-
index 9169637..105bf28 100644 (file)
 #include <cstdlib>
 #include <ext/debug_allocator.h>
 #include <ext/malloc_allocator.h>
-#include <testsuite_hooks.h>
-#include <testsuite_allocator.h>
+#include <replacement_memory_operators.h>
 
-using __gnu_cxx::malloc_allocator;
-using __gnu_cxx::debug_allocator;
-
-void* 
-operator new(std::size_t n) throw(std::bad_alloc)
-{
-  new_called = true;
-  return std::malloc(n);
-}
-
-void
-operator delete(void *v) throw()
-{
-  delete_called = true;
-  return std::free(v);
-}
-
-// These just help tracking down error messages.
-void test01() 
+int main()
 { 
-  bool test __attribute__((unused)) = true;
+  using namespace __gnu_cxx;
   typedef debug_allocator<malloc_allocator<unsigned int> > allocator_type;
-  VERIFY( bool(__gnu_test::check_new<allocator_type, false>()) ); 
-}
-
-int main()
-{
-  test01();
+  __gnu_test::check_new<allocator_type, false>(); 
   return 0;
 }
-
index 2b9f8bc..2ed8d04 100644 (file)
 
 #include <cstdlib>
 #include <ext/malloc_allocator.h>
-#include <testsuite_hooks.h>
-#include <testsuite_allocator.h>
-
-using __gnu_cxx::malloc_allocator;
-
-void* 
-operator new(std::size_t n) throw(std::bad_alloc)
-{
-  new_called = true;
-  return std::malloc(n);
-}
-
-void
-operator delete(void *v) throw()
-{
-  delete_called = true;
-  return std::free(v);
-}
-
-// These just help tracking down error messages.
-void test01() 
-{ 
-  bool test __attribute__((unused)) = true;
-  typedef malloc_allocator<unsigned int> allocator_type;
-  VERIFY( bool(__gnu_test::check_delete<allocator_type, false>()) ); 
-}
+#include <replacement_memory_operators.h>
 
 int main()
-{
-  test01();
+{ 
+  typedef __gnu_cxx::malloc_allocator<unsigned int> allocator_type;
+  __gnu_test::check_delete<allocator_type, false>(); 
   return 0;
 }
-
index 51acf69..fac139f 100644 (file)
 
 #include <cstdlib>
 #include <ext/malloc_allocator.h>
-#include <testsuite_hooks.h>
-#include <testsuite_allocator.h>
-
-using __gnu_cxx::malloc_allocator;
-
-void* 
-operator new(std::size_t n) throw(std::bad_alloc)
-{
-  new_called = true;
-  return std::malloc(n);
-}
-
-void
-operator delete(void *v) throw()
-{
-  delete_called = true;
-  return std::free(v);
-}
-
-// These just help tracking down error messages.
-void test01() 
-{ 
-  bool test __attribute__((unused)) = true;
-  typedef malloc_allocator<unsigned int> allocator_type;
-  VERIFY( bool(__gnu_test::check_new<allocator_type, false>()) ); 
-}
+#include <replacement_memory_operators.h>
 
 int main()
-{
-  test01();
+{ 
+  typedef __gnu_cxx::malloc_allocator<unsigned int> allocator_type;
+  __gnu_test::check_new<allocator_type, false>(); 
   return 0;
 }
-
index 2d1ded8..67041f5 100644 (file)
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-// 20.4.1.1 allocator members
-
 #include <string>
 #include <stdexcept>
-#include <cstdio>
 #include <ext/malloc_allocator.h>
-#include <testsuite_hooks.h>
-
-static size_t count;
-
-struct count_check
-{
-  count_check() {}
-  ~count_check()
-  {
-    if (count != 0)
-      throw std::runtime_error("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--;
-  if (count == 0)
-    printf("All memory released \n");
-  else
-    printf("%lu allocations to be released \n",
-          static_cast<unsigned long>(count));
-  free(p);
-}
+#include <replacement_memory_operators.h>
 
 typedef char char_t;
 typedef std::char_traits<char_t> traits_t;
 typedef __gnu_cxx::malloc_allocator<char_t> allocator_t;
-typedef std::basic_string<char_t, traits_t, allocator_t> string_t;
+typedef std::basic_string<char_t, traits_t, allocator_t> string_t;  
 
 string_t s("bayou bend");
 
index f9cd80d..76ae199 100644 (file)
@@ -1,5 +1,5 @@
 //
-// Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009
+// Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 
 // Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-// 20.4.1.1 allocator members
-
 #include <string>
-#include <cstdio>
 #include <ext/malloc_allocator.h>
-#include <testsuite_hooks.h>
-
-static size_t alloc_cnt;
-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++;
-  return p;
-}
-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("%lu allocations to be released \n",
-          static_cast<unsigned long>(alloc_cnt));
-  free(p);
-}
+#include <replacement_memory_operators.h>
 
 typedef char char_t;
 typedef std::char_traits<char_t> traits_t;
 typedef __gnu_cxx::malloc_allocator<char_t> allocator_t;
-typedef std::basic_string<char_t, traits_t, allocator_t> string_t;
+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 );
+
+  if (__gnu_test::counter::count() != 0)
+    throw std::runtime_error("count not zero");
   return 0;
 }
index 470b66f..374c567 100644 (file)
 
 #include <cstdlib>
 #include <ext/mt_allocator.h>
-#include <testsuite_hooks.h>
-#include <testsuite_allocator.h>
-
-using __gnu_cxx::__mt_alloc;
-
-void* 
-operator new(std::size_t n) throw(std::bad_alloc)
-{
-  new_called = true;
-  return std::malloc(n);
-}
-
-void
-operator delete(void* v) throw()
-{
-  delete_called = true;
-  return std::free(v);
-}
-
-void test01() 
-{ 
-  bool test __attribute__((unused)) = true;
-  typedef __mt_alloc<unsigned int> allocator_type;
-  VERIFY( bool(__gnu_test::check_delete<allocator_type, false>()) ); 
-}
+#include <replacement_memory_operators.h>
 
 int main()
-{
-  test01();
+{ 
+  typedef __gnu_cxx::__mt_alloc<unsigned int> allocator_type;
+  __gnu_test::check_delete<allocator_type, false>(); 
   return 0;
 }
index 171a207..5279326 100644 (file)
 
 #include <cstdlib>
 #include <ext/mt_allocator.h>
-#include <testsuite_hooks.h>
-#include <testsuite_allocator.h>
+#include <replacement_memory_operators.h>
 
-using __gnu_cxx::__mt_alloc;
-
-void* 
-operator new(std::size_t n) throw(std::bad_alloc)
-{
-  new_called = true;
-  return std::malloc(n);
-}
-
-void
-operator delete(void* v) throw()
-{
-  delete_called = true;
-  return std::free(v);
-}
-
-void test01() 
+int main()
 { 
   // Uses new but delete only optionally.
-  bool test __attribute__((unused)) = true;
-  typedef __mt_alloc<unsigned int> allocator_type;
-  VERIFY( bool(__gnu_test::check_new<allocator_type, true>()) ); 
-}
-
-int main()
-{
-  test01();
+  typedef __gnu_cxx::__mt_alloc<unsigned int> allocator_type;
+  __gnu_test::check_new<allocator_type, true>(); 
   return 0;
 }
index a75f38a..fcc5006 100644 (file)
 #include <stdexcept>
 #include <cstdio>
 #include <ext/mt_allocator.h>
-
-static size_t count;
-
-struct count_check
-{
-  count_check() { }
-  ~count_check()
-  {
-    // NB: __mt_allocator doesn't clean itself up. Thus, this will not
-    // be zero.
-    if (count != 0)
-      {
-       //throw std::runtime_error("allocation/deallocation count isn't zero");
-       printf("allocation/deallocation count is %zu \n", count);
-      }
-  }
-};
-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--;
-}
+#include <replacement_memory_operators.h>
 
 typedef std::string value_type;
 using __gnu_cxx::__pool;
@@ -74,6 +38,9 @@ list_type l;
 
 int main()
 {
+  // NB: __mt_allocator doesn't clean itself up. Thus, the count will
+  // not be zero.
+  __gnu_test::counter::exceptions(false);
   l.push_back("bayou bend");
   return 0;
 }
index bc9c2c7..cafbffb 100644 (file)
 #include <stdexcept>
 #include <cstdio>
 #include <ext/mt_allocator.h>
-
-static size_t count;
-
-struct count_check
-{
-  count_check() { }
-  ~count_check()
-  {
-    // NB: __mt_allocator doesn't clean itself up. Thus, this will not
-    // be zero.
-    if (count != 0)
-      {
-       //throw std::runtime_error("allocation/deallocation count isn't zero");
-       printf("allocation/deallocation count is %zu \n", count);
-      }
-  }
-};
-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--;
-}
+#include <replacement_memory_operators.h>
 
 typedef std::string value_t;
 using __gnu_cxx::__pool;
@@ -74,6 +38,9 @@ list_type l;
 
 int main()
 {
+  // NB: __mt_allocator doesn't clean itself up. Thus, the count will
+  // not be zero.
+  __gnu_test::counter::exceptions(false);
   l.push_back("bayou bend");
   return 0;
 }
index 6881c9f..f61cd38 100644 (file)
 #include <stdexcept>
 #include <cstdio>
 #include <ext/mt_allocator.h>
-
-static size_t count;
-
-struct count_check
-{
-  count_check() { }
-  ~count_check()
-  {
-    // NB: __mt_allocator doesn't clean itself up. Thus, this will not
-    // be zero.
-    if (count != 0)
-      {
-       //throw std::runtime_error("allocation/deallocation count isn't zero");
-       printf("allocation/deallocation count is %zu \n", count);
-      }
-  }
-};
-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--;
-}
+#include <replacement_memory_operators.h>
 
 typedef std::string value_type;
 using __gnu_cxx::__pool;
@@ -74,6 +38,9 @@ list_type l;
 
 int main()
 {
+  // NB: __mt_allocator doesn't clean itself up. Thus, the count will
+  // not be zero.
+  __gnu_test::counter::exceptions(false);
   l.push_back("bayou bend");
   return 0;
 }
index 2724d36..62074f0 100644 (file)
 #include <stdexcept>
 #include <cstdio>
 #include <ext/mt_allocator.h>
-
-static size_t count;
-
-struct count_check
-{
-  count_check() { }
-  ~count_check()
-  {
-    // NB: __mt_allocator doesn't clean itself up. Thus, this will not
-    // be zero.
-    if (count != 0)
-      {
-       //throw std::runtime_error("allocation/deallocation count isn't zero");
-       printf("allocation/deallocation count is %zu \n", count);
-      }
-  }
-};
-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--;
-}
+#include <replacement_memory_operators.h>
 
 typedef std::string value_type;
 using __gnu_cxx::__pool;
@@ -74,6 +38,9 @@ list_type l;
 
 int main()
 {
+  // NB: __mt_allocator doesn't clean itself up. Thus, the count will
+  // not be zero.
+  __gnu_test::counter::exceptions(false);
   l.push_back("bayou bend");
   return 0;
 }
index eec6dea..9ccebd5 100644 (file)
 #include <stdexcept>
 #include <cstdio>
 #include <ext/mt_allocator.h>
-
-static size_t count;
-
-struct count_check
-{
-  count_check() { }
-  ~count_check()
-  {
-    // NB: __mt_allocator doesn't clean itself up. Thus, this will not
-    // be zero.
-    if (count != 0)
-      {
-       //throw std::runtime_error("allocation/deallocation count isn't zero");
-       printf("allocation/deallocation count is %zu \n", count);
-      }
-  }
-};
-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--;
-}
+#include <replacement_memory_operators.h>
 
 typedef char value_type;
 typedef std::char_traits<value_type> traits_type;
@@ -70,6 +34,9 @@ typedef std::basic_string<value_type, traits_type, allocator_type> string_type;
 
 int main()
 {
+  // NB: __mt_allocator doesn't clean itself up. Thus, the count will
+  // not be zero.
+  __gnu_test::counter::exceptions(false);
   string_type s;
   s += "bayou bend";
   return 0;
index 793f640..9265a15 100644 (file)
 #include <stdexcept>
 #include <cstdio>
 #include <ext/mt_allocator.h>
-
-static size_t count;
-
-struct count_check
-{
-  count_check() { }
-  ~count_check()
-  {
-    // NB: __mt_allocator doesn't clean itself up. Thus, this will not
-    // be zero.
-    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--;
-}
+#include <replacement_memory_operators.h>
 
 typedef char value_type;
 typedef std::char_traits<value_type> traits_type;
@@ -71,6 +35,9 @@ typedef std::basic_string<value_type, traits_type, allocator_type> string_type;
 
 int main()
 {
+  // NB: __mt_allocator doesn't clean itself up. Thus, the count will
+  // not be zero.
+  __gnu_test::counter::exceptions(false);
   string_type s;
   s += "bayou bend";
   return 0;
index fd1da97..0175571 100644 (file)
 #include <stdexcept>
 #include <cstdio>
 #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--;
-}
+#include <replacement_memory_operators.h>
 
 template<bool _Thread>
   struct cleanup_pool : public __gnu_cxx::__pool<false>
@@ -81,6 +46,9 @@ typedef std::basic_string<value_type, traits_type, allocator_type> string_type;
 
 int main()
 {
+  // NB: __mt_allocator doesn't clean itself up. Thus, the count will
+  // not be zero.
+  __gnu_test::counter::exceptions(false);
   string_type s;
   s += "bayou bend";
   return 0;
index 1574e8c..34005e4 100644 (file)
 #include <stdexcept>
 #include <cstdio>
 #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--;
-}
+#include <replacement_memory_operators.h>
 
 template<bool _Thread>
   struct cleanup_pool : public __gnu_cxx::__pool<false>
@@ -82,6 +47,9 @@ typedef std::basic_string<value_type, traits_type, allocator_type> string_type;
 
 int main()
 {
+  // NB: __mt_allocator doesn't clean itself up. Thus, the count will
+  // not be zero.
+  __gnu_test::counter::exceptions(false);
   string_type s;
   s += "bayou bend";
   return 0;
index 399d576..012a758 100644 (file)
 #include <stdexcept>
 #include <cstdio>
 #include <ext/mt_allocator.h>
-
-static size_t count;
-
-struct count_check
-{
-  count_check() { }
-  ~count_check()
-  {
-    // NB: __mt_allocator doesn't clean itself up. Thus, this will not
-    // be zero.
-    if (count != 0)
-      {
-       //throw std::runtime_error("allocation/deallocation count isn't zero");
-       printf("allocation/deallocation count is %zu \n", count);
-      }
-  }
-};
-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--;
-}
+#include <replacement_memory_operators.h>
 
 typedef char value_type;
 typedef std::char_traits<value_type> traits_type;
@@ -70,6 +34,9 @@ typedef std::basic_string<value_type, traits_type, allocator_type> string_type;
 
 int main()
 {
+  // NB: __mt_allocator doesn't clean itself up. Thus, the count will
+  // not be zero.
+  __gnu_test::counter::exceptions(false);
   string_type s;
   s += "bayou bend";
   return 0;
index 38977c5..0a9fde0 100644 (file)
 #include <stdexcept>
 #include <cstdio>
 #include <ext/mt_allocator.h>
-
-static size_t count;
-
-struct count_check
-{
-  count_check() { }
-  ~count_check()
-  {
-    // NB: __mt_allocator doesn't clean itself up. Thus, this will not
-    // be zero.
-    if (count != 0)
-      {
-       //throw std::runtime_error("allocation/deallocation count isn't zero");
-       printf("allocation/deallocation count is %zu \n", count);
-      }
-  }
-};
-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--;
-}
+#include <replacement_memory_operators.h>
 
 typedef char value_type;
 typedef std::char_traits<value_type> traits_type;
@@ -71,6 +35,9 @@ typedef std::basic_string<value_type, traits_type, allocator_type> string_type;
 
 int main()
 {
+  // NB: __mt_allocator doesn't clean itself up. Thus, the count will
+  // not be zero.
+  __gnu_test::counter::exceptions(false);
   string_type s;
   s += "bayou bend";
   return 0;
index 49701c0..a812aec 100644 (file)
 #include <stdexcept>
 #include <cstdio>
 #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--;
-}
+#include <replacement_memory_operators.h>
 
 template<bool _Thread>
   struct cleanup_pool : public __gnu_cxx::__pool<true>
@@ -72,7 +37,6 @@ template<bool _Thread>
     ~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;
@@ -81,6 +45,9 @@ typedef std::basic_string<value_type, traits_type, allocator_type> string_type;
 
 int main()
 {
+  // NB: __mt_allocator doesn't clean itself up. Thus, the count will
+  // not be zero.
+  __gnu_test::counter::exceptions(false);
   string_type s;
   s += "bayou bend";
   return 0;
index 5bdfd0d..ac8426e 100644 (file)
 #include <stdexcept>
 #include <cstdio>
 #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--;
-}
+#include <replacement_memory_operators.h>
 
 template<bool _Thread>
   struct cleanup_pool : public __gnu_cxx::__pool<true>
@@ -82,6 +47,9 @@ typedef std::basic_string<value_type, traits_type, allocator_type> string_type;
 
 int main()
 {
+  // NB: __mt_allocator doesn't clean itself up. Thus, the count will
+  // not be zero.
+  __gnu_test::counter::exceptions(false);
   string_type s;
   s += "bayou bend";
   return 0;
index f979037..cff31c8 100644 (file)
 
 #include <cstdlib>
 #include <ext/new_allocator.h>
-#include <testsuite_hooks.h>
-#include <testsuite_allocator.h>
-
-using __gnu_cxx::new_allocator;
-
-void* 
-operator new(std::size_t n) throw(std::bad_alloc)
-{
-  new_called = true;
-  return std::malloc(n);
-}
-
-void
-operator delete(void *v) throw()
-{
-  delete_called = true;
-  return std::free(v);
-}
-
-// These just help tracking down error messages.
-void test01() 
-{ 
-  bool test __attribute__((unused)) = true;
-  typedef new_allocator<unsigned int> allocator_type;
-  VERIFY( bool(__gnu_test::check_delete<allocator_type, true>()) ); 
-}
+#include <replacement_memory_operators.h>
 
 int main()
-{
-  test01();
+{ 
+  typedef __gnu_cxx::new_allocator<unsigned int> allocator_type;
+  __gnu_test::check_delete<allocator_type, true>(); 
   return 0;
 }
-
index 9fa0c04..098b624 100644 (file)
 
 #include <cstdlib>
 #include <ext/new_allocator.h>
-#include <testsuite_hooks.h>
-#include <testsuite_allocator.h>
-
-using __gnu_cxx::new_allocator;
-
-void* 
-operator new(std::size_t n) throw(std::bad_alloc)
-{
-  new_called = true;
-  return std::malloc(n);
-}
-
-void
-operator delete(void *v) throw()
-{
-  delete_called = true;
-  return std::free(v);
-}
-
-// These just help tracking down error messages.
-void test01() 
-{ 
-  bool test __attribute__((unused)) = true;
-  typedef new_allocator<unsigned int> allocator_type;
-  VERIFY( bool(__gnu_test::check_new<allocator_type, true>()) ); 
-}
+#include <replacement_memory_operators.h>
 
 int main()
-{
-  test01();
+{ 
+  typedef __gnu_cxx::new_allocator<unsigned int> allocator_type;
+  __gnu_test::check_new<allocator_type, true>(); 
   return 0;
 }
-
index 014141b..783be48 100644 (file)
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-// 20.4.1.1 allocator members
-
 #include <string>
 #include <stdexcept>
-#include <cstdlib>
-#include <cstdio>
 #include <ext/new_allocator.h>
-
-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)
-{
-  std::printf("operator new is called \n");
-  void* p = std::malloc(size);
-  if (p == NULL)
-    throw std::bad_alloc();
-  count++;
-  return p;
-}
-void operator delete(void* p) throw()
-{
-  std::printf("operator delete is called \n");
-  if (p == NULL)
-    return;
-  count--;
-}
+#include <replacement_memory_operators.h>
 
 typedef char char_t;
 typedef std::char_traits<char_t> traits_t;
 typedef __gnu_cxx::new_allocator<char_t> allocator_t;
-typedef std::basic_string<char_t, traits_t, allocator_t> string_t;
+typedef std::basic_string<char_t, traits_t, allocator_t> string_t;  
 
 string_t s("bayou bend");
 
index 7f224a5..dd7c634 100644 (file)
@@ -1,5 +1,5 @@
 //
-// Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009
+// Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 
 // Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-// 20.4.1.1 allocator members
-
 #include <string>
-#include <stdexcept>
-#include <cstdlib>
-#include <cstdio>
 #include <ext/new_allocator.h>
-
-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)
-{
-  std::printf("operator new is called \n");
-  void* p = std::malloc(size);
-  if (p == NULL)
-    throw std::bad_alloc();
-  count++;
-  return p;
-}
-void operator delete(void* p) throw()
-{
-  std::printf("operator delete is called \n");
-  if (p == NULL)
-    return;
-  count--;
-}
+#include <replacement_memory_operators.h>
 
 typedef char char_t;
 typedef std::char_traits<char_t> traits_t;
 typedef __gnu_cxx::new_allocator<char_t> allocator_t;
-typedef std::basic_string<char_t, traits_t, allocator_t> string_t;
+typedef std::basic_string<char_t, traits_t, allocator_t> string_t;  
 
 int main()
 {
-  string_t s;
-  s += "bayou bend";
+  {
+    string_t s;
+    s += "bayou bend";
+  }
+
+  if (__gnu_test::counter::count() != 0)
+    throw std::runtime_error("count not zero");
   return 0;
 }
index b24550e..ecc399d 100644 (file)
 
 #include <cstdlib>
 #include <ext/pool_allocator.h>
-#include <testsuite_hooks.h>
-#include <testsuite_allocator.h>
-
-using __gnu_cxx::__pool_alloc;
-
-void* 
-operator new(std::size_t n) throw(std::bad_alloc)
-{
-  new_called = true;
-  return std::malloc(n);
-}
-
-void
-operator delete(void *v) throw()
-{
-  delete_called = true;
-  return std::free(v);
-}
-
-void test01() 
-{ 
-  // Uses new, but delete only sometimes.
-  bool test __attribute__((unused)) = true;
-  typedef __pool_alloc<unsigned int> allocator_type;
-  VERIFY( bool(__gnu_test::check_delete<allocator_type, false>()) ); 
-}
+#include <replacement_memory_operators.h>
 
 int main()
 {
-  test01();
+  // Uses new, but delete only sometimes.
+  typedef __gnu_cxx::__pool_alloc<unsigned int> allocator_type;
+  __gnu_test::check_delete<allocator_type, false>(); 
   return 0;
 }
-
index a4fad95..f1bdb77 100644 (file)
 
 #include <cstdlib>
 #include <ext/pool_allocator.h>
-#include <testsuite_hooks.h>
-#include <testsuite_allocator.h>
-
-using __gnu_cxx::__pool_alloc;
-
-void* 
-operator new(std::size_t n) throw(std::bad_alloc)
-{
-  new_called = true;
-  return std::malloc(n);
-}
-
-void
-operator delete(void *v) throw()
-{
-  delete_called = true;
-  return std::free(v);
-}
-
-void test01() 
-{ 
-  bool test __attribute__((unused)) = true;
-  typedef __pool_alloc<unsigned int> allocator_type;
-  VERIFY( bool(__gnu_test::check_new<allocator_type, true>()) ); 
-}
+#include <replacement_memory_operators.h>
 
 int main()
-{
-  test01();
+{ 
+  typedef __gnu_cxx::__pool_alloc<unsigned int> allocator_type;
+  __gnu_test::check_new<allocator_type, true>(); 
   return 0;
 }
-
index a334931..cfc38ee 100644 (file)
 
 #include <cstdlib>
 #include <ext/throw_allocator.h>
-#include <testsuite_hooks.h>
-#include <testsuite_allocator.h>
-
-using __gnu_cxx::throw_allocator;
-
-void* 
-operator new(std::size_t n) throw(std::bad_alloc)
-{
-  new_called = true;
-  return std::malloc(n);
-}
-
-void
-operator delete(void *v) throw()
-{
-  delete_called = true;
-  return std::free(v);
-}
-
-// These just help tracking down error messages.
-void test01() 
-{ 
-  bool test __attribute__((unused)) = true;
-  typedef throw_allocator<unsigned int> allocator_type;
-  VERIFY( bool(__gnu_test::check_delete<allocator_type, true>()) ); 
-}
+#include <replacement_memory_operators.h>
 
 int main()
-{
-  test01();
+{ 
+  typedef __gnu_cxx::throw_allocator<unsigned int> allocator_type;
+  __gnu_test::check_delete<allocator_type, true>(); 
   return 0;
 }
-
index f0579fb..2d42891 100644 (file)
 
 #include <cstdlib>
 #include <ext/throw_allocator.h>
-#include <testsuite_hooks.h>
-#include <testsuite_allocator.h>
-
-using __gnu_cxx::throw_allocator;
-
-void* 
-operator new(std::size_t n) throw(std::bad_alloc)
-{
-  new_called = true;
-  return std::malloc(n);
-}
-
-void
-operator delete(void *v) throw()
-{
-  delete_called = true;
-  return std::free(v);
-}
-
-// These just help tracking down error messages.
-void test01() 
-{ 
-  bool test __attribute__((unused)) = true;
-  typedef throw_allocator<unsigned int> allocator_type;
-  VERIFY( bool(__gnu_test::check_new<allocator_type, true>()) ); 
-}
+#include <replacement_memory_operators.h>
 
 int main()
-{
-  test01();
+{ 
+  typedef __gnu_cxx::throw_allocator<unsigned int> allocator_type;
+  __gnu_test::check_new<allocator_type, true>(); 
   return 0;
 }
-
index d298fe4..c53517e 100644 (file)
 #include <string>
 #include <stdexcept>
 #include <ext/throw_allocator.h>
-#include <testsuite_hooks.h>
-
-static size_t count;
-
-struct count_check
-{
-  count_check() {}
-  ~count_check()
-  {
-    if (count != 0)
-      throw std::runtime_error("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--;
-  if (count == 0)
-    printf("All memory released \n");
-  else
-    printf("%lu allocations to be released \n",
-          static_cast<unsigned long>(count));
-  free(p);
-}
+#include <replacement_memory_operators.h>
 
 typedef char char_t;
 typedef std::char_traits<char_t> traits_t;
 typedef __gnu_cxx::throw_allocator<char_t> allocator_t;
-typedef std::basic_string<char_t, traits_t, allocator_t> string_t;
+typedef std::basic_string<char_t, traits_t, allocator_t> string_t;  
 
 string_t s("bayou bend");
 
index 45fd6dc..c2e918c 100644 (file)
 
 #include <string>
 #include <ext/throw_allocator.h>
-#include <testsuite_hooks.h>
-
-static size_t alloc_cnt;
-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++;
-  return p;
-}
-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("%lu allocations to be released \n",
-          static_cast<unsigned long>(alloc_cnt));
-  free(p);
-}
+#include <replacement_memory_operators.h>
 
 typedef char char_t;
 typedef std::char_traits<char_t> traits_t;
 typedef __gnu_cxx::throw_allocator<char_t> allocator_t;
-typedef std::basic_string<char_t, traits_t, allocator_t> string_t;
+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 );
+
+  if (__gnu_test::counter::count() != 0)
+    throw std::runtime_error("count not zero");
   return 0;
 }
diff --git a/libstdc++-v3/testsuite/util/replacement_memory_operators.h b/libstdc++-v3/testsuite/util/replacement_memory_operators.h
new file mode 100644 (file)
index 0000000..91c8fa3
--- /dev/null
@@ -0,0 +1,110 @@
+//
+// Copyright (C) 2007, 2009 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 3, 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 COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <exception>
+
+namespace __gnu_test
+{
+  struct counter_error : public std::exception { };
+
+  struct counter
+  {
+    size_t     _M_count;
+    bool       _M_throw;
+
+    counter() : _M_count(0), _M_throw(true) { }
+    
+    ~counter()
+    {
+      if (_M_throw && _M_count != 0)
+       throw counter_error();
+    }
+
+    static void
+    increment() { get()._M_count++; }
+
+    static void
+    decrement() { get()._M_count--; }
+
+    static counter&
+    get() 
+    {
+      static counter g;
+      return g;
+    }
+  
+    static size_t
+    count() { return get()._M_count; }
+
+    static void
+    exceptions(bool __b) { get()._M_throw = __b; }
+  };
+
+  template<typename Alloc, bool uses_global_new>
+    bool 
+    check_new(Alloc a = Alloc())
+    {
+      __gnu_test::counter::exceptions(false);
+      a.allocate(10);
+      const bool __b((__gnu_test::counter::count() > 0) == uses_global_new);
+      if (!__b)
+       throw std::logic_error("counter not incremented");
+      return __b;
+    }
+
+  template<typename Alloc, bool uses_global_delete>
+    bool 
+    check_delete(Alloc a = Alloc())
+    {
+      __gnu_test::counter::exceptions(false);
+      typename Alloc::pointer p = a.allocate(10);
+      const std::size_t count1 = __gnu_test::counter::count();
+      a.deallocate(p, 10);
+      const std::size_t count2 = __gnu_test::counter::count();
+      const bool __b((count2 < count1) == uses_global_delete);
+      if (!__b)
+       throw std::logic_error("counter not decremented");
+      return __b;
+    }
+} // namespace __gnu_test
+
+void* operator new(std::size_t size) throw(std::bad_alloc)
+{
+  printf("operator new is called \n");
+  void* p = std::malloc(size);
+  if (p == NULL)
+    throw std::bad_alloc();
+  __gnu_test::counter::increment();
+  return p;
+}
+void operator delete(void* p) throw()
+{
+  printf("operator delete is called \n");
+  if (p != NULL)
+    {
+      std::free(p);
+      __gnu_test::counter::decrement();
+
+      std::size_t count = __gnu_test::counter::count(); 
+      if (count == 0)
+       printf("All memory released \n");
+      else
+       printf("%lu allocations to be released \n", count);
+    }
+}
index d2759f4..96fe546 100644 (file)
 #include <cassert>
 #include <bits/move.h>
 
-namespace 
-{
-  bool new_called = false;
-  bool delete_called = false;
-}
-
 namespace __gnu_test
 {
   class tracker_allocator_counter
@@ -186,27 +180,6 @@ namespace __gnu_test
   bool
   check_construct_destroy(const char* tag, int expected_c, int expected_d);
 
-  template<typename Alloc, bool uses_global_new>
-    bool 
-    check_new(Alloc a = Alloc())
-    {
-      bool test __attribute__((unused)) = true;
-      a.allocate(10);
-      test &= ( new_called == uses_global_new );
-      return test;
-    }
-
-  template<typename Alloc, bool uses_global_delete>
-    bool 
-    check_delete(Alloc a = Alloc())
-    {
-      bool test __attribute__((unused)) = true;
-      typename Alloc::pointer p = a.allocate(10);
-      a.deallocate(p, 10);
-      test &= ( delete_called == uses_global_delete );
-      return test;
-    }
-
   template<typename Alloc>
     bool
     check_deallocate_null()
index 8fb7e15..6d77d57 100644 (file)
@@ -217,7 +217,7 @@ namespace __gnu_test
 #endif
   }
 
-  counter::size_type  counter::count = 0;
+  object_counter::size_type  object_counter::count = 0;
   unsigned int copy_constructor::count_ = 0;
   unsigned int copy_constructor::throw_on_ = 0;
   unsigned int assignment_operator::count_ = 0;
index add47b6..88155fa 100644 (file)
@@ -34,8 +34,8 @@
 //   limit in megabytes (a floating-point number).  If _GLIBCXX_RES_LIMITS is
 //   not #defined before including this header, then no limiting is attempted.
 //
-// 3)  counter
-//   This is a POD with a static data member, gnu_counting_struct::count,
+// 3)  object_counter
+//   This is a POD with a static data member, object_counter::count,
 //   which starts at zero, increments on instance construction, and decrements
 //   on instance destruction.  "assert_count(n)" can be called to VERIFY()
 //   that the count equals N.
@@ -135,19 +135,19 @@ namespace __gnu_test
   run_tests_wrapped_env(const char*, const char*, const func_callback&);
 
   // Counting.
-  struct counter
+  struct object_counter
   {
-    // Specifically and glaringly-obviously marked 'signed' so that when
-    // COUNT mistakenly goes negative, we can track the patterns of
-    // deletions more easily.
+    // Specifically and glaringly-obviously marked 'signed' so that
+    // when COUNT mistakenly goes negative, we can track the patterns
+    // of deletions more easily.
     typedef  signed int     size_type;
     static size_type   count;
-    counter() { ++count; }
-    counter (const counter&) { ++count; }
-    ~counter() { --count; }
+    object_counter() { ++count; }
+    object_counter (const object_counter&) { ++count; }
+    ~object_counter() { --count; }
   };
   
-#define assert_count(n)   VERIFY(__gnu_test::counter::count == n)
+#define assert_count(n)   VERIFY(__gnu_test::object_counter::count == n)
   
   // A (static) class for counting copy constructors and possibly throwing an
   // exception on a desired count.