diff options
author | mikhnenko <mikhnenko@yandex-team.com> | 2024-03-27 10:35:27 +0300 |
---|---|---|
committer | mikhnenko <mikhnenko@yandex-team.com> | 2024-03-27 10:47:39 +0300 |
commit | 9b902baa4a858f2176c82aa0b20f88232f0da0d8 (patch) | |
tree | 7165a551c2244c4b3c28479ac3a3f6d62346ec89 /contrib/libs/cxxsupp/libcxx/src | |
parent | a1c989e67e438005fa0c34ed0e910536c8941862 (diff) | |
download | ydb-9b902baa4a858f2176c82aa0b20f88232f0da0d8.tar.gz |
Update libcxx to 10 Oct 2023 dc129d6f715cf83a2072fc8de8b4e4c70bca6935
97ce40d276e44357a49b7a945af841896126dca8
Diffstat (limited to 'contrib/libs/cxxsupp/libcxx/src')
23 files changed, 663 insertions, 511 deletions
diff --git a/contrib/libs/cxxsupp/libcxx/src/atomic.cpp b/contrib/libs/cxxsupp/libcxx/src/atomic.cpp index a55249a15c..fc90a1f5b2 100644 --- a/contrib/libs/cxxsupp/libcxx/src/atomic.cpp +++ b/contrib/libs/cxxsupp/libcxx/src/atomic.cpp @@ -147,7 +147,7 @@ static void __libcpp_contention_notify(__cxx_atomic_contention_t volatile* __con // We only call 'wake' if we consumed a contention bit here. __libcpp_platform_wake_by_address(__platform_state, __notify_one); } -static __cxx_contention_t __libcpp_contention_monitor_for_wait(__cxx_atomic_contention_t volatile* __contention_state, +static __cxx_contention_t __libcpp_contention_monitor_for_wait(__cxx_atomic_contention_t volatile* /*__contention_state*/, __cxx_atomic_contention_t const volatile* __platform_state) { // We will monitor this value. diff --git a/contrib/libs/cxxsupp/libcxx/src/chrono.cpp b/contrib/libs/cxxsupp/libcxx/src/chrono.cpp index f159613202..b31ef19c0a 100644 --- a/contrib/libs/cxxsupp/libcxx/src/chrono.cpp +++ b/contrib/libs/cxxsupp/libcxx/src/chrono.cpp @@ -99,7 +99,7 @@ static system_clock::time_point __libcpp_system_clock_now() { nanoseconds::period>>; // The Windows epoch is Jan 1 1601, the Unix epoch Jan 1 1970. - static _LIBCPP_CONSTEXPR const seconds nt_to_unix_epoch{11644473600}; + static constexpr const seconds nt_to_unix_epoch{11644473600}; FILETIME ft; #if (_WIN32_WINNT >= _WIN32_WINNT_WIN8 && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)) || \ diff --git a/contrib/libs/cxxsupp/libcxx/src/condition_variable.cpp b/contrib/libs/cxxsupp/libcxx/src/condition_variable.cpp index 85f334e024..87ce1d8434 100644 --- a/contrib/libs/cxxsupp/libcxx/src/condition_variable.cpp +++ b/contrib/libs/cxxsupp/libcxx/src/condition_variable.cpp @@ -61,7 +61,7 @@ condition_variable::__do_timed_wait(unique_lock<mutex>& lk, __libcpp_timespec_t ts; seconds s = duration_cast<seconds>(d); typedef decltype(ts.tv_sec) ts_sec; - _LIBCPP_CONSTEXPR ts_sec ts_sec_max = numeric_limits<ts_sec>::max(); + constexpr ts_sec ts_sec_max = numeric_limits<ts_sec>::max(); if (s.count() < ts_sec_max) { ts.tv_sec = static_cast<ts_sec>(s.count()); diff --git a/contrib/libs/cxxsupp/libcxx/src/error_category.cpp b/contrib/libs/cxxsupp/libcxx/src/error_category.cpp new file mode 100644 index 0000000000..8ae460fb5f --- /dev/null +++ b/contrib/libs/cxxsupp/libcxx/src/error_category.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include <__config> + +#ifdef _LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS +# define _LIBCPP_ERROR_CATEGORY_DEFINE_LEGACY_INLINE_FUNCTIONS +#endif + +#include <system_error> + +_LIBCPP_BEGIN_NAMESPACE_STD + +// class error_category + +#if defined(_LIBCPP_ERROR_CATEGORY_DEFINE_LEGACY_INLINE_FUNCTIONS) +error_category::error_category() noexcept {} +#endif + +error_category::~error_category() noexcept {} + +error_condition error_category::default_error_condition(int ev) const noexcept { return error_condition(ev, *this); } + +bool error_category::equivalent(int code, const error_condition& condition) const noexcept { + return default_error_condition(code) == condition; +} + +bool error_category::equivalent(const error_code& code, int condition) const noexcept { + return *this == code.category() && code.value() == condition; +} + +_LIBCPP_END_NAMESPACE_STD diff --git a/contrib/libs/cxxsupp/libcxx/src/filesystem/error.h b/contrib/libs/cxxsupp/libcxx/src/filesystem/error.h index 965e0eadcd..93da758761 100644 --- a/contrib/libs/cxxsupp/libcxx/src/filesystem/error.h +++ b/contrib/libs/cxxsupp/libcxx/src/filesystem/error.h @@ -112,7 +112,7 @@ inline error_code make_windows_error(int err) { template <class T> T error_value(); template <> -inline _LIBCPP_CONSTEXPR_SINCE_CXX14 void error_value<void>() {} +inline constexpr void error_value<void>() {} template <> inline bool error_value<bool>() { return false; @@ -128,7 +128,7 @@ inline uintmax_t error_value<uintmax_t>() { return uintmax_t(-1); } template <> -inline _LIBCPP_CONSTEXPR_SINCE_CXX14 file_time_type error_value<file_time_type>() { +inline constexpr file_time_type error_value<file_time_type>() { return file_time_type::min(); } template <> diff --git a/contrib/libs/cxxsupp/libcxx/src/filesystem/posix_compat.h b/contrib/libs/cxxsupp/libcxx/src/filesystem/posix_compat.h index f11f41552e..fb213d9ec1 100644 --- a/contrib/libs/cxxsupp/libcxx/src/filesystem/posix_compat.h +++ b/contrib/libs/cxxsupp/libcxx/src/filesystem/posix_compat.h @@ -322,8 +322,8 @@ inline int statvfs(const wchar_t *p, StatVFS *buf) { inline wchar_t* getcwd([[maybe_unused]] wchar_t* in_buf, [[maybe_unused]] size_t in_size) { // Only expected to be used with us allocating the buffer. - _LIBCPP_ASSERT(in_buf == nullptr, "Windows getcwd() assumes in_buf==nullptr"); - _LIBCPP_ASSERT(in_size == 0, "Windows getcwd() assumes in_size==0"); + _LIBCPP_ASSERT_UNCATEGORIZED(in_buf == nullptr, "Windows getcwd() assumes in_buf==nullptr"); + _LIBCPP_ASSERT_UNCATEGORIZED(in_size == 0, "Windows getcwd() assumes in_size==0"); size_t buff_size = MAX_PATH + 10; std::unique_ptr<wchar_t, decltype(&::free)> buff(static_cast<wchar_t*>(malloc(buff_size * sizeof(wchar_t))), &::free); diff --git a/contrib/libs/cxxsupp/libcxx/src/filesystem/time_utils.h b/contrib/libs/cxxsupp/libcxx/src/filesystem/time_utils.h index 9177e1013d..eb41769368 100644 --- a/contrib/libs/cxxsupp/libcxx/src/filesystem/time_utils.h +++ b/contrib/libs/cxxsupp/libcxx/src/filesystem/time_utils.h @@ -147,7 +147,7 @@ struct time_util_base { .count(); private: - static _LIBCPP_CONSTEXPR fs_duration get_min_nsecs() { + static constexpr fs_duration get_min_nsecs() { return duration_cast<fs_duration>( fs_nanoseconds(min_nsec_timespec) - duration_cast<fs_nanoseconds>(fs_seconds(1))); @@ -157,7 +157,7 @@ private: FileTimeT::duration::min(), "value doesn't roundtrip"); - static _LIBCPP_CONSTEXPR_SINCE_CXX14 bool check_range() { + static constexpr bool check_range() { // This kinda sucks, but it's what happens when we don't have __int128_t. if (sizeof(TimeT) == sizeof(rep)) { typedef duration<long long, ratio<3600 * 24 * 365> > Years; @@ -225,7 +225,7 @@ struct time_util : time_util_base<FileTimeT, TimeT> { public: template <class CType, class ChronoType> - static _LIBCPP_CONSTEXPR_SINCE_CXX14 bool checked_set(CType* out, + static constexpr bool checked_set(CType* out, ChronoType time) { using Lim = numeric_limits<CType>; if (time > Lim::max() || time < Lim::min()) @@ -234,7 +234,7 @@ public: return true; } - static _LIBCPP_CONSTEXPR_SINCE_CXX14 bool is_representable(TimeSpecT tm) { + static constexpr bool is_representable(TimeSpecT tm) { if (tm.tv_sec >= 0) { return tm.tv_sec < max_seconds || (tm.tv_sec == max_seconds && tm.tv_nsec <= max_nsec); @@ -245,7 +245,7 @@ public: } } - static _LIBCPP_CONSTEXPR_SINCE_CXX14 bool is_representable(FileTimeT tm) { + static constexpr bool is_representable(FileTimeT tm) { auto secs = duration_cast<fs_seconds>(tm.time_since_epoch()); auto nsecs = duration_cast<fs_nanoseconds>(tm.time_since_epoch() - secs); if (nsecs.count() < 0) { @@ -258,7 +258,7 @@ public: return secs.count() >= TLim::min(); } - static _LIBCPP_CONSTEXPR_SINCE_CXX14 FileTimeT + static constexpr FileTimeT convert_from_timespec(TimeSpecT tm) { if (tm.tv_sec >= 0 || tm.tv_nsec == 0) { return FileTimeT(fs_seconds(tm.tv_sec) + @@ -272,7 +272,7 @@ public: } template <class SubSecT> - static _LIBCPP_CONSTEXPR_SINCE_CXX14 bool + static constexpr bool set_times_checked(TimeT* sec_out, SubSecT* subsec_out, FileTimeT tp) { auto dur = tp.time_since_epoch(); auto sec_dur = duration_cast<fs_seconds>(dur); @@ -289,7 +289,7 @@ public: return checked_set(sec_out, sec_dur.count()) && checked_set(subsec_out, subsec_dur.count()); } - static _LIBCPP_CONSTEXPR_SINCE_CXX14 bool convert_to_timespec(TimeSpecT& dest, + static constexpr bool convert_to_timespec(TimeSpecT& dest, FileTimeT tp) { if (!is_representable(tp)) return false; diff --git a/contrib/libs/cxxsupp/libcxx/src/future.cpp b/contrib/libs/cxxsupp/libcxx/src/future.cpp index f8f466bd5a..3383b506a2 100644 --- a/contrib/libs/cxxsupp/libcxx/src/future.cpp +++ b/contrib/libs/cxxsupp/libcxx/src/future.cpp @@ -59,8 +59,13 @@ _LIBCPP_DIAGNOSTIC_POP const error_category& future_category() noexcept { - static __future_error_category __f; - return __f; + union AvoidDestroyingFutureCategory { + __future_error_category future_error_category; + constexpr explicit AvoidDestroyingFutureCategory() : future_error_category() {} + ~AvoidDestroyingFutureCategory() {} + }; + constinit static AvoidDestroyingFutureCategory helper; + return helper.future_error_category; } future_error::future_error(error_code __ec) @@ -199,9 +204,7 @@ promise<void>::~promise() { #ifndef _LIBCPP_HAS_NO_EXCEPTIONS if (!__state_->__has_value() && __state_->use_count() > 1) - __state_->set_exception(make_exception_ptr( - future_error(make_error_code(future_errc::broken_promise)) - )); + __state_->set_exception(make_exception_ptr(future_error(future_errc::broken_promise))); #endif // _LIBCPP_HAS_NO_EXCEPTIONS __state_->__release_shared(); } diff --git a/contrib/libs/cxxsupp/libcxx/src/ios.cpp b/contrib/libs/cxxsupp/libcxx/src/ios.cpp index bb62eb9948..f17cd6e1db 100644 --- a/contrib/libs/cxxsupp/libcxx/src/ios.cpp +++ b/contrib/libs/cxxsupp/libcxx/src/ios.cpp @@ -52,8 +52,13 @@ __iostream_category::message(int ev) const const error_category& iostream_category() noexcept { - static __iostream_category s; - return s; + union AvoidDestroyingIostreamCategory { + __iostream_category iostream_error_category; + constexpr explicit AvoidDestroyingIostreamCategory() : iostream_error_category() {} + ~AvoidDestroyingIostreamCategory() {} + }; + constinit static AvoidDestroyingIostreamCategory helper; + return helper.iostream_error_category; } // ios_base::failure diff --git a/contrib/libs/cxxsupp/libcxx/src/locale.cpp b/contrib/libs/cxxsupp/libcxx/src/locale.cpp index e274ede995..071edb903a 100644 --- a/contrib/libs/cxxsupp/libcxx/src/locale.cpp +++ b/contrib/libs/cxxsupp/libcxx/src/locale.cpp @@ -7,7 +7,6 @@ //===----------------------------------------------------------------------===// #include <__utility/unreachable.h> -#include <__verbose_abort> #include <algorithm> #include <clocale> #include <codecvt> @@ -38,8 +37,8 @@ # include <langinfo.h> #endif -#include "atomic" #include "include/sso_allocator.h" +#include <mutex> // On Linux, wint_t and wchar_t have different signed-ness, and this causes // lots of noise in the build log, but no bugs that I know of. @@ -95,7 +94,7 @@ T& make(Args ...args) template <typename T, size_t N> inline -_LIBCPP_CONSTEXPR +constexpr size_t countof(const T (&)[N]) { @@ -104,22 +103,13 @@ countof(const T (&)[N]) template <typename T> inline -_LIBCPP_CONSTEXPR +constexpr size_t countof(const T * const begin, const T * const end) { return static_cast<size_t>(end - begin); } -_LIBCPP_NORETURN static void __throw_runtime_error(const string &msg) -{ -#ifndef _LIBCPP_HAS_NO_EXCEPTIONS - throw runtime_error(msg); -#else - _LIBCPP_VERBOSE_ABORT("runtime_error was thrown in -fno-exceptions mode with message \"%s\"", msg.c_str()); -#endif -} - } string @@ -698,30 +688,9 @@ locale::facet::__on_zero_shared() noexcept // locale::id -namespace -{ - -class __fake_bind -{ - locale::id* id_; - void (locale::id::* pmf_)(); -public: - __fake_bind(void (locale::id::* pmf)(), locale::id* id) - : id_(id), pmf_(pmf) {} - - void operator()() const - { - (id_->*pmf_)(); - } -}; - -} - -int32_t locale::id::__next_id; +constinit int32_t locale::id::__next_id = 0; -long -locale::id::__get() -{ +long locale::id::__get() { int32_t result = __id_.load(std::memory_order_acquire); if (result == 0) { static std::mutex m; @@ -742,8 +711,8 @@ collate_byname<char>::collate_byname(const char* n, size_t refs) __l_(newlocale(LC_ALL_MASK, n, 0)) { if (__l_ == 0) - __throw_runtime_error("collate_byname<char>::collate_byname" - " failed to construct for " + string(n)); + __throw_runtime_error(("collate_byname<char>::collate_byname" + " failed to construct for " + string(n)).c_str()); } collate_byname<char>::collate_byname(const string& name, size_t refs) @@ -751,8 +720,8 @@ collate_byname<char>::collate_byname(const string& name, size_t refs) __l_(newlocale(LC_ALL_MASK, name.c_str(), 0)) { if (__l_ == 0) - __throw_runtime_error("collate_byname<char>::collate_byname" - " failed to construct for " + name); + __throw_runtime_error(("collate_byname<char>::collate_byname" + " failed to construct for " + name).c_str()); } collate_byname<char>::~collate_byname() @@ -791,8 +760,8 @@ collate_byname<wchar_t>::collate_byname(const char* n, size_t refs) __l_(newlocale(LC_ALL_MASK, n, 0)) { if (__l_ == 0) - __throw_runtime_error("collate_byname<wchar_t>::collate_byname(size_t refs)" - " failed to construct for " + string(n)); + __throw_runtime_error(("collate_byname<wchar_t>::collate_byname(size_t refs)" + " failed to construct for " + string(n)).c_str()); } collate_byname<wchar_t>::collate_byname(const string& name, size_t refs) @@ -800,8 +769,8 @@ collate_byname<wchar_t>::collate_byname(const string& name, size_t refs) __l_(newlocale(LC_ALL_MASK, name.c_str(), 0)) { if (__l_ == 0) - __throw_runtime_error("collate_byname<wchar_t>::collate_byname(size_t refs)" - " failed to construct for " + name); + __throw_runtime_error(("collate_byname<wchar_t>::collate_byname(size_t refs)" + " failed to construct for " + name).c_str()); } collate_byname<wchar_t>::~collate_byname() @@ -849,7 +818,7 @@ const ctype_base::mask ctype_base::graph; // template <> class ctype<wchar_t>; #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS -locale::id ctype<wchar_t>::id; +constinit locale::id ctype<wchar_t>::id; ctype<wchar_t>::~ctype() { @@ -982,7 +951,7 @@ ctype<wchar_t>::do_narrow(const char_type* low, const char_type* high, char dfau // template <> class ctype<char>; -locale::id ctype<char>::id; +constinit locale::id ctype<char>::id; const size_t ctype<char>::table_size; @@ -1115,7 +1084,7 @@ extern "C" const unsigned short* const _ctype_android; const ctype<char>::mask* ctype<char>::classic_table() noexcept { - static _LIBCPP_CONSTEXPR const ctype<char>::mask builtin_table[table_size] = { + static constexpr const ctype<char>::mask builtin_table[table_size] = { cntrl, cntrl, cntrl, cntrl, cntrl, cntrl, @@ -1294,8 +1263,8 @@ ctype_byname<char>::ctype_byname(const char* name, size_t refs) __l_(newlocale(LC_ALL_MASK, name, 0)) { if (__l_ == 0) - __throw_runtime_error("ctype_byname<char>::ctype_byname" - " failed to construct for " + string(name)); + __throw_runtime_error(("ctype_byname<char>::ctype_byname" + " failed to construct for " + string(name)).c_str()); } ctype_byname<char>::ctype_byname(const string& name, size_t refs) @@ -1303,8 +1272,8 @@ ctype_byname<char>::ctype_byname(const string& name, size_t refs) __l_(newlocale(LC_ALL_MASK, name.c_str(), 0)) { if (__l_ == 0) - __throw_runtime_error("ctype_byname<char>::ctype_byname" - " failed to construct for " + name); + __throw_runtime_error(("ctype_byname<char>::ctype_byname" + " failed to construct for " + name).c_str()); } ctype_byname<char>::~ctype_byname() @@ -1348,8 +1317,8 @@ ctype_byname<wchar_t>::ctype_byname(const char* name, size_t refs) __l_(newlocale(LC_ALL_MASK, name, 0)) { if (__l_ == 0) - __throw_runtime_error("ctype_byname<wchar_t>::ctype_byname" - " failed to construct for " + string(name)); + __throw_runtime_error(("ctype_byname<wchar_t>::ctype_byname" + " failed to construct for " + string(name)).c_str()); } ctype_byname<wchar_t>::ctype_byname(const string& name, size_t refs) @@ -1357,8 +1326,8 @@ ctype_byname<wchar_t>::ctype_byname(const string& name, size_t refs) __l_(newlocale(LC_ALL_MASK, name.c_str(), 0)) { if (__l_ == 0) - __throw_runtime_error("ctype_byname<wchar_t>::ctype_byname" - " failed to construct for " + name); + __throw_runtime_error(("ctype_byname<wchar_t>::ctype_byname" + " failed to construct for " + name).c_str()); } ctype_byname<wchar_t>::~ctype_byname() @@ -1544,7 +1513,7 @@ ctype_byname<wchar_t>::do_narrow(const char_type* low, const char_type* high, ch // template <> class codecvt<char, char, mbstate_t> -locale::id codecvt<char, char, mbstate_t>::id; +constinit locale::id codecvt<char, char, mbstate_t>::id; codecvt<char, char, mbstate_t>::~codecvt() { @@ -1606,7 +1575,7 @@ codecvt<char, char, mbstate_t>::do_max_length() const noexcept // template <> class codecvt<wchar_t, char, mbstate_t> #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS -locale::id codecvt<wchar_t, char, mbstate_t>::id; +constinit locale::id codecvt<wchar_t, char, mbstate_t>::id; codecvt<wchar_t, char, mbstate_t>::codecvt(size_t refs) : locale::facet(refs), @@ -1619,8 +1588,8 @@ codecvt<wchar_t, char, mbstate_t>::codecvt(const char* nm, size_t refs) __l_(newlocale(LC_ALL_MASK, nm, 0)) { if (__l_ == 0) - __throw_runtime_error("codecvt_byname<wchar_t, char, mbstate_t>::codecvt_byname" - " failed to construct for " + string(nm)); + __throw_runtime_error(("codecvt_byname<wchar_t, char, mbstate_t>::codecvt_byname" + " failed to construct for " + string(nm)).c_str()); } codecvt<wchar_t, char, mbstate_t>::~codecvt() @@ -3212,7 +3181,7 @@ _LIBCPP_SUPPRESS_DEPRECATED_POP // template <> class codecvt<char16_t, char, mbstate_t> -locale::id codecvt<char16_t, char, mbstate_t>::id; +constinit locale::id codecvt<char16_t, char, mbstate_t>::id; codecvt<char16_t, char, mbstate_t>::~codecvt() { @@ -3291,7 +3260,7 @@ codecvt<char16_t, char, mbstate_t>::do_max_length() const noexcept // template <> class codecvt<char16_t, char8_t, mbstate_t> -locale::id codecvt<char16_t, char8_t, mbstate_t>::id; +constinit locale::id codecvt<char16_t, char8_t, mbstate_t>::id; codecvt<char16_t, char8_t, mbstate_t>::~codecvt() { @@ -3370,7 +3339,7 @@ codecvt<char16_t, char8_t, mbstate_t>::do_max_length() const noexcept // template <> class codecvt<char32_t, char, mbstate_t> -locale::id codecvt<char32_t, char, mbstate_t>::id; +constinit locale::id codecvt<char32_t, char, mbstate_t>::id; codecvt<char32_t, char, mbstate_t>::~codecvt() { @@ -3449,7 +3418,7 @@ codecvt<char32_t, char, mbstate_t>::do_max_length() const noexcept // template <> class codecvt<char32_t, char8_t, mbstate_t> -locale::id codecvt<char32_t, char8_t, mbstate_t>::id; +constinit locale::id codecvt<char32_t, char8_t, mbstate_t>::id; codecvt<char32_t, char8_t, mbstate_t>::~codecvt() { @@ -4665,9 +4634,9 @@ static bool checked_string_to_char_convert(char& dest, // numpunct<char> && numpunct<wchar_t> -locale::id numpunct< char >::id; +constinit locale::id numpunct<char>::id; #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS -locale::id numpunct<wchar_t>::id; +constinit locale::id numpunct<wchar_t>::id; #endif numpunct<char>::numpunct(size_t refs) @@ -4747,8 +4716,8 @@ numpunct_byname<char>::__init(const char* nm) { __libcpp_unique_locale loc(nm); if (!loc) - __throw_runtime_error("numpunct_byname<char>::numpunct_byname" - " failed to construct for " + string(nm)); + __throw_runtime_error(("numpunct_byname<char>::numpunct_byname" + " failed to construct for " + string(nm)).c_str()); lconv* lc = __libcpp_localeconv_l(loc.get()); if (!checked_string_to_char_convert(__decimal_point_, lc->decimal_point, @@ -4788,8 +4757,8 @@ numpunct_byname<wchar_t>::__init(const char* nm) { __libcpp_unique_locale loc(nm); if (!loc) - __throw_runtime_error("numpunct_byname<wchar_t>::numpunct_byname" - " failed to construct for " + string(nm)); + __throw_runtime_error(("numpunct_byname<wchar_t>::numpunct_byname" + " failed to construct for " + string(nm)).c_str()); lconv* lc = __libcpp_localeconv_l(loc.get()); checked_string_to_wchar_convert(__decimal_point_, lc->decimal_point, @@ -5220,16 +5189,14 @@ __time_get::__time_get(const char* nm) : __loc_(newlocale(LC_ALL_MASK, nm, 0)) { if (__loc_ == 0) - __throw_runtime_error("time_get_byname" - " failed to construct for " + string(nm)); + __throw_runtime_error(("time_get_byname failed to construct for " + string(nm)).c_str()); } __time_get::__time_get(const string& nm) : __loc_(newlocale(LC_ALL_MASK, nm.c_str(), 0)) { if (__loc_ == 0) - __throw_runtime_error("time_get_byname" - " failed to construct for " + nm); + __throw_runtime_error(("time_get_byname failed to construct for " + nm).c_str()); } __time_get::~__time_get() @@ -5878,16 +5845,14 @@ __time_put::__time_put(const char* nm) : __loc_(newlocale(LC_ALL_MASK, nm, 0)) { if (__loc_ == 0) - __throw_runtime_error("time_put_byname" - " failed to construct for " + string(nm)); + __throw_runtime_error(("time_put_byname failed to construct for " + string(nm)).c_str()); } __time_put::__time_put(const string& nm) : __loc_(newlocale(LC_ALL_MASK, nm.c_str(), 0)) { if (__loc_ == 0) - __throw_runtime_error("time_put_byname" - " failed to construct for " + nm); + __throw_runtime_error(("time_put_byname failed to construct for " + nm).c_str()); } __time_put::~__time_put() @@ -6305,8 +6270,7 @@ moneypunct_byname<char, false>::init(const char* nm) typedef moneypunct<char, false> base; __libcpp_unique_locale loc(nm); if (!loc) - __throw_runtime_error("moneypunct_byname" - " failed to construct for " + string(nm)); + __throw_runtime_error(("moneypunct_byname failed to construct for " + string(nm)).c_str()); lconv* lc = __libcpp_localeconv_l(loc.get()); if (!checked_string_to_char_convert(__decimal_point_, @@ -6349,8 +6313,7 @@ moneypunct_byname<char, true>::init(const char* nm) typedef moneypunct<char, true> base; __libcpp_unique_locale loc(nm); if (!loc) - __throw_runtime_error("moneypunct_byname" - " failed to construct for " + string(nm)); + __throw_runtime_error(("moneypunct_byname failed to construct for " + string(nm)).c_str()); lconv* lc = __libcpp_localeconv_l(loc.get()); if (!checked_string_to_char_convert(__decimal_point_, @@ -6410,8 +6373,7 @@ moneypunct_byname<wchar_t, false>::init(const char* nm) typedef moneypunct<wchar_t, false> base; __libcpp_unique_locale loc(nm); if (!loc) - __throw_runtime_error("moneypunct_byname" - " failed to construct for " + string(nm)); + __throw_runtime_error(("moneypunct_byname failed to construct for " + string(nm)).c_str()); lconv* lc = __libcpp_localeconv_l(loc.get()); if (!checked_string_to_wchar_convert(__decimal_point_, lc->mon_decimal_point, @@ -6475,8 +6437,7 @@ moneypunct_byname<wchar_t, true>::init(const char* nm) typedef moneypunct<wchar_t, true> base; __libcpp_unique_locale loc(nm); if (!loc) - __throw_runtime_error("moneypunct_byname" - " failed to construct for " + string(nm)); + __throw_runtime_error(("moneypunct_byname failed to construct for " + string(nm)).c_str()); lconv* lc = __libcpp_localeconv_l(loc.get()); if (!checked_string_to_wchar_convert(__decimal_point_, @@ -6554,15 +6515,6 @@ moneypunct_byname<wchar_t, true>::init(const char* nm) void __do_nothing(void*) {} -void __throw_runtime_error(const char* msg) -{ -#ifndef _LIBCPP_HAS_NO_EXCEPTIONS - throw runtime_error(msg); -#else - _LIBCPP_VERBOSE_ABORT("runtime_error was thrown in -fno-exceptions mode with message \"%s\"", msg); -#endif -} - template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS collate<char>; _LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS collate<wchar_t>;) diff --git a/contrib/libs/cxxsupp/libcxx/src/memory.cpp b/contrib/libs/cxxsupp/libcxx/src/memory.cpp index 4682f1267a..e318eee327 100644 --- a/contrib/libs/cxxsupp/libcxx/src/memory.cpp +++ b/contrib/libs/cxxsupp/libcxx/src/memory.cpp @@ -181,7 +181,7 @@ static constinit __libcpp_mutex_t mut_back[__sp_mut_count] = _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER }; -_LIBCPP_CONSTEXPR __sp_mut::__sp_mut(void* p) noexcept +constexpr __sp_mut::__sp_mut(void* p) noexcept : __lx_(p) { } diff --git a/contrib/libs/cxxsupp/libcxx/src/memory_resource.cpp b/contrib/libs/cxxsupp/libcxx/src/memory_resource.cpp index 3a80b84efa..3786ec5136 100644 --- a/contrib/libs/cxxsupp/libcxx/src/memory_resource.cpp +++ b/contrib/libs/cxxsupp/libcxx/src/memory_resource.cpp @@ -74,7 +74,7 @@ union ResourceInitHelper { __null_memory_resource_imp null_res; } resources; char dummy; - _LIBCPP_CONSTEXPR_SINCE_CXX14 ResourceInitHelper() : resources() {} + constexpr ResourceInitHelper() : resources() {} ~ResourceInitHelper() {} }; diff --git a/contrib/libs/cxxsupp/libcxx/src/mutex.cpp b/contrib/libs/cxxsupp/libcxx/src/mutex.cpp index e304b97e6e..e8637f9275 100644 --- a/contrib/libs/cxxsupp/libcxx/src/mutex.cpp +++ b/contrib/libs/cxxsupp/libcxx/src/mutex.cpp @@ -8,6 +8,7 @@ #include <__assert> #include <__thread/id.h> +#include <__utility/exception_guard.h> #include <limits> #include <mutex> @@ -212,68 +213,52 @@ void __call_once(volatile once_flag::_State_type& flag, void* arg, #endif { #if defined(_LIBCPP_HAS_NO_THREADS) - if (flag == 0) - { -#ifndef _LIBCPP_HAS_NO_EXCEPTIONS - try - { -#endif // _LIBCPP_HAS_NO_EXCEPTIONS - flag = 1; - func(arg); - flag = ~once_flag::_State_type(0); -#ifndef _LIBCPP_HAS_NO_EXCEPTIONS - } - catch (...) - { - flag = 0; - throw; - } -#endif // _LIBCPP_HAS_NO_EXCEPTIONS + + if (flag == once_flag::_Unset) { + auto guard = std::__make_exception_guard([&flag] { flag = once_flag::_Unset; }); + flag = once_flag::_Pending; + func(arg); + flag = once_flag::_Complete; + guard.__complete(); } + #else // !_LIBCPP_HAS_NO_THREADS + __libcpp_mutex_lock(&mut); - while (flag == 1) + while (flag == once_flag::_Pending) __libcpp_condvar_wait(&cv, &mut); - if (flag == 0) - { -#ifndef _LIBCPP_HAS_NO_EXCEPTIONS - try - { -#endif // _LIBCPP_HAS_NO_EXCEPTIONS + if (flag == once_flag::_Unset) { + auto guard = std::__make_exception_guard([&flag] { + __libcpp_mutex_lock(&mut); #ifdef _LIBCPP_ABI_MICROSOFT - flag.store(once_flag::_State_type(1)); + flag.store(once_flag::_Unset); #else - __libcpp_relaxed_store(&flag, once_flag::_State_type(1)); + __libcpp_relaxed_store(&flag, once_flag::_Unset); #endif __libcpp_mutex_unlock(&mut); - func(arg); - __libcpp_mutex_lock(&mut); + __libcpp_condvar_broadcast(&cv); + }); + #ifdef _LIBCPP_ABI_MICROSOFT - flag.store(~once_flag::_State_type(0), memory_order_release); + flag.store(once_flag::_Pending, memory_order_relaxed); #else - __libcpp_atomic_store(&flag, ~once_flag::_State_type(0), - _AO_Release); + __libcpp_relaxed_store(&flag, once_flag::_Pending); #endif - __libcpp_mutex_unlock(&mut); - __libcpp_condvar_broadcast(&cv); -#ifndef _LIBCPP_HAS_NO_EXCEPTIONS - } - catch (...) - { - __libcpp_mutex_lock(&mut); + __libcpp_mutex_unlock(&mut); + func(arg); + __libcpp_mutex_lock(&mut); #ifdef _LIBCPP_ABI_MICROSOFT - flag.store(once_flag::_State_type(0), memory_order_relaxed); + flag.store(once_flag::_Complete, memory_order_release); #else - __libcpp_relaxed_store(&flag, once_flag::_State_type(0)); + __libcpp_atomic_store(&flag, once_flag::_Complete, _AO_Release); #endif - __libcpp_mutex_unlock(&mut); - __libcpp_condvar_broadcast(&cv); - throw; - } -#endif // _LIBCPP_HAS_NO_EXCEPTIONS - } - else __libcpp_mutex_unlock(&mut); + __libcpp_condvar_broadcast(&cv); + guard.__complete(); + } else { + __libcpp_mutex_unlock(&mut); + } + #endif // !_LIBCPP_HAS_NO_THREADS } diff --git a/contrib/libs/cxxsupp/libcxx/src/new_helpers.cpp b/contrib/libs/cxxsupp/libcxx/src/new_helpers.cpp index 45a0a661db..6560d0188e 100644 --- a/contrib/libs/cxxsupp/libcxx/src/new_helpers.cpp +++ b/contrib/libs/cxxsupp/libcxx/src/new_helpers.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include <cstdlib> +#include <__verbose_abort> #include <new> namespace std { // purposefully not versioned @@ -21,7 +21,7 @@ void __throw_bad_alloc() { # ifndef _LIBCPP_HAS_NO_EXCEPTIONS throw bad_alloc(); # else - std::abort(); + _LIBCPP_VERBOSE_ABORT("bad_alloc was thrown in -fno-exceptions mode"); # endif } diff --git a/contrib/libs/cxxsupp/libcxx/src/print.cpp b/contrib/libs/cxxsupp/libcxx/src/print.cpp index 3d8a4c291e..a581dd37fe 100644 --- a/contrib/libs/cxxsupp/libcxx/src/print.cpp +++ b/contrib/libs/cxxsupp/libcxx/src/print.cpp @@ -47,12 +47,7 @@ __write_to_windows_console([[maybe_unused]] FILE* __stream, [[maybe_unused]] wst __view.size(), nullptr, nullptr) == 0) { -# ifndef _LIBCPP_HAS_NO_EXCEPTIONS - // There is no __throw_system_error overload that takes an error code. - throw system_error{filesystem::detail::make_windows_error(GetLastError()), "failed to write formatted output"}; -# else // _LIBCPP_HAS_NO_EXCEPTIONS - std::abort(); -# endif // _LIBCPP_HAS_NO_EXCEPTIONS + __throw_system_error(filesystem::detail::make_windows_error(GetLastError()), "failed to write formatted output"); } } # endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS diff --git a/contrib/libs/cxxsupp/libcxx/src/std_stream.h b/contrib/libs/cxxsupp/libcxx/src/std_stream.h index 0febf42c9f..37b4ffd1b4 100644 --- a/contrib/libs/cxxsupp/libcxx/src/std_stream.h +++ b/contrib/libs/cxxsupp/libcxx/src/std_stream.h @@ -113,7 +113,7 @@ __stdinbuf<_CharT>::uflow() return __getchar(true); } -static bool __do_getc(FILE *__fp, char *__pbuf) { +inline bool __do_getc(FILE *__fp, char *__pbuf) { int __c = getc(__fp); if (__c == EOF) return false; @@ -121,7 +121,7 @@ static bool __do_getc(FILE *__fp, char *__pbuf) { return true; } #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS -static bool __do_getc(FILE *__fp, wchar_t *__pbuf) { +inline bool __do_getc(FILE *__fp, wchar_t *__pbuf) { wint_t __c = getwc(__fp); if (__c == WEOF) return false; @@ -130,13 +130,13 @@ static bool __do_getc(FILE *__fp, wchar_t *__pbuf) { } #endif -static bool __do_ungetc(int __c, FILE *__fp, char __dummy) { +inline bool __do_ungetc(int __c, FILE *__fp, char __dummy) { if (ungetc(__c, __fp) == EOF) return false; return true; } #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS -static bool __do_ungetc(std::wint_t __c, FILE *__fp, wchar_t __dummy) { +inline bool __do_ungetc(std::wint_t __c, FILE *__fp, wchar_t __dummy) { if (ungetwc(__c, __fp) == WEOF) return false; return true; @@ -324,13 +324,13 @@ __stdoutbuf<_CharT>::__stdoutbuf(FILE* __fp, state_type* __st) __always_noconv_ = true; } -static bool __do_fputc(char __c, FILE* __fp) { +inline bool __do_fputc(char __c, FILE* __fp) { if (fwrite(&__c, sizeof(__c), 1, __fp) != 1) return false; return true; } #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS -static bool __do_fputc(wchar_t __c, FILE* __fp) { +inline bool __do_fputc(wchar_t __c, FILE* __fp) { // fputwc works regardless of wide/narrow mode of stdout, while // fwrite of wchar_t only works if the stream actually has been set // into wide mode. diff --git a/contrib/libs/cxxsupp/libcxx/src/stdexcept.cpp b/contrib/libs/cxxsupp/libcxx/src/stdexcept.cpp index d5c9173576..bc25c0f9e6 100644 --- a/contrib/libs/cxxsupp/libcxx/src/stdexcept.cpp +++ b/contrib/libs/cxxsupp/libcxx/src/stdexcept.cpp @@ -6,12 +6,25 @@ // //===----------------------------------------------------------------------===// +#include <__verbose_abort> #include <new> #include <stdexcept> #include <string> #ifdef _LIBCPP_ABI_VCRUNTIME -#include "support/runtime/stdexcept_vcruntime.ipp" +# include "support/runtime/stdexcept_vcruntime.ipp" #else -#include "support/runtime/stdexcept_default.ipp" +# include "support/runtime/stdexcept_default.ipp" #endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +_LIBCPP_NORETURN void __throw_runtime_error(const char* msg) { +#ifndef _LIBCPP_HAS_NO_EXCEPTIONS + throw runtime_error(msg); +#else + _LIBCPP_VERBOSE_ABORT("runtime_error was thrown in -fno-exceptions mode with message \"%s\"", msg); +#endif +} + +_LIBCPP_END_NAMESPACE_STD diff --git a/contrib/libs/cxxsupp/libcxx/src/strstream.cpp b/contrib/libs/cxxsupp/libcxx/src/strstream.cpp index bc56cafa8f..c97db698c0 100644 --- a/contrib/libs/cxxsupp/libcxx/src/strstream.cpp +++ b/contrib/libs/cxxsupp/libcxx/src/strstream.cpp @@ -20,321 +20,239 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD strstreambuf::strstreambuf(streamsize __alsize) - : __strmode_(__dynamic), - __alsize_(__alsize), - __palloc_(nullptr), - __pfree_(nullptr) -{ -} + : __strmode_(__dynamic), __alsize_(__alsize), __palloc_(nullptr), __pfree_(nullptr) {} strstreambuf::strstreambuf(void* (*__palloc)(size_t), void (*__pfree)(void*)) - : __strmode_(__dynamic), - __alsize_(__default_alsize), - __palloc_(__palloc), - __pfree_(__pfree) -{ -} + : __strmode_(__dynamic), __alsize_(__default_alsize), __palloc_(__palloc), __pfree_(__pfree) {} -void -strstreambuf::__init(char* __gnext, streamsize __n, char* __pbeg) -{ - if (__n == 0) - __n = static_cast<streamsize>(strlen(__gnext)); - else if (__n < 0) - __n = INT_MAX; - if (__pbeg == nullptr) - setg(__gnext, __gnext, __gnext + __n); - else - { - setg(__gnext, __gnext, __pbeg); - setp(__pbeg, __pbeg + __n); - } +void strstreambuf::__init(char* __gnext, streamsize __n, char* __pbeg) { + if (__n == 0) + __n = static_cast<streamsize>(strlen(__gnext)); + else if (__n < 0) + __n = INT_MAX; + if (__pbeg == nullptr) + setg(__gnext, __gnext, __gnext + __n); + else { + setg(__gnext, __gnext, __pbeg); + setp(__pbeg, __pbeg + __n); + } } strstreambuf::strstreambuf(char* __gnext, streamsize __n, char* __pbeg) - : __strmode_(), - __alsize_(__default_alsize), - __palloc_(nullptr), - __pfree_(nullptr) -{ - __init(__gnext, __n, __pbeg); + : __strmode_(), __alsize_(__default_alsize), __palloc_(nullptr), __pfree_(nullptr) { + __init(__gnext, __n, __pbeg); } strstreambuf::strstreambuf(const char* __gnext, streamsize __n) - : __strmode_(__constant), - __alsize_(__default_alsize), - __palloc_(nullptr), - __pfree_(nullptr) -{ - __init(const_cast<char *>(__gnext), __n, nullptr); + : __strmode_(__constant), __alsize_(__default_alsize), __palloc_(nullptr), __pfree_(nullptr) { + __init(const_cast<char*>(__gnext), __n, nullptr); } strstreambuf::strstreambuf(signed char* __gnext, streamsize __n, signed char* __pbeg) - : __strmode_(), - __alsize_(__default_alsize), - __palloc_(nullptr), - __pfree_(nullptr) -{ - __init(const_cast<char *>(reinterpret_cast<const char*>(__gnext)), __n, reinterpret_cast<char*>(__pbeg)); + : __strmode_(), __alsize_(__default_alsize), __palloc_(nullptr), __pfree_(nullptr) { + __init(const_cast<char*>(reinterpret_cast<const char*>(__gnext)), __n, reinterpret_cast<char*>(__pbeg)); } strstreambuf::strstreambuf(const signed char* __gnext, streamsize __n) - : __strmode_(__constant), - __alsize_(__default_alsize), - __palloc_(nullptr), - __pfree_(nullptr) -{ - __init(const_cast<char *>(reinterpret_cast<const char*>(__gnext)), __n, nullptr); + : __strmode_(__constant), __alsize_(__default_alsize), __palloc_(nullptr), __pfree_(nullptr) { + __init(const_cast<char*>(reinterpret_cast<const char*>(__gnext)), __n, nullptr); } strstreambuf::strstreambuf(unsigned char* __gnext, streamsize __n, unsigned char* __pbeg) - : __strmode_(), - __alsize_(__default_alsize), - __palloc_(nullptr), - __pfree_(nullptr) -{ - __init(const_cast<char *>(reinterpret_cast<const char*>(__gnext)), __n, reinterpret_cast<char*>(__pbeg)); + : __strmode_(), __alsize_(__default_alsize), __palloc_(nullptr), __pfree_(nullptr) { + __init(const_cast<char*>(reinterpret_cast<const char*>(__gnext)), __n, reinterpret_cast<char*>(__pbeg)); } strstreambuf::strstreambuf(const unsigned char* __gnext, streamsize __n) - : __strmode_(__constant), - __alsize_(__default_alsize), - __palloc_(nullptr), - __pfree_(nullptr) -{ - __init(const_cast<char *>(reinterpret_cast<const char*>(__gnext)), __n, nullptr); -} - -strstreambuf::~strstreambuf() -{ - if (eback() && (__strmode_ & __allocated) != 0 && (__strmode_ & __frozen) == 0) - { - if (__pfree_) - __pfree_(eback()); - else - delete [] eback(); - } + : __strmode_(__constant), __alsize_(__default_alsize), __palloc_(nullptr), __pfree_(nullptr) { + __init(const_cast<char*>(reinterpret_cast<const char*>(__gnext)), __n, nullptr); } -void -strstreambuf::swap(strstreambuf& __rhs) -{ - streambuf::swap(__rhs); - _VSTD::swap(__strmode_, __rhs.__strmode_); - _VSTD::swap(__alsize_, __rhs.__alsize_); - _VSTD::swap(__palloc_, __rhs.__palloc_); - _VSTD::swap(__pfree_, __rhs.__pfree_); +strstreambuf::~strstreambuf() { + if (eback() && (__strmode_ & __allocated) != 0 && (__strmode_ & __frozen) == 0) { + if (__pfree_) + __pfree_(eback()); + else + delete[] eback(); + } } -void -strstreambuf::freeze(bool __freezefl) -{ - if (__strmode_ & __dynamic) - { - if (__freezefl) - __strmode_ |= __frozen; - else - __strmode_ &= ~__frozen; - } +void strstreambuf::swap(strstreambuf& __rhs) { + streambuf::swap(__rhs); + _VSTD::swap(__strmode_, __rhs.__strmode_); + _VSTD::swap(__alsize_, __rhs.__alsize_); + _VSTD::swap(__palloc_, __rhs.__palloc_); + _VSTD::swap(__pfree_, __rhs.__pfree_); } -char* -strstreambuf::str() -{ - if (__strmode_ & __dynamic) - __strmode_ |= __frozen; - return eback(); +void strstreambuf::freeze(bool __freezefl) { + if (__strmode_ & __dynamic) { + if (__freezefl) + __strmode_ |= __frozen; + else + __strmode_ &= ~__frozen; + } } -int -strstreambuf::pcount() const -{ - return static_cast<int>(pptr() - pbase()); +char* strstreambuf::str() { + if (__strmode_ & __dynamic) + __strmode_ |= __frozen; + return eback(); } -strstreambuf::int_type -strstreambuf::overflow(int_type __c) -{ - if (__c == EOF) - return int_type(0); - if (pptr() == epptr()) - { - if ((__strmode_ & __dynamic) == 0 || (__strmode_ & __frozen) != 0) - return int_type(EOF); - size_t old_size = static_cast<size_t> ((epptr() ? epptr() : egptr()) - eback()); - size_t new_size = max<size_t>(static_cast<size_t>(__alsize_), 2*old_size); - if (new_size == 0) - new_size = __default_alsize; - char* buf = nullptr; - if (__palloc_) - buf = static_cast<char*>(__palloc_(new_size)); - else - buf = new char[new_size]; - if (buf == nullptr) - return int_type(EOF); - if (old_size != 0) { - _LIBCPP_ASSERT_UNCATEGORIZED(eback(), "overflow copying from NULL"); - memcpy(buf, eback(), static_cast<size_t>(old_size)); - } - ptrdiff_t ninp = gptr() - eback(); - ptrdiff_t einp = egptr() - eback(); - ptrdiff_t nout = pptr() - pbase(); - if (__strmode_ & __allocated) - { - if (__pfree_) - __pfree_(eback()); - else - delete [] eback(); - } - setg(buf, buf + ninp, buf + einp); - setp(buf + einp, buf + new_size); - __pbump(nout); - __strmode_ |= __allocated; - } - *pptr() = static_cast<char>(__c); - pbump(1); - return int_type(static_cast<unsigned char>(__c)); -} +int strstreambuf::pcount() const { return static_cast<int>(pptr() - pbase()); } -strstreambuf::int_type -strstreambuf::pbackfail(int_type __c) -{ - if (eback() == gptr()) - return EOF; - if (__c == EOF) - { - gbump(-1); - return int_type(0); +strstreambuf::int_type strstreambuf::overflow(int_type __c) { + if (__c == EOF) + return int_type(0); + if (pptr() == epptr()) { + if ((__strmode_ & __dynamic) == 0 || (__strmode_ & __frozen) != 0) + return int_type(EOF); + size_t old_size = static_cast<size_t>((epptr() ? epptr() : egptr()) - eback()); + size_t new_size = max<size_t>(static_cast<size_t>(__alsize_), 2 * old_size); + if (new_size == 0) + new_size = __default_alsize; + char* buf = nullptr; + if (__palloc_) + buf = static_cast<char*>(__palloc_(new_size)); + else + buf = new char[new_size]; + if (buf == nullptr) + return int_type(EOF); + if (old_size != 0) { + _LIBCPP_ASSERT_UNCATEGORIZED(eback(), "overflow copying from NULL"); + memcpy(buf, eback(), static_cast<size_t>(old_size)); } - if (__strmode_ & __constant) - { - if (gptr()[-1] == static_cast<char>(__c)) - { - gbump(-1); - return __c; - } - return EOF; + ptrdiff_t ninp = gptr() - eback(); + ptrdiff_t einp = egptr() - eback(); + ptrdiff_t nout = pptr() - pbase(); + if (__strmode_ & __allocated) { + if (__pfree_) + __pfree_(eback()); + else + delete[] eback(); } - gbump(-1); - *gptr() = static_cast<char>(__c); - return __c; + setg(buf, buf + ninp, buf + einp); + setp(buf + einp, buf + new_size); + __pbump(nout); + __strmode_ |= __allocated; + } + *pptr() = static_cast<char>(__c); + pbump(1); + return int_type(static_cast<unsigned char>(__c)); } -strstreambuf::int_type -strstreambuf::underflow() -{ - if (gptr() == egptr()) - { - if (egptr() >= pptr()) - return EOF; - setg(eback(), gptr(), pptr()); +strstreambuf::int_type strstreambuf::pbackfail(int_type __c) { + if (eback() == gptr()) + return EOF; + if (__c == EOF) { + gbump(-1); + return int_type(0); + } + if (__strmode_ & __constant) { + if (gptr()[-1] == static_cast<char>(__c)) { + gbump(-1); + return __c; } - return int_type(static_cast<unsigned char>(*gptr())); + return EOF; + } + gbump(-1); + *gptr() = static_cast<char>(__c); + return __c; } -strstreambuf::pos_type -strstreambuf::seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __which) -{ - off_type __p(-1); - bool pos_in = (__which & ios::in) != 0; - bool pos_out = (__which & ios::out) != 0; - bool legal = false; - switch (__way) - { - case ios::beg: - case ios::end: - if (pos_in || pos_out) - legal = true; - break; - case ios::cur: - if (pos_in != pos_out) - legal = true; - break; - } - if (pos_in && gptr() == nullptr) - legal = false; - if (pos_out && pptr() == nullptr) - legal = false; - if (legal) - { - off_type newoff; - char* seekhigh = epptr() ? epptr() : egptr(); - switch (__way) - { - case ios::beg: - newoff = 0; - break; - case ios::cur: - newoff = (pos_in ? gptr() : pptr()) - eback(); - break; - case ios::end: - newoff = seekhigh - eback(); - break; - default: - __libcpp_unreachable(); - } - newoff += __off; - if (0 <= newoff && newoff <= seekhigh - eback()) - { - char* newpos = eback() + newoff; - if (pos_in) - setg(eback(), newpos, _VSTD::max(newpos, egptr())); - if (pos_out) - { - // min(pbase, newpos), newpos, epptr() - __off = epptr() - newpos; - setp(min(pbase(), newpos), epptr()); - __pbump((epptr() - pbase()) - __off); - } - __p = newoff; - } - } - return pos_type(__p); +strstreambuf::int_type strstreambuf::underflow() { + if (gptr() == egptr()) { + if (egptr() >= pptr()) + return EOF; + setg(eback(), gptr(), pptr()); + } + return int_type(static_cast<unsigned char>(*gptr())); } -strstreambuf::pos_type -strstreambuf::seekpos(pos_type __sp, ios_base::openmode __which) -{ - off_type __p(-1); - bool pos_in = (__which & ios::in) != 0; - bool pos_out = (__which & ios::out) != 0; - if (pos_in || pos_out) - { - if (!((pos_in && gptr() == nullptr) || (pos_out && pptr() == nullptr))) - { - off_type newoff = __sp; - char* seekhigh = epptr() ? epptr() : egptr(); - if (0 <= newoff && newoff <= seekhigh - eback()) - { - char* newpos = eback() + newoff; - if (pos_in) - setg(eback(), newpos, _VSTD::max(newpos, egptr())); - if (pos_out) - { - // min(pbase, newpos), newpos, epptr() - off_type temp = epptr() - newpos; - setp(min(pbase(), newpos), epptr()); - __pbump((epptr() - pbase()) - temp); - } - __p = newoff; - } - } - } - return pos_type(__p); -} +strstreambuf::pos_type strstreambuf::seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __which) { + bool pos_in = (__which & ios::in) != 0; + bool pos_out = (__which & ios::out) != 0; + switch (__way) { + case ios::beg: + case ios::end: + if (!pos_in && !pos_out) + return pos_type(off_type(-1)); + break; + case ios::cur: + if (pos_in == pos_out) + return pos_type(off_type(-1)); + break; + } -istrstream::~istrstream() -{ -} + if (pos_in && gptr() == nullptr) + return pos_type(off_type(-1)); + if (pos_out && pptr() == nullptr) + return pos_type(off_type(-1)); + + off_type newoff; + char* seekhigh = epptr() ? epptr() : egptr(); + switch (__way) { + case ios::beg: + newoff = 0; + break; + case ios::cur: + newoff = (pos_in ? gptr() : pptr()) - eback(); + break; + case ios::end: + newoff = seekhigh - eback(); + break; + default: + __libcpp_unreachable(); + } + newoff += __off; + if (newoff < 0 || newoff > seekhigh - eback()) + return pos_type(off_type(-1)); -ostrstream::~ostrstream() -{ + char* newpos = eback() + newoff; + if (pos_in) + setg(eback(), newpos, _VSTD::max(newpos, egptr())); + if (pos_out) { + // min(pbase, newpos), newpos, epptr() + __off = epptr() - newpos; + setp(min(pbase(), newpos), epptr()); + __pbump((epptr() - pbase()) - __off); + } + return pos_type(newoff); } -strstream::~strstream() -{ +strstreambuf::pos_type strstreambuf::seekpos(pos_type __sp, ios_base::openmode __which) { + bool pos_in = (__which & ios::in) != 0; + bool pos_out = (__which & ios::out) != 0; + if (!pos_in && !pos_out) + return pos_type(off_type(-1)); + + if ((pos_in && gptr() == nullptr) || (pos_out && pptr() == nullptr)) + return pos_type(off_type(-1)); + + off_type newoff = __sp; + char* seekhigh = epptr() ? epptr() : egptr(); + if (newoff < 0 || newoff > seekhigh - eback()) + return pos_type(off_type(-1)); + + char* newpos = eback() + newoff; + if (pos_in) + setg(eback(), newpos, _VSTD::max(newpos, egptr())); + if (pos_out) { + // min(pbase, newpos), newpos, epptr() + off_type temp = epptr() - newpos; + setp(min(pbase(), newpos), epptr()); + __pbump((epptr() - pbase()) - temp); + } + return pos_type(newoff); } +istrstream::~istrstream() {} + +ostrstream::~ostrstream() {} + +strstream::~strstream() {} + _LIBCPP_END_NAMESPACE_STD _LIBCPP_POP_MACROS diff --git a/contrib/libs/cxxsupp/libcxx/src/support/win32/locale_win32.cpp b/contrib/libs/cxxsupp/libcxx/src/support/win32/locale_win32.cpp index 2543686c90..c9d1d63b25 100644 --- a/contrib/libs/cxxsupp/libcxx/src/support/win32/locale_win32.cpp +++ b/contrib/libs/cxxsupp/libcxx/src/support/win32/locale_win32.cpp @@ -17,8 +17,8 @@ int __libcpp_vasprintf(char **sptr, const char *__restrict fmt, va_list ap); using std::__libcpp_locale_guard; -// FIXME: base currently unused. Needs manual work to construct the new locale -locale_t newlocale( int mask, const char * locale, locale_t /*base*/ ) +// 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}; } diff --git a/contrib/libs/cxxsupp/libcxx/src/support/win32/thread_win32.cpp b/contrib/libs/cxxsupp/libcxx/src/support/win32/thread_win32.cpp index f2072b1435..c25aefcc34 100644 --- a/contrib/libs/cxxsupp/libcxx/src/support/win32/thread_win32.cpp +++ b/contrib/libs/cxxsupp/libcxx/src/support/win32/thread_win32.cpp @@ -7,6 +7,8 @@ //===----------------------------------------------------------------------===// #include <__threading_support> +#include <chrono> + #define NOMINMAX #define WIN32_LEAN_AND_MEAN #include <windows.h> diff --git a/contrib/libs/cxxsupp/libcxx/src/system_error.cpp b/contrib/libs/cxxsupp/libcxx/src/system_error.cpp index 7875f59d88..1cc6b7d7e1 100644 --- a/contrib/libs/cxxsupp/libcxx/src/system_error.cpp +++ b/contrib/libs/cxxsupp/libcxx/src/system_error.cpp @@ -6,12 +6,8 @@ // //===----------------------------------------------------------------------===// -#include <__config> -#ifdef _LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS -# define _LIBCPP_ERROR_CATEGORY_DEFINE_LEGACY_INLINE_FUNCTIONS -#endif - #include <__assert> +#include <__config> #include <__verbose_abort> #include <cerrno> #include <cstdio> @@ -29,38 +25,8 @@ _LIBCPP_BEGIN_NAMESPACE_STD -// class error_category - -#if defined(_LIBCPP_ERROR_CATEGORY_DEFINE_LEGACY_INLINE_FUNCTIONS) -error_category::error_category() noexcept -{ -} -#endif - -error_category::~error_category() noexcept -{ -} - -error_condition -error_category::default_error_condition(int ev) const noexcept -{ - return error_condition(ev, *this); -} - -bool -error_category::equivalent(int code, const error_condition& condition) const noexcept -{ - return default_error_condition(code) == condition; -} - -bool -error_category::equivalent(const error_code& code, int condition) const noexcept -{ - return *this == code.category() && code.value() == condition; -} - -#if !defined(_LIBCPP_HAS_NO_THREADS) namespace { +#if !defined(_LIBCPP_HAS_NO_THREADS) // GLIBC also uses 1024 as the maximum buffer size internally. constexpr size_t strerror_buff_size = 1024; @@ -128,8 +94,26 @@ string do_strerror_r(int ev) { return string(error_message); } #endif + +#endif // !defined(_LIBCPP_HAS_NO_THREADS) + +string make_error_str(const error_code& ec, string what_arg) { + if (ec) { + if (!what_arg.empty()) { + what_arg += ": "; + } + what_arg += ec.message(); + } + return what_arg; +} + +string make_error_str(const error_code& ec) { + if (ec) { + return ec.message(); + } + return string(); +} } // end namespace -#endif string __do_message::message(int ev) const @@ -168,8 +152,13 @@ __generic_error_category::message(int ev) const const error_category& generic_category() noexcept { - static __generic_error_category s; - return s; + union AvoidDestroyingGenericCategory { + __generic_error_category generic_error_category; + constexpr explicit AvoidDestroyingGenericCategory() : generic_error_category() {} + ~AvoidDestroyingGenericCategory() {} + }; + constinit static AvoidDestroyingGenericCategory helper; + return helper.generic_error_category; } class _LIBCPP_HIDDEN __system_error_category @@ -210,8 +199,13 @@ __system_error_category::default_error_condition(int ev) const noexcept const error_category& system_category() noexcept { - static __system_error_category s; - return s; + union AvoidDestroyingSystemCategory { + __system_error_category system_error_category; + constexpr explicit AvoidDestroyingSystemCategory() : system_error_category() {} + ~AvoidDestroyingSystemCategory() {} + }; + constinit static AvoidDestroyingSystemCategory helper; + return helper.system_error_category; } // error_condition @@ -232,50 +226,38 @@ error_code::message() const // system_error -string -system_error::__init(const error_code& ec, string what_arg) -{ - if (ec) - { - if (!what_arg.empty()) - what_arg += ": "; - what_arg += ec.message(); - } - return what_arg; -} - system_error::system_error(error_code ec, const string& what_arg) - : runtime_error(__init(ec, what_arg)), + : runtime_error(make_error_str(ec, what_arg)), __ec_(ec) { } system_error::system_error(error_code ec, const char* what_arg) - : runtime_error(__init(ec, what_arg)), + : runtime_error(make_error_str(ec, what_arg)), __ec_(ec) { } system_error::system_error(error_code ec) - : runtime_error(__init(ec, "")), + : runtime_error(make_error_str(ec)), __ec_(ec) { } system_error::system_error(int ev, const error_category& ecat, const string& what_arg) - : runtime_error(__init(error_code(ev, ecat), what_arg)), + : runtime_error(make_error_str(error_code(ev, ecat), what_arg)), __ec_(error_code(ev, ecat)) { } system_error::system_error(int ev, const error_category& ecat, const char* what_arg) - : runtime_error(__init(error_code(ev, ecat), what_arg)), + : runtime_error(make_error_str(error_code(ev, ecat), what_arg)), __ec_(error_code(ev, ecat)) { } system_error::system_error(int ev, const error_category& ecat) - : runtime_error(__init(error_code(ev, ecat), "")), + : runtime_error(make_error_str(error_code(ev, ecat))), __ec_(error_code(ev, ecat)) { } @@ -288,8 +270,9 @@ void __throw_system_error(int ev, const char* what_arg) { #ifndef _LIBCPP_HAS_NO_EXCEPTIONS - throw system_error(error_code(ev, system_category()), what_arg); + std::__throw_system_error(error_code(ev, system_category()), what_arg); #else + // The above could also handle the no-exception case, but for size, avoid referencing system_category() unnecessarily. _LIBCPP_VERBOSE_ABORT("system_error was thrown in -fno-exceptions mode with error %i and message \"%s\"", ev, what_arg); #endif } diff --git a/contrib/libs/cxxsupp/libcxx/src/tz.cpp b/contrib/libs/cxxsupp/libcxx/src/tz.cpp new file mode 100644 index 0000000000..4425f0e6b9 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxx/src/tz.cpp @@ -0,0 +1,146 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +// For information see https://libcxx.llvm.org/DesignDocs/TimeZone.html + +#include <chrono> +#include <filesystem> +#include <fstream> +#include <stdexcept> +#include <string> + +// Contains a parser for the IANA time zone data files. +// +// These files can be found at https://data.iana.org/time-zones/ and are in the +// public domain. Information regarding the input can be found at +// https://data.iana.org/time-zones/tz-how-to.html and +// https://man7.org/linux/man-pages/man8/zic.8.html. +// +// As indicated at https://howardhinnant.github.io/date/tz.html#Installation +// For Windows another file seems to be required +// https://raw.githubusercontent.com/unicode-org/cldr/master/common/supplemental/windowsZones.xml +// This file seems to contain the mapping of Windows time zone name to IANA +// time zone names. +// +// However this article mentions another way to do the mapping on Windows +// https://devblogs.microsoft.com/oldnewthing/20210527-00/?p=105255 +// This requires Windows 10 Version 1903, which was released in May of 2019 +// and considered end of life in December 2020 +// https://learn.microsoft.com/en-us/lifecycle/announcements/windows-10-1903-end-of-servicing +// +// TODO TZDB Implement the Windows mapping in tzdb::current_zone + +_LIBCPP_BEGIN_NAMESPACE_STD + +namespace chrono { + +// This function is weak so it can be overriden in the tests. The +// declaration is in the test header test/support/test_tzdb.h +_LIBCPP_WEAK string_view __libcpp_tzdb_directory() { +#if defined(__linux__) + return "/usr/share/zoneinfo/"; +#else +# error "unknown path to the IANA Time Zone Database" +#endif +} + +[[nodiscard]] static bool __is_whitespace(int __c) { return __c == ' ' || __c == '\t'; } + +static void __skip_optional_whitespace(istream& __input) { + while (chrono::__is_whitespace(__input.peek())) + __input.get(); +} + +static void __skip_mandatory_whitespace(istream& __input) { + if (!chrono::__is_whitespace(__input.get())) + std::__throw_runtime_error("corrupt tzdb: expected whitespace"); + + chrono::__skip_optional_whitespace(__input); +} + +static void __matches(istream& __input, char __expected) { + if (std::tolower(__input.get()) != __expected) + std::__throw_runtime_error((string("corrupt tzdb: expected character '") + __expected + '\'').c_str()); +} + +static void __matches(istream& __input, string_view __expected) { + for (auto __c : __expected) + if (std::tolower(__input.get()) != __c) + std::__throw_runtime_error((string("corrupt tzdb: expected string '") + string(__expected) + '\'').c_str()); +} + +[[nodiscard]] static string __parse_string(istream& __input) { + string __result; + while (true) { + int __c = __input.get(); + switch (__c) { + case ' ': + case '\t': + case '\n': + __input.unget(); + [[fallthrough]]; + case istream::traits_type::eof(): + if (__result.empty()) + std::__throw_runtime_error("corrupt tzdb: expected a string"); + + return __result; + + default: + __result.push_back(__c); + } + } +} + +static string __parse_version(istream& __input) { + // The first line in tzdata.zi contains + // # version YYYYw + // The parser expects this pattern + // #\s*version\s*\(.*) + // This part is not documented. + chrono::__matches(__input, '#'); + chrono::__skip_optional_whitespace(__input); + chrono::__matches(__input, "version"); + chrono::__skip_mandatory_whitespace(__input); + return chrono::__parse_string(__input); +} + +static tzdb __make_tzdb() { + tzdb __result; + + filesystem::path __root = chrono::__libcpp_tzdb_directory(); + ifstream __tzdata{__root / "tzdata.zi"}; + + __result.version = chrono::__parse_version(__tzdata); + return __result; +} + +//===----------------------------------------------------------------------===// +// Public API +//===----------------------------------------------------------------------===// + +_LIBCPP_NODISCARD_EXT _LIBCPP_AVAILABILITY_TZDB _LIBCPP_EXPORTED_FROM_ABI tzdb_list& get_tzdb_list() { + static tzdb_list __result{chrono::__make_tzdb()}; + return __result; +} + +_LIBCPP_AVAILABILITY_TZDB _LIBCPP_EXPORTED_FROM_ABI const tzdb& reload_tzdb() { + if (chrono::remote_version() == chrono::get_tzdb().version) + return chrono::get_tzdb(); + + return chrono::get_tzdb_list().__emplace_front(chrono::__make_tzdb()); +} + +_LIBCPP_NODISCARD_EXT _LIBCPP_AVAILABILITY_TZDB _LIBCPP_EXPORTED_FROM_ABI string remote_version() { + filesystem::path __root = chrono::__libcpp_tzdb_directory(); + ifstream __tzdata{__root / "tzdata.zi"}; + return chrono::__parse_version(__tzdata); +} + +} // namespace chrono + +_LIBCPP_END_NAMESPACE_STD diff --git a/contrib/libs/cxxsupp/libcxx/src/tzdb_list.cpp b/contrib/libs/cxxsupp/libcxx/src/tzdb_list.cpp new file mode 100644 index 0000000000..7eaaedc6ed --- /dev/null +++ b/contrib/libs/cxxsupp/libcxx/src/tzdb_list.cpp @@ -0,0 +1,113 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +// For information see https://libcxx.llvm.org/DesignDocs/TimeZone.html + +#include <chrono> + +#include <__mutex/unique_lock.h> +#include <forward_list> + +// When threads are not available the locking is not required. +#ifndef _LIBCPP_HAS_NO_THREADS +# include <shared_mutex> +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +namespace chrono { + +//===----------------------------------------------------------------------===// +// Private API +//===----------------------------------------------------------------------===// + +class tzdb_list::__impl { +public: + explicit __impl(tzdb&& __tzdb) { __tzdb_.push_front(std::move(__tzdb)); } + + using const_iterator = tzdb_list::const_iterator; + + const tzdb& front() const noexcept { +#ifndef _LIBCPP_HAS_NO_THREADS + shared_lock __lock{__mutex_}; +#endif + return __tzdb_.front(); + } + + const_iterator erase_after(const_iterator __p) { +#ifndef _LIBCPP_HAS_NO_THREADS + unique_lock __lock{__mutex_}; +#endif + return __tzdb_.erase_after(__p); + } + + tzdb& __emplace_front(tzdb&& __tzdb) { +#ifndef _LIBCPP_HAS_NO_THREADS + unique_lock __lock{__mutex_}; +#endif + return __tzdb_.emplace_front(std::move(__tzdb)); + } + + const_iterator begin() const noexcept { +#ifndef _LIBCPP_HAS_NO_THREADS + shared_lock __lock{__mutex_}; +#endif + return __tzdb_.begin(); + } + const_iterator end() const noexcept { + // forward_list<T>::end does not access the list, so no need to take a lock. + return __tzdb_.end(); + } + + const_iterator cbegin() const noexcept { return begin(); } + const_iterator cend() const noexcept { return end(); } + +private: +#ifndef _LIBCPP_HAS_NO_THREADS + mutable shared_mutex __mutex_; +#endif + forward_list<tzdb> __tzdb_; +}; + +//===----------------------------------------------------------------------===// +// Public API +//===----------------------------------------------------------------------===// + +_LIBCPP_EXPORTED_FROM_ABI tzdb_list::tzdb_list(tzdb&& __tzdb) : __impl_{new __impl(std::move(__tzdb))} {} + +_LIBCPP_EXPORTED_FROM_ABI tzdb_list::~tzdb_list() { delete __impl_; } + +_LIBCPP_NODISCARD_EXT _LIBCPP_EXPORTED_FROM_ABI const tzdb& tzdb_list::front() const noexcept { + return __impl_->front(); +} + +_LIBCPP_EXPORTED_FROM_ABI tzdb_list::const_iterator tzdb_list::erase_after(const_iterator __p) { + return __impl_->erase_after(__p); +} + +_LIBCPP_EXPORTED_FROM_ABI tzdb& tzdb_list::__emplace_front(tzdb&& __tzdb) { + return __impl_->__emplace_front(std::move(__tzdb)); +} + +_LIBCPP_NODISCARD_EXT _LIBCPP_EXPORTED_FROM_ABI tzdb_list::const_iterator tzdb_list::begin() const noexcept { + return __impl_->begin(); +} +_LIBCPP_NODISCARD_EXT _LIBCPP_EXPORTED_FROM_ABI tzdb_list::const_iterator tzdb_list::end() const noexcept { + return __impl_->end(); +} + +_LIBCPP_NODISCARD_EXT _LIBCPP_EXPORTED_FROM_ABI tzdb_list::const_iterator tzdb_list::cbegin() const noexcept { + return __impl_->cbegin(); +} +_LIBCPP_NODISCARD_EXT _LIBCPP_EXPORTED_FROM_ABI tzdb_list::const_iterator tzdb_list::cend() const noexcept { + return __impl_->cend(); +} + +} // namespace chrono + +_LIBCPP_END_NAMESPACE_STD |