[libcxx] r261230 - Split locale management out of ibm/xlocale.h. NFCI

Ben Craig via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 18 09:37:33 PST 2016


Author: bcraig
Date: Thu Feb 18 11:37:33 2016
New Revision: 261230

URL: http://llvm.org/viewvc/llvm-project?rev=261230&view=rev
Log:
Split locale management out of ibm/xlocale.h. NFCI

This is one part of many of a locale refactor. See
http://reviews.llvm.org/D17146 for an idea of where this is going.

For the locale refactor, the locale management functions (newlocale,
freelocale, uselocale) are needed in a separate header from the various _l
functions. This is because some platforms implement the _l functions in terms
of a locale switcher RAII helper, and the locale switcher RAII helper needs
the locale management functions. This patch helps pave the way by getting all
the functions in the right files, so that later diffs aren't completely
horrible.

Unfortunately, I have no access to an AIX machine to build with, so this change
has been made blind. Also, the original author (Xing Xue) does not appear to
have a Phabricator account.

Reviewed: http://reviews.llvm.org/D17380

Added:
    libcxx/trunk/include/support/ibm/locale_mgmt_aix.h
Modified:
    libcxx/trunk/include/support/ibm/xlocale.h

Added: libcxx/trunk/include/support/ibm/locale_mgmt_aix.h
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/support/ibm/locale_mgmt_aix.h?rev=261230&view=auto
==============================================================================
--- libcxx/trunk/include/support/ibm/locale_mgmt_aix.h (added)
+++ libcxx/trunk/include/support/ibm/locale_mgmt_aix.h Thu Feb 18 11:37:33 2016
@@ -0,0 +1,85 @@
+// -*- C++ -*-
+//===------------------- support/ibm/locale_mgmt_aix.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.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_SUPPORT_IBM_LOCALE_MGMT_AIX_H
+#define _LIBCPP_SUPPORT_IBM_LOCALE_MGMT_AIX_H
+
+#if defined(_AIX)
+#include "cstdlib"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if !defined(_AIX71)
+// AIX 7.1 and higher has these definitions.  Definitions and stubs
+// are provied here as a temporary workaround on AIX 6.1.
+
+#define LC_COLLATE_MASK         1
+#define LC_CTYPE_MASK           2
+#define LC_MESSAGES_MASK        4
+#define LC_MONETARY_MASK        8
+#define LC_NUMERIC_MASK         16
+#define LC_TIME_MASK            32
+#define LC_ALL_MASK             (LC_COLLATE_MASK | LC_CTYPE_MASK | \
+                                 LC_MESSAGES_MASK | LC_MONETARY_MASK |\
+                                 LC_NUMERIC_MASK | LC_TIME_MASK)
+
+typedef void* locale_t;
+
+// The following are stubs.  They are not supported on AIX 6.1.
+static inline
+locale_t newlocale(int category_mask, const char *locale, locale_t base)
+{
+  _LC_locale_t *newloc, *loc;
+  if ((loc = (_LC_locale_t *)__xopen_locale(locale)) == NULL)
+  {
+    errno = EINVAL;
+    return (locale_t)0;
+  }
+  if ((newloc = (_LC_locale_t *)calloc(1, sizeof(_LC_locale_t))) == NULL)
+  {
+    errno = ENOMEM;
+    return (locale_t)0;
+  }
+  if (!base)
+    base = (_LC_locale_t *)__xopen_locale("C");
+  memcpy(newloc, base, sizeof (_LC_locale_t));
+  if (category_mask & LC_COLLATE_MASK)
+    newloc->lc_collate = loc->lc_collate;
+  if (category_mask & LC_CTYPE_MASK)
+    newloc->lc_ctype = loc->lc_ctype;
+  //if (category_mask & LC_MESSAGES_MASK)
+  //  newloc->lc_messages = loc->lc_messages;
+  if (category_mask & LC_MONETARY_MASK)
+    newloc->lc_monetary = loc->lc_monetary;
+  if (category_mask & LC_TIME_MASK)
+    newloc->lc_time = loc->lc_time;
+  if (category_mask & LC_NUMERIC_MASK)
+    newloc->lc_numeric = loc->lc_numeric;
+  return (locale_t)newloc;
+}
+static inline
+void freelocale(locale_t locobj)
+{
+  free(locobj);
+}
+static inline
+locale_t uselocale(locale_t newloc)
+{
+  return (locale_t)0;
+}
+#endif // !defined(_AIX71)
+
+#ifdef __cplusplus
+}
+#endif
+#endif // defined(_AIX)
+#endif // _LIBCPP_SUPPORT_IBM_LOCALE_MGMT_AIX_H

Modified: libcxx/trunk/include/support/ibm/xlocale.h
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/support/ibm/xlocale.h?rev=261230&r1=261229&r2=261230&view=diff
==============================================================================
--- libcxx/trunk/include/support/ibm/xlocale.h (original)
+++ libcxx/trunk/include/support/ibm/xlocale.h Thu Feb 18 11:37:33 2016
@@ -10,6 +10,7 @@
 
 #ifndef _LIBCPP_SUPPORT_IBM_XLOCALE_H
 #define _LIBCPP_SUPPORT_IBM_XLOCALE_H
+#include <support/ibm/locale_mgmt_aix.h>
 
 #if defined(_AIX)
 #include "cstdlib"
@@ -21,62 +22,6 @@ extern "C" {
 #if !defined(_AIX71)
 // AIX 7.1 and higher has these definitions.  Definitions and stubs
 // are provied here as a temporary workaround on AIX 6.1.
-
-#define LC_COLLATE_MASK         1
-#define LC_CTYPE_MASK           2
-#define LC_MESSAGES_MASK        4
-#define LC_MONETARY_MASK        8
-#define LC_NUMERIC_MASK         16
-#define LC_TIME_MASK            32
-#define LC_ALL_MASK             (LC_COLLATE_MASK | LC_CTYPE_MASK | \
-                                 LC_MESSAGES_MASK | LC_MONETARY_MASK |\
-                                 LC_NUMERIC_MASK | LC_TIME_MASK)
-
-typedef void* locale_t;
-
-// The following are stubs.  They are not supported on AIX 6.1.
-static inline
-locale_t newlocale(int category_mask, const char *locale, locale_t base)
-{
-  _LC_locale_t *newloc, *loc;
-  if ((loc = (_LC_locale_t *)__xopen_locale(locale)) == NULL)
-  {
-    errno = EINVAL;
-    return (locale_t)0;
-  }
-  if ((newloc = (_LC_locale_t *)calloc(1, sizeof(_LC_locale_t))) == NULL)
-  {
-    errno = ENOMEM;
-    return (locale_t)0;
-  }
-  if (!base)
-    base = (_LC_locale_t *)__xopen_locale("C");
-  memcpy(newloc, base, sizeof (_LC_locale_t));
-  if (category_mask & LC_COLLATE_MASK) 
-    newloc->lc_collate = loc->lc_collate;
-  if (category_mask & LC_CTYPE_MASK)
-    newloc->lc_ctype = loc->lc_ctype;
-  //if (category_mask & LC_MESSAGES_MASK)
-  //  newloc->lc_messages = loc->lc_messages;
-  if (category_mask & LC_MONETARY_MASK)
-    newloc->lc_monetary = loc->lc_monetary;
-  if (category_mask & LC_TIME_MASK)
-    newloc->lc_time = loc->lc_time;
-  if (category_mask & LC_NUMERIC_MASK)
-    newloc->lc_numeric = loc->lc_numeric;
-  return (locale_t)newloc; 
-}
-static inline
-void freelocale(locale_t locobj)
-{
-  free(locobj);
-}
-static inline
-locale_t uselocale(locale_t newloc)
-{
-  return (locale_t)0;
-}
-
 static inline
 int isalnum_l(int c, locale_t locale)
 {




More information about the cfe-commits mailing list