[cfe-commits] [libcxx] r135246 - in /libcxx/trunk: include/__config include/locale src/locale.cpp

Sean Hunt scshunt at csclub.uwaterloo.ca
Thu Jul 14 22:40:33 PDT 2011


Author: coppro
Date: Fri Jul 15 00:40:33 2011
New Revision: 135246

URL: http://llvm.org/viewvc/llvm-project?rev=135246&view=rev
Log:
Reapply 135035 with proper conditional inclusion, hopefully solving
issues with it.

Modified:
    libcxx/trunk/include/__config
    libcxx/trunk/include/locale
    libcxx/trunk/src/locale.cpp

Modified: libcxx/trunk/include/__config
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__config?rev=135246&r1=135245&r2=135246&view=diff
==============================================================================
--- libcxx/trunk/include/__config (original)
+++ libcxx/trunk/include/__config Fri Jul 15 00:40:33 2011
@@ -286,6 +286,10 @@
 #endif
 
 #ifdef __APPLE__
+#define _LIBCPP_LOCALE__L_EXTENSIONS 1
+#endif
+
+#ifdef __APPLE__
 #define _LIBCPP_STABLE_APPLE_ABI
 #endif
 

Modified: libcxx/trunk/include/locale
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/locale?rev=135246&r1=135245&r2=135246&view=diff
==============================================================================
--- libcxx/trunk/include/locale (original)
+++ libcxx/trunk/include/locale Fri Jul 15 00:40:33 2011
@@ -197,11 +197,14 @@
 locale_t __cloc();
 #endif
 
+typedef _VSTD::remove_pointer<locale_t>::type __locale_struct;
+typedef _VSTD::unique_ptr<__locale_struct, decltype(&freelocale)> __locale_unique_ptr;
+typedef _VSTD::unique_ptr<__locale_struct, decltype(&uselocale)> __locale_raii;
+
 // OSX has nice foo_l() functions that let you turn off use of the global
 // locale.  Linux, not so much.  The following functions avoid the locale when
 // that's possible and otherwise do the wrong thing.  FIXME.
-#if __APPLE__
-
+#ifdef _LIBCPP_STABLE_APPLE_ABI
 template <class _Tp>
 inline _LIBCPP_INLINE_VISIBILITY
 int
@@ -269,77 +272,195 @@
     return isdigit_l(__c, 0);
 }
 
-#else  // __APPLE__
-inline
-#ifndef _LIBCPP_HAS_NO_ALWAYS_INLINE_VARIADICS
-_LIBCPP_INLINE_VISIBILITY
-#endif
-int
-__nolocale_sprintf(char* __restrict __str,
-                   const char* __restrict __format, ...)
+#else  // _LIBCPP_STABLE_APPLE_ABI
+
+#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
+decltype(MB_CUR_MAX_L(_VSTD::declval<locale_t>()))
+inline _LIBCPP_INLINE_VISIBILITY
+__mb_cur_max_l(locale_t __l)
+{
+  return MB_CUR_MAX_L(__l);
+}
+#else  // _LIBCPP_LOCALE__L_EXTENSIONS
+_LIBCPP_ALWAYS_INLINE inline
+decltype(MB_CUR_MAX) __mb_cur_max_l(locale_t __l)
+{
+  __locale_raii __current(uselocale(__l), uselocale);
+  return MB_CUR_MAX;
+}
+#endif // _LIBCPP_LOCALE__L_EXTENSIONS
+
+_LIBCPP_ALWAYS_INLINE inline
+wint_t __btowc_l(int __c, locale_t __l)
 {
-    va_list __ap;
-    va_start(__ap, __format);
-    int __result = vsprintf(__str, __format, __ap);
-    va_end(__ap);
-    return __result;
-}
-inline
-#ifndef _LIBCPP_HAS_NO_ALWAYS_INLINE_VARIADICS
-_LIBCPP_INLINE_VISIBILITY
+#ifdef _LIBCPP_STABLE_APPLE_ABI
+  return btowc_l(__c, __l);
+#else
+  __locale_raii __current(uselocale(__l), uselocale);
+  return btowc(__c);
 #endif
-int
-__nolocale_snprintf(char* __restrict __str, size_t __size,
-                    const char* __restrict __format, ...)
+}
+
+_LIBCPP_ALWAYS_INLINE inline
+int __wctob_l(wint_t __c, locale_t __l)
 {
-    va_list __ap;
-    va_start(__ap, __format);
-    int __result = vsnprintf(__str, __size, __format, __ap);
-    va_end(__ap);
-    return __result;
-}
-inline
-#ifndef _LIBCPP_HAS_NO_ALWAYS_INLINE_VARIADICS
-_LIBCPP_INLINE_VISIBILITY
+#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
+  return wctob_l(__c, __l);
+#else
+  __locale_raii __current(uselocale(__l), uselocale);
+  return wctob(__c);
 #endif
-int
-__nolocale_asprintf(char** __ret,
-                    const char* __restrict __format, ...)
+}
+
+_LIBCPP_ALWAYS_INLINE inline
+size_t __wcsnrtombs_l(char *__dest, const wchar_t **__src, size_t __nwc,
+                      size_t __len, mbstate_t *__ps, locale_t __l)
+{
+#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
+  return wcsnrtombs_l(__dest, __src, __nwc, __len, __ps, __l);
+#else
+  __locale_raii __current(uselocale(__l), uselocale);
+  return wcsnrtombs(__dest, __src, __nwc, __len, __ps);
+#endif
+}
+
+_LIBCPP_ALWAYS_INLINE inline
+size_t __wcrtomb_l(char *__s, wchar_t __wc, mbstate_t *__ps, locale_t __l)
 {
-    va_list __ap;
-    va_start(__ap, __format);
-    int __result = vasprintf(__ret, __format, __ap);
-    va_end(__ap);
-    return __result;
-}
-inline
-#ifndef _LIBCPP_HAS_NO_ALWAYS_INLINE_VARIADICS
-_LIBCPP_INLINE_VISIBILITY
+#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
+  return wcrtomb_l(__s, __wc, __ps, __l);
+#else
+  __locale_raii __current(uselocale(__l), uselocale);
+  return wcrtomb(__s, __wc, __ps);
 #endif
-int
-__nolocale_sscanf(const char* __restrict __str,
-                  const char* __restrict __format, ...)
+}
+
+_LIBCPP_ALWAYS_INLINE inline
+size_t __mbsnrtowcs_l(wchar_t * __dest, const char **__src, size_t __nms,
+                      size_t __len, mbstate_t *__ps, locale_t __l)
+{
+#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
+  return mbsnrtowcs_l(__dest, __src, __nms__len, __ps, __l);
+#else
+  __locale_raii __current(uselocale(__l), uselocale);
+  return mbsnrtowcs(__dest, __src, __nms, __len, __ps);
+#endif
+}
+
+_LIBCPP_ALWAYS_INLINE inline
+size_t __mbrtowc_l(wchar_t *__pwc, const char *__s, size_t __n,
+                   mbstate_t *__ps, locale_t __l)
+{
+#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
+  return mbrtowc_l(__pwc, __s, __n, __ps, __l);
+#else
+  __locale_raii __current(uselocale(__l), uselocale);
+  return mbrtowc(__pwc, __s, __n, __ps);
+#endif
+}
+
+_LIBCPP_ALWAYS_INLINE inline
+int __mbtowc_l(wchar_t *__pwc, const char *__pmb, size_t __max, locale_t __l)
 {
-    va_list __ap;
-    va_start(__ap, __format);
-    int __result = vsscanf(__str, __format, __ap);
-    va_end(__ap);
-    return __result;
+#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
+  return mbtowc(__pwc, __pmb, __max, __l);
+#else
+  __locale_raii __current(uselocale(__l), uselocale);
+  return mbtowc(__pwc, __pmb, __max);
+#endif
 }
-inline _LIBCPP_INLINE_VISIBILITY
-int
-__nolocale_isxdigit(int __c)
+
+_LIBCPP_ALWAYS_INLINE inline
+size_t __mbrlen_l(const char *__s, size_t __n, mbstate_t *__ps, locale_t __l)
 {
-    return isxdigit(__c);
+#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
+  return mbrlen_l(__s, __n, __ps, __l);
+#else
+  __locale_raii __current(uselocale(__l), uselocale);
+  return mbrlen(__s, __n, __ps);
+#endif
 }
 
-inline _LIBCPP_INLINE_VISIBILITY
-int
-__nolocale_isdigit(int __c)
+_LIBCPP_ALWAYS_INLINE inline
+lconv *__localeconv_l(locale_t __l)
 {
-    return isdigit(__c);
+#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
+  return localeconv_l(__l);
+#else
+  __locale_raii __current(uselocale(__l), uselocale);
+  return localeconv();
+#endif
+}
+
+_LIBCPP_ALWAYS_INLINE inline
+size_t __mbsrtowcs_l(wchar_t *__dest, const char **__src, size_t __len,
+                     mbstate_t *__ps, locale_t __l)
+{
+#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
+  return mbsrtowcs_l(__dest, __src, __len, __ps, __l);
+#else
+  __locale_raii __current(uselocale(__l), uselocale);
+  return mbsrtowcs(__dest, __src, __len, __ps);
+#endif
+}
+
+_LIBCPP_ALWAYS_INLINE inline
+int __sprintf_l(char *__s, locale_t __l, const char *__format, ...) {
+  va_list __va;
+  va_start(__va, __format);
+#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
+  int __res = vsprintf_l(__s, __l, __format, __va);
+#else
+  __locale_raii __current(uselocale(__l), uselocale);
+  int __res = vsprintf(__s, __format, __va);
+#endif
+  va_end(__va);
+  return __res;
+}
+
+_LIBCPP_ALWAYS_INLINE inline
+int __snprintf_l(char *__s, size_t __n, locale_t __l, const char *__format, ...) {
+  va_list __va;
+  va_start(__va, __format);
+#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
+  int __res = vsnprintf_l(__s, __n, __l, __format, __va);
+#else
+  __locale_raii __current(uselocale(__l), uselocale);
+  int __res = vsnprintf(__s, __n, __format, __va);
+#endif
+  va_end(__va);
+  return __res;
+}
+
+_LIBCPP_ALWAYS_INLINE inline
+int __asprintf_l(char **__s, locale_t __l, const char *__format, ...) {
+  va_list __va;
+  va_start(__va, __format);
+#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
+  int __res = vasprintf_l(__s, __l, __format, __va);
+#else
+  __locale_raii __current(uselocale(__l), uselocale);
+  int __res = vasprintf(__s, __format, __va);
+#endif
+  va_end(__va);
+  return __res;
 }
-#endif  // __APPLE__
+
+_LIBCPP_ALWAYS_INLINE inline
+int __sscanf_l(const char *__s, locale_t __l, const char *__format, ...) {
+  va_list __va;
+  va_start(__va, __format);
+#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
+  int __res = vsscanf_l(__s, __l, __format, __va);
+#else
+  __locale_raii __current(uselocale(__l), uselocale);
+  int __res = vsscanf(__s, __format, __va);
+#endif
+  va_end(__va);
+  return __res;
+}
+
+#endif  // _LIBCPP_STABLE_APPLE_ABI
 
 // __scan_keyword
 // Scans [__b, __e) until a match is found in the basic_strings range
@@ -753,7 +874,11 @@
         int __save_errno = errno;
         errno = 0;
         char *__p2;
+#ifdef _LIBCXX_STABLE_APPLE_ABI
         long long __ll = strtoll_l(__a, &__p2, __base, 0);
+#else
+        long long __ll = strtoll_l(__a, &__p2, __base, __cloc());
+#endif
         int __current_errno = errno;
         if (__current_errno == 0)
             errno = __save_errno;
@@ -793,7 +918,11 @@
         int __save_errno = errno;
         errno = 0;
         char *__p2;
+#ifdef _LIBCXX_STABLE_APPLE_ABI
         unsigned long long __ll = strtoull_l(__a, &__p2, __base, 0);
+#else
+        unsigned long long __ll = strtoull_l(__a, &__p2, __base, __cloc());
+#endif
         int __current_errno = errno;
         if (__current_errno == 0)
             errno = __save_errno;
@@ -821,7 +950,11 @@
     if (__a != __a_end)
     {
         char *__p2;
+#ifdef _LIBCXX_STABLE_APPLE_ABI
         long double __ld = strtold_l(__a, &__p2, 0);
+#else
+        long double __ld = strtold_l(__a, &__p2, __cloc());
+#endif
         if (__p2 != __a_end)
         {
             __err = ios_base::failbit;
@@ -1226,7 +1359,11 @@
             break;
     // Stage 3
     __a[sizeof(__a)-1] = 0;
+#ifdef _LIBCPP_STABLE_APPLE_ABI
     if (__nolocale_sscanf(__a, "%p", &__v) != 1)
+#else
+    if (__sscanf_l(__a, __cloc(), "%p", &__v) != 1)
+#endif
         __err = ios_base::failbit;
     // EOF checked
     if (__b == __e)
@@ -1331,13 +1468,21 @@
         *__oe++ = __ct.widen(*__nf++);
         *__oe++ = __ct.widen(*__nf++);
         for (__ns = __nf; __ns < __ne; ++__ns)
+#ifdef _LIBCPP_STABLE_APPLE_ABI
             if (!__nolocale_isxdigit(*__ns))
+#else
+            if (!isxdigit_l(*__ns, __cloc()))
+#endif
                 break;
     }
     else
     {
         for (__ns = __nf; __ns < __ne; ++__ns)
+#ifdef _LIBCPP_STABLE_APPLE_ABI
             if (!__nolocale_isdigit(*__ns))
+#else
+            if (!isdigit_l(*__ns, __cloc()))
+#endif
                 break;
     }
     if (__grouping.empty())
@@ -1535,7 +1680,11 @@
                           + ((numeric_limits<long>::digits % 3) != 0)
                           + 1;
     char __nar[__nbuf];
+#ifdef _LIBCPP_STABLE_APPLE_ABI
     int __nc = __nolocale_sprintf(__nar, __fmt, __v);
+#else
+    int __nc = __sprintf_l(__nar, __cloc(), __fmt, __v);
+#endif
     char* __ne = __nar + __nc;
     char* __np = this->__identify_padding(__nar, __ne, __iob);
     // Stage 2 - Widen __nar while adding thousands separators
@@ -1561,7 +1710,11 @@
                           + ((numeric_limits<long long>::digits % 3) != 0)
                           + 1;
     char __nar[__nbuf];
+#ifdef _LIBCPP_STABLE_APPLE_ABI
     int __nc = __nolocale_sprintf(__nar, __fmt, __v);
+#else
+    int __nc = __sprintf_l(__nar, __cloc(), __fmt, __v);
+#endif
     char* __ne = __nar + __nc;
     char* __np = this->__identify_padding(__nar, __ne, __iob);
     // Stage 2 - Widen __nar while adding thousands separators
@@ -1587,7 +1740,11 @@
                           + ((numeric_limits<unsigned long>::digits % 3) != 0)
                           + 1;
     char __nar[__nbuf];
+#ifdef _LIBCPP_STABLE_APPLE_ABI
     int __nc = __nolocale_sprintf(__nar, __fmt, __v);
+#else
+    int __nc = __sprintf_l(__nar, __cloc(), __fmt, __v);
+#endif
     char* __ne = __nar + __nc;
     char* __np = this->__identify_padding(__nar, __ne, __iob);
     // Stage 2 - Widen __nar while adding thousands separators
@@ -1613,7 +1770,11 @@
                           + ((numeric_limits<unsigned long long>::digits % 3) != 0)
                           + 1;
     char __nar[__nbuf];
+#ifdef _LIBCPP_STABLE_APPLE_ABI
     int __nc = __nolocale_sprintf(__nar, __fmt, __v);
+#else
+    int __nc = __sprintf_l(__nar, __cloc(), __fmt, __v);
+#endif
     char* __ne = __nar + __nc;
     char* __np = this->__identify_padding(__nar, __ne, __iob);
     // Stage 2 - Widen __nar while adding thousands separators
@@ -1640,18 +1801,36 @@
     char* __nb = __nar;
     int __nc;
     if (__specify_precision)
+#ifdef _LIBCPP_STABLE_APPLE_ABI
         __nc = __nolocale_snprintf(__nb, __nbuf, __fmt,
                                    (int)__iob.precision(), __v);
+#else
+        __nc = __snprintf_l(__nb, __nbuf, __cloc(), __fmt,
+                            (int)__iob.precision(), __v);
+#endif
     else
+#ifdef _LIBCPP_STABLE_APPLE_ABI
         __nc = __nolocale_snprintf(__nb, __nbuf, __fmt, __v);
+#else
+        __nc = __snprintf_l(__nb, __nbuf, __cloc(), __fmt, __v);
+#endif
     unique_ptr<char, void(*)(void*)> __nbh(0, free);
     if (__nc > static_cast<int>(__nbuf-1))
     {
         if (__specify_precision)
+#ifdef _LIBCPP_STABLE_APPLE_ABI
             __nc = __nolocale_asprintf(&__nb, __fmt, (int)__iob.precision(),
                                        __v);
+#else
+            __nc = __asprintf_l(&__nb, __cloc(), __fmt,
+                              (int)__iob.precision());
+#endif
         else
+#ifdef _LIBCPP_STABLE_APPLE_ABI
             __nc = __nolocale_asprintf(&__nb, __fmt, __v);
+#else
+            __nc = __asprintf_l(&__nb, __cloc(), __fmt, (int)__iob.precision());
+#endif
         if (__nb == 0)
             __throw_bad_alloc();
         __nbh.reset(__nb);
@@ -1692,18 +1871,36 @@
     char* __nb = __nar;
     int __nc;
     if (__specify_precision)
+#ifdef _LIBCPP_STABLE_APPLE_ABI
         __nc = __nolocale_snprintf(__nb, __nbuf, __fmt,
                                    (int)__iob.precision(), __v);
+#else
+        __nc = __snprintf_l(__nb, __nbuf, __cloc(), __fmt,
+                            (int)__iob.precision(), __v);
+#endif
     else
+#ifdef _LIBCPP_STABLE_APPLE_ABI
         __nc = __nolocale_snprintf(__nb, __nbuf, __fmt, __v);
+#else
+        __nc = __snprintf_l(__nb, __nbuf, __cloc(), __fmt, __v);
+#endif
     unique_ptr<char, void(*)(void*)> __nbh(0, free);
     if (__nc > static_cast<int>(__nbuf-1))
     {
         if (__specify_precision)
+#ifdef _LIBCPP_STABLE_APPLE_ABI
             __nc = __nolocale_asprintf(&__nb, __fmt, (int)__iob.precision(),
                                        __v);
+#else
+            __nc = __asprintf_l(&__nb, __cloc(), __fmt,
+                              (int)__iob.precision());
+#endif
         else
+#ifdef _LIBCPP_STABLE_APPLE_ABI
             __nc = __nolocale_asprintf(&__nb, __fmt, __v);
+#else
+            __nc = __asprintf_l(&__nb, __cloc(), __fmt, (int)__iob.precision());
+#endif
         if (__nb == 0)
             __throw_bad_alloc();
         __nbh.reset(__nb);
@@ -1739,7 +1936,11 @@
     char __fmt[6] = "%p";
     const unsigned __nbuf = 20;
     char __nar[__nbuf];
+#ifdef _LIBCPP_STABLE_APPLE_ABI
     int __nc = __nolocale_sprintf(__nar, __fmt, __v);
+#else
+    int __nc = __sprintf_l(__nar, __cloc(), __fmt, __v);
+#endif
     char* __ne = __nar + __nc;
     char* __np = this->__identify_padding(__nar, __ne, __iob);
     // Stage 2 - Widen __nar
@@ -3423,7 +3624,11 @@
     // secure memory for digit storage
     if (__n > __bs-1)
     {
+#ifdef _LIBCPP_STABLE_APPLE_ABI
         __n = __nolocale_asprintf(&__bb, "%.0Lf", __units);
+#else
+        __n = __asprintf_l(&__bb, __cloc(), "%.0Lf", __units);
+#endif
         if (__bb == 0)
             __throw_bad_alloc();
         __hn.reset(__bb);

Modified: libcxx/trunk/src/locale.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/locale.cpp?rev=135246&r1=135245&r2=135246&view=diff
==============================================================================
--- libcxx/trunk/src/locale.cpp (original)
+++ libcxx/trunk/src/locale.cpp Fri Jul 15 00:40:33 2011
@@ -22,97 +22,16 @@
 #include <langinfo.h>
 #include <stdlib.h>
 
+#ifdef _LIBCPP_STABLE_APPLE_ABI
 namespace {
-  typedef std::remove_pointer<locale_t>::type locale_struct;
-  typedef std::unique_ptr<locale_struct, decltype(&freelocale)> locale_unique_ptr;
-  typedef std::unique_ptr<locale_struct, decltype(&uselocale)> locale_raii;
-}
-
-namespace with_locale { namespace {
-#ifdef __APPLE__
-  using ::btowc_l;
-  using ::wctob_l;
-  using ::wcsnrtombs_l;
-  using ::wcrtomb_l;
-  using ::mbsnrtowcs_l;
-  using ::mbrtowc_l;
-  using ::mbtowc_l;
-  using ::mbrlen_l;
-  using ::localeconv_l;
-  using ::mbsrtowcs_l;
-
   decltype(MB_CUR_MAX_L(_VSTD::declval<locale_t>()))
   inline _LIBCPP_INLINE_VISIBILITY
   mb_cur_max_l(locale_t loc)
   {
     return MB_CUR_MAX_L(loc);
   }
-#else
-  template
-  <typename Function, typename ...Args>
-  auto using_locale(Function f, locale_t loc, Args&&... params) -> decltype(f(std::forward<Args>(params)...))
-  {
-    locale_raii current(uselocale(loc), uselocale);
-    return f(std::forward<Args>(params)...);
-  }
-
-  decltype(MB_CUR_MAX)
-  mb_cur_max_l(locale_t loc)
-  {
-    locale_raii current(uselocale(loc), uselocale);
-    return MB_CUR_MAX;
-  }
-
-  wint_t btowc_l(int c, locale_t l) { return using_locale(&btowc, l, c); }
-  int wctob_l(wint_t c, locale_t l) { return using_locale(&wctob, l, c); }
-  size_t wcsnrtombs_l(char * dest,
-                      const wchar_t * * src,
-                      size_t nwc,
-                      size_t len,
-                      mbstate_t * ps,
-                      locale_t l)
-  {
-    return using_locale(&wcsnrtombs, l, dest, src, nwc, len, ps);
-  }
-  size_t wcrtomb_l(char *s, wchar_t wc, mbstate_t *ps, locale_t l)
-  {
-    return using_locale(&wcrtomb, l, s, wc, ps);
-  }
-  size_t mbsnrtowcs_l(wchar_t * dest,
-                      const char * * src,
-                      size_t nms,
-                      size_t len,
-                      mbstate_t * ps,
-                      locale_t l)
-  {
-    return using_locale(&mbsnrtowcs, l, dest, src, nms, len, ps);
-  }
-  size_t mbrtowc_l(wchar_t *pwc, const char *s, size_t n, mbstate_t *ps, locale_t l)
-  {
-    return using_locale(&mbrtowc, l, pwc, s, n, ps);
-  }
-  int mbtowc_l(wchar_t * pwc, const char * pmb, size_t max, locale_t l)
-  {
-    return using_locale(&mbtowc, l, pwc, pmb, max);
-  }
-  size_t mbrlen_l(const char *s, size_t n, mbstate_t *ps, locale_t l)
-  {
-    return using_locale(&mbrlen, l, s, n, ps);
-  }
-  struct lconv *localeconv_l(locale_t l)
-  {
-    return using_locale(&localeconv, l);
-  }
-  size_t mbsrtowcs_l(wchar_t * dest,
-                     const char * * src,
-                     size_t len,
-                     mbstate_t * ps,
-                     locale_t l)
-  {
-    return using_locale(&mbsrtowcs, l, dest, src, len, ps);
-  }
+}
 #endif
-} }
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
@@ -1245,21 +1164,33 @@
 wchar_t
 ctype_byname<wchar_t>::do_widen(char c) const
 {
-    return with_locale::btowc_l(c, __l);
+#ifdef _LIBCPP_STABLE_APPLE_ABI
+    return btowc_l(c, __l);
+#else
+    return __btowc_l(c, __l);
+#endif
 }
 
 const char*
 ctype_byname<wchar_t>::do_widen(const char* low, const char* high, char_type* dest) const
 {
     for (; low != high; ++low, ++dest)
-        *dest = with_locale::btowc_l(*low, __l);
+#ifdef _LIBCPP_STABLE_APPLE_ABI
+        *dest = btowc_l(*low, __l);
+#else
+        *dest = __btowc_l(*low, __l);
+#endif
     return low;
 }
 
 char
 ctype_byname<wchar_t>::do_narrow(char_type c, char dfault) const
 {
-    int r = with_locale::wctob_l(c, __l);
+#ifdef _LIBCPP_STABLE_APPLE_ABI
+    int r = wctob_l(c, __l);
+#else
+    int r = __wctob_l(c, __l);
+#endif
     return r != WEOF ? static_cast<char>(r) : dfault;
 }
 
@@ -1268,7 +1199,11 @@
 {
     for (; low != high; ++low, ++dest)
     {
-        int r = with_locale::wctob_l(*low, __l);
+#ifdef _LIBCPP_STABLE_APPLE_ABI
+        int r = wctob_l(*low, __l);
+#else
+        int r = __wctob_l(*low, __l);
+#endif
         *dest = r != WEOF ? static_cast<char>(r) : dfault;
     }
     return low;
@@ -1378,13 +1313,21 @@
     {
         // save state in case needed to reover to_nxt on error
         mbstate_t save_state = st;
-        size_t n = with_locale::wcsnrtombs_l(to, &frm_nxt, fend-frm, to_end-to, &st, __l);
+#ifdef _LIBCPP_STABLE_APPLE_ABI
+        size_t n = wcsnrtombs_l(to, &frm_nxt, fend-frm, to_end-to, &st, __l);
+#else
+        size_t n = __wcsnrtombs_l(to, &frm_nxt, fend-frm, to_end-to, &st, __l);
+#endif
         if (n == size_t(-1))
         {
             // need to recover to_nxt
             for (to_nxt = to; frm != frm_nxt; ++frm)
             {
-                n = with_locale::wcrtomb_l(to_nxt, *frm, &save_state, __l);
+#ifdef _LIBCPP_STABLE_APPLE_ABI
+                n = wcrtomb_l(to_nxt, *frm, &save_state, __l);
+#else
+                n = __wcrtomb_l(to_nxt, *frm, &save_state, __l);
+#endif
                 if (n == size_t(-1))
                     break;
                 to_nxt += n;
@@ -1401,7 +1344,11 @@
         {
             // Try to write the terminating null
             extern_type tmp[MB_LEN_MAX];
-            n = with_locale::wcrtomb_l(tmp, intern_type(), &st, __l);
+#ifdef _LIBCPP_STABLE_APPLE_ABI
+            n = wcrtomb_l(tmp, intern_type(), &st, __l);
+#else
+            n = __wcrtomb_l(tmp, intern_type(), &st, __l);
+#endif
             if (n == size_t(-1))  // on error
                 return error;
             if (n > to_end-to_nxt)  // is there room?
@@ -1434,13 +1381,21 @@
     {
         // save state in case needed to reover to_nxt on error
         mbstate_t save_state = st;
-        size_t n = with_locale::mbsnrtowcs_l(to, &frm_nxt, fend-frm, to_end-to, &st, __l);
+#ifdef _LIBCPP_STABLE_APPLE_ABI
+        size_t n = mbsnrtowcs_l(to, &frm_nxt, fend-frm, to_end-to, &st, __l);
+#else
+        size_t n = __mbsnrtowcs_l(to, &frm_nxt, fend-frm, to_end-to, &st, __l);
+#endif
         if (n == size_t(-1))
         {
             // need to recover to_nxt
             for (to_nxt = to; frm != frm_nxt; ++to_nxt)
             {
-                n = with_locale::mbrtowc_l(to_nxt, frm, fend-frm, &save_state, __l);
+#ifdef _LIBCPP_STABLE_APPLE_ABI
+                n = mbrtowc_l(to_nxt, frm, fend-frm, &save_state, __l);
+#else
+                n = __mbrtowc_l(to_nxt, frm, fend-frm, &save_state, __l);
+#endif
                 switch (n)
                 {
                 case 0:
@@ -1468,7 +1423,11 @@
         if (fend != frm_end)  // set up next null terminated sequence
         {
             // Try to write the terminating null
-            n = with_locale::mbrtowc_l(to_nxt, frm_nxt, 1, &st, __l);
+#ifdef _LIBCPP_STABLE_APPLE_ABI
+            n = mbrtowc_l(to_nxt, frm_nxt, 1, &st, __l);
+#else
+            n = __mbrtowc_l(to_nxt, frm_nxt, 1, &st, __l);
+#endif
             if (n != 0)  // on error
                 return error;
             ++to_nxt;
@@ -1488,7 +1447,11 @@
 {
     to_nxt = to;
     extern_type tmp[MB_LEN_MAX];
-    size_t n = with_locale::wcrtomb_l(tmp, intern_type(), &st, __l);
+#ifdef _LIBCPP_STABLE_APPLE_ABI
+    size_t n = wcrtomb_l(tmp, intern_type(), &st, __l);
+#else
+    size_t n = __wcrtomb_l(tmp, intern_type(), &st, __l);
+#endif
     if (n == size_t(-1) || n == 0)  // on error
         return error;
     --n;
@@ -1502,10 +1465,18 @@
 int
 codecvt<wchar_t, char, mbstate_t>::do_encoding() const  _NOEXCEPT
 {
-    if (with_locale::mbtowc_l((wchar_t*) 0, (const char*) 0, MB_LEN_MAX, __l) == 0)
+#ifdef _LIBCPP_STABLE_APPLE_ABI
+    if (mbtowc_l((wchar_t*) 0, (const char*) 0, MB_LEN_MAX, __l) == 0)
+#else
+    if (__mbtowc_l((wchar_t*) 0, (const char*) 0, MB_LEN_MAX, __l) == 0)
+#endif
     {
         // stateless encoding
-        if (__l == 0 || with_locale::mb_cur_max_l(__l) == 1)  // there are no known constant length encodings
+#ifdef _LIBCPP_STABLE_APPLE_ABI
+        if (__l == 0 || MB_CUR_MAX_L(__l) == 1)  // there are no known constant length encodings
+#else
+        if (__l == 0 || __mb_cur_max_l(__l) == 1)  // there are no known constant length encodings
+#endif
             return 1;                // which take more than 1 char to form a wchar_t
          return 0;
     }
@@ -1525,7 +1496,11 @@
     int nbytes = 0;
     for (size_t nwchar_t = 0; nwchar_t < mx && frm != frm_end; ++nwchar_t)
     {
-        size_t n = with_locale::mbrlen_l(frm, frm_end-frm, &st, __l);
+#ifdef _LIBCPP_STABLE_APPLE_ABI
+        size_t n = mbrlen_l(frm, frm_end-frm, &st, __l);
+#else
+        size_t n = __mbrlen_l(frm, frm_end-frm, &st, __l);
+#endif
         switch (n)
         {
         case 0:
@@ -1547,7 +1522,11 @@
 int
 codecvt<wchar_t, char, mbstate_t>::do_max_length() const  _NOEXCEPT
 {
-    return __l == 0 ? 1 : with_locale::mb_cur_max_l(__l);
+#ifdef _LIBCPP_STABLE_APPLE_ABI
+    return __l == 0 ? 1 : MB_CUR_MAX_L(__l);
+#else
+    return __l == 0 ? 1 : __mb_cur_max_l(__l);
+#endif
 }
 
 //                                     Valid UTF ranges
@@ -4090,13 +4069,17 @@
 {
     if (strcmp(nm, "C") != 0)
     {
-        locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
+        __locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
 #ifndef _LIBCPP_NO_EXCEPTIONS
         if (loc == 0)
             throw runtime_error("numpunct_byname<char>::numpunct_byname"
                                 " failed to construct for " + string(nm));
 #endif  // _LIBCPP_NO_EXCEPTIONS
-        lconv* lc = with_locale::localeconv_l(loc.get());
+#ifdef _LIBCPP_STABLE_APPLE_ABI
+        lconv* lc = localeconv_l(loc.get());
+#else
+        lconv* lc = __localeconv_l(loc.get());
+#endif
         if (*lc->decimal_point)
             __decimal_point_ = *lc->decimal_point;
         if (*lc->thousands_sep)
@@ -4129,13 +4112,17 @@
 {
     if (strcmp(nm, "C") != 0)
     {
-        locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
+        __locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
 #ifndef _LIBCPP_NO_EXCEPTIONS
         if (loc == 0)
             throw runtime_error("numpunct_byname<char>::numpunct_byname"
                                 " failed to construct for " + string(nm));
 #endif  // _LIBCPP_NO_EXCEPTIONS
-        lconv* lc = with_locale::localeconv_l(loc.get());
+#ifdef _LIBCPP_STABLE_APPLE_ABI
+        lconv* lc = localeconv_l(loc.get());
+#else
+        lconv* lc = __localeconv_l(loc.get());
+#endif
         if (*lc->decimal_point)
             __decimal_point_ = *lc->decimal_point;
         if (*lc->thousands_sep)
@@ -4726,7 +4713,11 @@
     wchar_t* wbb = wbuf;
     mbstate_t mb = {0};
     const char* bb = buf;
-    size_t i = with_locale::mbsrtowcs_l( wbb, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
+#ifdef _LIBCPP_STABLE_APPLE_ABI
+    size_t i = mbsrtowcs_l( wbb, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
+#else
+    size_t i = __mbsrtowcs_l( wbb, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
+#endif
     if (i == -1)
         __throw_runtime_error("locale not supported");
     wchar_t* wbe = wbb + i;
@@ -4907,7 +4898,11 @@
         be = strftime_l(buf, 100, "%A", &t, __loc_);
         mb = mbstate_t();
         const char* bb = buf;
-        size_t j = with_locale::mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
+#ifdef _LIBCPP_STABLE_APPLE_ABI
+        size_t j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
+#else
+        size_t j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
+#endif
         if (j == -1)
             __throw_runtime_error("locale not supported");
         wbe = wbuf + j;
@@ -4915,7 +4910,11 @@
         be = strftime_l(buf, 100, "%a", &t, __loc_);
         mb = mbstate_t();
         bb = buf;
-        j = with_locale::mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
+#ifdef _LIBCPP_STABLE_APPLE_ABI
+        j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
+#else
+        j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
+#endif
         if (j == -1)
             __throw_runtime_error("locale not supported");
         wbe = wbuf + j;
@@ -4928,7 +4927,11 @@
         be = strftime_l(buf, 100, "%B", &t, __loc_);
         mb = mbstate_t();
         const char* bb = buf;
-        size_t j = with_locale::mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
+#ifdef _LIBCPP_STABLE_APPLE_ABI
+        size_t j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
+#else
+        size_t j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
+#endif
         if (j == -1)
             __throw_runtime_error("locale not supported");
         wbe = wbuf + j;
@@ -4936,7 +4939,11 @@
         be = strftime_l(buf, 100, "%b", &t, __loc_);
         mb = mbstate_t();
         bb = buf;
-        j = with_locale::mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
+#ifdef _LIBCPP_STABLE_APPLE_ABI
+        j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
+#else
+        j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
+#endif
         if (j == -1)
             __throw_runtime_error("locale not supported");
         wbe = wbuf + j;
@@ -4947,7 +4954,11 @@
     be = strftime_l(buf, 100, "%p", &t, __loc_);
     mb = mbstate_t();
     const char* bb = buf;
-    size_t j = with_locale::mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
+#ifdef _LIBCPP_STABLE_APPLE_ABI
+    size_t j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
+#else
+    size_t j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
+#endif
     if (j == -1)
         __throw_runtime_error("locale not supported");
     wbe = wbuf + j;
@@ -4956,7 +4967,11 @@
     be = strftime_l(buf, 100, "%p", &t, __loc_);
     mb = mbstate_t();
     bb = buf;
-    j = with_locale::mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
+#ifdef _LIBCPP_STABLE_APPLE_ABI
+    j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
+#else
+    j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
+#endif
     if (j == -1)
         __throw_runtime_error("locale not supported");
     wbe = wbuf + j;
@@ -5231,7 +5246,11 @@
     __do_put(__nar, __ne, __tm, __fmt, __mod);
     mbstate_t mb = {0};
     const char* __nb = __nar;
-    size_t j = with_locale::mbsrtowcs_l(__wb, &__nb, 100, &mb, __loc_);
+#ifdef _LIBCPP_STABLE_APPLE_ABI
+    size_t j = mbsrtowcs_l(__wb, &__nb, 100, &mb, __loc_);
+#else
+    size_t j = __mbsrtowcs_l(__wb, &__nb, 100, &mb, __loc_);
+#endif
     if (j == -1)
         __throw_runtime_error("locale not supported");
     __we = __wb + j;
@@ -5480,13 +5499,17 @@
 moneypunct_byname<char, false>::init(const char* nm)
 {
     typedef moneypunct<char, false> base;
-    locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
+    __locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
 #ifndef _LIBCPP_NO_EXCEPTIONS
     if (loc == 0)
         throw runtime_error("moneypunct_byname"
                             " failed to construct for " + string(nm));
 #endif  // _LIBCPP_NO_EXCEPTIONS
-    lconv* lc = with_locale::localeconv_l(loc.get());
+#ifdef _LIBCPP_STABLE_APPLE_ABI
+    lconv* lc = localeconv_l(loc.get());
+#else
+    lconv* lc = __localeconv_l(loc.get());
+#endif
     if (*lc->mon_decimal_point)
         __decimal_point_ = *lc->mon_decimal_point;
     else
@@ -5518,13 +5541,17 @@
 moneypunct_byname<char, true>::init(const char* nm)
 {
     typedef moneypunct<char, true> base;
-    locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
+    __locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
 #ifndef _LIBCPP_NO_EXCEPTIONS
     if (loc == 0)
         throw runtime_error("moneypunct_byname"
                             " failed to construct for " + string(nm));
 #endif  // _LIBCPP_NO_EXCEPTIONS
-    lconv* lc = with_locale::localeconv_l(loc.get());
+#ifdef _LIBCPP_STABLE_APPLE_ABI
+    lconv* lc = localeconv_l(loc.get());
+#else
+    lconv* lc = __localeconv_l(loc.get());
+#endif
     if (*lc->mon_decimal_point)
         __decimal_point_ = *lc->mon_decimal_point;
     else
@@ -5556,13 +5583,17 @@
 moneypunct_byname<wchar_t, false>::init(const char* nm)
 {
     typedef moneypunct<wchar_t, false> base;
-    locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
+    __locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
 #ifndef _LIBCPP_NO_EXCEPTIONS
     if (loc == 0)
         throw runtime_error("moneypunct_byname"
                             " failed to construct for " + string(nm));
 #endif  // _LIBCPP_NO_EXCEPTIONS
-    lconv* lc = with_locale::localeconv_l(loc.get());
+#ifdef _LIBCPP_STABLE_APPLE_ABI
+    lconv* lc = localeconv_l(loc.get());
+#else
+    lconv* lc = __localeconv_l(loc.get());
+#endif
     if (*lc->mon_decimal_point)
         __decimal_point_ = static_cast<wchar_t>(*lc->mon_decimal_point);
     else
@@ -5575,7 +5606,11 @@
     wchar_t wbuf[100];
     mbstate_t mb = {0};
     const char* bb = lc->currency_symbol;
-    size_t j = with_locale::mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
+#ifdef _LIBCPP_STABLE_APPLE_ABI
+    size_t j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
+#else
+    size_t j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
+#endif
     if (j == -1)
         __throw_runtime_error("locale not supported");
     wchar_t* wbe = wbuf + j;
@@ -5590,7 +5625,11 @@
     {
         mb = mbstate_t();
         bb = lc->positive_sign;
-        j = with_locale::mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
+#ifdef _LIBCPP_STABLE_APPLE_ABI
+        j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
+#else
+        j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
+#endif
         if (j == -1)
             __throw_runtime_error("locale not supported");
         wbe = wbuf + j;
@@ -5602,7 +5641,11 @@
     {
         mb = mbstate_t();
         bb = lc->negative_sign;
-        j = with_locale::mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
+#ifdef _LIBCPP_STABLE_APPLE_ABI
+        j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
+#else
+        j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
+#endif
         if (j == -1)
             __throw_runtime_error("locale not supported");
         wbe = wbuf + j;
@@ -5617,13 +5660,17 @@
 moneypunct_byname<wchar_t, true>::init(const char* nm)
 {
     typedef moneypunct<wchar_t, true> base;
-    locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
+    __locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
 #ifndef _LIBCPP_NO_EXCEPTIONS
     if (loc == 0)
         throw runtime_error("moneypunct_byname"
                             " failed to construct for " + string(nm));
 #endif  // _LIBCPP_NO_EXCEPTIONS
-    lconv* lc = with_locale::localeconv_l(loc.get());
+#ifdef _LIBCPP_STABLE_APPLE_ABI
+    lconv* lc = localeconv_l(loc.get());
+#else
+    lconv* lc = __localeconv_l(loc.get());
+#endif
     if (*lc->mon_decimal_point)
         __decimal_point_ = static_cast<wchar_t>(*lc->mon_decimal_point);
     else
@@ -5636,7 +5683,11 @@
     wchar_t wbuf[100];
     mbstate_t mb = {0};
     const char* bb = lc->int_curr_symbol;
-    size_t j = with_locale::mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
+#ifdef _LIBCPP_STABLE_APPLE_ABI
+    size_t j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
+#else
+    size_t j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
+#endif
     if (j == -1)
         __throw_runtime_error("locale not supported");
     wchar_t* wbe = wbuf + j;
@@ -5651,7 +5702,11 @@
     {
         mb = mbstate_t();
         bb = lc->positive_sign;
-        j = with_locale::mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
+#ifdef _LIBCPP_STABLE_APPLE_ABI
+        j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
+#else
+        j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
+#endif
         if (j == -1)
             __throw_runtime_error("locale not supported");
         wbe = wbuf + j;
@@ -5663,7 +5718,11 @@
     {
         mb = mbstate_t();
         bb = lc->negative_sign;
-        j = with_locale::mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
+#ifdef _LIBCPP_STABLE_APPLE_ABI
+        j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
+#else
+        j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
+#endif
         if (j == -1)
             __throw_runtime_error("locale not supported");
         wbe = wbuf + j;





More information about the cfe-commits mailing list