Commit 1ff9402d by Benjamin Kosnik

[multiple changes]


2003-06-11  Benjamin Kosnik  <bkoz@redhat.com>

	* include/bits/stl_alloc.h (__debug_alloc): Move out.
	(__malloc_alloc): Same.
	(__pool_alloc): Same.
	(__new_alloc): Same.
	Rename to..
	* include/bits/allocator.h: ...this.
	* include/bits/stl_deque.h: Modify comment.
	* include/bits/stl_tree.h: Modify include.
	* include/std/std_memory.h: Same.
	* include/ext/rope: Same.
	* include/ext/slist: Same.
	* include/std/std_vector.h: Same.
	* include/std/std_stack.h: Same.
	* include/std/std_queue.h: Same.
	* include/std/std_list.h: Same.
	* include/std/std_deque.h: Same.
	* include/backward/alloc.h: Same.
	* include/ext/debug_allocator.h: New.
	* include/ext/malloc_allocator.h: New.
	* include/ext/pool_allocator.h: New.
	* include/ext/new_allocator.h: New.
	* include/bits/pthread_allocimpl.h: Remove.
	* include/bits/stl_pthread_alloc.h: Remove.
	* include/Makefile.am (ext_headers): Add.
	* include/Makefile.in: Regenerate.
	* src/stl-inst.cc: Use __gnu_cxx namespace.
	* src/stl-inst.cc: Move to...
	* src/allocator-inst.cc: Here.
	* src/Makefile.am (sources): Update.
	* src/Makefile.in: Regenerate.
	* config/linker-map.gnu: Remove __pool_alloc bits.
	* testsuite/ext/headers.cc: Add.
	* testsuite/ext/allocators.cc: Fixup.

2003-06-11  Stefan Olsson  <stefan@snon.net>
            Ola R�nnerup  <fnolis@home.se>

	* include/Makefile.am (ext_headers): Add.
	* include/Makefile.in: Regenerate.
	* include/ext/mt_allocator.h: New file.

From-SVN: r67777
parent 1d5d594d
2003-06-11 Benjamin Kosnik <bkoz@redhat.com>
* include/bits/stl_alloc.h (__debug_alloc): Move out.
(__malloc_alloc): Same.
(__pool_alloc): Same.
(__new_alloc): Same.
Rename to..
* include/bits/allocator.h: ...this.
* include/bits/stl_deque.h: Modify comment.
* include/bits/stl_tree.h: Modify include.
* include/std/std_memory.h: Same.
* include/ext/rope: Same.
* include/ext/slist: Same.
* include/std/std_vector.h: Same.
* include/std/std_stack.h: Same.
* include/std/std_queue.h: Same.
* include/std/std_list.h: Same.
* include/std/std_deque.h: Same.
* include/backward/alloc.h: Same.
* include/ext/debug_allocator.h: New.
* include/ext/malloc_allocator.h: New.
* include/ext/pool_allocator.h: New.
* include/ext/new_allocator.h: New.
* include/bits/pthread_allocimpl.h: Remove.
* include/bits/stl_pthread_alloc.h: Remove.
* include/Makefile.am (ext_headers): Add.
* include/Makefile.in: Regenerate.
* src/stl-inst.cc: Use __gnu_cxx namespace.
* src/stl-inst.cc: Move to...
* src/allocator-inst.cc: Here.
* src/Makefile.am (sources): Update.
* src/Makefile.in: Regenerate.
* config/linker-map.gnu: Remove __pool_alloc bits.
* testsuite/ext/headers.cc: Add.
* testsuite/ext/allocators.cc: Fixup.
2003-06-11 Stefan Olsson <stefan@snon.net>
Ola Rnnerup <fnolis@home.se>
* include/Makefile.am (ext_headers): Add.
* include/Makefile.in: Regenerate.
* include/ext/mt_allocator.h: New file.
2003-06-10 Paolo Carlini <pcarlini@unitus.it>
* include/bits/fstream.tcc (close): Clean up a bit.
......
......@@ -78,15 +78,6 @@ GLIBCPP_3.4 {
# bool has_facet
_ZSt9has_facet*;
# std::__pool_alloc
_ZNSt12__pool_allocILb1ELi0EE10deallocateEPv[jm]*;
_ZNSt12__pool_allocILb1ELi0EE8allocateE[jm]*;
_ZNSt12__pool_allocILb1ELi0EE5_Lock*;
_ZNSt12__pool_allocILb1ELi0EE12_S_force_newE;
_ZNSt12__pool_allocILb1ELi0EE12_S_free_listE;
_ZNSt12__pool_allocILb1ELi0EE7_S_lockE;
_ZNSt12__pool_allocILb1ELi0EE9_S_refillE[jm];
# operator new(size_t)
_Znw[jm];
# operator new(size_t, std::nothrow_t const&)
......
......@@ -103,6 +103,8 @@ std_headers_rename = \
bits_srcdir = ${glibcpp_srcdir}/include/bits
bits_builddir = ./bits
bits_headers = \
${bits_srcdir}/allocator.h \
${bits_srcdir}/allocator_traits.h \
${bits_srcdir}/basic_ios.h \
${bits_srcdir}/basic_ios.tcc \
${bits_srcdir}/basic_string.h \
......@@ -129,14 +131,12 @@ bits_headers = \
${bits_srcdir}/localefwd.h \
${bits_srcdir}/mask_array.h \
${bits_srcdir}/ostream.tcc \
${bits_srcdir}/pthread_allocimpl.h \
${bits_srcdir}/stream_iterator.h \
${bits_srcdir}/streambuf_iterator.h \
${bits_srcdir}/slice_array.h \
${bits_srcdir}/sstream.tcc \
${bits_srcdir}/stl_algo.h \
${bits_srcdir}/stl_algobase.h \
${bits_srcdir}/stl_alloc.h \
${bits_srcdir}/stl_bvector.h \
${bits_srcdir}/stl_construct.h \
${bits_srcdir}/stl_deque.h \
......@@ -151,7 +151,6 @@ bits_headers = \
${bits_srcdir}/stl_multiset.h \
${bits_srcdir}/stl_numeric.h \
${bits_srcdir}/stl_pair.h \
${bits_srcdir}/stl_pthread_alloc.h \
${bits_srcdir}/stl_queue.h \
${bits_srcdir}/stl_raw_storage_iter.h \
${bits_srcdir}/stl_relops.h \
......@@ -215,6 +214,7 @@ ext_srcdir = ${glibcpp_srcdir}/include/ext
ext_builddir = ./ext
ext_headers = \
${ext_srcdir}/algorithm \
${ext_srcdir}/debug_allocator.h \
${ext_srcdir}/enc_filebuf.h \
${ext_srcdir}/stdio_filebuf.h \
${ext_srcdir}/stdio_sync_filebuf.h \
......@@ -222,8 +222,12 @@ ext_headers = \
${ext_srcdir}/hash_map \
${ext_srcdir}/hash_set \
${ext_srcdir}/iterator \
${ext_srcdir}/malloc_allocator.h \
${ext_srcdir}/memory \
${ext_srcdir}/mt_allocator.h \
${ext_srcdir}/new_allocator.h \
${ext_srcdir}/numeric \
${ext_srcdir}/pool_allocator.h \
${ext_srcdir}/rb_tree \
${ext_srcdir}/rope \
${ext_srcdir}/ropeimpl.h \
......
......@@ -222,6 +222,8 @@ std_headers_rename = \
bits_srcdir = ${glibcpp_srcdir}/include/bits
bits_builddir = ./bits
bits_headers = \
${bits_srcdir}/allocator.h \
${bits_srcdir}/allocator_traits.h \
${bits_srcdir}/basic_ios.h \
${bits_srcdir}/basic_ios.tcc \
${bits_srcdir}/basic_string.h \
......@@ -248,14 +250,12 @@ bits_headers = \
${bits_srcdir}/localefwd.h \
${bits_srcdir}/mask_array.h \
${bits_srcdir}/ostream.tcc \
${bits_srcdir}/pthread_allocimpl.h \
${bits_srcdir}/stream_iterator.h \
${bits_srcdir}/streambuf_iterator.h \
${bits_srcdir}/slice_array.h \
${bits_srcdir}/sstream.tcc \
${bits_srcdir}/stl_algo.h \
${bits_srcdir}/stl_algobase.h \
${bits_srcdir}/stl_alloc.h \
${bits_srcdir}/stl_bvector.h \
${bits_srcdir}/stl_construct.h \
${bits_srcdir}/stl_deque.h \
......@@ -270,7 +270,6 @@ bits_headers = \
${bits_srcdir}/stl_multiset.h \
${bits_srcdir}/stl_numeric.h \
${bits_srcdir}/stl_pair.h \
${bits_srcdir}/stl_pthread_alloc.h \
${bits_srcdir}/stl_queue.h \
${bits_srcdir}/stl_raw_storage_iter.h \
${bits_srcdir}/stl_relops.h \
......@@ -336,6 +335,7 @@ ext_srcdir = ${glibcpp_srcdir}/include/ext
ext_builddir = ./ext
ext_headers = \
${ext_srcdir}/algorithm \
${ext_srcdir}/debug_allocator.h \
${ext_srcdir}/enc_filebuf.h \
${ext_srcdir}/stdio_filebuf.h \
${ext_srcdir}/stdio_sync_filebuf.h \
......@@ -343,8 +343,12 @@ ext_headers = \
${ext_srcdir}/hash_map \
${ext_srcdir}/hash_set \
${ext_srcdir}/iterator \
${ext_srcdir}/malloc_allocator.h \
${ext_srcdir}/memory \
${ext_srcdir}/mt_allocator.h \
${ext_srcdir}/new_allocator.h \
${ext_srcdir}/numeric \
${ext_srcdir}/pool_allocator.h \
${ext_srcdir}/rb_tree \
${ext_srcdir}/rope \
${ext_srcdir}/ropeimpl.h \
......
......@@ -45,15 +45,15 @@
#include "backward_warning.h"
#include <bits/c++config.h>
#include <bits/stl_alloc.h>
#include <bits/allocator.h>
#include <ext/debug_allocator.h>
#include <ext/malloc_allocator.h>
using std::__malloc_alloc;
using std::__simple_alloc;
using std::__debug_alloc;
using __gnu_cxx::__malloc_alloc;
using __gnu_cxx::__debug_alloc;
using __gnu_cxx::__pool_alloc;
using std::__alloc;
using std::__single_client_alloc;
using std::__pool_alloc;
using std::__simple_alloc;
using std::allocator;
#endif
// Allocators -*- C++ -*-
// Copyright (C) 2001, 2002, 2003 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
/*
* Copyright (c) 1996-1997
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*/
/** @file allocator.h
* This is an internal header file, included by other library headers.
* You should not attempt to use it directly.
*/
/**
* @defgroup Allocators Memory Allocators
* @if maint
* allocator.h implements some node allocators. These are NOT the same as
* allocators in the C++ standard, nor in the original H-P STL. They do not
* encapsulate different pointer types; we assume that there is only one
* pointer type. The C++ standard allocators are intended to allocate
* individual objects, not pools or arenas.
*
* In this file allocators are of two different styles: "standard" and
* "SGI" (quotes included). "Standard" allocators conform to 20.4. "SGI"
* allocators differ in AT LEAST the following ways (add to this list as you
* discover them):
*
* - "Standard" allocate() takes two parameters (n_count,hint=0) but "SGI"
* allocate() takes one paramter (n_size).
* - Likewise, "standard" deallocate()'s argument is a count, but in "SGI"
* is a byte size.
* - max_size(), construct(), and destroy() are missing in "SGI" allocators.
* - reallocate(p,oldsz,newsz) is added in "SGI", and behaves as
* if p=realloc(p,newsz).
*
* "SGI" allocators may be wrapped in __allocator to convert the interface
* into a "standard" one.
* @endif
*
* The canonical description of these classes is in docs/html/ext/howto.html
* or online at http://gcc.gnu.org/onlinedocs/libstdc++/ext/howto.html#3
*/
#ifndef _ALLOCATOR_H
#define _ALLOCATOR_H 1
#include <bits/functexcept.h> // For __throw_bad_alloc
#include <bits/allocator_traits.h>
// Pick a default underlying allocator.
#include <ext/pool_allocator.h>
namespace std
{
typedef __gnu_cxx::__pool_alloc<true, 0> __alloc;
/// The version for the default allocator.
template<typename _Tp, typename _Tp1>
struct _Alloc_traits<_Tp, allocator<_Tp1> >
{
static const bool _S_instanceless = true;
typedef __simple_alloc<_Tp, __alloc> _Alloc_type;
typedef allocator<_Tp> allocator_type;
};
//@}
}
namespace std
{
/**
* @brief The "standard" allocator, as per [20.4].
*
* The private _Alloc is "SGI" style. (See comments at the top
* of allocator.h.)
*
* The underlying allocator behaves as follows.
* - __pool_alloc is used via two typedefs
* - "__alloc" typedef is threadsafe via the locks
* - __new_alloc is used for memory requests
*
* (See @link Allocators allocators info @endlink for more.)
*/
template<typename _Tp>
class allocator
{
// The underlying allocator.
typedef __alloc _Alloc;
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef _Tp* pointer;
typedef const _Tp* const_pointer;
typedef _Tp& reference;
typedef const _Tp& const_reference;
typedef _Tp value_type;
template<typename _Tp1>
struct rebind
{ typedef allocator<_Tp1> other; };
allocator() throw() { }
allocator(const allocator&) throw() { }
template<typename _Tp1>
allocator(const allocator<_Tp1>&) throw() { }
~allocator() throw() { }
pointer
address(reference __x) const { return &__x; }
const_pointer
address(const_reference __x) const { return &__x; }
// NB: __n is permitted to be 0. The C++ standard says nothing
// about what the return value is when __n == 0.
_Tp*
allocate(size_type __n, const void* = 0)
{
_Tp* __ret = 0;
if (__n)
{
if (__n <= this->max_size())
__ret = static_cast<_Tp*>(_Alloc::allocate(__n * sizeof(_Tp)));
else
__throw_bad_alloc();
}
return __ret;
}
// __p is not permitted to be a null pointer.
void
deallocate(pointer __p, size_type __n)
{ _Alloc::deallocate(__p, __n * sizeof(_Tp)); }
size_type
max_size() const throw() { return size_t(-1) / sizeof(_Tp); }
void construct(pointer __p, const _Tp& __val) { new(__p) _Tp(__val); }
void destroy(pointer __p) { __p->~_Tp(); }
};
template<>
class allocator<void>
{
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef void* pointer;
typedef const void* const_pointer;
typedef void value_type;
template<typename _Tp1>
struct rebind
{ typedef allocator<_Tp1> other; };
};
template<typename _T1, typename _T2>
inline bool
operator==(const allocator<_T1>&, const allocator<_T2>&)
{ return true; }
template<typename _T1, typename _T2>
inline bool
operator!=(const allocator<_T1>&, const allocator<_T2>&)
{ return false; }
// Inhibit implicit instantiations for required instantiations,
// which are defined via explicit instantiations elsewhere.
// NB: This syntax is a GNU extension.
#if _GLIBCPP_EXTERN_TEMPLATE
extern template class allocator<char>;
extern template class allocator<wchar_t>;
#endif
} // namespace std
#endif
// Allocators -*- C++ -*-
// Copyright (C) 2001, 2002, 2003 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
/*
* Copyright (c) 1996-1997
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*/
#ifndef _ALLOCATOR_TRAITS_H
#define _ALLOCATOR_TRAITS_H 1
#include <cstddef>
namespace std
{
/**
* @if maint
* This is used primarily (only?) in _Alloc_traits and other places to
* help provide the _Alloc_type typedef. All it does is forward the
* requests after some minimal checking.
*
* This is neither "standard"-conforming nor "SGI". The _Alloc parameter
* must be "SGI" style.
* @endif
* (See @link Allocators allocators info @endlink for more.)
*/
template<typename _Tp, typename _Alloc>
class __simple_alloc
{
public:
static _Tp*
allocate(size_t __n)
{
_Tp* __ret = 0;
if (__n)
__ret = static_cast<_Tp*>(_Alloc::allocate(__n * sizeof(_Tp)));
return __ret;
}
static _Tp*
allocate()
{ return (_Tp*) _Alloc::allocate(sizeof (_Tp)); }
static void
deallocate(_Tp* __p, size_t __n)
{ if (0 != __n) _Alloc::deallocate(__p, __n * sizeof (_Tp)); }
static void
deallocate(_Tp* __p)
{ _Alloc::deallocate(__p, sizeof (_Tp)); }
};
/**
* @if maint
* Allocator adaptor to turn an "SGI" style allocator (e.g.,
* __alloc, __malloc_alloc) into a "standard" conforming
* allocator. Note that this adaptor does *not* assume that all
* objects of the underlying alloc class are identical, nor does it
* assume that all of the underlying alloc's member functions are
* static member functions. Note, also, that __allocator<_Tp,
* __alloc> is essentially the same thing as allocator<_Tp>.
* @endif
* (See @link Allocators allocators info @endlink for more.)
*/
template<typename _Tp, typename _Alloc>
struct __allocator
{
_Alloc __underlying_alloc;
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef _Tp* pointer;
typedef const _Tp* const_pointer;
typedef _Tp& reference;
typedef const _Tp& const_reference;
typedef _Tp value_type;
template<typename _Tp1>
struct rebind
{ typedef __allocator<_Tp1, _Alloc> other; };
__allocator() throw() { }
__allocator(const __allocator& __a) throw()
: __underlying_alloc(__a.__underlying_alloc) { }
template<typename _Tp1>
__allocator(const __allocator<_Tp1, _Alloc>& __a) throw()
: __underlying_alloc(__a.__underlying_alloc) { }
~__allocator() throw() { }
pointer
address(reference __x) const { return &__x; }
const_pointer
address(const_reference __x) const { return &__x; }
// NB: __n is permitted to be 0. The C++ standard says nothing
// about what the return value is when __n == 0.
_Tp*
allocate(size_type __n, const void* = 0)
{
_Tp* __ret = 0;
if (__n)
__ret = static_cast<_Tp*>(_Alloc::allocate(__n * sizeof(_Tp)));
return __ret;
}
// __p is not permitted to be a null pointer.
void
deallocate(pointer __p, size_type __n)
{ __underlying_alloc.deallocate(__p, __n * sizeof(_Tp)); }
size_type
max_size() const throw() { return size_t(-1) / sizeof(_Tp); }
void
construct(pointer __p, const _Tp& __val) { new(__p) _Tp(__val); }
void
destroy(pointer __p) { __p->~_Tp(); }
};
template<typename _Alloc>
struct __allocator<void, _Alloc>
{
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef void* pointer;
typedef const void* const_pointer;
typedef void value_type;
template<typename _Tp1>
struct rebind
{ typedef __allocator<_Tp1, _Alloc> other; };
};
template<typename _Tp, typename _Alloc>
inline bool
operator==(const __allocator<_Tp,_Alloc>& __a1,
const __allocator<_Tp,_Alloc>& __a2)
{ return __a1.__underlying_alloc == __a2.__underlying_alloc; }
template<typename _Tp, typename _Alloc>
inline bool
operator!=(const __allocator<_Tp, _Alloc>& __a1,
const __allocator<_Tp, _Alloc>& __a2)
{ return __a1.__underlying_alloc != __a2.__underlying_alloc; }
/**
* @if maint
* Another allocator adaptor: _Alloc_traits. This serves two purposes.
* First, make it possible to write containers that can use either "SGI"
* style allocators or "standard" allocators. Second, provide a mechanism
* so that containers can query whether or not the allocator has distinct
* instances. If not, the container can avoid wasting a word of memory to
* store an empty object. For examples of use, see stl_vector.h, etc, or
* any of the other classes derived from this one.
*
* This adaptor uses partial specialization. The general case of
* _Alloc_traits<_Tp, _Alloc> assumes that _Alloc is a
* standard-conforming allocator, possibly with non-equal instances and
* non-static members. (It still behaves correctly even if _Alloc has
* static member and if all instances are equal. Refinements affect
* performance, not correctness.)
*
* There are always two members: allocator_type, which is a standard-
* conforming allocator type for allocating objects of type _Tp, and
* _S_instanceless, a static const member of type bool. If
* _S_instanceless is true, this means that there is no difference
* between any two instances of type allocator_type. Furthermore, if
* _S_instanceless is true, then _Alloc_traits has one additional
* member: _Alloc_type. This type encapsulates allocation and
* deallocation of objects of type _Tp through a static interface; it
* has two member functions, whose signatures are
*
* - static _Tp* allocate(size_t)
* - static void deallocate(_Tp*, size_t)
*
* The size_t parameters are "standard" style (see top of
* allocator.h) in that they take counts, not sizes.
*
* @endif
* (See @link Allocators allocators info @endlink for more.)
*/
//@{
// The fully general version.
template<typename _Tp, typename _Allocator>
struct _Alloc_traits
{
static const bool _S_instanceless = false;
typedef typename _Allocator::template rebind<_Tp>::other allocator_type;
};
template<typename _Tp, typename _Allocator>
const bool _Alloc_traits<_Tp, _Allocator>::_S_instanceless;
} // namespace std
#endif
......@@ -340,7 +340,7 @@ namespace std
* and destructor allocate (but don't initialize) storage. This makes
* %exception safety easier. Second, the base class encapsulates all of
* the differences between SGI-style allocators and standard-conforming
* allocators. (See stl_alloc.h for more on this topic.) There are two
* allocators. (See allocator.h for more on this topic.) There are two
* versions: this ordinary one, and the space-saving specialization for
* instanceless allocators.
* @endif
......
......@@ -48,6 +48,8 @@
#ifndef __SGI_STL_INTERNAL_THREADS_H
#define __SGI_STL_INTERNAL_THREADS_H
#include <cstddef>
// The only supported threading model is GCC's own gthr.h abstraction layer.
#include "bits/gthr.h"
......@@ -209,7 +211,6 @@ namespace std
void operator=(const _STL_auto_lock&);
_STL_auto_lock(const _STL_auto_lock&);
} __attribute__ ((__unused__));
} // namespace std
#endif
......@@ -84,7 +84,7 @@ iterators invalidated are those referring to the deleted node.
*/
#include <bits/stl_algobase.h>
#include <bits/stl_alloc.h>
#include <bits/allocator.h>
#include <bits/stl_construct.h>
#include <bits/stl_function.h>
......
// Allocators -*- C++ -*-
// Copyright (C) 2001, 2002, 2003 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
/*
* Copyright (c) 1996-1997
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*/
/** @file ext/debug_allocator.h
* This file is a GNU extension to the Standard C++ Library.
* You should only include this header if you are using GCC 3 or later.
*/
#ifndef _DEBUG_ALLOCATOR_H
#define _DEBUG_ALLOCATOR_H 1
#include <bits/allocator_traits.h>
namespace __gnu_cxx
{
/**
* @if maint
* An adaptor for an underlying allocator (_Alloc) to check the size
* arguments for debugging.
*
* "There is some evidence that this can confuse Purify." - SGI comment
*
* This adaptor is "SGI" style. The _Alloc parameter must also be "SGI".
* @endif
* (See @link Allocators allocators info @endlink for more.)
*/
template<typename _Alloc>
class __debug_alloc
{
private:
// Size of space used to store size. Note that this must be
// large enough to preserve alignment.
enum {_S_extra = 8};
public:
static void*
allocate(size_t __n)
{
char* __result = (char*)_Alloc::allocate(__n + (int) _S_extra);
*(size_t*)__result = __n;
return __result + (int) _S_extra;
}
static void
deallocate(void* __p, size_t __n)
{
char* __real_p = (char*)__p - (int) _S_extra;
if (*(size_t*)__real_p != __n)
abort();
_Alloc::deallocate(__real_p, __n + (int) _S_extra);
}
};
//@{
/** Comparison operators for all of the predifined SGI-style allocators.
* This ensures that __allocator<malloc_alloc> (for example) will work
* correctly. As required, all allocators compare equal.
*/
template<typename _Alloc>
inline bool
operator==(const __debug_alloc<_Alloc>&, const __debug_alloc<_Alloc>&)
{ return true; }
template<typename _Alloc>
inline bool
operator!=(const __debug_alloc<_Alloc>&, const __debug_alloc<_Alloc>&)
{ return false; }
//@}
} // namespace __gnu_cxx
namespace std
{
//@{
/// Versions for the predefined "SGI" style allocators.
template<typename _Tp, typename _Alloc>
struct _Alloc_traits<_Tp, __gnu_cxx::__debug_alloc<_Alloc> >
{
static const bool _S_instanceless = true;
typedef __gnu_cxx::__debug_alloc<_Alloc> base_alloc_type;
typedef __simple_alloc<_Tp, base_alloc_type> _Alloc_type;
typedef __allocator<_Tp, base_alloc_type> allocator_type;
};
//@}
//@{
/// Versions for the __allocator adaptor used with the predefined
/// "SGI" style allocators.
template<typename _Tp, typename _Tp1, typename _Alloc>
struct _Alloc_traits<_Tp, __allocator<_Tp1,
__gnu_cxx::__debug_alloc<_Alloc> > >
{
static const bool _S_instanceless = true;
typedef __gnu_cxx::__debug_alloc<_Alloc> base_alloc_type;
typedef __simple_alloc<_Tp, base_alloc_type> _Alloc_type;
typedef __allocator<_Tp, base_alloc_type> allocator_type;
};
//@}
} // namespace std
#endif
// Allocators -*- C++ -*-
// Copyright (C) 2001, 2002, 2003 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
/*
* Copyright (c) 1996-1997
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*/
/** @file ext/debug_allocator.h
* This file is a GNU extension to the Standard C++ Library.
* You should only include this header if you are using GCC 3 or later.
*/
#ifndef _MALLOC_ALLOCATOR_H
#define _MALLOC_ALLOCATOR_H 1
#include <bits/allocator_traits.h>
namespace __gnu_cxx
{
/**
* @if maint
* A malloc-based allocator. Typically slower than the
* __pool_alloc (below). Typically thread-safe and more
* storage efficient. The template argument is unused and is only present
* to permit multiple instantiations (but see __pool_alloc
* for caveats). "SGI" style, plus __set_malloc_handler for OOM conditions.
* @endif
* (See @link Allocators allocators info @endlink for more.)
*/
template<int __inst>
class __malloc_alloc
{
private:
static void* _S_oom_malloc(size_t);
static void (* __malloc_alloc_oom_handler)();
public:
static void*
allocate(size_t __n)
{
void* __result = malloc(__n);
if (__builtin_expect(__result == 0, 0))
__result = _S_oom_malloc(__n);
return __result;
}
static void
deallocate(void* __p, size_t /* __n */)
{ free(__p); }
static void (* __set_malloc_handler(void (*__f)()))()
{
void (* __old)() = __malloc_alloc_oom_handler;
__malloc_alloc_oom_handler = __f;
return __old;
}
};
// malloc_alloc out-of-memory handling
template<int __inst>
void (* __malloc_alloc<__inst>::__malloc_alloc_oom_handler)() = 0;
template<int __inst>
void*
__malloc_alloc<__inst>::
_S_oom_malloc(size_t __n)
{
void (* __my_malloc_handler)();
void* __result;
for (;;)
{
__my_malloc_handler = __malloc_alloc_oom_handler;
if (__builtin_expect(__my_malloc_handler == 0, 0))
__throw_bad_alloc();
(*__my_malloc_handler)();
__result = malloc(__n);
if (__result)
return __result;
}
}
//@{
/** Comparison operators for all of the predifined SGI-style allocators.
* This ensures that __allocator<malloc_alloc> (for example) will work
* correctly. As required, all allocators compare equal.
*/
template<int inst>
inline bool
operator==(const __malloc_alloc<inst>&, const __malloc_alloc<inst>&)
{ return true; }
template<int __inst>
inline bool
operator!=(const __malloc_alloc<__inst>&, const __malloc_alloc<__inst>&)
{ return false; }
//@}
} // namespace __gnu_cxx
namespace std
{
//@{
/// Versions for the predefined "SGI" style allocators.
template<typename _Tp, int __inst>
struct _Alloc_traits<_Tp, __gnu_cxx::__malloc_alloc<__inst> >
{
static const bool _S_instanceless = true;
typedef __gnu_cxx:: __malloc_alloc<__inst> base_alloc_type;
typedef __simple_alloc<_Tp, base_alloc_type> _Alloc_type;
typedef __allocator<_Tp, base_alloc_type> allocator_type;
};
//@}
//@{
/// Versions for the __allocator adaptor used with the predefined
/// "SGI" style allocators.
template<typename _Tp, typename _Tp1, int __inst>
struct _Alloc_traits<_Tp, __allocator<_Tp1,
__gnu_cxx::__malloc_alloc<__inst> > >
{
static const bool _S_instanceless = true;
typedef __gnu_cxx:: __malloc_alloc<__inst> base_alloc_type;
typedef __simple_alloc<_Tp, base_alloc_type> _Alloc_type;
typedef __allocator<_Tp, base_alloc_type> allocator_type;
};
//@}
} // namespace std
#endif
// Allocators -*- C++ -*-
// Copyright (C) 2001, 2002, 2003 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
#ifndef _NEW_ALLOCATOR_H
#define _NEW_ALLOCATOR_H 1
#include <new>
namespace __gnu_cxx
{
/**
* @if maint
* A new-based allocator, as required by the standard. Allocation and
* deallocation forward to global new and delete. "SGI" style, minus
* reallocate().
* @endif
* (See @link Allocators allocators info @endlink for more.)
*/
class __new_alloc
{
public:
static void*
allocate(size_t __n)
{ return ::operator new(__n); }
static void
deallocate(void* __p, size_t)
{ ::operator delete(__p); }
};
} // namespace __gnu_cxx
#endif
......@@ -53,7 +53,7 @@
#include <bits/stl_algo.h>
#include <bits/stl_function.h>
#include <bits/stl_numeric.h>
#include <bits/stl_alloc.h>
#include <bits/allocator.h>
#include <bits/stl_construct.h>
#include <bits/stl_uninitialized.h>
#include <ext/hash_fun.h>
......
......@@ -51,7 +51,7 @@
#define _SLIST 1
#include <bits/stl_algobase.h>
#include <bits/stl_alloc.h>
#include <bits/allocator.h>
#include <bits/stl_construct.h>
#include <bits/stl_uninitialized.h>
#include <bits/concept_check.h>
......
......@@ -65,7 +65,7 @@
#include <bits/functexcept.h>
#include <bits/stl_algobase.h>
#include <bits/stl_alloc.h>
#include <bits/allocator.h>
#include <bits/stl_construct.h>
#include <bits/stl_uninitialized.h>
#include <bits/stl_deque.h>
......
......@@ -65,7 +65,7 @@
#include <bits/functexcept.h>
#include <bits/stl_algobase.h>
#include <bits/stl_alloc.h>
#include <bits/allocator.h>
#include <bits/stl_construct.h>
#include <bits/stl_uninitialized.h>
#include <bits/stl_list.h>
......
......@@ -52,7 +52,7 @@
#pragma GCC system_header
#include <bits/stl_algobase.h>
#include <bits/stl_alloc.h>
#include <bits/allocator.h>
#include <bits/stl_construct.h>
#include <bits/stl_iterator_base_types.h> //for iterator_traits
#include <bits/stl_uninitialized.h>
......
......@@ -65,7 +65,7 @@
#include <bits/c++config.h>
#include <bits/functexcept.h>
#include <bits/stl_algobase.h>
#include <bits/stl_alloc.h>
#include <bits/allocator.h>
#include <bits/stl_construct.h>
#include <bits/stl_uninitialized.h>
#include <bits/stl_vector.h>
......
......@@ -64,7 +64,7 @@
#pragma GCC system_header
#include <bits/stl_algobase.h>
#include <bits/stl_alloc.h>
#include <bits/allocator.h>
#include <bits/stl_construct.h>
#include <bits/stl_uninitialized.h>
#include <bits/stl_deque.h>
......
......@@ -65,7 +65,7 @@
#include <bits/functexcept.h>
#include <bits/stl_algobase.h>
#include <bits/stl_alloc.h>
#include <bits/allocator.h>
#include <bits/stl_construct.h>
#include <bits/stl_uninitialized.h>
#include <bits/stl_vector.h>
......
......@@ -117,6 +117,7 @@ basic_file.cc: ${glibcpp_srcdir}/@BASIC_FILE_CC@
# Sources present in the src directory.
sources = \
allocator-inst.cc \
codecvt.cc \
complex_io.cc \
concept-inst.cc \
......@@ -137,7 +138,6 @@ sources = \
ostream-inst.cc \
sstream-inst.cc \
stdexcept.cc \
stl-inst.cc \
streambuf-inst.cc \
string-inst.cc \
strstream.cc \
......
......@@ -121,6 +121,7 @@ enable_shared = @enable_shared@
enable_static = @enable_static@
glibcpp_CXX = @glibcpp_CXX@
glibcpp_MOFILES = @glibcpp_MOFILES@
glibcpp_PCHFLAGS = @glibcpp_PCHFLAGS@
glibcpp_POFILES = @glibcpp_POFILES@
glibcpp_basedir = @glibcpp_basedir@
glibcpp_localedir = @glibcpp_localedir@
......@@ -199,6 +200,7 @@ target_sources_extra = \
# Sources present in the src directory.
sources = \
allocator-inst.cc \
codecvt.cc \
complex_io.cc \
concept-inst.cc \
......@@ -219,7 +221,6 @@ sources = \
ostream-inst.cc \
sstream-inst.cc \
stdexcept.cc \
stl-inst.cc \
streambuf-inst.cc \
string-inst.cc \
strstream.cc \
......@@ -304,15 +305,15 @@ DEFS = @DEFS@ -I. -I$(srcdir) -I..
CPPFLAGS = @CPPFLAGS@
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
libstdc___la_OBJECTS = codecvt.lo complex_io.lo concept-inst.lo \
ctype.lo demangle.lo ext-inst.lo fstream-inst.lo functexcept.lo \
globals.lo io-inst.lo ios.lo istream-inst.lo limits.lo locale.lo \
locale-inst.lo localename.lo misc-inst.lo ostream-inst.lo \
sstream-inst.lo stdexcept.lo stl-inst.lo streambuf-inst.lo \
string-inst.lo strstream.lo valarray-inst.lo wstring-inst.lo \
codecvt_members.lo collate_members.lo ctype_members.lo \
messages_members.lo monetary_members.lo numeric_members.lo \
time_members.lo basic_file.lo c++locale.lo
libstdc___la_OBJECTS = allocator-inst.lo codecvt.lo complex_io.lo \
concept-inst.lo ctype.lo demangle.lo ext-inst.lo fstream-inst.lo \
functexcept.lo globals.lo io-inst.lo ios.lo istream-inst.lo limits.lo \
locale.lo locale-inst.lo localename.lo misc-inst.lo ostream-inst.lo \
sstream-inst.lo stdexcept.lo streambuf-inst.lo string-inst.lo \
strstream.lo valarray-inst.lo wstring-inst.lo codecvt_members.lo \
collate_members.lo ctype_members.lo messages_members.lo \
monetary_members.lo numeric_members.lo time_members.lo basic_file.lo \
c++locale.lo
CXXFLAGS = @CXXFLAGS@
CXXCOMPILE = $(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
CXXLD = $(CXX)
......
// Wrapper of pthread allocation header -*- C++ -*-
// Explicit instantiation file.
// Copyright (C) 2001 Free Software Foundation, Inc.
// Copyright (C) 1999, 2001, 2002, 2003 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
......@@ -27,34 +27,15 @@
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
/*
* Copyright (c) 1996-1997
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*/
/** @file stl_pthread_alloc.h
* This is an internal header file, included by other library headers.
* You should not attempt to use it directly.
*/
#ifndef _CPP_BITS_STL_PTHREAD_ALLOC_H
#define _CPP_BITS_STL_PTHREAD_ALLOC_H 1
#include <bits/pthread_allocimpl.h>
using std::_Pthread_alloc_template;
using std::pthread_alloc;
//
// ISO C++ 14882:
//
#endif /* _CPP_BITS_STL_PTHREAD_ALLOC_H */
#include <bits/c++config.h>
#include <memory>
// Local Variables:
// mode:C++
// End:
namespace std
{
template class allocator<char>;
template class allocator<wchar_t>;
} // namespace std
// 2001-11-25 Phil Edwards <pme@gcc.gnu.org>
//
// Copyright (C) 2001 Free Software Foundation, Inc.
// Copyright (C) 2001, 2003 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,23 +20,21 @@
// 20.4.1.1 allocator members
#include <memory>
#include <cstdlib>
#include <memory>
#include <ext/pool_allocator.h>
#include <ext/debug_allocator.h>
#include <ext/malloc_allocator.h>
#include <testsuite_hooks.h>
typedef std::__malloc_alloc<3> weird_alloc;
template class std::__malloc_alloc<3>;
typedef std::__debug_alloc<weird_alloc> debug_weird_alloc;
template class std::__debug_alloc<weird_alloc>;
typedef std::__pool_alloc<true, 3> unshared_normal_alloc;
template class std::__pool_alloc<true, 3>;
typedef std::__pool_alloc<false, 3> unshared_singlethreaded;
template class std::__pool_alloc<false, 3>;
using __gnu_cxx::__malloc_alloc;
using __gnu_cxx::__debug_alloc;
using __gnu_cxx::__pool_alloc;
//std::malloc_alloc test_malloc_alloc;
template class __malloc_alloc<3>;
template class __debug_alloc<__malloc_alloc<3> >;
template class __pool_alloc<true, 3>;
template class __pool_alloc<false, 3>;
struct big
{
......@@ -63,32 +61,32 @@ operator delete(void *v) throw()
return std::free(v);
}
template <typename arbitrary_SGIstyle_allocator,
bool uses_global_new_and_delete>
void test()
template<typename Alloc, bool uses_global_new_and_delete>
void check_allocator()
{
bool test = true;
new_called = false;
delete_called = false;
requested = 0;
std::__allocator<big, arbitrary_SGIstyle_allocator> a;
std::__allocator<big, Alloc> a;
big *p = a.allocate(10);
if (uses_global_new_and_delete) VERIFY (requested >= (10*15*sizeof(long)));
if (uses_global_new_and_delete)
VERIFY( requested >= (10 * 15 * sizeof(long)) );
// Touch the far end of supposedly-allocated memory to check that we got
// all of it. Why "3"? Because it's my favorite integer between e and pi.
p[9].f[14] = 3;
VERIFY (new_called == uses_global_new_and_delete );
VERIFY( new_called == uses_global_new_and_delete );
a.deallocate(p,10);
VERIFY (delete_called == uses_global_new_and_delete );
VERIFY( delete_called == uses_global_new_and_delete );
}
// These just help tracking down error messages.
void test01() { test<weird_alloc,false>(); }
void test02() { test<debug_weird_alloc,false>(); }
void test03() { test<unshared_normal_alloc,true>(); }
void test04() { test<unshared_singlethreaded,true>(); }
void test01() { check_allocator<__malloc_alloc<3>, false>(); }
void test02() { check_allocator<__debug_alloc<__malloc_alloc<3> >, false>(); }
void test03() { check_allocator<__pool_alloc<true, 3>, true>(); }
void test04() { check_allocator<__pool_alloc<false, 3>, true>(); }
int main()
{
......@@ -96,7 +94,6 @@ int main()
test02();
test03();
test04();
return 0;
}
// 1999-06-23 bkoz
// Copyright (C) 1999, 2001 Free Software Foundation, Inc.
// Copyright (C) 1999, 2001, 2003 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
......@@ -33,5 +33,11 @@
#include <ext/rb_tree>
#include <ext/rope>
#include <ext/slist>
#include <ext/debug_allocator.h>
#include <ext/malloc_allocator.h>
#include <ext/mt_allocator.h>
#include <ext/pool_allocator.h>
#include <ext/stdio_filebuf.h>
#include <ext/stdio_sync_filebuf.h>
int main() { }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment