PR libstdc++/29134 (ext/vstring bits)
2006-09-21 Paolo Carlini <pcarlini@suse.de> PR libstdc++/29134 (ext/vstring bits) * include/ext/sso_string_base.h (__sso_string_base<>::_S_max_size): Remove. (__sso_string_base<>::_M_max_size): Use allocator' max_size. (__sso_string_base<>::_M_create): Adjust. * include/ext/vstring.h: Minor comment tweak. * testsuite/ext/vstring/capacity/29134.cc: New. From-SVN: r117109
This commit is contained in:
parent
93c2177fea
commit
3ad7074772
|
@ -1,3 +1,13 @@
|
|||
2006-09-21 Paolo Carlini <pcarlini@suse.de>
|
||||
|
||||
PR libstdc++/29134 (ext/vstring bits)
|
||||
* include/ext/sso_string_base.h (__sso_string_base<>::_S_max_size):
|
||||
Remove.
|
||||
(__sso_string_base<>::_M_max_size): Use allocator' max_size.
|
||||
(__sso_string_base<>::_M_create): Adjust.
|
||||
* include/ext/vstring.h: Minor comment tweak.
|
||||
* testsuite/ext/vstring/capacity/29134.cc: New.
|
||||
|
||||
2006-09-20 Paolo Carlini <pcarlini@suse.de>
|
||||
|
||||
PR libstdc++/29134
|
||||
|
|
|
@ -51,21 +51,7 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
|
|||
typedef typename _CharT_alloc_type::size_type size_type;
|
||||
|
||||
private:
|
||||
// The maximum number of individual char_type elements of an
|
||||
// individual string is determined by _S_max_size. This is the
|
||||
// value that will be returned by max_size(). (Whereas npos
|
||||
// is the maximum number of bytes the allocator can allocate.)
|
||||
// If one was to divvy up the theoretical largest size string,
|
||||
// with a terminating character and m _CharT elements, it'd
|
||||
// look like this:
|
||||
// npos = m * sizeof(_CharT) + sizeof(_CharT)
|
||||
// Solving for m:
|
||||
// m = npos / sizeof(_CharT) - 1
|
||||
// In addition, this implementation halfs this amount.
|
||||
enum { _S_max_size = (((static_cast<size_type>(-1)
|
||||
/ sizeof(_CharT)) - 1) / 2) };
|
||||
|
||||
// Data Members (private):
|
||||
// Data Members:
|
||||
typename _Util_Base::template _Alloc_hider<_CharT_alloc_type>
|
||||
_M_dataplus;
|
||||
size_type _M_string_length;
|
||||
|
@ -151,7 +137,7 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
|
|||
public:
|
||||
size_type
|
||||
_M_max_size() const
|
||||
{ return size_type(_S_max_size); }
|
||||
{ return (_M_dataplus._CharT_alloc_type::max_size() - 1) / 2; }
|
||||
|
||||
_CharT*
|
||||
_M_data() const
|
||||
|
@ -322,7 +308,7 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
|
|||
{
|
||||
// _GLIBCXX_RESOLVE_LIB_DEFECTS
|
||||
// 83. String::npos vs. string::max_size()
|
||||
if (__capacity > size_type(_S_max_size))
|
||||
if (__capacity > _M_max_size())
|
||||
std::__throw_length_error(__N("__sso_string_base::_M_create"));
|
||||
|
||||
// The below implements an exponential growth policy, necessary to
|
||||
|
@ -331,9 +317,9 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
|
|||
if (__capacity > __old_capacity && __capacity < 2 * __old_capacity)
|
||||
{
|
||||
__capacity = 2 * __old_capacity;
|
||||
// Never allocate a string bigger than _S_max_size.
|
||||
if (__capacity > size_type(_S_max_size))
|
||||
__capacity = size_type(_S_max_size);
|
||||
// Never allocate a string bigger than max_size.
|
||||
if (__capacity > _M_max_size())
|
||||
__capacity = _M_max_size();
|
||||
}
|
||||
|
||||
// NB: Need an array of char_type[__capacity], plus a terminating
|
||||
|
|
|
@ -74,8 +74,6 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
|
|||
typedef std::reverse_iterator<iterator> reverse_iterator;
|
||||
|
||||
// Data Member (public):
|
||||
// NB: This is an unsigned type, and thus represents the maximum
|
||||
// size that the allocator can hold.
|
||||
/// Value returned by various member functions when they fail.
|
||||
static const size_type npos = static_cast<size_type>(-1);
|
||||
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
// Copyright (C) 2006 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 Pred 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.
|
||||
|
||||
// 21.3.3 basic_string capacity [lib.string.capacity]
|
||||
|
||||
#include <ext/vstring.h>
|
||||
#include <testsuite_hooks.h>
|
||||
|
||||
// libstdc++/29134
|
||||
void test01()
|
||||
{
|
||||
bool test __attribute__((unused)) = true;
|
||||
|
||||
__gnu_cxx::__vstring vs;
|
||||
|
||||
VERIFY( vs.max_size() <= vs.get_allocator().max_size() );
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test01();
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue