summaryrefslogtreecommitdiff
path: root/libstdc++-v3
diff options
context:
space:
mode:
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2004-11-29 12:59:53 +0000
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2004-11-29 12:59:53 +0000
commit5a57ffb537514bc561da9fc599f838a398640682 (patch)
treee2be759f3acfab35833964f8d63eda30acb0ee2d /libstdc++-v3
parent3ef7f5472e9aa7dd8de53ad14bb503957f15b62f (diff)
downloadgcc-5a57ffb537514bc561da9fc599f838a398640682.tar.gz
2004-11-29 Paolo Carlini <pcarlini@suse.de>
PR libstdc++/18654 * include/bits/basic_string.tcc (_Rep::_S_create): When shrinking, do not round to pagesize. * testsuite/21_strings/basic_string/capacity/char/18654.cc: New. * testsuite/21_strings/basic_string/capacity/wchar_t/18654.cc: New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@91466 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3')
-rw-r--r--libstdc++-v3/ChangeLog8
-rw-r--r--libstdc++-v3/include/bits/basic_string.tcc2
-rw-r--r--libstdc++-v3/testsuite/21_strings/basic_string/capacity/char/18654.cc56
-rw-r--r--libstdc++-v3/testsuite/21_strings/basic_string/capacity/wchar_t/18654.cc56
4 files changed, 121 insertions, 1 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 0dee3c5cef7..b0d82f84ab6 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,11 @@
+2004-11-29 Paolo Carlini <pcarlini@suse.de>
+
+ PR libstdc++/18654
+ * include/bits/basic_string.tcc (_Rep::_S_create): When shrinking,
+ do not round to pagesize.
+ * testsuite/21_strings/basic_string/capacity/char/18654.cc: New.
+ * testsuite/21_strings/basic_string/capacity/wchar_t/18654.cc: New.
+
2004-11-27 Paolo Carlini <pcarlini@suse.de>
PR libstdc++/18690
diff --git a/libstdc++-v3/include/bits/basic_string.tcc b/libstdc++-v3/include/bits/basic_string.tcc
index 872156f12ab..3bdce0f090a 100644
--- a/libstdc++-v3/include/bits/basic_string.tcc
+++ b/libstdc++-v3/include/bits/basic_string.tcc
@@ -577,7 +577,7 @@ namespace std
size_type __size = (__capacity + 1) * sizeof(_CharT) + sizeof(_Rep);
const size_type __adj_size = __size + __malloc_header_size;
- if (__adj_size > __pagesize)
+ if (__adj_size > __pagesize && __capacity > __old_capacity)
{
const size_type __extra = __pagesize - __adj_size % __pagesize;
__capacity += __extra / sizeof(_CharT);
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/capacity/char/18654.cc b/libstdc++-v3/testsuite/21_strings/basic_string/capacity/char/18654.cc
new file mode 100644
index 00000000000..16dd7ea9ebe
--- /dev/null
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/capacity/char/18654.cc
@@ -0,0 +1,56 @@
+// 2004-11-29 Paolo Carlini <pcarlini@suse.de>
+
+// Copyright (C) 2004 Free Software Foundation
+//
+// 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.
+
+// 21.3.3 string capacity
+
+#include <string>
+#include <testsuite_hooks.h>
+
+// libstdc++/18654
+void test01()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+
+ typedef string::size_type size_type;
+
+ // Our current implementation provides exact shrink-to-size
+ // and shrink-to-fit (in the future, maybe this will change
+ // for short strings).
+ size_type min = 2 << 0;
+ size_type max = 2 << 20;
+ for (size_type i = min; i <= max; i *= 2)
+ {
+ string str(i, 'x');
+ str.reserve(3 * i);
+
+ str.reserve(2 * i);
+ VERIFY( str.capacity() == 2 * i );
+
+ str.reserve();
+ VERIFY( str.capacity() == i );
+ }
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/capacity/wchar_t/18654.cc b/libstdc++-v3/testsuite/21_strings/basic_string/capacity/wchar_t/18654.cc
new file mode 100644
index 00000000000..1b683bb4ada
--- /dev/null
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/capacity/wchar_t/18654.cc
@@ -0,0 +1,56 @@
+// 2004-11-29 Paolo Carlini <pcarlini@suse.de>
+
+// Copyright (C) 2004 Free Software Foundation
+//
+// 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.
+
+// 21.3.3 string capacity
+
+#include <string>
+#include <testsuite_hooks.h>
+
+// libstdc++/18654
+void test01()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+
+ typedef wstring::size_type size_type;
+
+ // Our current implementation provides exact shrink-to-size
+ // and shrink-to-fit (in the future, maybe this will change
+ // for short strings).
+ size_type min = 2 << 0;
+ size_type max = 2 << 20;
+ for (size_type i = min; i <= max; i *= 2)
+ {
+ wstring str(i, L'x');
+ str.reserve(3 * i);
+
+ str.reserve(2 * i);
+ VERIFY( str.capacity() == 2 * i );
+
+ str.reserve();
+ VERIFY( str.capacity() == i );
+ }
+}
+
+int main()
+{
+ test01();
+ return 0;
+}