Commit acb8a4ef by Paolo Carlini Committed by Paolo Carlini

stl_memory.h: Rename to stl_auto_ptr.h.

2007-05-04  Paolo Carlini  <pcarlini@suse.de>

	* include/bits/stl_memory.h: Rename to stl_auto_ptr.h.
	(__get_temporary_buffer, get_temporary_buffer,
	return_temporary_buffer): Move...
	* include/bits/stl_tempbuf.h: ... here.
	* include/std/memory: Adjust includes.
	* testsuite/20_util/auto_ptr/assign_neg.cc: Adjust dg-error line
	numbers.
	* include/Makefile.am: Adjust.
	* include/Makefile.in: Regenerate.

	* testsuite/util/testsuite_iterators.h: Do not include the entire
	<iterator>.
	* include/bits/stl_iterator_base_types.h: Adjust includes.
	* testsuite/25_algorithms/unique_copy/2.cc: Include <functional>.

From-SVN: r124438
parent dcdc26df
2007-05-04 Paolo Carlini <pcarlini@suse.de>
* include/bits/stl_memory.h: Rename to stl_auto_ptr.h.
(__get_temporary_buffer, get_temporary_buffer,
return_temporary_buffer): Move...
* include/bits/stl_tempbuf.h: ... here.
* include/std/memory: Adjust includes.
* testsuite/20_util/auto_ptr/assign_neg.cc: Adjust dg-error line
numbers.
* include/Makefile.am: Adjust.
* include/Makefile.in: Regenerate.
* testsuite/util/testsuite_iterators.h: Do not include the entire
<iterator>.
* include/bits/stl_iterator_base_types.h: Adjust includes.
* testsuite/25_algorithms/unique_copy/2.cc: Include <functional>.
2007-05-04 Mark Mitchell <mark@codesourcery.com> 2007-05-04 Mark Mitchell <mark@codesourcery.com>
* libsupc++/atexit_arm.cc: New file. * libsupc++/atexit_arm.cc: New file.
......
...@@ -115,7 +115,7 @@ bits_headers = \ ...@@ -115,7 +115,7 @@ bits_headers = \
${bits_srcdir}/stl_iterator_base_types.h \ ${bits_srcdir}/stl_iterator_base_types.h \
${bits_srcdir}/stl_list.h \ ${bits_srcdir}/stl_list.h \
${bits_srcdir}/stl_map.h \ ${bits_srcdir}/stl_map.h \
${bits_srcdir}/stl_memory.h \ ${bits_srcdir}/stl_auto_ptr.h \
${bits_srcdir}/stl_multimap.h \ ${bits_srcdir}/stl_multimap.h \
${bits_srcdir}/stl_multiset.h \ ${bits_srcdir}/stl_multiset.h \
${bits_srcdir}/stl_numeric.h \ ${bits_srcdir}/stl_numeric.h \
......
...@@ -349,7 +349,7 @@ bits_headers = \ ...@@ -349,7 +349,7 @@ bits_headers = \
${bits_srcdir}/stl_iterator_base_types.h \ ${bits_srcdir}/stl_iterator_base_types.h \
${bits_srcdir}/stl_list.h \ ${bits_srcdir}/stl_list.h \
${bits_srcdir}/stl_map.h \ ${bits_srcdir}/stl_map.h \
${bits_srcdir}/stl_memory.h \ ${bits_srcdir}/stl_auto_ptr.h \
${bits_srcdir}/stl_multimap.h \ ${bits_srcdir}/stl_multimap.h \
${bits_srcdir}/stl_multiset.h \ ${bits_srcdir}/stl_multiset.h \
${bits_srcdir}/stl_numeric.h \ ${bits_srcdir}/stl_numeric.h \
......
// Memory implementation -*- C++ -*- // auto_ptr implementation -*- C++ -*-
// Copyright (C) 2007 Free Software Foundation, Inc. // Copyright (C) 2007 Free Software Foundation, Inc.
// //
...@@ -27,86 +27,20 @@ ...@@ -27,86 +27,20 @@
// invalidate any other reasons why the executable file might be covered by // invalidate any other reasons why the executable file might be covered by
// the GNU General Public License. // the GNU General Public License.
/** @file stl_memory.h /** @file stl_auto_ptr.h
* This is an internal header file, included by other library headers. * This is an internal header file, included by other library headers.
* You should not attempt to use it directly. * You should not attempt to use it directly.
*/ */
#ifndef _STL_MEMORY_H #ifndef _STL_AUTO_PTR_H
#define _STL_MEMORY_H 1 #define _STL_AUTO_PTR_H 1
#include <bits/stl_algobase.h> #include <bits/c++config.h>
#include <bits/allocator.h>
#include <bits/stl_construct.h>
#include <bits/stl_uninitialized.h>
#include <bits/stl_raw_storage_iter.h>
#include <debug/debug.h> #include <debug/debug.h>
_GLIBCXX_BEGIN_NAMESPACE(std) _GLIBCXX_BEGIN_NAMESPACE(std)
/** /**
* @if maint
* This is a helper function. The unused second parameter exists to
* permit the real get_temporary_buffer to use template parameter deduction.
*
* XXX This should perhaps use the pool.
* @endif
*/
template<typename _Tp>
pair<_Tp*, ptrdiff_t>
__get_temporary_buffer(ptrdiff_t __len, _Tp*)
{
const ptrdiff_t __max =
__gnu_cxx::__numeric_traits<ptrdiff_t>::__max / sizeof(_Tp);
if (__len > __max)
__len = __max;
while (__len > 0)
{
_Tp* __tmp = static_cast<_Tp*>(::operator new(__len * sizeof(_Tp),
nothrow));
if (__tmp != 0)
return pair<_Tp*, ptrdiff_t>(__tmp, __len);
__len /= 2;
}
return pair<_Tp*, ptrdiff_t>(static_cast<_Tp*>(0), 0);
}
/**
* @brief Allocates a temporary buffer.
* @param len The number of objects of type Tp.
* @return See full description.
*
* Reinventing the wheel, but this time with prettier spokes!
*
* This function tries to obtain storage for @c len adjacent Tp
* objects. The objects themselves are not constructed, of course.
* A pair<> is returned containing "the buffer s address and
* capacity (in the units of sizeof(Tp)), or a pair of 0 values if
* no storage can be obtained." Note that the capacity obtained
* may be less than that requested if the memory is unavailable;
* you should compare len with the .second return value.
*
* Provides the nothrow exception guarantee.
*/
template<typename _Tp>
inline pair<_Tp*, ptrdiff_t>
get_temporary_buffer(ptrdiff_t __len)
{ return std::__get_temporary_buffer(__len, static_cast<_Tp*>(0)); }
/**
* @brief The companion to get_temporary_buffer().
* @param p A buffer previously allocated by get_temporary_buffer.
* @return None.
*
* Frees the memory pointed to by p.
*/
template<typename _Tp>
void
return_temporary_buffer(_Tp* __p)
{ ::operator delete(__p, nothrow); }
/**
* A wrapper class to provide auto_ptr with reference semantics. * A wrapper class to provide auto_ptr with reference semantics.
* For example, an auto_ptr can be assigned (or constructed from) * For example, an auto_ptr can be assigned (or constructed from)
* the result of a function which returns an auto_ptr by value. * the result of a function which returns an auto_ptr by value.
...@@ -364,4 +298,4 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -364,4 +298,4 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
_GLIBCXX_END_NAMESPACE _GLIBCXX_END_NAMESPACE
#endif /* _STL_MEMORY_H */ #endif /* _STL_AUTO_PTR_H */
// Types used in iterator implementation -*- C++ -*- // Types used in iterator implementation -*- C++ -*-
// Copyright (C) 2001, 2002, 2004, 2005 Free Software Foundation, Inc. // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007
// Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // 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 // software; you can redistribute it and/or modify it under the
...@@ -66,6 +67,9 @@ ...@@ -66,6 +67,9 @@
#pragma GCC system_header #pragma GCC system_header
#include <bits/c++config.h>
#include <cstddef>
_GLIBCXX_BEGIN_NAMESPACE(std) _GLIBCXX_BEGIN_NAMESPACE(std)
//@{ //@{
......
...@@ -62,12 +62,75 @@ ...@@ -62,12 +62,75 @@
#ifndef _TEMPBUF_H #ifndef _TEMPBUF_H
#define _TEMPBUF_H 1 #define _TEMPBUF_H 1
#include <bits/stl_memory.h> #include <bits/stl_algobase.h>
#include <bits/stl_construct.h>
#include <bits/stl_uninitialized.h>
_GLIBCXX_BEGIN_NAMESPACE(std) _GLIBCXX_BEGIN_NAMESPACE(std)
/** /**
* @if maint * @if maint
* This is a helper function. The unused second parameter exists to
* permit the real get_temporary_buffer to use template parameter deduction.
* @endif
*/
template<typename _Tp>
pair<_Tp*, ptrdiff_t>
__get_temporary_buffer(ptrdiff_t __len, _Tp*)
{
const ptrdiff_t __max =
__gnu_cxx::__numeric_traits<ptrdiff_t>::__max / sizeof(_Tp);
if (__len > __max)
__len = __max;
while (__len > 0)
{
_Tp* __tmp = static_cast<_Tp*>(::operator new(__len * sizeof(_Tp),
std::nothrow));
if (__tmp != 0)
return std::pair<_Tp*, ptrdiff_t>(__tmp, __len);
__len /= 2;
}
return std::pair<_Tp*, ptrdiff_t>(static_cast<_Tp*>(0), 0);
}
/**
* @brief Allocates a temporary buffer.
* @param len The number of objects of type Tp.
* @return See full description.
*
* Reinventing the wheel, but this time with prettier spokes!
*
* This function tries to obtain storage for @c len adjacent Tp
* objects. The objects themselves are not constructed, of course.
* A pair<> is returned containing "the buffer s address and
* capacity (in the units of sizeof(Tp)), or a pair of 0 values if
* no storage can be obtained." Note that the capacity obtained
* may be less than that requested if the memory is unavailable;
* you should compare len with the .second return value.
*
* Provides the nothrow exception guarantee.
*/
template<typename _Tp>
inline pair<_Tp*, ptrdiff_t>
get_temporary_buffer(ptrdiff_t __len)
{ return std::__get_temporary_buffer(__len, static_cast<_Tp*>(0)); }
/**
* @brief The companion to get_temporary_buffer().
* @param p A buffer previously allocated by get_temporary_buffer.
* @return None.
*
* Frees the memory pointed to by p.
*/
template<typename _Tp>
void
return_temporary_buffer(_Tp* __p)
{ ::operator delete(__p, nothrow); }
/**
* @if maint
* This class is used in two places: stl_algo.h and ext/memory, * This class is used in two places: stl_algo.h and ext/memory,
* where it is wrapped as the temporary_buffer class. See * where it is wrapped as the temporary_buffer class. See
* temporary_buffer docs for more notes. * temporary_buffer docs for more notes.
...@@ -131,7 +194,6 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -131,7 +194,6 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
operator=(const _Temporary_buffer&); operator=(const _Temporary_buffer&);
}; };
template<typename _ForwardIterator, typename _Tp> template<typename _ForwardIterator, typename _Tp>
_Temporary_buffer<_ForwardIterator, _Tp>:: _Temporary_buffer<_ForwardIterator, _Tp>::
_Temporary_buffer(_ForwardIterator __first, _ForwardIterator __last) _Temporary_buffer(_ForwardIterator __first, _ForwardIterator __last)
...@@ -140,7 +202,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -140,7 +202,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
{ {
try try
{ {
pair<pointer, size_type> __p(get_temporary_buffer< std::pair<pointer, size_type> __p(std::get_temporary_buffer<
value_type>(_M_original_len)); value_type>(_M_original_len));
_M_buffer = __p.first; _M_buffer = __p.first;
_M_len = __p.second; _M_len = __p.second;
......
...@@ -51,8 +51,13 @@ ...@@ -51,8 +51,13 @@
#pragma GCC system_header #pragma GCC system_header
#include <bits/c++config.h> #include <bits/stl_algobase.h>
#include <bits/stl_memory.h> #include <bits/allocator.h>
#include <bits/stl_construct.h>
#include <bits/stl_uninitialized.h>
#include <bits/stl_tempbuf.h>
#include <bits/stl_auto_ptr.h>
#include <bits/stl_raw_storage_iter.h>
#ifdef __GXX_EXPERIMENTAL_CXX0X__ #ifdef __GXX_EXPERIMENTAL_CXX0X__
# include <tr1/memory> # include <tr1/memory>
......
...@@ -46,5 +46,5 @@ main() ...@@ -46,5 +46,5 @@ main()
test01(); test01();
return 0; return 0;
} }
// { dg-error "candidates" "" { target *-*-* } 207 } // { dg-error "candidates" "" { target *-*-* } 141 }
// { dg-error "::auto_ptr" "" { target *-*-* } 337 } // { dg-error "::auto_ptr" "" { target *-*-* } 271 }
// Copyright (C) 2006 Free Software Foundation, Inc. // Copyright (C) 2006, 2007 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // 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 // software; you can redistribute it and/or modify it under the
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
// 25.2.8 [lib.alg.unique] // 25.2.8 [lib.alg.unique]
#include <algorithm> #include <algorithm>
#include <functional>
#include <testsuite_hooks.h> #include <testsuite_hooks.h>
#include <testsuite_iterators.h> #include <testsuite_iterators.h>
......
// -*- C++ -*- // -*- C++ -*-
// Iterator Wrappers for the C++ library testsuite. // Iterator Wrappers for the C++ library testsuite.
// //
// Copyright (C) 2004, 2005 Free Software Foundation, Inc. // Copyright (C) 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // 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 // software; you can redistribute it and/or modify it under the
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
// test_container, which is given two pointers to T and an iterator type. // test_container, which is given two pointers to T and an iterator type.
#include <testsuite_hooks.h> #include <testsuite_hooks.h>
#include <iterator> #include <bits/stl_iterator_base_types.h>
#ifndef _TESTSUITE_ITERATORS #ifndef _TESTSUITE_ITERATORS
#define _TESTSUITE_ITERATORS #define _TESTSUITE_ITERATORS
......
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