From: Benjamin Kosnik Date: Thu, 7 Oct 2004 22:06:23 +0000 (+0000) Subject: tr1: New. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3febde356c3b2393bd6b62058618ed90ed0c1f4e;p=platform%2Fupstream%2Fgcc.git tr1: New. 2004-10-07 Benjamin Kosnik * include/tr1: New. * include/tr1/array: New. * include/Makefile.am (tr1_headers): New. (stamp-tr1): New. (install-headers): New. (allstamped): Add stamp-tr1. * include/ext/array_allocator.h: New. * include/Makefile.am: Add. * include/Makefile.in: Regenerate. * testsuite/ext/array_allocator/1.cc: New. * testsuite/ext/array_allocator/2.cc: New. From-SVN: r88711 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 4ff8dcd..daae169 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,18 @@ +2004-10-07 Benjamin Kosnik + + * include/tr1: New. + * include/tr1/array: New. + * include/Makefile.am (tr1_headers): New. + (stamp-tr1): New. + (install-headers): New. + (allstamped): Add stamp-tr1. + + * include/ext/array_allocator.h: New. + * include/Makefile.am: Add. + * include/Makefile.in: Regenerate. + * testsuite/ext/array_allocator/1.cc: New. + * testsuite/ext/array_allocator/2.cc: New. + 2004-10-07 Richard Earnshaw * testsuite/lib/libstdc++.exp (libstdc++_exit): New proc. diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am index 2ab53ee..ffa16d5 100644 --- a/libstdc++-v3/include/Makefile.am +++ b/libstdc++-v3/include/Makefile.am @@ -201,6 +201,7 @@ ext_srcdir = ${glibcxx_srcdir}/include/ext ext_builddir = ./ext ext_headers = \ ${ext_srcdir}/algorithm \ + ${ext_srcdir}/array_allocator.h \ ${ext_srcdir}/bitmap_allocator.h \ ${ext_srcdir}/debug_allocator.h \ ${ext_srcdir}/enc_filebuf.h \ @@ -224,6 +225,11 @@ ext_headers = \ ${ext_srcdir}/hash_fun.h \ ${ext_srcdir}/hashtable.h +tr1_srcdir = ${glibcxx_srcdir}/include/tr1 +tr1_builddir = ./tr1 +tr1_headers = \ + ${tr1_srcdir}/array + # This is the common subset of files that all three "C" header models use. c_base_srcdir = $(C_INCLUDE_DIR) c_base_builddir = . @@ -380,7 +386,7 @@ endif # CLEANFILES and all-local are kept up-to-date. allstamped = \ stamp-std stamp-bits stamp-c_base stamp-c_compatibility \ - stamp-backward stamp-ext stamp-debug stamp-host + stamp-backward stamp-ext stamp-tr1 stamp-debug stamp-host # List of all files that are created by explicit building, editing, or # catenation. @@ -459,6 +465,16 @@ stamp-ext: ${ext_headers} fi ;\ $(STAMP) stamp-ext + +stamp-tr1: ${tr1_headers} + @if [ ! -d "${tr1_builddir}" ]; then \ + mkdir -p ${tr1_builddir} ;\ + fi ;\ + if [ ! -f stamp-tr1 ]; then \ + (cd ${tr1_builddir} && $(LN_S) $? . || true) ;\ + fi ;\ + $(STAMP) stamp-tr1 + stamp-debug: ${debug_headers} @if [ ! -d "${debug_builddir}" ]; then \ mkdir -p ${debug_builddir} ;\ @@ -596,6 +612,9 @@ install-headers: $(mkinstalldirs) $(DESTDIR)${gxx_include_dir}/${ext_builddir} for file in ${ext_headers}; do \ $(INSTALL_DATA) $${file} $(DESTDIR)${gxx_include_dir}/${ext_builddir}; done + $(mkinstalldirs) $(DESTDIR)${gxx_include_dir}/${tr1_builddir} + for file in ${tr1_headers}; do \ + $(INSTALL_DATA) $${file} $(DESTDIR)${gxx_include_dir}/${tr1_builddir}; done $(mkinstalldirs) $(DESTDIR)${gxx_include_dir}/${c_base_builddir} for file in ${c_base_headers_rename}; do \ $(INSTALL_DATA) ${c_base_builddir}/$${file} $(DESTDIR)${gxx_include_dir}/${c_base_builddir}; done diff --git a/libstdc++-v3/include/Makefile.in b/libstdc++-v3/include/Makefile.in index bc35f0c..4a2ec86 100644 --- a/libstdc++-v3/include/Makefile.in +++ b/libstdc++-v3/include/Makefile.in @@ -418,6 +418,7 @@ ext_srcdir = ${glibcxx_srcdir}/include/ext ext_builddir = ./ext ext_headers = \ ${ext_srcdir}/algorithm \ + ${ext_srcdir}/array_allocator.h \ ${ext_srcdir}/bitmap_allocator.h \ ${ext_srcdir}/debug_allocator.h \ ${ext_srcdir}/enc_filebuf.h \ @@ -441,6 +442,11 @@ ext_headers = \ ${ext_srcdir}/hash_fun.h \ ${ext_srcdir}/hashtable.h +tr1_srcdir = ${glibcxx_srcdir}/include/tr1 +tr1_builddir = ./tr1 +tr1_headers = \ + ${tr1_srcdir}/array + # This is the common subset of files that all three "C" header models use. c_base_srcdir = $(C_INCLUDE_DIR) @@ -593,7 +599,7 @@ PCHFLAGS = -Winvalid-pch -Wno-deprecated -x c++-header $(CXXFLAGS) # CLEANFILES and all-local are kept up-to-date. allstamped = \ stamp-std stamp-bits stamp-c_base stamp-c_compatibility \ - stamp-backward stamp-ext stamp-debug stamp-host + stamp-backward stamp-ext stamp-tr1 stamp-debug stamp-host # List of all files that are created by explicit building, editing, or @@ -841,6 +847,15 @@ stamp-ext: ${ext_headers} fi ;\ $(STAMP) stamp-ext +stamp-tr1: ${tr1_headers} + @if [ ! -d "${tr1_builddir}" ]; then \ + mkdir -p ${tr1_builddir} ;\ + fi ;\ + if [ ! -f stamp-tr1 ]; then \ + (cd ${tr1_builddir} && $(LN_S) $? . || true) ;\ + fi ;\ + $(STAMP) stamp-tr1 + stamp-debug: ${debug_headers} @if [ ! -d "${debug_builddir}" ]; then \ mkdir -p ${debug_builddir} ;\ @@ -972,6 +987,9 @@ install-headers: $(mkinstalldirs) $(DESTDIR)${gxx_include_dir}/${ext_builddir} for file in ${ext_headers}; do \ $(INSTALL_DATA) $${file} $(DESTDIR)${gxx_include_dir}/${ext_builddir}; done + $(mkinstalldirs) $(DESTDIR)${gxx_include_dir}/${tr1_builddir} + for file in ${tr1_headers}; do \ + $(INSTALL_DATA) $${file} $(DESTDIR)${gxx_include_dir}/${tr1_builddir}; done $(mkinstalldirs) $(DESTDIR)${gxx_include_dir}/${c_base_builddir} for file in ${c_base_headers_rename}; do \ $(INSTALL_DATA) ${c_base_builddir}/$${file} $(DESTDIR)${gxx_include_dir}/${c_base_builddir}; done diff --git a/libstdc++-v3/include/ext/array_allocator.h b/libstdc++-v3/include/ext/array_allocator.h new file mode 100644 index 0000000..22564c8 --- /dev/null +++ b/libstdc++-v3/include/ext/array_allocator.h @@ -0,0 +1,141 @@ +// array allocator -*- C++ -*- + +// Copyright (C) 2004 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 _ARRAY_ALLOCATOR_H +#define _ARRAY_ALLOCATOR_H 1 + +#include +#include +#include + +namespace __gnu_cxx +{ + template + class array_allocator_base + { + 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; + + pointer + address(reference __x) const { return &__x; } + + const_pointer + address(const_reference __x) const { return &__x; } + + void + deallocate(pointer __p, size_type) + { + // Does nothing. + } + + size_type + max_size() const throw() + { return size_t(-1) / sizeof(_Tp); } + + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 402. wrong new expression in [some_] allocator::construct + void + construct(pointer __p, const _Tp& __val) + { ::new(__p) value_type(__val); } + + void + destroy(pointer __p) { __p->~_Tp(); } + }; + + /** + * @brief An allocator that uses previously allocated memory. + * This memory can be externally, globally, or otherwise allocated. + * + * (See @link Allocators allocators info @endlink for more.) + */ + template > + class array_allocator : public array_allocator_base<_Tp> + { + 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; + + typedef _Array array_type; + + array_type* _M_array; + + template + struct rebind + { typedef array_allocator<_Tp1, _Array1> other; }; + + array_allocator(array_type* __array = NULL) throw() + : _M_array(__array) + { } + + array_allocator(const array_allocator& __o) throw() + : _M_array(__o._M_array) { } + + template + array_allocator(const array_allocator<_Tp1, _Array1>&) throw() + : _M_array(NULL) { } + + ~array_allocator() throw() { } + + pointer + allocate(size_type __n, const void* = 0) + { + static size_type used; + if (__builtin_expect(used > array_type::_S_index, false)) + throw std::bad_alloc(); + pointer __ret = _M_array->begin() + used; + used += __n; + return __ret; + } + }; + + template + inline bool + operator==(const array_allocator<_Tp, _Array>&, + const array_allocator<_Tp, _Array>&) + { return true; } + + template + inline bool + operator!=(const array_allocator<_Tp, _Array>&, + const array_allocator<_Tp, _Array>&) + { return false; } +} // namespace __gnu_cxx + +#endif diff --git a/libstdc++-v3/include/tr1/array b/libstdc++-v3/include/tr1/array new file mode 100644 index 0000000..e41fced --- /dev/null +++ b/libstdc++-v3/include/tr1/array @@ -0,0 +1,200 @@ +// class template array -*- C++ -*- + +// Copyright (C) 2004 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 _ARRAY +#define _ARRAY 1 + +#include +#include + +//namespace std::tr1 +namespace std +{ +namespace tr1 +{ + // [6.2.2] Class template array template + // Requires complete type _Tp. + // Use of char array allows _Tp to skirt default constructable requirement. + template + struct array + { + enum { _S_index = _Nm }; + + typedef _Tp value_type; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef value_type* iterator; + typedef const value_type* const_iterator; + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef std::reverse_iterator reverse_iterator; + typedef std::reverse_iterator const_reverse_iterator; + typedef char layout_type[sizeof(_Tp)] __attribute__ ((aligned(__alignof__(_Tp)))); + + layout_type _M_instance[_Nm]; + + // No explicit construct/copy/destroy for aggregate type. + + void + assign(const value_type& u); + + void + swap(array&); + + // Iterators. + iterator + begin() + { return reinterpret_cast(&_M_instance[0]); } + + const_iterator + begin() const + { return reinterpret_cast(&_M_instance[0]); } + + iterator + end() + { return reinterpret_cast(&_M_instance[_S_index - 1]); } + + const_iterator + end() const + { return reinterpret_cast(&_M_instance[_S_index - 1]); } + + reverse_iterator + rbegin() + { return reverse_iterator(this->end()); } + + const_reverse_iterator + rbegin() const + { return const_reverse_iterator(this->end()); } + + reverse_iterator + rend() + { return reverse_iterator(this->begin()); } + + const_reverse_iterator + rend() const + { return const_reverse_iterator(this->begin()); } + + // Capacity. + size_type + size() const { return _S_index; } + + size_type + max_size() const + { + // XXX Not specified. Unnecessary, this is fixed-size. + return _S_index; + } + + bool + empty() const; + + // Element access. + reference + operator[](size_type __n) + { return reinterpret_cast(_M_instance[__n]); } + + const_reference + operator[](size_type __n) const + { return reinterpret_cast(_M_instance[__n]); } + + const_reference + at(size_type __n) const + { + if (__builtin_expect(__n > _S_index, false)) + throw std::bad_alloc(); + return reinterpret_cast(_M_instance[__n]); + } + + reference + at(size_type __n) + { + if (__builtin_expect(__n > _S_index, false)) + throw std::bad_alloc(); + return reinterpret_cast(_M_instance[__n]); + } + + reference + front(); + + const_reference + front() const; + + reference + back(); + + const_reference + back() const; + + _Tp* + data(); + + const _Tp* + data() const; + }; + + // Array comparisons. + template + bool + operator==(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) + { return false; } + + template + bool + operator!=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) + { return !(__one == __two); } + + template + bool + operator<(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) + { return false; } + + template + bool + operator>(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) + { return false; } + + template + bool + operator<=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) + { return false; } + + template + bool + operator>=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) + { return false; } + + // [6.2.2.2] Specialized algorithms. + template + void + swap(array<_Tp, _Nm>& __one, array<_Tp, _Nm>& __two) + { swap_ranges(__one.begin(), __one.end(), __two.begin()); } +} // namespace std::tr1 +} + +#endif diff --git a/libstdc++-v3/testsuite/ext/array_allocator/1.cc b/libstdc++-v3/testsuite/ext/array_allocator/1.cc new file mode 100644 index 0000000..68cbc73 --- /dev/null +++ b/libstdc++-v3/testsuite/ext/array_allocator/1.cc @@ -0,0 +1,65 @@ +// Copyright (C) 2004 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. + +#include +#include +#include + +typedef char char_type; +typedef std::char_traits traits_type; +typedef std::tr1::array array_type; + +array_type extern_array; + +void test01() +{ + using std::basic_string; + typedef __gnu_cxx::array_allocator allocator_type; + typedef basic_string string_type; + + allocator_type a(&extern_array); + string_type s(a); + + try + { + s.reserve(4); // Actually need 4 + 1 + sizeof(std::string::_Rep). + } + catch(std::bad_alloc& obj) + { + assert(true); + } + catch(...) + { + assert(false); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/ext/array_allocator/2.cc b/libstdc++-v3/testsuite/ext/array_allocator/2.cc new file mode 100644 index 0000000..2d757b5 --- /dev/null +++ b/libstdc++-v3/testsuite/ext/array_allocator/2.cc @@ -0,0 +1,72 @@ +// Copyright (C) 2004 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. + +#include +#include +#include +#include + +typedef char char_type; +typedef std::char_traits traits_type; +typedef std::tr1::array array_type; + +array_type extern_array; + +void test01() +{ + using std::basic_string; + typedef __gnu_cxx::array_allocator allocator_type; + typedef basic_string string_type; + + size_t index = array_type::_S_index; + allocator_type a(&extern_array); + string_type s(a); + + try + { + s.reserve(4); // Actually need 4 + 1 + sizeof(std::string::_Rep). + } + catch(std::bad_alloc& obj) + { + assert(false); + } + catch(...) + { + assert(false); + } + + s.append(1, 'c'); + s.append(2, 'b'); + + std::cout << s.c_str() << std::endl; +} + +int main() +{ + test01(); + return 0; +}