[PATCH] libc++ locale: Disable cat*() on CloudABI. Also make tiny cleanups.

Ed Schouten ed at nuxi.nl
Mon Mar 9 04:17:03 PDT 2015


Hi mclow.lists,

On a new platform that I am working on (https://github.com/NuxiNL/cloudlibc) I am not implementing the cat{open,close,gets}() API, just like Android, Newlib, etc.

Instead of adding yet another operating system name to the #ifs, introduce _LIPCPP_LOCALE_MESSAGE_CATALOGS in include/__config. Also adjust the code to only pull in nl_types.h when _LIPCPP_LOCALE_MESSAGE_CATALOGS is set. We only needed this header for the cat*() API.

REPOSITORY
  rL LLVM

http://reviews.llvm.org/D8163

Files:
  include/__config
  include/locale

Index: include/__config
===================================================================
--- include/__config
+++ include/__config
@@ -636,6 +636,11 @@
 #define _LIBCPP_LOCALE__L_EXTENSIONS 1
 #endif
 
+#if !defined(_WIN32) && !defined(__ANDROID__) && !defined(_NEWLIB_VERSION) && \
+    !defined(__CloudABI__)
+#define _LIPCPP_LOCALE_MESSAGE_CATALOGS 1
+#endif
+
 #ifdef __FreeBSD__
 #define _DECLARE_C99_LDBL_MATH 1
 #endif
Index: include/locale
===================================================================
--- include/locale
+++ include/locale
@@ -198,7 +198,8 @@
 // include of <sys/cdefs.h> once https://sourceware.org/ml/newlib-cvs/2014-q3/msg00038.html
 // has had a chance to bake for a bit
 #include <support/newlib/xlocale.h>
-#elif !defined(__ANDROID__)
+#endif
+#ifdef _LIPCPP_LOCALE_MESSAGE_CATALOGS
 #include <nl_types.h>
 #endif
 
@@ -3681,14 +3682,14 @@
 typename messages<_CharT>::catalog
 messages<_CharT>::do_open(const basic_string<char>& __nm, const locale&) const
 {
-#if defined(_WIN32) || defined(__ANDROID__) || defined(_NEWLIB_VERSION)
-    return -1;
-#else // _WIN32 || __ANDROID__
+#ifdef _LIPCPP_LOCALE_MESSAGE_CATALOGS
     catalog __cat = (catalog)catopen(__nm.c_str(), NL_CAT_LOCALE);
     if (__cat != -1)
         __cat = static_cast<catalog>((static_cast<size_t>(__cat) >> 1));
     return __cat;
-#endif // _WIN32 || __ANDROID__
+#else // !_LIPCPP_LOCALE_MESSAGE_CATALOGS
+    return -1;
+#endif // _LIPCPP_LOCALE_MESSAGE_CATALOGS
 }
 
 template <class _CharT>
@@ -3696,9 +3697,7 @@
 messages<_CharT>::do_get(catalog __c, int __set, int __msgid,
                          const string_type& __dflt) const
 {
-#if defined(_WIN32) || defined(__ANDROID__) || defined(_NEWLIB_VERSION)
-    return __dflt;
-#else // _WIN32
+#ifdef _LIPCPP_LOCALE_MESSAGE_CATALOGS
     string __ndflt;
     __narrow_to_utf8<sizeof(char_type)*__CHAR_BIT__>()(back_inserter(__ndflt),
                                                        __dflt.c_str(),
@@ -3711,7 +3710,9 @@
     __widen_from_utf8<sizeof(char_type)*__CHAR_BIT__>()(back_inserter(__w),
                                                         __n, __n + strlen(__n));
     return __w;
-#endif // _WIN32
+#else // !_LIPCPP_LOCALE_MESSAGE_CATALOGS
+    return __dflt;
+#endif // _LIPCPP_LOCALE_MESSAGE_CATALOGS
 }
 
 template <class _CharT>
@@ -3718,12 +3719,12 @@
 void
 messages<_CharT>::do_close(catalog __c) const
 {
-#if !defined(_WIN32) && !defined(__ANDROID__) && !defined(_NEWLIB_VERSION)
+#ifdef _LIPCPP_LOCALE_MESSAGE_CATALOGS
     if (__c != -1)
         __c <<= 1;
     nl_catd __cat = (nl_catd)__c;
     catclose(__cat);
-#endif // !_WIN32
+#endif // _LIPCPP_LOCALE_MESSAGE_CATALOGS
 }
 
 _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS messages<char>)

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D8163.21478.patch
Type: text/x-patch
Size: 2755 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150309/9f8992b8/attachment.bin>


More information about the cfe-commits mailing list