Hi jroelofs, mclow.lists,

After D10690 lands, libc++'s locale code will compile on CloudABI, with the 
exception of the following two bits:

- CloudABI doesn't have `setlocale()`, as the C library does not keep track of 
any global state. The global locale is always set to "C". Disable the call to 
`setlocale()` on this system.
- Similarly, `mbtowc_l()` is also not present, as it is also not thread-safe. 
As CloudABI does not support state-dependent encodings, simply disable that 
part of the logic.

After D10690 and this patch hit the tree, the locale code will compile out of 
the box on CloudABI.

REPOSITORY
  rL LLVM

http://reviews.llvm.org/D10729

Files:
  src/locale.cpp

Index: src/locale.cpp
===================================================================
--- src/locale.cpp
+++ src/locale.cpp
@@ -575,8 +575,10 @@
     locale& g = __global();
     locale r = g;
     g = loc;
+#ifndef __CloudABI__
     if (g.name() != "*")
         setlocale(LC_ALL, g.name().c_str());
+#endif
     return r;
 }
 
@@ -1707,22 +1709,23 @@
 int
 codecvt<wchar_t, char, mbstate_t>::do_encoding() const  _NOEXCEPT
 {
+#ifndef __CloudABI__
 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
-    if (mbtowc_l(nullptr, nullptr, MB_LEN_MAX, __l) == 0)
+    if (mbtowc_l(nullptr, nullptr, MB_LEN_MAX, __l) != 0)
 #else
-    if (__mbtowc_l(nullptr, nullptr, MB_LEN_MAX, __l) == 0)
+    if (__mbtowc_l(nullptr, nullptr, MB_LEN_MAX, __l) != 0)
 #endif
-    {
-        // stateless encoding
+        return -1;
+#endif
+
+    // stateless encoding
 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
-        if (__l == 0 || MB_CUR_MAX_L(__l) == 1)  // there are no known 
constant length encodings
+    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
+    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;
-    }
-    return -1;
+        return 1;                // which take more than 1 char to form a 
wchar_t
+    return 0;
 }
 
 bool

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
Index: src/locale.cpp
===================================================================
--- src/locale.cpp
+++ src/locale.cpp
@@ -575,8 +575,10 @@
     locale& g = __global();
     locale r = g;
     g = loc;
+#ifndef __CloudABI__
     if (g.name() != "*")
         setlocale(LC_ALL, g.name().c_str());
+#endif
     return r;
 }
 
@@ -1707,22 +1709,23 @@
 int
 codecvt<wchar_t, char, mbstate_t>::do_encoding() const  _NOEXCEPT
 {
+#ifndef __CloudABI__
 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
-    if (mbtowc_l(nullptr, nullptr, MB_LEN_MAX, __l) == 0)
+    if (mbtowc_l(nullptr, nullptr, MB_LEN_MAX, __l) != 0)
 #else
-    if (__mbtowc_l(nullptr, nullptr, MB_LEN_MAX, __l) == 0)
+    if (__mbtowc_l(nullptr, nullptr, MB_LEN_MAX, __l) != 0)
 #endif
-    {
-        // stateless encoding
+        return -1;
+#endif
+
+    // stateless encoding
 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
-        if (__l == 0 || MB_CUR_MAX_L(__l) == 1)  // there are no known constant length encodings
+    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
+    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;
-    }
-    return -1;
+        return 1;                // which take more than 1 char to form a wchar_t
+    return 0;
 }
 
 bool
_______________________________________________
cfe-commits mailing list
cfe-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to