OSDN Git Service

2004-09-28 Paolo Carlini <pcarlini@suse.de>
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 28 Sep 2004 08:58:35 +0000 (08:58 +0000)
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 28 Sep 2004 08:58:35 +0000 (08:58 +0000)
PR libstdc++/16612
* include/bits/basic_string.h (_M_dispose, _M_refcopy,
basic_string()): When _GLIBCXX_FULLY_DYNAMIC_STRING is defined,
don't deal with _S_empty_rep.
* include/bits/basic_string.tcc (_S_construct, _M_destroy,
_M_leak_hard, _M_mutate): Likewise.
* acinclude.m4 (GLIBCXX_ENABLE_FULLY_DYNAMIC_STRING): New.
* acconfig.h: Add corresponding undef.
* configure.ac: Use GLIBCXX_ENABLE_FULLY_DYNAMIC_STRING.
* docs/html/configopts.html: Document --enable-fully-dynamic-string.
* configure: Regenerate.
* config.h.in: Likewise.

2004-09-28  Benjamin Kosnik  <bkoz@redhat.com>
            Paolo Carlini  <pcarlini@suse.de>

* testsuite/21_strings/basic_string/operations/char/1.cc: New.
* testsuite/21_strings/basic_string/operations/wchar_t/1.cc: New.
* testsuite/21_strings/basic_string/element_access/char/empty.cc: New.
* testsuite/21_strings/basic_string/element_access/wchar_t/empty.cc:
New.

2004-09-28  Paolo Carlini  <pcarlini@suse.de>

* README: Remove obsolete entry about include/c_shadow.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@88225 138bc75d-0d04-0410-961f-82ee72b054a4

14 files changed:
libstdc++-v3/ChangeLog
libstdc++-v3/README
libstdc++-v3/acconfig.h
libstdc++-v3/acinclude.m4
libstdc++-v3/config.h.in
libstdc++-v3/configure
libstdc++-v3/configure.ac
libstdc++-v3/docs/html/configopts.html
libstdc++-v3/include/bits/basic_string.h
libstdc++-v3/include/bits/basic_string.tcc
libstdc++-v3/testsuite/21_strings/basic_string/element_access/char/empty.cc [new file with mode: 0644]
libstdc++-v3/testsuite/21_strings/basic_string/element_access/wchar_t/empty.cc [new file with mode: 0644]
libstdc++-v3/testsuite/21_strings/basic_string/operations/char/1.cc [new file with mode: 0644]
libstdc++-v3/testsuite/21_strings/basic_string/operations/wchar_t/1.cc [new file with mode: 0644]

index a262ee3..e5dee83 100644 (file)
@@ -1,3 +1,31 @@
+2004-09-28  Paolo Carlini  <pcarlini@suse.de>
+
+       PR libstdc++/16612
+       * include/bits/basic_string.h (_M_dispose, _M_refcopy,
+       basic_string()): When _GLIBCXX_FULLY_DYNAMIC_STRING is defined,
+       don't deal with _S_empty_rep.
+       * include/bits/basic_string.tcc (_S_construct, _M_destroy,
+       _M_leak_hard, _M_mutate): Likewise.
+       * acinclude.m4 (GLIBCXX_ENABLE_FULLY_DYNAMIC_STRING): New.
+       * acconfig.h: Add corresponding undef.  
+       * configure.ac: Use GLIBCXX_ENABLE_FULLY_DYNAMIC_STRING.
+       * docs/html/configopts.html: Document --enable-fully-dynamic-string.
+       * configure: Regenerate.
+       * config.h.in: Likewise.
+
+2004-09-28  Benjamin Kosnik  <bkoz@redhat.com>
+            Paolo Carlini  <pcarlini@suse.de>
+
+       * testsuite/21_strings/basic_string/operations/char/1.cc: New.
+       * testsuite/21_strings/basic_string/operations/wchar_t/1.cc: New.
+       * testsuite/21_strings/basic_string/element_access/char/empty.cc: New.
+       * testsuite/21_strings/basic_string/element_access/wchar_t/empty.cc: 
+       New.
+
+2004-09-28  Paolo Carlini  <pcarlini@suse.de>
+
+       * README: Remove obsolete entry about include/c_shadow.
+
 2004-09-24  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR libstdc++/17469
index 6844909..1064095 100644 (file)
@@ -35,13 +35,6 @@ It has subdirectories:
       names into the std:: namespace.
       [NB: this is the default, and is the same as --enable-cheaders=c_std]
 
-    include/c_shadow
-      Headers intended to shadow standard C headers provided by an
-      underlying OS or C library, and other headers depended on directly
-      by C++ headers (e.g. unistd.h).  These are meant to wrap the names
-      defined there into the _C_legacy namespace.
-      [NB: this can be enabled via --enable-cheaders=c_shadow]
-
     include/bits
       Files included by standard headers and by other files in
       the bits directory. 
index c2a96c2..cffecbd 100644 (file)
@@ -45,6 +45,9 @@
 // Define if LFS support is available.
 #undef _GLIBCXX_USE_LFS
 
+// Define if a fully dynamic basic_string is wanted.
+#undef _GLIBCXX_FULLY_DYNAMIC_STRING
+
 // Define if NLS translations are to be used.
 #undef _GLIBCXX_USE_NLS
 
index 6e53100..6c9f13a 100644 (file)
@@ -594,6 +594,25 @@ AC_DEFUN([GLIBCXX_CHECK_LFS], [
 
 
 dnl
+dnl Check for whether a fully dynamic basic_string implementation should
+dnl be turned on, that does not put empty objects in per-process static
+dnl memory (mostly useful together with shared memory allocators, see PR
+dnl libstdc++/16612 for details).
+dnl
+dnl --enable-fully-dynamic-string defines _GLIBCXX_FULLY_DYNAMIC_STRING
+dnl --disable-fully-dynamic-string leaves _GLIBCXX_FULLY_DYNAMIC_STRING undefined
+dnl  +  Usage:  GLIBCXX_ENABLE_FULLY_DYNAMIC_STRING[(DEFAULT)]
+dnl       Where DEFAULT is either `yes' or `no'.
+dnl
+AC_DEFUN([GLIBCXX_ENABLE_FULLY_DYNAMIC_STRING], [
+  GLIBCXX_ENABLE(fully-dynamic-string,$1,,[do not put empty strings in per-process static memory])
+  if test $enable_fully_dynamic_string = yes; then
+    AC_DEFINE(_GLIBCXX_FULLY_DYNAMIC_STRING)
+  fi
+])
+
+
+dnl
 dnl Does any necessary configuration of the testsuite directory.  Generates
 dnl the testsuite_hooks.h header.
 dnl
index ecb29eb..acb7d73 100644 (file)
@@ -46,6 +46,9 @@
 // Define if LFS support is available.
 #undef _GLIBCXX_USE_LFS
 
+// Define if a fully dynamic basic_string is wanted.
+#undef _GLIBCXX_FULLY_DYNAMIC_STRING
+
 // Define if NLS translations are to be used.
 #undef _GLIBCXX_USE_NLS
 
index 92492db..f19e56b 100755 (executable)
@@ -884,6 +884,9 @@ Optional Features:
   --enable-cxx-flags=FLAGS
                           pass compiler FLAGS when building library
                           [default=]
+  --enable-fully-dynamic-string
+                          do not put empty strings in per-process static
+                          memory [default=no]
   --enable-symvers=STYLE  enables symbol versioning of the shared library
                           [default=yes]
   --enable-version-specific-runtime-libs
@@ -4394,7 +4397,7 @@ test x"$pic_mode" = xno && libtool_flags="$libtool_flags --prefer-non-pic"
 case $host in
 *-*-irix6*)
   # Find out which ABI we are using.
-  echo '#line 4397 "configure"' > conftest.$ac_ext
+  echo '#line 4400 "configure"' > conftest.$ac_ext
   if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
   (eval $ac_compile) 2>&5
   ac_status=$?
@@ -5015,7 +5018,7 @@ fi;
     #
     # Fake what AC_TRY_COMPILE does.  XXX Look at redoing this new-style.
     cat > conftest.$ac_ext << EOF
-#line 5018 "configure"
+#line 5021 "configure"
 struct S { ~S(); };
 void bar();
 void foo()
@@ -7841,6 +7844,29 @@ echo "${ECHO_T}$EXTRA_CXX_FLAGS" >&6
 
 
 
+   # Check whether --enable-fully-dynamic-string or --disable-fully-dynamic-string was given.
+if test "${enable_fully_dynamic_string+set}" = set; then
+  enableval="$enable_fully_dynamic_string"
+
+      case "$enableval" in
+       yes|no) ;;
+       *) { { echo "$as_me:$LINENO: error: Argument to enable/disable fully-dynamic-string must be yes or no" >&5
+echo "$as_me: error: Argument to enable/disable fully-dynamic-string must be yes or no" >&2;}
+   { (exit 1); exit 1; }; } ;;
+      esac
+
+else
+  enable_fully_dynamic_string=no
+fi;
+
+  if test $enable_fully_dynamic_string = yes; then
+    cat >>confdefs.h <<\_ACEOF
+#define _GLIBCXX_FULLY_DYNAMIC_STRING 1
+_ACEOF
+
+  fi
+
+
 # No surprises, no surprises...
 if test $atomicity_dir = cpu/generic ; then
   { echo "$as_me:$LINENO: WARNING: No native atomic operations are provided for this platform." >&5
index 279a5f0..7c1d193 100644 (file)
@@ -94,6 +94,7 @@ GLIBCXX_ENABLE_CONCEPT_CHECKS([no])
 GLIBCXX_ENABLE_DEBUG_FLAGS(["-g3 -O0"])
 GLIBCXX_ENABLE_DEBUG([no])
 GLIBCXX_ENABLE_CXX_FLAGS
+GLIBCXX_ENABLE_FULLY_DYNAMIC_STRING([no])
 
 # No surprises, no surprises...
 if test $atomicity_dir = cpu/generic ; then
index 8ef9c42..2c84e96 100644 (file)
@@ -144,9 +144,8 @@ options</a></h1>
 
  <dt><code>--enable-cheaders=OPTION  </code></dt>
  <dd><p>This allows the user to define what kind of C headers are
-        used.  Options are: c, c_std, and c_shadow. These correspond
-        to the source directory's include/c, include/c_std, and
-        include/c_shadow directories.  The default is c_std.
+        used.  Options are c and c_std.  These correspond to the source
+       directory's include/c and include/c_std.  The default is c_std.
      </p>
  </dd>
 
@@ -261,6 +260,14 @@ options</a></h1>
      </p>
  </dd>
 
+ <dt><code>--enable-fully-dynamic-string  </code></dt>
+ <dd><p>This option enables a special version of basic_string avoiding
+        the optimization that allocates empty objects in static memory.
+       Mostly useful together with shared memory allocators, see PR
+       libstdc++/16612 for details.
+     </p>
+ </dd>
+
  <dt><code>--enable-concept-checks  </code></dt>
  <dd><p>This turns on additional compile-time checks for instantiated
         library templates, in the form of specialized templates,
index 7e6c669..1e79da4 100644 (file)
@@ -211,7 +211,9 @@ namespace std
        void
        _M_dispose(const _Alloc& __a)
        {
+#ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
          if (__builtin_expect(this != &_S_empty_rep(), false))
+#endif
            if (__gnu_cxx::__exchange_and_add(&this->_M_refcount, -1) <= 0)
              _M_destroy(__a);
        }  // XXX MT
@@ -222,7 +224,9 @@ namespace std
        _CharT*
        _M_refcopy() throw()
        {
+#ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
          if (__builtin_expect(this != &_S_empty_rep(), false))
+#endif
             __gnu_cxx::__atomic_add(&this->_M_refcount, 1);
          return _M_refdata();
        }  // XXX MT
@@ -1957,11 +1961,14 @@ namespace std
              size_type __n2) const;
   };
 
-
   template<typename _CharT, typename _Traits, typename _Alloc>
     inline basic_string<_CharT, _Traits, _Alloc>::
     basic_string()
+#ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
     : _M_dataplus(_S_empty_rep()._M_refdata(), _Alloc()) { }
+#else
+    : _M_dataplus(_S_construct(size_type(), _CharT(), _Alloc()), _Alloc()) { }
+#endif
 
   // operator+
   /**
index 7d27aab..49b6362 100644 (file)
@@ -88,8 +88,10 @@ namespace std
       _S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a,
                   input_iterator_tag)
       {
+#ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
        if (__beg == __end && __a == _Alloc())
          return _S_empty_rep()._M_refdata();
+#endif
        // Avoid reallocation for common case.
        _CharT __buf[128];
        size_type __len = 0;
@@ -134,11 +136,12 @@ namespace std
       _S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a,
                   forward_iterator_tag)
       {
+#ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
        if (__beg == __end && __a == _Alloc())
          return _S_empty_rep()._M_refdata();
-
+#endif
        // NB: Not required, but considered best practice.
-       if (__builtin_expect(__is_null_pointer(__beg), 0))
+       if (__builtin_expect(__is_null_pointer(__beg) && __beg != __end, 0))
          __throw_logic_error(__N("basic_string::_S_construct NULL not valid"));
 
        const size_type __dnew = static_cast<size_type>(std::distance(__beg,
@@ -162,9 +165,10 @@ namespace std
     basic_string<_CharT, _Traits, _Alloc>::
     _S_construct(size_type __n, _CharT __c, const _Alloc& __a)
     {
+#ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
       if (__n == 0 && __a == _Alloc())
        return _S_empty_rep()._M_refdata();
-
+#endif
       // Check for out_of_range and length_error exceptions.
       _Rep* __r = _Rep::_S_create(__n, size_type(0), __a);
       if (__n)
@@ -358,8 +362,10 @@ namespace std
     basic_string<_CharT, _Traits, _Alloc>::_Rep::
     _M_destroy(const _Alloc& __a) throw ()
     {
+#ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
       if (this == &_S_empty_rep())
-        return;
+       return;
+#endif
       const size_type __size = sizeof(_Rep_base) +
                               (this->_M_capacity + 1) * sizeof(_CharT);
       _Raw_bytes_alloc(__a).deallocate(reinterpret_cast<char*>(this), __size);
@@ -369,8 +375,10 @@ namespace std
     void
     basic_string<_CharT, _Traits, _Alloc>::_M_leak_hard()
     {
+#ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
       if (_M_rep() == &_S_empty_rep())
-        return;
+       return;
+#endif
       if (_M_rep()->_M_is_shared())
        _M_mutate(0, 0, 0);
       _M_rep()->_M_set_leaked();
@@ -385,8 +393,12 @@ namespace std
       const size_type __new_size = __old_size + __len2 - __len1;
       const size_type __how_much = __old_size - __pos - __len1;
 
+#ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
       if (_M_rep() == &_S_empty_rep()
          || _M_rep()->_M_is_shared() || __new_size > capacity())
+#else
+      if (_M_rep()->_M_is_shared() || __new_size > capacity())
+#endif
        {
          // Must reallocate.
          const allocator_type __a = get_allocator();
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/element_access/char/empty.cc b/libstdc++-v3/testsuite/21_strings/basic_string/element_access/char/empty.cc
new file mode 100644 (file)
index 0000000..37c9420
--- /dev/null
@@ -0,0 +1,48 @@
+// 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
+// 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.
+//
+// As a special exception, you may use this file as part of a free software
+// library without restriction.  Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License.  This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+#include <string>
+#include <testsuite_hooks.h>
+
+// as per 21.3.4
+int main()
+{
+  bool test __attribute__((unused)) = true;
+  
+  {
+    std::string empty;
+    char c = empty[0];
+    VERIFY( c == char() );
+  }
+
+  {
+    const std::string empty;
+    char c = empty[0];
+    VERIFY( c == char() );
+  }
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/element_access/wchar_t/empty.cc b/libstdc++-v3/testsuite/21_strings/basic_string/element_access/wchar_t/empty.cc
new file mode 100644 (file)
index 0000000..b039169
--- /dev/null
@@ -0,0 +1,48 @@
+// 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
+// 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.
+//
+// As a special exception, you may use this file as part of a free software
+// library without restriction.  Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License.  This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+#include <string>
+#include <testsuite_hooks.h>
+
+// as per 21.3.4
+int main()
+{
+  bool test __attribute__((unused)) = true;
+  
+  {
+    std::wstring empty;
+    wchar_t c = empty[0];
+    VERIFY( c == wchar_t() );
+  }
+
+  {
+    const std::wstring empty;
+    wchar_t c = empty[0];
+    VERIFY( c == wchar_t() );
+  }
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/operations/char/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/operations/char/1.cc
new file mode 100644 (file)
index 0000000..5194be7
--- /dev/null
@@ -0,0 +1,42 @@
+// 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
+// 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.6 string operations
+
+#include <string>
+#include <testsuite_hooks.h>
+
+int test01(void)
+{
+  bool test __attribute__((unused)) = true;
+
+  std::string empty;
+
+  // data() for size == 0 is non-NULL.
+  VERIFY( empty.size() == 0 );
+  const std::string::value_type* p = empty.data();
+  VERIFY( p != NULL );
+
+  return 0;
+}
+
+int main()
+{ 
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/operations/wchar_t/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/operations/wchar_t/1.cc
new file mode 100644 (file)
index 0000000..86374cc
--- /dev/null
@@ -0,0 +1,42 @@
+// 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
+// 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.6 string operations
+
+#include <string>
+#include <testsuite_hooks.h>
+
+int test01(void)
+{
+  bool test __attribute__((unused)) = true;
+
+  std::wstring empty;
+
+  // data() for size == 0 is non-NULL.
+  VERIFY( empty.size() == 0 );
+  const std::wstring::value_type* p = empty.data();
+  VERIFY( p != NULL );
+
+  return 0;
+}
+
+int main()
+{ 
+  test01();
+  return 0;
+}