Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/external/gpl3/gcc/dist/libstdc++-v3/config/locale/dragonfly ...



details:   https://anonhg.NetBSD.org/src/rev/e1f41ff03c24
branches:  trunk
changeset: 458065:e1f41ff03c24
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Jul 28 17:41:21 2019 +0000

description:
Factor out the uselocale() calls by providing the _l missing functions as
inlines in xlocale_port.h except in c_locale.{cc,h} because the header gets
installed.

diffstat:

 external/gpl3/gcc/dist/libstdc++-v3/config/locale/dragonfly/c_locale.cc         |   2 +
 external/gpl3/gcc/dist/libstdc++-v3/config/locale/dragonfly/c_locale.h          |  14 +-
 external/gpl3/gcc/dist/libstdc++-v3/config/locale/dragonfly/codecvt_members.cc  |  55 ++----
 external/gpl3/gcc/dist/libstdc++-v3/config/locale/dragonfly/ctype_members.cc    |  72 ++++++++-
 external/gpl3/gcc/dist/libstdc++-v3/config/locale/dragonfly/monetary_members.cc |  29 +--
 external/gpl3/gcc/dist/libstdc++-v3/config/locale/dragonfly/numeric_members.cc  |   3 +-
 external/gpl3/gcc/dist/libstdc++-v3/config/locale/dragonfly/time_members.cc     |   3 +-
 external/gpl3/gcc/dist/libstdc++-v3/config/locale/dragonfly/xlocale_port.h      |  70 +++++++++
 8 files changed, 186 insertions(+), 62 deletions(-)

diffs (truncated from 600 to 300 lines):

diff -r 3a1121e547e5 -r e1f41ff03c24 external/gpl3/gcc/dist/libstdc++-v3/config/locale/dragonfly/c_locale.cc
--- a/external/gpl3/gcc/dist/libstdc++-v3/config/locale/dragonfly/c_locale.cc   Sun Jul 28 16:30:36 2019 +0000
+++ b/external/gpl3/gcc/dist/libstdc++-v3/config/locale/dragonfly/c_locale.cc   Sun Jul 28 17:41:21 2019 +0000
@@ -34,7 +34,9 @@
 #include <stdexcept>
 #include <limits>
 #include <langinfo.h>
+#ifndef __NetBSD__
 #include <xlocale.h>
+#endif
 
 namespace std _GLIBCXX_VISIBILITY(default)
 {
diff -r 3a1121e547e5 -r e1f41ff03c24 external/gpl3/gcc/dist/libstdc++-v3/config/locale/dragonfly/c_locale.h
--- a/external/gpl3/gcc/dist/libstdc++-v3/config/locale/dragonfly/c_locale.h    Sun Jul 28 16:30:36 2019 +0000
+++ b/external/gpl3/gcc/dist/libstdc++-v3/config/locale/dragonfly/c_locale.h    Sun Jul 28 17:41:21 2019 +0000
@@ -40,7 +40,11 @@
 #pragma GCC system_header
 
 #include <clocale>
+#ifndef __NetBSD__
 #include <xlocale.h>
+#else
+#include <cstdio>
+#endif
 
 #define _GLIBCXX_NUM_CATEGORIES 0
 
@@ -59,20 +63,28 @@
                   const int __size __attribute__ ((__unused__)),
                   const char* __fmt, ...)
   {
+#ifndef __NetBSD__
     __c_locale __old = (__c_locale)uselocale((locale_t)__cloc);
+#endif
 
     __builtin_va_list __args;
     __builtin_va_start(__args, __fmt);
 
+#ifndef __NetBSD__
 #if _GLIBCXX_USE_C99_STDIO
     const int __ret = __builtin_vsnprintf(__out, __size, __fmt, __args);
 #else
     const int __ret = __builtin_vsprintf(__out, __fmt, __args);
 #endif
 
+    uselocale((locale_t)__old);
+#else
+    const int __ret = vsnprintf_l(__out, __size, (locale_t)__cloc, __fmt,
+       __args);
+#endif
+
     __builtin_va_end(__args);
 
-    uselocale((locale_t)__old);
     return __ret;
   }
 
diff -r 3a1121e547e5 -r e1f41ff03c24 external/gpl3/gcc/dist/libstdc++-v3/config/locale/dragonfly/codecvt_members.cc
--- a/external/gpl3/gcc/dist/libstdc++-v3/config/locale/dragonfly/codecvt_members.cc    Sun Jul 28 16:30:36 2019 +0000
+++ b/external/gpl3/gcc/dist/libstdc++-v3/config/locale/dragonfly/codecvt_members.cc    Sun Jul 28 17:41:21 2019 +0000
@@ -34,6 +34,8 @@
 #include <cstdlib>  // For MB_CUR_MAX
 #include <climits>  // For MB_LEN_MAX
 
+#include "xlocale_port.h"
+
 namespace std _GLIBCXX_VISIBILITY(default)
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
@@ -50,8 +52,6 @@
     result __ret = ok;
     state_type __tmp_state(__state);
 
-    __c_locale __old = (__c_locale)uselocale((locale_t)_M_c_locale_codecvt);
-
     // wcsnrtombs is *very* fast but stops if encounters NUL characters:
     // in case we fall back to wcrtomb and then continue, in a loop.
     // NB: wcsnrtombs is a GNU extension
@@ -65,16 +65,18 @@
          __from_chunk_end = __from_end;
 
        __from = __from_next;
-       const size_t __conv = wcsnrtombs(__to_next, &__from_next,
+       const size_t __conv = wcsnrtombs_l(__to_next, &__from_next,
                                         __from_chunk_end - __from_next,
-                                        __to_end - __to_next, &__state);
+                                        __to_end - __to_next, &__state,
+                                        (locale_t)_M_c_locale_codecvt);
        if (__conv == static_cast<size_t>(-1))
          {
            // In case of error, in order to stop at the exact place we
            // have to start again from the beginning with a series of
            // wcrtomb.
            for (; __from < __from_next; ++__from)
-             __to_next += wcrtomb(__to_next, *__from, &__tmp_state);
+             __to_next += wcrtomb_l(__to_next, *__from, &__tmp_state,
+               (locale_t)_M_c_locale_codecvt);
            __state = __tmp_state;
            __ret = error;
          }
@@ -93,7 +95,8 @@
          {
            extern_type __buf[MB_LEN_MAX];
            __tmp_state = __state;
-           const size_t __conv2 = wcrtomb(__buf, *__from_next, &__tmp_state);
+           const size_t __conv2 = wcrtomb_l(__buf, *__from_next, &__tmp_state,
+               (locale_t)_M_c_locale_codecvt);
            if (__conv2 > static_cast<size_t>(__to_end - __to_next))
              __ret = partial;
            else
@@ -106,8 +109,6 @@
          }
       }
 
-    uselocale((locale_t)__old);
-
     return __ret;
   }
 
@@ -121,8 +122,6 @@
     result __ret = ok;
     state_type __tmp_state(__state);
 
-    __c_locale __old = (__c_locale)uselocale((locale_t)_M_c_locale_codecvt);
-
     // mbsnrtowcs is *very* fast but stops if encounters NUL characters:
     // in case we store a L'\0' and then continue, in a loop.
     // NB: mbsnrtowcs is a GNU extension
@@ -138,9 +137,10 @@
          __from_chunk_end = __from_end;
 
        __from = __from_next;
-       size_t __conv = mbsnrtowcs(__to_next, &__from_next,
+       size_t __conv = mbsnrtowcs_l(__to_next, &__from_next,
                                   __from_chunk_end - __from_next,
-                                  __to_end - __to_next, &__state);
+                                  __to_end - __to_next, &__state,
+                                  (locale_t)_M_c_locale_codecvt);
        if (__conv == static_cast<size_t>(-1))
          {
            // In case of error, in order to stop at the exact place we
@@ -148,8 +148,8 @@
            // mbrtowc.
            for (;; ++__to_next, __from += __conv)
              {
-               __conv = mbrtowc(__to_next, __from, __from_end - __from,
-                                &__tmp_state);
+               __conv = mbrtowc_l(__to_next, __from, __from_end - __from,
+                                &__tmp_state), (locale_t)_M_c_locale_codecvt);
                if (__conv == static_cast<size_t>(-1)
                    || __conv == static_cast<size_t>(-2))
                  break;
@@ -184,8 +184,6 @@
          }
       }
 
-    uselocale((locale_t)__old);
-
     return __ret;
   }
 
@@ -195,23 +193,15 @@
   {
     // XXX This implementation assumes that the encoding is
     // stateless and is either single-byte or variable-width.
-    int __ret = 0;
-    __c_locale __old = (__c_locale)uselocale((locale_t)_M_c_locale_codecvt);
-    if (MB_CUR_MAX == 1)
-      __ret = 1;
-    uselocale((locale_t)__old);
-    return __ret;
+    return MB_CUR_MAX_L((locale_t)_M_c_locale_codecvt) == 1 ? 1 : 0;
   }
 
   int
   codecvt<wchar_t, char, mbstate_t>::
   do_max_length() const throw()
   {
-    __c_locale __old = (__c_locale)uselocale((locale_t)_M_c_locale_codecvt);
     // XXX Probably wrong for stateful encodings.
-    int __ret = MB_CUR_MAX;
-    uselocale((locale_t)__old);
-    return __ret;
+    return MB_CUR_MAX_L((locale_t)_M_c_locale_codecvt);
   }
 
   int
@@ -222,8 +212,6 @@
     int __ret = 0;
     state_type __tmp_state(__state);
 
-    __c_locale __old = (__c_locale)uselocale((locale_t)_M_c_locale_codecvt);
-
     // mbsnrtowcs is *very* fast but stops if encounters NUL characters:
     // in case we advance past it and then continue, in a loop.
     // NB: mbsnrtowcs is a GNU extension
@@ -242,9 +230,10 @@
          __from_chunk_end = __end;
 
        const extern_type* __tmp_from = __from;
-       size_t __conv = mbsnrtowcs(__to, &__from,
+       size_t __conv = mbsnrtowcs_l(__to, &__from,
                                   __from_chunk_end - __from,
-                                  __max, &__state);
+                                  __max, &__state),
+                                  (locale_t)_M_c_locale_codecvt);
        if (__conv == static_cast<size_t>(-1))
          {
            // In case of error, in order to stop at the exact place we
@@ -252,8 +241,8 @@
            // mbrtowc.
            for (__from = __tmp_from;; __from += __conv)
              {
-               __conv = mbrtowc(0, __from, __end - __from,
-                                &__tmp_state);
+               __conv = mbrtowc_l(0, __from, __end - __from,
+                                &__tmp_state, (locale_t)_M_c_locale_codecvt);
                if (__conv == static_cast<size_t>(-1)
                    || __conv == static_cast<size_t>(-2))
                  break;
@@ -278,8 +267,6 @@
          }
       }
 
-    uselocale((locale_t)__old);
-
     return __ret;
   }
 #endif
diff -r 3a1121e547e5 -r e1f41ff03c24 external/gpl3/gcc/dist/libstdc++-v3/config/locale/dragonfly/ctype_members.cc
--- a/external/gpl3/gcc/dist/libstdc++-v3/config/locale/dragonfly/ctype_members.cc      Sun Jul 28 16:30:36 2019 +0000
+++ b/external/gpl3/gcc/dist/libstdc++-v3/config/locale/dragonfly/ctype_members.cc      Sun Jul 28 17:41:21 2019 +0000
@@ -33,6 +33,8 @@
 #include <cstring>
 #include <cstdio>
 
+#include "xlocale_port.h"
+
 #ifndef _ISbit
 #define _ISbit(bit) ((bit) < 8 ? ((1 << (bit)) << 8) : ((1 << (bit)) >> 8))
 #endif
@@ -96,9 +98,11 @@
       case graph:
        __ret = wctype_l("graph", (locale_t)_M_c_locale_ctype);
        break;
+#ifndef __NetBSD__
       case blank:
        __ret = wctype_l("blank", (locale_t)_M_c_locale_ctype);
        break;
+#endif
       default:
        __ret = __wmask_type();
       }
@@ -135,6 +139,60 @@
     return __hi;
   }
 
+  bool
+  ctype<wchar_t>::
+  do_is(mask __m, char_type __c) const
+  {
+    bool __ret = false;
+    // Generically, 15 (instead of 11) since we don't know the numerical
+    // encoding of the various categories in /usr/include/ctype.h.
+    const size_t __bitmasksize = 15;
+    for (size_t __bitcur = 0; __bitcur <= __bitmasksize; ++__bitcur)
+      if (__m & _M_bit[__bitcur]
+         && iswctype(__c, _M_wmask[__bitcur]))
+       {
+         __ret = true;
+         break;
+       }
+    return __ret;
+  }
+
+  const wchar_t*
+  ctype<wchar_t>::
+  do_is(const wchar_t* __lo, const wchar_t* __hi, mask* __vec) const
+  {
+    for (;__lo < __hi; ++__vec, ++__lo)
+      {
+       // Generically, 15 (instead of 11) since we don't know the numerical
+       // encoding of the various categories in /usr/include/ctype.h.
+       const size_t __bitmasksize = 15;
+       mask __m = 0;
+       for (size_t __bitcur = 0; __bitcur <= __bitmasksize; ++__bitcur)
+         if (iswctype(*__lo, _M_wmask[__bitcur]))
+           __m |= _M_bit[__bitcur];
+       *__vec = __m;
+      }
+    return __hi;
+  }
+
+  const wchar_t*
+  ctype<wchar_t>::
+  do_scan_is(mask __m, const wchar_t* __lo, const wchar_t* __hi) const
+  {
+    while (__lo < __hi && !this->do_is(__m, *__lo))
+      ++__lo;



Home | Main Index | Thread Index | Old Index