Upgrade to 2022-era LLVM LIBCXX

This commit is contained in:
Justine Tunney 2024-05-27 02:12:27 -07:00
parent 2f4ca71f26
commit 8e68384e15
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
2078 changed files with 165657 additions and 65010 deletions

View file

@ -0,0 +1,72 @@
// -*- 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___SUPPORT_ANDROID_LOCALE_BIONIC_H
#define _LIBCPP___SUPPORT_ANDROID_LOCALE_BIONIC_H
#if defined(__BIONIC__)
#ifdef __cplusplus
extern "C" {
#endif
#include <stdlib.h>
#include <xlocale.h>
#ifdef __cplusplus
}
#endif
#if defined(__ANDROID__)
#include <android/api-level.h>
#if __ANDROID_API__ < 21
#include <__support/xlocale/__posix_l_fallback.h>
#endif
// If we do not have this header, we are in a platform build rather than an NDK
// build, which will always be at least as new as the ToT NDK, in which case we
// don't need any of the inlines below since libc provides them.
#if __has_include(<android/ndk-version.h>)
#include <android/ndk-version.h>
// In NDK versions later than 16, locale-aware functions are provided by
// legacy_stdlib_inlines.h
#if __NDK_MAJOR__ <= 16
#if __ANDROID_API__ < 21
#include <__support/xlocale/__strtonum_fallback.h>
#elif __ANDROID_API__ < 26
#if defined(__cplusplus)
extern "C" {
#endif
inline _LIBCPP_HIDE_FROM_ABI_C float strtof_l(const char* __nptr, char** __endptr, locale_t) {
return ::strtof(__nptr, __endptr);
}
inline _LIBCPP_HIDE_FROM_ABI_C double strtod_l(const char* __nptr, char** __endptr, locale_t) {
return ::strtod(__nptr, __endptr);
}
inline _LIBCPP_HIDE_FROM_ABI_C long strtol_l(const char* __nptr, char** __endptr, int __base, locale_t) {
return ::strtol(__nptr, __endptr, __base);
}
#if defined(__cplusplus)
}
#endif
#endif // __ANDROID_API__ < 26
#endif // __NDK_MAJOR__ <= 16
#endif // __has_include(<android/ndk-version.h>)
#endif // defined(__ANDROID__)
#endif // defined(__BIONIC__)
#endif // _LIBCPP___SUPPORT_ANDROID_LOCALE_BIONIC_H

View file

@ -0,0 +1,22 @@
// -*- 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___SUPPORT_FUCHSIA_XLOCALE_H
#define _LIBCPP___SUPPORT_FUCHSIA_XLOCALE_H
#if defined(__Fuchsia__)
#include <cstdlib>
#include <cwchar>
#include <__support/xlocale/__posix_l_fallback.h>
#include <__support/xlocale/__strtonum_fallback.h>
#endif // defined(__Fuchsia__)
#endif // _LIBCPP___SUPPORT_FUCHSIA_XLOCALE_H

View file

@ -0,0 +1,54 @@
// -*- 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___SUPPORT_IBM_GETTOD_ZOS_H
#define _LIBCPP___SUPPORT_IBM_GETTOD_ZOS_H
#include <time.h>
inline _LIBCPP_HIDE_FROM_ABI int
gettimeofdayMonotonic(struct timespec64* Output) {
// The POSIX gettimeofday() function is not available on z/OS. Therefore,
// we will call stcke and other hardware instructions in implement equivalent.
// Note that nanoseconds alone will overflow when reaching new epoch in 2042.
struct _t {
uint64_t Hi;
uint64_t Lo;
};
struct _t Value = {0, 0};
uint64_t CC = 0;
asm(" stcke %0\n"
" ipm %1\n"
" srlg %1,%1,28\n"
: "=m"(Value), "+r"(CC)::);
if (CC != 0) {
errno = EMVSTODNOTSET;
return CC;
}
uint64_t us = (Value.Hi >> 4);
uint64_t ns = ((Value.Hi & 0x0F) << 8) + (Value.Lo >> 56);
ns = (ns * 1000) >> 12;
us = us - 2208988800000000;
register uint64_t DivPair0 asm("r0"); // dividend (upper half), remainder
DivPair0 = 0;
register uint64_t DivPair1 asm("r1"); // dividend (lower half), quotient
DivPair1 = us;
uint64_t Divisor = 1000000;
asm(" dlgr %0,%2" : "+r"(DivPair0), "+r"(DivPair1) : "r"(Divisor) :);
Output->tv_sec = DivPair1;
Output->tv_nsec = DivPair0 * 1000 + ns;
return 0;
}
#endif // _LIBCPP___SUPPORT_IBM_GETTOD_ZOS_H

View file

@ -0,0 +1,53 @@
// -*- 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___SUPPORT_IBM_LOCALE_MGMT_ZOS_H
#define _LIBCPP___SUPPORT_IBM_LOCALE_MGMT_ZOS_H
#if defined(__MVS__)
#include <locale.h>
#include <string>
#ifdef __cplusplus
extern "C" {
#endif
#define _LC_MAX LC_MESSAGES /* highest real category */
#define _NCAT (_LC_MAX + 1) /* maximum + 1 */
#define _CATMASK(n) (1 << (n))
#define LC_COLLATE_MASK _CATMASK(LC_COLLATE)
#define LC_CTYPE_MASK _CATMASK(LC_CTYPE)
#define LC_MONETARY_MASK _CATMASK(LC_MONETARY)
#define LC_NUMERIC_MASK _CATMASK(LC_NUMERIC)
#define LC_TIME_MASK _CATMASK(LC_TIME)
#define LC_MESSAGES_MASK _CATMASK(LC_MESSAGES)
#define LC_ALL_MASK (_CATMASK(_NCAT) - 1)
typedef struct locale_struct {
int category_mask;
std::string lc_collate;
std::string lc_ctype;
std::string lc_monetary;
std::string lc_numeric;
std::string lc_time;
std::string lc_messages;
} * locale_t;
// z/OS does not have newlocale, freelocale and uselocale.
// The functions below are workarounds in single thread mode.
locale_t newlocale(int category_mask, const char* locale, locale_t base);
void freelocale(locale_t locobj);
locale_t uselocale(locale_t newloc);
#ifdef __cplusplus
}
#endif
#endif // defined(__MVS__)
#endif // _LIBCPP___SUPPORT_IBM_LOCALE_MGMT_ZOS_H

View file

@ -0,0 +1,55 @@
// -*- 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___SUPPORT_IBM_NANOSLEEP_H
#define _LIBCPP___SUPPORT_IBM_NANOSLEEP_H
#include <unistd.h>
inline int nanosleep(const struct timespec* __req, struct timespec* __rem) {
// The nanosleep() function is not available on z/OS. Therefore, we will call
// sleep() to sleep for whole seconds and usleep() to sleep for any remaining
// fraction of a second. Any remaining nanoseconds will round up to the next
// microsecond.
if (__req->tv_sec < 0 || __req->tv_nsec < 0 || __req->tv_nsec > 999999999) {
errno = EINVAL;
return -1;
}
long __micro_sec = (__req->tv_nsec + 999) / 1000;
time_t __sec = __req->tv_sec;
if (__micro_sec > 999999) {
++__sec;
__micro_sec -= 1000000;
}
__sec = static_cast<time_t>(sleep(static_cast<unsigned int>(__sec)));
if (__sec) {
if (__rem) {
// Updating the remaining time to sleep in case of unsuccessful call to sleep().
__rem->tv_sec = __sec;
__rem->tv_nsec = __micro_sec * 1000;
}
errno = EINTR;
return -1;
}
if (__micro_sec) {
int __rt = usleep(static_cast<unsigned int>(__micro_sec));
if (__rt != 0 && __rem) {
// The usleep() does not provide the amount of remaining time upon its failure,
// so the time slept will be ignored.
__rem->tv_sec = 0;
__rem->tv_nsec = __micro_sec * 1000;
// The errno is already set.
return -1;
}
return __rt;
}
return 0;
}
#endif // _LIBCPP___SUPPORT_IBM_NANOSLEEP_H

View file

@ -0,0 +1,129 @@
// -*- 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___SUPPORT_IBM_XLOCALE_H
#define _LIBCPP___SUPPORT_IBM_XLOCALE_H
#if defined(__MVS__)
#include <__support/ibm/locale_mgmt_zos.h>
#endif // defined(__MVS__)
#include <stdarg.h>
#include "cstdlib"
#ifdef __cplusplus
extern "C" {
#endif
#if defined(__MVS__)
#include <wctype.h>
// POSIX routines
#include <__support/xlocale/__posix_l_fallback.h>
#endif // defined(__MVS__)
namespace {
struct __setAndRestore {
explicit __setAndRestore(locale_t locale) {
if (locale == (locale_t)0) {
__cloc = newlocale(LC_ALL_MASK, "C", /* base */ (locale_t)0);
__stored = uselocale(__cloc);
} else {
__stored = uselocale(locale);
}
}
~__setAndRestore() {
uselocale(__stored);
if (__cloc)
freelocale(__cloc);
}
private:
locale_t __stored = (locale_t)0;
locale_t __cloc = (locale_t)0;
};
} // namespace
// The following are not POSIX routines. These are quick-and-dirty hacks
// to make things pretend to work
inline _LIBCPP_HIDE_FROM_ABI long long
strtoll_l(const char *__nptr, char **__endptr, int __base, locale_t locale) {
__setAndRestore __newloc(locale);
return ::strtoll(__nptr, __endptr, __base);
}
inline _LIBCPP_HIDE_FROM_ABI long
strtol_l(const char *__nptr, char **__endptr, int __base, locale_t locale) {
__setAndRestore __newloc(locale);
return ::strtol(__nptr, __endptr, __base);
}
inline _LIBCPP_HIDE_FROM_ABI double
strtod_l(const char *__nptr, char **__endptr, locale_t locale) {
__setAndRestore __newloc(locale);
return ::strtod(__nptr, __endptr);
}
inline _LIBCPP_HIDE_FROM_ABI float
strtof_l(const char *__nptr, char **__endptr, locale_t locale) {
__setAndRestore __newloc(locale);
return ::strtof(__nptr, __endptr);
}
inline _LIBCPP_HIDE_FROM_ABI long double
strtold_l(const char *__nptr, char **__endptr, locale_t locale) {
__setAndRestore __newloc(locale);
return ::strtold(__nptr, __endptr);
}
inline _LIBCPP_HIDE_FROM_ABI unsigned long long
strtoull_l(const char *__nptr, char **__endptr, int __base, locale_t locale) {
__setAndRestore __newloc(locale);
return ::strtoull(__nptr, __endptr, __base);
}
inline _LIBCPP_HIDE_FROM_ABI unsigned long
strtoul_l(const char *__nptr, char **__endptr, int __base, locale_t locale) {
__setAndRestore __newloc(locale);
return ::strtoul(__nptr, __endptr, __base);
}
inline _LIBCPP_HIDE_FROM_ABI int
vasprintf(char **strp, const char *fmt, va_list ap) {
const size_t buff_size = 256;
if ((*strp = (char *)malloc(buff_size)) == NULL) {
return -1;
}
va_list ap_copy;
// va_copy may not be provided by the C library in C++ 03 mode.
#if defined(_LIBCPP_CXX03_LANG) && __has_builtin(__builtin_va_copy)
__builtin_va_copy(ap_copy, ap);
#else
va_copy(ap_copy, ap);
#endif
int str_size = vsnprintf(*strp, buff_size, fmt, ap_copy);
va_end(ap_copy);
if ((size_t) str_size >= buff_size) {
if ((*strp = (char *)realloc(*strp, str_size + 1)) == NULL) {
return -1;
}
str_size = vsnprintf(*strp, str_size + 1, fmt, ap);
}
return str_size;
}
#ifdef __cplusplus
}
#endif
#endif // _LIBCPP___SUPPORT_IBM_XLOCALE_H

View file

@ -0,0 +1,52 @@
// -*- 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
//
//===----------------------------------------------------------------------===//
// This adds support for the extended locale functions that are currently
// missing from the Musl C library.
//
// This only works when the specified locale is "C" or "POSIX", but that's
// about as good as we can do without implementing full xlocale support
// in Musl.
//===----------------------------------------------------------------------===//
#ifndef _LIBCPP___SUPPORT_MUSL_XLOCALE_H
#define _LIBCPP___SUPPORT_MUSL_XLOCALE_H
#include <cstdlib>
#include <cwchar>
#ifdef __cplusplus
extern "C" {
#endif
inline _LIBCPP_HIDE_FROM_ABI_C long long strtoll_l(const char* __nptr, char** __endptr, int __base, locale_t) {
return ::strtoll(__nptr, __endptr, __base);
}
inline _LIBCPP_HIDE_FROM_ABI_C unsigned long long
strtoull_l(const char* __nptr, char** __endptr, int __base, locale_t) {
return ::strtoull(__nptr, __endptr, __base);
}
inline _LIBCPP_HIDE_FROM_ABI_C long long wcstoll_l(const wchar_t* __nptr, wchar_t** __endptr, int __base, locale_t) {
return ::wcstoll(__nptr, __endptr, __base);
}
inline _LIBCPP_HIDE_FROM_ABI_C long long wcstoull_l(const wchar_t* __nptr, wchar_t** __endptr, int __base, locale_t) {
return ::wcstoull(__nptr, __endptr, __base);
}
inline _LIBCPP_HIDE_FROM_ABI_C long double wcstold_l(const wchar_t* __nptr, wchar_t** __endptr, locale_t) {
return ::wcstold(__nptr, __endptr);
}
#ifdef __cplusplus
}
#endif
#endif // _LIBCPP___SUPPORT_MUSL_XLOCALE_H

View file

@ -0,0 +1,23 @@
//===----------------------------------------------------------------------===//
//
// 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___SUPPORT_NEWLIB_XLOCALE_H
#define _LIBCPP___SUPPORT_NEWLIB_XLOCALE_H
#if defined(_NEWLIB_VERSION)
#if !defined(__NEWLIB__) || __NEWLIB__ < 2 || \
__NEWLIB__ == 2 && __NEWLIB_MINOR__ < 5
#include <__support/xlocale/__nop_locale_mgmt.h>
#include <__support/xlocale/__posix_l_fallback.h>
#include <__support/xlocale/__strtonum_fallback.h>
#endif
#endif // _NEWLIB_VERSION
#endif

View file

@ -0,0 +1,35 @@
// -*- 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___SUPPORT_OPENBSD_XLOCALE_H
#define _LIBCPP___SUPPORT_OPENBSD_XLOCALE_H
#include <__support/xlocale/__strtonum_fallback.h>
#include <clocale>
#include <cstdlib>
#include <ctype.h>
#include <cwctype>
#ifdef __cplusplus
extern "C" {
#endif
inline _LIBCPP_HIDE_FROM_ABI_C long strtol_l(const char* __nptr, char** __endptr, int __base, locale_t) {
return ::strtol(__nptr, __endptr, __base);
}
inline _LIBCPP_HIDE_FROM_ABI_C unsigned long strtoul_l(const char* __nptr, char** __endptr, int __base, locale_t) {
return ::strtoul(__nptr, __endptr, __base);
}
#ifdef __cplusplus
}
#endif
#endif

View file

@ -0,0 +1,282 @@
// -*- 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___SUPPORT_WIN32_LOCALE_WIN32_H
#define _LIBCPP___SUPPORT_WIN32_LOCALE_WIN32_H
#include <__config>
#include <cstddef>
#include <locale.h> // _locale_t
#include <stdio.h>
#include <string>
#define _X_ALL LC_ALL
#define _X_COLLATE LC_COLLATE
#define _X_CTYPE LC_CTYPE
#define _X_MONETARY LC_MONETARY
#define _X_NUMERIC LC_NUMERIC
#define _X_TIME LC_TIME
#define _X_MAX LC_MAX
#define _X_MESSAGES 6
#define _NCAT (_X_MESSAGES + 1)
#define _CATMASK(n) ((1 << (n)) >> 1)
#define _M_COLLATE _CATMASK(_X_COLLATE)
#define _M_CTYPE _CATMASK(_X_CTYPE)
#define _M_MONETARY _CATMASK(_X_MONETARY)
#define _M_NUMERIC _CATMASK(_X_NUMERIC)
#define _M_TIME _CATMASK(_X_TIME)
#define _M_MESSAGES _CATMASK(_X_MESSAGES)
#define _M_ALL (_CATMASK(_NCAT) - 1)
#define LC_COLLATE_MASK _M_COLLATE
#define LC_CTYPE_MASK _M_CTYPE
#define LC_MONETARY_MASK _M_MONETARY
#define LC_NUMERIC_MASK _M_NUMERIC
#define LC_TIME_MASK _M_TIME
#define LC_MESSAGES_MASK _M_MESSAGES
#define LC_ALL_MASK ( LC_COLLATE_MASK \
| LC_CTYPE_MASK \
| LC_MESSAGES_MASK \
| LC_MONETARY_MASK \
| LC_NUMERIC_MASK \
| LC_TIME_MASK )
class __lconv_storage {
public:
__lconv_storage(const lconv *__lc_input) {
__lc_ = *__lc_input;
__decimal_point_ = __lc_input->decimal_point;
__thousands_sep_ = __lc_input->thousands_sep;
__grouping_ = __lc_input->grouping;
__int_curr_symbol_ = __lc_input->int_curr_symbol;
__currency_symbol_ = __lc_input->currency_symbol;
__mon_decimal_point_ = __lc_input->mon_decimal_point;
__mon_thousands_sep_ = __lc_input->mon_thousands_sep;
__mon_grouping_ = __lc_input->mon_grouping;
__positive_sign_ = __lc_input->positive_sign;
__negative_sign_ = __lc_input->negative_sign;
__lc_.decimal_point = const_cast<char *>(__decimal_point_.c_str());
__lc_.thousands_sep = const_cast<char *>(__thousands_sep_.c_str());
__lc_.grouping = const_cast<char *>(__grouping_.c_str());
__lc_.int_curr_symbol = const_cast<char *>(__int_curr_symbol_.c_str());
__lc_.currency_symbol = const_cast<char *>(__currency_symbol_.c_str());
__lc_.mon_decimal_point = const_cast<char *>(__mon_decimal_point_.c_str());
__lc_.mon_thousands_sep = const_cast<char *>(__mon_thousands_sep_.c_str());
__lc_.mon_grouping = const_cast<char *>(__mon_grouping_.c_str());
__lc_.positive_sign = const_cast<char *>(__positive_sign_.c_str());
__lc_.negative_sign = const_cast<char *>(__negative_sign_.c_str());
}
lconv *__get() {
return &__lc_;
}
private:
lconv __lc_;
std::string __decimal_point_;
std::string __thousands_sep_;
std::string __grouping_;
std::string __int_curr_symbol_;
std::string __currency_symbol_;
std::string __mon_decimal_point_;
std::string __mon_thousands_sep_;
std::string __mon_grouping_;
std::string __positive_sign_;
std::string __negative_sign_;
};
class locale_t {
public:
locale_t()
: __locale_(nullptr), __locale_str_(nullptr), __lc_(nullptr) {}
locale_t(std::nullptr_t)
: __locale_(nullptr), __locale_str_(nullptr), __lc_(nullptr) {}
locale_t(_locale_t __xlocale, const char* __xlocale_str)
: __locale_(__xlocale), __locale_str_(__xlocale_str), __lc_(nullptr) {}
locale_t(const locale_t &__l)
: __locale_(__l.__locale_), __locale_str_(__l.__locale_str_), __lc_(nullptr) {}
~locale_t() {
delete __lc_;
}
locale_t &operator =(const locale_t &__l) {
__locale_ = __l.__locale_;
__locale_str_ = __l.__locale_str_;
// __lc_ not copied
return *this;
}
friend bool operator==(const locale_t& __left, const locale_t& __right) {
return __left.__locale_ == __right.__locale_;
}
friend bool operator==(const locale_t& __left, int __right) {
return __left.__locale_ == nullptr && __right == 0;
}
friend bool operator==(const locale_t& __left, long long __right) {
return __left.__locale_ == nullptr && __right == 0;
}
friend bool operator==(const locale_t& __left, std::nullptr_t) {
return __left.__locale_ == nullptr;
}
friend bool operator==(int __left, const locale_t& __right) {
return __left == 0 && nullptr == __right.__locale_;
}
friend bool operator==(std::nullptr_t, const locale_t& __right) {
return nullptr == __right.__locale_;
}
friend bool operator!=(const locale_t& __left, const locale_t& __right) {
return !(__left == __right);
}
friend bool operator!=(const locale_t& __left, int __right) {
return !(__left == __right);
}
friend bool operator!=(const locale_t& __left, long long __right) {
return !(__left == __right);
}
friend bool operator!=(const locale_t& __left, std::nullptr_t __right) {
return !(__left == __right);
}
friend bool operator!=(int __left, const locale_t& __right) {
return !(__left == __right);
}
friend bool operator!=(std::nullptr_t __left, const locale_t& __right) {
return !(__left == __right);
}
operator bool() const {
return __locale_ != nullptr;
}
const char* __get_locale() const { return __locale_str_; }
operator _locale_t() const {
return __locale_;
}
lconv *__store_lconv(const lconv *__input_lc) {
delete __lc_;
__lc_ = new __lconv_storage(__input_lc);
return __lc_->__get();
}
private:
_locale_t __locale_;
const char* __locale_str_;
__lconv_storage *__lc_ = nullptr;
};
// Locale management functions
#define freelocale _free_locale
// FIXME: base currently unused. Needs manual work to construct the new locale
locale_t newlocale( int __mask, const char * __locale, locale_t __base );
// uselocale can't be implemented on Windows because Windows allows partial modification
// of thread-local locale and so _get_current_locale() returns a copy while uselocale does
// not create any copies.
// We can still implement raii even without uselocale though.
lconv *localeconv_l( locale_t & __loc );
size_t mbrlen_l( const char *__restrict __s, size_t __n,
mbstate_t *__restrict __ps, locale_t __loc);
size_t mbsrtowcs_l( wchar_t *__restrict __dst, const char **__restrict __src,
size_t __len, mbstate_t *__restrict __ps, locale_t __loc );
size_t wcrtomb_l( char *__restrict __s, wchar_t __wc, mbstate_t *__restrict __ps,
locale_t __loc);
size_t mbrtowc_l( wchar_t *__restrict __pwc, const char *__restrict __s,
size_t __n, mbstate_t *__restrict __ps, locale_t __loc);
size_t mbsnrtowcs_l( wchar_t *__restrict __dst, const char **__restrict __src,
size_t __nms, size_t __len, mbstate_t *__restrict __ps, locale_t __loc);
size_t wcsnrtombs_l( char *__restrict __dst, const wchar_t **__restrict __src,
size_t __nwc, size_t __len, mbstate_t *__restrict __ps, locale_t __loc);
wint_t btowc_l( int __c, locale_t __loc );
int wctob_l( wint_t __c, locale_t __loc );
decltype(MB_CUR_MAX) MB_CUR_MAX_L( locale_t __l );
// the *_l functions are prefixed on Windows, only available for msvcr80+, VS2005+
#define mbtowc_l _mbtowc_l
#define strtoll_l _strtoi64_l
#define strtoull_l _strtoui64_l
#define strtod_l _strtod_l
#if defined(_LIBCPP_MSVCRT)
#define strtof_l _strtof_l
#define strtold_l _strtold_l
#else
_LIBCPP_FUNC_VIS float strtof_l(const char*, char**, locale_t);
_LIBCPP_FUNC_VIS long double strtold_l(const char*, char**, locale_t);
#endif
inline _LIBCPP_HIDE_FROM_ABI int
islower_l(int __c, _locale_t __loc)
{
return _islower_l((int)__c, __loc);
}
inline _LIBCPP_HIDE_FROM_ABI int
isupper_l(int __c, _locale_t __loc)
{
return _isupper_l((int)__c, __loc);
}
#define isdigit_l _isdigit_l
#define isxdigit_l _isxdigit_l
#define strcoll_l _strcoll_l
#define strxfrm_l _strxfrm_l
#define wcscoll_l _wcscoll_l
#define wcsxfrm_l _wcsxfrm_l
#define toupper_l _toupper_l
#define tolower_l _tolower_l
#define iswspace_l _iswspace_l
#define iswprint_l _iswprint_l
#define iswcntrl_l _iswcntrl_l
#define iswupper_l _iswupper_l
#define iswlower_l _iswlower_l
#define iswalpha_l _iswalpha_l
#define iswdigit_l _iswdigit_l
#define iswpunct_l _iswpunct_l
#define iswxdigit_l _iswxdigit_l
#define towupper_l _towupper_l
#define towlower_l _towlower_l
#if defined(__MINGW32__) && __MSVCRT_VERSION__ < 0x0800
_LIBCPP_FUNC_VIS size_t strftime_l(char *ret, size_t n, const char *format,
const struct tm *tm, locale_t loc);
#else
#define strftime_l _strftime_l
#endif
#define sscanf_l( __s, __l, __f, ...) _sscanf_l( __s, __f, __l, __VA_ARGS__ )
#define sprintf_l( __s, __l, __f, ... ) _sprintf_l( __s, __f, __l, __VA_ARGS__ )
#define vsprintf_l( __s, __l, __f, ... ) _vsprintf_l( __s, __f, __l, __VA_ARGS__ )
#define vsnprintf_l( __s, __n, __l, __f, ... ) _vsnprintf_l( __s, __n, __f, __l, __VA_ARGS__ )
_LIBCPP_FUNC_VIS int snprintf_l(char *__ret, size_t __n, locale_t __loc, const char *__format, ...);
_LIBCPP_FUNC_VIS int asprintf_l( char **__ret, locale_t __loc, const char *__format, ... );
_LIBCPP_FUNC_VIS int vasprintf_l( char **__ret, locale_t __loc, const char *__format, va_list __ap );
// not-so-pressing FIXME: use locale to determine blank characters
inline int isblank_l( int __c, locale_t /*loc*/ )
{
return ( __c == ' ' || __c == '\t' );
}
inline int iswblank_l( wint_t __c, locale_t /*loc*/ )
{
return ( __c == L' ' || __c == L'\t' );
}
#endif // _LIBCPP___SUPPORT_WIN32_LOCALE_WIN32_H

View file

@ -0,0 +1,47 @@
// -*- 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___SUPPORT_XLOCALE_NOP_LOCALE_MGMT_H
#define _LIBCPP___SUPPORT_XLOCALE_NOP_LOCALE_MGMT_H
#include <__config>
#ifdef __cplusplus
extern "C" {
#endif
// Patch over lack of extended locale support
typedef void *locale_t;
inline _LIBCPP_HIDE_FROM_ABI_C locale_t duplocale(locale_t) { return NULL; }
inline _LIBCPP_HIDE_FROM_ABI_C void freelocale(locale_t) {}
inline _LIBCPP_HIDE_FROM_ABI_C locale_t newlocale(int, const char*, locale_t) { return NULL; }
inline _LIBCPP_HIDE_FROM_ABI_C locale_t uselocale(locale_t) { return NULL; }
#define LC_COLLATE_MASK (1 << LC_COLLATE)
#define LC_CTYPE_MASK (1 << LC_CTYPE)
#define LC_MESSAGES_MASK (1 << LC_MESSAGES)
#define LC_MONETARY_MASK (1 << LC_MONETARY)
#define LC_NUMERIC_MASK (1 << LC_NUMERIC)
#define LC_TIME_MASK (1 << LC_TIME)
#define LC_ALL_MASK (LC_COLLATE_MASK|\
LC_CTYPE_MASK|\
LC_MONETARY_MASK|\
LC_NUMERIC_MASK|\
LC_TIME_MASK|\
LC_MESSAGES_MASK)
#ifdef __cplusplus
} // extern "C"
#endif
#endif // _LIBCPP___SUPPORT_XLOCALE_NOP_LOCALE_MGMT_H

View file

@ -0,0 +1,115 @@
// -*- 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
//
//===----------------------------------------------------------------------===//
// 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
#include <__config>
#include <ctype.h>
#include <time.h>
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
# include <wctype.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
inline _LIBCPP_HIDE_FROM_ABI_C int isalnum_l(int __c, locale_t) { return ::isalnum(__c); }
inline _LIBCPP_HIDE_FROM_ABI_C int isalpha_l(int __c, locale_t) { return ::isalpha(__c); }
inline _LIBCPP_HIDE_FROM_ABI_C int isblank_l(int __c, locale_t) { return ::isblank(__c); }
inline _LIBCPP_HIDE_FROM_ABI_C int iscntrl_l(int __c, locale_t) { return ::iscntrl(__c); }
inline _LIBCPP_HIDE_FROM_ABI_C int isdigit_l(int __c, locale_t) { return ::isdigit(__c); }
inline _LIBCPP_HIDE_FROM_ABI_C int isgraph_l(int __c, locale_t) { return ::isgraph(__c); }
inline _LIBCPP_HIDE_FROM_ABI_C int islower_l(int __c, locale_t) { return ::islower(__c); }
inline _LIBCPP_HIDE_FROM_ABI_C int isprint_l(int __c, locale_t) { return ::isprint(__c); }
inline _LIBCPP_HIDE_FROM_ABI_C int ispunct_l(int __c, locale_t) { return ::ispunct(__c); }
inline _LIBCPP_HIDE_FROM_ABI_C int isspace_l(int __c, locale_t) { return ::isspace(__c); }
inline _LIBCPP_HIDE_FROM_ABI_C int isupper_l(int __c, locale_t) { return ::isupper(__c); }
inline _LIBCPP_HIDE_FROM_ABI_C int isxdigit_l(int __c, locale_t) { return ::isxdigit(__c); }
inline _LIBCPP_HIDE_FROM_ABI_C int toupper_l(int __c, locale_t) { return ::toupper(__c); }
inline _LIBCPP_HIDE_FROM_ABI_C int tolower_l(int __c, locale_t) { return ::tolower(__c); }
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
inline _LIBCPP_HIDE_FROM_ABI_C int iswalnum_l(wint_t __c, locale_t) { return ::iswalnum(__c); }
inline _LIBCPP_HIDE_FROM_ABI_C int iswalpha_l(wint_t __c, locale_t) { return ::iswalpha(__c); }
inline _LIBCPP_HIDE_FROM_ABI_C int iswblank_l(wint_t __c, locale_t) { return ::iswblank(__c); }
inline _LIBCPP_HIDE_FROM_ABI_C int iswcntrl_l(wint_t __c, locale_t) { return ::iswcntrl(__c); }
inline _LIBCPP_HIDE_FROM_ABI_C int iswdigit_l(wint_t __c, locale_t) { return ::iswdigit(__c); }
inline _LIBCPP_HIDE_FROM_ABI_C int iswgraph_l(wint_t __c, locale_t) { return ::iswgraph(__c); }
inline _LIBCPP_HIDE_FROM_ABI_C int iswlower_l(wint_t __c, locale_t) { return ::iswlower(__c); }
inline _LIBCPP_HIDE_FROM_ABI_C int iswprint_l(wint_t __c, locale_t) { return ::iswprint(__c); }
inline _LIBCPP_HIDE_FROM_ABI_C int iswpunct_l(wint_t __c, locale_t) { return ::iswpunct(__c); }
inline _LIBCPP_HIDE_FROM_ABI_C int iswspace_l(wint_t __c, locale_t) { return ::iswspace(__c); }
inline _LIBCPP_HIDE_FROM_ABI_C int iswupper_l(wint_t __c, locale_t) { return ::iswupper(__c); }
inline _LIBCPP_HIDE_FROM_ABI_C int iswxdigit_l(wint_t __c, locale_t) { return ::iswxdigit(__c); }
inline _LIBCPP_HIDE_FROM_ABI_C wint_t towupper_l(wint_t __c, locale_t) { return ::towupper(__c); }
inline _LIBCPP_HIDE_FROM_ABI_C wint_t towlower_l(wint_t __c, locale_t) { return ::towlower(__c); }
#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
inline _LIBCPP_HIDE_FROM_ABI_C int strcoll_l(const char* __s1, const char* __s2, locale_t) {
return ::strcoll(__s1, __s2);
}
inline _LIBCPP_HIDE_FROM_ABI_C size_t strxfrm_l(char* __dest, const char* __src, size_t __n, locale_t) {
return ::strxfrm(__dest, __src, __n);
}
inline _LIBCPP_HIDE_FROM_ABI_C size_t
strftime_l(char* __s, size_t __max, const char* __format, const struct tm* __tm, locale_t) {
return ::strftime(__s, __max, __format, __tm);
}
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
inline _LIBCPP_HIDE_FROM_ABI_C int wcscoll_l(const wchar_t* __ws1, const wchar_t* __ws2, locale_t) {
return ::wcscoll(__ws1, __ws2);
}
inline _LIBCPP_HIDE_FROM_ABI_C size_t wcsxfrm_l(wchar_t* __dest, const wchar_t* __src, size_t __n, locale_t) {
return ::wcsxfrm(__dest, __src, __n);
}
#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
#ifdef __cplusplus
}
#endif
#endif // _LIBCPP___SUPPORT_XLOCALE_POSIX_L_FALLBACK_H

View file

@ -0,0 +1,69 @@
// -*- 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
//
//===----------------------------------------------------------------------===//
// 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
#include <__config>
#include <stdlib.h>
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
# include <wchar.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
inline _LIBCPP_HIDE_FROM_ABI_C float strtof_l(const char* __nptr, char** __endptr, locale_t) {
return ::strtof(__nptr, __endptr);
}
inline _LIBCPP_HIDE_FROM_ABI_C double strtod_l(const char* __nptr, char** __endptr, locale_t) {
return ::strtod(__nptr, __endptr);
}
inline _LIBCPP_HIDE_FROM_ABI_C long double strtold_l(const char* __nptr, char** __endptr, locale_t) {
return ::strtold(__nptr, __endptr);
}
inline _LIBCPP_HIDE_FROM_ABI_C long long strtoll_l(const char* __nptr, char** __endptr, int __base, locale_t) {
return ::strtoll(__nptr, __endptr, __base);
}
inline _LIBCPP_HIDE_FROM_ABI_C unsigned long long
strtoull_l(const char* __nptr, char** __endptr, int __base, locale_t) {
return ::strtoull(__nptr, __endptr, __base);
}
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
inline _LIBCPP_HIDE_FROM_ABI_C long long wcstoll_l(const wchar_t* __nptr, wchar_t** __endptr, int __base, locale_t) {
return ::wcstoll(__nptr, __endptr, __base);
}
inline _LIBCPP_HIDE_FROM_ABI_C unsigned long long
wcstoull_l(const wchar_t* __nptr, wchar_t** __endptr, int __base, locale_t) {
return ::wcstoull(__nptr, __endptr, __base);
}
inline _LIBCPP_HIDE_FROM_ABI_C long double wcstold_l(const wchar_t* __nptr, wchar_t** __endptr, locale_t) {
return ::wcstold(__nptr, __endptr);
}
#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
#ifdef __cplusplus
}
#endif
#endif // _LIBCPP___SUPPORT_XLOCALE_STRTONUM_FALLBACK_H