+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>
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
</p>
<p>The datum describing pools characteristics is
-<pre>
- template<bool _Thread>
- class __pool
-</pre>
+ <pre>
+ template<bool _Thread>
+ 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
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
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">
//
-// 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)
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;
typedef std::char_traits<value_type> traits_type;
typedef std::list<value_type, allocator_type> list_type;
-// Second.
list_type l;
int main()
//
-// 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)
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;
typedef std::char_traits<value_t> traits_type;
typedef std::list<value_t, allocator_type> list_type;
-// Second.
list_type l;
int main()
//
-// 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)
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;
typedef std::char_traits<value_type> traits_type;
typedef std::list<value_type, allocator_type> list_type;
-// Second.
list_type l;
int main()
//
-// 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)
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;
typedef std::char_traits<value_type> traits_type;
typedef std::list<value_type, allocator_type> list_type;
-// Second.
list_type l;
int main()
//
-// 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);
}
}
};
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;
int main()
{
- bool test __attribute__((unused)) = true;
- {
- string_type s;
- s += "bayou bend";
- }
+ string_type s;
+ s += "bayou bend";
return 0;
}
//
-// 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");
}
}
};
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;
int main()
{
- bool test __attribute__((unused)) = true;
- {
- string_type s;
- s += "bayou bend";
- }
+ string_type s;
+ s += "bayou bend";
return 0;
}
--- /dev/null
+// { 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;
+}
--- /dev/null
+// { 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;
+}
//
-// 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);
}
}
};
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;
int main()
{
- bool test __attribute__((unused)) = true;
- {
- string_type s;
- s += "bayou bend";
- }
+ string_type s;
+ s += "bayou bend";
return 0;
}
//
-// 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);
}
}
};
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;
int main()
{
- bool test __attribute__((unused)) = true;
- {
- string_type s;
- s += "bayou bend";
- }
+ string_type s;
+ s += "bayou bend";
return 0;
}
--- /dev/null
+// { 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;
+}
--- /dev/null
+// { 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;
+}
//
-// 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");
}
};
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;
//
-// 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;
}
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;
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;
}
}
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
+}
}
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
+}
}
throw;
}
-
}; // namespace __gnu_test
#endif // _GLIBCXX_TESTSUITE_ALLOCATOR_H