[libcxx] r270213 - Reorganize locale extension fallbacks. NFCI

Ben Craig via cfe-commits cfe-commits at lists.llvm.org
Fri May 20 05:58:44 PDT 2016


Author: bcraig
Date: Fri May 20 07:58:41 2016
New Revision: 270213

URL: http://llvm.org/viewvc/llvm-project?rev=270213&view=rev
Log:
Reorganize locale extension fallbacks. NFCI

The various _l locale extension functions originate from very
different places.  Some come from POSIX, some are BSD extensions,
and some are shared BSD and GLIBC extensions. This patch tries to
group the local extension reimplementations by source. This should
make it easier to make libcxx work with POSIX compliant C libraries
that lack these extensions.

The fallback locale functions are also useful on their own for other
lightweight platforms. Putting these fallback implementations in
support/xlocale should enable code sharing.

I have no access to a newlib system or an android system to build
and test with. I _do_ have access to a system without any of the _l
locale extensions though, and I was able to ensure that the new
__posix_l_fallback.h and __strtonum_fallback.h didn't have any massive
problems.

http://reviews.llvm.org/D17416

Added:
    libcxx/trunk/include/support/xlocale/__posix_l_fallback.h
    libcxx/trunk/include/support/xlocale/__strtonum_fallback.h
    libcxx/trunk/include/support/xlocale/xlocale.h
Modified:
    libcxx/trunk/include/support/android/locale_bionic.h
    libcxx/trunk/include/support/newlib/xlocale.h

Modified: libcxx/trunk/include/support/android/locale_bionic.h
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/support/android/locale_bionic.h?rev=270213&r1=270212&r2=270213&view=diff
==============================================================================
--- libcxx/trunk/include/support/android/locale_bionic.h (original)
+++ libcxx/trunk/include/support/android/locale_bionic.h Fri May 20 07:58:41 2016
@@ -24,8 +24,8 @@ extern "C" {
 }
 #endif
 
-// Share implementation with Newlib
-#include <support/xlocale/xlocale.h>
+#include <support/xlocale/__posix_l_fallback.h>
+#include <support/xlocale/__strtonum_fallback.h>
 
 #endif // defined(__ANDROID__)
 #endif // _LIBCPP_SUPPORT_ANDROID_LOCALE_BIONIC_H

Modified: libcxx/trunk/include/support/newlib/xlocale.h
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/support/newlib/xlocale.h?rev=270213&r1=270212&r2=270213&view=diff
==============================================================================
--- libcxx/trunk/include/support/newlib/xlocale.h (original)
+++ libcxx/trunk/include/support/newlib/xlocale.h Fri May 20 07:58:41 2016
@@ -17,17 +17,8 @@
 #include <cwctype>
 #include <ctype.h>
 #include <support/xlocale/__nop_locale_mgmt.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-// Share implementation with Android's Bionic
-#include <support/xlocale/xlocale.h>
-
-#ifdef __cplusplus
-} // extern "C"
-#endif
+#include <support/xlocale/__posix_l_fallback.h>
+#include <support/xlocale/__strtonum_fallback.h>
 
 #endif // _NEWLIB_VERSION
 

Added: libcxx/trunk/include/support/xlocale/__posix_l_fallback.h
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/support/xlocale/__posix_l_fallback.h?rev=270213&view=auto
==============================================================================
--- libcxx/trunk/include/support/xlocale/__posix_l_fallback.h (added)
+++ libcxx/trunk/include/support/xlocale/__posix_l_fallback.h Fri May 20 07:58:41 2016
@@ -0,0 +1,165 @@
+// -*- C++ -*-
+//===--------------- support/xlocale/__posix_l_fallback.h -----------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+// These are reimplementations of some extended locale functions ( *_l ) that
+// are normally part of POSIX.  This shared implementation provides parts of the
+// extended locale support for libc's that normally don't have any (like
+// Android's bionic and Newlib).
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_SUPPORT_XLOCALE_POSIX_L_FALLBACK_H
+#define _LIBCPP_SUPPORT_XLOCALE_POSIX_L_FALLBACK_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+inline _LIBCPP_ALWAYS_INLINE int isalnum_l(int c, locale_t) {
+  return ::isalnum(c);
+}
+
+inline _LIBCPP_ALWAYS_INLINE int isalpha_l(int c, locale_t) {
+  return ::isalpha(c);
+}
+
+inline _LIBCPP_ALWAYS_INLINE int isblank_l(int c, locale_t) {
+  return ::isblank(c);
+}
+
+inline _LIBCPP_ALWAYS_INLINE int iscntrl_l(int c, locale_t) {
+  return ::iscntrl(c);
+}
+
+inline _LIBCPP_ALWAYS_INLINE int isdigit_l(int c, locale_t) {
+  return ::isdigit(c);
+}
+
+inline _LIBCPP_ALWAYS_INLINE int isgraph_l(int c, locale_t) {
+  return ::isgraph(c);
+}
+
+inline _LIBCPP_ALWAYS_INLINE int islower_l(int c, locale_t) {
+  return ::islower(c);
+}
+
+inline _LIBCPP_ALWAYS_INLINE int isprint_l(int c, locale_t) {
+  return ::isprint(c);
+}
+
+inline _LIBCPP_ALWAYS_INLINE int ispunct_l(int c, locale_t) {
+  return ::ispunct(c);
+}
+
+inline _LIBCPP_ALWAYS_INLINE int isspace_l(int c, locale_t) {
+  return ::isspace(c);
+}
+
+inline _LIBCPP_ALWAYS_INLINE int isupper_l(int c, locale_t) {
+  return ::isupper(c);
+}
+
+inline _LIBCPP_ALWAYS_INLINE int isxdigit_l(int c, locale_t) {
+  return ::isxdigit(c);
+}
+
+inline _LIBCPP_ALWAYS_INLINE int iswalnum_l(wint_t c, locale_t) {
+  return ::iswalnum(c);
+}
+
+inline _LIBCPP_ALWAYS_INLINE int iswalpha_l(wint_t c, locale_t) {
+  return ::iswalpha(c);
+}
+
+inline _LIBCPP_ALWAYS_INLINE int iswblank_l(wint_t c, locale_t) {
+  return ::iswblank(c);
+}
+
+inline _LIBCPP_ALWAYS_INLINE int iswcntrl_l(wint_t c, locale_t) {
+  return ::iswcntrl(c);
+}
+
+inline _LIBCPP_ALWAYS_INLINE int iswdigit_l(wint_t c, locale_t) {
+  return ::iswdigit(c);
+}
+
+inline _LIBCPP_ALWAYS_INLINE int iswgraph_l(wint_t c, locale_t) {
+  return ::iswgraph(c);
+}
+
+inline _LIBCPP_ALWAYS_INLINE int iswlower_l(wint_t c, locale_t) {
+  return ::iswlower(c);
+}
+
+inline _LIBCPP_ALWAYS_INLINE int iswprint_l(wint_t c, locale_t) {
+  return ::iswprint(c);
+}
+
+inline _LIBCPP_ALWAYS_INLINE int iswpunct_l(wint_t c, locale_t) {
+  return ::iswpunct(c);
+}
+
+inline _LIBCPP_ALWAYS_INLINE int iswspace_l(wint_t c, locale_t) {
+  return ::iswspace(c);
+}
+
+inline _LIBCPP_ALWAYS_INLINE int iswupper_l(wint_t c, locale_t) {
+  return ::iswupper(c);
+}
+
+inline _LIBCPP_ALWAYS_INLINE int iswxdigit_l(wint_t c, locale_t) {
+  return ::iswxdigit(c);
+}
+
+inline _LIBCPP_ALWAYS_INLINE int toupper_l(int c, locale_t) {
+  return ::toupper(c);
+}
+
+inline _LIBCPP_ALWAYS_INLINE int tolower_l(int c, locale_t) {
+  return ::tolower(c);
+}
+
+inline _LIBCPP_ALWAYS_INLINE int towupper_l(int c, locale_t) {
+  return ::towupper(c);
+}
+
+inline _LIBCPP_ALWAYS_INLINE int towlower_l(int c, locale_t) {
+  return ::towlower(c);
+}
+
+inline _LIBCPP_ALWAYS_INLINE int strcoll_l(const char *s1, const char *s2,
+                                           locale_t) {
+  return ::strcoll(s1, s2);
+}
+
+inline _LIBCPP_ALWAYS_INLINE size_t strxfrm_l(char *dest, const char *src,
+                                              size_t n, locale_t) {
+  return ::strxfrm(dest, src, n);
+}
+
+inline _LIBCPP_ALWAYS_INLINE size_t strftime_l(char *s, size_t max,
+                                               const char *format,
+                                               const struct tm *tm, locale_t) {
+  return ::strftime(s, max, format, tm);
+}
+
+inline _LIBCPP_ALWAYS_INLINE int wcscoll_l(const wchar_t *ws1,
+                                           const wchar_t *ws2, locale_t) {
+  return ::wcscoll(ws1, ws2);
+}
+
+inline _LIBCPP_ALWAYS_INLINE size_t wcsxfrm_l(wchar_t *dest, const wchar_t *src,
+                                              size_t n, locale_t) {
+  return ::wcsxfrm(dest, src, n);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // _LIBCPP_SUPPORT_XLOCALE_POSIX_L_FALLBACK_H

Added: libcxx/trunk/include/support/xlocale/__strtonum_fallback.h
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/support/xlocale/__strtonum_fallback.h?rev=270213&view=auto
==============================================================================
--- libcxx/trunk/include/support/xlocale/__strtonum_fallback.h (added)
+++ libcxx/trunk/include/support/xlocale/__strtonum_fallback.h Fri May 20 07:58:41 2016
@@ -0,0 +1,56 @@
+// -*- C++ -*-
+//===-------------- support/xlocale/__strtonum_fallback.h -----------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+// These are reimplementations of some extended locale functions ( *_l ) that
+// aren't part of POSIX.  They are widely available though (GLIBC, BSD, maybe
+// others).  The unifying aspect in this case is that all of these functions
+// convert strings to some numeric type.
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_SUPPORT_XLOCALE_STRTONUM_FALLBACK_H
+#define _LIBCPP_SUPPORT_XLOCALE_STRTONUM_FALLBACK_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+inline _LIBCPP_ALWAYS_INLINE long double strtold_l(const char *nptr,
+                                                   char **endptr, locale_t) {
+  return ::strtold(nptr, endptr);
+}
+
+inline _LIBCPP_ALWAYS_INLINE long long
+strtoll_l(const char *nptr, char **endptr, int base, locale_t) {
+  return ::strtoll(nptr, endptr, base);
+}
+
+inline _LIBCPP_ALWAYS_INLINE unsigned long long
+strtoull_l(const char *nptr, char **endptr, int base, locale_t) {
+  return ::strtoull(nptr, endptr, base);
+}
+
+inline _LIBCPP_ALWAYS_INLINE long long
+wcstoll_l(const wchar_t *nptr, wchar_t **endptr, int base, locale_t) {
+  return ::wcstoll(nptr, endptr, base);
+}
+
+inline _LIBCPP_ALWAYS_INLINE unsigned long long
+wcstoull_l(const wchar_t *nptr, wchar_t **endptr, int base, locale_t) {
+  return ::wcstoull(nptr, endptr, base);
+}
+
+inline _LIBCPP_ALWAYS_INLINE long double wcstold_l(const wchar_t *nptr,
+                                                   wchar_t **endptr, locale_t) {
+  return ::wcstold(nptr, endptr);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // _LIBCPP_SUPPORT_XLOCALE_STRTONUM_FALLBACK_H

Added: libcxx/trunk/include/support/xlocale/xlocale.h
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/support/xlocale/xlocale.h?rev=270213&view=auto
==============================================================================
    (empty)




More information about the cfe-commits mailing list