summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2006-09-21 10:34:48 +0000
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2006-09-21 10:34:48 +0000
commite6c19c46a2cea66232a05eabfd451e8af8793c53 (patch)
tree3a670308fc2c1ce3157c9bdd5cda22115dd848ef
parent3dfddb1d8096b7763f71cea0c8ca3147cae77286 (diff)
downloadgcc-e6c19c46a2cea66232a05eabfd451e8af8793c53.tar.gz
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@117109 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--libstdc++-v3/ChangeLog10
-rw-r--r--libstdc++-v3/include/ext/sso_string_base.h26
-rw-r--r--libstdc++-v3/include/ext/vstring.h2
-rw-r--r--libstdc++-v3/testsuite/ext/vstring/capacity/29134.cc38
4 files changed, 54 insertions, 22 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 48059ebe044..8e0014aad75 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -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
diff --git a/libstdc++-v3/include/ext/sso_string_base.h b/libstdc++-v3/include/ext/sso_string_base.h
index 30988260dd7..24cd160be11 100644
--- a/libstdc++-v3/include/ext/sso_string_base.h
+++ b/libstdc++-v3/include/ext/sso_string_base.h
@@ -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
diff --git a/libstdc++-v3/include/ext/vstring.h b/libstdc++-v3/include/ext/vstring.h
index d858949db46..62e9673d3ef 100644
--- a/libstdc++-v3/include/ext/vstring.h
+++ b/libstdc++-v3/include/ext/vstring.h
@@ -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);
diff --git a/libstdc++-v3/testsuite/ext/vstring/capacity/29134.cc b/libstdc++-v3/testsuite/ext/vstring/capacity/29134.cc
new file mode 100644
index 00000000000..41658ee0ae9
--- /dev/null
+++ b/libstdc++-v3/testsuite/ext/vstring/capacity/29134.cc
@@ -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;
+}