diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2025-04-05 01:46:13 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-05 01:46:13 -0400 |
| commit | 0cd31fc7ff157551cfbba5da35cd79f118d2a2e3 (patch) | |
| tree | a308488f5d85184c8ec402fb3f55f1cf2704443e /lib/libcxx/src/support | |
| parent | 8acedfd5baabab705946ad097746f9183ef62420 (diff) | |
| parent | cefe65c1b8abe65a22d4b68410db1be264fdeda0 (diff) | |
| download | zig-0cd31fc7ff157551cfbba5da35cd79f118d2a2e3.tar.gz zig-0cd31fc7ff157551cfbba5da35cd79f118d2a2e3.zip | |
Merge pull request #22780 from ziglang/llvm20
LLVM 20
Diffstat (limited to 'lib/libcxx/src/support')
| -rw-r--r-- | lib/libcxx/src/support/ibm/mbsnrtowcs.cpp | 4 | ||||
| -rw-r--r-- | lib/libcxx/src/support/ibm/wcsnrtombs.cpp | 4 | ||||
| -rw-r--r-- | lib/libcxx/src/support/ibm/xlocale_zos.cpp | 16 | ||||
| -rw-r--r-- | lib/libcxx/src/support/runtime/exception_fallback.ipp | 23 | ||||
| -rw-r--r-- | lib/libcxx/src/support/runtime/exception_msvc.ipp | 21 | ||||
| -rw-r--r-- | lib/libcxx/src/support/runtime/exception_pointer_cxxabi.ipp | 4 | ||||
| -rw-r--r-- | lib/libcxx/src/support/runtime/exception_pointer_glibcxx.ipp | 6 | ||||
| -rw-r--r-- | lib/libcxx/src/support/runtime/exception_pointer_msvc.ipp | 4 | ||||
| -rw-r--r-- | lib/libcxx/src/support/runtime/exception_pointer_unimplemented.ipp | 28 | ||||
| -rw-r--r-- | lib/libcxx/src/support/win32/locale_win32.cpp | 213 | ||||
| -rw-r--r-- | lib/libcxx/src/support/win32/support.cpp | 41 | ||||
| -rw-r--r-- | lib/libcxx/src/support/win32/thread_win32.cpp | 2 |
12 files changed, 186 insertions, 180 deletions
diff --git a/lib/libcxx/src/support/ibm/mbsnrtowcs.cpp b/lib/libcxx/src/support/ibm/mbsnrtowcs.cpp index 122dc5ed89..d0006a8468 100644 --- a/lib/libcxx/src/support/ibm/mbsnrtowcs.cpp +++ b/lib/libcxx/src/support/ibm/mbsnrtowcs.cpp @@ -48,7 +48,7 @@ _LIBCPP_EXPORTED_FROM_ABI size_t mbsnrtowcs( size_t dest_remaining = max_dest_chars - dest_converted; if (dst == nullptr) { - result = mbrtowc(NULL, *src + source_converted, source_remaining, ps); + result = mbrtowc(nullptr, *src + source_converted, source_remaining, ps); } else if (dest_remaining >= source_remaining) { // dst has enough space to translate in-place. result = mbrtowc(dst + dest_converted, *src + source_converted, source_remaining, ps); @@ -86,7 +86,7 @@ _LIBCPP_EXPORTED_FROM_ABI size_t mbsnrtowcs( if (dst) { if (result == terminated_sequence) - *src = NULL; + *src = nullptr; else *src += source_converted; } diff --git a/lib/libcxx/src/support/ibm/wcsnrtombs.cpp b/lib/libcxx/src/support/ibm/wcsnrtombs.cpp index f037215233..df87b9ea07 100644 --- a/lib/libcxx/src/support/ibm/wcsnrtombs.cpp +++ b/lib/libcxx/src/support/ibm/wcsnrtombs.cpp @@ -41,7 +41,7 @@ _LIBCPP_EXPORTED_FROM_ABI size_t wcsnrtombs( size_t dest_remaining = dst_size_bytes - dest_converted; if (dst == nullptr) { - result = wcrtomb(NULL, c, ps); + result = wcrtomb(nullptr, c, ps); } else if (dest_remaining >= static_cast<size_t>(MB_CUR_MAX)) { // dst has enough space to translate in-place. result = wcrtomb(dst + dest_converted, c, ps); @@ -82,7 +82,7 @@ _LIBCPP_EXPORTED_FROM_ABI size_t wcsnrtombs( if (c == L'\0') { if (dst) - *src = NULL; + *src = nullptr; return dest_converted; } } diff --git a/lib/libcxx/src/support/ibm/xlocale_zos.cpp b/lib/libcxx/src/support/ibm/xlocale_zos.cpp index 9a90e08e11..136999ec0b 100644 --- a/lib/libcxx/src/support/ibm/xlocale_zos.cpp +++ b/lib/libcxx/src/support/ibm/xlocale_zos.cpp @@ -20,12 +20,12 @@ locale_t newlocale(int category_mask, const char* locale, locale_t base) { std::string current_loc_name(setlocale(LC_ALL, 0)); // Check for errors. - if (category_mask == LC_ALL_MASK && setlocale(LC_ALL, locale) == NULL) { + if (category_mask == LC_ALL_MASK && setlocale(LC_ALL, locale) == nullptr) { errno = EINVAL; return (locale_t)0; } else { for (int _Cat = 0; _Cat <= _LC_MAX; ++_Cat) { - if ((_CATMASK(_Cat) & category_mask) != 0 && setlocale(_Cat, locale) == NULL) { + if ((_CATMASK(_Cat) & category_mask) != 0 && setlocale(_Cat, locale) == nullptr) { setlocale(LC_ALL, current_loc_name.c_str()); errno = EINVAL; return (locale_t)0; @@ -74,12 +74,12 @@ locale_t uselocale(locale_t newloc) { if (newloc) { // Set locales and check for errors. bool is_error = - (newloc->category_mask & LC_COLLATE_MASK && setlocale(LC_COLLATE, newloc->lc_collate.c_str()) == NULL) || - (newloc->category_mask & LC_CTYPE_MASK && setlocale(LC_CTYPE, newloc->lc_ctype.c_str()) == NULL) || - (newloc->category_mask & LC_MONETARY_MASK && setlocale(LC_MONETARY, newloc->lc_monetary.c_str()) == NULL) || - (newloc->category_mask & LC_NUMERIC_MASK && setlocale(LC_NUMERIC, newloc->lc_numeric.c_str()) == NULL) || - (newloc->category_mask & LC_TIME_MASK && setlocale(LC_TIME, newloc->lc_time.c_str()) == NULL) || - (newloc->category_mask & LC_MESSAGES_MASK && setlocale(LC_MESSAGES, newloc->lc_messages.c_str()) == NULL); + (newloc->category_mask & LC_COLLATE_MASK && setlocale(LC_COLLATE, newloc->lc_collate.c_str()) == nullptr) || + (newloc->category_mask & LC_CTYPE_MASK && setlocale(LC_CTYPE, newloc->lc_ctype.c_str()) == nullptr) || + (newloc->category_mask & LC_MONETARY_MASK && setlocale(LC_MONETARY, newloc->lc_monetary.c_str()) == nullptr) || + (newloc->category_mask & LC_NUMERIC_MASK && setlocale(LC_NUMERIC, newloc->lc_numeric.c_str()) == nullptr) || + (newloc->category_mask & LC_TIME_MASK && setlocale(LC_TIME, newloc->lc_time.c_str()) == nullptr) || + (newloc->category_mask & LC_MESSAGES_MASK && setlocale(LC_MESSAGES, newloc->lc_messages.c_str()) == nullptr); if (is_error) { setlocale(LC_ALL, current_loc_name.c_str()); diff --git a/lib/libcxx/src/support/runtime/exception_fallback.ipp b/lib/libcxx/src/support/runtime/exception_fallback.ipp index 18ff4b83d8..ba283aee22 100644 --- a/lib/libcxx/src/support/runtime/exception_fallback.ipp +++ b/lib/libcxx/src/support/runtime/exception_fallback.ipp @@ -7,7 +7,7 @@ // //===----------------------------------------------------------------------===// -#include <cstdio> +#include <__verbose_abort> namespace std { @@ -21,7 +21,7 @@ unexpected_handler set_unexpected(unexpected_handler func) noexcept { unexpected_handler get_unexpected() noexcept { return __libcpp_atomic_load(&__unexpected_handler); } -_LIBCPP_NORETURN void unexpected() { +[[noreturn]] void unexpected() { (*get_unexpected())(); // unexpected handler should not return terminate(); @@ -33,29 +33,26 @@ terminate_handler set_terminate(terminate_handler func) noexcept { terminate_handler get_terminate() noexcept { return __libcpp_atomic_load(&__terminate_handler); } -_LIBCPP_NORETURN void terminate() noexcept { -#ifndef _LIBCPP_HAS_NO_EXCEPTIONS +[[noreturn]] void terminate() noexcept { +#if _LIBCPP_HAS_EXCEPTIONS try { -#endif // _LIBCPP_HAS_NO_EXCEPTIONS +#endif // _LIBCPP_HAS_EXCEPTIONS (*get_terminate())(); // handler should not return - fprintf(stderr, "terminate_handler unexpectedly returned\n"); - ::abort(); -#ifndef _LIBCPP_HAS_NO_EXCEPTIONS + __libcpp_verbose_abort("terminate_handler unexpectedly returned\n"); +#if _LIBCPP_HAS_EXCEPTIONS } catch (...) { // handler should not throw exception - fprintf(stderr, "terminate_handler unexpectedly threw an exception\n"); - ::abort(); + __libcpp_verbose_abort("terminate_handler unexpectedly threw an exception\n"); } -#endif // _LIBCPP_HAS_NO_EXCEPTIONS +#endif // _LIBCPP_HAS_EXCEPTIONS } bool uncaught_exception() noexcept { return uncaught_exceptions() > 0; } int uncaught_exceptions() noexcept { #warning uncaught_exception not yet implemented - fprintf(stderr, "uncaught_exceptions not yet implemented\n"); - ::abort(); + __libcpp_verbose_abort("uncaught_exceptions not yet implemented\n"); } exception::~exception() noexcept {} diff --git a/lib/libcxx/src/support/runtime/exception_msvc.ipp b/lib/libcxx/src/support/runtime/exception_msvc.ipp index 323cd9d180..2ae004bb02 100644 --- a/lib/libcxx/src/support/runtime/exception_msvc.ipp +++ b/lib/libcxx/src/support/runtime/exception_msvc.ipp @@ -11,8 +11,7 @@ # error this header can only be used when targeting the MSVC ABI #endif -#include <stdio.h> -#include <stdlib.h> +#include <__verbose_abort> extern "C" { typedef void(__cdecl* terminate_handler)(); @@ -32,7 +31,7 @@ unexpected_handler set_unexpected(unexpected_handler func) noexcept { return ::s unexpected_handler get_unexpected() noexcept { return ::_get_unexpected(); } -_LIBCPP_NORETURN void unexpected() { +[[noreturn]] void unexpected() { (*get_unexpected())(); // unexpected handler should not return terminate(); @@ -42,21 +41,19 @@ terminate_handler set_terminate(terminate_handler func) noexcept { return ::set_ terminate_handler get_terminate() noexcept { return ::_get_terminate(); } -_LIBCPP_NORETURN void terminate() noexcept { -#ifndef _LIBCPP_HAS_NO_EXCEPTIONS +[[noreturn]] void terminate() noexcept { +#if _LIBCPP_HAS_EXCEPTIONS try { -#endif // _LIBCPP_HAS_NO_EXCEPTIONS +#endif // _LIBCPP_HAS_EXCEPTIONS (*get_terminate())(); // handler should not return - fprintf(stderr, "terminate_handler unexpectedly returned\n"); - ::abort(); -#ifndef _LIBCPP_HAS_NO_EXCEPTIONS + __libcpp_verbose_abort("terminate_handler unexpectedly returned\n"); +#if _LIBCPP_HAS_EXCEPTIONS } catch (...) { // handler should not throw exception - fprintf(stderr, "terminate_handler unexpectedly threw an exception\n"); - ::abort(); + __libcpp_verbose_abort("terminate_handler unexpectedly threw an exception\n"); } -#endif // _LIBCPP_HAS_NO_EXCEPTIONS +#endif // _LIBCPP_HAS_EXCEPTIONS } bool uncaught_exception() noexcept { return uncaught_exceptions() > 0; } diff --git a/lib/libcxx/src/support/runtime/exception_pointer_cxxabi.ipp b/lib/libcxx/src/support/runtime/exception_pointer_cxxabi.ipp index bdb17b9996..8f5c2060bb 100644 --- a/lib/libcxx/src/support/runtime/exception_pointer_cxxabi.ipp +++ b/lib/libcxx/src/support/runtime/exception_pointer_cxxabi.ipp @@ -40,7 +40,7 @@ nested_exception::nested_exception() noexcept : __ptr_(current_exception()) {} nested_exception::~nested_exception() noexcept {} -_LIBCPP_NORETURN void nested_exception::rethrow_nested() const { +void nested_exception::rethrow_nested() const { if (__ptr_ == nullptr) terminate(); rethrow_exception(__ptr_); @@ -55,7 +55,7 @@ exception_ptr current_exception() noexcept { return ptr; } -_LIBCPP_NORETURN void rethrow_exception(exception_ptr p) { +void rethrow_exception(exception_ptr p) { __cxa_rethrow_primary_exception(p.__ptr_); // if p.__ptr_ is NULL, above returns so we terminate terminate(); diff --git a/lib/libcxx/src/support/runtime/exception_pointer_glibcxx.ipp b/lib/libcxx/src/support/runtime/exception_pointer_glibcxx.ipp index 6dad248f9e..174b44ce0e 100644 --- a/lib/libcxx/src/support/runtime/exception_pointer_glibcxx.ipp +++ b/lib/libcxx/src/support/runtime/exception_pointer_glibcxx.ipp @@ -31,7 +31,7 @@ struct exception_ptr { } // namespace __exception_ptr -_LIBCPP_NORETURN void rethrow_exception(__exception_ptr::exception_ptr); +[[noreturn]] void rethrow_exception(__exception_ptr::exception_ptr); exception_ptr::~exception_ptr() noexcept { reinterpret_cast<__exception_ptr::exception_ptr*>(this)->~exception_ptr(); } @@ -55,13 +55,13 @@ exception_ptr exception_ptr::__from_native_exception_pointer(void* __e) noexcept nested_exception::nested_exception() noexcept : __ptr_(current_exception()) {} -_LIBCPP_NORETURN void nested_exception::rethrow_nested() const { +[[noreturn]] void nested_exception::rethrow_nested() const { if (__ptr_ == nullptr) terminate(); rethrow_exception(__ptr_); } -_LIBCPP_NORETURN void rethrow_exception(exception_ptr p) { +[[noreturn]] void rethrow_exception(exception_ptr p) { rethrow_exception(reinterpret_cast<__exception_ptr::exception_ptr&>(p)); } diff --git a/lib/libcxx/src/support/runtime/exception_pointer_msvc.ipp b/lib/libcxx/src/support/runtime/exception_pointer_msvc.ipp index b87742b32d..2be5136176 100644 --- a/lib/libcxx/src/support/runtime/exception_pointer_msvc.ipp +++ b/lib/libcxx/src/support/runtime/exception_pointer_msvc.ipp @@ -61,13 +61,13 @@ exception_ptr current_exception() noexcept { return __ret; } -_LIBCPP_NORETURN void rethrow_exception(exception_ptr p) { __ExceptionPtrRethrow(&p); } +[[noreturn]] void rethrow_exception(exception_ptr p) { __ExceptionPtrRethrow(&p); } nested_exception::nested_exception() noexcept : __ptr_(current_exception()) {} nested_exception::~nested_exception() noexcept {} -_LIBCPP_NORETURN void nested_exception::rethrow_nested() const { +[[noreturn]] void nested_exception::rethrow_nested() const { if (__ptr_ == nullptr) terminate(); rethrow_exception(__ptr_); diff --git a/lib/libcxx/src/support/runtime/exception_pointer_unimplemented.ipp b/lib/libcxx/src/support/runtime/exception_pointer_unimplemented.ipp index e12b0caf41..05a71ce34e 100644 --- a/lib/libcxx/src/support/runtime/exception_pointer_unimplemented.ipp +++ b/lib/libcxx/src/support/runtime/exception_pointer_unimplemented.ipp @@ -7,33 +7,28 @@ // //===----------------------------------------------------------------------===// -#include <stdio.h> -#include <stdlib.h> +#include <__verbose_abort> namespace std { exception_ptr::~exception_ptr() noexcept { #warning exception_ptr not yet implemented - fprintf(stderr, "exception_ptr not yet implemented\n"); - ::abort(); + __libcpp_verbose_abort("exception_ptr not yet implemented\n"); } exception_ptr::exception_ptr(const exception_ptr& other) noexcept : __ptr_(other.__ptr_) { #warning exception_ptr not yet implemented - fprintf(stderr, "exception_ptr not yet implemented\n"); - ::abort(); + __libcpp_verbose_abort("exception_ptr not yet implemented\n"); } exception_ptr& exception_ptr::operator=(const exception_ptr& other) noexcept { #warning exception_ptr not yet implemented - fprintf(stderr, "exception_ptr not yet implemented\n"); - ::abort(); + __libcpp_verbose_abort("exception_ptr not yet implemented\n"); } exception_ptr exception_ptr::__from_native_exception_pointer(void *__e) noexcept { #warning exception_ptr not yet implemented - fprintf(stderr, "exception_ptr not yet implemented\n"); - ::abort(); + __libcpp_verbose_abort("exception_ptr not yet implemented\n"); } nested_exception::nested_exception() noexcept : __ptr_(current_exception()) {} @@ -44,10 +39,9 @@ nested_exception::~nested_exception() noexcept {} #endif -_LIBCPP_NORETURN void nested_exception::rethrow_nested() const { +[[noreturn]] void nested_exception::rethrow_nested() const { #warning exception_ptr not yet implemented - fprintf(stderr, "exception_ptr not yet implemented\n"); - ::abort(); + __libcpp_verbose_abort("exception_ptr not yet implemented\n"); #if 0 if (__ptr_ == nullptr) terminate(); @@ -57,14 +51,12 @@ _LIBCPP_NORETURN void nested_exception::rethrow_nested() const { exception_ptr current_exception() noexcept { #warning exception_ptr not yet implemented - fprintf(stderr, "exception_ptr not yet implemented\n"); - ::abort(); + __libcpp_verbose_abort("exception_ptr not yet implemented\n"); } -_LIBCPP_NORETURN void rethrow_exception(exception_ptr p) { +[[noreturn]] void rethrow_exception(exception_ptr p) { #warning exception_ptr not yet implemented - fprintf(stderr, "exception_ptr not yet implemented\n"); - ::abort(); + __libcpp_verbose_abort("exception_ptr not yet implemented\n"); } } // namespace std diff --git a/lib/libcxx/src/support/win32/locale_win32.cpp b/lib/libcxx/src/support/win32/locale_win32.cpp index 57ef94932b..24402e818d 100644 --- a/lib/libcxx/src/support/win32/locale_win32.cpp +++ b/lib/libcxx/src/support/win32/locale_win32.cpp @@ -6,127 +6,180 @@ // //===----------------------------------------------------------------------===// -#include <cstdarg> // va_start, va_end -#include <locale> -#include <memory> -#include <type_traits> +#include <__locale_dir/support/windows.h> +#include <clocale> // std::localeconv() & friends +#include <cstdarg> // va_start & friends +#include <cstddef> +#include <cstdio> // std::vsnprintf & friends +#include <cstdlib> // std::strtof & friends +#include <ctime> // std::strftime +#include <cwchar> // wide char manipulation -#include <__locale_dir/locale_base_api/locale_guard.h> +_LIBCPP_BEGIN_NAMESPACE_STD +namespace __locale { -int __libcpp_vasprintf(char** sptr, const char* __restrict fmt, va_list ap); +// +// Locale management +// +// FIXME: base and mask currently unused. Needs manual work to construct the new locale +__locale_t __newlocale(int /*mask*/, const char* locale, __locale_t /*base*/) { + return {::_create_locale(LC_ALL, locale), locale}; +} + +__lconv_t* __localeconv(__locale_t& loc) { + __locale_guard __current(loc); + lconv* lc = std::localeconv(); + if (!lc) + return lc; + return loc.__store_lconv(lc); +} -using std::__libcpp_locale_guard; +// +// Strtonum functions +// +#if !defined(_LIBCPP_MSVCRT) +float __strtof(const char* nptr, char** endptr, __locale_t loc) { + __locale_guard __current(loc); + return std::strtof(nptr, endptr); +} -// FIXME: base and mask currently unused. Needs manual work to construct the new locale -locale_t newlocale(int /*mask*/, const char* locale, locale_t /*base*/) { - return {_create_locale(LC_ALL, locale), locale}; +long double __strtold(const char* nptr, char** endptr, __locale_t loc) { + __locale_guard __current(loc); + return std::strtold(nptr, endptr); +} +#endif + +// +// Character manipulation functions +// +#if defined(__MINGW32__) && __MSVCRT_VERSION__ < 0x0800 +size_t __strftime(char* ret, size_t n, const char* format, const struct tm* tm, __locale_t loc) { + __locale_guard __current(loc); + return std::strftime(ret, n, format, tm); } +#endif -decltype(MB_CUR_MAX) MB_CUR_MAX_L(locale_t __l) { +// +// Other functions +// +decltype(MB_CUR_MAX) __mb_len_max(__locale_t __l) { #if defined(_LIBCPP_MSVCRT) - return ___mb_cur_max_l_func(__l); + return ::___mb_cur_max_l_func(__l); #else - __libcpp_locale_guard __current(__l); + __locale_guard __current(__l); return MB_CUR_MAX; #endif } -lconv* localeconv_l(locale_t& loc) { - __libcpp_locale_guard __current(loc); - lconv* lc = localeconv(); - if (!lc) - return lc; - return loc.__store_lconv(lc); +wint_t __btowc(int c, __locale_t loc) { + __locale_guard __current(loc); + return std::btowc(c); } -size_t mbrlen_l(const char* __restrict s, size_t n, mbstate_t* __restrict ps, locale_t loc) { - __libcpp_locale_guard __current(loc); - return mbrlen(s, n, ps); -} -size_t -mbsrtowcs_l(wchar_t* __restrict dst, const char** __restrict src, size_t len, mbstate_t* __restrict ps, locale_t loc) { - __libcpp_locale_guard __current(loc); - return mbsrtowcs(dst, src, len, ps); + +int __wctob(wint_t c, __locale_t loc) { + __locale_guard __current(loc); + return std::wctob(c); } -size_t wcrtomb_l(char* __restrict s, wchar_t wc, mbstate_t* __restrict ps, locale_t loc) { - __libcpp_locale_guard __current(loc); - return wcrtomb(s, wc, ps); + +size_t __wcsnrtombs(char* __restrict dst, + const wchar_t** __restrict src, + size_t nwc, + size_t len, + mbstate_t* __restrict ps, + __locale_t loc) { + __locale_guard __current(loc); + return ::wcsnrtombs(dst, src, nwc, len, ps); } -size_t mbrtowc_l(wchar_t* __restrict pwc, const char* __restrict s, size_t n, mbstate_t* __restrict ps, locale_t loc) { - __libcpp_locale_guard __current(loc); - return mbrtowc(pwc, s, n, ps); + +size_t __wcrtomb(char* __restrict s, wchar_t wc, mbstate_t* __restrict ps, __locale_t loc) { + __locale_guard __current(loc); + return std::wcrtomb(s, wc, ps); } -size_t mbsnrtowcs_l(wchar_t* __restrict dst, + +size_t __mbsnrtowcs(wchar_t* __restrict dst, const char** __restrict src, size_t nms, size_t len, mbstate_t* __restrict ps, - locale_t loc) { - __libcpp_locale_guard __current(loc); - return mbsnrtowcs(dst, src, nms, len, ps); + __locale_t loc) { + __locale_guard __current(loc); + return ::mbsnrtowcs(dst, src, nms, len, ps); } -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) { - __libcpp_locale_guard __current(loc); - return wcsnrtombs(dst, src, nwc, len, ps); + +size_t +__mbrtowc(wchar_t* __restrict pwc, const char* __restrict s, size_t n, mbstate_t* __restrict ps, __locale_t loc) { + __locale_guard __current(loc); + return std::mbrtowc(pwc, s, n, ps); } -wint_t btowc_l(int c, locale_t loc) { - __libcpp_locale_guard __current(loc); - return btowc(c); + +size_t __mbrlen(const char* __restrict s, size_t n, mbstate_t* __restrict ps, __locale_t loc) { + __locale_guard __current(loc); + return std::mbrlen(s, n, ps); } -int wctob_l(wint_t c, locale_t loc) { - __libcpp_locale_guard __current(loc); - return wctob(c); + +size_t __mbsrtowcs( + wchar_t* __restrict dst, const char** __restrict src, size_t len, mbstate_t* __restrict ps, __locale_t loc) { + __locale_guard __current(loc); + return std::mbsrtowcs(dst, src, len, ps); } -int snprintf_l(char* ret, size_t n, locale_t loc, const char* format, ...) { +int __snprintf(char* ret, size_t n, __locale_t loc, const char* format, ...) { va_list ap; va_start(ap, format); #if defined(_LIBCPP_MSVCRT) // FIXME: Remove usage of internal CRT function and globals. - int result = __stdio_common_vsprintf( + int result = ::__stdio_common_vsprintf( _CRT_INTERNAL_LOCAL_PRINTF_OPTIONS | _CRT_INTERNAL_PRINTF_STANDARD_SNPRINTF_BEHAVIOR, ret, n, format, loc, ap); #else - __libcpp_locale_guard __current(loc); + __locale_guard __current(loc); _LIBCPP_DIAGNOSTIC_PUSH _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wformat-nonliteral") - int result = vsnprintf(ret, n, format, ap); + int result = std::vsnprintf(ret, n, format, ap); _LIBCPP_DIAGNOSTIC_POP #endif va_end(ap); return result; } -int asprintf_l(char** ret, locale_t loc, const char* format, ...) { +// Like sprintf, but when return value >= 0 it returns +// a pointer to a malloc'd string in *sptr. +// If return >= 0, use free to delete *sptr. +int __libcpp_vasprintf(char** sptr, const char* __restrict format, va_list ap) { + *sptr = nullptr; + // Query the count required. + va_list ap_copy; + va_copy(ap_copy, ap); + _LIBCPP_DIAGNOSTIC_PUSH + _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wformat-nonliteral") + int count = vsnprintf(nullptr, 0, format, ap_copy); + _LIBCPP_DIAGNOSTIC_POP + va_end(ap_copy); + if (count < 0) + return count; + size_t buffer_size = static_cast<size_t>(count) + 1; + char* p = static_cast<char*>(malloc(buffer_size)); + if (!p) + return -1; + // If we haven't used exactly what was required, something is wrong. + // Maybe bug in vsnprintf. Report the error and return. + _LIBCPP_DIAGNOSTIC_PUSH + _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wformat-nonliteral") + if (vsnprintf(p, buffer_size, format, ap) != count) { + _LIBCPP_DIAGNOSTIC_POP + free(p); + return -1; + } + // All good. This is returning memory to the caller not freeing it. + *sptr = p; + return count; +} + +int __asprintf(char** ret, __locale_t loc, const char* format, ...) { va_list ap; va_start(ap, format); - int result = vasprintf_l(ret, loc, format, ap); - va_end(ap); - return result; -} -int vasprintf_l(char** ret, locale_t loc, const char* format, va_list ap) { - __libcpp_locale_guard __current(loc); + __locale_guard __current(loc); return __libcpp_vasprintf(ret, format, ap); } -#if !defined(_LIBCPP_MSVCRT) -float strtof_l(const char* nptr, char** endptr, locale_t loc) { - __libcpp_locale_guard __current(loc); - return strtof(nptr, endptr); -} - -long double strtold_l(const char* nptr, char** endptr, locale_t loc) { - __libcpp_locale_guard __current(loc); - return strtold(nptr, endptr); -} -#endif - -#if defined(__MINGW32__) && __MSVCRT_VERSION__ < 0x0800 -size_t strftime_l(char* ret, size_t n, const char* format, const struct tm* tm, locale_t loc) { - __libcpp_locale_guard __current(loc); - return strftime(ret, n, format, tm); -} -#endif +} // namespace __locale +_LIBCPP_END_NAMESPACE_STD diff --git a/lib/libcxx/src/support/win32/support.cpp b/lib/libcxx/src/support/win32/support.cpp index fed51d8b0b..7ac508301b 100644 --- a/lib/libcxx/src/support/win32/support.cpp +++ b/lib/libcxx/src/support/win32/support.cpp @@ -13,39 +13,6 @@ #include <cstring> // strcpy, wcsncpy #include <cwchar> // mbstate_t -// Like sprintf, but when return value >= 0 it returns -// a pointer to a malloc'd string in *sptr. -// If return >= 0, use free to delete *sptr. -int __libcpp_vasprintf(char** sptr, const char* __restrict format, va_list ap) { - *sptr = NULL; - // Query the count required. - va_list ap_copy; - va_copy(ap_copy, ap); - _LIBCPP_DIAGNOSTIC_PUSH - _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wformat-nonliteral") - int count = vsnprintf(NULL, 0, format, ap_copy); - _LIBCPP_DIAGNOSTIC_POP - va_end(ap_copy); - if (count < 0) - return count; - size_t buffer_size = static_cast<size_t>(count) + 1; - char* p = static_cast<char*>(malloc(buffer_size)); - if (!p) - return -1; - // If we haven't used exactly what was required, something is wrong. - // Maybe bug in vsnprintf. Report the error and return. - _LIBCPP_DIAGNOSTIC_PUSH - _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wformat-nonliteral") - if (vsnprintf(p, buffer_size, format, ap) != count) { - _LIBCPP_DIAGNOSTIC_POP - free(p); - return -1; - } - // All good. This is returning memory to the caller not freeing it. - *sptr = p; - return count; -} - // Returns >= 0: the number of wide characters found in the // multi byte sequence src (of src_size_bytes), that fit in the buffer dst // (of max_dest_chars elements size). The count returned excludes the @@ -81,7 +48,7 @@ size_t mbsnrtowcs(wchar_t* __restrict dst, // if result > 0, it's the size in bytes of that character. // othewise if result is zero it indicates the null character has been found. // otherwise it's an error and errno may be set. - size_t char_size = mbrtowc(dst ? dst + dest_converted : NULL, *src + source_converted, source_remaining, ps); + size_t char_size = mbrtowc(dst ? dst + dest_converted : nullptr, *src + source_converted, source_remaining, ps); // Don't do anything to change errno from here on. if (char_size > 0) { source_remaining -= char_size; @@ -95,7 +62,7 @@ size_t mbsnrtowcs(wchar_t* __restrict dst, } if (dst) { if (have_result && result == terminated_sequence) - *src = NULL; + *src = nullptr; else *src += source_converted; } @@ -141,7 +108,7 @@ size_t wcsnrtombs(char* __restrict dst, if (dst) result = wcrtomb_s(&char_size, dst + dest_converted, dest_remaining, c, ps); else - result = wcrtomb_s(&char_size, NULL, 0, c, ps); + result = wcrtomb_s(&char_size, nullptr, 0, c, ps); // If result is zero there is no error and char_size contains the // size of the multi-byte-sequence converted. // Otherwise result indicates an errno type error. @@ -161,7 +128,7 @@ size_t wcsnrtombs(char* __restrict dst, } if (dst) { if (terminator_found) - *src = NULL; + *src = nullptr; else *src = *src + source_converted; } diff --git a/lib/libcxx/src/support/win32/thread_win32.cpp b/lib/libcxx/src/support/win32/thread_win32.cpp index a2585c0b89..3a67d759f0 100644 --- a/lib/libcxx/src/support/win32/thread_win32.cpp +++ b/lib/libcxx/src/support/win32/thread_win32.cpp @@ -129,7 +129,7 @@ __libcpp_init_once_execute_once_thunk(PINIT_ONCE __init_once, PVOID __parameter, int __libcpp_execute_once(__libcpp_exec_once_flag* __flag, void (*__init_routine)(void)) { if (!InitOnceExecuteOnce( - (PINIT_ONCE)__flag, __libcpp_init_once_execute_once_thunk, reinterpret_cast<void*>(__init_routine), NULL)) + (PINIT_ONCE)__flag, __libcpp_init_once_execute_once_thunk, reinterpret_cast<void*>(__init_routine), nullptr)) return GetLastError(); return 0; } |
