[libc-commits] [libc] [libc] Add internal locale structures and config options (PR #211470)
Jeff Bailey via libc-commits
libc-commits at lists.llvm.org
Tue Nov 17 07:47:31 PST 2026
================
@@ -1,36 +1,96 @@
-//===-- Implementation header for the locale --------------------*- C++ -*-===//
+//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Implementation header for locale state and structures.
+///
+//===----------------------------------------------------------------------===//
-#ifndef LLVM_LIBC_SRC_LOCALE_LOCALECONV_H
-#define LLVM_LIBC_SRC_LOCALE_LOCALECONV_H
+#ifndef LLVM_LIBC_SRC_LOCALE_LOCALE_H
+#define LLVM_LIBC_SRC_LOCALE_LOCALE_H
+#include "hdr/types/locale_t.h"
#include "src/__support/macros/attributes.h"
#include "src/__support/macros/config.h"
+#include "src/locale/locale_data.h"
-#include "hdr/types/locale_t.h"
+namespace LIBC_NAMESPACE_DECL {
-#include <stddef.h>
+template <bool DisableRuntimeLocale> struct LocaleStorage {
+ const LcCtypeData *ctype_ptr;
+ const LcNumericData *numeric_ptr;
+ const LcTimeData *time_ptr;
+ const void *collate_ptr;
+ const LcMonetaryData *monetary_ptr;
+ const LcMessagesData *messages_ptr;
-namespace LIBC_NAMESPACE_DECL {
+ LIBC_INLINE constexpr LocaleStorage(const LcCtypeData *c,
+ const LcNumericData *num,
+ const LcTimeData *t, const void *col,
+ const LcMonetaryData *mon,
+ const LcMessagesData *msg)
+ : ctype_ptr(c), numeric_ptr(num), time_ptr(t), collate_ptr(col),
+ monetary_ptr(mon), messages_ptr(msg) {}
+
+ LIBC_INLINE constexpr const LcCtypeData *ctype() const { return ctype_ptr; }
+ LIBC_INLINE constexpr const LcNumericData *numeric() const {
+ return numeric_ptr;
+ }
+ LIBC_INLINE constexpr const LcTimeData *time() const { return time_ptr; }
+ LIBC_INLINE constexpr const LcMonetaryData *monetary() const {
+ return monetary_ptr;
+ }
+ LIBC_INLINE constexpr const LcMessagesData *messages() const {
+ return messages_ptr;
+ }
+};
-// We only support the "C" locale right now.
-static constexpr size_t MAX_LOCALE_NAME_SIZE = 2;
+template <> struct LocaleStorage<true> {
+ LIBC_INLINE constexpr LocaleStorage(const LcCtypeData *,
+ const LcNumericData *, const LcTimeData *,
+ const void *, const LcMonetaryData *,
+ const LcMessagesData *) {}
-struct __locale_data {
- char name[MAX_LOCALE_NAME_SIZE];
+ LIBC_INLINE constexpr const LcCtypeData *ctype() const { return nullptr; }
+ LIBC_INLINE constexpr const LcNumericData *numeric() const { return nullptr; }
+ LIBC_INLINE constexpr const LcTimeData *time() const { return nullptr; }
+ LIBC_INLINE constexpr const LcMonetaryData *monetary() const {
+ return nullptr;
+ }
+ LIBC_INLINE constexpr const LcMessagesData *messages() const {
+ return nullptr;
+ }
};
-// The pointer to the default "C" locale.
+} // namespace LIBC_NAMESPACE_DECL
+
+struct __locale_t
----------------
kaladron wrote:
locale_t is forward-declared as typedef struct __locale_t *locale_t; in the global namespace in llvm-libc-types/locale_t.h. Defining struct __locale_t inside LIBC_NAMESPACE_DECL would create a distinct type and leave ::__locale_t incomplete.
I added a brief comment noting this.
https://github.com/llvm/llvm-project/pull/211470
More information about the libc-commits
mailing list