aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3
diff options
context:
space:
mode:
authorPaolo Carlini <pcarlini@suse.de>2005-05-28 21:57:03 +0000
committerPaolo Carlini <paolo@gcc.gnu.org>2005-05-28 21:57:03 +0000
commit6be8b52474f98eab9b3c490169627b9d1ece43df (patch)
tree81a0d6886d0cf976642a98f38627e30489df1086 /libstdc++-v3
parent76b8a7a14335e0b10318353efff63b90898ff8ce (diff)
downloadgcc-6be8b52474f98eab9b3c490169627b9d1ece43df.zip
gcc-6be8b52474f98eab9b3c490169627b9d1ece43df.tar.gz
gcc-6be8b52474f98eab9b3c490169627b9d1ece43df.tar.bz2
revert: re PR libstdc++/19495 (basic_string::_M_rep() can produce an unnaturally aligned pointer to _Rep)
2005-05-28 Paolo Carlini <pcarlini@suse.de> Revert: 2005-05-18 Paolo Carlini <pcarlini@suse.de> Nathan Myers <ncm@cantrip.org> PR libstdc++/19495 * include/bits/basic_string.h (_Raw_bytes_alloc): Rebind to size_type instead of char and rename to _Raw_alloc. * include/bits/basic_string.tcc (_Rep::_M_destroy, _Rep::_S_create): Use the above. * src/bitmap_allocator.cc: Add instantiation for size_type. * src/mt_allocator.cc: Likewise. * src/pool_allocator.cc: Likewise. * include/ext/array_allocator.h: Tweak slightly, avoid assuming the existence of an _Array::begin() and size() members. * testsuite/ext/array_allocator/2.cc: Tweak to use an allocator of size_type, instead of char, thus avoiding problems with rebinds, not treated correctly by array_allocator. From-SVN: r100304
Diffstat (limited to 'libstdc++-v3')
-rw-r--r--libstdc++-v3/ChangeLog20
-rw-r--r--libstdc++-v3/include/bits/basic_string.h2
-rw-r--r--libstdc++-v3/include/bits/basic_string.tcc20
-rw-r--r--libstdc++-v3/include/ext/array_allocator.h5
-rw-r--r--libstdc++-v3/src/bitmap_allocator.cc4
-rw-r--r--libstdc++-v3/src/mt_allocator.cc5
-rw-r--r--libstdc++-v3/src/pool_allocator.cc1
-rw-r--r--libstdc++-v3/testsuite/ext/array_allocator/2.cc12
8 files changed, 39 insertions, 30 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 64db402..a572b0b 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,23 @@
+2005-05-28 Paolo Carlini <pcarlini@suse.de>
+
+ Revert:
+ 2005-05-18 Paolo Carlini <pcarlini@suse.de>
+ Nathan Myers <ncm@cantrip.org>
+
+ PR libstdc++/19495
+ * include/bits/basic_string.h (_Raw_bytes_alloc): Rebind to
+ size_type instead of char and rename to _Raw_alloc.
+ * include/bits/basic_string.tcc (_Rep::_M_destroy, _Rep::_S_create):
+ Use the above.
+ * src/bitmap_allocator.cc: Add instantiation for size_type.
+ * src/mt_allocator.cc: Likewise.
+ * src/pool_allocator.cc: Likewise.
+ * include/ext/array_allocator.h: Tweak slightly, avoid assuming
+ the existence of an _Array::begin() and size() members.
+ * testsuite/ext/array_allocator/2.cc: Tweak to use an allocator
+ of size_type, instead of char, thus avoiding problems with
+ rebinds, not treated correctly by array_allocator.
+
2005-05-27 Paolo Carlini <pcarlini@suse.de>
* docs/html/abi.html: Mention 3.4.0 as the current baseline; add
diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h
index 001a68f..c889ce6 100644
--- a/libstdc++-v3/include/bits/basic_string.h
+++ b/libstdc++-v3/include/bits/basic_string.h
@@ -151,7 +151,7 @@ namespace std
struct _Rep : _Rep_base
{
// Types:
- typedef typename _Alloc::template rebind<size_type>::other _Raw_alloc;
+ typedef typename _Alloc::template rebind<char>::other _Raw_bytes_alloc;
// (Public) Data members:
diff --git a/libstdc++-v3/include/bits/basic_string.tcc b/libstdc++-v3/include/bits/basic_string.tcc
index 672457f..41db0dff 100644
--- a/libstdc++-v3/include/bits/basic_string.tcc
+++ b/libstdc++-v3/include/bits/basic_string.tcc
@@ -425,10 +425,9 @@ namespace std
basic_string<_CharT, _Traits, _Alloc>::_Rep::
_M_destroy(const _Alloc& __a) throw ()
{
- const size_type __size = ((this->_M_capacity + 1) * sizeof(_CharT)
- + sizeof(_Rep_base) + sizeof(size_type) - 1);
- _Raw_alloc(__a).deallocate(reinterpret_cast<size_type*>(this), __size
- / sizeof(size_type));
+ const size_type __size = sizeof(_Rep_base) +
+ (this->_M_capacity + 1) * sizeof(_CharT);
+ _Raw_bytes_alloc(__a).deallocate(reinterpret_cast<char*>(this), __size);
}
template<typename _CharT, typename _Traits, typename _Alloc>
@@ -569,12 +568,9 @@ namespace std
__capacity = 2 * __old_capacity;
// NB: Need an array of char_type[__capacity], plus a terminating
- // null char_type() element, plus enough for the _Rep data structure,
- // plus sizeof(size_type) - 1 to upper round to a size multiple
- // of sizeof(size_type).
+ // null char_type() element, plus enough for the _Rep data structure.
// Whew. Seemingly so needy, yet so elemental.
- size_type __size = ((__capacity + 1) * sizeof(_CharT) + sizeof(_Rep)
- + sizeof(size_type) - 1);
+ size_type __size = (__capacity + 1) * sizeof(_CharT) + sizeof(_Rep);
const size_type __adj_size = __size + __malloc_header_size;
if (__adj_size > __pagesize && __capacity > __old_capacity)
@@ -584,14 +580,12 @@ namespace std
// Never allocate a string bigger than _S_max_size.
if (__capacity > _S_max_size)
__capacity = _S_max_size;
- __size = ((__capacity + 1) * sizeof(_CharT) + sizeof(_Rep)
- + sizeof(size_type) - 1);
+ __size = (__capacity + 1) * sizeof(_CharT) + sizeof(_Rep);
}
// NB: Might throw, but no worries about a leak, mate: _Rep()
// does not throw.
- void* __place = _Raw_alloc(__alloc).allocate(__size
- / sizeof(size_type));
+ void* __place = _Raw_bytes_alloc(__alloc).allocate(__size);
_Rep *__p = new (__place) _Rep;
__p->_M_capacity = __capacity;
return __p;
diff --git a/libstdc++-v3/include/ext/array_allocator.h b/libstdc++-v3/include/ext/array_allocator.h
index 2716919..8689d9d 100644
--- a/libstdc++-v3/include/ext/array_allocator.h
+++ b/libstdc++-v3/include/ext/array_allocator.h
@@ -121,10 +121,9 @@ namespace __gnu_cxx
allocate(size_type __n, const void* = 0)
{
static size_type __array_used;
- if (_M_array == 0
- || __array_used + __n > sizeof(*_M_array) / sizeof(_Tp))
+ if (_M_array == 0 || __array_used + __n > _M_array->size())
std::__throw_bad_alloc();
- pointer __ret = reinterpret_cast<_Tp*>(_M_array) + __array_used;
+ pointer __ret = _M_array->begin() + __array_used;
__array_used += __n;
return __ret;
}
diff --git a/libstdc++-v3/src/bitmap_allocator.cc b/libstdc++-v3/src/bitmap_allocator.cc
index 4e42cce..c8d94af 100644
--- a/libstdc++-v3/src/bitmap_allocator.cc
+++ b/libstdc++-v3/src/bitmap_allocator.cc
@@ -41,10 +41,6 @@ namespace __gnu_cxx
<bitmap_allocator<wchar_t>::_Alloc_block*,
bitmap_allocator<wchar_t>::_Alloc_block*> >;
- template class __mini_vector<std::pair
- <bitmap_allocator<size_t>::_Alloc_block*,
- bitmap_allocator<size_t>::_Alloc_block*> >;
-
template class __mini_vector<size_t*>;
template size_t** __lower_bound
diff --git a/libstdc++-v3/src/mt_allocator.cc b/libstdc++-v3/src/mt_allocator.cc
index 9c94bc8..bb6ab89 100644
--- a/libstdc++-v3/src/mt_allocator.cc
+++ b/libstdc++-v3/src/mt_allocator.cc
@@ -1,8 +1,8 @@
// Allocator details.
-// Copyright (C) 2004, 2005 Free Software Foundation, Inc.
+// Copyright (C) 2004 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++ Librarbooly. 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)
@@ -552,5 +552,4 @@ namespace __gnu_cxx
// Instantiations.
template class __mt_alloc<char>;
template class __mt_alloc<wchar_t>;
- template class __mt_alloc<size_t>;
} // namespace __gnu_cxx
diff --git a/libstdc++-v3/src/pool_allocator.cc b/libstdc++-v3/src/pool_allocator.cc
index 1ad4e9c..731cfff 100644
--- a/libstdc++-v3/src/pool_allocator.cc
+++ b/libstdc++-v3/src/pool_allocator.cc
@@ -170,5 +170,4 @@ namespace __gnu_cxx
// Instantiations.
template class __pool_alloc<char>;
template class __pool_alloc<wchar_t>;
- template class __pool_alloc<size_t>;
} // namespace __gnu_cxx
diff --git a/libstdc++-v3/testsuite/ext/array_allocator/2.cc b/libstdc++-v3/testsuite/ext/array_allocator/2.cc
index 1e83725..f580ea2 100644
--- a/libstdc++-v3/testsuite/ext/array_allocator/2.cc
+++ b/libstdc++-v3/testsuite/ext/array_allocator/2.cc
@@ -1,4 +1,7 @@
-// Copyright (C) 2004, 2005 Free Software Foundation, Inc.
+// Expected execution error for PR19495.
+// { dg-do run { xfail powerpc*-*-linux* } }
+
+// 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
@@ -32,10 +35,7 @@
typedef char char_type;
typedef std::char_traits<char_type> traits_type;
-// NB: Array_allocator doesn't properly support rebinding, used by
-// basic_string. See libstdc++/21609 for details.
-typedef std::tr1::array<size_t, 16> array_type;
-typedef __gnu_cxx::array_allocator<size_t, array_type> allocator_type;
+typedef std::tr1::array<char_type, 32> array_type;
array_type extern_array;
@@ -44,8 +44,10 @@ void test01()
bool test __attribute__((unused)) = true;
using std::basic_string;
+ typedef __gnu_cxx::array_allocator<char_type, array_type> allocator_type;
typedef basic_string<char_type, traits_type, allocator_type> string_type;
+ size_t index = array_type::_S_index;
allocator_type a(&extern_array);
string_type s(a);