[libc-commits] [libc] [libc] Add `locale.h` and related stubs (PR #97494)
via libc-commits
libc-commits at lists.llvm.org
Tue Jul 2 17:27:24 PDT 2024
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff 3402a1a4d2d4c7ead69156c3d741fc9ae9c4d399 11db1703d2b6afcc6e8950e4d3dc6ecefc1b2bc2 -- libc/include/llvm-libc-macros/locale-macros.h libc/include/llvm-libc-types/locale_t.h libc/include/llvm-libc-types/struct_lconv.h libc/src/ctype/isdigit_l.cpp libc/src/ctype/isdigit_l.h libc/src/ctype/islower_l.cpp libc/src/ctype/islower_l.h libc/src/ctype/isupper_l.cpp libc/src/ctype/isupper_l.h libc/src/ctype/isxdigit_l.cpp libc/src/ctype/isxdigit_l.h libc/src/ctype/tolower_l.cpp libc/src/ctype/tolower_l.h libc/src/ctype/toupper_l.cpp libc/src/ctype/toupper_l.h libc/src/locale/duplocale.cpp libc/src/locale/duplocale.h libc/src/locale/freelocale.cpp libc/src/locale/freelocale.h libc/src/locale/localeconv.cpp libc/src/locale/localeconv.h libc/src/locale/newlocale.cpp libc/src/locale/newlocale.h libc/src/locale/setlocale.cpp libc/src/locale/setlocale.h libc/src/locale/uselocale.cpp libc/src/locale/uselocale.h libc/src/stdlib/strtod_l.cpp libc/src/stdlib/strtod_l.h libc/src/stdlib/strtof_l.cpp libc/src/stdlib/strtof_l.h libc/src/stdlib/strtold_l.cpp libc/src/stdlib/strtold_l.h libc/src/stdlib/strtoll_l.cpp libc/src/stdlib/strtoll_l.h libc/src/stdlib/strtoull_l.cpp libc/src/stdlib/strtoull_l.h libc/src/string/strcoll_l.cpp libc/src/string/strcoll_l.h libc/src/string/strxfrm_l.cpp libc/src/string/strxfrm_l.h libc/include/llvm-libc-macros/stdlib-macros.h
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/libc/include/llvm-libc-macros/locale-macros.h b/libc/include/llvm-libc-macros/locale-macros.h
index 3c9098cb97..afc3fdbfdb 100644
--- a/libc/include/llvm-libc-macros/locale-macros.h
+++ b/libc/include/llvm-libc-macros/locale-macros.h
@@ -27,6 +27,4 @@
#define LC_NUMERIC_MASK 0
#define LC_TIME_MASK 0
-
-
#endif // LLVM_LIBC_MACROS_LOCALE_MACROS_H
diff --git a/libc/include/llvm-libc-types/locale_t.h b/libc/include/llvm-libc-types/locale_t.h
index 3201458853..35b0f9756e 100644
--- a/libc/include/llvm-libc-types/locale_t.h
+++ b/libc/include/llvm-libc-types/locale_t.h
@@ -13,6 +13,6 @@
// HACK(@izaakschroeder): Placeholder.
// NOTE: According to `libcxx` the `locale_t` type has to be at least
// coercible to a `bool`.
-typedef void* locale_t;
+typedef void *locale_t;
#endif // LLVM_LIBC_TYPES_LOCALE_T_H
diff --git a/libc/include/llvm-libc-types/struct_lconv.h b/libc/include/llvm-libc-types/struct_lconv.h
index a5067a2d37..27dd7048ec 100644
--- a/libc/include/llvm-libc-types/struct_lconv.h
+++ b/libc/include/llvm-libc-types/struct_lconv.h
@@ -11,29 +11,29 @@
struct lconv {
char *currency_symbol;
- char *decimal_point;
+ char *decimal_point;
char *grouping;
char *int_curr_symbol;
char *mon_decimal_point;
char *mon_grouping;
- char *mon_thousands_sep;
+ char *mon_thousands_sep;
char *negative_sign;
char *positive_sign;
- char *thousands_sep;
+ char *thousands_sep;
char frac_digits;
char int_frac_digits;
char int_p_cs_precedes;
- char int_p_sep_by_space;
- char int_n_cs_precedes;
- char int_n_sep_by_space;
+ char int_p_sep_by_space;
+ char int_n_cs_precedes;
+ char int_n_sep_by_space;
char int_n_sign_posn;
- char int_p_sign_posn;
+ char int_p_sign_posn;
char n_cs_precedes;
- char n_sep_by_space;
+ char n_sep_by_space;
char n_sign_posn;
- char p_cs_precedes;
- char p_sep_by_space;
- char p_sign_posn;
+ char p_cs_precedes;
+ char p_sep_by_space;
+ char p_sign_posn;
};
#endif // LLVM_LIBC_TYPES_STRUCT_LCONV_H
diff --git a/libc/src/ctype/isdigit_l.cpp b/libc/src/ctype/isdigit_l.cpp
index 24efd56358..5ae615177e 100644
--- a/libc/src/ctype/isdigit_l.cpp
+++ b/libc/src/ctype/isdigit_l.cpp
@@ -7,13 +7,11 @@
//===----------------------------------------------------------------------===//
#include "src/ctype/isdigit_l.h"
-#include "src/ctype/isdigit.h"
#include "src/__support/common.h"
+#include "src/ctype/isdigit.h"
namespace LIBC_NAMESPACE {
-LLVM_LIBC_FUNCTION(int, isdigit_l, (int c, locale_t)) {
- return isdigit(c);
-}
+LLVM_LIBC_FUNCTION(int, isdigit_l, (int c, locale_t)) { return isdigit(c); }
} // namespace LIBC_NAMESPACE
diff --git a/libc/src/ctype/islower_l.cpp b/libc/src/ctype/islower_l.cpp
index 45977dc637..2e4cfcb756 100644
--- a/libc/src/ctype/islower_l.cpp
+++ b/libc/src/ctype/islower_l.cpp
@@ -15,8 +15,6 @@ namespace LIBC_NAMESPACE {
// TODO: Currently restricted to default locale.
// These should be extended using locale information.
-LLVM_LIBC_FUNCTION(int, islower_l, (int c, locale_t)) {
- return islower(c);
-}
+LLVM_LIBC_FUNCTION(int, islower_l, (int c, locale_t)) { return islower(c); }
} // namespace LIBC_NAMESPACE
diff --git a/libc/src/ctype/isupper_l.cpp b/libc/src/ctype/isupper_l.cpp
index e3b1250b94..38a8a90717 100644
--- a/libc/src/ctype/isupper_l.cpp
+++ b/libc/src/ctype/isupper_l.cpp
@@ -15,8 +15,6 @@ namespace LIBC_NAMESPACE {
// TODO: Currently restricted to default locale.
// These should be extended using locale information.
-LLVM_LIBC_FUNCTION(int, isupper_l, (int c, locale_t)) {
- return isupper(c);
-}
+LLVM_LIBC_FUNCTION(int, isupper_l, (int c, locale_t)) { return isupper(c); }
} // namespace LIBC_NAMESPACE
diff --git a/libc/src/ctype/isxdigit_l.cpp b/libc/src/ctype/isxdigit_l.cpp
index cdb6c05438..8e1333331e 100644
--- a/libc/src/ctype/isxdigit_l.cpp
+++ b/libc/src/ctype/isxdigit_l.cpp
@@ -7,8 +7,8 @@
//===----------------------------------------------------------------------===//
#include "src/ctype/isxdigit_l.h"
-#include "src/ctype/isxdigit.h"
#include "src/__support/ctype_utils.h"
+#include "src/ctype/isxdigit.h"
#include "src/__support/common.h"
@@ -16,8 +16,6 @@ namespace LIBC_NAMESPACE {
// TODO: Currently restricted to default locale.
// These should be extended using locale information.
-LLVM_LIBC_FUNCTION(int, isxdigit_l, (int c, locale_t)) {
- return isxdigit(c);
-}
+LLVM_LIBC_FUNCTION(int, isxdigit_l, (int c, locale_t)) { return isxdigit(c); }
} // namespace LIBC_NAMESPACE
diff --git a/libc/src/ctype/toupper_l.cpp b/libc/src/ctype/toupper_l.cpp
index 5806f22d69..59ab613ffa 100644
--- a/libc/src/ctype/toupper_l.cpp
+++ b/libc/src/ctype/toupper_l.cpp
@@ -7,8 +7,8 @@
//===----------------------------------------------------------------------===//
#include "src/ctype/toupper_l.h"
-#include "src/ctype/toupper.h"
#include "src/__support/ctype_utils.h"
+#include "src/ctype/toupper.h"
#include "src/__support/common.h"
@@ -16,8 +16,6 @@ namespace LIBC_NAMESPACE {
// TODO: Currently restricted to default locale.
// These should be extended using locale information.
-LLVM_LIBC_FUNCTION(int, toupper_l, (int c, locale_t)) {
- return toupper(c);
-}
+LLVM_LIBC_FUNCTION(int, toupper_l, (int c, locale_t)) { return toupper(c); }
} // namespace LIBC_NAMESPACE
diff --git a/libc/src/locale/duplocale.cpp b/libc/src/locale/duplocale.cpp
index ab6441a01f..3c0a0f6688 100644
--- a/libc/src/locale/duplocale.cpp
+++ b/libc/src/locale/duplocale.cpp
@@ -11,8 +11,6 @@
namespace LIBC_NAMESPACE {
-LLVM_LIBC_FUNCTION(locale_t, duplocale, (locale_t locale)) {
- return locale;
-}
+LLVM_LIBC_FUNCTION(locale_t, duplocale, (locale_t locale)) { return locale; }
} // namespace LIBC_NAMESPACE
diff --git a/libc/src/locale/localeconv.cpp b/libc/src/locale/localeconv.cpp
index c36ef8f1ef..fd9a081198 100644
--- a/libc/src/locale/localeconv.cpp
+++ b/libc/src/locale/localeconv.cpp
@@ -6,37 +6,37 @@
//
//===----------------------------------------------------------------------===//
-#include <limits.h>
#include "localeconv.h"
#include "src/__support/common.h"
+#include <limits.h>
namespace LIBC_NAMESPACE {
static const struct lconv posix_lconv = {
- .currency_symbol = const_cast<char*>(""),
- .decimal_point = const_cast<char*>("."),
- .grouping = const_cast<char*>(""),
- .int_curr_symbol = const_cast<char*>(""),
- .mon_decimal_point = const_cast<char*>(""),
- .mon_grouping = const_cast<char*>(""),
- .mon_thousands_sep = const_cast<char*>(""),
- .negative_sign = const_cast<char*>(""),
- .positive_sign = const_cast<char*>(""),
- .thousands_sep = const_cast<char*>(""),
- .frac_digits = CHAR_MAX,
- .int_frac_digits = CHAR_MAX,
- .int_p_cs_precedes = CHAR_MAX,
- .int_p_sep_by_space = CHAR_MAX,
- .int_n_cs_precedes = CHAR_MAX,
- .int_n_sep_by_space = CHAR_MAX,
- .int_n_sign_posn = CHAR_MAX,
- .int_p_sign_posn = CHAR_MAX,
- .n_cs_precedes = CHAR_MAX,
- .n_sep_by_space = CHAR_MAX,
- .n_sign_posn = CHAR_MAX,
- .p_cs_precedes = CHAR_MAX,
- .p_sep_by_space = CHAR_MAX,
- .p_sign_posn = CHAR_MAX,
+ .currency_symbol = const_cast<char *>(""),
+ .decimal_point = const_cast<char *>("."),
+ .grouping = const_cast<char *>(""),
+ .int_curr_symbol = const_cast<char *>(""),
+ .mon_decimal_point = const_cast<char *>(""),
+ .mon_grouping = const_cast<char *>(""),
+ .mon_thousands_sep = const_cast<char *>(""),
+ .negative_sign = const_cast<char *>(""),
+ .positive_sign = const_cast<char *>(""),
+ .thousands_sep = const_cast<char *>(""),
+ .frac_digits = CHAR_MAX,
+ .int_frac_digits = CHAR_MAX,
+ .int_p_cs_precedes = CHAR_MAX,
+ .int_p_sep_by_space = CHAR_MAX,
+ .int_n_cs_precedes = CHAR_MAX,
+ .int_n_sep_by_space = CHAR_MAX,
+ .int_n_sign_posn = CHAR_MAX,
+ .int_p_sign_posn = CHAR_MAX,
+ .n_cs_precedes = CHAR_MAX,
+ .n_sep_by_space = CHAR_MAX,
+ .n_sign_posn = CHAR_MAX,
+ .p_cs_precedes = CHAR_MAX,
+ .p_sep_by_space = CHAR_MAX,
+ .p_sign_posn = CHAR_MAX,
};
LLVM_LIBC_FUNCTION(struct lconv *, localeconv, ()) {
diff --git a/libc/src/locale/setlocale.cpp b/libc/src/locale/setlocale.cpp
index bc8797b5e9..9a5aba4127 100644
--- a/libc/src/locale/setlocale.cpp
+++ b/libc/src/locale/setlocale.cpp
@@ -12,7 +12,7 @@
namespace LIBC_NAMESPACE {
LLVM_LIBC_FUNCTION(char *, setlocale, (int, const char *)) {
- return const_cast<char*>("unsupported");
+ return const_cast<char *>("unsupported");
}
} // namespace LIBC_NAMESPACE
diff --git a/libc/src/locale/uselocale.cpp b/libc/src/locale/uselocale.cpp
index 6266e24f49..b614313ac7 100644
--- a/libc/src/locale/uselocale.cpp
+++ b/libc/src/locale/uselocale.cpp
@@ -11,8 +11,6 @@
namespace LIBC_NAMESPACE {
-LLVM_LIBC_FUNCTION(locale_t, uselocale, (locale_t locale)) {
- return locale;
-}
+LLVM_LIBC_FUNCTION(locale_t, uselocale, (locale_t locale)) { return locale; }
} // namespace LIBC_NAMESPACE
diff --git a/libc/src/stdlib/strtod_l.cpp b/libc/src/stdlib/strtod_l.cpp
index 44670b0c18..898a925d5f 100644
--- a/libc/src/stdlib/strtod_l.cpp
+++ b/libc/src/stdlib/strtod_l.cpp
@@ -1,4 +1,5 @@
-//===-- Implementation of strtod_l -----------------------------------------===//
+//===-- Implementation of strtod_l
+//-----------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -7,14 +8,14 @@
//===----------------------------------------------------------------------===//
#include "src/stdlib/strtod_l.h"
-#include "src/stdlib/strtod.h"
#include "src/__support/common.h"
-
+#include "src/stdlib/strtod.h"
namespace LIBC_NAMESPACE {
LLVM_LIBC_FUNCTION(double, strtod_l,
- (const char *__restrict str, char **__restrict str_end, locale_t)) {
+ (const char *__restrict str, char **__restrict str_end,
+ locale_t)) {
return strtod(str, str_end);
}
diff --git a/libc/src/stdlib/strtod_l.h b/libc/src/stdlib/strtod_l.h
index 49da430d17..6e130f332e 100644
--- a/libc/src/stdlib/strtod_l.h
+++ b/libc/src/stdlib/strtod_l.h
@@ -1,4 +1,5 @@
-//===-- Implementation header for strtod_l -----------------------*- C++ -*-===//
+//===-- Implementation header for strtod_l -----------------------*- C++
+//-*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -13,7 +14,8 @@
namespace LIBC_NAMESPACE {
-double strtod_l(const char *__restrict str, char **__restrict str_end, locale_t locale);
+double strtod_l(const char *__restrict str, char **__restrict str_end,
+ locale_t locale);
} // namespace LIBC_NAMESPACE
diff --git a/libc/src/stdlib/strtof_l.cpp b/libc/src/stdlib/strtof_l.cpp
index f8e480fc10..c5d25e60be 100644
--- a/libc/src/stdlib/strtof_l.cpp
+++ b/libc/src/stdlib/strtof_l.cpp
@@ -1,4 +1,5 @@
-//===-- Implementation of strtof_l -----------------------------------------===//
+//===-- Implementation of strtof_l
+//-----------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -7,13 +8,14 @@
//===----------------------------------------------------------------------===//
#include "src/stdlib/strtof_l.h"
-#include "src/stdlib/strtof.h"
#include "src/__support/common.h"
+#include "src/stdlib/strtof.h"
namespace LIBC_NAMESPACE {
LLVM_LIBC_FUNCTION(float, strtof_l,
- (const char *__restrict str, char **__restrict str_end, locale_t)) {
+ (const char *__restrict str, char **__restrict str_end,
+ locale_t)) {
return strtof(str, str_end);
}
diff --git a/libc/src/stdlib/strtof_l.h b/libc/src/stdlib/strtof_l.h
index 290b7825d1..40552ba2d8 100644
--- a/libc/src/stdlib/strtof_l.h
+++ b/libc/src/stdlib/strtof_l.h
@@ -1,4 +1,5 @@
-//===-- Implementation header for strtof_l -----------------------*- C++ -*-===//
+//===-- Implementation header for strtof_l -----------------------*- C++
+//-*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -13,7 +14,8 @@
namespace LIBC_NAMESPACE {
-float strtof_l(const char *__restrict str, char **__restrict str_end, locale_t locale);
+float strtof_l(const char *__restrict str, char **__restrict str_end,
+ locale_t locale);
} // namespace LIBC_NAMESPACE
diff --git a/libc/src/stdlib/strtold_l.cpp b/libc/src/stdlib/strtold_l.cpp
index 0756d81ea4..245356ce08 100644
--- a/libc/src/stdlib/strtold_l.cpp
+++ b/libc/src/stdlib/strtold_l.cpp
@@ -7,13 +7,14 @@
//===----------------------------------------------------------------------===//
#include "src/stdlib/strtold_l.h"
-#include "src/stdlib/strtold.h"
#include "src/__support/common.h"
+#include "src/stdlib/strtold.h"
namespace LIBC_NAMESPACE {
LLVM_LIBC_FUNCTION(long double, strtold_l,
- (const char *__restrict str, char **__restrict str_end, locale_t)) {
+ (const char *__restrict str, char **__restrict str_end,
+ locale_t)) {
return strtold(str, str_end);
}
diff --git a/libc/src/stdlib/strtold_l.h b/libc/src/stdlib/strtold_l.h
index e66e68c9dc..d156f46d50 100644
--- a/libc/src/stdlib/strtold_l.h
+++ b/libc/src/stdlib/strtold_l.h
@@ -13,7 +13,8 @@
namespace LIBC_NAMESPACE {
-long double strtold_l(const char *__restrict str, char **__restrict str_end, locale_t locale);
+long double strtold_l(const char *__restrict str, char **__restrict str_end,
+ locale_t locale);
} // namespace LIBC_NAMESPACE
diff --git a/libc/src/stdlib/strtoll_l.cpp b/libc/src/stdlib/strtoll_l.cpp
index d48d1b1c13..e3a6c89a2a 100644
--- a/libc/src/stdlib/strtoll_l.cpp
+++ b/libc/src/stdlib/strtoll_l.cpp
@@ -7,15 +7,15 @@
//===----------------------------------------------------------------------===//
#include "src/stdlib/strtoll_l.h"
-#include "src/stdlib/strtoll.h"
#include "src/__support/common.h"
+#include "src/stdlib/strtoll.h"
namespace LIBC_NAMESPACE {
LLVM_LIBC_FUNCTION(long long, strtoll_l,
(const char *__restrict str, char **__restrict str_end,
int base, locale_t)) {
-
+
return strtoll(str, str_end, base);
}
diff --git a/libc/src/stdlib/strtoll_l.h b/libc/src/stdlib/strtoll_l.h
index b0e1122e64..96cab62897 100644
--- a/libc/src/stdlib/strtoll_l.h
+++ b/libc/src/stdlib/strtoll_l.h
@@ -14,7 +14,7 @@
namespace LIBC_NAMESPACE {
long long strtoll_l(const char *__restrict str, char **__restrict str_end,
- int base, locale_t);
+ int base, locale_t);
} // namespace LIBC_NAMESPACE
diff --git a/libc/src/stdlib/strtoull_l.cpp b/libc/src/stdlib/strtoull_l.cpp
index 4a246826a4..72f8fd011d 100644
--- a/libc/src/stdlib/strtoull_l.cpp
+++ b/libc/src/stdlib/strtoull_l.cpp
@@ -7,8 +7,8 @@
//===----------------------------------------------------------------------===//
#include "src/stdlib/strtoull_l.h"
-#include "src/stdlib/strtoull.h"
#include "src/__support/common.h"
+#include "src/stdlib/strtoull.h"
namespace LIBC_NAMESPACE {
diff --git a/libc/src/stdlib/strtoull_l.h b/libc/src/stdlib/strtoull_l.h
index a7c1ae197f..6c24ecd3ab 100644
--- a/libc/src/stdlib/strtoull_l.h
+++ b/libc/src/stdlib/strtoull_l.h
@@ -14,7 +14,8 @@
namespace LIBC_NAMESPACE {
unsigned long long strtoull_l(const char *__restrict str,
- char **__restrict str_end, int base, locale_t locale);
+ char **__restrict str_end, int base,
+ locale_t locale);
} // namespace LIBC_NAMESPACE
diff --git a/libc/src/string/strcoll_l.cpp b/libc/src/string/strcoll_l.cpp
index 5392b3553b..8bfef08d91 100644
--- a/libc/src/string/strcoll_l.cpp
+++ b/libc/src/string/strcoll_l.cpp
@@ -14,7 +14,8 @@
namespace LIBC_NAMESPACE {
// TODO: Add support for locales.
-LLVM_LIBC_FUNCTION(int, strcoll_l, (const char *left, const char *right, locale_t)) {
+LLVM_LIBC_FUNCTION(int, strcoll_l,
+ (const char *left, const char *right, locale_t)) {
return strcoll(left, right);
}
diff --git a/libc/src/string/strxfrm_l.cpp b/libc/src/string/strxfrm_l.cpp
index 28f20985c2..8e929185a6 100644
--- a/libc/src/string/strxfrm_l.cpp
+++ b/libc/src/string/strxfrm_l.cpp
@@ -15,8 +15,8 @@ namespace LIBC_NAMESPACE {
// TODO: Add support for locales.
LLVM_LIBC_FUNCTION(size_t, strxfrm_l,
- (char *__restrict dest, const char *__restrict src,
- size_t n, locale_t)) {
+ (char *__restrict dest, const char *__restrict src, size_t n,
+ locale_t)) {
return strxfrm(dest, src, n);
}
diff --git a/libc/src/string/strxfrm_l.h b/libc/src/string/strxfrm_l.h
index ae958a16f3..d56a6ff073 100644
--- a/libc/src/string/strxfrm_l.h
+++ b/libc/src/string/strxfrm_l.h
@@ -1,4 +1,5 @@
-//===-- Implementation header for strxfrm_l -----------------------*- C++ -*-===//
+//===-- Implementation header for strxfrm_l -----------------------*- C++
+//-*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -9,12 +10,13 @@
#ifndef LLVM_LIBC_SRC_STRING_STRXFRM_L_H
#define LLVM_LIBC_SRC_STRING_STRXFRM_L_H
-#include <stddef.h> // For size_t
#include "include/llvm-libc-types/locale_t.h"
+#include <stddef.h> // For size_t
namespace LIBC_NAMESPACE {
-size_t strxfrm_l(char *__restrict dest, const char *__restrict src, size_t n, locale_t locale);
+size_t strxfrm_l(char *__restrict dest, const char *__restrict src, size_t n,
+ locale_t locale);
} // namespace LIBC_NAMESPACE
``````````
</details>
https://github.com/llvm/llvm-project/pull/97494
More information about the libc-commits
mailing list