]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR libstdc++/19955 (Second std::ctype<char>::narrow() does not call std::ctype...
authorPaolo Carlini <pcarlini@suse.de>
Sun, 20 Feb 2005 17:14:46 +0000 (17:14 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Sun, 20 Feb 2005 17:14:46 +0000 (17:14 +0000)
2005-02-20  Paolo Carlini  <pcarlini@suse.de>
    Jon Grimm  <jgrimm2@us.ibm.com>

PR libstdc++/19955
* include/bits/locale_facets.h (ctype<char>::_M_narrow_init()):
Fix the logic setting _M_narrow_ok: first check whether the
transformation is trivial with a dflt == 0, then deal with the
special case of zero.
* testsuite/22_locale/ctype/narrow/char/19955.cc: New.

* include/bits/locale_facets.h (ctype<char>::_M_widen_init()):
Tweak consistently to use memcmp; minor formatting fixes.

Co-Authored-By: Jon Grimm <jgrimm2@us.ibm.com>
From-SVN: r95305

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/locale_facets.h

index d74d67226963a837947e98c121ddc208a511c5ab..fe0d1767da596fd2ae33cf23584e4f70f1872e32 100644 (file)
@@ -1,3 +1,16 @@
+2005-02-20  Paolo Carlini  <pcarlini@suse.de>
+           Jon Grimm  <jgrimm2@us.ibm.com>
+       
+       PR libstdc++/19955
+       * include/bits/locale_facets.h (ctype<char>::_M_narrow_init()):
+       Fix the logic setting _M_narrow_ok: first check whether the
+       transformation is trivial with a dflt == 0, then deal with the
+       special case of zero.
+       * testsuite/22_locale/ctype/narrow/char/19955.cc: New.
+
+       * include/bits/locale_facets.h (ctype<char>::_M_widen_init()):
+       Tweak consistently to use memcmp; minor formatting fixes.
+
 2005-02-18  Eric Botcazou  <ebotcazou@libertysurf.fr>
 
        * testsuite/thread/pthread1.cc: Do not invoke pthread_setconcurrency
index 60db8a45f2618b14f4a5f4cde0a8b480464f7e24..db0e9514623574041fef232a2d2618290240d700 100644 (file)
@@ -1,6 +1,6 @@
 // Locale support -*- C++ -*-
 
-// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
+// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
 // Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
@@ -690,7 +690,7 @@ namespace std
       mutable char             _M_widen[1 + static_cast<unsigned char>(-1)];
       mutable char             _M_narrow[1 + static_cast<unsigned char>(-1)];
       mutable char             _M_narrow_ok;   // 0 uninitialized, 1 init,
-                                               // 2 non-consecutive
+                                               // 2 memcpy can't be used
 
     public:
       /// The facet id for ctype<char>
@@ -865,7 +865,8 @@ namespace std
       char_type
       widen(char __c) const
       {
-       if (_M_widen_ok) return _M_widen[static_cast<unsigned char>(__c)];
+       if (_M_widen_ok)
+         return _M_widen[static_cast<unsigned char>(__c)];
        this->_M_widen_init();
        return this->do_widen(__c);
       }
@@ -896,7 +897,8 @@ namespace std
            memcpy(__to, __lo, __hi - __lo);
            return __hi;
          }
-       if (!_M_widen_ok) _M_widen_init();
+       if (!_M_widen_ok)
+         _M_widen_init();
        return this->do_widen(__lo, __hi, __to);
       }
 
@@ -924,7 +926,8 @@ namespace std
        if (_M_narrow[static_cast<unsigned char>(__c)])
          return _M_narrow[static_cast<unsigned char>(__c)];
        const char __t = do_narrow(__c, __dfault);
-       if (__t != __dfault) _M_narrow[static_cast<unsigned char>(__c)] = __t;
+       if (__t != __dfault)
+         _M_narrow[static_cast<unsigned char>(__c)] = __t;
        return __t;
       }
 
@@ -954,7 +957,7 @@ namespace std
       narrow(const char_type* __lo, const char_type* __hi,
             char __dfault, char *__to) const
       {
-       if (__builtin_expect(_M_narrow_ok == 1,true))
+       if (__builtin_expect(_M_narrow_ok == 1, true))
          {
            memcpy(__to, __lo, __hi - __lo);
            return __hi;
@@ -1161,17 +1164,13 @@ namespace std
 
        _M_widen_ok = 1;
        // Set _M_widen_ok to 2 if memcpy can't be used.
-       for (size_t __j = 0; __j < sizeof(_M_widen); ++__j)
-         if (__tmp[__j] != _M_widen[__j])
-           {
-             _M_widen_ok = 2;
-             break;
-           }
+       if (memcmp(__tmp, _M_widen, sizeof(_M_widen)))
+         _M_widen_ok = 2;
       }
 
       // Fill in the narrowing cache and flag whether all values are
-      // valid or not.  _M_narrow_ok is set to 1 if the whole table is
-      // narrowed, 2 if only some values could be narrowed.
+      // valid or not.  _M_narrow_ok is set to 2 if memcpy can't
+      // be used.
       void _M_narrow_init() const
       {
        char __tmp[sizeof(_M_narrow)];
@@ -1179,21 +1178,18 @@ namespace std
          __tmp[__i] = __i;
        do_narrow(__tmp, __tmp + sizeof(__tmp), 0, _M_narrow);
 
-       // Check if any default values were created.  Do this by
-       // renarrowing with a different default value and comparing.
-       bool __consecutive = true;
-       for (size_t __j = 0; __j < sizeof(_M_narrow); ++__j)
-         if (!_M_narrow[__j])
-           {
-             char __c;
-             do_narrow(__tmp + __j, __tmp + __j + 1, 1, &__c);
-             if (__c == 1)
-               {
-                 __consecutive = false;
-                 break;
-               }
-           }
-       _M_narrow_ok = __consecutive ? 1 : 2;
+       _M_narrow_ok = 1;
+       if (memcmp(__tmp, _M_narrow, sizeof(_M_narrow)))
+         _M_narrow_ok = 2;
+       else
+         {
+           // Deal with the special case of zero: renarrow with a
+           // different default and compare.
+           char __c;
+           do_narrow(__tmp, __tmp + 1, 1, &__c);
+           if (__c == 1)
+             _M_narrow_ok = 2;
+         }
       }
     };