Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions libcxx/include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -492,8 +492,10 @@ set(files
__locale
__locale_dir/locale_base_api.h
__locale_dir/locale_base_api/android.h
__locale_dir/locale_base_api/apple.h
__locale_dir/locale_base_api/bsd_locale_defaults.h
__locale_dir/locale_base_api/bsd_locale_fallbacks.h
__locale_dir/locale_base_api/freebsd.h
__locale_dir/locale_base_api/fuchsia.h
__locale_dir/locale_base_api/ibm.h
__locale_dir/locale_base_api/locale_guard.h
Expand Down
10 changes: 5 additions & 5 deletions libcxx/include/__locale
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ class _LIBCPP_TEMPLATE_VIS collate_byname;

template <>
class _LIBCPP_EXPORTED_FROM_ABI collate_byname<char> : public collate<char> {
locale_t __l_;
__libcpp_locale_t __l_;

public:
typedef char char_type;
Expand All @@ -266,7 +266,7 @@ protected:
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
template <>
class _LIBCPP_EXPORTED_FROM_ABI collate_byname<wchar_t> : public collate<wchar_t> {
locale_t __l_;
__libcpp_locale_t __l_;

public:
typedef wchar_t char_type;
Expand Down Expand Up @@ -616,7 +616,7 @@ class _LIBCPP_TEMPLATE_VIS ctype_byname;

template <>
class _LIBCPP_EXPORTED_FROM_ABI ctype_byname<char> : public ctype<char> {
locale_t __l_;
__libcpp_locale_t __l_;

public:
explicit ctype_byname(const char*, size_t = 0);
Expand All @@ -633,7 +633,7 @@ protected:
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
template <>
class _LIBCPP_EXPORTED_FROM_ABI ctype_byname<wchar_t> : public ctype<wchar_t> {
locale_t __l_;
__libcpp_locale_t __l_;

public:
explicit ctype_byname(const char*, size_t = 0);
Expand Down Expand Up @@ -824,7 +824,7 @@ protected:
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
template <>
class _LIBCPP_EXPORTED_FROM_ABI codecvt<wchar_t, char, mbstate_t> : public locale::facet, public codecvt_base {
locale_t __l_;
__libcpp_locale_t __l_;

public:
typedef wchar_t intern_type;
Expand Down
105 changes: 54 additions & 51 deletions libcxx/include/__locale_dir/locale_base_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
#ifndef _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_H
#define _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_H

#include <__config>

#if defined(_LIBCPP_MSVCRT_LIKE)
# include <__locale_dir/locale_base_api/win32.h>
#elif defined(_AIX) || defined(__MVS__)
# include <__locale_dir/locale_base_api/ibm.h>
#elif defined(__ANDROID__)
# include <__locale_dir/locale_base_api/android.h>
#elif defined(__sun__)
# include <__locale_dir/locale_base_api/solaris.h>
#elif defined(_NEWLIB_VERSION)
# include <__locale_dir/locale_base_api/newlib.h>
#elif defined(__OpenBSD__)
Expand All @@ -25,74 +25,77 @@
# include <__locale_dir/locale_base_api/fuchsia.h>
#elif defined(__wasi__) || defined(_LIBCPP_HAS_MUSL_LIBC)
# include <__locale_dir/locale_base_api/musl.h>
#elif defined(__APPLE__) || defined(__FreeBSD__)
# include <xlocale.h>
#elif defined(__APPLE__)
# include <__locale_dir/locale_base_api/apple.h>
#elif defined(__FreeBSD__)
# include <__locale_dir/locale_base_api/freebsd.h>
#endif

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif

// clang-format off
/*
The platform-specific headers have to provide the following interface:

// TODO: rename this to __libcpp_locale_t
using locale_t = implementation-defined;
using __libcpp_locale_t = implementation-defined;

implementation-defined __libcpp_mb_cur_max_l(locale_t);
wint_t __libcpp_btowc_l(int, locale_t);
int __libcpp_wctob_l(wint_t, locale_t);
size_t __libcpp_wcsnrtombs_l(char* dest, const wchar_t** src, size_t wide_char_count, size_t len, mbstate_t, locale_t);
size_t __libcpp_wcrtomb_l(char* str, wchar_t wide_char, mbstate_t*, locale_t);
size_t __libcpp_mbsnrtowcs_l(wchar_t* dest, const char** src, size_t max_out, size_t len, mbstate_t*, locale_t);
size_t __libcpp_mbrtowc_l(wchar_t* dest, cosnt char* src, size_t count, mbstate_t*, locale_t);
int __libcpp_mbtowc_l(wchar_t* dest, const char* src, size_t count, locale_t);
size_t __libcpp_mbrlen_l(const char* str, size_t count, mbstate_t*, locale_t);
lconv* __libcpp_localeconv_l(locale_t);
size_t __libcpp_mbsrtowcs_l(wchar_t* dest, const char** src, size_t len, mbstate_t*, locale_t);
int __libcpp_snprintf_l(char* dest, size_t buff_size, locale_t, const char* format, ...);
int __libcpp_asprintf_l(char** dest, locale_t, const char* format, ...);
int __libcpp_sscanf_l(const char* dest, locale_t, const char* format, ...);
implementation-defined __libcpp_mb_cur_max_l(__libcpp_locale_t);
wint_t __libcpp_btowc_l(int, __libcpp_locale_t);
int __libcpp_wctob_l(wint_t, __libcpp_locale_t);
size_t __libcpp_wcsnrtombs_l(char* dest, const wchar_t** src, size_t wide_char_count, size_t len, mbstate_t, __libcpp_locale_t);
size_t __libcpp_wcrtomb_l(char* str, wchar_t wide_char, mbstate_t*, __libcpp_locale_t);
size_t __libcpp_mbsnrtowcs_l(wchar_t* dest, const char** src, size_t max_out, size_t len, mbstate_t*, __libcpp_locale_t);
size_t __libcpp_mbrtowc_l(wchar_t* dest, cosnt char* src, size_t count, mbstate_t*, __libcpp_locale_t);
int __libcpp_mbtowc_l(wchar_t* dest, const char* src, size_t count, __libcpp_locale_t);
size_t __libcpp_mbrlen_l(const char* str, size_t count, mbstate_t*, __libcpp_locale_t);
lconv* __libcpp_localeconv_l(__libcpp_locale_t);
size_t __libcpp_mbsrtowcs_l(wchar_t* dest, const char** src, size_t len, mbstate_t*, __libcpp_locale_t);
int __libcpp_snprintf_l(char* dest, size_t buff_size, __libcpp_locale_t, const char* format, ...);
int __libcpp_asprintf_l(char** dest, __libcpp_locale_t, const char* format, ...);
int __libcpp_sscanf_l(const char* dest, __libcpp_locale_t, const char* format, ...);

// TODO: change these to reserved names
float strtof_l(const char* str, char** str_end, locale_t);
double strtod_l(const char* str, char** str_end, locale_t);
long double strtold_l(const char* str, char** str_end, locale_t);
long long strtoll_l(const char* str, char** str_end, locale_t);
unsigned long long strtoull_l(const char* str, char** str_end, locale_t);
float strtof_l(const char* str, char** str_end, __libcpp_locale_t);
double strtod_l(const char* str, char** str_end, __libcpp_locale_t);
long double strtold_l(const char* str, char** str_end, __libcpp_locale_t);
long long strtoll_l(const char* str, char** str_end, __libcpp_locale_t);
unsigned long long strtoull_l(const char* str, char** str_end, __libcpp_locale_t);

locale_t newlocale(int category_mask, const char* locale, locale_t base);
void freelocale(locale_t);
__libcpp_locale_t newlocale(int category_mask, const char* locale, __libcpp_locale_t base);
void freelocale(__libcpp_locale_t);

int islower_l(int ch, locale_t);
int isupper_l(int ch, locale_t);
int isdigit_l(int ch, locale_t);
int isxdigit_l(int ch, locale_t);
int strcoll_l(const char* lhs, const char* rhs, locale_t);
size_t strxfrm_l(char* dst, const char* src, size_t n, locale_t);
int wcscoll_l(const char* lhs, const char* rhs, locale_t);
size_t wcsxfrm_l(wchar_t* dst, const wchar_t* src, size_t n, locale_t);
int toupper_l(int ch, locale_t);
int tolower_l(int ch, locale_t);
int iswspace_l(wint_t ch, locale_t);
int iswprint_l(wint_t ch, locale_t);
int iswcntrl_l(wint_t ch, locale_t);
int iswupper_l(wint_t ch, locale_t);
int iswlower_l(wint_t ch, locale_t);
int iswalpha_l(wint_t ch, locale_t);
int iswblank_l(wint_t ch, locale_t);
int iswdigit_l(wint_t ch, locale_t);
int iswpunct_l(wint_t ch, locale_t);
int iswxdigit_l(wint_t ch, locale_t);
wint_t towupper_l(wint_t ch, locale_t);
wint_t towlower_l(wint_t ch, locale_t);
size_t strftime_l(char* str, size_t len, const char* format, const tm*, locale_t);
int islower_l(int ch, __libcpp_locale_t);
int isupper_l(int ch, __libcpp_locale_t);
int isdigit_l(int ch, __libcpp_locale_t);
int isxdigit_l(int ch, __libcpp_locale_t);
int strcoll_l(const char* lhs, const char* rhs, __libcpp_locale_t);
size_t strxfrm_l(char* dst, const char* src, size_t n, __libcpp_locale_t);
int wcscoll_l(const char* lhs, const char* rhs, __libcpp_locale_t);
size_t wcsxfrm_l(wchar_t* dst, const wchar_t* src, size_t n, __libcpp_locale_t);
int toupper_l(int ch, __libcpp_locale_t);
int tolower_l(int ch, __libcpp_locale_t);
int iswspace_l(wint_t ch, __libcpp_locale_t);
int iswprint_l(wint_t ch, __libcpp_locale_t);
int iswcntrl_l(wint_t ch, __libcpp_locale_t);
int iswupper_l(wint_t ch, __libcpp_locale_t);
int iswlower_l(wint_t ch, __libcpp_locale_t);
int iswalpha_l(wint_t ch, __libcpp_locale_t);
int iswblank_l(wint_t ch, __libcpp_locale_t);
int iswdigit_l(wint_t ch, __libcpp_locale_t);
int iswpunct_l(wint_t ch, __libcpp_locale_t);
int iswxdigit_l(wint_t ch, __libcpp_locale_t);
wint_t towupper_l(wint_t ch, __libcpp_locale_t);
wint_t towlower_l(wint_t ch, __libcpp_locale_t);
size_t strftime_l(char* str, size_t len, const char* format, const tm*, __libcpp_locale_t);


These functions are equivalent to their C counterparts,
except that locale_t is used instead of the current global locale.
except that __libcpp_locale_t is used instead of the current global locale.

The variadic functions may be implemented as templates with a parameter pack instead of variadic functions.
*/
// clang-format on

#endif // _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_H
6 changes: 4 additions & 2 deletions libcxx/include/__locale_dir/locale_base_api/android.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ extern "C" {
# include <__support/xlocale/__strtonum_fallback.h>
# elif __ANDROID_API__ < 26

inline _LIBCPP_HIDE_FROM_ABI float strtof_l(const char* __nptr, char** __endptr, locale_t) {
inline _LIBCPP_HIDE_FROM_ABI float strtof_l(const char* __nptr, char** __endptr, __libcpp_locale_t) {
return ::strtof(__nptr, __endptr);
}

inline _LIBCPP_HIDE_FROM_ABI double strtod_l(const char* __nptr, char** __endptr, locale_t) {
inline _LIBCPP_HIDE_FROM_ABI double strtod_l(const char* __nptr, char** __endptr, __libcpp_locale_t) {
return ::strtod(__nptr, __endptr);
}

Expand All @@ -47,4 +47,6 @@ inline _LIBCPP_HIDE_FROM_ABI double strtod_l(const char* __nptr, char** __endptr
# endif // __NDK_MAJOR__ <= 16
#endif // __has_include(<android/ndk-version.h>)

using __libcpp_locale_t = ::locale_t;

#endif // _LIBCPP___LOCALE_LOCALE_BASE_API_ANDROID_H
17 changes: 17 additions & 0 deletions libcxx/include/__locale_dir/locale_base_api/apple.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// -*- 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
//
//===----------------------------------------------------------------------===//

#ifndef _LIBCPP___LOCALE_LOCALE_BASE_API_APPLE_H
#define _LIBCPP___LOCALE_LOCALE_BASE_API_APPLE_H

#include <xlocale.h>

using __libcpp_locale_t = locale_t;

#endif // _LIBCPP___LOCALE_LOCALE_BASE_API_APPLE_H
Original file line number Diff line number Diff line change
Expand Up @@ -28,71 +28,74 @@

_LIBCPP_BEGIN_NAMESPACE_STD

inline _LIBCPP_HIDE_FROM_ABI decltype(MB_CUR_MAX) __libcpp_mb_cur_max_l(locale_t __l) {
inline _LIBCPP_HIDE_FROM_ABI decltype(MB_CUR_MAX) __libcpp_mb_cur_max_l(__libcpp_locale_t __l) {
__libcpp_locale_guard __current(__l);
return MB_CUR_MAX;
}

#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
inline _LIBCPP_HIDE_FROM_ABI wint_t __libcpp_btowc_l(int __c, locale_t __l) {
inline _LIBCPP_HIDE_FROM_ABI wint_t __libcpp_btowc_l(int __c, __libcpp_locale_t __l) {
__libcpp_locale_guard __current(__l);
return btowc(__c);
}

inline _LIBCPP_HIDE_FROM_ABI int __libcpp_wctob_l(wint_t __c, locale_t __l) {
inline _LIBCPP_HIDE_FROM_ABI int __libcpp_wctob_l(wint_t __c, __libcpp_locale_t __l) {
__libcpp_locale_guard __current(__l);
return wctob(__c);
}

inline _LIBCPP_HIDE_FROM_ABI size_t
__libcpp_wcsnrtombs_l(char* __dest, const wchar_t** __src, size_t __nwc, size_t __len, mbstate_t* __ps, locale_t __l) {
inline _LIBCPP_HIDE_FROM_ABI size_t __libcpp_wcsnrtombs_l(
char* __dest, const wchar_t** __src, size_t __nwc, size_t __len, mbstate_t* __ps, __libcpp_locale_t __l) {
__libcpp_locale_guard __current(__l);
return wcsnrtombs(__dest, __src, __nwc, __len, __ps);
}

inline _LIBCPP_HIDE_FROM_ABI size_t __libcpp_wcrtomb_l(char* __s, wchar_t __wc, mbstate_t* __ps, locale_t __l) {
inline _LIBCPP_HIDE_FROM_ABI size_t
__libcpp_wcrtomb_l(char* __s, wchar_t __wc, mbstate_t* __ps, __libcpp_locale_t __l) {
__libcpp_locale_guard __current(__l);
return wcrtomb(__s, __wc, __ps);
}

inline _LIBCPP_HIDE_FROM_ABI size_t
__libcpp_mbsnrtowcs_l(wchar_t* __dest, const char** __src, size_t __nms, size_t __len, mbstate_t* __ps, locale_t __l) {
inline _LIBCPP_HIDE_FROM_ABI size_t __libcpp_mbsnrtowcs_l(
wchar_t* __dest, const char** __src, size_t __nms, size_t __len, mbstate_t* __ps, __libcpp_locale_t __l) {
__libcpp_locale_guard __current(__l);
return mbsnrtowcs(__dest, __src, __nms, __len, __ps);
}

inline _LIBCPP_HIDE_FROM_ABI size_t
__libcpp_mbrtowc_l(wchar_t* __pwc, const char* __s, size_t __n, mbstate_t* __ps, locale_t __l) {
__libcpp_mbrtowc_l(wchar_t* __pwc, const char* __s, size_t __n, mbstate_t* __ps, __libcpp_locale_t __l) {
__libcpp_locale_guard __current(__l);
return mbrtowc(__pwc, __s, __n, __ps);
}

inline _LIBCPP_HIDE_FROM_ABI int __libcpp_mbtowc_l(wchar_t* __pwc, const char* __pmb, size_t __max, locale_t __l) {
inline _LIBCPP_HIDE_FROM_ABI int
__libcpp_mbtowc_l(wchar_t* __pwc, const char* __pmb, size_t __max, __libcpp_locale_t __l) {
__libcpp_locale_guard __current(__l);
return mbtowc(__pwc, __pmb, __max);
}

inline _LIBCPP_HIDE_FROM_ABI size_t __libcpp_mbrlen_l(const char* __s, size_t __n, mbstate_t* __ps, locale_t __l) {
inline _LIBCPP_HIDE_FROM_ABI size_t
__libcpp_mbrlen_l(const char* __s, size_t __n, mbstate_t* __ps, __libcpp_locale_t __l) {
__libcpp_locale_guard __current(__l);
return mbrlen(__s, __n, __ps);
}
#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS

inline _LIBCPP_HIDE_FROM_ABI lconv* __libcpp_localeconv_l(locale_t __l) {
inline _LIBCPP_HIDE_FROM_ABI lconv* __libcpp_localeconv_l(__libcpp_locale_t __l) {
__libcpp_locale_guard __current(__l);
return localeconv();
}

#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
inline _LIBCPP_HIDE_FROM_ABI size_t
__libcpp_mbsrtowcs_l(wchar_t* __dest, const char** __src, size_t __len, mbstate_t* __ps, locale_t __l) {
__libcpp_mbsrtowcs_l(wchar_t* __dest, const char** __src, size_t __len, mbstate_t* __ps, __libcpp_locale_t __l) {
__libcpp_locale_guard __current(__l);
return mbsrtowcs(__dest, __src, __len, __ps);
}
#endif

inline _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 4, 5) int __libcpp_snprintf_l(
char* __s, size_t __n, locale_t __l, const char* __format, ...) {
char* __s, size_t __n, __libcpp_locale_t __l, const char* __format, ...) {
va_list __va;
va_start(__va, __format);
__libcpp_locale_guard __current(__l);
Expand All @@ -102,7 +105,7 @@ inline _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 4, 5) int __libcpp_snprintf_l(
}

inline _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 3, 4) int __libcpp_asprintf_l(
char** __s, locale_t __l, const char* __format, ...) {
char** __s, __libcpp_locale_t __l, const char* __format, ...) {
va_list __va;
va_start(__va, __format);
__libcpp_locale_guard __current(__l);
Expand All @@ -112,7 +115,7 @@ inline _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 3, 4) int __libcpp_asprintf_l(
}

inline _LIBCPP_ATTRIBUTE_FORMAT(__scanf__, 3, 4) int __libcpp_sscanf_l(
const char* __s, locale_t __l, const char* __format, ...) {
const char* __s, __libcpp_locale_t __l, const char* __format, ...) {
va_list __va;
va_start(__va, __format);
__libcpp_locale_guard __current(__l);
Expand Down
17 changes: 17 additions & 0 deletions libcxx/include/__locale_dir/locale_base_api/freebsd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// -*- 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
//
//===----------------------------------------------------------------------===//

#ifndef _LIBCPP___LOCALE_LOCALE_BASE_API_FREEBSD_H
#define _LIBCPP___LOCALE_LOCALE_BASE_API_FREEBSD_H

#include <xlocale.h>

using __libcpp_locale_t = locale_t;

#endif // _LIBCPP___LOCALE_LOCALE_BASE_API_FREEBSD_H
2 changes: 2 additions & 0 deletions libcxx/include/__locale_dir/locale_base_api/fuchsia.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@
#include <cstdlib>
#include <cwchar>

using __libcpp_locale_t = locale_t;

#endif // _LIBCPP___LOCALE_LOCALE_BASE_API_FUCHSIA_H
Loading
Loading