PR libstdc++/29134 (ext/vstring bits)
authorPaolo Carlini <pcarlini@suse.de>
Thu, 21 Sep 2006 10:34:48 +0000 (10:34 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Thu, 21 Sep 2006 10:34:48 +0000 (10:34 +0000)
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

libstdc++-v3/ChangeLog
libstdc++-v3/include/ext/sso_string_base.h
libstdc++-v3/include/ext/vstring.h
libstdc++-v3/testsuite/ext/vstring/capacity/29134.cc [new file with mode: 0644]

index 48059ebe044bb1cd83c283896c6dbef7a19b6ff0..8e0014aad7516da97c50e7a1a953a4fc933822e2 100644 (file)
@@ -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
index 30988260dd7934f4f00498640a5d64d683eb1f16..24cd160be114dc3e9c34d9be3900dc8a37b5bf1d 100644 (file)
@@ -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
index d858949db467636fada95a03e2ccb4d227b88ac3..62e9673d3efe25e4ae8d1f2e974d2e8d4d35a5dc 100644 (file)
@@ -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 (file)
index 0000000..41658ee
--- /dev/null
@@ -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;
+}