libstdc++.exp (check_v3_target_cxa_atexit): New.

2005-09-01  Benjamin Kosnik  <bkoz@redhat.com>

        * testsuite/lib/libstdc++.exp (check_v3_target_cxa_atexit): New.
        * testsuite/lib/dg-options.exp (dg-require-cxa-atexit): New.
        * testsuite/ext/mt_allocator/deallocate_local-6.cc: New.
        * testsuite/ext/mt_allocator/deallocate_local-8.cc: New.
        * testsuite/ext/mt_allocator/deallocate_local_thread-5.cc: New.
        * testsuite/ext/mt_allocator/deallocate_local_thread-7.cc: New.
        * docs/html/ext/mt_allocator.html: Add link to examples.
        * testsuite/testsuite_allocator.h: Tweak.
        * testsuite/ext/mt_allocator/deallocate_global-2.cc: Same.
        * testsuite/ext/mt_allocator/deallocate_global-4.cc: Same.
        * testsuite/ext/mt_allocator/deallocate_global_thread-1.cc: Same.
        * testsuite/ext/mt_allocator/deallocate_global_thread-3.cc: Same.
        * testsuite/ext/mt_allocator/deallocate_local-2.cc: Same.
        * testsuite/ext/mt_allocator/deallocate_local-4.cc: Same.
        * testsuite/ext/mt_allocator/deallocate_local_thread-1.cc: Same.
        * testsuite/ext/mt_allocator/deallocate_local_thread-3.cc: Same.
        * testsuite/ext/new_allocator/deallocate_global.cc: Same.
        * testsuite/ext/new_allocator/deallocate_local.cc: Same.

From-SVN: r103721
This commit is contained in:
Benjamin Kosnik 2005-09-01 07:06:05 +00:00 committed by Benjamin Kosnik
parent 95c37cdb41
commit a1340af76f
19 changed files with 553 additions and 145 deletions

View 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>

View 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">

View 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
@ -23,24 +23,24 @@
#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()

View 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
@ -23,24 +23,24 @@
#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()

View 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
@ -23,24 +23,24 @@
#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()

View 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
@ -23,24 +23,24 @@
#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()

View 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
@ -22,19 +22,20 @@
#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;
}

View 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
@ -22,19 +22,20 @@
#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;
}

View File

@ -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;
}

View File

@ -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;
}

View 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
@ -22,19 +22,20 @@
#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;
}

View 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
@ -22,19 +22,20 @@
#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;
}

View File

@ -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;
}

View File

@ -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;
}

View 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
@ -22,17 +22,16 @@
#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;

View 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,18 +20,30 @@
// 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;
}

View 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
}

View 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
}

View File

@ -229,7 +229,6 @@ namespace __gnu_test
}
throw;
}
}; // namespace __gnu_test
#endif // _GLIBCXX_TESTSUITE_ALLOCATOR_H