aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/libcxx/src
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/libcxx/src')
-rw-r--r--contrib/llvm-project/libcxx/src/algorithm.cpp41
-rw-r--r--contrib/llvm-project/libcxx/src/any.cpp20
-rw-r--r--contrib/llvm-project/libcxx/src/atomic.cpp225
-rw-r--r--contrib/llvm-project/libcxx/src/barrier.cpp118
-rw-r--r--contrib/llvm-project/libcxx/src/bind.cpp27
-rw-r--r--contrib/llvm-project/libcxx/src/call_once.cpp70
-rw-r--r--contrib/llvm-project/libcxx/src/charconv.cpp177
-rw-r--r--contrib/llvm-project/libcxx/src/chrono.cpp234
-rw-r--r--contrib/llvm-project/libcxx/src/chrono_system_time_init.h2
-rw-r--r--contrib/llvm-project/libcxx/src/condition_variable.cpp114
-rw-r--r--contrib/llvm-project/libcxx/src/condition_variable_destructor.cpp32
-rw-r--r--contrib/llvm-project/libcxx/src/debug.cpp578
-rw-r--r--contrib/llvm-project/libcxx/src/error_category.cpp37
-rw-r--r--contrib/llvm-project/libcxx/src/exception.cpp36
-rw-r--r--contrib/llvm-project/libcxx/src/experimental/keep.cpp (renamed from contrib/llvm-project/libcxx/src/utility.cpp)11
-rw-r--r--contrib/llvm-project/libcxx/src/experimental/memory_resource.cpp151
-rw-r--r--contrib/llvm-project/libcxx/src/filesystem/directory_entry.cpp73
-rw-r--r--contrib/llvm-project/libcxx/src/filesystem/directory_iterator.cpp197
-rw-r--r--contrib/llvm-project/libcxx/src/filesystem/error.h232
-rw-r--r--contrib/llvm-project/libcxx/src/filesystem/file_descriptor.h291
-rw-r--r--contrib/llvm-project/libcxx/src/filesystem/filesystem_clock.cpp62
-rw-r--r--contrib/llvm-project/libcxx/src/filesystem/filesystem_common.h475
-rw-r--r--contrib/llvm-project/libcxx/src/filesystem/filesystem_error.cpp39
-rw-r--r--contrib/llvm-project/libcxx/src/filesystem/format_string.h77
-rw-r--r--contrib/llvm-project/libcxx/src/filesystem/int128_builtins.cpp18
-rw-r--r--contrib/llvm-project/libcxx/src/filesystem/operations.cpp1717
-rw-r--r--contrib/llvm-project/libcxx/src/filesystem/path.cpp441
-rw-r--r--contrib/llvm-project/libcxx/src/filesystem/path_parser.h352
-rw-r--r--contrib/llvm-project/libcxx/src/filesystem/posix_compat.h497
-rw-r--r--contrib/llvm-project/libcxx/src/filesystem/time_utils.h351
-rw-r--r--contrib/llvm-project/libcxx/src/fstream.cpp37
-rw-r--r--contrib/llvm-project/libcxx/src/functional.cpp16
-rw-r--r--contrib/llvm-project/libcxx/src/future.cpp352
-rw-r--r--contrib/llvm-project/libcxx/src/hash.cpp913
-rw-r--r--contrib/llvm-project/libcxx/src/include/apple_availability.h55
-rw-r--r--contrib/llvm-project/libcxx/src/include/atomic_support.h164
-rw-r--r--contrib/llvm-project/libcxx/src/include/config_elast.h24
-rw-r--r--contrib/llvm-project/libcxx/src/include/overridable_function.h119
-rw-r--r--contrib/llvm-project/libcxx/src/include/refstring.h139
-rw-r--r--contrib/llvm-project/libcxx/src/include/ryu/common.h109
-rw-r--r--contrib/llvm-project/libcxx/src/include/ryu/d2fixed.h60
-rw-r--r--contrib/llvm-project/libcxx/src/include/ryu/d2fixed_full_table.h4451
-rw-r--r--contrib/llvm-project/libcxx/src/include/ryu/d2s.h62
-rw-r--r--contrib/llvm-project/libcxx/src/include/ryu/d2s_full_table.h368
-rw-r--r--contrib/llvm-project/libcxx/src/include/ryu/d2s_intrinsics.h260
-rw-r--r--contrib/llvm-project/libcxx/src/include/ryu/digit_table.h57
-rw-r--r--contrib/llvm-project/libcxx/src/include/ryu/f2s.h55
-rw-r--r--contrib/llvm-project/libcxx/src/include/ryu/ryu.h147
-rw-r--r--contrib/llvm-project/libcxx/src/include/sso_allocator.h80
-rw-r--r--contrib/llvm-project/libcxx/src/include/to_chars_floating_point.h1079
-rw-r--r--contrib/llvm-project/libcxx/src/ios.cpp602
-rw-r--r--contrib/llvm-project/libcxx/src/ios.instantiations.cpp31
-rw-r--r--contrib/llvm-project/libcxx/src/iostream.cpp210
-rw-r--r--contrib/llvm-project/libcxx/src/iostream_init.h2
-rw-r--r--contrib/llvm-project/libcxx/src/legacy_pointer_safety.cpp23
-rw-r--r--contrib/llvm-project/libcxx/src/locale.cpp10219
-rw-r--r--contrib/llvm-project/libcxx/src/memory.cpp325
-rw-r--r--contrib/llvm-project/libcxx/src/memory_resource.cpp498
-rw-r--r--contrib/llvm-project/libcxx/src/memory_resource_init_helper.h2
-rw-r--r--contrib/llvm-project/libcxx/src/mutex.cpp305
-rw-r--r--contrib/llvm-project/libcxx/src/mutex_destructor.cpp32
-rw-r--r--contrib/llvm-project/libcxx/src/new.cpp460
-rw-r--r--contrib/llvm-project/libcxx/src/new_handler.cpp39
-rw-r--r--contrib/llvm-project/libcxx/src/new_helpers.cpp (renamed from contrib/llvm-project/libcxx/src/support/runtime/new_handler_fallback.ipp)28
-rw-r--r--contrib/llvm-project/libcxx/src/optional.cpp31
-rw-r--r--contrib/llvm-project/libcxx/src/ostream.cpp42
-rw-r--r--contrib/llvm-project/libcxx/src/print.cpp64
-rw-r--r--contrib/llvm-project/libcxx/src/pstl/libdispatch.cpp35
-rw-r--r--contrib/llvm-project/libcxx/src/random.cpp222
-rw-r--r--contrib/llvm-project/libcxx/src/random_shuffle.cpp52
-rw-r--r--contrib/llvm-project/libcxx/src/regex.cpp413
-rw-r--r--contrib/llvm-project/libcxx/src/ryu/README.txt11
-rw-r--r--contrib/llvm-project/libcxx/src/ryu/d2fixed.cpp669
-rw-r--r--contrib/llvm-project/libcxx/src/ryu/d2s.cpp783
-rw-r--r--contrib/llvm-project/libcxx/src/ryu/f2s.cpp716
-rw-r--r--contrib/llvm-project/libcxx/src/shared_mutex.cpp141
-rw-r--r--contrib/llvm-project/libcxx/src/std_stream.h387
-rw-r--r--contrib/llvm-project/libcxx/src/stdexcept.cpp27
-rw-r--r--contrib/llvm-project/libcxx/src/string.cpp586
-rw-r--r--contrib/llvm-project/libcxx/src/strstream.cpp475
-rw-r--r--contrib/llvm-project/libcxx/src/support/ibm/mbsnrtowcs.cpp97
-rw-r--r--contrib/llvm-project/libcxx/src/support/ibm/wcsnrtombs.cpp94
-rw-r--r--contrib/llvm-project/libcxx/src/support/ibm/xlocale_zos.cpp130
-rw-r--r--contrib/llvm-project/libcxx/src/support/runtime/exception_fallback.ipp153
-rw-r--r--contrib/llvm-project/libcxx/src/support/runtime/exception_glibcxx.ipp18
-rw-r--r--contrib/llvm-project/libcxx/src/support/runtime/exception_libcxxabi.ipp17
-rw-r--r--contrib/llvm-project/libcxx/src/support/runtime/exception_libcxxrt.ipp11
-rw-r--r--contrib/llvm-project/libcxx/src/support/runtime/exception_msvc.ipp155
-rw-r--r--contrib/llvm-project/libcxx/src/support/runtime/exception_pointer_cxxabi.ipp79
-rw-r--r--contrib/llvm-project/libcxx/src/support/runtime/exception_pointer_glibcxx.ipp65
-rw-r--r--contrib/llvm-project/libcxx/src/support/runtime/exception_pointer_msvc.ipp40
-rw-r--r--contrib/llvm-project/libcxx/src/support/runtime/exception_pointer_unimplemented.ipp47
-rw-r--r--contrib/llvm-project/libcxx/src/support/runtime/stdexcept_default.ipp38
-rw-r--r--contrib/llvm-project/libcxx/src/support/runtime/stdexcept_vcruntime.ipp4
-rw-r--r--contrib/llvm-project/libcxx/src/system_error.cpp286
-rw-r--r--contrib/llvm-project/libcxx/src/thread.cpp250
-rw-r--r--contrib/llvm-project/libcxx/src/typeinfo.cpp37
-rw-r--r--contrib/llvm-project/libcxx/src/tz.cpp146
-rw-r--r--contrib/llvm-project/libcxx/src/tzdb_list.cpp113
-rw-r--r--contrib/llvm-project/libcxx/src/valarray.cpp64
-rw-r--r--contrib/llvm-project/libcxx/src/variant.cpp10
-rw-r--r--contrib/llvm-project/libcxx/src/vector.cpp21
-rw-r--r--contrib/llvm-project/libcxx/src/verbose_abort.cpp77
103 files changed, 21961 insertions, 12663 deletions
diff --git a/contrib/llvm-project/libcxx/src/algorithm.cpp b/contrib/llvm-project/libcxx/src/algorithm.cpp
index 9f11dc38b15b..af9d60a8e271 100644
--- a/contrib/llvm-project/libcxx/src/algorithm.cpp
+++ b/contrib/llvm-project/libcxx/src/algorithm.cpp
@@ -1,4 +1,4 @@
-//===----------------------- algorithm.cpp --------------------------------===//
+//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -6,12 +6,30 @@
//
//===----------------------------------------------------------------------===//
-#include "algorithm"
+#include <algorithm>
+#include <bit>
_LIBCPP_BEGIN_NAMESPACE_STD
+template <class Comp, class RandomAccessIterator>
+void __sort(RandomAccessIterator first, RandomAccessIterator last, Comp comp) {
+ auto depth_limit = 2 * std::__bit_log2(static_cast<size_t>(last - first));
+
+ // Only use bitset partitioning for arithmetic types. We should also check
+ // that the default comparator is in use so that we are sure that there are no
+ // branches in the comparator.
+ std::__introsort<_ClassicAlgPolicy,
+ ranges::less,
+ RandomAccessIterator,
+ __use_branchless_sort<ranges::less, RandomAccessIterator>::value>(
+ first, last, ranges::less{}, depth_limit);
+}
+
+// clang-format off
template void __sort<__less<char>&, char*>(char*, char*, __less<char>&);
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
template void __sort<__less<wchar_t>&, wchar_t*>(wchar_t*, wchar_t*, __less<wchar_t>&);
+#endif
template void __sort<__less<signed char>&, signed char*>(signed char*, signed char*, __less<signed char>&);
template void __sort<__less<unsigned char>&, unsigned char*>(unsigned char*, unsigned char*, __less<unsigned char>&);
template void __sort<__less<short>&, short*>(short*, short*, __less<short>&);
@@ -25,23 +43,6 @@ template void __sort<__less<unsigned long long>&, unsigned long long*>(unsigned
template void __sort<__less<float>&, float*>(float*, float*, __less<float>&);
template void __sort<__less<double>&, double*>(double*, double*, __less<double>&);
template void __sort<__less<long double>&, long double*>(long double*, long double*, __less<long double>&);
-
-template bool __insertion_sort_incomplete<__less<char>&, char*>(char*, char*, __less<char>&);
-template bool __insertion_sort_incomplete<__less<wchar_t>&, wchar_t*>(wchar_t*, wchar_t*, __less<wchar_t>&);
-template bool __insertion_sort_incomplete<__less<signed char>&, signed char*>(signed char*, signed char*, __less<signed char>&);
-template bool __insertion_sort_incomplete<__less<unsigned char>&, unsigned char*>(unsigned char*, unsigned char*, __less<unsigned char>&);
-template bool __insertion_sort_incomplete<__less<short>&, short*>(short*, short*, __less<short>&);
-template bool __insertion_sort_incomplete<__less<unsigned short>&, unsigned short*>(unsigned short*, unsigned short*, __less<unsigned short>&);
-template bool __insertion_sort_incomplete<__less<int>&, int*>(int*, int*, __less<int>&);
-template bool __insertion_sort_incomplete<__less<unsigned>&, unsigned*>(unsigned*, unsigned*, __less<unsigned>&);
-template bool __insertion_sort_incomplete<__less<long>&, long*>(long*, long*, __less<long>&);
-template bool __insertion_sort_incomplete<__less<unsigned long>&, unsigned long*>(unsigned long*, unsigned long*, __less<unsigned long>&);
-template bool __insertion_sort_incomplete<__less<long long>&, long long*>(long long*, long long*, __less<long long>&);
-template bool __insertion_sort_incomplete<__less<unsigned long long>&, unsigned long long*>(unsigned long long*, unsigned long long*, __less<unsigned long long>&);
-template bool __insertion_sort_incomplete<__less<float>&, float*>(float*, float*, __less<float>&);
-template bool __insertion_sort_incomplete<__less<double>&, double*>(double*, double*, __less<double>&);
-template bool __insertion_sort_incomplete<__less<long double>&, long double*>(long double*, long double*, __less<long double>&);
-
-template unsigned __sort5<__less<long double>&, long double*>(long double*, long double*, long double*, long double*, long double*, __less<long double>&);
+// clang-format on
_LIBCPP_END_NAMESPACE_STD
diff --git a/contrib/llvm-project/libcxx/src/any.cpp b/contrib/llvm-project/libcxx/src/any.cpp
index 0cf09068837d..b0ad695669de 100644
--- a/contrib/llvm-project/libcxx/src/any.cpp
+++ b/contrib/llvm-project/libcxx/src/any.cpp
@@ -1,4 +1,4 @@
-//===---------------------------- any.cpp ---------------------------------===//
+//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -6,14 +6,11 @@
//
//===----------------------------------------------------------------------===//
-#include "any"
+#include <any>
namespace std {
-const char* bad_any_cast::what() const _NOEXCEPT {
- return "bad any cast";
-}
-}
-
+const char* bad_any_cast::what() const noexcept { return "bad any cast"; }
+} // namespace std
#include <experimental/__config>
@@ -21,14 +18,11 @@ const char* bad_any_cast::what() const _NOEXCEPT {
// Even though it no longer exists in a header file
_LIBCPP_BEGIN_NAMESPACE_LFTS
-class _LIBCPP_EXCEPTION_ABI _LIBCPP_AVAILABILITY_BAD_ANY_CAST bad_any_cast : public bad_cast
-{
+class _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_AVAILABILITY_BAD_ANY_CAST bad_any_cast : public bad_cast {
public:
- virtual const char* what() const _NOEXCEPT;
+ virtual const char* what() const noexcept;
};
-const char* bad_any_cast::what() const _NOEXCEPT {
- return "bad any cast";
-}
+const char* bad_any_cast::what() const noexcept { return "bad any cast"; }
_LIBCPP_END_NAMESPACE_LFTS
diff --git a/contrib/llvm-project/libcxx/src/atomic.cpp b/contrib/llvm-project/libcxx/src/atomic.cpp
index 9ae1fb5199bf..2f0389ae6974 100644
--- a/contrib/llvm-project/libcxx/src/atomic.cpp
+++ b/contrib/llvm-project/libcxx/src/atomic.cpp
@@ -1,4 +1,4 @@
-//===------------------------- atomic.cpp ---------------------------------===//
+//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -6,24 +6,30 @@
//
//===----------------------------------------------------------------------===//
-#include <__config>
-#ifndef _LIBCPP_HAS_NO_THREADS
-
-#include <climits>
+#include <__thread/timed_backoff_policy.h>
#include <atomic>
+#include <climits>
#include <functional>
+#include <thread>
+
+#include "include/apple_availability.h"
#ifdef __linux__
-#include <unistd.h>
-#include <linux/futex.h>
-#include <sys/syscall.h>
+# include <linux/futex.h>
+# include <sys/syscall.h>
+# include <unistd.h>
// libc++ uses SYS_futex as a universal syscall name. However, on 32 bit architectures
// with a 64 bit time_t, we need to specify SYS_futex_time64.
-#if !defined(SYS_futex) && defined(SYS_futex_time64)
-# define SYS_futex SYS_futex_time64
-#endif
+# if !defined(SYS_futex) && defined(SYS_futex_time64)
+# define SYS_futex SYS_futex_time64
+# endif
+
+#elif defined(__FreeBSD__)
+
+# include <sys/types.h>
+# include <sys/umtx.h>
#else // <- Add other operating systems here
@@ -35,75 +41,80 @@ _LIBCPP_BEGIN_NAMESPACE_STD
#ifdef __linux__
-static void __libcpp_platform_wait_on_address(__cxx_atomic_contention_t const volatile* __ptr,
- __cxx_contention_t __val)
-{
- static constexpr timespec __timeout = { 2, 0 };
- syscall(SYS_futex, __ptr, FUTEX_WAIT_PRIVATE, __val, &__timeout, 0, 0);
+static void
+__libcpp_platform_wait_on_address(__cxx_atomic_contention_t const volatile* __ptr, __cxx_contention_t __val) {
+ static constexpr timespec __timeout = {2, 0};
+ syscall(SYS_futex, __ptr, FUTEX_WAIT_PRIVATE, __val, &__timeout, 0, 0);
}
-static void __libcpp_platform_wake_by_address(__cxx_atomic_contention_t const volatile* __ptr,
- bool __notify_one)
-{
- syscall(SYS_futex, __ptr, FUTEX_WAKE_PRIVATE, __notify_one ? 1 : INT_MAX, 0, 0, 0);
+static void __libcpp_platform_wake_by_address(__cxx_atomic_contention_t const volatile* __ptr, bool __notify_one) {
+ syscall(SYS_futex, __ptr, FUTEX_WAKE_PRIVATE, __notify_one ? 1 : INT_MAX, 0, 0, 0);
}
#elif defined(__APPLE__) && defined(_LIBCPP_USE_ULOCK)
-extern "C" int __ulock_wait(uint32_t operation, void *addr, uint64_t value,
- uint32_t timeout); /* timeout is specified in microseconds */
-extern "C" int __ulock_wake(uint32_t operation, void *addr, uint64_t wake_value);
+extern "C" int __ulock_wait(
+ uint32_t operation, void* addr, uint64_t value, uint32_t timeout); /* timeout is specified in microseconds */
+extern "C" int __ulock_wake(uint32_t operation, void* addr, uint64_t wake_value);
-#define UL_COMPARE_AND_WAIT 1
-#define ULF_WAKE_ALL 0x00000100
+# define UL_COMPARE_AND_WAIT 1
+# define ULF_WAKE_ALL 0x00000100
-static void __libcpp_platform_wait_on_address(__cxx_atomic_contention_t const volatile* __ptr,
- __cxx_contention_t __val)
-{
- __ulock_wait(UL_COMPARE_AND_WAIT,
- const_cast<__cxx_atomic_contention_t*>(__ptr), __val, 0);
+static void
+__libcpp_platform_wait_on_address(__cxx_atomic_contention_t const volatile* __ptr, __cxx_contention_t __val) {
+ __ulock_wait(UL_COMPARE_AND_WAIT, const_cast<__cxx_atomic_contention_t*>(__ptr), __val, 0);
}
-static void __libcpp_platform_wake_by_address(__cxx_atomic_contention_t const volatile* __ptr,
- bool __notify_one)
-{
- __ulock_wake(UL_COMPARE_AND_WAIT | (__notify_one ? 0 : ULF_WAKE_ALL),
- const_cast<__cxx_atomic_contention_t*>(__ptr), 0);
+static void __libcpp_platform_wake_by_address(__cxx_atomic_contention_t const volatile* __ptr, bool __notify_one) {
+ __ulock_wake(
+ UL_COMPARE_AND_WAIT | (__notify_one ? 0 : ULF_WAKE_ALL), const_cast<__cxx_atomic_contention_t*>(__ptr), 0);
+}
+
+#elif defined(__FreeBSD__) && __SIZEOF_LONG__ == 8
+/*
+ * Since __cxx_contention_t is int64_t even on 32bit FreeBSD
+ * platforms, we have to use umtx ops that work on the long type, and
+ * limit its use to architectures where long and int64_t are synonyms.
+ */
+
+static void
+__libcpp_platform_wait_on_address(__cxx_atomic_contention_t const volatile* __ptr, __cxx_contention_t __val) {
+ _umtx_op(const_cast<__cxx_atomic_contention_t*>(__ptr), UMTX_OP_WAIT, __val, NULL, NULL);
+}
+
+static void __libcpp_platform_wake_by_address(__cxx_atomic_contention_t const volatile* __ptr, bool __notify_one) {
+ _umtx_op(const_cast<__cxx_atomic_contention_t*>(__ptr), UMTX_OP_WAKE, __notify_one ? 1 : INT_MAX, NULL, NULL);
}
#else // <- Add other operating systems here
// Baseline is just a timed backoff
-static void __libcpp_platform_wait_on_address(__cxx_atomic_contention_t const volatile* __ptr,
- __cxx_contention_t __val)
-{
- __libcpp_thread_poll_with_backoff([=]() -> bool {
- return !__cxx_nonatomic_compare_equal(__cxx_atomic_load(__ptr, memory_order_relaxed), __val);
- }, __libcpp_timed_backoff_policy());
+static void
+__libcpp_platform_wait_on_address(__cxx_atomic_contention_t const volatile* __ptr, __cxx_contention_t __val) {
+ __libcpp_thread_poll_with_backoff(
+ [=]() -> bool { return !__cxx_nonatomic_compare_equal(__cxx_atomic_load(__ptr, memory_order_relaxed), __val); },
+ __libcpp_timed_backoff_policy());
}
-static void __libcpp_platform_wake_by_address(__cxx_atomic_contention_t const volatile*, bool) { }
+static void __libcpp_platform_wake_by_address(__cxx_atomic_contention_t const volatile*, bool) {}
#endif // __linux__
-static constexpr size_t __libcpp_contention_table_size = (1 << 8); /* < there's no magic in this number */
+static constexpr size_t __libcpp_contention_table_size = (1 << 8); /* < there's no magic in this number */
-struct alignas(64) /* aim to avoid false sharing */ __libcpp_contention_table_entry
-{
- __cxx_atomic_contention_t __contention_state;
- __cxx_atomic_contention_t __platform_state;
- inline constexpr __libcpp_contention_table_entry() :
- __contention_state(0), __platform_state(0) { }
+struct alignas(64) /* aim to avoid false sharing */ __libcpp_contention_table_entry {
+ __cxx_atomic_contention_t __contention_state;
+ __cxx_atomic_contention_t __platform_state;
+ inline constexpr __libcpp_contention_table_entry() : __contention_state(0), __platform_state(0) {}
};
-static __libcpp_contention_table_entry __libcpp_contention_table[ __libcpp_contention_table_size ];
+static __libcpp_contention_table_entry __libcpp_contention_table[__libcpp_contention_table_size];
static hash<void const volatile*> __libcpp_contention_hasher;
-static __libcpp_contention_table_entry* __libcpp_contention_state(void const volatile * p)
-{
- return &__libcpp_contention_table[__libcpp_contention_hasher(p) & (__libcpp_contention_table_size - 1)];
+static __libcpp_contention_table_entry* __libcpp_contention_state(void const volatile* p) {
+ return &__libcpp_contention_table[__libcpp_contention_hasher(p) & (__libcpp_contention_table_size - 1)];
}
/* Given an atomic to track contention and an atomic to actually wait on, which may be
@@ -111,83 +122,69 @@ static __libcpp_contention_table_entry* __libcpp_contention_state(void const vol
static void __libcpp_contention_notify(__cxx_atomic_contention_t volatile* __contention_state,
__cxx_atomic_contention_t const volatile* __platform_state,
- bool __notify_one)
-{
- if(0 != __cxx_atomic_load(__contention_state, memory_order_seq_cst))
- // 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,
- __cxx_atomic_contention_t const volatile* __platform_state)
-{
- // We will monitor this value.
- return __cxx_atomic_load(__platform_state, memory_order_acquire);
+ bool __notify_one) {
+ if (0 != __cxx_atomic_load(__contention_state, memory_order_seq_cst))
+ // 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*/,
+ __cxx_atomic_contention_t const volatile* __platform_state) {
+ // We will monitor this value.
+ return __cxx_atomic_load(__platform_state, memory_order_acquire);
}
static void __libcpp_contention_wait(__cxx_atomic_contention_t volatile* __contention_state,
__cxx_atomic_contention_t const volatile* __platform_state,
- __cxx_contention_t __old_value)
-{
- __cxx_atomic_fetch_add(__contention_state, __cxx_contention_t(1), memory_order_seq_cst);
- // We sleep as long as the monitored value hasn't changed.
- __libcpp_platform_wait_on_address(__platform_state, __old_value);
- __cxx_atomic_fetch_sub(__contention_state, __cxx_contention_t(1), memory_order_release);
+ __cxx_contention_t __old_value) {
+ __cxx_atomic_fetch_add(__contention_state, __cxx_contention_t(1), memory_order_seq_cst);
+ // We sleep as long as the monitored value hasn't changed.
+ __libcpp_platform_wait_on_address(__platform_state, __old_value);
+ __cxx_atomic_fetch_sub(__contention_state, __cxx_contention_t(1), memory_order_release);
}
/* When the incoming atomic is the wrong size for the platform wait size, need to
launder the value sequence through an atomic from our table. */
-static void __libcpp_atomic_notify(void const volatile* __location)
-{
- auto const __entry = __libcpp_contention_state(__location);
- // The value sequence laundering happens on the next line below.
- __cxx_atomic_fetch_add(&__entry->__platform_state, __cxx_contention_t(1), memory_order_release);
- __libcpp_contention_notify(&__entry->__contention_state,
- &__entry->__platform_state,
- false /* when laundering, we can't handle notify_one */);
-}
-_LIBCPP_EXPORTED_FROM_ABI
-void __cxx_atomic_notify_one(void const volatile* __location)
- { __libcpp_atomic_notify(__location); }
-_LIBCPP_EXPORTED_FROM_ABI
-void __cxx_atomic_notify_all(void const volatile* __location)
- { __libcpp_atomic_notify(__location); }
-_LIBCPP_EXPORTED_FROM_ABI
-__cxx_contention_t __libcpp_atomic_monitor(void const volatile* __location)
-{
- auto const __entry = __libcpp_contention_state(__location);
- return __libcpp_contention_monitor_for_wait(&__entry->__contention_state, &__entry->__platform_state);
-}
-_LIBCPP_EXPORTED_FROM_ABI
-void __libcpp_atomic_wait(void const volatile* __location, __cxx_contention_t __old_value)
-{
- auto const __entry = __libcpp_contention_state(__location);
- __libcpp_contention_wait(&__entry->__contention_state, &__entry->__platform_state, __old_value);
+static void __libcpp_atomic_notify(void const volatile* __location) {
+ auto const __entry = __libcpp_contention_state(__location);
+ // The value sequence laundering happens on the next line below.
+ __cxx_atomic_fetch_add(&__entry->__platform_state, __cxx_contention_t(1), memory_order_release);
+ __libcpp_contention_notify(
+ &__entry->__contention_state,
+ &__entry->__platform_state,
+ false /* when laundering, we can't handle notify_one */);
+}
+_LIBCPP_EXPORTED_FROM_ABI void __cxx_atomic_notify_one(void const volatile* __location) {
+ __libcpp_atomic_notify(__location);
+}
+_LIBCPP_EXPORTED_FROM_ABI void __cxx_atomic_notify_all(void const volatile* __location) {
+ __libcpp_atomic_notify(__location);
+}
+_LIBCPP_EXPORTED_FROM_ABI __cxx_contention_t __libcpp_atomic_monitor(void const volatile* __location) {
+ auto const __entry = __libcpp_contention_state(__location);
+ return __libcpp_contention_monitor_for_wait(&__entry->__contention_state, &__entry->__platform_state);
+}
+_LIBCPP_EXPORTED_FROM_ABI void __libcpp_atomic_wait(void const volatile* __location, __cxx_contention_t __old_value) {
+ auto const __entry = __libcpp_contention_state(__location);
+ __libcpp_contention_wait(&__entry->__contention_state, &__entry->__platform_state, __old_value);
}
/* When the incoming atomic happens to be the platform wait size, we still need to use the
table for the contention detection, but we can use the atomic directly for the wait. */
-_LIBCPP_EXPORTED_FROM_ABI
-void __cxx_atomic_notify_one(__cxx_atomic_contention_t const volatile* __location)
-{
- __libcpp_contention_notify(&__libcpp_contention_state(__location)->__contention_state, __location, true);
+_LIBCPP_EXPORTED_FROM_ABI void __cxx_atomic_notify_one(__cxx_atomic_contention_t const volatile* __location) {
+ __libcpp_contention_notify(&__libcpp_contention_state(__location)->__contention_state, __location, true);
}
-_LIBCPP_EXPORTED_FROM_ABI
-void __cxx_atomic_notify_all(__cxx_atomic_contention_t const volatile* __location)
-{
- __libcpp_contention_notify(&__libcpp_contention_state(__location)->__contention_state, __location, false);
+_LIBCPP_EXPORTED_FROM_ABI void __cxx_atomic_notify_all(__cxx_atomic_contention_t const volatile* __location) {
+ __libcpp_contention_notify(&__libcpp_contention_state(__location)->__contention_state, __location, false);
}
-_LIBCPP_EXPORTED_FROM_ABI
-__cxx_contention_t __libcpp_atomic_monitor(__cxx_atomic_contention_t const volatile* __location)
-{
- return __libcpp_contention_monitor_for_wait(&__libcpp_contention_state(__location)->__contention_state, __location);
+_LIBCPP_EXPORTED_FROM_ABI __cxx_contention_t
+__libcpp_atomic_monitor(__cxx_atomic_contention_t const volatile* __location) {
+ return __libcpp_contention_monitor_for_wait(&__libcpp_contention_state(__location)->__contention_state, __location);
}
-_LIBCPP_EXPORTED_FROM_ABI
-void __libcpp_atomic_wait(__cxx_atomic_contention_t const volatile* __location, __cxx_contention_t __old_value)
-{
- __libcpp_contention_wait(&__libcpp_contention_state(__location)->__contention_state, __location, __old_value);
+_LIBCPP_EXPORTED_FROM_ABI void
+__libcpp_atomic_wait(__cxx_atomic_contention_t const volatile* __location, __cxx_contention_t __old_value) {
+ __libcpp_contention_wait(&__libcpp_contention_state(__location)->__contention_state, __location, __old_value);
}
_LIBCPP_END_NAMESPACE_STD
-
-#endif //_LIBCPP_HAS_NO_THREADS
diff --git a/contrib/llvm-project/libcxx/src/barrier.cpp b/contrib/llvm-project/libcxx/src/barrier.cpp
index 9ee476993b81..baa26101cd57 100644
--- a/contrib/llvm-project/libcxx/src/barrier.cpp
+++ b/contrib/llvm-project/libcxx/src/barrier.cpp
@@ -1,4 +1,4 @@
-//===------------------------- barrier.cpp ---------------------------------===//
+//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -6,92 +6,70 @@
//
//===----------------------------------------------------------------------===//
-#include <__config>
-
-#ifndef _LIBCPP_HAS_NO_THREADS
-
#include <barrier>
#include <thread>
_LIBCPP_BEGIN_NAMESPACE_STD
-#if !defined(_LIBCPP_HAS_NO_TREE_BARRIER) && (_LIBCPP_STD_VER > 11)
+#if !defined(_LIBCPP_HAS_NO_TREE_BARRIER)
class __barrier_algorithm_base {
public:
- struct alignas(64) /* naturally-align the heap state */ __state_t
- {
- struct {
- __atomic_base<__barrier_phase_t> __phase = ATOMIC_VAR_INIT(0);
- } __tickets[64];
- };
+ struct alignas(64) /* naturally-align the heap state */ __state_t {
+ struct {
+ __atomic_base<__barrier_phase_t> __phase{0};
+ } __tickets[64];
+ };
- ptrdiff_t& __expected;
- unique_ptr<__state_t[]> __state;
+ ptrdiff_t& __expected;
+ unique_ptr<__state_t[]> __state;
- _LIBCPP_HIDDEN
- __barrier_algorithm_base(ptrdiff_t& __expected)
- : __expected(__expected)
- {
- size_t const __count = (__expected + 1) >> 1;
- __state = unique_ptr<__state_t[]>(new __state_t[__count]);
- }
- _LIBCPP_HIDDEN
- bool __arrive(__barrier_phase_t __old_phase)
- {
- __barrier_phase_t const __half_step = __old_phase + 1,
- __full_step = __old_phase + 2;
- size_t __current_expected = __expected,
- __current = hash<thread::id>()(this_thread::get_id()) % ((__expected + 1) >> 1);
- for(int __round = 0;; ++__round) {
- if(__current_expected <= 1)
- return true;
- size_t const __end_node = ((__current_expected + 1) >> 1),
- __last_node = __end_node - 1;
- for(;;++__current) {
- if(__current == __end_node)
- __current = 0;
- __barrier_phase_t expect = __old_phase;
- if(__current == __last_node && (__current_expected & 1))
- {
- if(__state[__current].__tickets[__round].__phase.compare_exchange_strong(expect, __full_step, memory_order_acq_rel))
- break; // I'm 1 in 1, go to next __round
- }
- else if(__state[__current].__tickets[__round].__phase.compare_exchange_strong(expect, __half_step, memory_order_acq_rel))
- {
- return false; // I'm 1 in 2, done with arrival
- }
- else if(expect == __half_step)
- {
- if(__state[__current].__tickets[__round].__phase.compare_exchange_strong(expect, __full_step, memory_order_acq_rel))
- break; // I'm 2 in 2, go to next __round
- }
- }
- __current_expected = __last_node + 1;
- __current >>= 1;
+ _LIBCPP_HIDDEN __barrier_algorithm_base(ptrdiff_t& __expected) : __expected(__expected) {
+ size_t const __count = (__expected + 1) >> 1;
+ __state = unique_ptr<__state_t[]>(new __state_t[__count]);
+ }
+ _LIBCPP_HIDDEN bool __arrive(__barrier_phase_t __old_phase) {
+ __barrier_phase_t const __half_step = __old_phase + 1, __full_step = __old_phase + 2;
+ size_t __current_expected = __expected,
+ __current = hash<thread::id>()(this_thread::get_id()) % ((__expected + 1) >> 1);
+ for (int __round = 0;; ++__round) {
+ if (__current_expected <= 1)
+ return true;
+ size_t const __end_node = ((__current_expected + 1) >> 1), __last_node = __end_node - 1;
+ for (;; ++__current) {
+ if (__current == __end_node)
+ __current = 0;
+ __barrier_phase_t expect = __old_phase;
+ if (__current == __last_node && (__current_expected & 1)) {
+ if (__state[__current].__tickets[__round].__phase.compare_exchange_strong(
+ expect, __full_step, memory_order_acq_rel))
+ break; // I'm 1 in 1, go to next __round
+ } else if (__state[__current].__tickets[__round].__phase.compare_exchange_strong(
+ expect, __half_step, memory_order_acq_rel)) {
+ return false; // I'm 1 in 2, done with arrival
+ } else if (expect == __half_step) {
+ if (__state[__current].__tickets[__round].__phase.compare_exchange_strong(
+ expect, __full_step, memory_order_acq_rel))
+ break; // I'm 2 in 2, go to next __round
}
+ }
+ __current_expected = __last_node + 1;
+ __current >>= 1;
}
+ }
};
-_LIBCPP_EXPORTED_FROM_ABI
-__barrier_algorithm_base * __construct_barrier_algorithm_base(ptrdiff_t& __expected)
-{
- return new __barrier_algorithm_base(__expected);
+_LIBCPP_EXPORTED_FROM_ABI __barrier_algorithm_base* __construct_barrier_algorithm_base(ptrdiff_t& __expected) {
+ return new __barrier_algorithm_base(__expected);
}
-_LIBCPP_EXPORTED_FROM_ABI
-bool __arrive_barrier_algorithm_base(__barrier_algorithm_base* __barrier,
- __barrier_phase_t __old_phase)
-{
- return __barrier->__arrive(__old_phase);
+_LIBCPP_EXPORTED_FROM_ABI bool
+__arrive_barrier_algorithm_base(__barrier_algorithm_base* __barrier, __barrier_phase_t __old_phase) {
+ return __barrier->__arrive(__old_phase);
}
-_LIBCPP_EXPORTED_FROM_ABI
-void __destroy_barrier_algorithm_base(__barrier_algorithm_base* __barrier)
-{
- delete __barrier;
+_LIBCPP_EXPORTED_FROM_ABI void __destroy_barrier_algorithm_base(__barrier_algorithm_base* __barrier) {
+ delete __barrier;
}
-#endif //!defined(_LIBCPP_HAS_NO_TREE_BARRIER) && (_LIBCPP_STD_VER >= 11)
+#endif // !defined(_LIBCPP_HAS_NO_TREE_BARRIER)
_LIBCPP_END_NAMESPACE_STD
-
-#endif //_LIBCPP_HAS_NO_THREADS
diff --git a/contrib/llvm-project/libcxx/src/bind.cpp b/contrib/llvm-project/libcxx/src/bind.cpp
index 53efdf9df375..e057395842ec 100644
--- a/contrib/llvm-project/libcxx/src/bind.cpp
+++ b/contrib/llvm-project/libcxx/src/bind.cpp
@@ -1,4 +1,4 @@
-//===-------------------------- bind.cpp ----------------------------------===//
+//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -6,24 +6,23 @@
//
//===----------------------------------------------------------------------===//
-#include "functional"
+#include <functional>
_LIBCPP_BEGIN_NAMESPACE_STD
-namespace placeholders
-{
+namespace placeholders {
-const __ph<1> _1{};
-const __ph<2> _2{};
-const __ph<3> _3{};
-const __ph<4> _4{};
-const __ph<5> _5{};
-const __ph<6> _6{};
-const __ph<7> _7{};
-const __ph<8> _8{};
-const __ph<9> _9{};
+const __ph<1> _1{};
+const __ph<2> _2{};
+const __ph<3> _3{};
+const __ph<4> _4{};
+const __ph<5> _5{};
+const __ph<6> _6{};
+const __ph<7> _7{};
+const __ph<8> _8{};
+const __ph<9> _9{};
const __ph<10> _10{};
-} // placeholders
+} // namespace placeholders
_LIBCPP_END_NAMESPACE_STD
diff --git a/contrib/llvm-project/libcxx/src/call_once.cpp b/contrib/llvm-project/libcxx/src/call_once.cpp
new file mode 100644
index 000000000000..b596518a6540
--- /dev/null
+++ b/contrib/llvm-project/libcxx/src/call_once.cpp
@@ -0,0 +1,70 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 <__mutex/once_flag.h>
+#include <__utility/exception_guard.h>
+
+#ifndef _LIBCPP_HAS_NO_THREADS
+# include <__threading_support>
+#endif
+
+#include "include/atomic_support.h"
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+// If dispatch_once_f ever handles C++ exceptions, and if one can get to it
+// without illegal macros (unexpected macros not beginning with _UpperCase or
+// __lowercase), and if it stops spinning waiting threads, then call_once should
+// call into dispatch_once_f instead of here. Relevant radar this code needs to
+// keep in sync with: 7741191.
+
+#ifndef _LIBCPP_HAS_NO_THREADS
+static constinit __libcpp_mutex_t mut = _LIBCPP_MUTEX_INITIALIZER;
+static constinit __libcpp_condvar_t cv = _LIBCPP_CONDVAR_INITIALIZER;
+#endif
+
+void __call_once(volatile once_flag::_State_type& flag, void* arg, void (*func)(void*)) {
+#if defined(_LIBCPP_HAS_NO_THREADS)
+
+ 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 == once_flag::_Pending)
+ __libcpp_condvar_wait(&cv, &mut);
+ if (flag == once_flag::_Unset) {
+ auto guard = std::__make_exception_guard([&flag] {
+ __libcpp_mutex_lock(&mut);
+ __libcpp_relaxed_store(&flag, once_flag::_Unset);
+ __libcpp_mutex_unlock(&mut);
+ __libcpp_condvar_broadcast(&cv);
+ });
+
+ __libcpp_relaxed_store(&flag, once_flag::_Pending);
+ __libcpp_mutex_unlock(&mut);
+ func(arg);
+ __libcpp_mutex_lock(&mut);
+ __libcpp_atomic_store(&flag, once_flag::_Complete, _AO_Release);
+ __libcpp_mutex_unlock(&mut);
+ __libcpp_condvar_broadcast(&cv);
+ guard.__complete();
+ } else {
+ __libcpp_mutex_unlock(&mut);
+ }
+
+#endif // !_LIBCPP_HAS_NO_THREADS
+}
+
+_LIBCPP_END_NAMESPACE_STD
diff --git a/contrib/llvm-project/libcxx/src/charconv.cpp b/contrib/llvm-project/libcxx/src/charconv.cpp
index 8cfe40d156b2..4fd7a2c2c0f0 100644
--- a/contrib/llvm-project/libcxx/src/charconv.cpp
+++ b/contrib/llvm-project/libcxx/src/charconv.cpp
@@ -1,4 +1,4 @@
-//===------------------------- charconv.cpp -------------------------------===//
+//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -6,155 +6,72 @@
//
//===----------------------------------------------------------------------===//
-#include "charconv"
+#include <charconv>
#include <string.h>
+#include "include/to_chars_floating_point.h"
+
_LIBCPP_BEGIN_NAMESPACE_STD
-namespace __itoa
-{
-
-static constexpr char cDigitsLut[200] = {
- '0', '0', '0', '1', '0', '2', '0', '3', '0', '4', '0', '5', '0', '6', '0',
- '7', '0', '8', '0', '9', '1', '0', '1', '1', '1', '2', '1', '3', '1', '4',
- '1', '5', '1', '6', '1', '7', '1', '8', '1', '9', '2', '0', '2', '1', '2',
- '2', '2', '3', '2', '4', '2', '5', '2', '6', '2', '7', '2', '8', '2', '9',
- '3', '0', '3', '1', '3', '2', '3', '3', '3', '4', '3', '5', '3', '6', '3',
- '7', '3', '8', '3', '9', '4', '0', '4', '1', '4', '2', '4', '3', '4', '4',
- '4', '5', '4', '6', '4', '7', '4', '8', '4', '9', '5', '0', '5', '1', '5',
- '2', '5', '3', '5', '4', '5', '5', '5', '6', '5', '7', '5', '8', '5', '9',
- '6', '0', '6', '1', '6', '2', '6', '3', '6', '4', '6', '5', '6', '6', '6',
- '7', '6', '8', '6', '9', '7', '0', '7', '1', '7', '2', '7', '3', '7', '4',
- '7', '5', '7', '6', '7', '7', '7', '8', '7', '9', '8', '0', '8', '1', '8',
- '2', '8', '3', '8', '4', '8', '5', '8', '6', '8', '7', '8', '8', '8', '9',
- '9', '0', '9', '1', '9', '2', '9', '3', '9', '4', '9', '5', '9', '6', '9',
- '7', '9', '8', '9', '9'};
-
-template <typename T>
-inline _LIBCPP_INLINE_VISIBILITY char*
-append1(char* buffer, T i) noexcept
-{
- *buffer = '0' + static_cast<char>(i);
- return buffer + 1;
-}
+#ifndef _LIBCPP_ABI_DO_NOT_EXPORT_TO_CHARS_BASE_10
+
+namespace __itoa {
+
+_LIBCPP_EXPORTED_FROM_ABI char* __u32toa(uint32_t value, char* buffer) noexcept { return __base_10_u32(buffer, value); }
+
+_LIBCPP_EXPORTED_FROM_ABI char* __u64toa(uint64_t value, char* buffer) noexcept { return __base_10_u64(buffer, value); }
+
+} // namespace __itoa
-template <typename T>
-inline _LIBCPP_INLINE_VISIBILITY char*
-append2(char* buffer, T i) noexcept
-{
- memcpy(buffer, &cDigitsLut[(i)*2], 2);
- return buffer + 2;
+#endif // _LIBCPP_ABI_DO_NOT_EXPORT_TO_CHARS_BASE_10
+
+// The original version of floating-point to_chars was written by Microsoft and
+// contributed with the following license.
+
+// Copyright (c) Microsoft Corporation.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+// This implementation is dedicated to the memory of Mary and Thavatchai.
+
+to_chars_result to_chars(char* __first, char* __last, float __value) {
+ return _Floating_to_chars<_Floating_to_chars_overload::_Plain>(__first, __last, __value, chars_format{}, 0);
}
-template <typename T>
-inline _LIBCPP_INLINE_VISIBILITY char*
-append3(char* buffer, T i) noexcept
-{
- return append2(append1(buffer, (i) / 100), (i) % 100);
+to_chars_result to_chars(char* __first, char* __last, double __value) {
+ return _Floating_to_chars<_Floating_to_chars_overload::_Plain>(__first, __last, __value, chars_format{}, 0);
}
-template <typename T>
-inline _LIBCPP_INLINE_VISIBILITY char*
-append4(char* buffer, T i) noexcept
-{
- return append2(append2(buffer, (i) / 100), (i) % 100);
+to_chars_result to_chars(char* __first, char* __last, long double __value) {
+ return _Floating_to_chars<_Floating_to_chars_overload::_Plain>(
+ __first, __last, static_cast<double>(__value), chars_format{}, 0);
}
-template <typename T>
-inline _LIBCPP_INLINE_VISIBILITY char*
-append2_no_zeros(char* buffer, T v) noexcept
-{
- if (v < 10)
- return append1(buffer, v);
- else
- return append2(buffer, v);
+to_chars_result to_chars(char* __first, char* __last, float __value, chars_format __fmt) {
+ return _Floating_to_chars<_Floating_to_chars_overload::_Format_only>(__first, __last, __value, __fmt, 0);
}
-template <typename T>
-inline _LIBCPP_INLINE_VISIBILITY char*
-append4_no_zeros(char* buffer, T v) noexcept
-{
- if (v < 100)
- return append2_no_zeros(buffer, v);
- else if (v < 1000)
- return append3(buffer, v);
- else
- return append4(buffer, v);
+to_chars_result to_chars(char* __first, char* __last, double __value, chars_format __fmt) {
+ return _Floating_to_chars<_Floating_to_chars_overload::_Format_only>(__first, __last, __value, __fmt, 0);
}
-template <typename T>
-inline _LIBCPP_INLINE_VISIBILITY char*
-append8_no_zeros(char* buffer, T v) noexcept
-{
- if (v < 10000)
- {
- buffer = append4_no_zeros(buffer, v);
- }
- else
- {
- buffer = append4_no_zeros(buffer, v / 10000);
- buffer = append4(buffer, v % 10000);
- }
- return buffer;
+to_chars_result to_chars(char* __first, char* __last, long double __value, chars_format __fmt) {
+ return _Floating_to_chars<_Floating_to_chars_overload::_Format_only>(
+ __first, __last, static_cast<double>(__value), __fmt, 0);
}
-char*
-__u32toa(uint32_t value, char* buffer) _NOEXCEPT
-{
- if (value < 100000000)
- {
- buffer = append8_no_zeros(buffer, value);
- }
- else
- {
- // value = aabbbbcccc in decimal
- const uint32_t a = value / 100000000; // 1 to 42
- value %= 100000000;
-
- buffer = append2_no_zeros(buffer, a);
- buffer = append4(buffer, value / 10000);
- buffer = append4(buffer, value % 10000);
- }
-
- return buffer;
+to_chars_result to_chars(char* __first, char* __last, float __value, chars_format __fmt, int __precision) {
+ return _Floating_to_chars<_Floating_to_chars_overload::_Format_precision>(
+ __first, __last, __value, __fmt, __precision);
}
-char*
-__u64toa(uint64_t value, char* buffer) _NOEXCEPT
-{
- if (value < 100000000)
- {
- uint32_t v = static_cast<uint32_t>(value);
- buffer = append8_no_zeros(buffer, v);
- }
- else if (value < 10000000000000000)
- {
- const uint32_t v0 = static_cast<uint32_t>(value / 100000000);
- const uint32_t v1 = static_cast<uint32_t>(value % 100000000);
-
- buffer = append8_no_zeros(buffer, v0);
- buffer = append4(buffer, v1 / 10000);
- buffer = append4(buffer, v1 % 10000);
- }
- else
- {
- const uint32_t a =
- static_cast<uint32_t>(value / 10000000000000000); // 1 to 1844
- value %= 10000000000000000;
-
- buffer = append4_no_zeros(buffer, a);
-
- const uint32_t v0 = static_cast<uint32_t>(value / 100000000);
- const uint32_t v1 = static_cast<uint32_t>(value % 100000000);
- buffer = append4(buffer, v0 / 10000);
- buffer = append4(buffer, v0 % 10000);
- buffer = append4(buffer, v1 / 10000);
- buffer = append4(buffer, v1 % 10000);
- }
-
- return buffer;
+to_chars_result to_chars(char* __first, char* __last, double __value, chars_format __fmt, int __precision) {
+ return _Floating_to_chars<_Floating_to_chars_overload::_Format_precision>(
+ __first, __last, __value, __fmt, __precision);
}
-} // namespace __itoa
+to_chars_result to_chars(char* __first, char* __last, long double __value, chars_format __fmt, int __precision) {
+ return _Floating_to_chars<_Floating_to_chars_overload::_Format_precision>(
+ __first, __last, static_cast<double>(__value), __fmt, __precision);
+}
_LIBCPP_END_NAMESPACE_STD
diff --git a/contrib/llvm-project/libcxx/src/chrono.cpp b/contrib/llvm-project/libcxx/src/chrono.cpp
index 085fbfde26c1..c5e827c0cb59 100644
--- a/contrib/llvm-project/libcxx/src/chrono.cpp
+++ b/contrib/llvm-project/libcxx/src/chrono.cpp
@@ -1,4 +1,4 @@
-//===------------------------- chrono.cpp ---------------------------------===//
+//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -6,22 +6,33 @@
//
//===----------------------------------------------------------------------===//
-#include "chrono"
-#include "cerrno" // errno
-#include "system_error" // __throw_system_error
-#include <time.h> // clock_gettime and CLOCK_{MONOTONIC,REALTIME,MONOTONIC_RAW}
+#if defined(__MVS__)
+// As part of monotonic clock support on z/OS we need macro _LARGE_TIME_API
+// to be defined before any system header to include definition of struct timespec64.
+# define _LARGE_TIME_API
+#endif
+
+#include <__system_error/system_error.h>
+#include <cerrno> // errno
+#include <chrono>
+
+#if defined(__MVS__)
+# include <__support/ibm/gettod_zos.h> // gettimeofdayMonotonic
+#endif
+
#include "include/apple_availability.h"
+#include <time.h> // clock_gettime and CLOCK_{MONOTONIC,REALTIME,MONOTONIC_RAW}
#if __has_include(<unistd.h>)
-# include <unistd.h>
+# include <unistd.h> // _POSIX_TIMERS
#endif
#if __has_include(<sys/time.h>)
-# include <sys/time.h> // for gettimeofday and timeval
+# include <sys/time.h> // for gettimeofday and timeval
#endif
-#if !defined(__APPLE__) && _POSIX_TIMERS > 0
-# define _LIBCPP_USE_CLOCK_GETTIME
+#if defined(__APPLE__) || defined(__gnu_hurd__) || (defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0)
+# define _LIBCPP_HAS_CLOCK_GETTIME
#endif
#if defined(_LIBCPP_WIN32API)
@@ -33,8 +44,12 @@
# endif
#endif // defined(_LIBCPP_WIN32API)
+#if defined(__Fuchsia__)
+# include <zircon/syscalls.h>
+#endif
+
#if __has_include(<mach/mach_time.h>)
-# include <mach/mach_time.h>
+# include <mach/mach_time.h>
#endif
#if defined(__ELF__) && defined(_LIBCPP_LINK_RT_LIB)
@@ -43,8 +58,7 @@
_LIBCPP_BEGIN_NAMESPACE_STD
-namespace chrono
-{
+namespace chrono {
//
// system_clock
@@ -52,29 +66,53 @@ namespace chrono
#if defined(_LIBCPP_WIN32API)
+# if _WIN32_WINNT < _WIN32_WINNT_WIN8
+
+namespace {
+
+typedef void(WINAPI* GetSystemTimeAsFileTimePtr)(LPFILETIME);
+
+class GetSystemTimeInit {
+public:
+ GetSystemTimeInit() {
+ fp =
+ (GetSystemTimeAsFileTimePtr)GetProcAddress(GetModuleHandleW(L"kernel32.dll"), "GetSystemTimePreciseAsFileTime");
+ if (fp == nullptr)
+ fp = GetSystemTimeAsFileTime;
+ }
+ GetSystemTimeAsFileTimePtr fp;
+};
+
+// Pretend we're inside a system header so the compiler doesn't flag the use of the init_priority
+// attribute with a value that's reserved for the implementation (we're the implementation).
+# include "chrono_system_time_init.h"
+} // namespace
+
+# endif
+
static system_clock::time_point __libcpp_system_clock_now() {
// FILETIME is in 100ns units
using filetime_duration =
- _VSTD::chrono::duration<__int64,
- _VSTD::ratio_multiply<_VSTD::ratio<100, 1>,
- nanoseconds::period>>;
+ std::chrono::duration<__int64, std::ratio_multiply<std::ratio<100, 1>, 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)
+# if (_WIN32_WINNT >= _WIN32_WINNT_WIN8 && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)) || \
+ (_WIN32_WINNT >= _WIN32_WINNT_WIN10)
GetSystemTimePreciseAsFileTime(&ft);
-#else
+# elif !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
GetSystemTimeAsFileTime(&ft);
-#endif
+# else
+ GetSystemTimeAsFileTimeFunc.fp(&ft);
+# endif
- filetime_duration d{(static_cast<__int64>(ft.dwHighDateTime) << 32) |
- static_cast<__int64>(ft.dwLowDateTime)};
+ filetime_duration d{(static_cast<__int64>(ft.dwHighDateTime) << 32) | static_cast<__int64>(ft.dwLowDateTime)};
return system_clock::time_point(duration_cast<system_clock::duration>(d - nt_to_unix_epoch));
}
-#elif defined(CLOCK_REALTIME) && defined(_LIBCPP_USE_CLOCK_GETTIME)
+#elif defined(_LIBCPP_HAS_CLOCK_GETTIME)
static system_clock::time_point __libcpp_system_clock_now() {
struct timespec tp;
@@ -86,32 +124,22 @@ static system_clock::time_point __libcpp_system_clock_now() {
#else
static system_clock::time_point __libcpp_system_clock_now() {
- timeval tv;
- gettimeofday(&tv, 0);
- return system_clock::time_point(seconds(tv.tv_sec) + microseconds(tv.tv_usec));
+ timeval tv;
+ gettimeofday(&tv, 0);
+ return system_clock::time_point(seconds(tv.tv_sec) + microseconds(tv.tv_usec));
}
#endif
const bool system_clock::is_steady;
-system_clock::time_point
-system_clock::now() _NOEXCEPT
-{
- return __libcpp_system_clock_now();
-}
+system_clock::time_point system_clock::now() noexcept { return __libcpp_system_clock_now(); }
-time_t
-system_clock::to_time_t(const time_point& t) _NOEXCEPT
-{
- return time_t(duration_cast<seconds>(t.time_since_epoch()).count());
+time_t system_clock::to_time_t(const time_point& t) noexcept {
+ return time_t(duration_cast<seconds>(t.time_since_epoch()).count());
}
-system_clock::time_point
-system_clock::from_time_t(time_t t) _NOEXCEPT
-{
- return system_clock::time_point(seconds(t));
-}
+system_clock::time_point system_clock::from_time_t(time_t t) noexcept { return system_clock::time_point(seconds(t)); }
//
// steady_clock
@@ -123,60 +151,7 @@ system_clock::from_time_t(time_t t) _NOEXCEPT
#ifndef _LIBCPP_HAS_NO_MONOTONIC_CLOCK
-#if defined(__APPLE__)
-
-// TODO(ldionne):
-// This old implementation of steady_clock is retained until Chrome drops supports
-// for macOS < 10.12. The issue is that they link libc++ statically into their
-// application, which means that libc++ must support being built for such deployment
-// targets. See https://llvm.org/D74489 for details.
-#if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101200) || \
- (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 100000) || \
- (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 100000) || \
- (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 30000)
-# define _LIBCPP_USE_OLD_MACH_ABSOLUTE_TIME
-#endif
-
-#if defined(_LIBCPP_USE_OLD_MACH_ABSOLUTE_TIME)
-
-// mach_absolute_time() * MachInfo.numer / MachInfo.denom is the number of
-// nanoseconds since the computer booted up. MachInfo.numer and MachInfo.denom
-// are run time constants supplied by the OS. This clock has no relationship
-// to the Gregorian calendar. It's main use is as a high resolution timer.
-
-// MachInfo.numer / MachInfo.denom is often 1 on the latest equipment. Specialize
-// for that case as an optimization.
-
-static steady_clock::rep steady_simplified() {
- return static_cast<steady_clock::rep>(mach_absolute_time());
-}
-static double compute_steady_factor() {
- mach_timebase_info_data_t MachInfo;
- mach_timebase_info(&MachInfo);
- return static_cast<double>(MachInfo.numer) / MachInfo.denom;
-}
-
-static steady_clock::rep steady_full() {
- static const double factor = compute_steady_factor();
- return static_cast<steady_clock::rep>(mach_absolute_time() * factor);
-}
-
-typedef steady_clock::rep (*FP)();
-
-static FP init_steady_clock() {
- mach_timebase_info_data_t MachInfo;
- mach_timebase_info(&MachInfo);
- if (MachInfo.numer == MachInfo.denom)
- return &steady_simplified;
- return &steady_full;
-}
-
-static steady_clock::time_point __libcpp_steady_clock_now() {
- static FP fp = init_steady_clock();
- return steady_clock::time_point(steady_clock::duration(fp()));
-}
-
-#else // vvvvv default behavior for Apple platforms vvvvv
+# if defined(__APPLE__)
// On Apple platforms, only CLOCK_UPTIME_RAW, CLOCK_MONOTONIC_RAW or
// mach_absolute_time are able to time functions in the nanosecond range.
@@ -184,63 +159,76 @@ static steady_clock::time_point __libcpp_steady_clock_now() {
// also counts cycles when the system is asleep. Thus, it is the only
// acceptable implementation of steady_clock.
static steady_clock::time_point __libcpp_steady_clock_now() {
- struct timespec tp;
- if (0 != clock_gettime(CLOCK_MONOTONIC_RAW, &tp))
- __throw_system_error(errno, "clock_gettime(CLOCK_MONOTONIC_RAW) failed");
- return steady_clock::time_point(seconds(tp.tv_sec) + nanoseconds(tp.tv_nsec));
+ struct timespec tp;
+ if (0 != clock_gettime(CLOCK_MONOTONIC_RAW, &tp))
+ __throw_system_error(errno, "clock_gettime(CLOCK_MONOTONIC_RAW) failed");
+ return steady_clock::time_point(seconds(tp.tv_sec) + nanoseconds(tp.tv_nsec));
}
-#endif
-
-#elif defined(_LIBCPP_WIN32API)
+# elif defined(_LIBCPP_WIN32API)
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms644905(v=vs.85).aspx says:
// If the function fails, the return value is zero. <snip>
// On systems that run Windows XP or later, the function will always succeed
// and will thus never return zero.
-static LARGE_INTEGER
-__QueryPerformanceFrequency()
-{
- LARGE_INTEGER val;
- (void) QueryPerformanceFrequency(&val);
- return val;
+static LARGE_INTEGER __QueryPerformanceFrequency() {
+ LARGE_INTEGER val;
+ (void)QueryPerformanceFrequency(&val);
+ return val;
}
static steady_clock::time_point __libcpp_steady_clock_now() {
static const LARGE_INTEGER freq = __QueryPerformanceFrequency();
LARGE_INTEGER counter;
- (void) QueryPerformanceCounter(&counter);
- auto seconds = counter.QuadPart / freq.QuadPart;
+ (void)QueryPerformanceCounter(&counter);
+ auto seconds = counter.QuadPart / freq.QuadPart;
auto fractions = counter.QuadPart % freq.QuadPart;
- auto dur = seconds * nano::den + fractions * nano::den / freq.QuadPart;
+ auto dur = seconds * nano::den + fractions * nano::den / freq.QuadPart;
return steady_clock::time_point(steady_clock::duration(dur));
}
-#elif defined(CLOCK_MONOTONIC)
+# elif defined(__MVS__)
static steady_clock::time_point __libcpp_steady_clock_now() {
- struct timespec tp;
- if (0 != clock_gettime(CLOCK_MONOTONIC, &tp))
- __throw_system_error(errno, "clock_gettime(CLOCK_MONOTONIC) failed");
- return steady_clock::time_point(seconds(tp.tv_sec) + nanoseconds(tp.tv_nsec));
+ struct timespec64 ts;
+ if (0 != gettimeofdayMonotonic(&ts))
+ __throw_system_error(errno, "failed to obtain time of day");
+
+ return steady_clock::time_point(seconds(ts.tv_sec) + nanoseconds(ts.tv_nsec));
}
-#else
-# error "Monotonic clock not implemented on this platform"
-#endif
+# elif defined(__Fuchsia__)
-const bool steady_clock::is_steady;
+static steady_clock::time_point __libcpp_steady_clock_now() noexcept {
+ // Implicitly link against the vDSO system call ABI without
+ // requiring the final link to specify -lzircon explicitly when
+ // statically linking libc++.
+# pragma comment(lib, "zircon")
-steady_clock::time_point
-steady_clock::now() _NOEXCEPT
-{
- return __libcpp_steady_clock_now();
+ return steady_clock::time_point(nanoseconds(_zx_clock_get_monotonic()));
}
-#endif // !_LIBCPP_HAS_NO_MONOTONIC_CLOCK
+# elif defined(_LIBCPP_HAS_CLOCK_GETTIME)
+static steady_clock::time_point __libcpp_steady_clock_now() {
+ struct timespec tp;
+ if (0 != clock_gettime(CLOCK_MONOTONIC, &tp))
+ __throw_system_error(errno, "clock_gettime(CLOCK_MONOTONIC) failed");
+ return steady_clock::time_point(seconds(tp.tv_sec) + nanoseconds(tp.tv_nsec));
}
+# else
+# error "Monotonic clock not implemented on this platform"
+# endif
+
+const bool steady_clock::is_steady;
+
+steady_clock::time_point steady_clock::now() noexcept { return __libcpp_steady_clock_now(); }
+
+#endif // !_LIBCPP_HAS_NO_MONOTONIC_CLOCK
+
+} // namespace chrono
+
_LIBCPP_END_NAMESPACE_STD
diff --git a/contrib/llvm-project/libcxx/src/chrono_system_time_init.h b/contrib/llvm-project/libcxx/src/chrono_system_time_init.h
new file mode 100644
index 000000000000..b1bdc691b385
--- /dev/null
+++ b/contrib/llvm-project/libcxx/src/chrono_system_time_init.h
@@ -0,0 +1,2 @@
+#pragma GCC system_header
+GetSystemTimeInit GetSystemTimeAsFileTimeFunc _LIBCPP_INIT_PRIORITY_MAX;
diff --git a/contrib/llvm-project/libcxx/src/condition_variable.cpp b/contrib/llvm-project/libcxx/src/condition_variable.cpp
index d133b010d71f..db60571cf5f5 100644
--- a/contrib/llvm-project/libcxx/src/condition_variable.cpp
+++ b/contrib/llvm-project/libcxx/src/condition_variable.cpp
@@ -1,4 +1,4 @@
-//===-------------------- condition_variable.cpp --------------------------===//
+//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -6,88 +6,66 @@
//
//===----------------------------------------------------------------------===//
-#include "__config"
-
-#ifndef _LIBCPP_HAS_NO_THREADS
-
-#include "condition_variable"
-#include "thread"
-#include "system_error"
-#include "__undef_macros"
+#include <condition_variable>
+#include <thread>
#if defined(__ELF__) && defined(_LIBCPP_LINK_PTHREAD_LIB)
-#pragma comment(lib, "pthread")
+# pragma comment(lib, "pthread")
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
_LIBCPP_BEGIN_NAMESPACE_STD
// ~condition_variable is defined elsewhere.
-void
-condition_variable::notify_one() _NOEXCEPT
-{
- __libcpp_condvar_signal(&__cv_);
-}
+void condition_variable::notify_one() noexcept { __libcpp_condvar_signal(&__cv_); }
-void
-condition_variable::notify_all() _NOEXCEPT
-{
- __libcpp_condvar_broadcast(&__cv_);
-}
+void condition_variable::notify_all() noexcept { __libcpp_condvar_broadcast(&__cv_); }
-void
-condition_variable::wait(unique_lock<mutex>& lk) _NOEXCEPT
-{
- if (!lk.owns_lock())
- __throw_system_error(EPERM,
- "condition_variable::wait: mutex not locked");
- int ec = __libcpp_condvar_wait(&__cv_, lk.mutex()->native_handle());
- if (ec)
- __throw_system_error(ec, "condition_variable wait failed");
+void condition_variable::wait(unique_lock<mutex>& lk) noexcept {
+ if (!lk.owns_lock())
+ __throw_system_error(EPERM, "condition_variable::wait: mutex not locked");
+ int ec = __libcpp_condvar_wait(&__cv_, lk.mutex()->native_handle());
+ if (ec)
+ __throw_system_error(ec, "condition_variable wait failed");
}
-void
-condition_variable::__do_timed_wait(unique_lock<mutex>& lk,
- chrono::time_point<chrono::system_clock, chrono::nanoseconds> tp) _NOEXCEPT
-{
- using namespace chrono;
- if (!lk.owns_lock())
- __throw_system_error(EPERM,
- "condition_variable::timed wait: mutex not locked");
- nanoseconds d = tp.time_since_epoch();
- if (d > nanoseconds(0x59682F000000E941))
- d = nanoseconds(0x59682F000000E941);
- __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();
- if (s.count() < ts_sec_max)
- {
- ts.tv_sec = static_cast<ts_sec>(s.count());
- ts.tv_nsec = static_cast<decltype(ts.tv_nsec)>((d - s).count());
- }
- else
- {
- ts.tv_sec = ts_sec_max;
- ts.tv_nsec = giga::num - 1;
- }
- int ec = __libcpp_condvar_timedwait(&__cv_, lk.mutex()->native_handle(), &ts);
- if (ec != 0 && ec != ETIMEDOUT)
- __throw_system_error(ec, "condition_variable timed_wait failed");
+void condition_variable::__do_timed_wait(unique_lock<mutex>& lk,
+ chrono::time_point<chrono::system_clock, chrono::nanoseconds> tp) noexcept {
+ using namespace chrono;
+ if (!lk.owns_lock())
+ __throw_system_error(EPERM, "condition_variable::timed wait: mutex not locked");
+ nanoseconds d = tp.time_since_epoch();
+ if (d > nanoseconds(0x59682F000000E941))
+ d = nanoseconds(0x59682F000000E941);
+ __libcpp_timespec_t ts;
+ seconds s = duration_cast<seconds>(d);
+ typedef decltype(ts.tv_sec) ts_sec;
+ 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());
+ ts.tv_nsec = static_cast<decltype(ts.tv_nsec)>((d - s).count());
+ } else {
+ ts.tv_sec = ts_sec_max;
+ ts.tv_nsec = giga::num - 1;
+ }
+ int ec = __libcpp_condvar_timedwait(&__cv_, lk.mutex()->native_handle(), &ts);
+ if (ec != 0 && ec != ETIMEDOUT)
+ __throw_system_error(ec, "condition_variable timed_wait failed");
}
-void
-notify_all_at_thread_exit(condition_variable& cond, unique_lock<mutex> lk)
-{
- auto& tl_ptr = __thread_local_data();
- // If this thread was not created using std::thread then it will not have
- // previously allocated.
- if (tl_ptr.get() == nullptr) {
- tl_ptr.set_pointer(new __thread_struct);
- }
- __thread_local_data()->notify_all_at_thread_exit(&cond, lk.release());
+void notify_all_at_thread_exit(condition_variable& cond, unique_lock<mutex> lk) {
+ auto& tl_ptr = __thread_local_data();
+ // If this thread was not created using std::thread then it will not have
+ // previously allocated.
+ if (tl_ptr.get() == nullptr) {
+ tl_ptr.set_pointer(new __thread_struct);
+ }
+ __thread_local_data()->notify_all_at_thread_exit(&cond, lk.release());
}
_LIBCPP_END_NAMESPACE_STD
-#endif // !_LIBCPP_HAS_NO_THREADS
+_LIBCPP_POP_MACROS
diff --git a/contrib/llvm-project/libcxx/src/condition_variable_destructor.cpp b/contrib/llvm-project/libcxx/src/condition_variable_destructor.cpp
index 44fa240ba78b..8b62d4184018 100644
--- a/contrib/llvm-project/libcxx/src/condition_variable_destructor.cpp
+++ b/contrib/llvm-project/libcxx/src/condition_variable_destructor.cpp
@@ -1,4 +1,4 @@
-//===---------------- condition_variable_destructor.cpp ------------------===//
+//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -11,36 +11,30 @@
// On some platforms ~condition_variable has been made trivial and the
// definition is only provided for ABI compatibility.
-#include "__config"
-#include "__threading_support"
+#include <__config>
+#include <__threading_support>
-#if !defined(_LIBCPP_HAS_NO_THREADS)
-# if _LIBCPP_ABI_VERSION == 1 || !defined(_LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION)
-# define NEEDS_CONDVAR_DESTRUCTOR
-# endif
+#if _LIBCPP_ABI_VERSION == 1 || !defined(_LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION)
+# define NEEDS_CONDVAR_DESTRUCTOR
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
#ifdef NEEDS_CONDVAR_DESTRUCTOR
-class _LIBCPP_TYPE_VIS condition_variable
-{
- __libcpp_condvar_t __cv_ = _LIBCPP_CONDVAR_INITIALIZER;
+class _LIBCPP_EXPORTED_FROM_ABI condition_variable {
+ __libcpp_condvar_t __cv_ = _LIBCPP_CONDVAR_INITIALIZER;
+
public:
- _LIBCPP_INLINE_VISIBILITY
- constexpr condition_variable() noexcept = default;
+ _LIBCPP_HIDE_FROM_ABI constexpr condition_variable() noexcept = default;
- ~condition_variable();
+ ~condition_variable();
- condition_variable(const condition_variable&) = delete;
- condition_variable& operator=(const condition_variable&) = delete;
+ condition_variable(const condition_variable&) = delete;
+ condition_variable& operator=(const condition_variable&) = delete;
};
-condition_variable::~condition_variable()
-{
- __libcpp_condvar_destroy(&__cv_);
-}
+condition_variable::~condition_variable() { __libcpp_condvar_destroy(&__cv_); }
#endif
_LIBCPP_END_NAMESPACE_STD
diff --git a/contrib/llvm-project/libcxx/src/debug.cpp b/contrib/llvm-project/libcxx/src/debug.cpp
deleted file mode 100644
index 20055fcf7590..000000000000
--- a/contrib/llvm-project/libcxx/src/debug.cpp
+++ /dev/null
@@ -1,578 +0,0 @@
-//===-------------------------- debug.cpp ---------------------------------===//
-//
-// 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"
-#include "__debug"
-#include "functional"
-#include "algorithm"
-#include "string"
-#include "cstdio"
-#include "__hash_table"
-#ifndef _LIBCPP_HAS_NO_THREADS
-#include "mutex"
-#if defined(__ELF__) && defined(_LIBCPP_LINK_PTHREAD_LIB)
-#pragma comment(lib, "pthread")
-#endif
-#endif
-
-_LIBCPP_BEGIN_NAMESPACE_STD
-
-std::string __libcpp_debug_info::what() const {
- string msg = __file_;
- msg += ":" + to_string(__line_) + ": _LIBCPP_ASSERT '";
- msg += __pred_;
- msg += "' failed. ";
- msg += __msg_;
- return msg;
-}
-_LIBCPP_NORETURN void __libcpp_abort_debug_function(__libcpp_debug_info const& info) {
- std::fprintf(stderr, "%s\n", info.what().c_str());
- std::abort();
-}
-
-_LIBCPP_SAFE_STATIC __libcpp_debug_function_type
- __libcpp_debug_function = __libcpp_abort_debug_function;
-
-bool __libcpp_set_debug_function(__libcpp_debug_function_type __func) {
- __libcpp_debug_function = __func;
- return true;
-}
-
-_LIBCPP_FUNC_VIS
-__libcpp_db*
-__get_db()
-{
- static _LIBCPP_NO_DESTROY __libcpp_db db;
- return &db;
-}
-
-_LIBCPP_FUNC_VIS
-const __libcpp_db*
-__get_const_db()
-{
- return __get_db();
-}
-
-namespace
-{
-
-#ifndef _LIBCPP_HAS_NO_THREADS
-typedef mutex mutex_type;
-typedef lock_guard<mutex_type> WLock;
-typedef lock_guard<mutex_type> RLock;
-
-mutex_type&
-mut()
-{
- static _LIBCPP_NO_DESTROY mutex_type m;
- return m;
-}
-#endif // !_LIBCPP_HAS_NO_THREADS
-
-} // unnamed namespace
-
-__i_node::~__i_node()
-{
- if (__next_)
- {
- __next_->~__i_node();
- free(__next_);
- }
-}
-
-__c_node::~__c_node()
-{
- free(beg_);
- if (__next_)
- {
- __next_->~__c_node();
- free(__next_);
- }
-}
-
-__libcpp_db::__libcpp_db()
- : __cbeg_(nullptr),
- __cend_(nullptr),
- __csz_(0),
- __ibeg_(nullptr),
- __iend_(nullptr),
- __isz_(0)
-{
-}
-
-__libcpp_db::~__libcpp_db()
-{
- if (__cbeg_)
- {
- for (__c_node** p = __cbeg_; p != __cend_; ++p)
- {
- if (*p != nullptr)
- {
- (*p)->~__c_node();
- free(*p);
- }
- }
- free(__cbeg_);
- }
- if (__ibeg_)
- {
- for (__i_node** p = __ibeg_; p != __iend_; ++p)
- {
- if (*p != nullptr)
- {
- (*p)->~__i_node();
- free(*p);
- }
- }
- free(__ibeg_);
- }
-}
-
-void*
-__libcpp_db::__find_c_from_i(void* __i) const
-{
-#ifndef _LIBCPP_HAS_NO_THREADS
- RLock _(mut());
-#endif
- __i_node* i = __find_iterator(__i);
- _LIBCPP_ASSERT(i != nullptr, "iterator not found in debug database.");
- return i->__c_ != nullptr ? i->__c_->__c_ : nullptr;
-}
-
-void
-__libcpp_db::__insert_ic(void* __i, const void* __c)
-{
-#ifndef _LIBCPP_HAS_NO_THREADS
- WLock _(mut());
-#endif
- if (__cbeg_ == __cend_)
- return;
- size_t hc = hash<const void*>()(__c) % static_cast<size_t>(__cend_ - __cbeg_);
- __c_node* c = __cbeg_[hc];
- if (c == nullptr)
- return;
- while (c->__c_ != __c)
- {
- c = c->__next_;
- if (c == nullptr)
- return;
- }
- __i_node* i = __insert_iterator(__i);
- c->__add(i);
- i->__c_ = c;
-}
-
-void
-__libcpp_db::__insert_c(void* __c, __libcpp_db::_InsertConstruct *__fn)
-{
-#ifndef _LIBCPP_HAS_NO_THREADS
- WLock _(mut());
-#endif
- if (__csz_ + 1 > static_cast<size_t>(__cend_ - __cbeg_))
- {
- size_t nc = __next_prime(2*static_cast<size_t>(__cend_ - __cbeg_) + 1);
- __c_node** cbeg = static_cast<__c_node**>(calloc(nc, sizeof(__c_node*)));
- if (cbeg == nullptr)
- __throw_bad_alloc();
-
- for (__c_node** p = __cbeg_; p != __cend_; ++p)
- {
- __c_node* q = *p;
- while (q != nullptr)
- {
- size_t h = hash<void*>()(q->__c_) % nc;
- __c_node* r = q->__next_;
- q->__next_ = cbeg[h];
- cbeg[h] = q;
- q = r;
- }
- }
- free(__cbeg_);
- __cbeg_ = cbeg;
- __cend_ = __cbeg_ + nc;
- }
- size_t hc = hash<void*>()(__c) % static_cast<size_t>(__cend_ - __cbeg_);
- __c_node* p = __cbeg_[hc];
- void *buf = malloc(sizeof(__c_node));
- if (buf == nullptr)
- __throw_bad_alloc();
- __cbeg_[hc] = __fn(buf, __c, p);
-
- ++__csz_;
-}
-
-void
-__libcpp_db::__erase_i(void* __i)
-{
-#ifndef _LIBCPP_HAS_NO_THREADS
- WLock _(mut());
-#endif
- if (__ibeg_ != __iend_)
- {
- size_t hi = hash<void*>()(__i) % static_cast<size_t>(__iend_ - __ibeg_);
- __i_node* p = __ibeg_[hi];
- if (p != nullptr)
- {
- __i_node* q = nullptr;
- while (p->__i_ != __i)
- {
- q = p;
- p = p->__next_;
- if (p == nullptr)
- return;
- }
- if (q == nullptr)
- __ibeg_[hi] = p->__next_;
- else
- q->__next_ = p->__next_;
- __c_node* c = p->__c_;
- --__isz_;
- if (c != nullptr)
- c->__remove(p);
- free(p);
- }
- }
-}
-
-void
-__libcpp_db::__invalidate_all(void* __c)
-{
-#ifndef _LIBCPP_HAS_NO_THREADS
- WLock _(mut());
-#endif
- if (__cend_ != __cbeg_)
- {
- size_t hc = hash<void*>()(__c) % static_cast<size_t>(__cend_ - __cbeg_);
- __c_node* p = __cbeg_[hc];
- if (p == nullptr)
- return;
- while (p->__c_ != __c)
- {
- p = p->__next_;
- if (p == nullptr)
- return;
- }
- while (p->end_ != p->beg_)
- {
- --p->end_;
- (*p->end_)->__c_ = nullptr;
- }
- }
-}
-
-__c_node*
-__libcpp_db::__find_c_and_lock(void* __c) const
-{
-#ifndef _LIBCPP_HAS_NO_THREADS
- mut().lock();
-#endif
- if (__cend_ == __cbeg_)
- {
-#ifndef _LIBCPP_HAS_NO_THREADS
- mut().unlock();
-#endif
- return nullptr;
- }
- size_t hc = hash<void*>()(__c) % static_cast<size_t>(__cend_ - __cbeg_);
- __c_node* p = __cbeg_[hc];
- if (p == nullptr)
- {
-#ifndef _LIBCPP_HAS_NO_THREADS
- mut().unlock();
-#endif
- return nullptr;
- }
- while (p->__c_ != __c)
- {
- p = p->__next_;
- if (p == nullptr)
- {
-#ifndef _LIBCPP_HAS_NO_THREADS
- mut().unlock();
-#endif
- return nullptr;
- }
- }
- return p;
-}
-
-__c_node*
-__libcpp_db::__find_c(void* __c) const
-{
- size_t hc = hash<void*>()(__c) % static_cast<size_t>(__cend_ - __cbeg_);
- __c_node* p = __cbeg_[hc];
- _LIBCPP_ASSERT(p != nullptr, "debug mode internal logic error __find_c A");
- while (p->__c_ != __c)
- {
- p = p->__next_;
- _LIBCPP_ASSERT(p != nullptr, "debug mode internal logic error __find_c B");
- }
- return p;
-}
-
-void
-__libcpp_db::unlock() const
-{
-#ifndef _LIBCPP_HAS_NO_THREADS
- mut().unlock();
-#endif
-}
-
-void
-__libcpp_db::__erase_c(void* __c)
-{
-#ifndef _LIBCPP_HAS_NO_THREADS
- WLock _(mut());
-#endif
- if (__cend_ != __cbeg_)
- {
- size_t hc = hash<void*>()(__c) % static_cast<size_t>(__cend_ - __cbeg_);
- __c_node* p = __cbeg_[hc];
- if (p == nullptr)
- return;
- __c_node* q = nullptr;
- _LIBCPP_ASSERT(p != nullptr, "debug mode internal logic error __erase_c A");
- while (p->__c_ != __c)
- {
- q = p;
- p = p->__next_;
- if (p == nullptr)
- return;
- _LIBCPP_ASSERT(p != nullptr, "debug mode internal logic error __erase_c B");
- }
- if (q == nullptr)
- __cbeg_[hc] = p->__next_;
- else
- q->__next_ = p->__next_;
- while (p->end_ != p->beg_)
- {
- --p->end_;
- (*p->end_)->__c_ = nullptr;
- }
- free(p->beg_);
- free(p);
- --__csz_;
- }
-}
-
-void
-__libcpp_db::__iterator_copy(void* __i, const void* __i0)
-{
-#ifndef _LIBCPP_HAS_NO_THREADS
- WLock _(mut());
-#endif
- __i_node* i = __find_iterator(__i);
- __i_node* i0 = __find_iterator(__i0);
- __c_node* c0 = i0 != nullptr ? i0->__c_ : nullptr;
- if (i == nullptr && i0 != nullptr)
- i = __insert_iterator(__i);
- __c_node* c = i != nullptr ? i->__c_ : nullptr;
- if (c != c0)
- {
- if (c != nullptr)
- c->__remove(i);
- if (i != nullptr)
- {
- i->__c_ = nullptr;
- if (c0 != nullptr)
- {
- i->__c_ = c0;
- i->__c_->__add(i);
- }
- }
- }
-}
-
-bool
-__libcpp_db::__dereferenceable(const void* __i) const
-{
-#ifndef _LIBCPP_HAS_NO_THREADS
- RLock _(mut());
-#endif
- __i_node* i = __find_iterator(__i);
- return i != nullptr && i->__c_ != nullptr && i->__c_->__dereferenceable(__i);
-}
-
-bool
-__libcpp_db::__decrementable(const void* __i) const
-{
-#ifndef _LIBCPP_HAS_NO_THREADS
- RLock _(mut());
-#endif
- __i_node* i = __find_iterator(__i);
- return i != nullptr && i->__c_ != nullptr && i->__c_->__decrementable(__i);
-}
-
-bool
-__libcpp_db::__addable(const void* __i, ptrdiff_t __n) const
-{
-#ifndef _LIBCPP_HAS_NO_THREADS
- RLock _(mut());
-#endif
- __i_node* i = __find_iterator(__i);
- return i != nullptr && i->__c_ != nullptr && i->__c_->__addable(__i, __n);
-}
-
-bool
-__libcpp_db::__subscriptable(const void* __i, ptrdiff_t __n) const
-{
-#ifndef _LIBCPP_HAS_NO_THREADS
- RLock _(mut());
-#endif
- __i_node* i = __find_iterator(__i);
- return i != nullptr && i->__c_ != nullptr && i->__c_->__subscriptable(__i, __n);
-}
-
-bool
-__libcpp_db::__less_than_comparable(const void* __i, const void* __j) const
-{
-#ifndef _LIBCPP_HAS_NO_THREADS
- RLock _(mut());
-#endif
- __i_node* i = __find_iterator(__i);
- __i_node* j = __find_iterator(__j);
- __c_node* ci = i != nullptr ? i->__c_ : nullptr;
- __c_node* cj = j != nullptr ? j->__c_ : nullptr;
- return ci != nullptr && ci == cj;
-}
-
-void
-__libcpp_db::swap(void* c1, void* c2)
-{
-#ifndef _LIBCPP_HAS_NO_THREADS
- WLock _(mut());
-#endif
- size_t hc = hash<void*>()(c1) % static_cast<size_t>(__cend_ - __cbeg_);
- __c_node* p1 = __cbeg_[hc];
- _LIBCPP_ASSERT(p1 != nullptr, "debug mode internal logic error swap A");
- while (p1->__c_ != c1)
- {
- p1 = p1->__next_;
- _LIBCPP_ASSERT(p1 != nullptr, "debug mode internal logic error swap B");
- }
- hc = hash<void*>()(c2) % static_cast<size_t>(__cend_ - __cbeg_);
- __c_node* p2 = __cbeg_[hc];
- _LIBCPP_ASSERT(p2 != nullptr, "debug mode internal logic error swap C");
- while (p2->__c_ != c2)
- {
- p2 = p2->__next_;
- _LIBCPP_ASSERT(p2 != nullptr, "debug mode internal logic error swap D");
- }
- std::swap(p1->beg_, p2->beg_);
- std::swap(p1->end_, p2->end_);
- std::swap(p1->cap_, p2->cap_);
- for (__i_node** p = p1->beg_; p != p1->end_; ++p)
- (*p)->__c_ = p1;
- for (__i_node** p = p2->beg_; p != p2->end_; ++p)
- (*p)->__c_ = p2;
-}
-
-void
-__libcpp_db::__insert_i(void* __i)
-{
-#ifndef _LIBCPP_HAS_NO_THREADS
- WLock _(mut());
-#endif
- __insert_iterator(__i);
-}
-
-void
-__c_node::__add(__i_node* i)
-{
- if (end_ == cap_)
- {
- size_t nc = 2*static_cast<size_t>(cap_ - beg_);
- if (nc == 0)
- nc = 1;
- __i_node** beg =
- static_cast<__i_node**>(malloc(nc * sizeof(__i_node*)));
- if (beg == nullptr)
- __throw_bad_alloc();
-
- if (nc > 1)
- memcpy(beg, beg_, nc/2*sizeof(__i_node*));
- free(beg_);
- beg_ = beg;
- end_ = beg_ + nc/2;
- cap_ = beg_ + nc;
- }
- *end_++ = i;
-}
-
-// private api
-
-_LIBCPP_HIDDEN
-__i_node*
-__libcpp_db::__insert_iterator(void* __i)
-{
- if (__isz_ + 1 > static_cast<size_t>(__iend_ - __ibeg_))
- {
- size_t nc = __next_prime(2*static_cast<size_t>(__iend_ - __ibeg_) + 1);
- __i_node** ibeg = static_cast<__i_node**>(calloc(nc, sizeof(__i_node*)));
- if (ibeg == nullptr)
- __throw_bad_alloc();
-
- for (__i_node** p = __ibeg_; p != __iend_; ++p)
- {
- __i_node* q = *p;
- while (q != nullptr)
- {
- size_t h = hash<void*>()(q->__i_) % nc;
- __i_node* r = q->__next_;
- q->__next_ = ibeg[h];
- ibeg[h] = q;
- q = r;
- }
- }
- free(__ibeg_);
- __ibeg_ = ibeg;
- __iend_ = __ibeg_ + nc;
- }
- size_t hi = hash<void*>()(__i) % static_cast<size_t>(__iend_ - __ibeg_);
- __i_node* p = __ibeg_[hi];
- __i_node* r = __ibeg_[hi] =
- static_cast<__i_node*>(malloc(sizeof(__i_node)));
- if (r == nullptr)
- __throw_bad_alloc();
-
- ::new(r) __i_node(__i, p, nullptr);
- ++__isz_;
- return r;
-}
-
-_LIBCPP_HIDDEN
-__i_node*
-__libcpp_db::__find_iterator(const void* __i) const
-{
- __i_node* r = nullptr;
- if (__ibeg_ != __iend_)
- {
- size_t h = hash<const void*>()(__i) % static_cast<size_t>(__iend_ - __ibeg_);
- for (__i_node* nd = __ibeg_[h]; nd != nullptr; nd = nd->__next_)
- {
- if (nd->__i_ == __i)
- {
- r = nd;
- break;
- }
- }
- }
- return r;
-}
-
-_LIBCPP_HIDDEN
-void
-__c_node::__remove(__i_node* p)
-{
- __i_node** r = find(beg_, end_, p);
- _LIBCPP_ASSERT(r != end_, "debug mode internal logic error __c_node::__remove");
- if (--end_ != r)
- memmove(r, r+1, static_cast<size_t>(end_ - r)*sizeof(__i_node*));
-}
-
-_LIBCPP_END_NAMESPACE_STD
diff --git a/contrib/llvm-project/libcxx/src/error_category.cpp b/contrib/llvm-project/libcxx/src/error_category.cpp
new file mode 100644
index 000000000000..8ae460fb5f1f
--- /dev/null
+++ b/contrib/llvm-project/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/llvm-project/libcxx/src/exception.cpp b/contrib/llvm-project/libcxx/src/exception.cpp
index fce6db7c38b6..ddb186bf8048 100644
--- a/contrib/llvm-project/libcxx/src/exception.cpp
+++ b/contrib/llvm-project/libcxx/src/exception.cpp
@@ -1,4 +1,4 @@
-//===------------------------ exception.cpp -------------------------------===//
+//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -6,30 +6,30 @@
//
//===----------------------------------------------------------------------===//
-#include "exception"
-#include "new"
-#include "typeinfo"
+#include <exception>
+#include <new>
+#include <typeinfo>
#if defined(LIBCXXRT) || defined(LIBCXX_BUILDING_LIBCXXABI)
- #include <cxxabi.h>
- using namespace __cxxabiv1;
- #define HAVE_DEPENDENT_EH_ABI 1
+# include <cxxabi.h>
+using namespace __cxxabiv1;
+# define HAVE_DEPENDENT_EH_ABI 1
#endif
#if defined(_LIBCPP_ABI_MICROSOFT)
-#include "support/runtime/exception_msvc.ipp"
-#include "support/runtime/exception_pointer_msvc.ipp"
+# include "support/runtime/exception_msvc.ipp"
+# include "support/runtime/exception_pointer_msvc.ipp"
#elif defined(_LIBCPPABI_VERSION)
-#include "support/runtime/exception_libcxxabi.ipp"
-#include "support/runtime/exception_pointer_cxxabi.ipp"
+# include "support/runtime/exception_libcxxabi.ipp"
+# include "support/runtime/exception_pointer_cxxabi.ipp"
#elif defined(LIBCXXRT)
-#include "support/runtime/exception_libcxxrt.ipp"
-#include "support/runtime/exception_pointer_cxxabi.ipp"
+# include "support/runtime/exception_libcxxrt.ipp"
+# include "support/runtime/exception_pointer_cxxabi.ipp"
#elif defined(__GLIBCXX__)
-#include "support/runtime/exception_glibcxx.ipp"
-#include "support/runtime/exception_pointer_glibcxx.ipp"
+# include "support/runtime/exception_glibcxx.ipp"
+# include "support/runtime/exception_pointer_glibcxx.ipp"
#else
-#include "include/atomic_support.h"
-#include "support/runtime/exception_fallback.ipp"
-#include "support/runtime/exception_pointer_unimplemented.ipp"
+# include "include/atomic_support.h"
+# include "support/runtime/exception_fallback.ipp"
+# include "support/runtime/exception_pointer_unimplemented.ipp"
#endif
diff --git a/contrib/llvm-project/libcxx/src/utility.cpp b/contrib/llvm-project/libcxx/src/experimental/keep.cpp
index 6a690dc2879e..f3db69d798dd 100644
--- a/contrib/llvm-project/libcxx/src/utility.cpp
+++ b/contrib/llvm-project/libcxx/src/experimental/keep.cpp
@@ -1,4 +1,4 @@
-//===------------------------ utility.cpp ---------------------------------===//
+//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -6,10 +6,5 @@
//
//===----------------------------------------------------------------------===//
-#include "utility"
-
-_LIBCPP_BEGIN_NAMESPACE_STD
-
-const piecewise_construct_t piecewise_construct{};
-
-_LIBCPP_END_NAMESPACE_STD
+// Empty file just to make sure we produce a libc++experimental.a library even
+// when there isn't anything in it.
diff --git a/contrib/llvm-project/libcxx/src/experimental/memory_resource.cpp b/contrib/llvm-project/libcxx/src/experimental/memory_resource.cpp
deleted file mode 100644
index 1304ef3df78f..000000000000
--- a/contrib/llvm-project/libcxx/src/experimental/memory_resource.cpp
+++ /dev/null
@@ -1,151 +0,0 @@
-//===------------------------ memory_resource.cpp -------------------------===//
-//
-// 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 "experimental/memory_resource"
-
-#ifndef _LIBCPP_HAS_NO_ATOMIC_HEADER
-#include "atomic"
-#elif !defined(_LIBCPP_HAS_NO_THREADS)
-#include "mutex"
-#if defined(__ELF__) && defined(_LIBCPP_LINK_PTHREAD_LIB)
-#pragma comment(lib, "pthread")
-#endif
-#endif
-
-_LIBCPP_BEGIN_NAMESPACE_LFTS_PMR
-
-// memory_resource
-
-//memory_resource::~memory_resource() {}
-
-// new_delete_resource()
-
-class _LIBCPP_TYPE_VIS __new_delete_memory_resource_imp
- : public memory_resource
-{
- void *do_allocate(size_t size, size_t align) override {
-#ifdef _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
- if (__is_overaligned_for_new(align))
- __throw_bad_alloc();
-#endif
- return _VSTD::__libcpp_allocate(size, align);
- }
-
- void do_deallocate(void *p, size_t n, size_t align) override {
- _VSTD::__libcpp_deallocate(p, n, align);
- }
-
- bool do_is_equal(memory_resource const & other) const _NOEXCEPT override
- { return &other == this; }
-
-public:
- ~__new_delete_memory_resource_imp() override = default;
-};
-
-// null_memory_resource()
-
-class _LIBCPP_TYPE_VIS __null_memory_resource_imp
- : public memory_resource
-{
-public:
- ~__null_memory_resource_imp() = default;
-
-protected:
- virtual void* do_allocate(size_t, size_t) {
- __throw_bad_alloc();
- }
- virtual void do_deallocate(void *, size_t, size_t) {}
- virtual bool do_is_equal(memory_resource const & __other) const _NOEXCEPT
- { return &__other == this; }
-};
-
-namespace {
-
-union ResourceInitHelper {
- struct {
- __new_delete_memory_resource_imp new_delete_res;
- __null_memory_resource_imp null_res;
- } resources;
- char dummy;
- _LIBCPP_CONSTEXPR_AFTER_CXX11 ResourceInitHelper() : resources() {}
- ~ResourceInitHelper() {}
-};
-
-// When compiled in C++14 this initialization should be a constant expression.
-// Only in C++11 is "init_priority" needed to ensure initialization order.
-#if _LIBCPP_STD_VER > 11
-_LIBCPP_SAFE_STATIC
-#endif
-ResourceInitHelper res_init _LIBCPP_INIT_PRIORITY_MAX;
-
-} // end namespace
-
-
-memory_resource * new_delete_resource() _NOEXCEPT {
- return &res_init.resources.new_delete_res;
-}
-
-memory_resource * null_memory_resource() _NOEXCEPT {
- return &res_init.resources.null_res;
-}
-
-// default_memory_resource()
-
-static memory_resource *
-__default_memory_resource(bool set = false, memory_resource * new_res = nullptr) _NOEXCEPT
-{
-#ifndef _LIBCPP_HAS_NO_ATOMIC_HEADER
- _LIBCPP_SAFE_STATIC static atomic<memory_resource*> __res =
- ATOMIC_VAR_INIT(&res_init.resources.new_delete_res);
- if (set) {
- new_res = new_res ? new_res : new_delete_resource();
- // TODO: Can a weaker ordering be used?
- return _VSTD::atomic_exchange_explicit(
- &__res, new_res, memory_order_acq_rel);
- }
- else {
- return _VSTD::atomic_load_explicit(
- &__res, memory_order_acquire);
- }
-#elif !defined(_LIBCPP_HAS_NO_THREADS)
- _LIBCPP_SAFE_STATIC static memory_resource * res = &res_init.resources.new_delete_res;
- static mutex res_lock;
- if (set) {
- new_res = new_res ? new_res : new_delete_resource();
- lock_guard<mutex> guard(res_lock);
- memory_resource * old_res = res;
- res = new_res;
- return old_res;
- } else {
- lock_guard<mutex> guard(res_lock);
- return res;
- }
-#else
- _LIBCPP_SAFE_STATIC static memory_resource* res = &res_init.resources.new_delete_res;
- if (set) {
- new_res = new_res ? new_res : new_delete_resource();
- memory_resource * old_res = res;
- res = new_res;
- return old_res;
- } else {
- return res;
- }
-#endif
-}
-
-memory_resource * get_default_resource() _NOEXCEPT
-{
- return __default_memory_resource();
-}
-
-memory_resource * set_default_resource(memory_resource * __new_res) _NOEXCEPT
-{
- return __default_memory_resource(true, __new_res);
-}
-
-_LIBCPP_END_NAMESPACE_LFTS_PMR
diff --git a/contrib/llvm-project/libcxx/src/filesystem/directory_entry.cpp b/contrib/llvm-project/libcxx/src/filesystem/directory_entry.cpp
new file mode 100644
index 000000000000..152715243906
--- /dev/null
+++ b/contrib/llvm-project/libcxx/src/filesystem/directory_entry.cpp
@@ -0,0 +1,73 @@
+//===----------------------------------------------------------------------===//
+//
+// 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>
+#include <cstdint>
+#include <filesystem>
+#include <system_error>
+
+#include "file_descriptor.h"
+#include "posix_compat.h"
+#include "time_utils.h"
+
+_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
+
+error_code directory_entry::__do_refresh() noexcept {
+ __data_.__reset();
+ error_code failure_ec;
+
+ detail::StatT full_st;
+ file_status st = detail::posix_lstat(__p_, full_st, &failure_ec);
+ if (!status_known(st)) {
+ __data_.__reset();
+ return failure_ec;
+ }
+
+ if (!filesystem::exists(st) || !filesystem::is_symlink(st)) {
+ __data_.__cache_type_ = directory_entry::_RefreshNonSymlink;
+ __data_.__type_ = st.type();
+ __data_.__non_sym_perms_ = st.permissions();
+ } else { // we have a symlink
+ __data_.__sym_perms_ = st.permissions();
+ // Get the information about the linked entity.
+ // Ignore errors from stat, since we don't want errors regarding symlink
+ // resolution to be reported to the user.
+ error_code ignored_ec;
+ st = detail::posix_stat(__p_, full_st, &ignored_ec);
+
+ __data_.__type_ = st.type();
+ __data_.__non_sym_perms_ = st.permissions();
+
+ // If we failed to resolve the link, then only partially populate the
+ // cache.
+ if (!status_known(st)) {
+ __data_.__cache_type_ = directory_entry::_RefreshSymlinkUnresolved;
+ return error_code{};
+ }
+ // Otherwise, we resolved the link, potentially as not existing.
+ // That's OK.
+ __data_.__cache_type_ = directory_entry::_RefreshSymlink;
+ }
+
+ if (filesystem::is_regular_file(st))
+ __data_.__size_ = static_cast<uintmax_t>(full_st.st_size);
+
+ if (filesystem::exists(st)) {
+ __data_.__nlink_ = static_cast<uintmax_t>(full_st.st_nlink);
+
+ // Attempt to extract the mtime, and fail if it's not representable using
+ // file_time_type. For now we ignore the error, as we'll report it when
+ // the value is actually used.
+ error_code ignored_ec;
+ __data_.__write_time_ = detail::__extract_last_write_time(__p_, full_st, &ignored_ec);
+ }
+
+ return failure_ec;
+}
+
+_LIBCPP_END_NAMESPACE_FILESYSTEM
diff --git a/contrib/llvm-project/libcxx/src/filesystem/directory_iterator.cpp b/contrib/llvm-project/libcxx/src/filesystem/directory_iterator.cpp
index 2721dea5c98f..dceb3486279f 100644
--- a/contrib/llvm-project/libcxx/src/filesystem/directory_iterator.cpp
+++ b/contrib/llvm-project/libcxx/src/filesystem/directory_iterator.cpp
@@ -1,4 +1,4 @@
-//===------------------ directory_iterator.cpp ----------------------------===//
+//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -6,110 +6,36 @@
//
//===----------------------------------------------------------------------===//
-#include "filesystem"
-#include "__config"
-#if defined(_LIBCPP_WIN32API)
-#define WIN32_LEAN_AND_MEAN
-#define NOMINMAX
-#include <windows.h>
-#else
-#include <dirent.h>
-#endif
+#include <__assert>
+#include <__config>
#include <errno.h>
+#include <filesystem>
+#include <stack>
+#include <utility>
-#include "filesystem_common.h"
+#include "error.h"
+#include "file_descriptor.h"
-_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
-
-namespace detail {
-namespace {
-
-#if !defined(_LIBCPP_WIN32API)
-
-#if defined(DT_BLK)
-template <class DirEntT, class = decltype(DirEntT::d_type)>
-static file_type get_file_type(DirEntT* ent, int) {
- switch (ent->d_type) {
- case DT_BLK:
- return file_type::block;
- case DT_CHR:
- return file_type::character;
- case DT_DIR:
- return file_type::directory;
- case DT_FIFO:
- return file_type::fifo;
- case DT_LNK:
- return file_type::symlink;
- case DT_REG:
- return file_type::regular;
- case DT_SOCK:
- return file_type::socket;
- // Unlike in lstat, hitting "unknown" here simply means that the underlying
- // filesystem doesn't support d_type. Report is as 'none' so we correctly
- // set the cache to empty.
- case DT_UNKNOWN:
- break;
- }
- return file_type::none;
-}
-#endif // defined(DT_BLK)
-
-template <class DirEntT>
-static file_type get_file_type(DirEntT* ent, long) {
- return file_type::none;
-}
-
-static pair<string_view, file_type> posix_readdir(DIR* dir_stream,
- error_code& ec) {
- struct dirent* dir_entry_ptr = nullptr;
- errno = 0; // zero errno in order to detect errors
- ec.clear();
- if ((dir_entry_ptr = ::readdir(dir_stream)) == nullptr) {
- if (errno)
- ec = capture_errno();
- return {};
- } else {
- return {dir_entry_ptr->d_name, get_file_type(dir_entry_ptr, 0)};
- }
-}
+#if defined(_LIBCPP_WIN32API)
+# define WIN32_LEAN_AND_MEAN
+# define NOMINMAX
+# include <windows.h>
#else
-// defined(_LIBCPP_WIN32API)
-
-static file_type get_file_type(const WIN32_FIND_DATAW& data) {
- if (data.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT &&
- data.dwReserved0 == IO_REPARSE_TAG_SYMLINK)
- return file_type::symlink;
- if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
- return file_type::directory;
- return file_type::regular;
-}
-static uintmax_t get_file_size(const WIN32_FIND_DATAW& data) {
- return (static_cast<uint64_t>(data.nFileSizeHigh) << 32) + data.nFileSizeLow;
-}
-static file_time_type get_write_time(const WIN32_FIND_DATAW& data) {
- ULARGE_INTEGER tmp;
- const FILETIME& time = data.ftLastWriteTime;
- tmp.u.LowPart = time.dwLowDateTime;
- tmp.u.HighPart = time.dwHighDateTime;
- return file_time_type(file_time_type::duration(tmp.QuadPart));
-}
-
+# include <dirent.h> // for DIR & friends
#endif
-} // namespace
-} // namespace detail
+_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
using detail::ErrorHandler;
#if defined(_LIBCPP_WIN32API)
class __dir_stream {
public:
- __dir_stream() = delete;
+ __dir_stream() = delete;
__dir_stream& operator=(const __dir_stream&) = delete;
- __dir_stream(__dir_stream&& __ds) noexcept : __stream_(__ds.__stream_),
- __root_(move(__ds.__root_)),
- __entry_(move(__ds.__entry_)) {
+ __dir_stream(__dir_stream&& __ds) noexcept
+ : __stream_(__ds.__stream_), __root_(std::move(__ds.__root_)), __entry_(std::move(__ds.__entry_)) {
__ds.__stream_ = INVALID_HANDLE_VALUE;
}
@@ -121,10 +47,9 @@ public:
}
__stream_ = ::FindFirstFileW((root / "*").c_str(), &__data_);
if (__stream_ == INVALID_HANDLE_VALUE) {
- ec = detail::make_windows_error(GetLastError());
- const bool ignore_permission_denied =
- bool(opts & directory_options::skip_permission_denied);
- if (ignore_permission_denied && ec.value() == ERROR_ACCESS_DENIED)
+ ec = detail::make_windows_error(GetLastError());
+ const bool ignore_permission_denied = bool(opts & directory_options::skip_permission_denied);
+ if (ignore_permission_denied && ec.value() == static_cast<int>(errc::permission_denied))
ec.clear();
return;
}
@@ -153,13 +78,12 @@ public:
if (!wcscmp(__data_.cFileName, L".") || !wcscmp(__data_.cFileName, L".."))
return false;
// FIXME: Cache more of this
- //directory_entry::__cached_data cdata;
- //cdata.__type_ = get_file_type(__data_);
- //cdata.__size_ = get_file_size(__data_);
- //cdata.__write_time_ = get_write_time(__data_);
+ // directory_entry::__cached_data cdata;
+ // cdata.__type_ = get_file_type(__data_);
+ // cdata.__size_ = get_file_size(__data_);
+ // cdata.__write_time_ = get_write_time(__data_);
__entry_.__assign_iter_entry(
- __root_ / __data_.cFileName,
- directory_entry::__create_iter_result(detail::get_file_type(__data_)));
+ __root_ / __data_.cFileName, directory_entry::__create_iter_result(detail::get_file_type(__data_)));
return true;
}
@@ -182,22 +106,19 @@ public:
#else
class __dir_stream {
public:
- __dir_stream() = delete;
+ __dir_stream() = delete;
__dir_stream& operator=(const __dir_stream&) = delete;
- __dir_stream(__dir_stream&& other) noexcept : __stream_(other.__stream_),
- __root_(move(other.__root_)),
- __entry_(move(other.__entry_)) {
+ __dir_stream(__dir_stream&& other) noexcept
+ : __stream_(other.__stream_), __root_(std::move(other.__root_)), __entry_(std::move(other.__entry_)) {
other.__stream_ = nullptr;
}
- __dir_stream(const path& root, directory_options opts, error_code& ec)
- : __stream_(nullptr), __root_(root) {
+ __dir_stream(const path& root, directory_options opts, error_code& ec) : __stream_(nullptr), __root_(root) {
if ((__stream_ = ::opendir(root.c_str())) == nullptr) {
- ec = detail::capture_errno();
- const bool allow_eacess =
- bool(opts & directory_options::skip_permission_denied);
- if (allow_eacess && ec.value() == EACCES)
+ ec = detail::capture_errno();
+ const bool allow_eacces = bool(opts & directory_options::skip_permission_denied);
+ if (allow_eacces && ec.value() == EACCES)
ec.clear();
return;
}
@@ -214,16 +135,14 @@ public:
bool advance(error_code& ec) {
while (true) {
auto str_type_pair = detail::posix_readdir(__stream_, ec);
- auto& str = str_type_pair.first;
+ auto& str = str_type_pair.first;
if (str == "." || str == "..") {
continue;
} else if (ec || str.empty()) {
close();
return false;
} else {
- __entry_.__assign_iter_entry(
- __root_ / str,
- directory_entry::__create_iter_result(str_type_pair.second));
+ __entry_.__assign_iter_entry(__root_ / str, directory_entry::__create_iter_result(str_type_pair.second));
return true;
}
}
@@ -248,8 +167,7 @@ public:
// directory_iterator
-directory_iterator::directory_iterator(const path& p, error_code* ec,
- directory_options opts) {
+directory_iterator::directory_iterator(const path& p, error_code* ec, directory_options opts) {
ErrorHandler<void> err("directory_iterator::directory_iterator(...)", ec, &p);
error_code m_ec;
@@ -264,21 +182,21 @@ directory_iterator::directory_iterator(const path& p, error_code* ec,
}
directory_iterator& directory_iterator::__increment(error_code* ec) {
- _LIBCPP_ASSERT(__imp_, "Attempting to increment an invalid iterator");
+ _LIBCPP_ASSERT_NON_NULL(__imp_ != nullptr, "Attempting to increment an invalid iterator");
ErrorHandler<void> err("directory_iterator::operator++()", ec);
error_code m_ec;
if (!__imp_->advance(m_ec)) {
- path root = move(__imp_->__root_);
+ path root = std::move(__imp_->__root_);
__imp_.reset();
if (m_ec)
- err.report(m_ec, "at root \"%s\"", root);
+ err.report(m_ec, "at root " PATH_CSTR_FMT, root.c_str());
}
return *this;
}
directory_entry const& directory_iterator::__dereference() const {
- _LIBCPP_ASSERT(__imp_, "Attempting to dereference an invalid iterator");
+ _LIBCPP_ASSERT_NON_NULL(__imp_ != nullptr, "Attempting to dereference an invalid iterator");
return __imp_->__entry_;
}
@@ -289,8 +207,7 @@ struct recursive_directory_iterator::__shared_imp {
directory_options __options_;
};
-recursive_directory_iterator::recursive_directory_iterator(
- const path& p, directory_options opt, error_code* ec)
+recursive_directory_iterator::recursive_directory_iterator(const path& p, directory_options opt, error_code* ec)
: __imp_(nullptr), __rec_(true) {
ErrorHandler<void> err("recursive_directory_iterator", ec, &p);
@@ -301,13 +218,13 @@ recursive_directory_iterator::recursive_directory_iterator(
if (m_ec || !new_s.good())
return;
- __imp_ = make_shared<__shared_imp>();
+ __imp_ = make_shared<__shared_imp>();
__imp_->__options_ = opt;
- __imp_->__stack_.push(move(new_s));
+ __imp_->__stack_.push(std::move(new_s));
}
void recursive_directory_iterator::__pop(error_code* ec) {
- _LIBCPP_ASSERT(__imp_, "Popping the end iterator");
+ _LIBCPP_ASSERT_NON_NULL(__imp_ != nullptr, "Popping the end iterator");
if (ec)
ec->clear();
__imp_->__stack_.pop();
@@ -317,20 +234,13 @@ void recursive_directory_iterator::__pop(error_code* ec) {
__advance(ec);
}
-directory_options recursive_directory_iterator::options() const {
- return __imp_->__options_;
-}
+directory_options recursive_directory_iterator::options() const { return __imp_->__options_; }
-int recursive_directory_iterator::depth() const {
- return __imp_->__stack_.size() - 1;
-}
+int recursive_directory_iterator::depth() const { return __imp_->__stack_.size() - 1; }
-const directory_entry& recursive_directory_iterator::__dereference() const {
- return __imp_->__stack_.top().__entry_;
-}
+const directory_entry& recursive_directory_iterator::__dereference() const { return __imp_->__stack_.top().__entry_; }
-recursive_directory_iterator&
-recursive_directory_iterator::__increment(error_code* ec) {
+recursive_directory_iterator& recursive_directory_iterator::__increment(error_code* ec) {
if (ec)
ec->clear();
if (recursion_pending()) {
@@ -357,9 +267,9 @@ void recursive_directory_iterator::__advance(error_code* ec) {
}
if (m_ec) {
- path root = move(stack.top().__root_);
+ path root = std::move(stack.top().__root_);
__imp_.reset();
- err.report(m_ec, "at root \"%s\"", root);
+ err.report(m_ec, "at root " PATH_CSTR_FMT, root.c_str());
} else {
__imp_.reset();
}
@@ -391,20 +301,19 @@ bool recursive_directory_iterator::__try_recursion(error_code* ec) {
if (!skip_rec) {
__dir_stream new_it(curr_it.__entry_.path(), __imp_->__options_, m_ec);
if (new_it.good()) {
- __imp_->__stack_.push(move(new_it));
+ __imp_->__stack_.push(std::move(new_it));
return true;
}
}
if (m_ec) {
- const bool allow_eacess =
- bool(__imp_->__options_ & directory_options::skip_permission_denied);
+ const bool allow_eacess = bool(__imp_->__options_ & directory_options::skip_permission_denied);
if (m_ec.value() == EACCES && allow_eacess) {
if (ec)
ec->clear();
} else {
- path at_ent = move(curr_it.__entry_.__p_);
+ path at_ent = std::move(curr_it.__entry_.__p_);
__imp_.reset();
- err.report(m_ec, "attempting recursion into \"%s\"", at_ent);
+ err.report(m_ec, "attempting recursion into " PATH_CSTR_FMT, at_ent.c_str());
}
}
return false;
diff --git a/contrib/llvm-project/libcxx/src/filesystem/error.h b/contrib/llvm-project/libcxx/src/filesystem/error.h
new file mode 100644
index 000000000000..572cc73292a1
--- /dev/null
+++ b/contrib/llvm-project/libcxx/src/filesystem/error.h
@@ -0,0 +1,232 @@
+//===----------------------------------------------------------------------===////
+//
+// 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 FILESYSTEM_ERROR_H
+#define FILESYSTEM_ERROR_H
+
+#include <__assert>
+#include <__config>
+#include <cerrno>
+#include <cstdarg>
+#include <cstddef>
+#include <cstdint>
+#include <filesystem>
+#include <string>
+#include <system_error>
+#include <utility> // __libcpp_unreachable
+
+#include "format_string.h"
+
+#if defined(_LIBCPP_WIN32API)
+# define WIN32_LEAN_AND_MEAN
+# define NOMINMAX
+# include <windows.h> // ERROR_* macros
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
+
+namespace detail {
+
+#if defined(_LIBCPP_WIN32API)
+
+inline errc __win_err_to_errc(int err) {
+ constexpr struct {
+ DWORD win;
+ errc errc;
+ } win_error_mapping[] = {
+ {ERROR_ACCESS_DENIED, errc::permission_denied},
+ {ERROR_ALREADY_EXISTS, errc::file_exists},
+ {ERROR_BAD_NETPATH, errc::no_such_file_or_directory},
+ {ERROR_BAD_PATHNAME, errc::no_such_file_or_directory},
+ {ERROR_BAD_UNIT, errc::no_such_device},
+ {ERROR_BROKEN_PIPE, errc::broken_pipe},
+ {ERROR_BUFFER_OVERFLOW, errc::filename_too_long},
+ {ERROR_BUSY, errc::device_or_resource_busy},
+ {ERROR_BUSY_DRIVE, errc::device_or_resource_busy},
+ {ERROR_CANNOT_MAKE, errc::permission_denied},
+ {ERROR_CANTOPEN, errc::io_error},
+ {ERROR_CANTREAD, errc::io_error},
+ {ERROR_CANTWRITE, errc::io_error},
+ {ERROR_CURRENT_DIRECTORY, errc::permission_denied},
+ {ERROR_DEV_NOT_EXIST, errc::no_such_device},
+ {ERROR_DEVICE_IN_USE, errc::device_or_resource_busy},
+ {ERROR_DIR_NOT_EMPTY, errc::directory_not_empty},
+ {ERROR_DIRECTORY, errc::invalid_argument},
+ {ERROR_DISK_FULL, errc::no_space_on_device},
+ {ERROR_FILE_EXISTS, errc::file_exists},
+ {ERROR_FILE_NOT_FOUND, errc::no_such_file_or_directory},
+ {ERROR_HANDLE_DISK_FULL, errc::no_space_on_device},
+ {ERROR_INVALID_ACCESS, errc::permission_denied},
+ {ERROR_INVALID_DRIVE, errc::no_such_device},
+ {ERROR_INVALID_FUNCTION, errc::function_not_supported},
+ {ERROR_INVALID_HANDLE, errc::invalid_argument},
+ {ERROR_INVALID_NAME, errc::no_such_file_or_directory},
+ {ERROR_INVALID_PARAMETER, errc::invalid_argument},
+ {ERROR_LOCK_VIOLATION, errc::no_lock_available},
+ {ERROR_LOCKED, errc::no_lock_available},
+ {ERROR_NEGATIVE_SEEK, errc::invalid_argument},
+ {ERROR_NOACCESS, errc::permission_denied},
+ {ERROR_NOT_ENOUGH_MEMORY, errc::not_enough_memory},
+ {ERROR_NOT_READY, errc::resource_unavailable_try_again},
+ {ERROR_NOT_SAME_DEVICE, errc::cross_device_link},
+ {ERROR_NOT_SUPPORTED, errc::not_supported},
+ {ERROR_OPEN_FAILED, errc::io_error},
+ {ERROR_OPEN_FILES, errc::device_or_resource_busy},
+ {ERROR_OPERATION_ABORTED, errc::operation_canceled},
+ {ERROR_OUTOFMEMORY, errc::not_enough_memory},
+ {ERROR_PATH_NOT_FOUND, errc::no_such_file_or_directory},
+ {ERROR_READ_FAULT, errc::io_error},
+ {ERROR_REPARSE_TAG_INVALID, errc::invalid_argument},
+ {ERROR_RETRY, errc::resource_unavailable_try_again},
+ {ERROR_SEEK, errc::io_error},
+ {ERROR_SHARING_VIOLATION, errc::permission_denied},
+ {ERROR_TOO_MANY_OPEN_FILES, errc::too_many_files_open},
+ {ERROR_WRITE_FAULT, errc::io_error},
+ {ERROR_WRITE_PROTECT, errc::permission_denied},
+ };
+
+ for (const auto& pair : win_error_mapping)
+ if (pair.win == static_cast<DWORD>(err))
+ return pair.errc;
+ return errc::invalid_argument;
+}
+
+#endif // _LIBCPP_WIN32API
+
+inline error_code capture_errno() {
+ _LIBCPP_ASSERT_INTERNAL(errno != 0, "Expected errno to be non-zero");
+ return error_code(errno, generic_category());
+}
+
+#if defined(_LIBCPP_WIN32API)
+inline error_code make_windows_error(int err) { return make_error_code(__win_err_to_errc(err)); }
+#endif
+
+template <class T>
+T error_value();
+template <>
+inline constexpr void error_value<void>() {}
+template <>
+inline bool error_value<bool>() {
+ return false;
+}
+#if __SIZEOF_SIZE_T__ != __SIZEOF_LONG_LONG__
+template <>
+inline size_t error_value<size_t>() {
+ return size_t(-1);
+}
+#endif
+template <>
+inline uintmax_t error_value<uintmax_t>() {
+ return uintmax_t(-1);
+}
+template <>
+inline constexpr file_time_type error_value<file_time_type>() {
+ return file_time_type::min();
+}
+template <>
+inline path error_value<path>() {
+ return {};
+}
+
+template <class T>
+struct ErrorHandler {
+ const char* func_name_;
+ error_code* ec_ = nullptr;
+ const path* p1_ = nullptr;
+ const path* p2_ = nullptr;
+
+ ErrorHandler(const char* fname, error_code* ec, const path* p1 = nullptr, const path* p2 = nullptr)
+ : func_name_(fname), ec_(ec), p1_(p1), p2_(p2) {
+ if (ec_)
+ ec_->clear();
+ }
+
+ T report(const error_code& ec) const {
+ if (ec_) {
+ *ec_ = ec;
+ return error_value<T>();
+ }
+ string what = string("in ") + func_name_;
+ switch (bool(p1_) + bool(p2_)) {
+ case 0:
+ __throw_filesystem_error(what, ec);
+ case 1:
+ __throw_filesystem_error(what, *p1_, ec);
+ case 2:
+ __throw_filesystem_error(what, *p1_, *p2_, ec);
+ }
+ __libcpp_unreachable();
+ }
+
+ _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 3, 0)
+ void report_impl(const error_code& ec, const char* msg, va_list ap) const {
+ if (ec_) {
+ *ec_ = ec;
+ return;
+ }
+ string what = string("in ") + func_name_ + ": " + detail::vformat_string(msg, ap);
+ switch (bool(p1_) + bool(p2_)) {
+ case 0:
+ __throw_filesystem_error(what, ec);
+ case 1:
+ __throw_filesystem_error(what, *p1_, ec);
+ case 2:
+ __throw_filesystem_error(what, *p1_, *p2_, ec);
+ }
+ __libcpp_unreachable();
+ }
+
+ _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 3, 4)
+ T report(const error_code& ec, const char* msg, ...) const {
+ va_list ap;
+ va_start(ap, msg);
+#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
+ try {
+#endif // _LIBCPP_HAS_NO_EXCEPTIONS
+ report_impl(ec, msg, ap);
+#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
+ } catch (...) {
+ va_end(ap);
+ throw;
+ }
+#endif // _LIBCPP_HAS_NO_EXCEPTIONS
+ va_end(ap);
+ return error_value<T>();
+ }
+
+ T report(errc const& err) const { return report(make_error_code(err)); }
+
+ _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 3, 4)
+ T report(errc const& err, const char* msg, ...) const {
+ va_list ap;
+ va_start(ap, msg);
+#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
+ try {
+#endif // _LIBCPP_HAS_NO_EXCEPTIONS
+ report_impl(make_error_code(err), msg, ap);
+#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
+ } catch (...) {
+ va_end(ap);
+ throw;
+ }
+#endif // _LIBCPP_HAS_NO_EXCEPTIONS
+ va_end(ap);
+ return error_value<T>();
+ }
+
+private:
+ ErrorHandler(ErrorHandler const&) = delete;
+ ErrorHandler& operator=(ErrorHandler const&) = delete;
+};
+
+} // end namespace detail
+
+_LIBCPP_END_NAMESPACE_FILESYSTEM
+
+#endif // FILESYSTEM_ERROR_H
diff --git a/contrib/llvm-project/libcxx/src/filesystem/file_descriptor.h b/contrib/llvm-project/libcxx/src/filesystem/file_descriptor.h
new file mode 100644
index 000000000000..50178ff84e03
--- /dev/null
+++ b/contrib/llvm-project/libcxx/src/filesystem/file_descriptor.h
@@ -0,0 +1,291 @@
+//===----------------------------------------------------------------------===////
+//
+// 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 FILESYSTEM_FILE_DESCRIPTOR_H
+#define FILESYSTEM_FILE_DESCRIPTOR_H
+
+#include <__config>
+#include <cstdint>
+#include <filesystem>
+#include <string_view>
+#include <system_error>
+#include <utility>
+
+#include "error.h"
+#include "posix_compat.h"
+#include "time_utils.h"
+
+#if defined(_LIBCPP_WIN32API)
+# define WIN32_LEAN_AND_MEAN
+# define NOMINMAX
+# include <windows.h>
+#else
+# include <dirent.h> // for DIR & friends
+# include <fcntl.h> // values for fchmodat
+# include <sys/stat.h>
+# include <sys/statvfs.h>
+# include <unistd.h>
+#endif // defined(_LIBCPP_WIN32API)
+
+_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
+
+namespace detail {
+
+#if !defined(_LIBCPP_WIN32API)
+
+# if defined(DT_BLK)
+template <class DirEntT, class = decltype(DirEntT::d_type)>
+file_type get_file_type(DirEntT* ent, int) {
+ switch (ent->d_type) {
+ case DT_BLK:
+ return file_type::block;
+ case DT_CHR:
+ return file_type::character;
+ case DT_DIR:
+ return file_type::directory;
+ case DT_FIFO:
+ return file_type::fifo;
+ case DT_LNK:
+ return file_type::symlink;
+ case DT_REG:
+ return file_type::regular;
+ case DT_SOCK:
+ return file_type::socket;
+ // Unlike in lstat, hitting "unknown" here simply means that the underlying
+ // filesystem doesn't support d_type. Report is as 'none' so we correctly
+ // set the cache to empty.
+ case DT_UNKNOWN:
+ break;
+ }
+ return file_type::none;
+}
+# endif // defined(DT_BLK)
+
+template <class DirEntT>
+file_type get_file_type(DirEntT*, long) {
+ return file_type::none;
+}
+
+inline pair<string_view, file_type> posix_readdir(DIR* dir_stream, error_code& ec) {
+ struct dirent* dir_entry_ptr = nullptr;
+ errno = 0; // zero errno in order to detect errors
+ ec.clear();
+ if ((dir_entry_ptr = ::readdir(dir_stream)) == nullptr) {
+ if (errno)
+ ec = capture_errno();
+ return {};
+ } else {
+ return {dir_entry_ptr->d_name, get_file_type(dir_entry_ptr, 0)};
+ }
+}
+
+#else // _LIBCPP_WIN32API
+
+inline file_type get_file_type(const WIN32_FIND_DATAW& data) {
+ if (data.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT && data.dwReserved0 == IO_REPARSE_TAG_SYMLINK)
+ return file_type::symlink;
+ if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+ return file_type::directory;
+ return file_type::regular;
+}
+inline uintmax_t get_file_size(const WIN32_FIND_DATAW& data) {
+ return (static_cast<uint64_t>(data.nFileSizeHigh) << 32) + data.nFileSizeLow;
+}
+inline file_time_type get_write_time(const WIN32_FIND_DATAW& data) {
+ ULARGE_INTEGER tmp;
+ const FILETIME& time = data.ftLastWriteTime;
+ tmp.u.LowPart = time.dwLowDateTime;
+ tmp.u.HighPart = time.dwHighDateTime;
+ return file_time_type(file_time_type::duration(tmp.QuadPart));
+}
+
+#endif // !_LIBCPP_WIN32API
+
+// POSIX HELPERS
+
+using value_type = path::value_type;
+using string_type = path::string_type;
+
+struct FileDescriptor {
+ const path& name;
+ int fd = -1;
+ StatT m_stat;
+ file_status m_status;
+
+ template <class... Args>
+ static FileDescriptor create(const path* p, error_code& ec, Args... args) {
+ ec.clear();
+ int fd;
+#ifdef _LIBCPP_WIN32API
+ // TODO: most of the filesystem implementation uses native Win32 calls
+ // (mostly via posix_compat.h). However, here we use the C-runtime APIs to
+ // open a file, because we subsequently pass the C-runtime fd to
+ // `std::[io]fstream::__open(int fd)` in order to implement copy_file.
+ //
+ // Because we're calling the windows C-runtime, win32 error codes are
+ // translated into C error numbers by the C runtime, and returned in errno,
+ // rather than being accessible directly via GetLastError.
+ //
+ // Ideally copy_file should be calling the Win32 CopyFile2 function, which
+ // works on paths, not open files -- at which point this FileDescriptor type
+ // will no longer be needed on windows at all.
+ fd = ::_wopen(p->c_str(), args...);
+#else
+ fd = open(p->c_str(), args...);
+#endif
+
+ if (fd == -1) {
+ ec = capture_errno();
+ return FileDescriptor{p};
+ }
+ return FileDescriptor(p, fd);
+ }
+
+ template <class... Args>
+ static FileDescriptor create_with_status(const path* p, error_code& ec, Args... args) {
+ FileDescriptor fd = create(p, ec, args...);
+ if (!ec)
+ fd.refresh_status(ec);
+
+ return fd;
+ }
+
+ file_status get_status() const { return m_status; }
+ StatT const& get_stat() const { return m_stat; }
+
+ bool status_known() const { return filesystem::status_known(m_status); }
+
+ file_status refresh_status(error_code& ec);
+
+ void close() noexcept {
+ if (fd != -1) {
+#ifdef _LIBCPP_WIN32API
+ ::_close(fd);
+#else
+ ::close(fd);
+#endif
+ // FIXME: shouldn't this return an error_code?
+ }
+ fd = -1;
+ }
+
+ FileDescriptor(FileDescriptor&& other)
+ : name(other.name), fd(other.fd), m_stat(other.m_stat), m_status(other.m_status) {
+ other.fd = -1;
+ other.m_status = file_status{};
+ }
+
+ ~FileDescriptor() { close(); }
+
+ FileDescriptor(FileDescriptor const&) = delete;
+ FileDescriptor& operator=(FileDescriptor const&) = delete;
+
+private:
+ explicit FileDescriptor(const path* p, int descriptor = -1) : name(*p), fd(descriptor) {}
+};
+
+inline perms posix_get_perms(const StatT& st) noexcept { return static_cast<perms>(st.st_mode) & perms::mask; }
+
+inline file_status create_file_status(error_code& m_ec, path const& p, const StatT& path_stat, error_code* ec) {
+ if (ec)
+ *ec = m_ec;
+ if (m_ec && (m_ec.value() == ENOENT || m_ec.value() == ENOTDIR)) {
+ return file_status(file_type::not_found);
+ } else if (m_ec) {
+ ErrorHandler<void> err("posix_stat", ec, &p);
+ err.report(m_ec, "failed to determine attributes for the specified path");
+ return file_status(file_type::none);
+ }
+ // else
+
+ file_status fs_tmp;
+ auto const mode = path_stat.st_mode;
+ if (S_ISLNK(mode))
+ fs_tmp.type(file_type::symlink);
+ else if (S_ISREG(mode))
+ fs_tmp.type(file_type::regular);
+ else if (S_ISDIR(mode))
+ fs_tmp.type(file_type::directory);
+ else if (S_ISBLK(mode))
+ fs_tmp.type(file_type::block);
+ else if (S_ISCHR(mode))
+ fs_tmp.type(file_type::character);
+ else if (S_ISFIFO(mode))
+ fs_tmp.type(file_type::fifo);
+ else if (S_ISSOCK(mode))
+ fs_tmp.type(file_type::socket);
+ else
+ fs_tmp.type(file_type::unknown);
+
+ fs_tmp.permissions(detail::posix_get_perms(path_stat));
+ return fs_tmp;
+}
+
+inline file_status posix_stat(path const& p, StatT& path_stat, error_code* ec) {
+ error_code m_ec;
+ if (detail::stat(p.c_str(), &path_stat) == -1)
+ m_ec = detail::capture_errno();
+ return create_file_status(m_ec, p, path_stat, ec);
+}
+
+inline file_status posix_stat(path const& p, error_code* ec) {
+ StatT path_stat;
+ return posix_stat(p, path_stat, ec);
+}
+
+inline file_status posix_lstat(path const& p, StatT& path_stat, error_code* ec) {
+ error_code m_ec;
+ if (detail::lstat(p.c_str(), &path_stat) == -1)
+ m_ec = detail::capture_errno();
+ return create_file_status(m_ec, p, path_stat, ec);
+}
+
+inline file_status posix_lstat(path const& p, error_code* ec) {
+ StatT path_stat;
+ return posix_lstat(p, path_stat, ec);
+}
+
+// http://pubs.opengroup.org/onlinepubs/9699919799/functions/ftruncate.html
+inline bool posix_ftruncate(const FileDescriptor& fd, off_t to_size, error_code& ec) {
+ if (detail::ftruncate(fd.fd, to_size) == -1) {
+ ec = capture_errno();
+ return true;
+ }
+ ec.clear();
+ return false;
+}
+
+inline bool posix_fchmod(const FileDescriptor& fd, const StatT& st, error_code& ec) {
+ if (detail::fchmod(fd.fd, st.st_mode) == -1) {
+ ec = capture_errno();
+ return true;
+ }
+ ec.clear();
+ return false;
+}
+
+inline bool stat_equivalent(const StatT& st1, const StatT& st2) {
+ return (st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino);
+}
+
+inline file_status FileDescriptor::refresh_status(error_code& ec) {
+ // FD must be open and good.
+ m_status = file_status{};
+ m_stat = {};
+ error_code m_ec;
+ if (detail::fstat(fd, &m_stat) == -1)
+ m_ec = capture_errno();
+ m_status = create_file_status(m_ec, name, m_stat, &ec);
+ return m_status;
+}
+
+} // end namespace detail
+
+_LIBCPP_END_NAMESPACE_FILESYSTEM
+
+#endif // FILESYSTEM_FILE_DESCRIPTOR_H
diff --git a/contrib/llvm-project/libcxx/src/filesystem/filesystem_clock.cpp b/contrib/llvm-project/libcxx/src/filesystem/filesystem_clock.cpp
new file mode 100644
index 000000000000..e13b2853e367
--- /dev/null
+++ b/contrib/llvm-project/libcxx/src/filesystem/filesystem_clock.cpp
@@ -0,0 +1,62 @@
+//===----------------------------------------------------------------------===//
+//
+// 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>
+#include <chrono>
+#include <filesystem>
+#include <time.h>
+
+#if defined(_LIBCPP_WIN32API)
+# include "time_utils.h"
+#endif
+
+#if defined(_LIBCPP_WIN32API)
+# define WIN32_LEAN_AND_MEAN
+# define NOMINMAX
+# include <windows.h>
+#endif
+
+#if __has_include(<unistd.h>)
+# include <unistd.h> // _POSIX_TIMERS
+#endif
+
+#if __has_include(<sys/time.h>)
+# include <sys/time.h> // for gettimeofday and timeval
+#endif
+
+#if defined(__APPLE__) || defined(__gnu_hurd__) || (defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0)
+# define _LIBCPP_HAS_CLOCK_GETTIME
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
+
+const bool _FilesystemClock::is_steady;
+
+_FilesystemClock::time_point _FilesystemClock::now() noexcept {
+ typedef chrono::duration<rep> __secs;
+#if defined(_LIBCPP_WIN32API)
+ typedef chrono::duration<rep, nano> __nsecs;
+ FILETIME time;
+ GetSystemTimeAsFileTime(&time);
+ detail::TimeSpec tp = detail::filetime_to_timespec(time);
+ return time_point(__secs(tp.tv_sec) + chrono::duration_cast<duration>(__nsecs(tp.tv_nsec)));
+#elif defined(_LIBCPP_HAS_CLOCK_GETTIME)
+ typedef chrono::duration<rep, nano> __nsecs;
+ struct timespec tp;
+ if (0 != clock_gettime(CLOCK_REALTIME, &tp))
+ __throw_system_error(errno, "clock_gettime(CLOCK_REALTIME) failed");
+ return time_point(__secs(tp.tv_sec) + chrono::duration_cast<duration>(__nsecs(tp.tv_nsec)));
+#else
+ typedef chrono::duration<rep, micro> __microsecs;
+ timeval tv;
+ gettimeofday(&tv, 0);
+ return time_point(__secs(tv.tv_sec) + __microsecs(tv.tv_usec));
+#endif
+}
+
+_LIBCPP_END_NAMESPACE_FILESYSTEM
diff --git a/contrib/llvm-project/libcxx/src/filesystem/filesystem_common.h b/contrib/llvm-project/libcxx/src/filesystem/filesystem_common.h
deleted file mode 100644
index e0fdbccf96b1..000000000000
--- a/contrib/llvm-project/libcxx/src/filesystem/filesystem_common.h
+++ /dev/null
@@ -1,475 +0,0 @@
-//===----------------------------------------------------------------------===////
-//
-// 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 FILESYSTEM_COMMON_H
-#define FILESYSTEM_COMMON_H
-
-#include "__config"
-#include "filesystem"
-#include "array"
-#include "chrono"
-#include "climits"
-#include "cstdlib"
-#include "ctime"
-
-#if !defined(_LIBCPP_WIN32API)
-# include <unistd.h>
-# include <sys/stat.h>
-# include <sys/statvfs.h>
-# include <sys/time.h> // for ::utimes as used in __last_write_time
-# include <fcntl.h> /* values for fchmodat */
-#endif
-
-#include "../include/apple_availability.h"
-
-#if !defined(__APPLE__)
-// We can use the presence of UTIME_OMIT to detect platforms that provide
-// utimensat.
-#if defined(UTIME_OMIT)
-#define _LIBCPP_USE_UTIMENSAT
-#endif
-#endif
-
-#if defined(__GNUC__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wunused-function"
-#endif
-
-#if defined(_LIBCPP_WIN32API)
-#define PS(x) (L##x)
-#else
-#define PS(x) (x)
-#endif
-
-_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
-
-namespace detail {
-
-#if defined(_LIBCPP_WIN32API)
-// Non anonymous, to allow access from two translation units.
-errc __win_err_to_errc(int err);
-#endif
-
-namespace {
-
-static string format_string_imp(const char* msg, ...) {
- // we might need a second shot at this, so pre-emptivly make a copy
- struct GuardVAList {
- va_list& target;
- bool active = true;
- GuardVAList(va_list& tgt) : target(tgt), active(true) {}
- void clear() {
- if (active)
- va_end(target);
- active = false;
- }
- ~GuardVAList() {
- if (active)
- va_end(target);
- }
- };
- va_list args;
- va_start(args, msg);
- GuardVAList args_guard(args);
-
- va_list args_cp;
- va_copy(args_cp, args);
- GuardVAList args_copy_guard(args_cp);
-
- std::string result;
-
- array<char, 256> local_buff;
- size_t size_with_null = local_buff.size();
- auto ret = ::vsnprintf(local_buff.data(), size_with_null, msg, args_cp);
-
- args_copy_guard.clear();
-
- // handle empty expansion
- if (ret == 0)
- return result;
- if (static_cast<size_t>(ret) < size_with_null) {
- result.assign(local_buff.data(), static_cast<size_t>(ret));
- return result;
- }
-
- // we did not provide a long enough buffer on our first attempt. The
- // return value is the number of bytes (excluding the null byte) that are
- // needed for formatting.
- size_with_null = static_cast<size_t>(ret) + 1;
- result.__resize_default_init(size_with_null - 1);
- ret = ::vsnprintf(&result[0], size_with_null, msg, args);
- _LIBCPP_ASSERT(static_cast<size_t>(ret) == (size_with_null - 1), "TODO");
-
- return result;
-}
-
-const path::value_type* unwrap(path::string_type const& s) { return s.c_str(); }
-const path::value_type* unwrap(path const& p) { return p.native().c_str(); }
-template <class Arg>
-Arg const& unwrap(Arg const& a) {
- static_assert(!is_class<Arg>::value, "cannot pass class here");
- return a;
-}
-
-template <class... Args>
-string format_string(const char* fmt, Args const&... args) {
- return format_string_imp(fmt, unwrap(args)...);
-}
-
-error_code capture_errno() {
- _LIBCPP_ASSERT(errno, "Expected errno to be non-zero");
- return error_code(errno, generic_category());
-}
-
-#if defined(_LIBCPP_WIN32API)
-error_code make_windows_error(int err) {
- return make_error_code(__win_err_to_errc(err));
-}
-#endif
-
-template <class T>
-T error_value();
-template <>
-_LIBCPP_CONSTEXPR_AFTER_CXX11 void error_value<void>() {}
-template <>
-bool error_value<bool>() {
- return false;
-}
-#if __SIZEOF_SIZE_T__ != __SIZEOF_LONG_LONG__
-template <>
-size_t error_value<size_t>() {
- return size_t(-1);
-}
-#endif
-template <>
-uintmax_t error_value<uintmax_t>() {
- return uintmax_t(-1);
-}
-template <>
-_LIBCPP_CONSTEXPR_AFTER_CXX11 file_time_type error_value<file_time_type>() {
- return file_time_type::min();
-}
-template <>
-path error_value<path>() {
- return {};
-}
-
-template <class T>
-struct ErrorHandler {
- const char* func_name_;
- error_code* ec_ = nullptr;
- const path* p1_ = nullptr;
- const path* p2_ = nullptr;
-
- ErrorHandler(const char* fname, error_code* ec, const path* p1 = nullptr,
- const path* p2 = nullptr)
- : func_name_(fname), ec_(ec), p1_(p1), p2_(p2) {
- if (ec_)
- ec_->clear();
- }
-
- T report(const error_code& ec) const {
- if (ec_) {
- *ec_ = ec;
- return error_value<T>();
- }
- string what = string("in ") + func_name_;
- switch (bool(p1_) + bool(p2_)) {
- case 0:
- __throw_filesystem_error(what, ec);
- case 1:
- __throw_filesystem_error(what, *p1_, ec);
- case 2:
- __throw_filesystem_error(what, *p1_, *p2_, ec);
- }
- _LIBCPP_UNREACHABLE();
- }
-
- template <class... Args>
- T report(const error_code& ec, const char* msg, Args const&... args) const {
- if (ec_) {
- *ec_ = ec;
- return error_value<T>();
- }
- string what =
- string("in ") + func_name_ + ": " + format_string(msg, args...);
- switch (bool(p1_) + bool(p2_)) {
- case 0:
- __throw_filesystem_error(what, ec);
- case 1:
- __throw_filesystem_error(what, *p1_, ec);
- case 2:
- __throw_filesystem_error(what, *p1_, *p2_, ec);
- }
- _LIBCPP_UNREACHABLE();
- }
-
- T report(errc const& err) const { return report(make_error_code(err)); }
-
- template <class... Args>
- T report(errc const& err, const char* msg, Args const&... args) const {
- return report(make_error_code(err), msg, args...);
- }
-
-private:
- ErrorHandler(ErrorHandler const&) = delete;
- ErrorHandler& operator=(ErrorHandler const&) = delete;
-};
-
-using chrono::duration;
-using chrono::duration_cast;
-
-using TimeSpec = struct timespec;
-using TimeVal = struct timeval;
-using StatT = struct stat;
-
-template <class FileTimeT, class TimeT,
- bool IsFloat = is_floating_point<typename FileTimeT::rep>::value>
-struct time_util_base {
- using rep = typename FileTimeT::rep;
- using fs_duration = typename FileTimeT::duration;
- using fs_seconds = duration<rep>;
- using fs_nanoseconds = duration<rep, nano>;
- using fs_microseconds = duration<rep, micro>;
-
- static constexpr rep max_seconds =
- duration_cast<fs_seconds>(FileTimeT::duration::max()).count();
-
- static constexpr rep max_nsec =
- duration_cast<fs_nanoseconds>(FileTimeT::duration::max() -
- fs_seconds(max_seconds))
- .count();
-
- static constexpr rep min_seconds =
- duration_cast<fs_seconds>(FileTimeT::duration::min()).count();
-
- static constexpr rep min_nsec_timespec =
- duration_cast<fs_nanoseconds>(
- (FileTimeT::duration::min() - fs_seconds(min_seconds)) +
- fs_seconds(1))
- .count();
-
-private:
-#if _LIBCPP_STD_VER > 11 && !defined(_LIBCPP_HAS_NO_CXX14_CONSTEXPR)
- static constexpr fs_duration get_min_nsecs() {
- return duration_cast<fs_duration>(
- fs_nanoseconds(min_nsec_timespec) -
- duration_cast<fs_nanoseconds>(fs_seconds(1)));
- }
- // Static assert that these values properly round trip.
- static_assert(fs_seconds(min_seconds) + get_min_nsecs() ==
- FileTimeT::duration::min(),
- "value doesn't roundtrip");
-
- 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;
- return duration_cast<Years>(fs_seconds(max_seconds)) > Years(250) &&
- duration_cast<Years>(fs_seconds(min_seconds)) < Years(-250);
- }
- return max_seconds >= numeric_limits<TimeT>::max() &&
- min_seconds <= numeric_limits<TimeT>::min();
- }
- static_assert(check_range(), "the representable range is unacceptable small");
-#endif
-};
-
-template <class FileTimeT, class TimeT>
-struct time_util_base<FileTimeT, TimeT, true> {
- using rep = typename FileTimeT::rep;
- using fs_duration = typename FileTimeT::duration;
- using fs_seconds = duration<rep>;
- using fs_nanoseconds = duration<rep, nano>;
- using fs_microseconds = duration<rep, micro>;
-
- static const rep max_seconds;
- static const rep max_nsec;
- static const rep min_seconds;
- static const rep min_nsec_timespec;
-};
-
-template <class FileTimeT, class TimeT>
-const typename FileTimeT::rep
- time_util_base<FileTimeT, TimeT, true>::max_seconds =
- duration_cast<fs_seconds>(FileTimeT::duration::max()).count();
-
-template <class FileTimeT, class TimeT>
-const typename FileTimeT::rep time_util_base<FileTimeT, TimeT, true>::max_nsec =
- duration_cast<fs_nanoseconds>(FileTimeT::duration::max() -
- fs_seconds(max_seconds))
- .count();
-
-template <class FileTimeT, class TimeT>
-const typename FileTimeT::rep
- time_util_base<FileTimeT, TimeT, true>::min_seconds =
- duration_cast<fs_seconds>(FileTimeT::duration::min()).count();
-
-template <class FileTimeT, class TimeT>
-const typename FileTimeT::rep
- time_util_base<FileTimeT, TimeT, true>::min_nsec_timespec =
- duration_cast<fs_nanoseconds>((FileTimeT::duration::min() -
- fs_seconds(min_seconds)) +
- fs_seconds(1))
- .count();
-
-template <class FileTimeT, class TimeT, class TimeSpecT>
-struct time_util : time_util_base<FileTimeT, TimeT> {
- using Base = time_util_base<FileTimeT, TimeT>;
- using Base::max_nsec;
- using Base::max_seconds;
- using Base::min_nsec_timespec;
- using Base::min_seconds;
-
- using typename Base::fs_duration;
- using typename Base::fs_microseconds;
- using typename Base::fs_nanoseconds;
- using typename Base::fs_seconds;
-
-public:
- template <class CType, class ChronoType>
- static _LIBCPP_CONSTEXPR_AFTER_CXX11 bool checked_set(CType* out,
- ChronoType time) {
- using Lim = numeric_limits<CType>;
- if (time > Lim::max() || time < Lim::min())
- return false;
- *out = static_cast<CType>(time);
- return true;
- }
-
- static _LIBCPP_CONSTEXPR_AFTER_CXX11 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);
- } else if (tm.tv_sec == (min_seconds - 1)) {
- return tm.tv_nsec >= min_nsec_timespec;
- } else {
- return tm.tv_sec >= min_seconds;
- }
- }
-
- static _LIBCPP_CONSTEXPR_AFTER_CXX11 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) {
- secs = secs + fs_seconds(1);
- nsecs = nsecs + fs_seconds(1);
- }
- using TLim = numeric_limits<TimeT>;
- if (secs.count() >= 0)
- return secs.count() <= TLim::max();
- return secs.count() >= TLim::min();
- }
-
- static _LIBCPP_CONSTEXPR_AFTER_CXX11 FileTimeT
- convert_from_timespec(TimeSpecT tm) {
- if (tm.tv_sec >= 0 || tm.tv_nsec == 0) {
- return FileTimeT(fs_seconds(tm.tv_sec) +
- duration_cast<fs_duration>(fs_nanoseconds(tm.tv_nsec)));
- } else { // tm.tv_sec < 0
- auto adj_subsec = duration_cast<fs_duration>(fs_seconds(1) -
- fs_nanoseconds(tm.tv_nsec));
- auto Dur = fs_seconds(tm.tv_sec + 1) - adj_subsec;
- return FileTimeT(Dur);
- }
- }
-
- template <class SubSecT>
- static _LIBCPP_CONSTEXPR_AFTER_CXX11 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);
- auto subsec_dur = duration_cast<fs_nanoseconds>(dur - sec_dur);
- // The tv_nsec and tv_usec fields must not be negative so adjust accordingly
- if (subsec_dur.count() < 0) {
- if (sec_dur.count() > min_seconds) {
- sec_dur = sec_dur - fs_seconds(1);
- subsec_dur = subsec_dur + fs_seconds(1);
- } else {
- subsec_dur = fs_nanoseconds::zero();
- }
- }
- return checked_set(sec_out, sec_dur.count()) &&
- checked_set(subsec_out, subsec_dur.count());
- }
- static _LIBCPP_CONSTEXPR_AFTER_CXX11 bool convert_to_timespec(TimeSpecT& dest,
- FileTimeT tp) {
- if (!is_representable(tp))
- return false;
- return set_times_checked(&dest.tv_sec, &dest.tv_nsec, tp);
- }
-};
-
-using fs_time = time_util<file_time_type, time_t, TimeSpec>;
-
-#if defined(__APPLE__)
-inline TimeSpec extract_mtime(StatT const& st) { return st.st_mtimespec; }
-inline TimeSpec extract_atime(StatT const& st) { return st.st_atimespec; }
-#elif defined(__MVS__)
-inline TimeSpec extract_mtime(StatT const& st) {
- TimeSpec TS = {st.st_mtime, 0};
- return TS;
-}
-inline TimeSpec extract_atime(StatT const& st) {
- TimeSpec TS = {st.st_atime, 0};
- return TS;
-}
-#else
-inline TimeSpec extract_mtime(StatT const& st) { return st.st_mtim; }
-inline TimeSpec extract_atime(StatT const& st) { return st.st_atim; }
-#endif
-
-inline TimeVal make_timeval(TimeSpec const& ts) {
- using namespace chrono;
- auto Convert = [](long nsec) {
- using int_type = decltype(std::declval<TimeVal>().tv_usec);
- auto dur = duration_cast<microseconds>(nanoseconds(nsec)).count();
- return static_cast<int_type>(dur);
- };
- TimeVal TV = {};
- TV.tv_sec = ts.tv_sec;
- TV.tv_usec = Convert(ts.tv_nsec);
- return TV;
-}
-
-inline bool posix_utimes(const path& p, std::array<TimeSpec, 2> const& TS,
- error_code& ec) {
- TimeVal ConvertedTS[2] = {make_timeval(TS[0]), make_timeval(TS[1])};
- if (::utimes(p.c_str(), ConvertedTS) == -1) {
- ec = capture_errno();
- return true;
- }
- return false;
-}
-
-#if defined(_LIBCPP_USE_UTIMENSAT)
-bool posix_utimensat(const path& p, std::array<TimeSpec, 2> const& TS,
- error_code& ec) {
- if (::utimensat(AT_FDCWD, p.c_str(), TS.data(), 0) == -1) {
- ec = capture_errno();
- return true;
- }
- return false;
-}
-#endif
-
-bool set_file_times(const path& p, std::array<TimeSpec, 2> const& TS,
- error_code& ec) {
-#if !defined(_LIBCPP_USE_UTIMENSAT)
- return posix_utimes(p, TS, ec);
-#else
- return posix_utimensat(p, TS, ec);
-#endif
-}
-
-} // namespace
-} // end namespace detail
-
-_LIBCPP_END_NAMESPACE_FILESYSTEM
-
-#endif // FILESYSTEM_COMMON_H
diff --git a/contrib/llvm-project/libcxx/src/filesystem/filesystem_error.cpp b/contrib/llvm-project/libcxx/src/filesystem/filesystem_error.cpp
new file mode 100644
index 000000000000..456b902c3315
--- /dev/null
+++ b/contrib/llvm-project/libcxx/src/filesystem/filesystem_error.cpp
@@ -0,0 +1,39 @@
+//===----------------------------------------------------------------------===//
+//
+// 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>
+#include <__utility/unreachable.h>
+#include <filesystem>
+#include <system_error>
+
+#include "format_string.h"
+
+_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
+
+filesystem_error::~filesystem_error() {}
+
+void filesystem_error::__create_what(int __num_paths) {
+ const char* derived_what = system_error::what();
+ __storage_->__what_ = [&]() -> string {
+ switch (__num_paths) {
+ case 0:
+ return detail::format_string("filesystem error: %s", derived_what);
+ case 1:
+ return detail::format_string("filesystem error: %s [" PATH_CSTR_FMT "]", derived_what, path1().c_str());
+ case 2:
+ return detail::format_string(
+ "filesystem error: %s [" PATH_CSTR_FMT "] [" PATH_CSTR_FMT "]",
+ derived_what,
+ path1().c_str(),
+ path2().c_str());
+ }
+ __libcpp_unreachable();
+ }();
+}
+
+_LIBCPP_END_NAMESPACE_FILESYSTEM
diff --git a/contrib/llvm-project/libcxx/src/filesystem/format_string.h b/contrib/llvm-project/libcxx/src/filesystem/format_string.h
new file mode 100644
index 000000000000..a44def86f53e
--- /dev/null
+++ b/contrib/llvm-project/libcxx/src/filesystem/format_string.h
@@ -0,0 +1,77 @@
+//===----------------------------------------------------------------------===////
+//
+// 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 FILESYSTEM_FORMAT_STRING_H
+#define FILESYSTEM_FORMAT_STRING_H
+
+#include <__assert>
+#include <__config>
+#include <array>
+#include <cstdarg>
+#include <cstddef>
+#include <cstdio>
+#include <string>
+
+#if defined(_LIBCPP_WIN32API)
+# define PATHSTR(x) (L##x)
+# define PATH_CSTR_FMT "\"%ls\""
+#else
+# define PATHSTR(x) (x)
+# define PATH_CSTR_FMT "\"%s\""
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
+
+namespace detail {
+
+inline _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 1, 0) string vformat_string(const char* msg, va_list ap) {
+ array<char, 256> buf;
+
+ va_list apcopy;
+ va_copy(apcopy, ap);
+ int ret = ::vsnprintf(buf.data(), buf.size(), msg, apcopy);
+ va_end(apcopy);
+
+ string result;
+ if (static_cast<size_t>(ret) < buf.size()) {
+ result.assign(buf.data(), static_cast<size_t>(ret));
+ } else {
+ // we did not provide a long enough buffer on our first attempt. The
+ // return value is the number of bytes (excluding the null byte) that are
+ // needed for formatting.
+ size_t size_with_null = static_cast<size_t>(ret) + 1;
+ result.__resize_default_init(size_with_null - 1);
+ ret = ::vsnprintf(&result[0], size_with_null, msg, ap);
+ _LIBCPP_ASSERT_INTERNAL(static_cast<size_t>(ret) == (size_with_null - 1), "TODO");
+ }
+ return result;
+}
+
+inline _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 1, 2) string format_string(const char* msg, ...) {
+ string ret;
+ va_list ap;
+ va_start(ap, msg);
+#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
+ try {
+#endif // _LIBCPP_HAS_NO_EXCEPTIONS
+ ret = detail::vformat_string(msg, ap);
+#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
+ } catch (...) {
+ va_end(ap);
+ throw;
+ }
+#endif // _LIBCPP_HAS_NO_EXCEPTIONS
+ va_end(ap);
+ return ret;
+}
+
+} // end namespace detail
+
+_LIBCPP_END_NAMESPACE_FILESYSTEM
+
+#endif // FILESYSTEM_FORMAT_STRING_H
diff --git a/contrib/llvm-project/libcxx/src/filesystem/int128_builtins.cpp b/contrib/llvm-project/libcxx/src/filesystem/int128_builtins.cpp
index ed531ee145a2..72b7cb4a8d1c 100644
--- a/contrib/llvm-project/libcxx/src/filesystem/int128_builtins.cpp
+++ b/contrib/llvm-project/libcxx/src/filesystem/int128_builtins.cpp
@@ -13,18 +13,18 @@
*
* ===----------------------------------------------------------------------===
*/
-#include "__config"
-#include "climits"
+#include <__config>
+#include <climits>
#if !defined(_LIBCPP_HAS_NO_INT128)
-extern "C" __attribute__((no_sanitize("undefined"))) _LIBCPP_FUNC_VIS
-__int128_t __muloti4(__int128_t a, __int128_t b, int* overflow) {
- const int N = (int)(sizeof(__int128_t) * CHAR_BIT);
+extern "C" __attribute__((no_sanitize("undefined"))) _LIBCPP_EXPORTED_FROM_ABI __int128_t
+__muloti4(__int128_t a, __int128_t b, int* overflow) {
+ const int N = (int)(sizeof(__int128_t) * CHAR_BIT);
const __int128_t MIN = (__int128_t)1 << (N - 1);
const __int128_t MAX = ~MIN;
- *overflow = 0;
- __int128_t result = a * b;
+ *overflow = 0;
+ __int128_t result = a * b;
if (a == MIN) {
if (b != 0 && b != 1)
*overflow = 1;
@@ -35,9 +35,9 @@ __int128_t __muloti4(__int128_t a, __int128_t b, int* overflow) {
*overflow = 1;
return result;
}
- __int128_t sa = a >> (N - 1);
+ __int128_t sa = a >> (N - 1);
__int128_t abs_a = (a ^ sa) - sa;
- __int128_t sb = b >> (N - 1);
+ __int128_t sb = b >> (N - 1);
__int128_t abs_b = (b ^ sb) - sb;
if (abs_a < 2 || abs_b < 2)
return result;
diff --git a/contrib/llvm-project/libcxx/src/filesystem/operations.cpp b/contrib/llvm-project/libcxx/src/filesystem/operations.cpp
index 50a895dc2fae..62bb248d5eca 100644
--- a/contrib/llvm-project/libcxx/src/filesystem/operations.cpp
+++ b/contrib/llvm-project/libcxx/src/filesystem/operations.cpp
@@ -1,4 +1,4 @@
-//===--------------------- filesystem/ops.cpp -----------------------------===//
+//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -6,553 +6,54 @@
//
//===----------------------------------------------------------------------===//
-#include "filesystem"
-#include "array"
-#include "iterator"
-#include "string_view"
-#include "type_traits"
-#include "vector"
-#include "cstdlib"
-#include "climits"
-
-#include "filesystem_common.h"
+#include <__assert>
+#include <__config>
+#include <__utility/unreachable.h>
+#include <array>
+#include <climits>
+#include <cstdlib>
+#include <filesystem>
+#include <iterator>
+#include <string_view>
+#include <type_traits>
+#include <vector>
+
+#include "error.h"
+#include "file_descriptor.h"
+#include "path_parser.h"
+#include "posix_compat.h"
+#include "time_utils.h"
#if defined(_LIBCPP_WIN32API)
-# define WIN32_LEAN_AND_MEAN
-# define NOMINMAX
-# include <windows.h>
+# define WIN32_LEAN_AND_MEAN
+# define NOMINMAX
+# include <windows.h>
#else
-# include <unistd.h>
-# include <sys/stat.h>
-# include <sys/statvfs.h>
+# include <dirent.h>
+# include <sys/stat.h>
+# include <sys/statvfs.h>
+# include <unistd.h>
#endif
-#include <time.h>
#include <fcntl.h> /* values for fchmodat */
+#include <time.h>
#if __has_include(<sys/sendfile.h>)
-# include <sys/sendfile.h>
-# define _LIBCPP_FILESYSTEM_USE_SENDFILE
+# include <sys/sendfile.h>
+# define _LIBCPP_FILESYSTEM_USE_SENDFILE
#elif defined(__APPLE__) || __has_include(<copyfile.h>)
-# include <copyfile.h>
-# define _LIBCPP_FILESYSTEM_USE_COPYFILE
+# include <copyfile.h>
+# define _LIBCPP_FILESYSTEM_USE_COPYFILE
#else
-# include "fstream"
-# define _LIBCPP_FILESYSTEM_USE_FSTREAM
-#endif
-
-#if !defined(CLOCK_REALTIME)
-# include <sys/time.h> // for gettimeofday and timeval
+# include <fstream>
+# define _LIBCPP_FILESYSTEM_USE_FSTREAM
#endif
#if defined(__ELF__) && defined(_LIBCPP_LINK_RT_LIB)
-# pragma comment(lib, "rt")
+# pragma comment(lib, "rt")
#endif
_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
-namespace {
-
-bool isSeparator(path::value_type C) {
- if (C == '/')
- return true;
-#if defined(_LIBCPP_WIN32API)
- if (C == '\\')
- return true;
-#endif
- return false;
-}
-
-namespace parser {
-
-using string_view_t = path::__string_view;
-using string_view_pair = pair<string_view_t, string_view_t>;
-using PosPtr = path::value_type const*;
-
-struct PathParser {
- enum ParserState : unsigned char {
- // Zero is a special sentinel value used by default constructed iterators.
- PS_BeforeBegin = path::iterator::_BeforeBegin,
- PS_InRootName = path::iterator::_InRootName,
- PS_InRootDir = path::iterator::_InRootDir,
- PS_InFilenames = path::iterator::_InFilenames,
- PS_InTrailingSep = path::iterator::_InTrailingSep,
- PS_AtEnd = path::iterator::_AtEnd
- };
-
- const string_view_t Path;
- string_view_t RawEntry;
- ParserState State;
-
-private:
- PathParser(string_view_t P, ParserState State) noexcept : Path(P),
- State(State) {}
-
-public:
- PathParser(string_view_t P, string_view_t E, unsigned char S)
- : Path(P), RawEntry(E), State(static_cast<ParserState>(S)) {
- // S cannot be '0' or PS_BeforeBegin.
- }
-
- static PathParser CreateBegin(string_view_t P) noexcept {
- PathParser PP(P, PS_BeforeBegin);
- PP.increment();
- return PP;
- }
-
- static PathParser CreateEnd(string_view_t P) noexcept {
- PathParser PP(P, PS_AtEnd);
- return PP;
- }
-
- PosPtr peek() const noexcept {
- auto TkEnd = getNextTokenStartPos();
- auto End = getAfterBack();
- return TkEnd == End ? nullptr : TkEnd;
- }
-
- void increment() noexcept {
- const PosPtr End = getAfterBack();
- const PosPtr Start = getNextTokenStartPos();
- if (Start == End)
- return makeState(PS_AtEnd);
-
- switch (State) {
- case PS_BeforeBegin: {
- PosPtr TkEnd = consumeSeparator(Start, End);
- if (TkEnd)
- return makeState(PS_InRootDir, Start, TkEnd);
- else
- return makeState(PS_InFilenames, Start, consumeName(Start, End));
- }
- case PS_InRootDir:
- return makeState(PS_InFilenames, Start, consumeName(Start, End));
-
- case PS_InFilenames: {
- PosPtr SepEnd = consumeSeparator(Start, End);
- if (SepEnd != End) {
- PosPtr TkEnd = consumeName(SepEnd, End);
- if (TkEnd)
- return makeState(PS_InFilenames, SepEnd, TkEnd);
- }
- return makeState(PS_InTrailingSep, Start, SepEnd);
- }
-
- case PS_InTrailingSep:
- return makeState(PS_AtEnd);
-
- case PS_InRootName:
- case PS_AtEnd:
- _LIBCPP_UNREACHABLE();
- }
- }
-
- void decrement() noexcept {
- const PosPtr REnd = getBeforeFront();
- const PosPtr RStart = getCurrentTokenStartPos() - 1;
- if (RStart == REnd) // we're decrementing the begin
- return makeState(PS_BeforeBegin);
-
- switch (State) {
- case PS_AtEnd: {
- // Try to consume a trailing separator or root directory first.
- if (PosPtr SepEnd = consumeSeparator(RStart, REnd)) {
- if (SepEnd == REnd)
- return makeState(PS_InRootDir, Path.data(), RStart + 1);
- return makeState(PS_InTrailingSep, SepEnd + 1, RStart + 1);
- } else {
- PosPtr TkStart = consumeName(RStart, REnd);
- return makeState(PS_InFilenames, TkStart + 1, RStart + 1);
- }
- }
- case PS_InTrailingSep:
- return makeState(PS_InFilenames, consumeName(RStart, REnd) + 1,
- RStart + 1);
- case PS_InFilenames: {
- PosPtr SepEnd = consumeSeparator(RStart, REnd);
- if (SepEnd == REnd)
- return makeState(PS_InRootDir, Path.data(), RStart + 1);
- PosPtr TkEnd = consumeName(SepEnd, REnd);
- return makeState(PS_InFilenames, TkEnd + 1, SepEnd + 1);
- }
- case PS_InRootDir:
- // return makeState(PS_InRootName, Path.data(), RStart + 1);
- case PS_InRootName:
- case PS_BeforeBegin:
- _LIBCPP_UNREACHABLE();
- }
- }
-
- /// \brief Return a view with the "preferred representation" of the current
- /// element. For example trailing separators are represented as a '.'
- string_view_t operator*() const noexcept {
- switch (State) {
- case PS_BeforeBegin:
- case PS_AtEnd:
- return PS("");
- case PS_InRootDir:
- if (RawEntry[0] == '\\')
- return PS("\\");
- else
- return PS("/");
- case PS_InTrailingSep:
- return PS("");
- case PS_InRootName:
- case PS_InFilenames:
- return RawEntry;
- }
- _LIBCPP_UNREACHABLE();
- }
-
- explicit operator bool() const noexcept {
- return State != PS_BeforeBegin && State != PS_AtEnd;
- }
-
- PathParser& operator++() noexcept {
- increment();
- return *this;
- }
-
- PathParser& operator--() noexcept {
- decrement();
- return *this;
- }
-
- bool atEnd() const noexcept {
- return State == PS_AtEnd;
- }
-
- bool inRootDir() const noexcept {
- return State == PS_InRootDir;
- }
-
- bool inRootName() const noexcept {
- return State == PS_InRootName;
- }
-
- bool inRootPath() const noexcept {
- return inRootName() || inRootDir();
- }
-
-private:
- void makeState(ParserState NewState, PosPtr Start, PosPtr End) noexcept {
- State = NewState;
- RawEntry = string_view_t(Start, End - Start);
- }
- void makeState(ParserState NewState) noexcept {
- State = NewState;
- RawEntry = {};
- }
-
- PosPtr getAfterBack() const noexcept { return Path.data() + Path.size(); }
-
- PosPtr getBeforeFront() const noexcept { return Path.data() - 1; }
-
- /// \brief Return a pointer to the first character after the currently
- /// lexed element.
- PosPtr getNextTokenStartPos() const noexcept {
- switch (State) {
- case PS_BeforeBegin:
- return Path.data();
- case PS_InRootName:
- case PS_InRootDir:
- case PS_InFilenames:
- return &RawEntry.back() + 1;
- case PS_InTrailingSep:
- case PS_AtEnd:
- return getAfterBack();
- }
- _LIBCPP_UNREACHABLE();
- }
-
- /// \brief Return a pointer to the first character in the currently lexed
- /// element.
- PosPtr getCurrentTokenStartPos() const noexcept {
- switch (State) {
- case PS_BeforeBegin:
- case PS_InRootName:
- return &Path.front();
- case PS_InRootDir:
- case PS_InFilenames:
- case PS_InTrailingSep:
- return &RawEntry.front();
- case PS_AtEnd:
- return &Path.back() + 1;
- }
- _LIBCPP_UNREACHABLE();
- }
-
- PosPtr consumeSeparator(PosPtr P, PosPtr End) const noexcept {
- if (P == End || !isSeparator(*P))
- return nullptr;
- const int Inc = P < End ? 1 : -1;
- P += Inc;
- while (P != End && isSeparator(*P))
- P += Inc;
- return P;
- }
-
- PosPtr consumeName(PosPtr P, PosPtr End) const noexcept {
- if (P == End || isSeparator(*P))
- return nullptr;
- const int Inc = P < End ? 1 : -1;
- P += Inc;
- while (P != End && !isSeparator(*P))
- P += Inc;
- return P;
- }
-};
-
-string_view_pair separate_filename(string_view_t const& s) {
- if (s == PS(".") || s == PS("..") || s.empty())
- return string_view_pair{s, PS("")};
- auto pos = s.find_last_of('.');
- if (pos == string_view_t::npos || pos == 0)
- return string_view_pair{s, string_view_t{}};
- return string_view_pair{s.substr(0, pos), s.substr(pos)};
-}
-
-string_view_t createView(PosPtr S, PosPtr E) noexcept {
- return {S, static_cast<size_t>(E - S) + 1};
-}
-
-} // namespace parser
-} // namespace
-
-// POSIX HELPERS
-
-#if defined(_LIBCPP_WIN32API)
-namespace detail {
-
-errc __win_err_to_errc(int err) {
- constexpr struct {
- DWORD win;
- errc errc;
- } win_error_mapping[] = {
- {ERROR_ACCESS_DENIED, errc::permission_denied},
- {ERROR_ALREADY_EXISTS, errc::file_exists},
- {ERROR_BAD_NETPATH, errc::no_such_file_or_directory},
- {ERROR_BAD_UNIT, errc::no_such_device},
- {ERROR_BROKEN_PIPE, errc::broken_pipe},
- {ERROR_BUFFER_OVERFLOW, errc::filename_too_long},
- {ERROR_BUSY, errc::device_or_resource_busy},
- {ERROR_BUSY_DRIVE, errc::device_or_resource_busy},
- {ERROR_CANNOT_MAKE, errc::permission_denied},
- {ERROR_CANTOPEN, errc::io_error},
- {ERROR_CANTREAD, errc::io_error},
- {ERROR_CANTWRITE, errc::io_error},
- {ERROR_CURRENT_DIRECTORY, errc::permission_denied},
- {ERROR_DEV_NOT_EXIST, errc::no_such_device},
- {ERROR_DEVICE_IN_USE, errc::device_or_resource_busy},
- {ERROR_DIR_NOT_EMPTY, errc::directory_not_empty},
- {ERROR_DIRECTORY, errc::invalid_argument},
- {ERROR_DISK_FULL, errc::no_space_on_device},
- {ERROR_FILE_EXISTS, errc::file_exists},
- {ERROR_FILE_NOT_FOUND, errc::no_such_file_or_directory},
- {ERROR_HANDLE_DISK_FULL, errc::no_space_on_device},
- {ERROR_INVALID_ACCESS, errc::permission_denied},
- {ERROR_INVALID_DRIVE, errc::no_such_device},
- {ERROR_INVALID_FUNCTION, errc::function_not_supported},
- {ERROR_INVALID_HANDLE, errc::invalid_argument},
- {ERROR_INVALID_NAME, errc::no_such_file_or_directory},
- {ERROR_INVALID_PARAMETER, errc::invalid_argument},
- {ERROR_LOCK_VIOLATION, errc::no_lock_available},
- {ERROR_LOCKED, errc::no_lock_available},
- {ERROR_NEGATIVE_SEEK, errc::invalid_argument},
- {ERROR_NOACCESS, errc::permission_denied},
- {ERROR_NOT_ENOUGH_MEMORY, errc::not_enough_memory},
- {ERROR_NOT_READY, errc::resource_unavailable_try_again},
- {ERROR_NOT_SAME_DEVICE, errc::cross_device_link},
- {ERROR_NOT_SUPPORTED, errc::not_supported},
- {ERROR_OPEN_FAILED, errc::io_error},
- {ERROR_OPEN_FILES, errc::device_or_resource_busy},
- {ERROR_OPERATION_ABORTED, errc::operation_canceled},
- {ERROR_OUTOFMEMORY, errc::not_enough_memory},
- {ERROR_PATH_NOT_FOUND, errc::no_such_file_or_directory},
- {ERROR_READ_FAULT, errc::io_error},
- {ERROR_REPARSE_TAG_INVALID, errc::invalid_argument},
- {ERROR_RETRY, errc::resource_unavailable_try_again},
- {ERROR_SEEK, errc::io_error},
- {ERROR_SHARING_VIOLATION, errc::permission_denied},
- {ERROR_TOO_MANY_OPEN_FILES, errc::too_many_files_open},
- {ERROR_WRITE_FAULT, errc::io_error},
- {ERROR_WRITE_PROTECT, errc::permission_denied},
- };
-
- for (const auto &pair : win_error_mapping)
- if (pair.win == static_cast<DWORD>(err))
- return pair.errc;
- return errc::invalid_argument;
-}
-
-} // namespace detail
-#endif
-
-namespace detail {
-namespace {
-
-using value_type = path::value_type;
-using string_type = path::string_type;
-
-struct FileDescriptor {
- const path& name;
- int fd = -1;
- StatT m_stat;
- file_status m_status;
-
- template <class... Args>
- static FileDescriptor create(const path* p, error_code& ec, Args... args) {
- ec.clear();
- int fd;
- if ((fd = ::open(p->c_str(), args...)) == -1) {
- ec = capture_errno();
- return FileDescriptor{p};
- }
- return FileDescriptor(p, fd);
- }
-
- template <class... Args>
- static FileDescriptor create_with_status(const path* p, error_code& ec,
- Args... args) {
- FileDescriptor fd = create(p, ec, args...);
- if (!ec)
- fd.refresh_status(ec);
-
- return fd;
- }
-
- file_status get_status() const { return m_status; }
- StatT const& get_stat() const { return m_stat; }
-
- bool status_known() const { return _VSTD_FS::status_known(m_status); }
-
- file_status refresh_status(error_code& ec);
-
- void close() noexcept {
- if (fd != -1)
- ::close(fd);
- fd = -1;
- }
-
- FileDescriptor(FileDescriptor&& other)
- : name(other.name), fd(other.fd), m_stat(other.m_stat),
- m_status(other.m_status) {
- other.fd = -1;
- other.m_status = file_status{};
- }
-
- ~FileDescriptor() { close(); }
-
- FileDescriptor(FileDescriptor const&) = delete;
- FileDescriptor& operator=(FileDescriptor const&) = delete;
-
-private:
- explicit FileDescriptor(const path* p, int fd = -1) : name(*p), fd(fd) {}
-};
-
-perms posix_get_perms(const StatT& st) noexcept {
- return static_cast<perms>(st.st_mode) & perms::mask;
-}
-
-::mode_t posix_convert_perms(perms prms) {
- return static_cast< ::mode_t>(prms & perms::mask);
-}
-
-file_status create_file_status(error_code& m_ec, path const& p,
- const StatT& path_stat, error_code* ec) {
- if (ec)
- *ec = m_ec;
- if (m_ec && (m_ec.value() == ENOENT || m_ec.value() == ENOTDIR)) {
- return file_status(file_type::not_found);
- } else if (m_ec) {
- ErrorHandler<void> err("posix_stat", ec, &p);
- err.report(m_ec, "failed to determine attributes for the specified path");
- return file_status(file_type::none);
- }
- // else
-
- file_status fs_tmp;
- auto const mode = path_stat.st_mode;
- if (S_ISLNK(mode))
- fs_tmp.type(file_type::symlink);
- else if (S_ISREG(mode))
- fs_tmp.type(file_type::regular);
- else if (S_ISDIR(mode))
- fs_tmp.type(file_type::directory);
- else if (S_ISBLK(mode))
- fs_tmp.type(file_type::block);
- else if (S_ISCHR(mode))
- fs_tmp.type(file_type::character);
- else if (S_ISFIFO(mode))
- fs_tmp.type(file_type::fifo);
- else if (S_ISSOCK(mode))
- fs_tmp.type(file_type::socket);
- else
- fs_tmp.type(file_type::unknown);
-
- fs_tmp.permissions(detail::posix_get_perms(path_stat));
- return fs_tmp;
-}
-
-file_status posix_stat(path const& p, StatT& path_stat, error_code* ec) {
- error_code m_ec;
- if (::stat(p.c_str(), &path_stat) == -1)
- m_ec = detail::capture_errno();
- return create_file_status(m_ec, p, path_stat, ec);
-}
-
-file_status posix_stat(path const& p, error_code* ec) {
- StatT path_stat;
- return posix_stat(p, path_stat, ec);
-}
-
-file_status posix_lstat(path const& p, StatT& path_stat, error_code* ec) {
- error_code m_ec;
- if (::lstat(p.c_str(), &path_stat) == -1)
- m_ec = detail::capture_errno();
- return create_file_status(m_ec, p, path_stat, ec);
-}
-
-file_status posix_lstat(path const& p, error_code* ec) {
- StatT path_stat;
- return posix_lstat(p, path_stat, ec);
-}
-
-// http://pubs.opengroup.org/onlinepubs/9699919799/functions/ftruncate.html
-bool posix_ftruncate(const FileDescriptor& fd, off_t to_size, error_code& ec) {
- if (::ftruncate(fd.fd, to_size) == -1) {
- ec = capture_errno();
- return true;
- }
- ec.clear();
- return false;
-}
-
-bool posix_fchmod(const FileDescriptor& fd, const StatT& st, error_code& ec) {
- if (::fchmod(fd.fd, st.st_mode) == -1) {
- ec = capture_errno();
- return true;
- }
- ec.clear();
- return false;
-}
-
-bool stat_equivalent(const StatT& st1, const StatT& st2) {
- return (st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino);
-}
-
-file_status FileDescriptor::refresh_status(error_code& ec) {
- // FD must be open and good.
- m_status = file_status{};
- m_stat = {};
- error_code m_ec;
- if (::fstat(fd, &m_stat) == -1)
- m_ec = capture_errno();
- m_status = create_file_status(m_ec, name, m_stat, &ec);
- return m_status;
-}
-} // namespace
-} // end namespace detail
-
using detail::capture_errno;
using detail::ErrorHandler;
using detail::StatT;
@@ -561,51 +62,6 @@ using parser::createView;
using parser::PathParser;
using parser::string_view_t;
-const bool _FilesystemClock::is_steady;
-
-_FilesystemClock::time_point _FilesystemClock::now() noexcept {
- typedef chrono::duration<rep> __secs;
-#if defined(CLOCK_REALTIME)
- typedef chrono::duration<rep, nano> __nsecs;
- struct timespec tp;
- if (0 != clock_gettime(CLOCK_REALTIME, &tp))
- __throw_system_error(errno, "clock_gettime(CLOCK_REALTIME) failed");
- return time_point(__secs(tp.tv_sec) +
- chrono::duration_cast<duration>(__nsecs(tp.tv_nsec)));
-#else
- typedef chrono::duration<rep, micro> __microsecs;
- timeval tv;
- gettimeofday(&tv, 0);
- return time_point(__secs(tv.tv_sec) + __microsecs(tv.tv_usec));
-#endif // CLOCK_REALTIME
-}
-
-filesystem_error::~filesystem_error() {}
-
-#if defined(_LIBCPP_WIN32API)
-#define PS_FMT "%ls"
-#else
-#define PS_FMT "%s"
-#endif
-
-void filesystem_error::__create_what(int __num_paths) {
- const char* derived_what = system_error::what();
- __storage_->__what_ = [&]() -> string {
- const path::value_type* p1 = path1().native().empty() ? PS("\"\"") : path1().c_str();
- const path::value_type* p2 = path2().native().empty() ? PS("\"\"") : path2().c_str();
- switch (__num_paths) {
- default:
- return detail::format_string("filesystem error: %s", derived_what);
- case 1:
- return detail::format_string("filesystem error: %s [" PS_FMT "]", derived_what,
- p1);
- case 2:
- return detail::format_string("filesystem error: %s [" PS_FMT "] [" PS_FMT "]",
- derived_what, p1, p2);
- }
- }();
-}
-
static path __do_absolute(const path& p, path* cwd, error_code* ec) {
if (ec)
ec->clear();
@@ -627,51 +83,45 @@ path __canonical(path const& orig_p, error_code* ec) {
ErrorHandler<path> err("canonical", ec, &orig_p, &cwd);
path p = __do_absolute(orig_p, &cwd, ec);
-#if defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112
- std::unique_ptr<char, decltype(&::free)>
- hold(::realpath(p.c_str(), nullptr), &::free);
+#if (defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112) || defined(_LIBCPP_WIN32API)
+ std::unique_ptr<path::value_type, decltype(&::free)> hold(detail::realpath(p.c_str(), nullptr), &::free);
if (hold.get() == nullptr)
return err.report(capture_errno());
return {hold.get()};
#else
- #if defined(__MVS__) && !defined(PATH_MAX)
- char buff[ _XOPEN_PATH_MAX + 1 ];
- #else
- char buff[PATH_MAX + 1];
- #endif
- char* ret;
- if ((ret = ::realpath(p.c_str(), buff)) == nullptr)
+# if defined(__MVS__) && !defined(PATH_MAX)
+ path::value_type buff[_XOPEN_PATH_MAX + 1];
+# else
+ path::value_type buff[PATH_MAX + 1];
+# endif
+ path::value_type* ret;
+ if ((ret = detail::realpath(p.c_str(), buff)) == nullptr)
return err.report(capture_errno());
return {ret};
#endif
}
-void __copy(const path& from, const path& to, copy_options options,
- error_code* ec) {
+void __copy(const path& from, const path& to, copy_options options, error_code* ec) {
ErrorHandler<void> err("copy", ec, &from, &to);
- const bool sym_status = bool(
- options & (copy_options::create_symlinks | copy_options::skip_symlinks));
+ const bool sym_status = bool(options & (copy_options::create_symlinks | copy_options::skip_symlinks));
const bool sym_status2 = bool(options & copy_options::copy_symlinks);
error_code m_ec1;
StatT f_st = {};
- const file_status f = sym_status || sym_status2
- ? detail::posix_lstat(from, f_st, &m_ec1)
- : detail::posix_stat(from, f_st, &m_ec1);
+ const file_status f =
+ sym_status || sym_status2 ? detail::posix_lstat(from, f_st, &m_ec1) : detail::posix_stat(from, f_st, &m_ec1);
if (m_ec1)
return err.report(m_ec1);
- StatT t_st = {};
- const file_status t = sym_status ? detail::posix_lstat(to, t_st, &m_ec1)
- : detail::posix_stat(to, t_st, &m_ec1);
+ StatT t_st = {};
+ const file_status t = sym_status ? detail::posix_lstat(to, t_st, &m_ec1) : detail::posix_stat(to, t_st, &m_ec1);
if (not status_known(t))
return err.report(m_ec1);
- if (!exists(f) || is_other(f) || is_other(t) ||
- (is_directory(f) && is_regular_file(t)) ||
+ if (!exists(f) || is_other(f) || is_other(t) || (is_directory(f) && is_regular_file(t)) ||
detail::stat_equivalent(f_st, t_st)) {
return err.report(errc::function_not_supported);
}
@@ -703,9 +153,7 @@ void __copy(const path& from, const path& to, copy_options options,
return;
} else if (is_directory(f) && bool(copy_options::create_symlinks & options)) {
return err.report(errc::is_a_directory);
- } else if (is_directory(f) && (bool(copy_options::recursive & options) ||
- copy_options::none == options)) {
-
+ } else if (is_directory(f) && (bool(copy_options::recursive & options) || copy_options::none == options)) {
if (!exists(t)) {
// create directory to with attributes from 'from'.
__create_directory(to, from, ec);
@@ -713,8 +161,7 @@ void __copy(const path& from, const path& to, copy_options options,
return;
}
}
- directory_iterator it =
- ec ? directory_iterator(from, *ec) : directory_iterator(from);
+ directory_iterator it = ec ? directory_iterator(from, *ec) : directory_iterator(from);
if (ec && *ec) {
return;
}
@@ -723,8 +170,7 @@ void __copy(const path& from, const path& to, copy_options options,
if (m_ec2) {
return err.report(m_ec2);
}
- __copy(it->path(), to / it->path().filename(),
- options | copy_options::__in_recursive_copy, ec);
+ __copy(it->path(), to / it->path().filename(), options | copy_options::__in_recursive_copy, ec);
if (ec && *ec) {
return;
}
@@ -736,95 +182,93 @@ namespace detail {
namespace {
#if defined(_LIBCPP_FILESYSTEM_USE_SENDFILE)
- bool copy_file_impl(FileDescriptor& read_fd, FileDescriptor& write_fd, error_code& ec) {
- size_t count = read_fd.get_stat().st_size;
- do {
- ssize_t res;
- if ((res = ::sendfile(write_fd.fd, read_fd.fd, nullptr, count)) == -1) {
- ec = capture_errno();
- return false;
- }
- count -= res;
- } while (count > 0);
-
- ec.clear();
-
- return true;
- }
-#elif defined(_LIBCPP_FILESYSTEM_USE_COPYFILE)
- bool copy_file_impl(FileDescriptor& read_fd, FileDescriptor& write_fd, error_code& ec) {
- struct CopyFileState {
- copyfile_state_t state;
- CopyFileState() { state = copyfile_state_alloc(); }
- ~CopyFileState() { copyfile_state_free(state); }
-
- private:
- CopyFileState(CopyFileState const&) = delete;
- CopyFileState& operator=(CopyFileState const&) = delete;
- };
-
- CopyFileState cfs;
- if (fcopyfile(read_fd.fd, write_fd.fd, cfs.state, COPYFILE_DATA) < 0) {
+bool copy_file_impl(FileDescriptor& read_fd, FileDescriptor& write_fd, error_code& ec) {
+ size_t count = read_fd.get_stat().st_size;
+ do {
+ ssize_t res;
+ if ((res = ::sendfile(write_fd.fd, read_fd.fd, nullptr, count)) == -1) {
ec = capture_errno();
return false;
}
+ count -= res;
+ } while (count > 0);
- ec.clear();
- return true;
+ ec.clear();
+
+ return true;
+}
+#elif defined(_LIBCPP_FILESYSTEM_USE_COPYFILE)
+bool copy_file_impl(FileDescriptor& read_fd, FileDescriptor& write_fd, error_code& ec) {
+ struct CopyFileState {
+ copyfile_state_t state;
+ CopyFileState() { state = copyfile_state_alloc(); }
+ ~CopyFileState() { copyfile_state_free(state); }
+
+ private:
+ CopyFileState(CopyFileState const&) = delete;
+ CopyFileState& operator=(CopyFileState const&) = delete;
+ };
+
+ CopyFileState cfs;
+ if (fcopyfile(read_fd.fd, write_fd.fd, cfs.state, COPYFILE_DATA) < 0) {
+ ec = capture_errno();
+ return false;
}
+
+ ec.clear();
+ return true;
+}
#elif defined(_LIBCPP_FILESYSTEM_USE_FSTREAM)
- bool copy_file_impl(FileDescriptor& read_fd, FileDescriptor& write_fd, error_code& ec) {
- ifstream in;
- in.__open(read_fd.fd, ios::binary);
- if (!in.is_open()) {
- // This assumes that __open didn't reset the error code.
- ec = capture_errno();
- return false;
- }
- read_fd.fd = -1;
- ofstream out;
- out.__open(write_fd.fd, ios::binary);
- if (!out.is_open()) {
- ec = capture_errno();
- return false;
- }
- write_fd.fd = -1;
-
- if (in.good() && out.good()) {
- using InIt = istreambuf_iterator<char>;
- using OutIt = ostreambuf_iterator<char>;
- InIt bin(in);
- InIt ein;
- OutIt bout(out);
- copy(bin, ein, bout);
- }
- if (out.fail() || in.fail()) {
- ec = make_error_code(errc::io_error);
- return false;
- }
+bool copy_file_impl(FileDescriptor& read_fd, FileDescriptor& write_fd, error_code& ec) {
+ ifstream in;
+ in.__open(read_fd.fd, ios::binary);
+ if (!in.is_open()) {
+ // This assumes that __open didn't reset the error code.
+ ec = capture_errno();
+ return false;
+ }
+ read_fd.fd = -1;
+ ofstream out;
+ out.__open(write_fd.fd, ios::binary);
+ if (!out.is_open()) {
+ ec = capture_errno();
+ return false;
+ }
+ write_fd.fd = -1;
- ec.clear();
- return true;
+ if (in.good() && out.good()) {
+ using InIt = istreambuf_iterator<char>;
+ using OutIt = ostreambuf_iterator<char>;
+ InIt bin(in);
+ InIt ein;
+ OutIt bout(out);
+ copy(bin, ein, bout);
}
+ if (out.fail() || in.fail()) {
+ ec = make_error_code(errc::io_error);
+ return false;
+ }
+
+ ec.clear();
+ return true;
+}
#else
-# error "Unknown implementation for copy_file_impl"
+# error "Unknown implementation for copy_file_impl"
#endif // copy_file_impl implementation
} // end anonymous namespace
} // end namespace detail
-bool __copy_file(const path& from, const path& to, copy_options options,
- error_code* ec) {
+bool __copy_file(const path& from, const path& to, copy_options options, error_code* ec) {
using detail::FileDescriptor;
ErrorHandler<bool> err("copy_file", ec, &to, &from);
error_code m_ec;
- FileDescriptor from_fd =
- FileDescriptor::create_with_status(&from, m_ec, O_RDONLY | O_NONBLOCK);
+ FileDescriptor from_fd = FileDescriptor::create_with_status(&from, m_ec, O_RDONLY | O_NONBLOCK | O_BINARY);
if (m_ec)
return err.report(m_ec);
- auto from_st = from_fd.get_status();
+ auto from_st = from_fd.get_status();
StatT const& from_stat = from_fd.get_stat();
if (!is_regular_file(from_st)) {
if (not m_ec)
@@ -832,10 +276,9 @@ bool __copy_file(const path& from, const path& to, copy_options options,
return err.report(m_ec);
}
- const bool skip_existing = bool(copy_options::skip_existing & options);
- const bool update_existing = bool(copy_options::update_existing & options);
- const bool overwrite_existing =
- bool(copy_options::overwrite_existing & options);
+ const bool skip_existing = bool(copy_options::skip_existing & options);
+ const bool update_existing = bool(copy_options::update_existing & options);
+ const bool overwrite_existing = bool(copy_options::overwrite_existing & options);
StatT to_stat_path;
file_status to_st = detail::posix_stat(to, to_stat_path, &m_ec);
@@ -855,11 +298,10 @@ bool __copy_file(const path& from, const path& to, copy_options options,
bool ShouldCopy = [&]() {
if (to_exists && update_existing) {
auto from_time = detail::extract_mtime(from_stat);
- auto to_time = detail::extract_mtime(to_stat_path);
+ auto to_time = detail::extract_mtime(to_stat_path);
if (from_time.tv_sec < to_time.tv_sec)
return false;
- if (from_time.tv_sec == to_time.tv_sec &&
- from_time.tv_nsec <= to_time.tv_nsec)
+ if (from_time.tv_sec == to_time.tv_sec && from_time.tv_nsec <= to_time.tv_nsec)
return false;
return true;
}
@@ -872,11 +314,10 @@ bool __copy_file(const path& from, const path& to, copy_options options,
// Don't truncate right away. We may not be opening the file we originally
// looked at; we'll check this later.
- int to_open_flags = O_WRONLY;
+ int to_open_flags = O_WRONLY | O_BINARY;
if (!to_exists)
to_open_flags |= O_CREAT;
- FileDescriptor to_fd = FileDescriptor::create_with_status(
- &to, m_ec, to_open_flags, from_stat.st_mode);
+ FileDescriptor to_fd = FileDescriptor::create_with_status(&to, m_ec, to_open_flags, from_stat.st_mode);
if (m_ec)
return err.report(m_ec);
@@ -894,7 +335,7 @@ bool __copy_file(const path& from, const path& to, copy_options options,
return err.report(m_ec);
}
- if (!copy_file_impl(from_fd, to_fd, m_ec)) {
+ if (!detail::copy_file_impl(from_fd, to_fd, m_ec)) {
// FIXME: Remove the dest file if we failed, and it didn't exist previously.
return err.report(m_ec);
}
@@ -902,16 +343,18 @@ bool __copy_file(const path& from, const path& to, copy_options options,
return true;
}
-void __copy_symlink(const path& existing_symlink, const path& new_symlink,
- error_code* ec) {
+void __copy_symlink(const path& existing_symlink, const path& new_symlink, error_code* ec) {
const path real_path(__read_symlink(existing_symlink, ec));
if (ec && *ec) {
return;
}
- // NOTE: proposal says you should detect if you should call
- // create_symlink or create_directory_symlink. I don't think this
- // is needed with POSIX
- __create_symlink(real_path, new_symlink, ec);
+#if defined(_LIBCPP_WIN32API)
+ error_code local_ec;
+ if (is_directory(real_path, local_ec))
+ __create_directory_symlink(real_path, new_symlink, ec);
+ else
+#endif
+ __create_symlink(real_path, new_symlink, ec);
}
bool __create_directories(const path& p, error_code* ec) {
@@ -932,31 +375,34 @@ bool __create_directories(const path& p, error_code* ec) {
if (not status_known(parent_st))
return err.report(m_ec);
if (not exists(parent_st)) {
+ if (parent == p)
+ return err.report(errc::invalid_argument);
__create_directories(parent, ec);
if (ec && *ec) {
return false;
}
- }
+ } else if (not is_directory(parent_st))
+ return err.report(errc::not_a_directory);
}
- return __create_directory(p, ec);
+ bool ret = __create_directory(p, &m_ec);
+ if (m_ec)
+ return err.report(m_ec);
+ return ret;
}
bool __create_directory(const path& p, error_code* ec) {
ErrorHandler<bool> err("create_directory", ec, &p);
- if (::mkdir(p.c_str(), static_cast<int>(perms::all)) == 0)
+ if (detail::mkdir(p.c_str(), static_cast<int>(perms::all)) == 0)
return true;
- if (errno == EEXIST) {
- error_code mec = capture_errno();
- error_code ignored_ec;
- const file_status st = status(p, ignored_ec);
- if (!is_directory(st)) {
- err.report(mec);
- }
- } else {
- err.report(capture_errno());
- }
+ if (errno != EEXIST)
+ return err.report(capture_errno());
+ error_code mec = capture_errno();
+ error_code ignored_ec;
+ const file_status st = status(p, ignored_ec);
+ if (!is_directory(st))
+ return err.report(mec);
return false;
}
@@ -965,65 +411,92 @@ bool __create_directory(path const& p, path const& attributes, error_code* ec) {
StatT attr_stat;
error_code mec;
- auto st = detail::posix_stat(attributes, attr_stat, &mec);
+ file_status st = detail::posix_stat(attributes, attr_stat, &mec);
if (!status_known(st))
return err.report(mec);
if (!is_directory(st))
- return err.report(errc::not_a_directory,
- "the specified attribute path is invalid");
+ return err.report(errc::not_a_directory, "the specified attribute path is invalid");
- if (::mkdir(p.c_str(), attr_stat.st_mode) == 0)
+ if (detail::mkdir(p.c_str(), attr_stat.st_mode) == 0)
return true;
- if (errno == EEXIST) {
- error_code mec = capture_errno();
- error_code ignored_ec;
- const file_status st = status(p, ignored_ec);
- if (!is_directory(st)) {
- err.report(mec);
- }
- } else {
- err.report(capture_errno());
- }
+ if (errno != EEXIST)
+ return err.report(capture_errno());
+
+ mec = capture_errno();
+ error_code ignored_ec;
+ st = status(p, ignored_ec);
+ if (!is_directory(st))
+ return err.report(mec);
return false;
}
-void __create_directory_symlink(path const& from, path const& to,
- error_code* ec) {
+void __create_directory_symlink(path const& from, path const& to, error_code* ec) {
ErrorHandler<void> err("create_directory_symlink", ec, &from, &to);
- if (::symlink(from.c_str(), to.c_str()) != 0)
+ if (detail::symlink_dir(from.c_str(), to.c_str()) == -1)
return err.report(capture_errno());
}
void __create_hard_link(const path& from, const path& to, error_code* ec) {
ErrorHandler<void> err("create_hard_link", ec, &from, &to);
- if (::link(from.c_str(), to.c_str()) == -1)
+ if (detail::link(from.c_str(), to.c_str()) == -1)
return err.report(capture_errno());
}
void __create_symlink(path const& from, path const& to, error_code* ec) {
ErrorHandler<void> err("create_symlink", ec, &from, &to);
- if (::symlink(from.c_str(), to.c_str()) == -1)
+ if (detail::symlink_file(from.c_str(), to.c_str()) == -1)
return err.report(capture_errno());
}
path __current_path(error_code* ec) {
ErrorHandler<path> err("current_path", ec);
+#if defined(_LIBCPP_WIN32API) || defined(__GLIBC__) || defined(__APPLE__)
+ // Common extension outside of POSIX getcwd() spec, without needing to
+ // preallocate a buffer. Also supported by a number of other POSIX libcs.
+ int size = 0;
+ path::value_type* ptr = nullptr;
+ typedef decltype(&::free) Deleter;
+ Deleter deleter = &::free;
+#else
+ errno = 0; // Note: POSIX mandates that modifying `errno` is thread-safe.
auto size = ::pathconf(".", _PC_PATH_MAX);
- _LIBCPP_ASSERT(size >= 0, "pathconf returned a 0 as max size");
+ if (size == -1) {
+ if (errno != 0) {
+ return err.report(capture_errno(), "call to pathconf failed");
- auto buff = unique_ptr<char[]>(new char[size + 1]);
- char* ret;
- if ((ret = ::getcwd(buff.get(), static_cast<size_t>(size))) == nullptr)
+ // `pathconf` returns `-1` without an error to indicate no limit.
+ } else {
+# if defined(__MVS__) && !defined(PATH_MAX)
+ size = _XOPEN_PATH_MAX + 1;
+# else
+ size = PATH_MAX + 1;
+# endif
+ }
+ }
+
+ auto buff = unique_ptr<path::value_type[]>(new path::value_type[size + 1]);
+ path::value_type* ptr = buff.get();
+
+ // Preallocated buffer, don't free the buffer in the second unique_ptr
+ // below.
+ struct Deleter {
+ void operator()(void*) const {}
+ };
+ Deleter deleter;
+#endif
+
+ unique_ptr<path::value_type, Deleter> hold(detail::getcwd(ptr, size), deleter);
+ if (hold.get() == nullptr)
return err.report(capture_errno(), "call to getcwd failed");
- return {buff.get()};
+ return {hold.get()};
}
void __current_path(const path& p, error_code* ec) {
ErrorHandler<void> err("current_path", ec, &p);
- if (::chdir(p.c_str()) == -1)
+ if (detail::chdir(p.c_str()) == -1)
err.report(capture_errno());
}
@@ -1049,8 +522,7 @@ uintmax_t __file_size(const path& p, error_code* ec) {
StatT st;
file_status fst = detail::posix_stat(p, st, &m_ec);
if (!exists(fst) || !is_regular_file(fst)) {
- errc error_kind =
- is_directory(fst) ? errc::is_a_directory : errc::not_supported;
+ errc error_kind = is_directory(fst) ? errc::is_a_directory : errc::not_supported;
if (!m_ec)
m_ec = make_error_code(error_kind);
return err.report(m_ec);
@@ -1088,19 +560,7 @@ bool __fs_is_empty(const path& p, error_code* ec) {
} else if (is_regular_file(st))
return static_cast<uintmax_t>(pst.st_size) == 0;
- _LIBCPP_UNREACHABLE();
-}
-
-static file_time_type __extract_last_write_time(const path& p, const StatT& st,
- error_code* ec) {
- using detail::fs_time;
- ErrorHandler<file_time_type> err("last_write_time", ec, &p);
-
- auto ts = detail::extract_mtime(st);
- if (!fs_time::is_representable(ts))
- return err.report(errc::value_too_large);
-
- return fs_time::convert_from_timespec(ts);
+ __libcpp_unreachable();
}
file_time_type __last_write_time(const path& p, error_code* ec) {
@@ -1112,16 +572,27 @@ file_time_type __last_write_time(const path& p, error_code* ec) {
detail::posix_stat(p, st, &m_ec);
if (m_ec)
return err.report(m_ec);
- return __extract_last_write_time(p, st, ec);
+ return detail::__extract_last_write_time(p, st, ec);
}
void __last_write_time(const path& p, file_time_type new_time, error_code* ec) {
using detail::fs_time;
ErrorHandler<void> err("last_write_time", ec, &p);
+#if defined(_LIBCPP_WIN32API)
+ TimeSpec ts;
+ if (!fs_time::convert_to_timespec(ts, new_time))
+ return err.report(errc::value_too_large);
+ detail::WinHandle h(p.c_str(), FILE_WRITE_ATTRIBUTES, 0);
+ if (!h)
+ return err.report(detail::make_windows_error(GetLastError()));
+ FILETIME last_write = timespec_to_filetime(ts);
+ if (!SetFileTime(h, nullptr, nullptr, &last_write))
+ return err.report(detail::make_windows_error(GetLastError()));
+#else
error_code m_ec;
array<TimeSpec, 2> tbuf;
-#if !defined(_LIBCPP_USE_UTIMENSAT)
+# if !defined(_LIBCPP_USE_UTIMENSAT)
// This implementation has a race condition between determining the
// last access time and attempting to set it to the same value using
// ::utimes
@@ -1130,52 +601,51 @@ void __last_write_time(const path& p, file_time_type new_time, error_code* ec) {
if (m_ec)
return err.report(m_ec);
tbuf[0] = detail::extract_atime(st);
-#else
- tbuf[0].tv_sec = 0;
+# else
+ tbuf[0].tv_sec = 0;
tbuf[0].tv_nsec = UTIME_OMIT;
-#endif
+# endif
if (!fs_time::convert_to_timespec(tbuf[1], new_time))
return err.report(errc::value_too_large);
detail::set_file_times(p, tbuf, m_ec);
if (m_ec)
return err.report(m_ec);
+#endif
}
-void __permissions(const path& p, perms prms, perm_options opts,
- error_code* ec) {
+void __permissions(const path& p, perms prms, perm_options opts, error_code* ec) {
ErrorHandler<void> err("permissions", ec, &p);
- auto has_opt = [&](perm_options o) { return bool(o & opts); };
+ auto has_opt = [&](perm_options o) { return bool(o & opts); };
const bool resolve_symlinks = !has_opt(perm_options::nofollow);
- const bool add_perms = has_opt(perm_options::add);
- const bool remove_perms = has_opt(perm_options::remove);
- _LIBCPP_ASSERT(
+ const bool add_perms = has_opt(perm_options::add);
+ const bool remove_perms = has_opt(perm_options::remove);
+ _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(
(add_perms + remove_perms + has_opt(perm_options::replace)) == 1,
- "One and only one of the perm_options constants replace, add, or remove "
- "is present in opts");
+ "One and only one of the perm_options constants 'replace', 'add', or 'remove' must be present in opts");
bool set_sym_perms = false;
prms &= perms::mask;
if (!resolve_symlinks || (add_perms || remove_perms)) {
error_code m_ec;
- file_status st = resolve_symlinks ? detail::posix_stat(p, &m_ec)
- : detail::posix_lstat(p, &m_ec);
- set_sym_perms = is_symlink(st);
+ file_status st = resolve_symlinks ? detail::posix_stat(p, &m_ec) : detail::posix_lstat(p, &m_ec);
+ set_sym_perms = is_symlink(st);
if (m_ec)
return err.report(m_ec);
- _LIBCPP_ASSERT(st.permissions() != perms::unknown,
- "Permissions unexpectedly unknown");
+ // TODO(hardening): double-check this assertion -- it might be a valid (if rare) case when the permissions are
+ // unknown.
+ _LIBCPP_ASSERT_VALID_EXTERNAL_API_CALL(st.permissions() != perms::unknown, "Permissions unexpectedly unknown");
if (add_perms)
prms |= st.permissions();
else if (remove_perms)
prms = st.permissions() & ~prms;
}
- const auto real_perms = detail::posix_convert_perms(prms);
+ const auto real_perms = static_cast<detail::ModeT>(prms & perms::mask);
#if defined(AT_SYMLINK_NOFOLLOW) && defined(AT_FDCWD)
const int flags = set_sym_perms ? AT_SYMLINK_NOFOLLOW : 0;
- if (::fchmodat(AT_FDCWD, p.c_str(), real_perms, flags) == -1) {
+ if (detail::fchmodat(AT_FDCWD, p.c_str(), real_perms, flags) == -1) {
return err.report(capture_errno());
}
#else
@@ -1190,23 +660,29 @@ void __permissions(const path& p, perms prms, perm_options opts,
path __read_symlink(const path& p, error_code* ec) {
ErrorHandler<path> err("read_symlink", ec, &p);
-#ifdef PATH_MAX
- struct NullDeleter { void operator()(void*) const {} };
+#if defined(PATH_MAX) || defined(MAX_SYMLINK_SIZE)
+ struct NullDeleter {
+ void operator()(void*) const {}
+ };
+# ifdef MAX_SYMLINK_SIZE
+ const size_t size = MAX_SYMLINK_SIZE + 1;
+# else
const size_t size = PATH_MAX + 1;
- char stack_buff[size];
- auto buff = std::unique_ptr<char[], NullDeleter>(stack_buff);
+# endif
+ path::value_type stack_buff[size];
+ auto buff = std::unique_ptr<path::value_type[], NullDeleter>(stack_buff);
#else
StatT sb;
- if (::lstat(p.c_str(), &sb) == -1) {
+ if (detail::lstat(p.c_str(), &sb) == -1) {
return err.report(capture_errno());
}
const size_t size = sb.st_size + 1;
- auto buff = unique_ptr<char[]>(new char[size]);
+ auto buff = unique_ptr<path::value_type[]>(new path::value_type[size]);
#endif
- ::ssize_t ret;
- if ((ret = ::readlink(p.c_str(), buff.get(), size)) == -1)
+ detail::SSizeT ret;
+ if ((ret = detail::readlink(p.c_str(), buff.get(), size)) == -1)
return err.report(capture_errno());
- _LIBCPP_ASSERT(ret > 0, "TODO");
+ // Note that `ret` returning `0` would work, resulting in a valid empty string being returned.
if (static_cast<size_t>(ret) >= size)
return err.report(errc::value_too_large);
buff[ret] = 0;
@@ -1215,7 +691,7 @@ path __read_symlink(const path& p, error_code* ec) {
bool __remove(const path& p, error_code* ec) {
ErrorHandler<bool> err("remove", ec, &p);
- if (::remove(p.c_str()) == -1) {
+ if (detail::remove(p.c_str()) == -1) {
if (errno != ENOENT)
err.report(capture_errno());
return false;
@@ -1223,17 +699,29 @@ bool __remove(const path& p, error_code* ec) {
return true;
}
+// We currently have two implementations of `__remove_all`. The first one is general and
+// used on platforms where we don't have access to the `openat()` family of POSIX functions.
+// That implementation uses `directory_iterator`, however it is vulnerable to some race
+// conditions, see https://reviews.llvm.org/D118134 for details.
+//
+// The second implementation is used on platforms where `openat()` & friends are available,
+// and it threads file descriptors through recursive calls to avoid such race conditions.
+#if defined(_LIBCPP_WIN32API) || defined(__MVS__)
+# define REMOVE_ALL_USE_DIRECTORY_ITERATOR
+#endif
+
+#if defined(REMOVE_ALL_USE_DIRECTORY_ITERATOR)
+
namespace {
uintmax_t remove_all_impl(path const& p, error_code& ec) {
- const auto npos = static_cast<uintmax_t>(-1);
+ const auto npos = static_cast<uintmax_t>(-1);
const file_status st = __symlink_status(p, &ec);
if (ec)
return npos;
uintmax_t count = 1;
if (is_directory(st)) {
- for (directory_iterator it(p, ec); !ec && it != directory_iterator();
- it.increment(ec)) {
+ for (directory_iterator it(p, ec); !ec && it != directory_iterator(); it.increment(ec)) {
auto other_count = remove_all_impl(it->path(), ec);
if (ec)
return npos;
@@ -1262,23 +750,116 @@ uintmax_t __remove_all(const path& p, error_code* ec) {
return count;
}
+#else // !REMOVE_ALL_USE_DIRECTORY_ITERATOR
+
+namespace {
+
+template <class Cleanup>
+struct scope_exit {
+ explicit scope_exit(Cleanup const& cleanup) : cleanup_(cleanup) {}
+
+ ~scope_exit() { cleanup_(); }
+
+private:
+ Cleanup cleanup_;
+};
+_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(scope_exit);
+
+uintmax_t remove_all_impl(int parent_directory, const path& p, error_code& ec) {
+ // First, try to open the path as a directory.
+ const int options = O_CLOEXEC | O_RDONLY | O_DIRECTORY | O_NOFOLLOW;
+ int fd = ::openat(parent_directory, p.c_str(), options);
+ if (fd != -1) {
+ // If that worked, iterate over the contents of the directory and
+ // remove everything in it, recursively.
+ DIR* stream = ::fdopendir(fd);
+ if (stream == nullptr) {
+ ::close(fd);
+ ec = detail::capture_errno();
+ return 0;
+ }
+ // Note: `::closedir` will also close the associated file descriptor, so
+ // there should be no call to `close(fd)`.
+ scope_exit close_stream([=] { ::closedir(stream); });
+
+ uintmax_t count = 0;
+ while (true) {
+ auto [str, type] = detail::posix_readdir(stream, ec);
+ static_assert(std::is_same_v<decltype(str), std::string_view>);
+ if (str == "." || str == "..") {
+ continue;
+ } else if (ec || str.empty()) {
+ break; // we're done iterating through the directory
+ } else {
+ count += remove_all_impl(fd, str, ec);
+ }
+ }
+
+ // Then, remove the now-empty directory itself.
+ if (::unlinkat(parent_directory, p.c_str(), AT_REMOVEDIR) == -1) {
+ ec = detail::capture_errno();
+ return count;
+ }
+
+ return count + 1; // the contents of the directory + the directory itself
+ }
+
+ ec = detail::capture_errno();
+
+ // If we failed to open `p` because it didn't exist, it's not an
+ // error -- it might have moved or have been deleted already.
+ if (ec == errc::no_such_file_or_directory) {
+ ec.clear();
+ return 0;
+ }
+
+ // If opening `p` failed because it wasn't a directory, remove it as
+ // a normal file instead. Note that `openat()` can return either ENOTDIR
+ // or ELOOP depending on the exact reason of the failure. On FreeBSD it
+ // may return EMLINK instead of ELOOP, contradicting POSIX.
+ if (ec == errc::not_a_directory || ec == errc::too_many_symbolic_link_levels || ec == errc::too_many_links) {
+ ec.clear();
+ if (::unlinkat(parent_directory, p.c_str(), /* flags = */ 0) == -1) {
+ ec = detail::capture_errno();
+ return 0;
+ }
+ return 1;
+ }
+
+ // Otherwise, it's a real error -- we don't remove anything.
+ return 0;
+}
+
+} // end namespace
+
+uintmax_t __remove_all(const path& p, error_code* ec) {
+ ErrorHandler<uintmax_t> err("remove_all", ec, &p);
+ error_code mec;
+ uintmax_t count = remove_all_impl(AT_FDCWD, p, mec);
+ if (mec)
+ return err.report(mec);
+ return count;
+}
+
+#endif // REMOVE_ALL_USE_DIRECTORY_ITERATOR
+
void __rename(const path& from, const path& to, error_code* ec) {
ErrorHandler<void> err("rename", ec, &from, &to);
- if (::rename(from.c_str(), to.c_str()) == -1)
+ if (detail::rename(from.c_str(), to.c_str()) == -1)
err.report(capture_errno());
}
void __resize_file(const path& p, uintmax_t size, error_code* ec) {
ErrorHandler<void> err("resize_file", ec, &p);
- if (::truncate(p.c_str(), static_cast< ::off_t>(size)) == -1)
+ if (detail::truncate(p.c_str(), static_cast< ::off_t>(size)) == -1)
return err.report(capture_errno());
}
space_info __space(const path& p, error_code* ec) {
ErrorHandler<void> err("space", ec, &p);
space_info si;
- struct statvfs m_svfs = {};
- if (::statvfs(p.c_str(), &m_svfs) == -1) {
+ detail::StatVFS m_svfs = {};
+ if (detail::statvfs(p.c_str(), &m_svfs) == -1) {
err.report(capture_errno());
si.capacity = si.free = si.available = static_cast<uintmax_t>(-1);
return si;
@@ -1295,35 +876,49 @@ space_info __space(const path& p, error_code* ec) {
return si;
}
-file_status __status(const path& p, error_code* ec) {
- return detail::posix_stat(p, ec);
-}
+file_status __status(const path& p, error_code* ec) { return detail::posix_stat(p, ec); }
-file_status __symlink_status(const path& p, error_code* ec) {
- return detail::posix_lstat(p, ec);
-}
+file_status __symlink_status(const path& p, error_code* ec) { return detail::posix_lstat(p, ec); }
path __temp_directory_path(error_code* ec) {
ErrorHandler<path> err("temp_directory_path", ec);
+#if defined(_LIBCPP_WIN32API)
+ wchar_t buf[MAX_PATH];
+ DWORD retval = GetTempPathW(MAX_PATH, buf);
+ if (!retval)
+ return err.report(detail::make_windows_error(GetLastError()));
+ if (retval > MAX_PATH)
+ return err.report(errc::filename_too_long);
+ // GetTempPathW returns a path with a trailing slash, which we
+ // shouldn't include for consistency.
+ if (buf[retval - 1] == L'\\')
+ buf[retval - 1] = L'\0';
+ path p(buf);
+#else
const char* env_paths[] = {"TMPDIR", "TMP", "TEMP", "TEMPDIR"};
- const char* ret = nullptr;
+ const char* ret = nullptr;
for (auto& ep : env_paths)
if ((ret = getenv(ep)))
break;
- if (ret == nullptr)
+ if (ret == nullptr) {
+# if defined(__ANDROID__)
+ ret = "/data/local/tmp";
+# else
ret = "/tmp";
+# endif
+ }
path p(ret);
+#endif
error_code m_ec;
file_status st = detail::posix_stat(p, &m_ec);
if (!status_known(st))
- return err.report(m_ec, "cannot access path \"" PS_FMT "\"", p);
+ return err.report(m_ec, "cannot access path " PATH_CSTR_FMT, p.c_str());
if (!exists(st) || !is_directory(st))
- return err.report(errc::not_a_directory, "path \"" PS_FMT "\" is not a directory",
- p);
+ return err.report(errc::not_a_directory, "path " PATH_CSTR_FMT " is not a directory", p.c_str());
return p;
}
@@ -1365,542 +960,4 @@ path __weakly_canonical(const path& p, error_code* ec) {
return result.lexically_normal();
}
-///////////////////////////////////////////////////////////////////////////////
-// path definitions
-///////////////////////////////////////////////////////////////////////////////
-
-constexpr path::value_type path::preferred_separator;
-
-path& path::replace_extension(path const& replacement) {
- path p = extension();
- if (not p.empty()) {
- __pn_.erase(__pn_.size() - p.native().size());
- }
- if (!replacement.empty()) {
- if (replacement.native()[0] != '.') {
- __pn_ += PS(".");
- }
- __pn_.append(replacement.__pn_);
- }
- return *this;
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// path.decompose
-
-string_view_t path::__root_name() const {
- auto PP = PathParser::CreateBegin(__pn_);
- if (PP.State == PathParser::PS_InRootName)
- return *PP;
- return {};
-}
-
-string_view_t path::__root_directory() const {
- auto PP = PathParser::CreateBegin(__pn_);
- if (PP.State == PathParser::PS_InRootName)
- ++PP;
- if (PP.State == PathParser::PS_InRootDir)
- return *PP;
- return {};
-}
-
-string_view_t path::__root_path_raw() const {
- auto PP = PathParser::CreateBegin(__pn_);
- if (PP.State == PathParser::PS_InRootName) {
- auto NextCh = PP.peek();
- if (NextCh && isSeparator(*NextCh)) {
- ++PP;
- return createView(__pn_.data(), &PP.RawEntry.back());
- }
- return PP.RawEntry;
- }
- if (PP.State == PathParser::PS_InRootDir)
- return *PP;
- return {};
-}
-
-static bool ConsumeRootName(PathParser *PP) {
- static_assert(PathParser::PS_BeforeBegin == 1 &&
- PathParser::PS_InRootName == 2,
- "Values for enums are incorrect");
- while (PP->State <= PathParser::PS_InRootName)
- ++(*PP);
- return PP->State == PathParser::PS_AtEnd;
-}
-
-static bool ConsumeRootDir(PathParser* PP) {
- static_assert(PathParser::PS_BeforeBegin == 1 &&
- PathParser::PS_InRootName == 2 &&
- PathParser::PS_InRootDir == 3, "Values for enums are incorrect");
- while (PP->State <= PathParser::PS_InRootDir)
- ++(*PP);
- return PP->State == PathParser::PS_AtEnd;
-}
-
-string_view_t path::__relative_path() const {
- auto PP = PathParser::CreateBegin(__pn_);
- if (ConsumeRootDir(&PP))
- return {};
- return createView(PP.RawEntry.data(), &__pn_.back());
-}
-
-string_view_t path::__parent_path() const {
- if (empty())
- return {};
- // Determine if we have a root path but not a relative path. In that case
- // return *this.
- {
- auto PP = PathParser::CreateBegin(__pn_);
- if (ConsumeRootDir(&PP))
- return __pn_;
- }
- // Otherwise remove a single element from the end of the path, and return
- // a string representing that path
- {
- auto PP = PathParser::CreateEnd(__pn_);
- --PP;
- if (PP.RawEntry.data() == __pn_.data())
- return {};
- --PP;
- return createView(__pn_.data(), &PP.RawEntry.back());
- }
-}
-
-string_view_t path::__filename() const {
- if (empty())
- return {};
- {
- PathParser PP = PathParser::CreateBegin(__pn_);
- if (ConsumeRootDir(&PP))
- return {};
- }
- return *(--PathParser::CreateEnd(__pn_));
-}
-
-string_view_t path::__stem() const {
- return parser::separate_filename(__filename()).first;
-}
-
-string_view_t path::__extension() const {
- return parser::separate_filename(__filename()).second;
-}
-
-////////////////////////////////////////////////////////////////////////////
-// path.gen
-
-enum PathPartKind : unsigned char {
- PK_None,
- PK_RootSep,
- PK_Filename,
- PK_Dot,
- PK_DotDot,
- PK_TrailingSep
-};
-
-static PathPartKind ClassifyPathPart(string_view_t Part) {
- if (Part.empty())
- return PK_TrailingSep;
- if (Part == PS("."))
- return PK_Dot;
- if (Part == PS(".."))
- return PK_DotDot;
- if (Part == PS("/"))
- return PK_RootSep;
-#if defined(_LIBCPP_WIN32API)
- if (Part == PS("\\"))
- return PK_RootSep;
-#endif
- return PK_Filename;
-}
-
-path path::lexically_normal() const {
- if (__pn_.empty())
- return *this;
-
- using PartKindPair = pair<string_view_t, PathPartKind>;
- vector<PartKindPair> Parts;
- // Guess as to how many elements the path has to avoid reallocating.
- Parts.reserve(32);
-
- // Track the total size of the parts as we collect them. This allows the
- // resulting path to reserve the correct amount of memory.
- size_t NewPathSize = 0;
- auto AddPart = [&](PathPartKind K, string_view_t P) {
- NewPathSize += P.size();
- Parts.emplace_back(P, K);
- };
- auto LastPartKind = [&]() {
- if (Parts.empty())
- return PK_None;
- return Parts.back().second;
- };
-
- bool MaybeNeedTrailingSep = false;
- // Build a stack containing the remaining elements of the path, popping off
- // elements which occur before a '..' entry.
- for (auto PP = PathParser::CreateBegin(__pn_); PP; ++PP) {
- auto Part = *PP;
- PathPartKind Kind = ClassifyPathPart(Part);
- switch (Kind) {
- case PK_Filename:
- case PK_RootSep: {
- // Add all non-dot and non-dot-dot elements to the stack of elements.
- AddPart(Kind, Part);
- MaybeNeedTrailingSep = false;
- break;
- }
- case PK_DotDot: {
- // Only push a ".." element if there are no elements preceding the "..",
- // or if the preceding element is itself "..".
- auto LastKind = LastPartKind();
- if (LastKind == PK_Filename) {
- NewPathSize -= Parts.back().first.size();
- Parts.pop_back();
- } else if (LastKind != PK_RootSep)
- AddPart(PK_DotDot, PS(".."));
- MaybeNeedTrailingSep = LastKind == PK_Filename;
- break;
- }
- case PK_Dot:
- case PK_TrailingSep: {
- MaybeNeedTrailingSep = true;
- break;
- }
- case PK_None:
- _LIBCPP_UNREACHABLE();
- }
- }
- // [fs.path.generic]p6.8: If the path is empty, add a dot.
- if (Parts.empty())
- return PS(".");
-
- // [fs.path.generic]p6.7: If the last filename is dot-dot, remove any
- // trailing directory-separator.
- bool NeedTrailingSep = MaybeNeedTrailingSep && LastPartKind() == PK_Filename;
-
- path Result;
- Result.__pn_.reserve(Parts.size() + NewPathSize + NeedTrailingSep);
- for (auto& PK : Parts)
- Result /= PK.first;
-
- if (NeedTrailingSep)
- Result /= PS("");
-
- return Result;
-}
-
-static int DetermineLexicalElementCount(PathParser PP) {
- int Count = 0;
- for (; PP; ++PP) {
- auto Elem = *PP;
- if (Elem == PS(".."))
- --Count;
- else if (Elem != PS(".") && Elem != PS(""))
- ++Count;
- }
- return Count;
-}
-
-path path::lexically_relative(const path& base) const {
- { // perform root-name/root-directory mismatch checks
- auto PP = PathParser::CreateBegin(__pn_);
- auto PPBase = PathParser::CreateBegin(base.__pn_);
- auto CheckIterMismatchAtBase = [&]() {
- return PP.State != PPBase.State &&
- (PP.inRootPath() || PPBase.inRootPath());
- };
- if (PP.inRootName() && PPBase.inRootName()) {
- if (*PP != *PPBase)
- return {};
- } else if (CheckIterMismatchAtBase())
- return {};
-
- if (PP.inRootPath())
- ++PP;
- if (PPBase.inRootPath())
- ++PPBase;
- if (CheckIterMismatchAtBase())
- return {};
- }
-
- // Find the first mismatching element
- auto PP = PathParser::CreateBegin(__pn_);
- auto PPBase = PathParser::CreateBegin(base.__pn_);
- while (PP && PPBase && PP.State == PPBase.State && *PP == *PPBase) {
- ++PP;
- ++PPBase;
- }
-
- // If there is no mismatch, return ".".
- if (!PP && !PPBase)
- return ".";
-
- // Otherwise, determine the number of elements, 'n', which are not dot or
- // dot-dot minus the number of dot-dot elements.
- int ElemCount = DetermineLexicalElementCount(PPBase);
- if (ElemCount < 0)
- return {};
-
- // if n == 0 and (a == end() || a->empty()), returns path("."); otherwise
- if (ElemCount == 0 && (PP.atEnd() || *PP == PS("")))
- return PS(".");
-
- // return a path constructed with 'n' dot-dot elements, followed by the the
- // elements of '*this' after the mismatch.
- path Result;
- // FIXME: Reserve enough room in Result that it won't have to re-allocate.
- while (ElemCount--)
- Result /= PS("..");
- for (; PP; ++PP)
- Result /= *PP;
- return Result;
-}
-
-////////////////////////////////////////////////////////////////////////////
-// path.comparisons
-static int CompareRootName(PathParser *LHS, PathParser *RHS) {
- if (!LHS->inRootName() && !RHS->inRootName())
- return 0;
-
- auto GetRootName = [](PathParser *Parser) -> string_view_t {
- return Parser->inRootName() ? **Parser : PS("");
- };
- int res = GetRootName(LHS).compare(GetRootName(RHS));
- ConsumeRootName(LHS);
- ConsumeRootName(RHS);
- return res;
-}
-
-static int CompareRootDir(PathParser *LHS, PathParser *RHS) {
- if (!LHS->inRootDir() && RHS->inRootDir())
- return -1;
- else if (LHS->inRootDir() && !RHS->inRootDir())
- return 1;
- else {
- ConsumeRootDir(LHS);
- ConsumeRootDir(RHS);
- return 0;
- }
-}
-
-static int CompareRelative(PathParser *LHSPtr, PathParser *RHSPtr) {
- auto &LHS = *LHSPtr;
- auto &RHS = *RHSPtr;
-
- int res;
- while (LHS && RHS) {
- if ((res = (*LHS).compare(*RHS)) != 0)
- return res;
- ++LHS;
- ++RHS;
- }
- return 0;
-}
-
-static int CompareEndState(PathParser *LHS, PathParser *RHS) {
- if (LHS->atEnd() && !RHS->atEnd())
- return -1;
- else if (!LHS->atEnd() && RHS->atEnd())
- return 1;
- return 0;
-}
-
-int path::__compare(string_view_t __s) const {
- auto LHS = PathParser::CreateBegin(__pn_);
- auto RHS = PathParser::CreateBegin(__s);
- int res;
-
- if ((res = CompareRootName(&LHS, &RHS)) != 0)
- return res;
-
- if ((res = CompareRootDir(&LHS, &RHS)) != 0)
- return res;
-
- if ((res = CompareRelative(&LHS, &RHS)) != 0)
- return res;
-
- return CompareEndState(&LHS, &RHS);
-}
-
-////////////////////////////////////////////////////////////////////////////
-// path.nonmembers
-size_t hash_value(const path& __p) noexcept {
- auto PP = PathParser::CreateBegin(__p.native());
- size_t hash_value = 0;
- hash<string_view_t> hasher;
- while (PP) {
- hash_value = __hash_combine(hash_value, hasher(*PP));
- ++PP;
- }
- return hash_value;
-}
-
-////////////////////////////////////////////////////////////////////////////
-// path.itr
-path::iterator path::begin() const {
- auto PP = PathParser::CreateBegin(__pn_);
- iterator it;
- it.__path_ptr_ = this;
- it.__state_ = static_cast<path::iterator::_ParserState>(PP.State);
- it.__entry_ = PP.RawEntry;
- it.__stashed_elem_.__assign_view(*PP);
- return it;
-}
-
-path::iterator path::end() const {
- iterator it{};
- it.__state_ = path::iterator::_AtEnd;
- it.__path_ptr_ = this;
- return it;
-}
-
-path::iterator& path::iterator::__increment() {
- PathParser PP(__path_ptr_->native(), __entry_, __state_);
- ++PP;
- __state_ = static_cast<_ParserState>(PP.State);
- __entry_ = PP.RawEntry;
- __stashed_elem_.__assign_view(*PP);
- return *this;
-}
-
-path::iterator& path::iterator::__decrement() {
- PathParser PP(__path_ptr_->native(), __entry_, __state_);
- --PP;
- __state_ = static_cast<_ParserState>(PP.State);
- __entry_ = PP.RawEntry;
- __stashed_elem_.__assign_view(*PP);
- return *this;
-}
-
-#if defined(_LIBCPP_WIN32API)
-////////////////////////////////////////////////////////////////////////////
-// Windows path conversions
-size_t __wide_to_char(const wstring &str, char *out, size_t outlen) {
- if (str.empty())
- return 0;
- ErrorHandler<size_t> err("__wide_to_char", nullptr);
- UINT codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP;
- BOOL used_default = FALSE;
- int ret = WideCharToMultiByte(codepage, 0, str.data(), str.size(), out,
- outlen, nullptr, &used_default);
- if (ret <= 0 || used_default)
- return err.report(errc::illegal_byte_sequence);
- return ret;
-}
-
-size_t __char_to_wide(const string &str, wchar_t *out, size_t outlen) {
- if (str.empty())
- return 0;
- ErrorHandler<size_t> err("__char_to_wide", nullptr);
- UINT codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP;
- int ret = MultiByteToWideChar(codepage, MB_ERR_INVALID_CHARS, str.data(),
- str.size(), out, outlen);
- if (ret <= 0)
- return err.report(errc::illegal_byte_sequence);
- return ret;
-}
-#endif
-
-
-///////////////////////////////////////////////////////////////////////////////
-// directory entry definitions
-///////////////////////////////////////////////////////////////////////////////
-
-#ifndef _LIBCPP_WIN32API
-error_code directory_entry::__do_refresh() noexcept {
- __data_.__reset();
- error_code failure_ec;
-
- StatT full_st;
- file_status st = detail::posix_lstat(__p_, full_st, &failure_ec);
- if (!status_known(st)) {
- __data_.__reset();
- return failure_ec;
- }
-
- if (!_VSTD_FS::exists(st) || !_VSTD_FS::is_symlink(st)) {
- __data_.__cache_type_ = directory_entry::_RefreshNonSymlink;
- __data_.__type_ = st.type();
- __data_.__non_sym_perms_ = st.permissions();
- } else { // we have a symlink
- __data_.__sym_perms_ = st.permissions();
- // Get the information about the linked entity.
- // Ignore errors from stat, since we don't want errors regarding symlink
- // resolution to be reported to the user.
- error_code ignored_ec;
- st = detail::posix_stat(__p_, full_st, &ignored_ec);
-
- __data_.__type_ = st.type();
- __data_.__non_sym_perms_ = st.permissions();
-
- // If we failed to resolve the link, then only partially populate the
- // cache.
- if (!status_known(st)) {
- __data_.__cache_type_ = directory_entry::_RefreshSymlinkUnresolved;
- return error_code{};
- }
- // Otherwise, we resolved the link, potentially as not existing.
- // That's OK.
- __data_.__cache_type_ = directory_entry::_RefreshSymlink;
- }
-
- if (_VSTD_FS::is_regular_file(st))
- __data_.__size_ = static_cast<uintmax_t>(full_st.st_size);
-
- if (_VSTD_FS::exists(st)) {
- __data_.__nlink_ = static_cast<uintmax_t>(full_st.st_nlink);
-
- // Attempt to extract the mtime, and fail if it's not representable using
- // file_time_type. For now we ignore the error, as we'll report it when
- // the value is actually used.
- error_code ignored_ec;
- __data_.__write_time_ =
- __extract_last_write_time(__p_, full_st, &ignored_ec);
- }
-
- return failure_ec;
-}
-#else
-error_code directory_entry::__do_refresh() noexcept {
- __data_.__reset();
- error_code failure_ec;
-
- file_status st = _VSTD_FS::symlink_status(__p_, failure_ec);
- if (!status_known(st)) {
- __data_.__reset();
- return failure_ec;
- }
-
- if (!_VSTD_FS::exists(st) || !_VSTD_FS::is_symlink(st)) {
- __data_.__cache_type_ = directory_entry::_RefreshNonSymlink;
- __data_.__type_ = st.type();
- __data_.__non_sym_perms_ = st.permissions();
- } else { // we have a symlink
- __data_.__sym_perms_ = st.permissions();
- // Get the information about the linked entity.
- // Ignore errors from stat, since we don't want errors regarding symlink
- // resolution to be reported to the user.
- error_code ignored_ec;
- st = _VSTD_FS::status(__p_, ignored_ec);
-
- __data_.__type_ = st.type();
- __data_.__non_sym_perms_ = st.permissions();
-
- // If we failed to resolve the link, then only partially populate the
- // cache.
- if (!status_known(st)) {
- __data_.__cache_type_ = directory_entry::_RefreshSymlinkUnresolved;
- return error_code{};
- }
- __data_.__cache_type_ = directory_entry::_RefreshSymlink;
- }
-
- // FIXME: This is currently broken, and the implementation only a placeholder.
- // We need to cache last_write_time, file_size, and hard_link_count here before
- // the implementation actually works.
-
- return failure_ec;
-}
-#endif
-
_LIBCPP_END_NAMESPACE_FILESYSTEM
diff --git a/contrib/llvm-project/libcxx/src/filesystem/path.cpp b/contrib/llvm-project/libcxx/src/filesystem/path.cpp
new file mode 100644
index 000000000000..c89346aa510c
--- /dev/null
+++ b/contrib/llvm-project/libcxx/src/filesystem/path.cpp
@@ -0,0 +1,441 @@
+//===----------------------------------------------------------------------===//
+//
+// 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>
+#include <filesystem>
+#include <vector>
+
+#include "error.h"
+#include "path_parser.h"
+
+_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
+
+using detail::ErrorHandler;
+using parser::createView;
+using parser::PathParser;
+using parser::string_view_t;
+
+///////////////////////////////////////////////////////////////////////////////
+// path definitions
+///////////////////////////////////////////////////////////////////////////////
+
+constexpr path::value_type path::preferred_separator;
+
+path& path::replace_extension(path const& replacement) {
+ path p = extension();
+ if (not p.empty()) {
+ __pn_.erase(__pn_.size() - p.native().size());
+ }
+ if (!replacement.empty()) {
+ if (replacement.native()[0] != '.') {
+ __pn_ += PATHSTR(".");
+ }
+ __pn_.append(replacement.__pn_);
+ }
+ return *this;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// path.decompose
+
+string_view_t path::__root_name() const {
+ auto PP = PathParser::CreateBegin(__pn_);
+ if (PP.State == PathParser::PS_InRootName)
+ return *PP;
+ return {};
+}
+
+string_view_t path::__root_directory() const {
+ auto PP = PathParser::CreateBegin(__pn_);
+ if (PP.State == PathParser::PS_InRootName)
+ ++PP;
+ if (PP.State == PathParser::PS_InRootDir)
+ return *PP;
+ return {};
+}
+
+string_view_t path::__root_path_raw() const {
+ auto PP = PathParser::CreateBegin(__pn_);
+ if (PP.State == PathParser::PS_InRootName) {
+ auto NextCh = PP.peek();
+ if (NextCh && isSeparator(*NextCh)) {
+ ++PP;
+ return createView(__pn_.data(), &PP.RawEntry.back());
+ }
+ return PP.RawEntry;
+ }
+ if (PP.State == PathParser::PS_InRootDir)
+ return *PP;
+ return {};
+}
+
+static bool ConsumeRootName(PathParser* PP) {
+ static_assert(PathParser::PS_BeforeBegin == 1 && PathParser::PS_InRootName == 2, "Values for enums are incorrect");
+ while (PP->State <= PathParser::PS_InRootName)
+ ++(*PP);
+ return PP->State == PathParser::PS_AtEnd;
+}
+
+static bool ConsumeRootDir(PathParser* PP) {
+ static_assert(PathParser::PS_BeforeBegin == 1 && PathParser::PS_InRootName == 2 && PathParser::PS_InRootDir == 3,
+ "Values for enums are incorrect");
+ while (PP->State <= PathParser::PS_InRootDir)
+ ++(*PP);
+ return PP->State == PathParser::PS_AtEnd;
+}
+
+string_view_t path::__relative_path() const {
+ auto PP = PathParser::CreateBegin(__pn_);
+ if (ConsumeRootDir(&PP))
+ return {};
+ return createView(PP.RawEntry.data(), &__pn_.back());
+}
+
+string_view_t path::__parent_path() const {
+ if (empty())
+ return {};
+ // Determine if we have a root path but not a relative path. In that case
+ // return *this.
+ {
+ auto PP = PathParser::CreateBegin(__pn_);
+ if (ConsumeRootDir(&PP))
+ return __pn_;
+ }
+ // Otherwise remove a single element from the end of the path, and return
+ // a string representing that path
+ {
+ auto PP = PathParser::CreateEnd(__pn_);
+ --PP;
+ if (PP.RawEntry.data() == __pn_.data())
+ return {};
+ --PP;
+ return createView(__pn_.data(), &PP.RawEntry.back());
+ }
+}
+
+string_view_t path::__filename() const {
+ if (empty())
+ return {};
+ {
+ PathParser PP = PathParser::CreateBegin(__pn_);
+ if (ConsumeRootDir(&PP))
+ return {};
+ }
+ return *(--PathParser::CreateEnd(__pn_));
+}
+
+string_view_t path::__stem() const { return parser::separate_filename(__filename()).first; }
+
+string_view_t path::__extension() const { return parser::separate_filename(__filename()).second; }
+
+////////////////////////////////////////////////////////////////////////////
+// path.gen
+
+enum PathPartKind : unsigned char { PK_None, PK_RootSep, PK_Filename, PK_Dot, PK_DotDot, PK_TrailingSep };
+
+static PathPartKind ClassifyPathPart(string_view_t Part) {
+ if (Part.empty())
+ return PK_TrailingSep;
+ if (Part == PATHSTR("."))
+ return PK_Dot;
+ if (Part == PATHSTR(".."))
+ return PK_DotDot;
+ if (Part == PATHSTR("/"))
+ return PK_RootSep;
+#if defined(_LIBCPP_WIN32API)
+ if (Part == PATHSTR("\\"))
+ return PK_RootSep;
+#endif
+ return PK_Filename;
+}
+
+path path::lexically_normal() const {
+ if (__pn_.empty())
+ return *this;
+
+ using PartKindPair = pair<string_view_t, PathPartKind>;
+ vector<PartKindPair> Parts;
+ // Guess as to how many elements the path has to avoid reallocating.
+ Parts.reserve(32);
+
+ // Track the total size of the parts as we collect them. This allows the
+ // resulting path to reserve the correct amount of memory.
+ size_t NewPathSize = 0;
+ auto AddPart = [&](PathPartKind K, string_view_t P) {
+ NewPathSize += P.size();
+ Parts.emplace_back(P, K);
+ };
+ auto LastPartKind = [&]() {
+ if (Parts.empty())
+ return PK_None;
+ return Parts.back().second;
+ };
+
+ bool MaybeNeedTrailingSep = false;
+ // Build a stack containing the remaining elements of the path, popping off
+ // elements which occur before a '..' entry.
+ for (auto PP = PathParser::CreateBegin(__pn_); PP; ++PP) {
+ auto Part = *PP;
+ PathPartKind Kind = ClassifyPathPart(Part);
+ switch (Kind) {
+ case PK_Filename:
+ case PK_RootSep: {
+ // Add all non-dot and non-dot-dot elements to the stack of elements.
+ AddPart(Kind, Part);
+ MaybeNeedTrailingSep = false;
+ break;
+ }
+ case PK_DotDot: {
+ // Only push a ".." element if there are no elements preceding the "..",
+ // or if the preceding element is itself "..".
+ auto LastKind = LastPartKind();
+ if (LastKind == PK_Filename) {
+ NewPathSize -= Parts.back().first.size();
+ Parts.pop_back();
+ } else if (LastKind != PK_RootSep)
+ AddPart(PK_DotDot, PATHSTR(".."));
+ MaybeNeedTrailingSep = LastKind == PK_Filename;
+ break;
+ }
+ case PK_Dot:
+ case PK_TrailingSep: {
+ MaybeNeedTrailingSep = true;
+ break;
+ }
+ case PK_None:
+ __libcpp_unreachable();
+ }
+ }
+ // [fs.path.generic]p6.8: If the path is empty, add a dot.
+ if (Parts.empty())
+ return PATHSTR(".");
+
+ // [fs.path.generic]p6.7: If the last filename is dot-dot, remove any
+ // trailing directory-separator.
+ bool NeedTrailingSep = MaybeNeedTrailingSep && LastPartKind() == PK_Filename;
+
+ path Result;
+ Result.__pn_.reserve(Parts.size() + NewPathSize + NeedTrailingSep);
+ for (auto& PK : Parts)
+ Result /= PK.first;
+
+ if (NeedTrailingSep)
+ Result /= PATHSTR("");
+
+ Result.make_preferred();
+ return Result;
+}
+
+static int DetermineLexicalElementCount(PathParser PP) {
+ int Count = 0;
+ for (; PP; ++PP) {
+ auto Elem = *PP;
+ if (Elem == PATHSTR(".."))
+ --Count;
+ else if (Elem != PATHSTR(".") && Elem != PATHSTR(""))
+ ++Count;
+ }
+ return Count;
+}
+
+path path::lexically_relative(const path& base) const {
+ { // perform root-name/root-directory mismatch checks
+ auto PP = PathParser::CreateBegin(__pn_);
+ auto PPBase = PathParser::CreateBegin(base.__pn_);
+ auto CheckIterMismatchAtBase = [&]() {
+ return PP.State != PPBase.State && (PP.inRootPath() || PPBase.inRootPath());
+ };
+ if (PP.inRootName() && PPBase.inRootName()) {
+ if (*PP != *PPBase)
+ return {};
+ } else if (CheckIterMismatchAtBase())
+ return {};
+
+ if (PP.inRootPath())
+ ++PP;
+ if (PPBase.inRootPath())
+ ++PPBase;
+ if (CheckIterMismatchAtBase())
+ return {};
+ }
+
+ // Find the first mismatching element
+ auto PP = PathParser::CreateBegin(__pn_);
+ auto PPBase = PathParser::CreateBegin(base.__pn_);
+ while (PP && PPBase && PP.State == PPBase.State && *PP == *PPBase) {
+ ++PP;
+ ++PPBase;
+ }
+
+ // If there is no mismatch, return ".".
+ if (!PP && !PPBase)
+ return ".";
+
+ // Otherwise, determine the number of elements, 'n', which are not dot or
+ // dot-dot minus the number of dot-dot elements.
+ int ElemCount = DetermineLexicalElementCount(PPBase);
+ if (ElemCount < 0)
+ return {};
+
+ // if n == 0 and (a == end() || a->empty()), returns path("."); otherwise
+ if (ElemCount == 0 && (PP.atEnd() || *PP == PATHSTR("")))
+ return PATHSTR(".");
+
+ // return a path constructed with 'n' dot-dot elements, followed by the
+ // elements of '*this' after the mismatch.
+ path Result;
+ // FIXME: Reserve enough room in Result that it won't have to re-allocate.
+ while (ElemCount--)
+ Result /= PATHSTR("..");
+ for (; PP; ++PP)
+ Result /= *PP;
+ return Result;
+}
+
+////////////////////////////////////////////////////////////////////////////
+// path.comparisons
+static int CompareRootName(PathParser* LHS, PathParser* RHS) {
+ if (!LHS->inRootName() && !RHS->inRootName())
+ return 0;
+
+ auto GetRootName = [](PathParser* Parser) -> string_view_t { return Parser->inRootName() ? **Parser : PATHSTR(""); };
+ int res = GetRootName(LHS).compare(GetRootName(RHS));
+ ConsumeRootName(LHS);
+ ConsumeRootName(RHS);
+ return res;
+}
+
+static int CompareRootDir(PathParser* LHS, PathParser* RHS) {
+ if (!LHS->inRootDir() && RHS->inRootDir())
+ return -1;
+ else if (LHS->inRootDir() && !RHS->inRootDir())
+ return 1;
+ else {
+ ConsumeRootDir(LHS);
+ ConsumeRootDir(RHS);
+ return 0;
+ }
+}
+
+static int CompareRelative(PathParser* LHSPtr, PathParser* RHSPtr) {
+ auto& LHS = *LHSPtr;
+ auto& RHS = *RHSPtr;
+
+ int res;
+ while (LHS && RHS) {
+ if ((res = (*LHS).compare(*RHS)) != 0)
+ return res;
+ ++LHS;
+ ++RHS;
+ }
+ return 0;
+}
+
+static int CompareEndState(PathParser* LHS, PathParser* RHS) {
+ if (LHS->atEnd() && !RHS->atEnd())
+ return -1;
+ else if (!LHS->atEnd() && RHS->atEnd())
+ return 1;
+ return 0;
+}
+
+int path::__compare(string_view_t __s) const {
+ auto LHS = PathParser::CreateBegin(__pn_);
+ auto RHS = PathParser::CreateBegin(__s);
+ int res;
+
+ if ((res = CompareRootName(&LHS, &RHS)) != 0)
+ return res;
+
+ if ((res = CompareRootDir(&LHS, &RHS)) != 0)
+ return res;
+
+ if ((res = CompareRelative(&LHS, &RHS)) != 0)
+ return res;
+
+ return CompareEndState(&LHS, &RHS);
+}
+
+////////////////////////////////////////////////////////////////////////////
+// path.nonmembers
+size_t hash_value(const path& __p) noexcept {
+ auto PP = PathParser::CreateBegin(__p.native());
+ size_t hash_value = 0;
+ hash<string_view_t> hasher;
+ while (PP) {
+ hash_value = __hash_combine(hash_value, hasher(*PP));
+ ++PP;
+ }
+ return hash_value;
+}
+
+////////////////////////////////////////////////////////////////////////////
+// path.itr
+path::iterator path::begin() const {
+ auto PP = PathParser::CreateBegin(__pn_);
+ iterator it;
+ it.__path_ptr_ = this;
+ it.__state_ = static_cast<path::iterator::_ParserState>(PP.State);
+ it.__entry_ = PP.RawEntry;
+ it.__stashed_elem_.__assign_view(*PP);
+ return it;
+}
+
+path::iterator path::end() const {
+ iterator it{};
+ it.__state_ = path::iterator::_AtEnd;
+ it.__path_ptr_ = this;
+ return it;
+}
+
+path::iterator& path::iterator::__increment() {
+ PathParser PP(__path_ptr_->native(), __entry_, __state_);
+ ++PP;
+ __state_ = static_cast<_ParserState>(PP.State);
+ __entry_ = PP.RawEntry;
+ __stashed_elem_.__assign_view(*PP);
+ return *this;
+}
+
+path::iterator& path::iterator::__decrement() {
+ PathParser PP(__path_ptr_->native(), __entry_, __state_);
+ --PP;
+ __state_ = static_cast<_ParserState>(PP.State);
+ __entry_ = PP.RawEntry;
+ __stashed_elem_.__assign_view(*PP);
+ return *this;
+}
+
+#if defined(_LIBCPP_WIN32API)
+////////////////////////////////////////////////////////////////////////////
+// Windows path conversions
+size_t __wide_to_char(const wstring& str, char* out, size_t outlen) {
+ if (str.empty())
+ return 0;
+ ErrorHandler<size_t> err("__wide_to_char", nullptr);
+ UINT codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP;
+ BOOL used_default = FALSE;
+ int ret = WideCharToMultiByte(codepage, 0, str.data(), str.size(), out, outlen, nullptr, &used_default);
+ if (ret <= 0 || used_default)
+ return err.report(errc::illegal_byte_sequence);
+ return ret;
+}
+
+size_t __char_to_wide(const string& str, wchar_t* out, size_t outlen) {
+ if (str.empty())
+ return 0;
+ ErrorHandler<size_t> err("__char_to_wide", nullptr);
+ UINT codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP;
+ int ret = MultiByteToWideChar(codepage, MB_ERR_INVALID_CHARS, str.data(), str.size(), out, outlen);
+ if (ret <= 0)
+ return err.report(errc::illegal_byte_sequence);
+ return ret;
+}
+#endif
+
+_LIBCPP_END_NAMESPACE_FILESYSTEM
diff --git a/contrib/llvm-project/libcxx/src/filesystem/path_parser.h b/contrib/llvm-project/libcxx/src/filesystem/path_parser.h
new file mode 100644
index 000000000000..28a8f240e3bd
--- /dev/null
+++ b/contrib/llvm-project/libcxx/src/filesystem/path_parser.h
@@ -0,0 +1,352 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 PATH_PARSER_H
+#define PATH_PARSER_H
+
+#include <__config>
+#include <__utility/unreachable.h>
+#include <cstddef>
+#include <filesystem>
+#include <utility>
+
+#include "format_string.h"
+
+_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
+
+inline bool isSeparator(path::value_type C) {
+ if (C == '/')
+ return true;
+#if defined(_LIBCPP_WIN32API)
+ if (C == '\\')
+ return true;
+#endif
+ return false;
+}
+
+inline bool isDriveLetter(path::value_type C) { return (C >= 'a' && C <= 'z') || (C >= 'A' && C <= 'Z'); }
+
+namespace parser {
+
+using string_view_t = path::__string_view;
+using string_view_pair = pair<string_view_t, string_view_t>;
+using PosPtr = path::value_type const*;
+
+struct PathParser {
+ enum ParserState : unsigned char {
+ // Zero is a special sentinel value used by default constructed iterators.
+ PS_BeforeBegin = path::iterator::_BeforeBegin,
+ PS_InRootName = path::iterator::_InRootName,
+ PS_InRootDir = path::iterator::_InRootDir,
+ PS_InFilenames = path::iterator::_InFilenames,
+ PS_InTrailingSep = path::iterator::_InTrailingSep,
+ PS_AtEnd = path::iterator::_AtEnd
+ };
+
+ const string_view_t Path;
+ string_view_t RawEntry;
+ ParserState State;
+
+private:
+ PathParser(string_view_t P, ParserState State) noexcept : Path(P), State(State) {}
+
+public:
+ PathParser(string_view_t P, string_view_t E, unsigned char S)
+ : Path(P), RawEntry(E), State(static_cast<ParserState>(S)) {
+ // S cannot be '0' or PS_BeforeBegin.
+ }
+
+ static PathParser CreateBegin(string_view_t P) noexcept {
+ PathParser PP(P, PS_BeforeBegin);
+ PP.increment();
+ return PP;
+ }
+
+ static PathParser CreateEnd(string_view_t P) noexcept {
+ PathParser PP(P, PS_AtEnd);
+ return PP;
+ }
+
+ PosPtr peek() const noexcept {
+ auto TkEnd = getNextTokenStartPos();
+ auto End = getAfterBack();
+ return TkEnd == End ? nullptr : TkEnd;
+ }
+
+ void increment() noexcept {
+ const PosPtr End = getAfterBack();
+ const PosPtr Start = getNextTokenStartPos();
+ if (Start == End)
+ return makeState(PS_AtEnd);
+
+ switch (State) {
+ case PS_BeforeBegin: {
+ PosPtr TkEnd = consumeRootName(Start, End);
+ if (TkEnd)
+ return makeState(PS_InRootName, Start, TkEnd);
+ }
+ _LIBCPP_FALLTHROUGH();
+ case PS_InRootName: {
+ PosPtr TkEnd = consumeAllSeparators(Start, End);
+ if (TkEnd)
+ return makeState(PS_InRootDir, Start, TkEnd);
+ else
+ return makeState(PS_InFilenames, Start, consumeName(Start, End));
+ }
+ case PS_InRootDir:
+ return makeState(PS_InFilenames, Start, consumeName(Start, End));
+
+ case PS_InFilenames: {
+ PosPtr SepEnd = consumeAllSeparators(Start, End);
+ if (SepEnd != End) {
+ PosPtr TkEnd = consumeName(SepEnd, End);
+ if (TkEnd)
+ return makeState(PS_InFilenames, SepEnd, TkEnd);
+ }
+ return makeState(PS_InTrailingSep, Start, SepEnd);
+ }
+
+ case PS_InTrailingSep:
+ return makeState(PS_AtEnd);
+
+ case PS_AtEnd:
+ __libcpp_unreachable();
+ }
+ }
+
+ void decrement() noexcept {
+ const PosPtr REnd = getBeforeFront();
+ const PosPtr RStart = getCurrentTokenStartPos() - 1;
+ if (RStart == REnd) // we're decrementing the begin
+ return makeState(PS_BeforeBegin);
+
+ switch (State) {
+ case PS_AtEnd: {
+ // Try to consume a trailing separator or root directory first.
+ if (PosPtr SepEnd = consumeAllSeparators(RStart, REnd)) {
+ if (SepEnd == REnd)
+ return makeState(PS_InRootDir, Path.data(), RStart + 1);
+ PosPtr TkStart = consumeRootName(SepEnd, REnd);
+ if (TkStart == REnd)
+ return makeState(PS_InRootDir, RStart, RStart + 1);
+ return makeState(PS_InTrailingSep, SepEnd + 1, RStart + 1);
+ } else {
+ PosPtr TkStart = consumeRootName(RStart, REnd);
+ if (TkStart == REnd)
+ return makeState(PS_InRootName, TkStart + 1, RStart + 1);
+ TkStart = consumeName(RStart, REnd);
+ return makeState(PS_InFilenames, TkStart + 1, RStart + 1);
+ }
+ }
+ case PS_InTrailingSep:
+ return makeState(PS_InFilenames, consumeName(RStart, REnd) + 1, RStart + 1);
+ case PS_InFilenames: {
+ PosPtr SepEnd = consumeAllSeparators(RStart, REnd);
+ if (SepEnd == REnd)
+ return makeState(PS_InRootDir, Path.data(), RStart + 1);
+ PosPtr TkStart = consumeRootName(SepEnd ? SepEnd : RStart, REnd);
+ if (TkStart == REnd) {
+ if (SepEnd)
+ return makeState(PS_InRootDir, SepEnd + 1, RStart + 1);
+ return makeState(PS_InRootName, TkStart + 1, RStart + 1);
+ }
+ TkStart = consumeName(SepEnd, REnd);
+ return makeState(PS_InFilenames, TkStart + 1, SepEnd + 1);
+ }
+ case PS_InRootDir:
+ return makeState(PS_InRootName, Path.data(), RStart + 1);
+ case PS_InRootName:
+ case PS_BeforeBegin:
+ __libcpp_unreachable();
+ }
+ }
+
+ /// \brief Return a view with the "preferred representation" of the current
+ /// element. For example trailing separators are represented as a '.'
+ string_view_t operator*() const noexcept {
+ switch (State) {
+ case PS_BeforeBegin:
+ case PS_AtEnd:
+ return PATHSTR("");
+ case PS_InRootDir:
+ if (RawEntry[0] == '\\')
+ return PATHSTR("\\");
+ else
+ return PATHSTR("/");
+ case PS_InTrailingSep:
+ return PATHSTR("");
+ case PS_InRootName:
+ case PS_InFilenames:
+ return RawEntry;
+ }
+ __libcpp_unreachable();
+ }
+
+ explicit operator bool() const noexcept { return State != PS_BeforeBegin && State != PS_AtEnd; }
+
+ PathParser& operator++() noexcept {
+ increment();
+ return *this;
+ }
+
+ PathParser& operator--() noexcept {
+ decrement();
+ return *this;
+ }
+
+ bool atEnd() const noexcept { return State == PS_AtEnd; }
+
+ bool inRootDir() const noexcept { return State == PS_InRootDir; }
+
+ bool inRootName() const noexcept { return State == PS_InRootName; }
+
+ bool inRootPath() const noexcept { return inRootName() || inRootDir(); }
+
+private:
+ void makeState(ParserState NewState, PosPtr Start, PosPtr End) noexcept {
+ State = NewState;
+ RawEntry = string_view_t(Start, End - Start);
+ }
+ void makeState(ParserState NewState) noexcept {
+ State = NewState;
+ RawEntry = {};
+ }
+
+ PosPtr getAfterBack() const noexcept { return Path.data() + Path.size(); }
+
+ PosPtr getBeforeFront() const noexcept { return Path.data() - 1; }
+
+ /// \brief Return a pointer to the first character after the currently
+ /// lexed element.
+ PosPtr getNextTokenStartPos() const noexcept {
+ switch (State) {
+ case PS_BeforeBegin:
+ return Path.data();
+ case PS_InRootName:
+ case PS_InRootDir:
+ case PS_InFilenames:
+ return &RawEntry.back() + 1;
+ case PS_InTrailingSep:
+ case PS_AtEnd:
+ return getAfterBack();
+ }
+ __libcpp_unreachable();
+ }
+
+ /// \brief Return a pointer to the first character in the currently lexed
+ /// element.
+ PosPtr getCurrentTokenStartPos() const noexcept {
+ switch (State) {
+ case PS_BeforeBegin:
+ case PS_InRootName:
+ return &Path.front();
+ case PS_InRootDir:
+ case PS_InFilenames:
+ case PS_InTrailingSep:
+ return &RawEntry.front();
+ case PS_AtEnd:
+ return &Path.back() + 1;
+ }
+ __libcpp_unreachable();
+ }
+
+ // Consume all consecutive separators.
+ PosPtr consumeAllSeparators(PosPtr P, PosPtr End) const noexcept {
+ if (P == nullptr || P == End || !isSeparator(*P))
+ return nullptr;
+ const int Inc = P < End ? 1 : -1;
+ P += Inc;
+ while (P != End && isSeparator(*P))
+ P += Inc;
+ return P;
+ }
+
+ // Consume exactly N separators, or return nullptr.
+ PosPtr consumeNSeparators(PosPtr P, PosPtr End, int N) const noexcept {
+ PosPtr Ret = consumeAllSeparators(P, End);
+ if (Ret == nullptr)
+ return nullptr;
+ if (P < End) {
+ if (Ret == P + N)
+ return Ret;
+ } else {
+ if (Ret == P - N)
+ return Ret;
+ }
+ return nullptr;
+ }
+
+ PosPtr consumeName(PosPtr P, PosPtr End) const noexcept {
+ PosPtr Start = P;
+ if (P == nullptr || P == End || isSeparator(*P))
+ return nullptr;
+ const int Inc = P < End ? 1 : -1;
+ P += Inc;
+ while (P != End && !isSeparator(*P))
+ P += Inc;
+ if (P == End && Inc < 0) {
+ // Iterating backwards and consumed all the rest of the input.
+ // Check if the start of the string would have been considered
+ // a root name.
+ PosPtr RootEnd = consumeRootName(End + 1, Start);
+ if (RootEnd)
+ return RootEnd - 1;
+ }
+ return P;
+ }
+
+ PosPtr consumeDriveLetter(PosPtr P, PosPtr End) const noexcept {
+ if (P == End)
+ return nullptr;
+ if (P < End) {
+ if (P + 1 == End || !isDriveLetter(P[0]) || P[1] != ':')
+ return nullptr;
+ return P + 2;
+ } else {
+ if (P - 1 == End || !isDriveLetter(P[-1]) || P[0] != ':')
+ return nullptr;
+ return P - 2;
+ }
+ }
+
+ PosPtr consumeNetworkRoot(PosPtr P, PosPtr End) const noexcept {
+ if (P == End)
+ return nullptr;
+ if (P < End)
+ return consumeName(consumeNSeparators(P, End, 2), End);
+ else
+ return consumeNSeparators(consumeName(P, End), End, 2);
+ }
+
+ PosPtr consumeRootName(PosPtr P, PosPtr End) const noexcept {
+#if defined(_LIBCPP_WIN32API)
+ if (PosPtr Ret = consumeDriveLetter(P, End))
+ return Ret;
+ if (PosPtr Ret = consumeNetworkRoot(P, End))
+ return Ret;
+#endif
+ return nullptr;
+ }
+};
+
+inline string_view_pair separate_filename(string_view_t const& s) {
+ if (s == PATHSTR(".") || s == PATHSTR("..") || s.empty())
+ return string_view_pair{s, PATHSTR("")};
+ auto pos = s.find_last_of('.');
+ if (pos == string_view_t::npos || pos == 0)
+ return string_view_pair{s, string_view_t{}};
+ return string_view_pair{s.substr(0, pos), s.substr(pos)};
+}
+
+inline string_view_t createView(PosPtr S, PosPtr E) noexcept { return {S, static_cast<size_t>(E - S) + 1}; }
+
+} // namespace parser
+
+_LIBCPP_END_NAMESPACE_FILESYSTEM
+
+#endif // PATH_PARSER_H
diff --git a/contrib/llvm-project/libcxx/src/filesystem/posix_compat.h b/contrib/llvm-project/libcxx/src/filesystem/posix_compat.h
new file mode 100644
index 000000000000..760cdb65dae1
--- /dev/null
+++ b/contrib/llvm-project/libcxx/src/filesystem/posix_compat.h
@@ -0,0 +1,497 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+//
+// POSIX-like portability helper functions.
+//
+// These generally behave like the proper posix functions, with these
+// exceptions:
+// On Windows, they take paths in wchar_t* form, instead of char* form.
+// The symlink() function is split into two frontends, symlink_file()
+// and symlink_dir().
+//
+// These are provided within an anonymous namespace within the detail
+// namespace - callers need to include this header and call them as
+// detail::function(), regardless of platform.
+//
+
+#ifndef POSIX_COMPAT_H
+#define POSIX_COMPAT_H
+
+#include <__assert>
+#include <__config>
+#include <filesystem>
+
+#include "error.h"
+#include "time_utils.h"
+
+#if defined(_LIBCPP_WIN32API)
+# define WIN32_LEAN_AND_MEAN
+# define NOMINMAX
+# include <io.h>
+# include <windows.h>
+# include <winioctl.h>
+#else
+# include <fcntl.h>
+# include <sys/stat.h>
+# include <sys/statvfs.h>
+# include <sys/time.h>
+# include <unistd.h>
+#endif
+#include <stdlib.h>
+#include <time.h>
+
+#if defined(_LIBCPP_WIN32API)
+// This struct isn't defined in the normal Windows SDK, but only in the
+// Windows Driver Kit.
+struct LIBCPP_REPARSE_DATA_BUFFER {
+ unsigned long ReparseTag;
+ unsigned short ReparseDataLength;
+ unsigned short Reserved;
+ union {
+ struct {
+ unsigned short SubstituteNameOffset;
+ unsigned short SubstituteNameLength;
+ unsigned short PrintNameOffset;
+ unsigned short PrintNameLength;
+ unsigned long Flags;
+ wchar_t PathBuffer[1];
+ } SymbolicLinkReparseBuffer;
+ struct {
+ unsigned short SubstituteNameOffset;
+ unsigned short SubstituteNameLength;
+ unsigned short PrintNameOffset;
+ unsigned short PrintNameLength;
+ wchar_t PathBuffer[1];
+ } MountPointReparseBuffer;
+ struct {
+ unsigned char DataBuffer[1];
+ } GenericReparseBuffer;
+ };
+};
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
+
+namespace detail {
+
+#if defined(_LIBCPP_WIN32API)
+
+// Various C runtime header sets provide more or less of these. As we
+// provide our own implementation, undef all potential defines from the
+// C runtime headers and provide a complete set of macros of our own.
+
+# undef _S_IFMT
+# undef _S_IFDIR
+# undef _S_IFCHR
+# undef _S_IFIFO
+# undef _S_IFREG
+# undef _S_IFBLK
+# undef _S_IFLNK
+# undef _S_IFSOCK
+
+# define _S_IFMT 0xF000
+# define _S_IFDIR 0x4000
+# define _S_IFCHR 0x2000
+# define _S_IFIFO 0x1000
+# define _S_IFREG 0x8000
+# define _S_IFBLK 0x6000
+# define _S_IFLNK 0xA000
+# define _S_IFSOCK 0xC000
+
+# undef S_ISDIR
+# undef S_ISFIFO
+# undef S_ISCHR
+# undef S_ISREG
+# undef S_ISLNK
+# undef S_ISBLK
+# undef S_ISSOCK
+
+# define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR)
+# define S_ISCHR(m) (((m) & _S_IFMT) == _S_IFCHR)
+# define S_ISFIFO(m) (((m) & _S_IFMT) == _S_IFIFO)
+# define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
+# define S_ISBLK(m) (((m) & _S_IFMT) == _S_IFBLK)
+# define S_ISLNK(m) (((m) & _S_IFMT) == _S_IFLNK)
+# define S_ISSOCK(m) (((m) & _S_IFMT) == _S_IFSOCK)
+
+# define O_NONBLOCK 0
+
+inline int set_errno(int e = GetLastError()) {
+ errno = static_cast<int>(__win_err_to_errc(e));
+ return -1;
+}
+
+class WinHandle {
+public:
+ WinHandle(const wchar_t* p, DWORD access, DWORD flags) {
+ h = CreateFileW(
+ p,
+ access,
+ FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
+ nullptr,
+ OPEN_EXISTING,
+ FILE_FLAG_BACKUP_SEMANTICS | flags,
+ nullptr);
+ }
+ ~WinHandle() {
+ if (h != INVALID_HANDLE_VALUE)
+ CloseHandle(h);
+ }
+ operator HANDLE() const { return h; }
+ operator bool() const { return h != INVALID_HANDLE_VALUE; }
+
+private:
+ HANDLE h;
+};
+
+inline int stat_handle(HANDLE h, StatT* buf) {
+ FILE_BASIC_INFO basic;
+ if (!GetFileInformationByHandleEx(h, FileBasicInfo, &basic, sizeof(basic)))
+ return set_errno();
+ memset(buf, 0, sizeof(*buf));
+ buf->st_mtim = filetime_to_timespec(basic.LastWriteTime);
+ buf->st_atim = filetime_to_timespec(basic.LastAccessTime);
+ buf->st_mode = 0555; // Read-only
+ if (!(basic.FileAttributes & FILE_ATTRIBUTE_READONLY))
+ buf->st_mode |= 0222; // Write
+ if (basic.FileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
+ buf->st_mode |= _S_IFDIR;
+ } else {
+ buf->st_mode |= _S_IFREG;
+ }
+ if (basic.FileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) {
+ FILE_ATTRIBUTE_TAG_INFO tag;
+ if (!GetFileInformationByHandleEx(h, FileAttributeTagInfo, &tag, sizeof(tag)))
+ return set_errno();
+ if (tag.ReparseTag == IO_REPARSE_TAG_SYMLINK)
+ buf->st_mode = (buf->st_mode & ~_S_IFMT) | _S_IFLNK;
+ }
+ FILE_STANDARD_INFO standard;
+ if (!GetFileInformationByHandleEx(h, FileStandardInfo, &standard, sizeof(standard)))
+ return set_errno();
+ buf->st_nlink = standard.NumberOfLinks;
+ buf->st_size = standard.EndOfFile.QuadPart;
+ BY_HANDLE_FILE_INFORMATION info;
+ if (!GetFileInformationByHandle(h, &info))
+ return set_errno();
+ buf->st_dev = info.dwVolumeSerialNumber;
+ memcpy(&buf->st_ino.id[0], &info.nFileIndexHigh, 4);
+ memcpy(&buf->st_ino.id[4], &info.nFileIndexLow, 4);
+ return 0;
+}
+
+inline int stat_file(const wchar_t* path, StatT* buf, DWORD flags) {
+ WinHandle h(path, FILE_READ_ATTRIBUTES, flags);
+ if (!h)
+ return set_errno();
+ int ret = stat_handle(h, buf);
+ return ret;
+}
+
+inline int stat(const wchar_t* path, StatT* buf) { return stat_file(path, buf, 0); }
+
+inline int lstat(const wchar_t* path, StatT* buf) { return stat_file(path, buf, FILE_FLAG_OPEN_REPARSE_POINT); }
+
+inline int fstat(int fd, StatT* buf) {
+ HANDLE h = reinterpret_cast<HANDLE>(_get_osfhandle(fd));
+ return stat_handle(h, buf);
+}
+
+inline int mkdir(const wchar_t* path, int permissions) {
+ (void)permissions;
+ if (!CreateDirectoryW(path, nullptr))
+ return set_errno();
+ return 0;
+}
+
+inline int symlink_file_dir(const wchar_t* oldname, const wchar_t* newname, bool is_dir) {
+ path dest(oldname);
+ dest.make_preferred();
+ oldname = dest.c_str();
+ DWORD flags = is_dir ? SYMBOLIC_LINK_FLAG_DIRECTORY : 0;
+ if (CreateSymbolicLinkW(newname, oldname, flags | SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE))
+ return 0;
+ int e = GetLastError();
+ if (e != ERROR_INVALID_PARAMETER)
+ return set_errno(e);
+ if (CreateSymbolicLinkW(newname, oldname, flags))
+ return 0;
+ return set_errno();
+}
+
+inline int symlink_file(const wchar_t* oldname, const wchar_t* newname) {
+ return symlink_file_dir(oldname, newname, false);
+}
+
+inline int symlink_dir(const wchar_t* oldname, const wchar_t* newname) {
+ return symlink_file_dir(oldname, newname, true);
+}
+
+inline int link(const wchar_t* oldname, const wchar_t* newname) {
+ if (CreateHardLinkW(newname, oldname, nullptr))
+ return 0;
+ return set_errno();
+}
+
+inline int remove(const wchar_t* path) {
+ detail::WinHandle h(path, DELETE, FILE_FLAG_OPEN_REPARSE_POINT);
+ if (!h)
+ return set_errno();
+ FILE_DISPOSITION_INFO info;
+ info.DeleteFile = TRUE;
+ if (!SetFileInformationByHandle(h, FileDispositionInfo, &info, sizeof(info)))
+ return set_errno();
+ return 0;
+}
+
+inline int truncate_handle(HANDLE h, off_t length) {
+ LARGE_INTEGER size_param;
+ size_param.QuadPart = length;
+ if (!SetFilePointerEx(h, size_param, 0, FILE_BEGIN))
+ return set_errno();
+ if (!SetEndOfFile(h))
+ return set_errno();
+ return 0;
+}
+
+inline int ftruncate(int fd, off_t length) {
+ HANDLE h = reinterpret_cast<HANDLE>(_get_osfhandle(fd));
+ return truncate_handle(h, length);
+}
+
+inline int truncate(const wchar_t* path, off_t length) {
+ detail::WinHandle h(path, GENERIC_WRITE, 0);
+ if (!h)
+ return set_errno();
+ return truncate_handle(h, length);
+}
+
+inline int rename(const wchar_t* from, const wchar_t* to) {
+ if (!(MoveFileExW(from, to, MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH)))
+ return set_errno();
+ return 0;
+}
+
+inline int chdir(const wchar_t* path) {
+ if (!SetCurrentDirectoryW(path))
+ return set_errno();
+ return 0;
+}
+
+struct StatVFS {
+ uint64_t f_frsize;
+ uint64_t f_blocks;
+ uint64_t f_bfree;
+ uint64_t f_bavail;
+};
+
+inline int statvfs(const wchar_t* p, StatVFS* buf) {
+ path dir = p;
+ while (true) {
+ error_code local_ec;
+ const file_status st = status(dir, local_ec);
+ if (!exists(st) || is_directory(st))
+ break;
+ path parent = dir.parent_path();
+ if (parent == dir) {
+ errno = ENOENT;
+ return -1;
+ }
+ dir = parent;
+ }
+ ULARGE_INTEGER free_bytes_available_to_caller, total_number_of_bytes, total_number_of_free_bytes;
+ if (!GetDiskFreeSpaceExW(
+ dir.c_str(), &free_bytes_available_to_caller, &total_number_of_bytes, &total_number_of_free_bytes))
+ return set_errno();
+ buf->f_frsize = 1;
+ buf->f_blocks = total_number_of_bytes.QuadPart;
+ buf->f_bfree = total_number_of_free_bytes.QuadPart;
+ buf->f_bavail = free_bytes_available_to_caller.QuadPart;
+ return 0;
+}
+
+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_INTERNAL(in_buf == nullptr, "Windows getcwd() assumes in_buf==nullptr");
+ _LIBCPP_ASSERT_INTERNAL(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);
+ DWORD retval = GetCurrentDirectoryW(buff_size, buff.get());
+ if (retval > buff_size) {
+ buff_size = retval;
+ buff.reset(static_cast<wchar_t*>(malloc(buff_size * sizeof(wchar_t))));
+ retval = GetCurrentDirectoryW(buff_size, buff.get());
+ }
+ if (!retval) {
+ set_errno();
+ return nullptr;
+ }
+ return buff.release();
+}
+
+inline wchar_t* realpath(const wchar_t* path, [[maybe_unused]] wchar_t* resolved_name) {
+ // Only expected to be used with us allocating the buffer.
+ _LIBCPP_ASSERT_INTERNAL(resolved_name == nullptr, "Windows realpath() assumes a null resolved_name");
+
+ WinHandle h(path, FILE_READ_ATTRIBUTES, 0);
+ if (!h) {
+ set_errno();
+ return nullptr;
+ }
+ 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);
+ DWORD retval = GetFinalPathNameByHandleW(h, buff.get(), buff_size, FILE_NAME_NORMALIZED | VOLUME_NAME_DOS);
+ if (retval > buff_size) {
+ buff_size = retval;
+ buff.reset(static_cast<wchar_t*>(malloc(buff_size * sizeof(wchar_t))));
+ retval = GetFinalPathNameByHandleW(h, buff.get(), buff_size, FILE_NAME_NORMALIZED | VOLUME_NAME_DOS);
+ }
+ if (!retval) {
+ set_errno();
+ return nullptr;
+ }
+ wchar_t* ptr = buff.get();
+ if (!wcsncmp(ptr, L"\\\\?\\", 4)) {
+ if (ptr[5] == ':') { // \\?\X: -> X:
+ memmove(&ptr[0], &ptr[4], (wcslen(&ptr[4]) + 1) * sizeof(wchar_t));
+ } else if (!wcsncmp(&ptr[4], L"UNC\\", 4)) { // \\?\UNC\server -> \\server
+ wcscpy(&ptr[0], L"\\\\");
+ memmove(&ptr[2], &ptr[8], (wcslen(&ptr[8]) + 1) * sizeof(wchar_t));
+ }
+ }
+ return buff.release();
+}
+
+# define AT_FDCWD -1
+# define AT_SYMLINK_NOFOLLOW 1
+using ModeT = int;
+
+inline int fchmod_handle(HANDLE h, int perms) {
+ FILE_BASIC_INFO basic;
+ if (!GetFileInformationByHandleEx(h, FileBasicInfo, &basic, sizeof(basic)))
+ return set_errno();
+ DWORD orig_attributes = basic.FileAttributes;
+ basic.FileAttributes &= ~FILE_ATTRIBUTE_READONLY;
+ if ((perms & 0222) == 0)
+ basic.FileAttributes |= FILE_ATTRIBUTE_READONLY;
+ if (basic.FileAttributes != orig_attributes && !SetFileInformationByHandle(h, FileBasicInfo, &basic, sizeof(basic)))
+ return set_errno();
+ return 0;
+}
+
+inline int fchmodat(int /*fd*/, const wchar_t* path, int perms, int flag) {
+ DWORD attributes = GetFileAttributesW(path);
+ if (attributes == INVALID_FILE_ATTRIBUTES)
+ return set_errno();
+ if (attributes & FILE_ATTRIBUTE_REPARSE_POINT && !(flag & AT_SYMLINK_NOFOLLOW)) {
+ // If the file is a symlink, and we are supposed to operate on the target
+ // of the symlink, we need to open a handle to it, without the
+ // FILE_FLAG_OPEN_REPARSE_POINT flag, to open the destination of the
+ // symlink, and operate on it via the handle.
+ detail::WinHandle h(path, FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES, 0);
+ if (!h)
+ return set_errno();
+ return fchmod_handle(h, perms);
+ } else {
+ // For a non-symlink, or if operating on the symlink itself instead of
+ // its target, we can use SetFileAttributesW, saving a few calls.
+ DWORD orig_attributes = attributes;
+ attributes &= ~FILE_ATTRIBUTE_READONLY;
+ if ((perms & 0222) == 0)
+ attributes |= FILE_ATTRIBUTE_READONLY;
+ if (attributes != orig_attributes && !SetFileAttributesW(path, attributes))
+ return set_errno();
+ }
+ return 0;
+}
+
+inline int fchmod(int fd, int perms) {
+ HANDLE h = reinterpret_cast<HANDLE>(_get_osfhandle(fd));
+ return fchmod_handle(h, perms);
+}
+
+# define MAX_SYMLINK_SIZE MAXIMUM_REPARSE_DATA_BUFFER_SIZE
+using SSizeT = ::int64_t;
+
+inline SSizeT readlink(const wchar_t* path, wchar_t* ret_buf, size_t bufsize) {
+ uint8_t buf[MAXIMUM_REPARSE_DATA_BUFFER_SIZE];
+ detail::WinHandle h(path, FILE_READ_ATTRIBUTES, FILE_FLAG_OPEN_REPARSE_POINT);
+ if (!h)
+ return set_errno();
+ DWORD out;
+ if (!DeviceIoControl(h, FSCTL_GET_REPARSE_POINT, nullptr, 0, buf, sizeof(buf), &out, 0))
+ return set_errno();
+ const auto* reparse = reinterpret_cast<LIBCPP_REPARSE_DATA_BUFFER*>(buf);
+ size_t path_buf_offset = offsetof(LIBCPP_REPARSE_DATA_BUFFER, SymbolicLinkReparseBuffer.PathBuffer[0]);
+ if (out < path_buf_offset) {
+ errno = EINVAL;
+ return -1;
+ }
+ if (reparse->ReparseTag != IO_REPARSE_TAG_SYMLINK) {
+ errno = EINVAL;
+ return -1;
+ }
+ const auto& symlink = reparse->SymbolicLinkReparseBuffer;
+ unsigned short name_offset, name_length;
+ if (symlink.PrintNameLength == 0) {
+ name_offset = symlink.SubstituteNameOffset;
+ name_length = symlink.SubstituteNameLength;
+ } else {
+ name_offset = symlink.PrintNameOffset;
+ name_length = symlink.PrintNameLength;
+ }
+ // name_offset/length are expressed in bytes, not in wchar_t
+ if (path_buf_offset + name_offset + name_length > out) {
+ errno = EINVAL;
+ return -1;
+ }
+ if (name_length / sizeof(wchar_t) > bufsize) {
+ errno = ENOMEM;
+ return -1;
+ }
+ memcpy(ret_buf, &symlink.PathBuffer[name_offset / sizeof(wchar_t)], name_length);
+ return name_length / sizeof(wchar_t);
+}
+
+#else
+inline int symlink_file(const char* oldname, const char* newname) { return ::symlink(oldname, newname); }
+inline int symlink_dir(const char* oldname, const char* newname) { return ::symlink(oldname, newname); }
+using ::chdir;
+using ::fchmod;
+# if defined(AT_SYMLINK_NOFOLLOW) && defined(AT_FDCWD)
+using ::fchmodat;
+# endif
+using ::fstat;
+using ::ftruncate;
+using ::getcwd;
+using ::link;
+using ::lstat;
+using ::mkdir;
+using ::readlink;
+using ::realpath;
+using ::remove;
+using ::rename;
+using ::stat;
+using ::statvfs;
+using ::truncate;
+
+# define O_BINARY 0
+
+using StatVFS = struct statvfs;
+using ModeT = ::mode_t;
+using SSizeT = ::ssize_t;
+
+#endif
+
+} // end namespace detail
+
+_LIBCPP_END_NAMESPACE_FILESYSTEM
+
+#endif // POSIX_COMPAT_H
diff --git a/contrib/llvm-project/libcxx/src/filesystem/time_utils.h b/contrib/llvm-project/libcxx/src/filesystem/time_utils.h
new file mode 100644
index 000000000000..e05f252868f0
--- /dev/null
+++ b/contrib/llvm-project/libcxx/src/filesystem/time_utils.h
@@ -0,0 +1,351 @@
+//===----------------------------------------------------------------------===////
+//
+// 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 FILESYSTEM_TIME_UTILS_H
+#define FILESYSTEM_TIME_UTILS_H
+
+#include <__config>
+#include <array>
+#include <chrono>
+#include <filesystem>
+#include <limits>
+#include <ratio>
+#include <system_error>
+#include <type_traits>
+#include <utility>
+
+#include "error.h"
+#include "format_string.h"
+
+#if defined(_LIBCPP_WIN32API)
+# define WIN32_LEAN_AND_MEAN
+# define NOMINMAX
+# include <windows.h>
+#else
+# include <fcntl.h>
+# include <sys/stat.h>
+# include <sys/time.h> // for ::utimes as used in __last_write_time
+#endif
+
+// We can use the presence of UTIME_OMIT to detect platforms that provide utimensat.
+#if defined(UTIME_OMIT)
+# define _LIBCPP_USE_UTIMENSAT
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
+
+namespace detail {
+
+#if defined(_LIBCPP_WIN32API)
+// Various C runtime versions (UCRT, or the legacy msvcrt.dll used by
+// some mingw toolchains) provide different stat function implementations,
+// with a number of limitations with respect to what we want from the
+// stat function. Instead provide our own which does exactly what we want,
+// along with our own stat structure and flag macros.
+
+struct TimeSpec {
+ int64_t tv_sec;
+ int64_t tv_nsec;
+};
+struct StatT {
+ unsigned st_mode;
+ TimeSpec st_atim;
+ TimeSpec st_mtim;
+ uint64_t st_dev; // FILE_ID_INFO::VolumeSerialNumber
+ struct FileIdStruct {
+ unsigned char id[16]; // FILE_ID_INFO::FileId
+ bool operator==(const FileIdStruct& other) const {
+ for (int i = 0; i < 16; i++)
+ if (id[i] != other.id[i])
+ return false;
+ return true;
+ }
+ } st_ino;
+ uint32_t st_nlink;
+ uintmax_t st_size;
+};
+
+// There were 369 years and 89 leap days from the Windows epoch
+// (1601) to the Unix epoch (1970).
+# define FILE_TIME_OFFSET_SECS (uint64_t(369 * 365 + 89) * (24 * 60 * 60))
+
+inline TimeSpec filetime_to_timespec(LARGE_INTEGER li) {
+ TimeSpec ret;
+ ret.tv_sec = li.QuadPart / 10000000 - FILE_TIME_OFFSET_SECS;
+ ret.tv_nsec = (li.QuadPart % 10000000) * 100;
+ return ret;
+}
+
+inline TimeSpec filetime_to_timespec(FILETIME ft) {
+ LARGE_INTEGER li;
+ li.LowPart = ft.dwLowDateTime;
+ li.HighPart = ft.dwHighDateTime;
+ return filetime_to_timespec(li);
+}
+
+inline FILETIME timespec_to_filetime(TimeSpec ts) {
+ LARGE_INTEGER li;
+ li.QuadPart = ts.tv_nsec / 100 + (ts.tv_sec + FILE_TIME_OFFSET_SECS) * 10000000;
+ FILETIME ft;
+ ft.dwLowDateTime = li.LowPart;
+ ft.dwHighDateTime = li.HighPart;
+ return ft;
+}
+
+#else
+using TimeSpec = struct timespec;
+using TimeVal = struct timeval;
+using StatT = struct stat;
+
+inline TimeVal make_timeval(TimeSpec const& ts) {
+ using namespace chrono;
+ auto Convert = [](long nsec) {
+ using int_type = decltype(std::declval<TimeVal>().tv_usec);
+ auto dur = duration_cast<microseconds>(nanoseconds(nsec)).count();
+ return static_cast<int_type>(dur);
+ };
+ TimeVal TV = {};
+ TV.tv_sec = ts.tv_sec;
+ TV.tv_usec = Convert(ts.tv_nsec);
+ return TV;
+}
+#endif
+
+using chrono::duration;
+using chrono::duration_cast;
+
+template <class FileTimeT, class TimeT, bool IsFloat = is_floating_point<typename FileTimeT::rep>::value>
+struct time_util_base {
+ using rep = typename FileTimeT::rep;
+ using fs_duration = typename FileTimeT::duration;
+ using fs_seconds = duration<rep>;
+ using fs_nanoseconds = duration<rep, nano>;
+ using fs_microseconds = duration<rep, micro>;
+
+ static constexpr rep max_seconds = duration_cast<fs_seconds>(FileTimeT::duration::max()).count();
+
+ static constexpr rep max_nsec =
+ duration_cast<fs_nanoseconds>(FileTimeT::duration::max() - fs_seconds(max_seconds)).count();
+
+ static constexpr rep min_seconds = duration_cast<fs_seconds>(FileTimeT::duration::min()).count();
+
+ static constexpr rep min_nsec_timespec =
+ duration_cast<fs_nanoseconds>((FileTimeT::duration::min() - fs_seconds(min_seconds)) + fs_seconds(1)).count();
+
+private:
+ static constexpr fs_duration get_min_nsecs() {
+ return duration_cast<fs_duration>(fs_nanoseconds(min_nsec_timespec) - duration_cast<fs_nanoseconds>(fs_seconds(1)));
+ }
+ // Static assert that these values properly round trip.
+ static_assert(fs_seconds(min_seconds) + get_min_nsecs() == FileTimeT::duration::min(), "value doesn't roundtrip");
+
+ 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;
+ return duration_cast<Years>(fs_seconds(max_seconds)) > Years(250) &&
+ duration_cast<Years>(fs_seconds(min_seconds)) < Years(-250);
+ }
+ return max_seconds >= numeric_limits<TimeT>::max() && min_seconds <= numeric_limits<TimeT>::min();
+ }
+#if _LIBCPP_STD_VER >= 14
+ static_assert(check_range(), "the representable range is unacceptable small");
+#endif
+};
+
+template <class FileTimeT, class TimeT>
+struct time_util_base<FileTimeT, TimeT, true> {
+ using rep = typename FileTimeT::rep;
+ using fs_duration = typename FileTimeT::duration;
+ using fs_seconds = duration<rep>;
+ using fs_nanoseconds = duration<rep, nano>;
+ using fs_microseconds = duration<rep, micro>;
+
+ static const rep max_seconds;
+ static const rep max_nsec;
+ static const rep min_seconds;
+ static const rep min_nsec_timespec;
+};
+
+template <class FileTimeT, class TimeT>
+const typename FileTimeT::rep time_util_base<FileTimeT, TimeT, true>::max_seconds =
+ duration_cast<fs_seconds>(FileTimeT::duration::max()).count();
+
+template <class FileTimeT, class TimeT>
+const typename FileTimeT::rep time_util_base<FileTimeT, TimeT, true>::max_nsec =
+ duration_cast<fs_nanoseconds>(FileTimeT::duration::max() - fs_seconds(max_seconds)).count();
+
+template <class FileTimeT, class TimeT>
+const typename FileTimeT::rep time_util_base<FileTimeT, TimeT, true>::min_seconds =
+ duration_cast<fs_seconds>(FileTimeT::duration::min()).count();
+
+template <class FileTimeT, class TimeT>
+const typename FileTimeT::rep time_util_base<FileTimeT, TimeT, true>::min_nsec_timespec =
+ duration_cast<fs_nanoseconds>((FileTimeT::duration::min() - fs_seconds(min_seconds)) + fs_seconds(1)).count();
+
+template <class FileTimeT, class TimeT, class TimeSpecT>
+struct time_util : time_util_base<FileTimeT, TimeT> {
+ using Base = time_util_base<FileTimeT, TimeT>;
+ using Base::max_nsec;
+ using Base::max_seconds;
+ using Base::min_nsec_timespec;
+ using Base::min_seconds;
+
+ using typename Base::fs_duration;
+ using typename Base::fs_microseconds;
+ using typename Base::fs_nanoseconds;
+ using typename Base::fs_seconds;
+
+public:
+ template <class CType, class ChronoType>
+ static constexpr bool checked_set(CType* out, ChronoType time) {
+ using Lim = numeric_limits<CType>;
+ if (time > Lim::max() || time < Lim::min())
+ return false;
+ *out = static_cast<CType>(time);
+ return true;
+ }
+
+ 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);
+ } else if (tm.tv_sec == (min_seconds - 1)) {
+ return tm.tv_nsec >= min_nsec_timespec;
+ } else {
+ return tm.tv_sec >= min_seconds;
+ }
+ }
+
+ 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) {
+ secs = secs + fs_seconds(1);
+ nsecs = nsecs + fs_seconds(1);
+ }
+ using TLim = numeric_limits<TimeT>;
+ if (secs.count() >= 0)
+ return secs.count() <= TLim::max();
+ return secs.count() >= TLim::min();
+ }
+
+ static constexpr FileTimeT convert_from_timespec(TimeSpecT tm) {
+ if (tm.tv_sec >= 0 || tm.tv_nsec == 0) {
+ return FileTimeT(fs_seconds(tm.tv_sec) + duration_cast<fs_duration>(fs_nanoseconds(tm.tv_nsec)));
+ } else { // tm.tv_sec < 0
+ auto adj_subsec = duration_cast<fs_duration>(fs_seconds(1) - fs_nanoseconds(tm.tv_nsec));
+ auto Dur = fs_seconds(tm.tv_sec + 1) - adj_subsec;
+ return FileTimeT(Dur);
+ }
+ }
+
+ template <class SubSecT>
+ 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);
+ auto subsec_dur = duration_cast<fs_nanoseconds>(dur - sec_dur);
+ // The tv_nsec and tv_usec fields must not be negative so adjust accordingly
+ if (subsec_dur.count() < 0) {
+ if (sec_dur.count() > min_seconds) {
+ sec_dur = sec_dur - fs_seconds(1);
+ subsec_dur = subsec_dur + fs_seconds(1);
+ } else {
+ subsec_dur = fs_nanoseconds::zero();
+ }
+ }
+ return checked_set(sec_out, sec_dur.count()) && checked_set(subsec_out, subsec_dur.count());
+ }
+ static constexpr bool convert_to_timespec(TimeSpecT& dest, FileTimeT tp) {
+ if (!is_representable(tp))
+ return false;
+ return set_times_checked(&dest.tv_sec, &dest.tv_nsec, tp);
+ }
+};
+
+#if defined(_LIBCPP_WIN32API)
+using fs_time = time_util<file_time_type, int64_t, TimeSpec>;
+#else
+using fs_time = time_util<file_time_type, time_t, TimeSpec>;
+#endif
+
+#if defined(__APPLE__)
+inline TimeSpec extract_mtime(StatT const& st) { return st.st_mtimespec; }
+inline TimeSpec extract_atime(StatT const& st) { return st.st_atimespec; }
+#elif defined(__MVS__)
+inline TimeSpec extract_mtime(StatT const& st) {
+ TimeSpec TS = {st.st_mtime, 0};
+ return TS;
+}
+inline TimeSpec extract_atime(StatT const& st) {
+ TimeSpec TS = {st.st_atime, 0};
+ return TS;
+}
+#elif defined(_AIX)
+inline TimeSpec extract_mtime(StatT const& st) {
+ TimeSpec TS = {st.st_mtime, st.st_mtime_n};
+ return TS;
+}
+inline TimeSpec extract_atime(StatT const& st) {
+ TimeSpec TS = {st.st_atime, st.st_atime_n};
+ return TS;
+}
+#else
+inline TimeSpec extract_mtime(StatT const& st) { return st.st_mtim; }
+inline TimeSpec extract_atime(StatT const& st) { return st.st_atim; }
+#endif
+
+#ifndef _LIBCPP_HAS_NO_FILESYSTEM
+
+# if !defined(_LIBCPP_WIN32API)
+inline bool posix_utimes(const path& p, std::array<TimeSpec, 2> const& TS, error_code& ec) {
+ TimeVal ConvertedTS[2] = {make_timeval(TS[0]), make_timeval(TS[1])};
+ if (::utimes(p.c_str(), ConvertedTS) == -1) {
+ ec = capture_errno();
+ return true;
+ }
+ return false;
+}
+
+# if defined(_LIBCPP_USE_UTIMENSAT)
+inline bool posix_utimensat(const path& p, std::array<TimeSpec, 2> const& TS, error_code& ec) {
+ if (::utimensat(AT_FDCWD, p.c_str(), TS.data(), 0) == -1) {
+ ec = capture_errno();
+ return true;
+ }
+ return false;
+}
+# endif
+
+inline bool set_file_times(const path& p, std::array<TimeSpec, 2> const& TS, error_code& ec) {
+# if !defined(_LIBCPP_USE_UTIMENSAT)
+ return posix_utimes(p, TS, ec);
+# else
+ return posix_utimensat(p, TS, ec);
+# endif
+}
+
+# endif // !_LIBCPP_WIN32API
+
+inline file_time_type __extract_last_write_time(const path& p, const StatT& st, error_code* ec) {
+ using detail::fs_time;
+ ErrorHandler<file_time_type> err("last_write_time", ec, &p);
+
+ auto ts = detail::extract_mtime(st);
+ if (!fs_time::is_representable(ts))
+ return err.report(errc::value_too_large);
+
+ return fs_time::convert_from_timespec(ts);
+}
+
+#endif // !_LIBCPP_HAS_NO_FILESYSTEM
+
+} // end namespace detail
+
+_LIBCPP_END_NAMESPACE_FILESYSTEM
+
+#endif // FILESYSTEM_TIME_UTILS_H
diff --git a/contrib/llvm-project/libcxx/src/fstream.cpp b/contrib/llvm-project/libcxx/src/fstream.cpp
new file mode 100644
index 000000000000..55a4442b9c78
--- /dev/null
+++ b/contrib/llvm-project/libcxx/src/fstream.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>
+#include <cstdio>
+#include <fstream>
+
+#if defined(_LIBCPP_WIN32API)
+# define WIN32_LEAN_AND_MEAN
+# define NOMINMAX
+# include <io.h>
+# include <windows.h>
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if defined(_LIBCPP_WIN32API)
+
+// Confirm that `HANDLE` is `void*` as implemented in `basic_filebuf`
+static_assert(std::same_as<HANDLE, void*>);
+
+_LIBCPP_EXPORTED_FROM_ABI void* __filebuf_windows_native_handle(FILE* __file) noexcept {
+ // https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/get-osfhandle?view=msvc-170
+ intptr_t __handle = _get_osfhandle(fileno(__file));
+ if (__handle == -1)
+ return nullptr;
+ return reinterpret_cast<void*>(__handle);
+}
+
+#endif
+
+_LIBCPP_END_NAMESPACE_STD
diff --git a/contrib/llvm-project/libcxx/src/functional.cpp b/contrib/llvm-project/libcxx/src/functional.cpp
index 555d2c53f2b0..570bb78e150b 100644
--- a/contrib/llvm-project/libcxx/src/functional.cpp
+++ b/contrib/llvm-project/libcxx/src/functional.cpp
@@ -1,4 +1,4 @@
-//===----------------------- functional.cpp -------------------------------===//
+//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -6,20 +6,16 @@
//
//===----------------------------------------------------------------------===//
-#include "functional"
+#include <functional>
_LIBCPP_BEGIN_NAMESPACE_STD
#ifdef _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
-bad_function_call::~bad_function_call() _NOEXCEPT
-{
-}
+bad_function_call::~bad_function_call() noexcept {}
+#endif
-const char*
-bad_function_call::what() const _NOEXCEPT
-{
- return "std::bad_function_call";
-}
+#ifdef _LIBCPP_ABI_BAD_FUNCTION_CALL_GOOD_WHAT_MESSAGE
+const char* bad_function_call::what() const noexcept { return "std::bad_function_call"; }
#endif
_LIBCPP_END_NAMESPACE_STD
diff --git a/contrib/llvm-project/libcxx/src/future.cpp b/contrib/llvm-project/libcxx/src/future.cpp
index 58d0b4c247cb..e2c14c8321dd 100644
--- a/contrib/llvm-project/libcxx/src/future.cpp
+++ b/contrib/llvm-project/libcxx/src/future.cpp
@@ -1,4 +1,4 @@
-//===------------------------- future.cpp ---------------------------------===//
+//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -6,272 +6,192 @@
//
//===----------------------------------------------------------------------===//
-#include "__config"
-
-#ifndef _LIBCPP_HAS_NO_THREADS
-
-#include "future"
-#include "string"
+#include <future>
+#include <string>
_LIBCPP_BEGIN_NAMESPACE_STD
-class _LIBCPP_HIDDEN __future_error_category
- : public __do_message
-{
+class _LIBCPP_HIDDEN __future_error_category : public __do_message {
public:
- virtual const char* name() const _NOEXCEPT;
- virtual string message(int ev) const;
+ virtual const char* name() const noexcept;
+ virtual string message(int ev) const;
};
-const char*
-__future_error_category::name() const _NOEXCEPT
-{
- return "future";
-}
+const char* __future_error_category::name() const noexcept { return "future"; }
-#if defined(__clang__)
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wswitch"
-#elif defined(__GNUC__) || defined(__GNUG__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wswitch"
-#endif
-
-string
-__future_error_category::message(int ev) const
-{
- switch (static_cast<future_errc>(ev))
- {
- case future_errc(0): // For backwards compatibility with C++11 (LWG 2056)
- case future_errc::broken_promise:
- return string("The associated promise has been destructed prior "
- "to the associated state becoming ready.");
- case future_errc::future_already_retrieved:
- return string("The future has already been retrieved from "
- "the promise or packaged_task.");
- case future_errc::promise_already_satisfied:
- return string("The state of the promise has already been set.");
- case future_errc::no_state:
- return string("Operation not permitted on an object without "
- "an associated state.");
- }
- return string("unspecified future_errc value\n");
-}
+_LIBCPP_DIAGNOSTIC_PUSH
+_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wswitch")
+_LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wswitch")
-#if defined(__clang__)
-#pragma clang diagnostic pop
-#elif defined(__GNUC__) || defined(__GNUG__)
-#pragma GCC diagnostic pop
-#endif
-
-const error_category&
-future_category() _NOEXCEPT
-{
- static __future_error_category __f;
- return __f;
+string __future_error_category::message(int ev) const {
+ switch (static_cast<future_errc>(ev)) {
+ case future_errc(0): // For backwards compatibility with C++11 (LWG 2056)
+ case future_errc::broken_promise:
+ return string("The associated promise has been destructed prior "
+ "to the associated state becoming ready.");
+ case future_errc::future_already_retrieved:
+ return string("The future has already been retrieved from "
+ "the promise or packaged_task.");
+ case future_errc::promise_already_satisfied:
+ return string("The state of the promise has already been set.");
+ case future_errc::no_state:
+ return string("Operation not permitted on an object without "
+ "an associated state.");
+ }
+ return string("unspecified future_errc value\n");
}
-future_error::future_error(error_code __ec)
- : logic_error(__ec.message()),
- __ec_(__ec)
-{
-}
+_LIBCPP_DIAGNOSTIC_POP
-future_error::~future_error() _NOEXCEPT
-{
+const error_category& future_category() noexcept {
+ union AvoidDestroyingFutureCategory {
+ __future_error_category future_error_category;
+ constexpr explicit AvoidDestroyingFutureCategory() : future_error_category() {}
+ ~AvoidDestroyingFutureCategory() {}
+ };
+ constinit static AvoidDestroyingFutureCategory helper;
+ return helper.future_error_category;
}
-void
-__assoc_sub_state::__on_zero_shared() _NOEXCEPT
-{
- delete this;
-}
+future_error::future_error(error_code __ec) : logic_error(__ec.message()), __ec_(__ec) {}
-void
-__assoc_sub_state::set_value()
-{
- unique_lock<mutex> __lk(__mut_);
- if (__has_value())
- __throw_future_error(future_errc::promise_already_satisfied);
- __state_ |= __constructed | ready;
- __cv_.notify_all();
-}
+future_error::~future_error() noexcept {}
-void
-__assoc_sub_state::set_value_at_thread_exit()
-{
- unique_lock<mutex> __lk(__mut_);
- if (__has_value())
- __throw_future_error(future_errc::promise_already_satisfied);
- __state_ |= __constructed;
- __thread_local_data()->__make_ready_at_thread_exit(this);
-}
+void __assoc_sub_state::__on_zero_shared() noexcept { delete this; }
-void
-__assoc_sub_state::set_exception(exception_ptr __p)
-{
- unique_lock<mutex> __lk(__mut_);
- if (__has_value())
- __throw_future_error(future_errc::promise_already_satisfied);
- __exception_ = __p;
- __state_ |= ready;
- __cv_.notify_all();
+void __assoc_sub_state::set_value() {
+ unique_lock<mutex> __lk(__mut_);
+ if (__has_value())
+ __throw_future_error(future_errc::promise_already_satisfied);
+ __state_ |= __constructed | ready;
+ __cv_.notify_all();
}
-void
-__assoc_sub_state::set_exception_at_thread_exit(exception_ptr __p)
-{
- unique_lock<mutex> __lk(__mut_);
- if (__has_value())
- __throw_future_error(future_errc::promise_already_satisfied);
- __exception_ = __p;
- __thread_local_data()->__make_ready_at_thread_exit(this);
+void __assoc_sub_state::set_value_at_thread_exit() {
+ unique_lock<mutex> __lk(__mut_);
+ if (__has_value())
+ __throw_future_error(future_errc::promise_already_satisfied);
+ __state_ |= __constructed;
+ __thread_local_data()->__make_ready_at_thread_exit(this);
}
-void
-__assoc_sub_state::__make_ready()
-{
- unique_lock<mutex> __lk(__mut_);
- __state_ |= ready;
- __cv_.notify_all();
+void __assoc_sub_state::set_exception(exception_ptr __p) {
+ unique_lock<mutex> __lk(__mut_);
+ if (__has_value())
+ __throw_future_error(future_errc::promise_already_satisfied);
+ __exception_ = __p;
+ __state_ |= ready;
+ __cv_.notify_all();
}
-void
-__assoc_sub_state::copy()
-{
- unique_lock<mutex> __lk(__mut_);
- __sub_wait(__lk);
- if (__exception_ != nullptr)
- rethrow_exception(__exception_);
+void __assoc_sub_state::set_exception_at_thread_exit(exception_ptr __p) {
+ unique_lock<mutex> __lk(__mut_);
+ if (__has_value())
+ __throw_future_error(future_errc::promise_already_satisfied);
+ __exception_ = __p;
+ __thread_local_data()->__make_ready_at_thread_exit(this);
}
-void
-__assoc_sub_state::wait()
-{
- unique_lock<mutex> __lk(__mut_);
- __sub_wait(__lk);
+void __assoc_sub_state::__make_ready() {
+ unique_lock<mutex> __lk(__mut_);
+ __state_ |= ready;
+ __cv_.notify_all();
}
-void
-__assoc_sub_state::__sub_wait(unique_lock<mutex>& __lk)
-{
- if (!__is_ready())
- {
- if (__state_ & static_cast<unsigned>(deferred))
- {
- __state_ &= ~static_cast<unsigned>(deferred);
- __lk.unlock();
- __execute();
- }
- else
- while (!__is_ready())
- __cv_.wait(__lk);
- }
+void __assoc_sub_state::copy() {
+ unique_lock<mutex> __lk(__mut_);
+ __sub_wait(__lk);
+ if (__exception_ != nullptr)
+ rethrow_exception(__exception_);
}
-void
-__assoc_sub_state::__execute()
-{
- __throw_future_error(future_errc::no_state);
+void __assoc_sub_state::wait() {
+ unique_lock<mutex> __lk(__mut_);
+ __sub_wait(__lk);
}
-future<void>::future(__assoc_sub_state* __state)
- : __state_(__state)
-{
- __state_->__attach_future();
+void __assoc_sub_state::__sub_wait(unique_lock<mutex>& __lk) {
+ if (!__is_ready()) {
+ if (__state_ & static_cast<unsigned>(deferred)) {
+ __state_ &= ~static_cast<unsigned>(deferred);
+ __lk.unlock();
+ __execute();
+ } else
+ while (!__is_ready())
+ __cv_.wait(__lk);
+ }
}
-future<void>::~future()
-{
- if (__state_)
- __state_->__release_shared();
-}
+void __assoc_sub_state::__execute() { __throw_future_error(future_errc::no_state); }
+
+future<void>::future(__assoc_sub_state* __state) : __state_(__state) { __state_->__attach_future(); }
-void
-future<void>::get()
-{
- unique_ptr<__shared_count, __release_shared_count> __(__state_);
- __assoc_sub_state* __s = __state_;
- __state_ = nullptr;
- __s->copy();
+future<void>::~future() {
+ if (__state_)
+ __state_->__release_shared();
}
-promise<void>::promise()
- : __state_(new __assoc_sub_state)
-{
+void future<void>::get() {
+ unique_ptr<__shared_count, __release_shared_count> __(__state_);
+ __assoc_sub_state* __s = __state_;
+ __state_ = nullptr;
+ __s->copy();
}
-promise<void>::~promise()
-{
- if (__state_)
- {
-#ifndef _LIBCPP_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))
- ));
-#endif // _LIBCPP_NO_EXCEPTIONS
- __state_->__release_shared();
- }
+promise<void>::promise() : __state_(new __assoc_sub_state) {}
+
+promise<void>::~promise() {
+ if (__state_) {
+#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
+ if (!__state_->__has_value() && __state_->use_count() > 1)
+ __state_->set_exception(make_exception_ptr(future_error(future_errc::broken_promise)));
+#endif // _LIBCPP_HAS_NO_EXCEPTIONS
+ __state_->__release_shared();
+ }
}
-future<void>
-promise<void>::get_future()
-{
- if (__state_ == nullptr)
- __throw_future_error(future_errc::no_state);
- return future<void>(__state_);
+future<void> promise<void>::get_future() {
+ if (__state_ == nullptr)
+ __throw_future_error(future_errc::no_state);
+ return future<void>(__state_);
}
-void
-promise<void>::set_value()
-{
- if (__state_ == nullptr)
- __throw_future_error(future_errc::no_state);
- __state_->set_value();
+void promise<void>::set_value() {
+ if (__state_ == nullptr)
+ __throw_future_error(future_errc::no_state);
+ __state_->set_value();
}
-void
-promise<void>::set_exception(exception_ptr __p)
-{
- if (__state_ == nullptr)
- __throw_future_error(future_errc::no_state);
- __state_->set_exception(__p);
+void promise<void>::set_exception(exception_ptr __p) {
+ if (__state_ == nullptr)
+ __throw_future_error(future_errc::no_state);
+ __state_->set_exception(__p);
}
-void
-promise<void>::set_value_at_thread_exit()
-{
- if (__state_ == nullptr)
- __throw_future_error(future_errc::no_state);
- __state_->set_value_at_thread_exit();
+void promise<void>::set_value_at_thread_exit() {
+ if (__state_ == nullptr)
+ __throw_future_error(future_errc::no_state);
+ __state_->set_value_at_thread_exit();
}
-void
-promise<void>::set_exception_at_thread_exit(exception_ptr __p)
-{
- if (__state_ == nullptr)
- __throw_future_error(future_errc::no_state);
- __state_->set_exception_at_thread_exit(__p);
+void promise<void>::set_exception_at_thread_exit(exception_ptr __p) {
+ if (__state_ == nullptr)
+ __throw_future_error(future_errc::no_state);
+ __state_->set_exception_at_thread_exit(__p);
}
-shared_future<void>::~shared_future()
-{
- if (__state_)
- __state_->__release_shared();
+shared_future<void>::~shared_future() {
+ if (__state_)
+ __state_->__release_shared();
}
-shared_future<void>&
-shared_future<void>::operator=(const shared_future& __rhs)
-{
- if (__rhs.__state_)
- __rhs.__state_->__add_shared();
- if (__state_)
- __state_->__release_shared();
- __state_ = __rhs.__state_;
- return *this;
+shared_future<void>& shared_future<void>::operator=(const shared_future& __rhs) {
+ if (__rhs.__state_)
+ __rhs.__state_->__add_shared();
+ if (__state_)
+ __state_->__release_shared();
+ __state_ = __rhs.__state_;
+ return *this;
}
_LIBCPP_END_NAMESPACE_STD
-
-#endif // !_LIBCPP_HAS_NO_THREADS
diff --git a/contrib/llvm-project/libcxx/src/hash.cpp b/contrib/llvm-project/libcxx/src/hash.cpp
index 89bb736c86c2..34b02b8eafc2 100644
--- a/contrib/llvm-project/libcxx/src/hash.cpp
+++ b/contrib/llvm-project/libcxx/src/hash.cpp
@@ -1,4 +1,4 @@
-//===-------------------------- hash.cpp ----------------------------------===//
+//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -6,128 +6,32 @@
//
//===----------------------------------------------------------------------===//
-#include "__hash_table"
-#include "algorithm"
-#include "stdexcept"
-#include "type_traits"
+#include <__hash_table>
+#include <algorithm>
+#include <stdexcept>
+#include <type_traits>
-#ifdef __clang__
-#pragma clang diagnostic ignored "-Wtautological-constant-out-of-range-compare"
-#endif
+_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wtautological-constant-out-of-range-compare")
_LIBCPP_BEGIN_NAMESPACE_STD
namespace {
// handle all next_prime(i) for i in [1, 210), special case 0
-const unsigned small_primes[] =
-{
- 0,
- 2,
- 3,
- 5,
- 7,
- 11,
- 13,
- 17,
- 19,
- 23,
- 29,
- 31,
- 37,
- 41,
- 43,
- 47,
- 53,
- 59,
- 61,
- 67,
- 71,
- 73,
- 79,
- 83,
- 89,
- 97,
- 101,
- 103,
- 107,
- 109,
- 113,
- 127,
- 131,
- 137,
- 139,
- 149,
- 151,
- 157,
- 163,
- 167,
- 173,
- 179,
- 181,
- 191,
- 193,
- 197,
- 199,
- 211
-};
+const unsigned small_primes[] = {
+ 0, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47,
+ 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127,
+ 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211};
// potential primes = 210*k + indices[i], k >= 1
// these numbers are not divisible by 2, 3, 5 or 7
// (or any integer 2 <= j <= 10 for that matter).
-const unsigned indices[] =
-{
- 1,
- 11,
- 13,
- 17,
- 19,
- 23,
- 29,
- 31,
- 37,
- 41,
- 43,
- 47,
- 53,
- 59,
- 61,
- 67,
- 71,
- 73,
- 79,
- 83,
- 89,
- 97,
- 101,
- 103,
- 107,
- 109,
- 113,
- 121,
- 127,
- 131,
- 137,
- 139,
- 143,
- 149,
- 151,
- 157,
- 163,
- 167,
- 169,
- 173,
- 179,
- 181,
- 187,
- 191,
- 193,
- 197,
- 199,
- 209
-};
+const unsigned indices[] = {
+ 1, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67,
+ 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 121, 127, 131, 137, 139,
+ 143, 149, 151, 157, 163, 167, 169, 173, 179, 181, 187, 191, 193, 197, 199, 209};
-}
+} // namespace
// Returns: If n == 0, returns 0. Else returns the lowest prime number that
// is greater than or equal to n.
@@ -149,413 +53,400 @@ const unsigned indices[] =
// against.
template <size_t _Sz = sizeof(size_t)>
-inline _LIBCPP_INLINE_VISIBILITY
-typename enable_if<_Sz == 4, void>::type
-__check_for_overflow(size_t N)
-{
- if (N > 0xFFFFFFFB)
- __throw_overflow_error("__next_prime overflow");
+inline _LIBCPP_HIDE_FROM_ABI typename enable_if<_Sz == 4, void>::type __check_for_overflow(size_t N) {
+ if (N > 0xFFFFFFFB)
+ __throw_overflow_error("__next_prime overflow");
}
template <size_t _Sz = sizeof(size_t)>
-inline _LIBCPP_INLINE_VISIBILITY
-typename enable_if<_Sz == 8, void>::type
-__check_for_overflow(size_t N)
-{
- if (N > 0xFFFFFFFFFFFFFFC5ull)
- __throw_overflow_error("__next_prime overflow");
+inline _LIBCPP_HIDE_FROM_ABI typename enable_if<_Sz == 8, void>::type __check_for_overflow(size_t N) {
+ if (N > 0xFFFFFFFFFFFFFFC5ull)
+ __throw_overflow_error("__next_prime overflow");
}
-size_t
-__next_prime(size_t n)
-{
- const size_t L = 210;
- const size_t N = sizeof(small_primes) / sizeof(small_primes[0]);
- // If n is small enough, search in small_primes
- if (n <= small_primes[N-1])
- return *std::lower_bound(small_primes, small_primes + N, n);
- // Else n > largest small_primes
- // Check for overflow
- __check_for_overflow(n);
- // Start searching list of potential primes: L * k0 + indices[in]
- const size_t M = sizeof(indices) / sizeof(indices[0]);
- // Select first potential prime >= n
- // Known a-priori n >= L
- size_t k0 = n / L;
- size_t in = static_cast<size_t>(std::lower_bound(indices, indices + M, n - k0 * L)
- - indices);
- n = L * k0 + indices[in];
- while (true)
+size_t __next_prime(size_t n) {
+ const size_t L = 210;
+ const size_t N = sizeof(small_primes) / sizeof(small_primes[0]);
+ // If n is small enough, search in small_primes
+ if (n <= small_primes[N - 1])
+ return *std::lower_bound(small_primes, small_primes + N, n);
+ // Else n > largest small_primes
+ // Check for overflow
+ __check_for_overflow(n);
+ // Start searching list of potential primes: L * k0 + indices[in]
+ const size_t M = sizeof(indices) / sizeof(indices[0]);
+ // Select first potential prime >= n
+ // Known a-priori n >= L
+ size_t k0 = n / L;
+ size_t in = static_cast<size_t>(std::lower_bound(indices, indices + M, n - k0 * L) - indices);
+ n = L * k0 + indices[in];
+ while (true) {
+ // Divide n by all primes or potential primes (i) until:
+ // 1. The division is even, so try next potential prime.
+ // 2. The i > sqrt(n), in which case n is prime.
+ // It is known a-priori that n is not divisible by 2, 3, 5 or 7,
+ // so don't test those (j == 5 -> divide by 11 first). And the
+ // potential primes start with 211, so don't test against the last
+ // small prime.
+ for (size_t j = 5; j < N - 1; ++j) {
+ const std::size_t p = small_primes[j];
+ const std::size_t q = n / p;
+ if (q < p)
+ return n;
+ if (n == q * p)
+ goto next;
+ }
+ // n wasn't divisible by small primes, try potential primes
{
- // Divide n by all primes or potential primes (i) until:
- // 1. The division is even, so try next potential prime.
- // 2. The i > sqrt(n), in which case n is prime.
- // It is known a-priori that n is not divisible by 2, 3, 5 or 7,
- // so don't test those (j == 5 -> divide by 11 first). And the
- // potential primes start with 211, so don't test against the last
- // small prime.
- for (size_t j = 5; j < N - 1; ++j)
- {
- const std::size_t p = small_primes[j];
- const std::size_t q = n / p;
- if (q < p)
- return n;
- if (n == q * p)
- goto next;
- }
- // n wasn't divisible by small primes, try potential primes
- {
- size_t i = 211;
- while (true)
- {
- std::size_t q = n / i;
- if (q < i)
- return n;
- if (n == q * i)
- break;
-
- i += 10;
- q = n / i;
- if (q < i)
- return n;
- if (n == q * i)
- break;
-
- i += 2;
- q = n / i;
- if (q < i)
- return n;
- if (n == q * i)
- break;
-
- i += 4;
- q = n / i;
- if (q < i)
- return n;
- if (n == q * i)
- break;
-
- i += 2;
- q = n / i;
- if (q < i)
- return n;
- if (n == q * i)
- break;
-
- i += 4;
- q = n / i;
- if (q < i)
- return n;
- if (n == q * i)
- break;
-
- i += 6;
- q = n / i;
- if (q < i)
- return n;
- if (n == q * i)
- break;
-
- i += 2;
- q = n / i;
- if (q < i)
- return n;
- if (n == q * i)
- break;
-
- i += 6;
- q = n / i;
- if (q < i)
- return n;
- if (n == q * i)
- break;
-
- i += 4;
- q = n / i;
- if (q < i)
- return n;
- if (n == q * i)
- break;
-
- i += 2;
- q = n / i;
- if (q < i)
- return n;
- if (n == q * i)
- break;
-
- i += 4;
- q = n / i;
- if (q < i)
- return n;
- if (n == q * i)
- break;
-
- i += 6;
- q = n / i;
- if (q < i)
- return n;
- if (n == q * i)
- break;
-
- i += 6;
- q = n / i;
- if (q < i)
- return n;
- if (n == q * i)
- break;
-
- i += 2;
- q = n / i;
- if (q < i)
- return n;
- if (n == q * i)
- break;
-
- i += 6;
- q = n / i;
- if (q < i)
- return n;
- if (n == q * i)
- break;
-
- i += 4;
- q = n / i;
- if (q < i)
- return n;
- if (n == q * i)
- break;
-
- i += 2;
- q = n / i;
- if (q < i)
- return n;
- if (n == q * i)
- break;
-
- i += 6;
- q = n / i;
- if (q < i)
- return n;
- if (n == q * i)
- break;
-
- i += 4;
- q = n / i;
- if (q < i)
- return n;
- if (n == q * i)
- break;
-
- i += 6;
- q = n / i;
- if (q < i)
- return n;
- if (n == q * i)
- break;
-
- i += 8;
- q = n / i;
- if (q < i)
- return n;
- if (n == q * i)
- break;
-
- i += 4;
- q = n / i;
- if (q < i)
- return n;
- if (n == q * i)
- break;
-
- i += 2;
- q = n / i;
- if (q < i)
- return n;
- if (n == q * i)
- break;
-
- i += 4;
- q = n / i;
- if (q < i)
- return n;
- if (n == q * i)
- break;
-
- i += 2;
- q = n / i;
- if (q < i)
- return n;
- if (n == q * i)
- break;
-
- i += 4;
- q = n / i;
- if (q < i)
- return n;
- if (n == q * i)
- break;
-
- i += 8;
- q = n / i;
- if (q < i)
- return n;
- if (n == q * i)
- break;
-
- i += 6;
- q = n / i;
- if (q < i)
- return n;
- if (n == q * i)
- break;
-
- i += 4;
- q = n / i;
- if (q < i)
- return n;
- if (n == q * i)
- break;
-
- i += 6;
- q = n / i;
- if (q < i)
- return n;
- if (n == q * i)
- break;
-
- i += 2;
- q = n / i;
- if (q < i)
- return n;
- if (n == q * i)
- break;
-
- i += 4;
- q = n / i;
- if (q < i)
- return n;
- if (n == q * i)
- break;
-
- i += 6;
- q = n / i;
- if (q < i)
- return n;
- if (n == q * i)
- break;
-
- i += 2;
- q = n / i;
- if (q < i)
- return n;
- if (n == q * i)
- break;
-
- i += 6;
- q = n / i;
- if (q < i)
- return n;
- if (n == q * i)
- break;
-
- i += 6;
- q = n / i;
- if (q < i)
- return n;
- if (n == q * i)
- break;
-
- i += 4;
- q = n / i;
- if (q < i)
- return n;
- if (n == q * i)
- break;
-
- i += 2;
- q = n / i;
- if (q < i)
- return n;
- if (n == q * i)
- break;
-
- i += 4;
- q = n / i;
- if (q < i)
- return n;
- if (n == q * i)
- break;
-
- i += 6;
- q = n / i;
- if (q < i)
- return n;
- if (n == q * i)
- break;
-
- i += 2;
- q = n / i;
- if (q < i)
- return n;
- if (n == q * i)
- break;
-
- i += 6;
- q = n / i;
- if (q < i)
- return n;
- if (n == q * i)
- break;
-
- i += 4;
- q = n / i;
- if (q < i)
- return n;
- if (n == q * i)
- break;
-
- i += 2;
- q = n / i;
- if (q < i)
- return n;
- if (n == q * i)
- break;
-
- i += 4;
- q = n / i;
- if (q < i)
- return n;
- if (n == q * i)
- break;
-
- i += 2;
- q = n / i;
- if (q < i)
- return n;
- if (n == q * i)
- break;
-
- i += 10;
- q = n / i;
- if (q < i)
- return n;
- if (n == q * i)
- break;
-
- // This will loop i to the next "plane" of potential primes
- i += 2;
- }
- }
-next:
- // n is not prime. Increment n to next potential prime.
- if (++in == M)
- {
- ++k0;
- in = 0;
- }
- n = L * k0 + indices[in];
+ size_t i = 211;
+ while (true) {
+ std::size_t q = n / i;
+ if (q < i)
+ return n;
+ if (n == q * i)
+ break;
+
+ i += 10;
+ q = n / i;
+ if (q < i)
+ return n;
+ if (n == q * i)
+ break;
+
+ i += 2;
+ q = n / i;
+ if (q < i)
+ return n;
+ if (n == q * i)
+ break;
+
+ i += 4;
+ q = n / i;
+ if (q < i)
+ return n;
+ if (n == q * i)
+ break;
+
+ i += 2;
+ q = n / i;
+ if (q < i)
+ return n;
+ if (n == q * i)
+ break;
+
+ i += 4;
+ q = n / i;
+ if (q < i)
+ return n;
+ if (n == q * i)
+ break;
+
+ i += 6;
+ q = n / i;
+ if (q < i)
+ return n;
+ if (n == q * i)
+ break;
+
+ i += 2;
+ q = n / i;
+ if (q < i)
+ return n;
+ if (n == q * i)
+ break;
+
+ i += 6;
+ q = n / i;
+ if (q < i)
+ return n;
+ if (n == q * i)
+ break;
+
+ i += 4;
+ q = n / i;
+ if (q < i)
+ return n;
+ if (n == q * i)
+ break;
+
+ i += 2;
+ q = n / i;
+ if (q < i)
+ return n;
+ if (n == q * i)
+ break;
+
+ i += 4;
+ q = n / i;
+ if (q < i)
+ return n;
+ if (n == q * i)
+ break;
+
+ i += 6;
+ q = n / i;
+ if (q < i)
+ return n;
+ if (n == q * i)
+ break;
+
+ i += 6;
+ q = n / i;
+ if (q < i)
+ return n;
+ if (n == q * i)
+ break;
+
+ i += 2;
+ q = n / i;
+ if (q < i)
+ return n;
+ if (n == q * i)
+ break;
+
+ i += 6;
+ q = n / i;
+ if (q < i)
+ return n;
+ if (n == q * i)
+ break;
+
+ i += 4;
+ q = n / i;
+ if (q < i)
+ return n;
+ if (n == q * i)
+ break;
+
+ i += 2;
+ q = n / i;
+ if (q < i)
+ return n;
+ if (n == q * i)
+ break;
+
+ i += 6;
+ q = n / i;
+ if (q < i)
+ return n;
+ if (n == q * i)
+ break;
+
+ i += 4;
+ q = n / i;
+ if (q < i)
+ return n;
+ if (n == q * i)
+ break;
+
+ i += 6;
+ q = n / i;
+ if (q < i)
+ return n;
+ if (n == q * i)
+ break;
+
+ i += 8;
+ q = n / i;
+ if (q < i)
+ return n;
+ if (n == q * i)
+ break;
+
+ i += 4;
+ q = n / i;
+ if (q < i)
+ return n;
+ if (n == q * i)
+ break;
+
+ i += 2;
+ q = n / i;
+ if (q < i)
+ return n;
+ if (n == q * i)
+ break;
+
+ i += 4;
+ q = n / i;
+ if (q < i)
+ return n;
+ if (n == q * i)
+ break;
+
+ i += 2;
+ q = n / i;
+ if (q < i)
+ return n;
+ if (n == q * i)
+ break;
+
+ i += 4;
+ q = n / i;
+ if (q < i)
+ return n;
+ if (n == q * i)
+ break;
+
+ i += 8;
+ q = n / i;
+ if (q < i)
+ return n;
+ if (n == q * i)
+ break;
+
+ i += 6;
+ q = n / i;
+ if (q < i)
+ return n;
+ if (n == q * i)
+ break;
+
+ i += 4;
+ q = n / i;
+ if (q < i)
+ return n;
+ if (n == q * i)
+ break;
+
+ i += 6;
+ q = n / i;
+ if (q < i)
+ return n;
+ if (n == q * i)
+ break;
+
+ i += 2;
+ q = n / i;
+ if (q < i)
+ return n;
+ if (n == q * i)
+ break;
+
+ i += 4;
+ q = n / i;
+ if (q < i)
+ return n;
+ if (n == q * i)
+ break;
+
+ i += 6;
+ q = n / i;
+ if (q < i)
+ return n;
+ if (n == q * i)
+ break;
+
+ i += 2;
+ q = n / i;
+ if (q < i)
+ return n;
+ if (n == q * i)
+ break;
+
+ i += 6;
+ q = n / i;
+ if (q < i)
+ return n;
+ if (n == q * i)
+ break;
+
+ i += 6;
+ q = n / i;
+ if (q < i)
+ return n;
+ if (n == q * i)
+ break;
+
+ i += 4;
+ q = n / i;
+ if (q < i)
+ return n;
+ if (n == q * i)
+ break;
+
+ i += 2;
+ q = n / i;
+ if (q < i)
+ return n;
+ if (n == q * i)
+ break;
+
+ i += 4;
+ q = n / i;
+ if (q < i)
+ return n;
+ if (n == q * i)
+ break;
+
+ i += 6;
+ q = n / i;
+ if (q < i)
+ return n;
+ if (n == q * i)
+ break;
+
+ i += 2;
+ q = n / i;
+ if (q < i)
+ return n;
+ if (n == q * i)
+ break;
+
+ i += 6;
+ q = n / i;
+ if (q < i)
+ return n;
+ if (n == q * i)
+ break;
+
+ i += 4;
+ q = n / i;
+ if (q < i)
+ return n;
+ if (n == q * i)
+ break;
+
+ i += 2;
+ q = n / i;
+ if (q < i)
+ return n;
+ if (n == q * i)
+ break;
+
+ i += 4;
+ q = n / i;
+ if (q < i)
+ return n;
+ if (n == q * i)
+ break;
+
+ i += 2;
+ q = n / i;
+ if (q < i)
+ return n;
+ if (n == q * i)
+ break;
+
+ i += 10;
+ q = n / i;
+ if (q < i)
+ return n;
+ if (n == q * i)
+ break;
+
+ // This will loop i to the next "plane" of potential primes
+ i += 2;
+ }
+ }
+ next:
+ // n is not prime. Increment n to next potential prime.
+ if (++in == M) {
+ ++k0;
+ in = 0;
}
+ n = L * k0 + indices[in];
+ }
}
_LIBCPP_END_NAMESPACE_STD
diff --git a/contrib/llvm-project/libcxx/src/include/apple_availability.h b/contrib/llvm-project/libcxx/src/include/apple_availability.h
index 0f999d3feafb..fc2ad1506541 100644
--- a/contrib/llvm-project/libcxx/src/include/apple_availability.h
+++ b/contrib/llvm-project/libcxx/src/include/apple_availability.h
@@ -1,50 +1,33 @@
-//===------------------------ apple_availability.h ------------------------===//
+//===----------------------------------------------------------------------===//
//
// 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_SRC_INCLUDE_APPLE_AVAILABILITY_H
#define _LIBCPP_SRC_INCLUDE_APPLE_AVAILABILITY_H
#if defined(__APPLE__)
-#if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__)
-#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101300
-#define _LIBCPP_USE_UTIMENSAT
-#endif
-#elif defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__)
-#if __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ >= 110000
-#define _LIBCPP_USE_UTIMENSAT
-#endif
-#elif defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__)
-#if __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ >= 110000
-#define _LIBCPP_USE_UTIMENSAT
-#endif
-#elif defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__)
-#if __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ >= 40000
-#define _LIBCPP_USE_UTIMENSAT
-#endif
-#endif // __ENVIRONMENT_.*_VERSION_MIN_REQUIRED__
-
-#if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__)
-#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101500
-#define _LIBCPP_USE_ULOCK
-#endif
-#elif defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__)
-#if __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ >= 130000
-#define _LIBCPP_USE_ULOCK
-#endif
-#elif defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__)
-#if __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ >= 130000
-#define _LIBCPP_USE_ULOCK
-#endif
-#elif defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__)
-#if __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ >= 60000
-#define _LIBCPP_USE_ULOCK
-#endif
-#endif // __ENVIRONMENT_.*_VERSION_MIN_REQUIRED__
+# if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__)
+# if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101500
+# define _LIBCPP_USE_ULOCK
+# endif
+# elif defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__)
+# if __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ >= 130000
+# define _LIBCPP_USE_ULOCK
+# endif
+# elif defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__)
+# if __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ >= 130000
+# define _LIBCPP_USE_ULOCK
+# endif
+# elif defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__)
+# if __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ >= 60000
+# define _LIBCPP_USE_ULOCK
+# endif
+# endif // __ENVIRONMENT_.*_VERSION_MIN_REQUIRED__
#endif // __APPLE__
diff --git a/contrib/llvm-project/libcxx/src/include/atomic_support.h b/contrib/llvm-project/libcxx/src/include/atomic_support.h
index 43c1a00234d2..9ce41b3229f5 100644
--- a/contrib/llvm-project/libcxx/src/include/atomic_support.h
+++ b/contrib/llvm-project/libcxx/src/include/atomic_support.h
@@ -9,31 +9,24 @@
#ifndef ATOMIC_SUPPORT_H
#define ATOMIC_SUPPORT_H
-#include "__config"
-#include "memory" // for __libcpp_relaxed_load
-
-#if defined(__clang__) && __has_builtin(__atomic_load_n) \
- && __has_builtin(__atomic_store_n) \
- && __has_builtin(__atomic_add_fetch) \
- && __has_builtin(__atomic_exchange_n) \
- && __has_builtin(__atomic_compare_exchange_n) \
- && defined(__ATOMIC_RELAXED) \
- && defined(__ATOMIC_CONSUME) \
- && defined(__ATOMIC_ACQUIRE) \
- && defined(__ATOMIC_RELEASE) \
- && defined(__ATOMIC_ACQ_REL) \
- && defined(__ATOMIC_SEQ_CST)
-# define _LIBCPP_HAS_ATOMIC_BUILTINS
-#elif !defined(__clang__) && defined(_GNUC_VER) && _GNUC_VER >= 407
-# define _LIBCPP_HAS_ATOMIC_BUILTINS
+#include <__config>
+#include <memory> // for __libcpp_relaxed_load
+
+#if defined(__clang__) && __has_builtin(__atomic_load_n) && __has_builtin(__atomic_store_n) && \
+ __has_builtin(__atomic_add_fetch) && __has_builtin(__atomic_exchange_n) && \
+ __has_builtin(__atomic_compare_exchange_n) && defined(__ATOMIC_RELAXED) && defined(__ATOMIC_CONSUME) && \
+ defined(__ATOMIC_ACQUIRE) && defined(__ATOMIC_RELEASE) && defined(__ATOMIC_ACQ_REL) && defined(__ATOMIC_SEQ_CST)
+# define _LIBCPP_HAS_ATOMIC_BUILTINS
+#elif defined(_LIBCPP_COMPILER_GCC)
+# define _LIBCPP_HAS_ATOMIC_BUILTINS
#endif
#if !defined(_LIBCPP_HAS_ATOMIC_BUILTINS) && !defined(_LIBCPP_HAS_NO_THREADS)
-# if defined(_LIBCPP_WARNING)
- _LIBCPP_WARNING("Building libc++ without __atomic builtins is unsupported")
-# else
-# warning Building libc++ without __atomic builtins is unsupported
-# endif
+# if defined(_LIBCPP_WARNING)
+_LIBCPP_WARNING("Building libc++ without __atomic builtins is unsupported")
+# else
+# warning Building libc++ without __atomic builtins is unsupported
+# endif
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -43,128 +36,91 @@ namespace {
#if defined(_LIBCPP_HAS_ATOMIC_BUILTINS) && !defined(_LIBCPP_HAS_NO_THREADS)
enum __libcpp_atomic_order {
- _AO_Relaxed = __ATOMIC_RELAXED,
- _AO_Consume = __ATOMIC_CONSUME,
- _AO_Acquire = __ATOMIC_ACQUIRE,
- _AO_Release = __ATOMIC_RELEASE,
- _AO_Acq_Rel = __ATOMIC_ACQ_REL,
- _AO_Seq = __ATOMIC_SEQ_CST
+ _AO_Relaxed = __ATOMIC_RELAXED,
+ _AO_Consume = __ATOMIC_CONSUME,
+ _AO_Acquire = __ATOMIC_ACQUIRE,
+ _AO_Release = __ATOMIC_RELEASE,
+ _AO_Acq_Rel = __ATOMIC_ACQ_REL,
+ _AO_Seq = __ATOMIC_SEQ_CST
};
template <class _ValueType, class _FromType>
-inline _LIBCPP_INLINE_VISIBILITY
-void __libcpp_atomic_store(_ValueType* __dest, _FromType __val,
- int __order = _AO_Seq)
-{
- __atomic_store_n(__dest, __val, __order);
+inline _LIBCPP_HIDE_FROM_ABI void __libcpp_atomic_store(_ValueType* __dest, _FromType __val, int __order = _AO_Seq) {
+ __atomic_store_n(__dest, __val, __order);
}
template <class _ValueType, class _FromType>
-inline _LIBCPP_INLINE_VISIBILITY
-void __libcpp_relaxed_store(_ValueType* __dest, _FromType __val)
-{
- __atomic_store_n(__dest, __val, _AO_Relaxed);
+inline _LIBCPP_HIDE_FROM_ABI void __libcpp_relaxed_store(_ValueType* __dest, _FromType __val) {
+ __atomic_store_n(__dest, __val, _AO_Relaxed);
}
template <class _ValueType>
-inline _LIBCPP_INLINE_VISIBILITY
-_ValueType __libcpp_atomic_load(_ValueType const* __val,
- int __order = _AO_Seq)
-{
- return __atomic_load_n(__val, __order);
+inline _LIBCPP_HIDE_FROM_ABI _ValueType __libcpp_atomic_load(_ValueType const* __val, int __order = _AO_Seq) {
+ return __atomic_load_n(__val, __order);
}
template <class _ValueType, class _AddType>
-inline _LIBCPP_INLINE_VISIBILITY
-_ValueType __libcpp_atomic_add(_ValueType* __val, _AddType __a,
- int __order = _AO_Seq)
-{
- return __atomic_add_fetch(__val, __a, __order);
+inline _LIBCPP_HIDE_FROM_ABI _ValueType __libcpp_atomic_add(_ValueType* __val, _AddType __a, int __order = _AO_Seq) {
+ return __atomic_add_fetch(__val, __a, __order);
}
template <class _ValueType>
-inline _LIBCPP_INLINE_VISIBILITY
-_ValueType __libcpp_atomic_exchange(_ValueType* __target,
- _ValueType __value, int __order = _AO_Seq)
-{
- return __atomic_exchange_n(__target, __value, __order);
+inline _LIBCPP_HIDE_FROM_ABI _ValueType
+__libcpp_atomic_exchange(_ValueType* __target, _ValueType __value, int __order = _AO_Seq) {
+ return __atomic_exchange_n(__target, __value, __order);
}
template <class _ValueType>
-inline _LIBCPP_INLINE_VISIBILITY
-bool __libcpp_atomic_compare_exchange(_ValueType* __val,
- _ValueType* __expected, _ValueType __after,
+inline _LIBCPP_HIDE_FROM_ABI bool __libcpp_atomic_compare_exchange(
+ _ValueType* __val,
+ _ValueType* __expected,
+ _ValueType __after,
int __success_order = _AO_Seq,
- int __fail_order = _AO_Seq)
-{
- return __atomic_compare_exchange_n(__val, __expected, __after, true,
- __success_order, __fail_order);
+ int __fail_order = _AO_Seq) {
+ return __atomic_compare_exchange_n(__val, __expected, __after, true, __success_order, __fail_order);
}
#else // _LIBCPP_HAS_NO_THREADS
-enum __libcpp_atomic_order {
- _AO_Relaxed,
- _AO_Consume,
- _AO_Acquire,
- _AO_Release,
- _AO_Acq_Rel,
- _AO_Seq
-};
+enum __libcpp_atomic_order { _AO_Relaxed, _AO_Consume, _AO_Acquire, _AO_Release, _AO_Acq_Rel, _AO_Seq };
template <class _ValueType, class _FromType>
-inline _LIBCPP_INLINE_VISIBILITY
-void __libcpp_atomic_store(_ValueType* __dest, _FromType __val,
- int = 0)
-{
- *__dest = __val;
+inline _LIBCPP_HIDE_FROM_ABI void __libcpp_atomic_store(_ValueType* __dest, _FromType __val, int = 0) {
+ *__dest = __val;
}
template <class _ValueType, class _FromType>
-inline _LIBCPP_INLINE_VISIBILITY
-void __libcpp_relaxed_store(_ValueType* __dest, _FromType __val)
-{
- *__dest = __val;
+inline _LIBCPP_HIDE_FROM_ABI void __libcpp_relaxed_store(_ValueType* __dest, _FromType __val) {
+ *__dest = __val;
}
template <class _ValueType>
-inline _LIBCPP_INLINE_VISIBILITY
-_ValueType __libcpp_atomic_load(_ValueType const* __val,
- int = 0)
-{
- return *__val;
+inline _LIBCPP_HIDE_FROM_ABI _ValueType __libcpp_atomic_load(_ValueType const* __val, int = 0) {
+ return *__val;
}
template <class _ValueType, class _AddType>
-inline _LIBCPP_INLINE_VISIBILITY
-_ValueType __libcpp_atomic_add(_ValueType* __val, _AddType __a,
- int = 0)
-{
- return *__val += __a;
+inline _LIBCPP_HIDE_FROM_ABI _ValueType __libcpp_atomic_add(_ValueType* __val, _AddType __a, int = 0) {
+ return *__val += __a;
}
template <class _ValueType>
-inline _LIBCPP_INLINE_VISIBILITY
-_ValueType __libcpp_atomic_exchange(_ValueType* __target,
- _ValueType __value, int __order = _AO_Seq)
-{
- _ValueType old = *__target;
- *__target = __value;
- return old;
+inline _LIBCPP_HIDE_FROM_ABI _ValueType
+__libcpp_atomic_exchange(_ValueType* __target, _ValueType __value, int = _AO_Seq) {
+ _ValueType old = *__target;
+ *__target = __value;
+ return old;
}
template <class _ValueType>
-inline _LIBCPP_INLINE_VISIBILITY
-bool __libcpp_atomic_compare_exchange(_ValueType* __val,
- _ValueType* __expected, _ValueType __after,
- int = 0, int = 0)
-{
- if (*__val == *__expected) {
- *__val = __after;
- return true;
- }
- *__expected = *__val;
- return false;
+inline _LIBCPP_HIDE_FROM_ABI bool
+__libcpp_atomic_compare_exchange(_ValueType* __val, _ValueType* __expected, _ValueType __after, int = 0, int = 0) {
+ if (*__val == *__expected) {
+ *__val = __after;
+ return true;
+ }
+ *__expected = *__val;
+ return false;
}
#endif // _LIBCPP_HAS_NO_THREADS
diff --git a/contrib/llvm-project/libcxx/src/include/config_elast.h b/contrib/llvm-project/libcxx/src/include/config_elast.h
index 3113f9fb5cd1..899e124ad261 100644
--- a/contrib/llvm-project/libcxx/src/include/config_elast.h
+++ b/contrib/llvm-project/libcxx/src/include/config_elast.h
@@ -1,4 +1,4 @@
-//===----------------------- config_elast.h -------------------------------===//
+//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -12,34 +12,38 @@
#include <__config>
#if defined(_LIBCPP_MSVCRT_LIKE)
-#include <stdlib.h>
+# include <stdlib.h>
#else
-#include <errno.h>
+# include <errno.h>
#endif
// Note: _LIBCPP_ELAST needs to be defined only on platforms
// where strerror/strerror_r can't handle out-of-range errno values.
#if defined(ELAST)
-#define _LIBCPP_ELAST ELAST
+# define _LIBCPP_ELAST ELAST
#elif defined(_NEWLIB_VERSION)
-#define _LIBCPP_ELAST __ELASTERROR
+# define _LIBCPP_ELAST __ELASTERROR
#elif defined(__NuttX__)
// No _LIBCPP_ELAST needed on NuttX
#elif defined(__Fuchsia__)
// No _LIBCPP_ELAST needed on Fuchsia
#elif defined(__wasi__)
// No _LIBCPP_ELAST needed on WASI
+#elif defined(__EMSCRIPTEN__)
+// No _LIBCPP_ELAST needed on Emscripten
#elif defined(__linux__) || defined(_LIBCPP_HAS_MUSL_LIBC)
-#define _LIBCPP_ELAST 4095
+# define _LIBCPP_ELAST 4095
#elif defined(__APPLE__)
// No _LIBCPP_ELAST needed on Apple
-#elif defined(__sun__)
-#define _LIBCPP_ELAST ESTALE
+#elif defined(__MVS__)
+# define _LIBCPP_ELAST 1160
#elif defined(_LIBCPP_MSVCRT_LIKE)
-#define _LIBCPP_ELAST (_sys_nerr - 1)
+# define _LIBCPP_ELAST (_sys_nerr - 1)
+#elif defined(_AIX)
+# define _LIBCPP_ELAST 127
#else
// Warn here so that the person doing the libcxx port has an easier time:
-#warning ELAST for this platform not yet implemented
+# warning ELAST for this platform not yet implemented
#endif
#endif // _LIBCPP_CONFIG_ELAST
diff --git a/contrib/llvm-project/libcxx/src/include/overridable_function.h b/contrib/llvm-project/libcxx/src/include/overridable_function.h
new file mode 100644
index 000000000000..7b0fba10f47d
--- /dev/null
+++ b/contrib/llvm-project/libcxx/src/include/overridable_function.h
@@ -0,0 +1,119 @@
+// -*- 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_SRC_INCLUDE_OVERRIDABLE_FUNCTION_H
+#define _LIBCPP_SRC_INCLUDE_OVERRIDABLE_FUNCTION_H
+
+#include <__config>
+#include <cstdint>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+# pragma GCC system_header
+#endif
+
+//
+// This file provides the std::__is_function_overridden utility, which allows checking
+// whether an overridable function (typically a weak symbol) like `operator new`
+// has been overridden by a user or not.
+//
+// This is a low-level utility which does not work on all platforms, since it needs
+// to make assumptions about the object file format in use. Furthermore, it requires
+// the "base definition" of the function (the one we want to check whether it has been
+// overridden) to be annotated with the _LIBCPP_MAKE_OVERRIDABLE_FUNCTION_DETECTABLE macro.
+//
+// This currently works with Mach-O files (used on Darwin) and with ELF files (used on Linux
+// and others). On platforms where we know how to implement this detection, the macro
+// _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION is defined to 1, and it is defined to 0 on
+// other platforms. The _LIBCPP_MAKE_OVERRIDABLE_FUNCTION_DETECTABLE macro is defined to
+// nothing on unsupported platforms so that it can be used to decorate functions regardless
+// of whether detection is actually supported.
+//
+// How does this work?
+// -------------------
+//
+// Let's say we want to check whether a weak function `f` has been overridden by the user.
+// The general mechanism works by placing `f`'s definition (in the libc++ built library)
+// inside a special section, which we do using the `__section__` attribute via the
+// _LIBCPP_MAKE_OVERRIDABLE_FUNCTION_DETECTABLE macro.
+//
+// Then, when comes the time to check whether the function has been overridden, we take
+// the address of the function and we check whether it falls inside the special function
+// we created. This can be done by finding pointers to the start and the end of the section
+// (which is done differently for ELF and Mach-O), and then checking whether `f` falls
+// within those bounds. If it falls within those bounds, then `f` is still inside the
+// special section and so it is the version we defined in the libc++ built library, i.e.
+// it was not overridden. Otherwise, it was overridden by the user because it falls
+// outside of the section.
+//
+// Important note
+// --------------
+//
+// This mechanism should never be used outside of the libc++ built library. In particular,
+// attempting to use this within the libc++ headers will not work at all because we don't
+// want to be defining special sections inside user's executables which use our headers.
+// This is provided inside libc++'s include tree solely to make it easier to share with
+// libc++abi, which needs the same mechanism.
+//
+
+#if defined(_LIBCPP_OBJECT_FORMAT_MACHO)
+
+# define _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION 1
+# define _LIBCPP_MAKE_OVERRIDABLE_FUNCTION_DETECTABLE \
+ __attribute__((__section__("__TEXT,__lcxx_override,regular,pure_instructions")))
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+template <class _Ret, class... _Args>
+_LIBCPP_HIDE_FROM_ABI bool __is_function_overridden(_Ret (*__fptr)(_Args...)) noexcept {
+ // Declare two dummy bytes and give them these special `__asm` values. These values are
+ // defined by the linker, which means that referring to `&__lcxx_override_start` will
+ // effectively refer to the address where the section starts (and same for the end).
+ extern char __lcxx_override_start __asm("section$start$__TEXT$__lcxx_override");
+ extern char __lcxx_override_end __asm("section$end$__TEXT$__lcxx_override");
+
+ // Now get a uintptr_t out of these locations, and out of the function pointer.
+ uintptr_t __start = reinterpret_cast<uintptr_t>(&__lcxx_override_start);
+ uintptr_t __end = reinterpret_cast<uintptr_t>(&__lcxx_override_end);
+ uintptr_t __ptr = reinterpret_cast<uintptr_t>(__fptr);
+
+ // Finally, the function was overridden if it falls outside of the section's bounds.
+ return __ptr < __start || __ptr > __end;
+}
+_LIBCPP_END_NAMESPACE_STD
+
+#elif defined(_LIBCPP_OBJECT_FORMAT_ELF)
+
+# define _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION 1
+# define _LIBCPP_MAKE_OVERRIDABLE_FUNCTION_DETECTABLE __attribute__((__section__("__lcxx_override")))
+
+// This is very similar to what we do for Mach-O above. The ELF linker will implicitly define
+// variables with those names corresponding to the start and the end of the section.
+//
+// See https://stackoverflow.com/questions/16552710/how-do-you-get-the-start-and-end-addresses-of-a-custom-elf-section
+extern char __start___lcxx_override;
+extern char __stop___lcxx_override;
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+template <class _Ret, class... _Args>
+_LIBCPP_HIDE_FROM_ABI bool __is_function_overridden(_Ret (*__fptr)(_Args...)) noexcept {
+ uintptr_t __start = reinterpret_cast<uintptr_t>(&__start___lcxx_override);
+ uintptr_t __end = reinterpret_cast<uintptr_t>(&__stop___lcxx_override);
+ uintptr_t __ptr = reinterpret_cast<uintptr_t>(__fptr);
+
+ return __ptr < __start || __ptr > __end;
+}
+_LIBCPP_END_NAMESPACE_STD
+
+#else
+
+# define _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION 0
+# define _LIBCPP_MAKE_OVERRIDABLE_FUNCTION_DETECTABLE /* nothing */
+
+#endif
+
+#endif // _LIBCPP_SRC_INCLUDE_OVERRIDABLE_FUNCTION_H
diff --git a/contrib/llvm-project/libcxx/src/include/refstring.h b/contrib/llvm-project/libcxx/src/include/refstring.h
index cefd7caf0f20..78452249f4fe 100644
--- a/contrib/llvm-project/libcxx/src/include/refstring.h
+++ b/contrib/llvm-project/libcxx/src/include/refstring.h
@@ -1,4 +1,4 @@
-//===------------------------ __refstring ---------------------------------===//
+//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -9,11 +9,11 @@
#ifndef _LIBCPP_REFSTRING_H
#define _LIBCPP_REFSTRING_H
+#include "atomic_support.h"
#include <__config>
-#include <stdexcept>
#include <cstddef>
#include <cstring>
-#include "atomic_support.h"
+#include <stdexcept>
// MacOS and iOS used to ship with libstdc++, and still support old applications
// linking against libstdc++. The libc++ and libstdc++ exceptions are supposed
@@ -25,113 +25,100 @@
// string singleton before manipulating the reference count. This is done so that
// if an exception is created with a zero-length string in libstdc++, libc++abi
// won't try to delete the memory.
-#if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) || \
- defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__)
-# define _LIBCPP_CHECK_FOR_GCC_EMPTY_STRING_STORAGE
-# include <dlfcn.h>
-# include <mach-o/dyld.h>
+#if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) || defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__)
+# define _LIBCPP_CHECK_FOR_GCC_EMPTY_STRING_STORAGE
+# include <dlfcn.h>
+# include <mach-o/dyld.h>
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
-namespace __refstring_imp { namespace {
+namespace __refstring_imp {
+namespace {
typedef int count_t;
struct _Rep_base {
- std::size_t len;
- std::size_t cap;
- count_t count;
+ std::size_t len;
+ std::size_t cap;
+ count_t count;
};
-inline _Rep_base* rep_from_data(const char *data_) noexcept {
- char *data = const_cast<char *>(data_);
- return reinterpret_cast<_Rep_base *>(data - sizeof(_Rep_base));
+inline _Rep_base* rep_from_data(const char* data_) noexcept {
+ char* data = const_cast<char*>(data_);
+ return reinterpret_cast<_Rep_base*>(data - sizeof(_Rep_base));
}
-inline char * data_from_rep(_Rep_base *rep) noexcept {
- char *data = reinterpret_cast<char *>(rep);
- return data + sizeof(*rep);
+inline char* data_from_rep(_Rep_base* rep) noexcept {
+ char* data = reinterpret_cast<char*>(rep);
+ return data + sizeof(*rep);
}
#if defined(_LIBCPP_CHECK_FOR_GCC_EMPTY_STRING_STORAGE)
-inline
-const char* compute_gcc_empty_string_storage() _NOEXCEPT
-{
- void* handle = dlopen("/usr/lib/libstdc++.6.dylib", RTLD_NOLOAD);
- if (handle == nullptr)
- return nullptr;
- void* sym = dlsym(handle, "_ZNSs4_Rep20_S_empty_rep_storageE");
- if (sym == nullptr)
- return nullptr;
- return data_from_rep(reinterpret_cast<_Rep_base *>(sym));
+inline const char* compute_gcc_empty_string_storage() noexcept {
+ void* handle = dlopen("/usr/lib/libstdc++.6.dylib", RTLD_NOLOAD);
+ if (handle == nullptr)
+ return nullptr;
+ void* sym = dlsym(handle, "_ZNSs4_Rep20_S_empty_rep_storageE");
+ if (sym == nullptr)
+ return nullptr;
+ return data_from_rep(reinterpret_cast<_Rep_base*>(sym));
}
-inline
-const char*
-get_gcc_empty_string_storage() _NOEXCEPT
-{
- static const char* p = compute_gcc_empty_string_storage();
- return p;
+inline const char* get_gcc_empty_string_storage() noexcept {
+ static const char* p = compute_gcc_empty_string_storage();
+ return p;
}
#endif
-}} // namespace __refstring_imp
+} // namespace
+} // namespace __refstring_imp
using namespace __refstring_imp;
-inline
-__libcpp_refstring::__libcpp_refstring(const char* msg) {
- std::size_t len = strlen(msg);
- _Rep_base* rep = static_cast<_Rep_base *>(::operator new(sizeof(*rep) + len + 1));
- rep->len = len;
- rep->cap = len;
- rep->count = 0;
- char *data = data_from_rep(rep);
- std::memcpy(data, msg, len + 1);
- __imp_ = data;
+inline __libcpp_refstring::__libcpp_refstring(const char* msg) {
+ std::size_t len = strlen(msg);
+ _Rep_base* rep = static_cast<_Rep_base*>(::operator new(sizeof(*rep) + len + 1));
+ rep->len = len;
+ rep->cap = len;
+ rep->count = 0;
+ char* data = data_from_rep(rep);
+ std::memcpy(data, msg, len + 1);
+ __imp_ = data;
}
-inline
-__libcpp_refstring::__libcpp_refstring(const __libcpp_refstring &s) _NOEXCEPT
- : __imp_(s.__imp_)
-{
- if (__uses_refcount())
- __libcpp_atomic_add(&rep_from_data(__imp_)->count, 1);
+inline __libcpp_refstring::__libcpp_refstring(const __libcpp_refstring& s) noexcept : __imp_(s.__imp_) {
+ if (__uses_refcount())
+ __libcpp_atomic_add(&rep_from_data(__imp_)->count, 1);
}
-inline
-__libcpp_refstring& __libcpp_refstring::operator=(__libcpp_refstring const& s) _NOEXCEPT {
- bool adjust_old_count = __uses_refcount();
- struct _Rep_base *old_rep = rep_from_data(__imp_);
- __imp_ = s.__imp_;
- if (__uses_refcount())
- __libcpp_atomic_add(&rep_from_data(__imp_)->count, 1);
- if (adjust_old_count)
- {
- if (__libcpp_atomic_add(&old_rep->count, count_t(-1)) < 0)
- {
- ::operator delete(old_rep);
- }
+inline __libcpp_refstring& __libcpp_refstring::operator=(__libcpp_refstring const& s) noexcept {
+ bool adjust_old_count = __uses_refcount();
+ struct _Rep_base* old_rep = rep_from_data(__imp_);
+ __imp_ = s.__imp_;
+ if (__uses_refcount())
+ __libcpp_atomic_add(&rep_from_data(__imp_)->count, 1);
+ if (adjust_old_count) {
+ if (__libcpp_atomic_add(&old_rep->count, count_t(-1)) < 0) {
+ ::operator delete(old_rep);
}
- return *this;
+ }
+ return *this;
}
-inline
-__libcpp_refstring::~__libcpp_refstring() {
- if (__uses_refcount()) {
- _Rep_base* rep = rep_from_data(__imp_);
- if (__libcpp_atomic_add(&rep->count, count_t(-1)) < 0) {
- ::operator delete(rep);
- }
+inline __libcpp_refstring::~__libcpp_refstring() {
+ if (__uses_refcount()) {
+ _Rep_base* rep = rep_from_data(__imp_);
+ if (__libcpp_atomic_add(&rep->count, count_t(-1)) < 0) {
+ ::operator delete(rep);
}
+ }
}
-inline
-bool __libcpp_refstring::__uses_refcount() const {
+inline bool __libcpp_refstring::__uses_refcount() const {
#if defined(_LIBCPP_CHECK_FOR_GCC_EMPTY_STRING_STORAGE)
- return __imp_ != get_gcc_empty_string_storage();
+ return __imp_ != get_gcc_empty_string_storage();
#else
- return true;
+ return true;
#endif
}
diff --git a/contrib/llvm-project/libcxx/src/include/ryu/common.h b/contrib/llvm-project/libcxx/src/include/ryu/common.h
new file mode 100644
index 000000000000..d5168d8710bf
--- /dev/null
+++ b/contrib/llvm-project/libcxx/src/include/ryu/common.h
@@ -0,0 +1,109 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// Copyright (c) Microsoft Corporation.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+// Copyright 2018 Ulf Adams
+// Copyright (c) Microsoft Corporation. All rights reserved.
+
+// Boost Software License - Version 1.0 - August 17th, 2003
+
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+
+#ifndef _LIBCPP_SRC_INCLUDE_RYU_COMMON_H
+#define _LIBCPP_SRC_INCLUDE_RYU_COMMON_H
+
+// Avoid formatting to keep the changes with the original code minimal.
+// clang-format off
+
+#include <__assert>
+#include <__config>
+#include <cstring>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint32_t __decimalLength9(const uint32_t __v) {
+ // Function precondition: __v is not a 10-digit number.
+ // (f2s: 9 digits are sufficient for round-tripping.)
+ // (d2fixed: We print 9-digit blocks.)
+ _LIBCPP_ASSERT_INTERNAL(__v < 1000000000, "");
+ if (__v >= 100000000) { return 9; }
+ if (__v >= 10000000) { return 8; }
+ if (__v >= 1000000) { return 7; }
+ if (__v >= 100000) { return 6; }
+ if (__v >= 10000) { return 5; }
+ if (__v >= 1000) { return 4; }
+ if (__v >= 100) { return 3; }
+ if (__v >= 10) { return 2; }
+ return 1;
+}
+
+// Returns __e == 0 ? 1 : ceil(log_2(5^__e)).
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline int32_t __pow5bits(const int32_t __e) {
+ // This approximation works up to the point that the multiplication overflows at __e = 3529.
+ // If the multiplication were done in 64 bits, it would fail at 5^4004 which is just greater
+ // than 2^9297.
+ _LIBCPP_ASSERT_INTERNAL(__e >= 0, "");
+ _LIBCPP_ASSERT_INTERNAL(__e <= 3528, "");
+ return static_cast<int32_t>(((static_cast<uint32_t>(__e) * 1217359) >> 19) + 1);
+}
+
+// Returns floor(log_10(2^__e)).
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint32_t __log10Pow2(const int32_t __e) {
+ // The first value this approximation fails for is 2^1651 which is just greater than 10^297.
+ _LIBCPP_ASSERT_INTERNAL(__e >= 0, "");
+ _LIBCPP_ASSERT_INTERNAL(__e <= 1650, "");
+ return (static_cast<uint32_t>(__e) * 78913) >> 18;
+}
+
+// Returns floor(log_10(5^__e)).
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint32_t __log10Pow5(const int32_t __e) {
+ // The first value this approximation fails for is 5^2621 which is just greater than 10^1832.
+ _LIBCPP_ASSERT_INTERNAL(__e >= 0, "");
+ _LIBCPP_ASSERT_INTERNAL(__e <= 2620, "");
+ return (static_cast<uint32_t>(__e) * 732923) >> 20;
+}
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint32_t __float_to_bits(const float __f) {
+ uint32_t __bits = 0;
+ std::memcpy(&__bits, &__f, sizeof(float));
+ return __bits;
+}
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __double_to_bits(const double __d) {
+ uint64_t __bits = 0;
+ std::memcpy(&__bits, &__d, sizeof(double));
+ return __bits;
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+// clang-format on
+
+#endif // _LIBCPP_SRC_INCLUDE_RYU_COMMON_H
diff --git a/contrib/llvm-project/libcxx/src/include/ryu/d2fixed.h b/contrib/llvm-project/libcxx/src/include/ryu/d2fixed.h
new file mode 100644
index 000000000000..b8862de251ce
--- /dev/null
+++ b/contrib/llvm-project/libcxx/src/include/ryu/d2fixed.h
@@ -0,0 +1,60 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// Copyright (c) Microsoft Corporation.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+// Copyright 2018 Ulf Adams
+// Copyright (c) Microsoft Corporation. All rights reserved.
+
+// Boost Software License - Version 1.0 - August 17th, 2003
+
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+
+#ifndef _LIBCPP_SRC_INCLUDE_RYU_D2FIXED_H
+#define _LIBCPP_SRC_INCLUDE_RYU_D2FIXED_H
+
+// Avoid formatting to keep the changes with the original code minimal.
+// clang-format off
+
+#include <__config>
+#include <cstdint>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+void __append_n_digits(const uint32_t __olength, uint32_t __digits, char* const __result);
+void __append_nine_digits(uint32_t __digits, char* const __result);
+
+[[nodiscard]] to_chars_result __d2fixed_buffered_n(char* _First, char* const _Last, const double __d, const uint32_t __precision);
+[[nodiscard]] to_chars_result __d2exp_buffered_n(char* _First, char* const _Last, const double __d, uint32_t __precision);
+
+_LIBCPP_END_NAMESPACE_STD
+
+// clang-format on
+
+#endif // _LIBCPP_SRC_INCLUDE_RYU_D2FIXED_H
diff --git a/contrib/llvm-project/libcxx/src/include/ryu/d2fixed_full_table.h b/contrib/llvm-project/libcxx/src/include/ryu/d2fixed_full_table.h
new file mode 100644
index 000000000000..a63d6f2d1619
--- /dev/null
+++ b/contrib/llvm-project/libcxx/src/include/ryu/d2fixed_full_table.h
@@ -0,0 +1,4451 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// Copyright (c) Microsoft Corporation.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+// Copyright 2018 Ulf Adams
+// Copyright (c) Microsoft Corporation. All rights reserved.
+
+// Boost Software License - Version 1.0 - August 17th, 2003
+
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+
+#ifndef _LIBCPP_SRC_INCLUDE_RYU_D2FIXED_FULL_TABLE_H
+#define _LIBCPP_SRC_INCLUDE_RYU_D2FIXED_FULL_TABLE_H
+
+// Avoid formatting to keep the changes with the original code minimal.
+// clang-format off
+
+#include <__config>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+inline constexpr int __TABLE_SIZE = 64;
+
+inline constexpr uint16_t __POW10_OFFSET[__TABLE_SIZE] = {
+ 0, 2, 5, 8, 12, 16, 21, 26, 32, 39,
+ 46, 54, 62, 71, 80, 90, 100, 111, 122, 134,
+ 146, 159, 173, 187, 202, 217, 233, 249, 266, 283,
+ 301, 319, 338, 357, 377, 397, 418, 440, 462, 485,
+ 508, 532, 556, 581, 606, 632, 658, 685, 712, 740,
+ 769, 798, 828, 858, 889, 920, 952, 984, 1017, 1050,
+ 1084, 1118, 1153, 1188
+};
+
+inline constexpr uint64_t __POW10_SPLIT[1224][3] = {
+ { 1u, 72057594037927936u, 0u },
+ { 699646928636035157u, 72057594u, 0u },
+ { 1u, 0u, 256u },
+ { 11902091922964236229u, 4722366482869u, 0u },
+ { 6760415703743915872u, 4722u, 0u },
+ { 1u, 0u, 16777216u },
+ { 13369850649504950658u, 309485009821345068u, 0u },
+ { 15151142278969419334u, 309485009u, 0u },
+ { 1u, 0u, 75511627776u },
+ { 4635408826454083567u, 9437866644873197963u, 1099u },
+ { 12367138975830625353u, 20282409603651u, 0u },
+ { 7555853734021184432u, 20282u, 0u },
+ { 1u, 0u, 250037927936u },
+ { 5171444645924616995u, 699646928636035156u, 72057594u },
+ { 16672297533003297786u, 1329227995784915872u, 0u },
+ { 14479142226848862515u, 1329227995u, 0u },
+ { 1u, 0u, 181645213696u },
+ { 12214193123817091081u, 11902091922964236228u, 114366482869u },
+ { 16592893013671929435u, 6760415703743915871u, 4722u },
+ { 4549827147718617003u, 87112285931760u, 0u },
+ { 5274510003815168971u, 87112u, 0u },
+ { 1u, 0u, 44724781056u },
+ { 9794971998307800535u, 13369850649504950657u, 209821345068u },
+ { 14720142899209240169u, 15151142278969419333u, 309485009u },
+ { 4300745446091561535u, 5708990770823839524u, 0u },
+ { 15197156861335443364u, 5708990770u, 0u },
+ { 1u, 0u, 139251286016u },
+ { 13484604155038683037u, 4635408826454083566u, 67670423947u },
+ { 8356963862052375699u, 12367138975830625352u, 58409603651u },
+ { 5850852848337610021u, 7555853734021184431u, 20282u },
+ { 2712780827214982050u, 374144419156711u, 0u },
+ { 7732076577307618052u, 374144u, 0u },
+ { 1u, 0u, 84280344576u },
+ { 17296309485351745867u, 5171444645924616994u, 160903807060u },
+ { 16598859101615853088u, 16672297533003297785u, 219784915872u },
+ { 7469952526870444257u, 14479142226848862514u, 1329227995u },
+ { 13531654022114669524u, 6073184580144670117u, 1u },
+ { 15757609704383306943u, 24519928653u, 0u },
+ { 9590990814237149590u, 24u, 0u },
+ { 1u, 0u, 196662132736u },
+ { 15408590707489433890u, 12214193123817091080u, 95899502532u },
+ { 18332056844289122710u, 16592893013671929434u, 240246646623u },
+ { 11114572877353986193u, 4549827147718617002u, 72285931760u },
+ { 1703393793997526525u, 5274510003815168970u, 87112u },
+ { 5082852056285196265u, 1606938044258990u, 0u },
+ { 816434266573722365u, 1606938u, 0u },
+ { 1u, 0u, 129530986496u },
+ { 5736523019264798742u, 9794971998307800534u, 69797980545u },
+ { 10129314776268243339u, 14720142899209240168u, 36233143877u },
+ { 16511595775483995364u, 4300745446091561534u, 50823839524u },
+ { 12367293405401453325u, 15197156861335443363u, 5708990770u },
+ { 16934621733248854291u, 13078571300009428617u, 5u },
+ { 10278280417769171336u, 105312291668u, 0u },
+ { 5760764486226151240u, 105u, 0u },
+ { 1u, 0u, 238731001856u },
+ { 4128368337188369761u, 13484604155038683036u, 72453031918u },
+ { 10240941003671005056u, 8356963862052375698u, 175317175368u },
+ { 17933378316822368251u, 5850852848337610020u, 231147060143u },
+ { 8346249813075698616u, 2712780827214982049u, 128419156711u },
+ { 15906203609160902695u, 7732076577307618051u, 374144u },
+ { 14525607416135386328u, 6901746346790563u, 0u },
+ { 6397156777364256320u, 6901746u, 0u },
+ { 1u, 0u, 34937634816u },
+ { 16798760952716600048u, 17296309485351745866u, 249899825954u },
+ { 2419982808370854967u, 16598859101615853087u, 50404946937u },
+ { 2922947087773078956u, 7469952526870444256u, 165733552434u },
+ { 15419220167069510190u, 13531654022114669523u, 77854221733u },
+ { 3452124642157173416u, 15757609704383306942u, 24519928653u },
+ { 5979700067267186899u, 9590990814237149589u, 24u },
+ { 4913998146922579597u, 452312848583u, 0u },
+ { 5771037749337678924u, 452u, 0u },
+ { 1u, 0u, 8835301376u },
+ { 3464734175350698519u, 15408590707489433889u, 90993782792u },
+ { 9334527711335850125u, 18332056844289122709u, 170602522202u },
+ { 7269882896518450106u, 11114572877353986192u, 202092341162u },
+ { 1372511258182263196u, 1703393793997526524u, 174275541962u },
+ { 7571228438575951046u, 5082852056285196264u, 26044258990u },
+ { 2992506536646070406u, 816434266573722364u, 1606938u },
+ { 524517896824344606u, 29642774844752946u, 0u },
+ { 15582941400898702773u, 29642774u, 0u },
+ { 1u, 0u, 214310977536u },
+ { 3846112492507251066u, 5736523019264798741u, 104549111254u },
+ { 16681117750123089487u, 10129314776268243338u, 62895095400u },
+ { 14986314536556547267u, 16511595775483995363u, 163670432318u },
+ { 2573712825027107389u, 12367293405401453324u, 137918027683u },
+ { 7504855874008324928u, 16934621733248854290u, 84557186697u },
+ { 9572138030626879787u, 10278280417769171335u, 105312291668u },
+ { 8520676959353394843u, 5760764486226151239u, 105u },
+ { 13448984662897903496u, 1942668892225u, 0u },
+ { 12338883700918130648u, 1942u, 0u },
+ { 1u, 0u, 156223799296u },
+ { 2517285787892561600u, 4128368337188369760u, 146555162524u },
+ { 4338831817635138103u, 10240941003671005055u, 36972170386u },
+ { 1561495325934523196u, 17933378316822368250u, 161452451108u },
+ { 12262635050079398786u, 8346249813075698615u, 3862277025u },
+ { 11144065765517284188u, 15906203609160902694u, 163787434755u },
+ { 1212260522471875711u, 14525607416135386327u, 242346790563u },
+ { 9695352922247418869u, 6397156777364256319u, 6901746u },
+ { 7227025834627242948u, 127314748520905380u, 0u },
+ { 9609008238705447829u, 127314748u, 0u },
+ { 1u, 0u, 74910662656u },
+ { 3609144142396852269u, 16798760952716600047u, 31131187530u },
+ { 11568848377382068865u, 2419982808370854966u, 224158453279u },
+ { 10068303578029323957u, 2922947087773078955u, 211835877600u },
+ { 11645070846862630231u, 15419220167069510189u, 190187140051u },
+ { 12449386705878485055u, 3452124642157173415u, 149324160190u },
+ { 15025619323517318418u, 5979700067267186898u, 199266388373u },
+ { 14996237555047131272u, 4913998146922579596u, 196312848583u },
+ { 10211005638256058413u, 5771037749337678923u, 452u },
+ { 1014743503555840530u, 8343699359066u, 0u },
+ { 12900897707145290678u, 8343u, 0u },
+ { 1u, 0u, 33187823616u },
+ { 4718003016239473662u, 3464734175350698518u, 149506025761u },
+ { 14865830648693666725u, 9334527711335850124u, 144394101141u },
+ { 14754517212823091778u, 7269882896518450105u, 252074403984u },
+ { 11113946551474911901u, 1372511258182263195u, 232410437116u },
+ { 1963520352638130630u, 7571228438575951045u, 252162224104u },
+ { 13342587341404964200u, 2992506536646070405u, 50028434172u },
+ { 6240392545013573291u, 524517896824344605u, 22844752946u },
+ { 14377490861349714758u, 15582941400898702772u, 29642774u },
+ { 1717863312631397839u, 546812681195752981u, 0u },
+ { 3611005143890591770u, 546812681u, 0u },
+ { 1u, 0u, 21208498176u },
+ { 13168252824351245504u, 3846112492507251065u, 138904285205u },
+ { 735883891883379688u, 16681117750123089486u, 227812409738u },
+ { 10609203866866106404u, 14986314536556547266u, 12139521251u },
+ { 12358191111890306470u, 2573712825027107388u, 18406839052u },
+ { 15229916368406413528u, 7504855874008324927u, 135518906642u },
+ { 7241424335568075942u, 9572138030626879786u, 71461906823u },
+ { 6049715868779871913u, 8520676959353394842u, 65729070919u },
+ { 2000548404719336762u, 13448984662897903495u, 150668892225u },
+ { 1410974761895205301u, 12338883700918130647u, 1942u },
+ { 16000132467694084868u, 35835915874844u, 0u },
+ { 16894908866816792556u, 35835u, 0u },
+ { 1u, 0u, 96136462336u },
+ { 589096329272056762u, 2517285787892561599u, 127235208544u },
+ { 7097729792403256904u, 4338831817635138102u, 250084648831u },
+ { 8553736750439287020u, 1561495325934523195u, 183664758778u },
+ { 2114152625261065696u, 12262635050079398785u, 38604121015u },
+ { 9817523680007641224u, 11144065765517284187u, 215065716774u },
+ { 13047215537500048015u, 1212260522471875710u, 63525586135u },
+ { 16755544192002345880u, 9695352922247418868u, 164391777855u },
+ { 6930119832670648356u, 7227025834627242947u, 60520905380u },
+ { 14560698131901886167u, 9609008238705447828u, 127314748u },
+ { 16408020927503338035u, 2348542582773833227u, 0u },
+ { 14274703510609809116u, 2348542582u, 0u },
+ { 1u, 0u, 239195652096u },
+ { 16428432973129962470u, 3609144142396852268u, 54627148527u },
+ { 3721112279790863774u, 11568848377382068864u, 171545803830u },
+ { 18032764903259620753u, 10068303578029323956u, 45631280555u },
+ { 18058455550468776079u, 11645070846862630230u, 167674882605u },
+ { 15692090139033993190u, 12449386705878485054u, 210814540455u },
+ { 389416944300619393u, 15025619323517318417u, 140812947666u },
+ { 12009691357260487293u, 14996237555047131271u, 75553539724u },
+ { 13494259174449809900u, 10211005638256058412u, 90055009355u },
+ { 18288583400616279877u, 1014743503555840529u, 151699359066u },
+ { 7216107869057472u, 12900897707145290677u, 8343u },
+ { 17237061291959073878u, 153914086704665u, 0u },
+ { 1599418782488783273u, 153914u, 0u },
+ { 1u, 0u, 22255763456u },
+ { 9565464987240335777u, 4718003016239473661u, 140805878294u },
+ { 857713933775880687u, 14865830648693666724u, 185799843980u },
+ { 4621617820081363356u, 14754517212823091777u, 155602488249u },
+ { 9630162611715632528u, 11113946551474911900u, 197106442651u },
+ { 9283986497984645815u, 1963520352638130629u, 133723303109u },
+ { 8981807745082630996u, 13342587341404964199u, 29338292357u },
+ { 18350140531565934622u, 6240392545013573290u, 180779405341u },
+ { 4411619033127524143u, 14377490861349714757u, 21093125556u },
+ { 1852297584111266889u, 1717863312631397838u, 9195752981u },
+ { 11746243463811666096u, 3611005143890591769u, 546812681u },
+ { 6335244004343789147u, 10086913586276986678u, 0u },
+ { 5109502367228239844u, 10086913586u, 0u },
+ { 1603272682579847821u, 10u, 0u },
+ { 1u, 0u, 121713852416u },
+ { 6609546910952910052u, 13168252824351245503u, 78039892345u },
+ { 3911171343112928288u, 735883891883379687u, 194575126094u },
+ { 5254510615100863555u, 10609203866866106403u, 60669938882u },
+ { 3881927570803887650u, 12358191111890306469u, 63825615420u },
+ { 6379348759607163190u, 15229916368406413527u, 42392558399u },
+ { 14595733737222406466u, 7241424335568075941u, 154327955754u },
+ { 14670223432002373542u, 6049715868779871912u, 135108449946u },
+ { 4045087795619708513u, 2000548404719336761u, 215076489095u },
+ { 12598467307137142718u, 1410974761895205300u, 28867368919u },
+ { 734704388050777108u, 16000132467694084867u, 251915874844u },
+ { 5682201693687285822u, 16894908866816792555u, 35835u },
+ { 11048712694145438788u, 661055968790248u, 0u },
+ { 17871025777010319485u, 661055u, 0u },
+ { 1u, 0u, 191031934976u },
+ { 15268761435931663695u, 589096329272056761u, 54384768703u },
+ { 5016238054648555438u, 7097729792403256903u, 59463698998u },
+ { 14236047313993899750u, 8553736750439287019u, 129114608443u },
+ { 6957759675154690848u, 2114152625261065695u, 91532209025u },
+ { 18439367135478514473u, 9817523680007641223u, 126707290971u },
+ { 8539004472540641041u, 13047215537500048014u, 244908319870u },
+ { 1908462039431738399u, 16755544192002345879u, 195375682548u },
+ { 714690453250792146u, 6930119832670648355u, 148789337027u },
+ { 13782189447673929633u, 14560698131901886166u, 11889480596u },
+ { 3584742913798803164u, 16408020927503338034u, 118773833227u },
+ { 4347581515245125291u, 14274703510609809115u, 2348542582u },
+ { 16836742268156371392u, 6429475823218628948u, 2u },
+ { 11764082328865615308u, 43322963970u, 0u },
+ { 5957633711383291746u, 43u, 0u },
+ { 1u, 0u, 44890587136u },
+ { 9917186842884466953u, 16428432973129962469u, 128201721900u },
+ { 4751011869809829335u, 3721112279790863773u, 180977558144u },
+ { 11068497969931435029u, 18032764903259620752u, 86978950836u },
+ { 17118056985122509954u, 18058455550468776078u, 62850669910u },
+ { 14607066080907684459u, 15692090139033993189u, 17021110334u },
+ { 11768892370493391107u, 389416944300619392u, 135651046673u },
+ { 4043396447647747170u, 12009691357260487292u, 44731525255u },
+ { 1670341095362518057u, 13494259174449809899u, 17991426092u },
+ { 3190817644167043165u, 18288583400616279876u, 181000391185u },
+ { 10425820027224322486u, 7216107869057471u, 25934422965u },
+ { 13139964660506311565u, 17237061291959073877u, 58086704665u },
+ { 2297772885416059937u, 1599418782488783272u, 153914u },
+ { 7677687919964523763u, 2839213766779714u, 0u },
+ { 14144589152747892828u, 2839213u, 0u },
+ { 1u, 0u, 253518544896u },
+ { 17069730341503660290u, 9565464987240335776u, 164046496765u },
+ { 18167423787163077107u, 857713933775880686u, 65250538404u },
+ { 3765746945827805904u, 4621617820081363355u, 156522052161u },
+ { 10241734342430761691u, 9630162611715632527u, 197503285916u },
+ { 13345717282537140784u, 9283986497984645814u, 103486904773u },
+ { 9313926784816939953u, 8981807745082630995u, 170994763111u },
+ { 550974205049535019u, 18350140531565934621u, 69239154346u },
+ { 4494692285504086222u, 4411619033127524142u, 206100413253u },
+ { 1134308559863725587u, 1852297584111266888u, 25636765134u },
+ { 17587558045116130233u, 11746243463811666095u, 54343434265u },
+ { 9817142032346161594u, 6335244004343789146u, 50276986678u },
+ { 6071944935834172568u, 5109502367228239843u, 10086913586u },
+ { 11564168293299416955u, 1603272682579847820u, 10u },
+ { 12458266507226064437u, 186070713419u, 0u },
+ { 1304432355328256915u, 186u, 0u },
+ { 1u, 0u, 191358304256u },
+ { 15946798815542087355u, 6609546910952910051u, 231212025023u },
+ { 12082566083831286138u, 3911171343112928287u, 35284847591u },
+ { 11449623684706196411u, 5254510615100863554u, 165210439715u },
+ { 17518743620362604446u, 3881927570803887649u, 215345825189u },
+ { 9451061563087633805u, 6379348759607163189u, 165791236311u },
+ { 13191114787623314926u, 14595733737222406465u, 168795274405u },
+ { 8367349876734474799u, 14670223432002373541u, 57219284648u },
+ { 6544253801674393507u, 4045087795619708512u, 180682964281u },
+ { 16113906253336597498u, 12598467307137142717u, 3039828404u },
+ { 10294087136797312392u, 734704388050777107u, 235308032771u },
+ { 9127173070014462803u, 5682201693687285821u, 232598951915u },
+ { 16266900839595484952u, 11048712694145438787u, 63968790248u },
+ { 3299745387370952632u, 17871025777010319484u, 661055u },
+ { 12061115182604399189u, 12194330274671844u, 0u },
+ { 5066801222582989646u, 12194330u, 0u },
+ { 1u, 0u, 185827721216u },
+ { 7568423425299591513u, 15268761435931663694u, 71271930809u },
+ { 16561505984665207377u, 5016238054648555437u, 235771737671u },
+ { 4329114621856906245u, 14236047313993899749u, 223377180907u },
+ { 1477500474861899139u, 6957759675154690847u, 135999600095u },
+ { 16891579639263969684u, 18439367135478514472u, 142462900359u },
+ { 4684451357140027420u, 8539004472540641040u, 151103457934u },
+ { 14727186580409080709u, 1908462039431738398u, 35038743447u },
+ { 15864176859687308834u, 714690453250792145u, 214747133987u },
+ { 1755486942842684438u, 13782189447673929632u, 50194329302u },
+ { 17417077516652710041u, 3584742913798803163u, 219235682866u },
+ { 4290982361913532783u, 4347581515245125290u, 84912721627u },
+ { 11826659981004351409u, 16836742268156371391u, 2637732180u },
+ { 932930645678090820u, 11764082328865615307u, 43322963970u },
+ { 12707792781328052617u, 5957633711383291745u, 43u },
+ { 16491596426880311906u, 799167628880u, 0u },
+ { 3092207065214166010u, 799u, 0u },
+ { 1u, 0u, 229537611776u },
+ { 8142946531605512550u, 9917186842884466952u, 157257552869u },
+ { 5328402096432654515u, 4751011869809829334u, 144600024477u },
+ { 1932004361303814512u, 11068497969931435028u, 142927971728u },
+ { 2511477647985517771u, 17118056985122509953u, 229791850638u },
+ { 17451375493324716694u, 14607066080907684458u, 128637992933u },
+ { 9489266854478998489u, 11768892370493391106u, 124219192960u },
+ { 8803053132063235169u, 4043396447647747169u, 235090549372u },
+ { 16198682197142616773u, 1670341095362518056u, 68172974571u },
+ { 13696242485403414202u, 3190817644167043164u, 191565184836u },
+ { 16409082426079859931u, 10425820027224322485u, 85712318911u },
+ { 11653410736879597610u, 13139964660506311564u, 168124562517u },
+ { 13589514120653213261u, 2297772885416059936u, 66416208296u },
+ { 8032934885905905774u, 7677687919964523762u, 173766779714u },
+ { 2753021350129449273u, 14144589152747892827u, 2839213u },
+ { 16974897459201404133u, 52374249726338269u, 0u },
+ { 13398576176159101589u, 52374249u, 0u },
+ { 1u, 0u, 160925351936u },
+ { 10284586955251725351u, 17069730341503660289u, 238984858016u },
+ { 5294476488634150891u, 18167423787163077106u, 155204141550u },
+ { 15833244538135063323u, 3765746945827805903u, 143555205531u },
+ { 10348512742273116664u, 10241734342430761690u, 182723472783u },
+ { 13658504610142595663u, 13345717282537140783u, 83504908982u },
+ { 11956362239240850266u, 9313926784816939952u, 29029868371u },
+ { 13415901703662731781u, 550974205049535018u, 46243657757u },
+ { 5161774027546852762u, 4494692285504086221u, 72061490990u },
+ { 15274384838790587711u, 1134308559863725586u, 175953423432u },
+ { 14233354597679374929u, 17587558045116130232u, 90532188335u },
+ { 4274656492162486921u, 9817142032346161593u, 227329160794u },
+ { 12040276505541795046u, 6071944935834172567u, 140626894819u },
+ { 13238307206256765457u, 11564168293299416954u, 75675363980u },
+ { 12850161204172713271u, 12458266507226064436u, 186070713419u },
+ { 17531777095001445154u, 1304432355328256914u, 186u },
+ { 5623628114515245990u, 3432398830065u, 0u },
+ { 7357116143579573377u, 3432u, 0u },
+ { 1u, 0u, 227864477696u },
+ { 3555734177475596582u, 15946798815542087354u, 31654997219u },
+ { 14001876724756424382u, 12082566083831286137u, 66620685343u },
+ { 18159905057231476140u, 11449623684706196410u, 33949692994u },
+ { 5585207679308509467u, 17518743620362604445u, 53512343073u },
+ { 13948697622866724672u, 9451061563087633804u, 65715091765u },
+ { 9807691927739036432u, 13191114787623314925u, 165453594945u },
+ { 15818010096140820918u, 8367349876734474798u, 96354764709u },
+ { 5629845624785010943u, 6544253801674393506u, 189873536608u },
+ { 9517635131137734707u, 16113906253336597497u, 19558043581u },
+ { 619338244618780585u, 10294087136797312391u, 61494785043u },
+ { 11632367007491958899u, 9127173070014462802u, 67881830461u },
+ { 12083314261009739916u, 16266900839595484951u, 124178879555u },
+ { 16880538609458881650u, 3299745387370952631u, 228653834364u },
+ { 17404223674486504228u, 12061115182604399188u, 26274671844u },
+ { 7089067015287185433u, 5066801222582989645u, 12194330u },
+ { 2592264228029443648u, 224945689727159819u, 0u },
+ { 13413731084370224440u, 224945689u, 0u },
+ { 1u, 0u, 78410285056u },
+ { 9323915941641553425u, 7568423425299591512u, 173897801038u },
+ { 12155831029092699564u, 16561505984665207376u, 229234681773u },
+ { 17397171276588232676u, 4329114621856906244u, 31080095461u },
+ { 11874560617553253769u, 1477500474861899138u, 40915694367u },
+ { 13444839516837727954u, 16891579639263969683u, 16253944616u },
+ { 16994416043584590671u, 4684451357140027419u, 30798362384u },
+ { 15879694502877015730u, 14727186580409080708u, 209859998750u },
+ { 4234647645735263359u, 15864176859687308833u, 160095165137u },
+ { 7978589901512919496u, 1755486942842684437u, 219944181664u },
+ { 6114237175390859894u, 17417077516652710040u, 170232614619u },
+ { 8658612872088282708u, 4290982361913532782u, 191641124522u },
+ { 10253813330683324853u, 11826659981004351408u, 203050574271u },
+ { 13289465061747830991u, 932930645678090819u, 97688890827u },
+ { 4123165538545565412u, 12707792781328052616u, 80894011233u },
+ { 7846417485927038481u, 16491596426880311905u, 31167628880u },
+ { 10562273346358018864u, 3092207065214166009u, 799u },
+ { 2691512658346619120u, 14742040721959u, 0u },
+ { 751187558544605998u, 14742u, 0u },
+ { 1u, 0u, 8441430016u },
+ { 3757709791947931308u, 8142946531605512549u, 214288853256u },
+ { 3452755398462519465u, 5328402096432654514u, 20104734166u },
+ { 3105818720159874523u, 1932004361303814511u, 129136147476u },
+ { 16859138458894499364u, 2511477647985517770u, 106946040961u },
+ { 12271894740606233755u, 17451375493324716693u, 2514414186u },
+ { 5429638071845793701u, 9489266854478998488u, 97477214466u },
+ { 145278150038876889u, 8803053132063235168u, 40878132321u },
+ { 9050266019724932450u, 16198682197142616772u, 92742474792u },
+ { 11907016253451490866u, 13696242485403414201u, 181889538140u },
+ { 2472757296513770735u, 16409082426079859930u, 140631732661u },
+ { 10558733798178239360u, 11653410736879597609u, 32736689036u },
+ { 15917322570831255850u, 13589514120653213260u, 242435466272u },
+ { 12254334656791355238u, 8032934885905905773u, 91149241586u },
+ { 7869542424662730262u, 2753021350129449272u, 221920211035u },
+ { 1378558986933000253u, 16974897459201404132u, 233726338269u },
+ { 13521405041909411105u, 13398576176159101588u, 52374249u },
+ { 3206744593298092012u, 966134380754314586u, 0u },
+ { 13914648122214918505u, 966134380u, 0u },
+ { 1u, 0u, 1557528576u },
+ { 1235541077112082496u, 10284586955251725350u, 242287014145u },
+ { 12014985518315533846u, 5294476488634150890u, 207858321906u },
+ { 1561535086344155741u, 15833244538135063322u, 218560993999u },
+ { 12761747276316224577u, 10348512742273116663u, 47740429018u },
+ { 9745594781103966137u, 13658504610142595662u, 176648155695u },
+ { 17514238702394846785u, 11956362239240850265u, 42727277488u },
+ { 2428898913707151713u, 13415901703662731780u, 205279820330u },
+ { 71666709959904945u, 5161774027546852761u, 18828026061u },
+ { 4049380135452919193u, 15274384838790587710u, 184771591698u },
+ { 18422240861777453733u, 14233354597679374928u, 185231729592u },
+ { 2914504416394425696u, 4274656492162486920u, 151652704697u },
+ { 12721377795748989418u, 12040276505541795045u, 122717650071u },
+ { 2626074459217717422u, 13238307206256765456u, 52696608634u },
+ { 4261529925046307655u, 12850161204172713270u, 146950399540u },
+ { 11536038685430305586u, 17531777095001445153u, 241304857490u },
+ { 12555757789435162768u, 5623628114515245989u, 104398830065u },
+ { 11905178684546080059u, 7357116143579573376u, 3432u },
+ { 14032797718924543051u, 63316582777114u, 0u },
+ { 10750340288005853484u, 63316u, 0u },
+ { 1u, 0u, 186192756736u },
+ { 9660290106216358253u, 3555734177475596581u, 121759043258u },
+ { 14820142034615351103u, 14001876724756424381u, 186984450425u },
+ { 12674041783707777619u, 18159905057231476139u, 157302774714u },
+ { 15386686816442679994u, 5585207679308509466u, 140756160413u },
+ { 5679510383719146248u, 13948697622866724671u, 237531676044u },
+ { 1391101719248678506u, 9807691927739036431u, 46857496045u },
+ { 3364596672173710517u, 15818010096140820917u, 162305194542u },
+ { 11276509210104319732u, 5629845624785010942u, 249515952034u },
+ { 5316312656902630164u, 9517635131137734706u, 135033574393u },
+ { 17470981304473644647u, 619338244618780584u, 82630591879u },
+ { 7373293636384920591u, 11632367007491958898u, 23655037778u },
+ { 7616810902585191937u, 12083314261009739915u, 183915095831u },
+ { 12740295655921903924u, 16880538609458881649u, 84943484855u },
+ { 18366635945916526940u, 17404223674486504227u, 77384299092u },
+ { 4472171448243407067u, 7089067015287185432u, 11140526925u },
+ { 229592460858185629u, 2592264228029443647u, 25727159819u },
+ { 12749672866417114996u, 13413731084370224439u, 224945689u },
+ { 9452256722867098693u, 4149515568880992958u, 0u },
+ { 16251451636418604634u, 4149515568u, 0u },
+ { 1u, 0u, 88505450496u },
+ { 4515791283442995454u, 9323915941641553424u, 80658968920u },
+ { 13306155670047701346u, 12155831029092699563u, 4943102544u },
+ { 4456930152933417601u, 17397171276588232675u, 130643721220u },
+ { 9089157128546489637u, 11874560617553253768u, 147728846210u },
+ { 12437332180345515840u, 13444839516837727953u, 27921269139u },
+ { 3433060408790452524u, 16994416043584590670u, 132860839963u },
+ { 8275594526021936172u, 15879694502877015729u, 33229560708u },
+ { 3846512444641107689u, 4234647645735263358u, 21432520225u },
+ { 6210962618469046250u, 7978589901512919495u, 152331453461u },
+ { 7272858906616296575u, 6114237175390859893u, 110469384344u },
+ { 3710743300451225347u, 8658612872088282707u, 176555860334u },
+ { 6424677242672030600u, 10253813330683324852u, 67720423344u },
+ { 11485842256170301862u, 13289465061747830990u, 136223517251u },
+ { 7355797963557024308u, 4123165538545565411u, 97425355144u },
+ { 6358188982569427273u, 7846417485927038480u, 249572581985u },
+ { 12475094728768767402u, 10562273346358018863u, 39145907193u },
+ { 17288154837907896183u, 2691512658346619119u, 150040721959u },
+ { 2983850577727105262u, 751187558544605997u, 14742u },
+ { 13918604635001185935u, 271942652322184u, 0u },
+ { 12033220395769876327u, 271942u, 0u },
+ { 1u, 0u, 101203705856u },
+ { 5782377197813462997u, 3757709791947931307u, 178187174245u },
+ { 17732139848231399226u, 3452755398462519464u, 111168366770u },
+ { 3628839527415562921u, 3105818720159874522u, 202913935727u },
+ { 3188692267613601004u, 16859138458894499363u, 149665260746u },
+ { 5168130193478377352u, 12271894740606233754u, 216294341269u },
+ { 12556227529405091290u, 5429638071845793700u, 96007875544u },
+ { 15087090312791441192u, 145278150038876888u, 196490615904u },
+ { 10281804758610642494u, 9050266019724932449u, 185645480644u },
+ { 14238177586158586580u, 11907016253451490865u, 218134048441u },
+ { 7107927498217678128u, 2472757296513770734u, 41572390106u },
+ { 3845814658485364450u, 10558733798178239359u, 76862879785u },
+ { 714293333681725946u, 15917322570831255849u, 109664308812u },
+ { 16766172658649116982u, 12254334656791355237u, 56426608749u },
+ { 812461421432632215u, 7869542424662730261u, 228074731832u },
+ { 15218024718633799196u, 1378558986933000252u, 148732996836u },
+ { 8110797782612805146u, 13521405041909411104u, 90173837972u },
+ { 15941193964933529227u, 3206744593298092011u, 108754314586u },
+ { 14144280602323277933u, 13914648122214918504u, 966134380u },
+ { 15072402647813125245u, 17822033662586700072u, 0u },
+ { 10822706091283369889u, 17822033662u, 0u },
+ { 15163844593710966731u, 17u, 0u },
+ { 1u, 0u, 38066978816u },
+ { 2408529687792073670u, 1235541077112082495u, 234651333670u },
+ { 3980682212356510808u, 12014985518315533845u, 26084650986u },
+ { 4202670442792148519u, 1561535086344155740u, 247691815706u },
+ { 9419583343154651922u, 12761747276316224576u, 78528309751u },
+ { 16359166491570434575u, 9745594781103966136u, 89949448782u },
+ { 12567727056384237385u, 17514238702394846784u, 4131670873u },
+ { 2068388267923286639u, 2428898913707151712u, 153003885060u },
+ { 5689135844565021196u, 71666709959904944u, 62219517337u },
+ { 3104061965171139313u, 4049380135452919192u, 80998671678u },
+ { 7955173880156328016u, 18422240861777453732u, 136157995600u },
+ { 1445179403240833754u, 2914504416394425695u, 229689627272u },
+ { 12538201164459126715u, 12721377795748989417u, 16142359781u },
+ { 7580606719088482667u, 2626074459217717421u, 54231018000u },
+ { 8168318283218819755u, 4261529925046307654u, 33625369910u },
+ { 5249615277755961676u, 11536038685430305585u, 165680648993u },
+ { 6312997372068219831u, 12555757789435162767u, 128645381029u },
+ { 9183815417025176703u, 11905178684546080058u, 26760719488u },
+ { 10683849953373876937u, 14032797718924543050u, 84582777114u },
+ { 17175012155615667568u, 10750340288005853483u, 63316u },
+ { 18003508288378896912u, 1167984798111281u, 0u },
+ { 14722554560950996951u, 1167984u, 0u },
+ { 1u, 0u, 37523685376u },
+ { 15059324482416394930u, 9660290106216358252u, 189803401509u },
+ { 4134778595813308312u, 14820142034615351102u, 171687061181u },
+ { 16321118342639660948u, 12674041783707777618u, 26834113963u },
+ { 1523550293123468805u, 15386686816442679993u, 63307886874u },
+ { 8016371634569878509u, 5679510383719146247u, 15075411775u },
+ { 9884220139611134110u, 1391101719248678505u, 181182395151u },
+ { 7218073002727840414u, 3364596672173710516u, 254611300789u },
+ { 16062235669481359233u, 11276509210104319731u, 50288197886u },
+ { 15558048660560338002u, 5316312656902630163u, 168947103794u },
+ { 8394398745765058609u, 17470981304473644646u, 114399707048u },
+ { 5693296366442904274u, 7373293636384920590u, 139412908146u },
+ { 11783494675061161358u, 7616810902585191936u, 113690652811u },
+ { 13377293110865447894u, 12740295655921903923u, 35995657329u },
+ { 12840734051093062130u, 18366635945916526939u, 24242436899u },
+ { 7009868331566697505u, 4472171448243407066u, 63012446232u },
+ { 5019690705031194477u, 229592460858185628u, 55691161151u },
+ { 8608277240439804984u, 12749672866417114995u, 190512407863u },
+ { 12172482590657749222u, 9452256722867098692u, 48880992958u },
+ { 16613484892678771990u, 16251451636418604633u, 4149515568u },
+ { 5721488662757049244u, 2758075434182769113u, 4u },
+ { 386931106438877039u, 76545051729u, 0u },
+ { 10054429752182825659u, 76u, 0u },
+ { 1u, 0u, 16244801536u },
+ { 8634592106137071313u, 4515791283442995453u, 171721328144u },
+ { 12626356501369830731u, 13306155670047701345u, 227241610667u },
+ { 4803333258178976933u, 4456930152933417600u, 136492724195u },
+ { 13613083223558209297u, 9089157128546489636u, 209674229128u },
+ { 16106967997237446989u, 12437332180345515839u, 78186106577u },
+ { 14832921244380020170u, 3433060408790452523u, 177448620878u },
+ { 13774024637717231397u, 8275594526021936171u, 126208519857u },
+ { 9673012968505228885u, 3846512444641107688u, 199336696958u },
+ { 5391832334264815667u, 6210962618469046249u, 117394262471u },
+ { 16514436292632703088u, 7272858906616296574u, 83201159797u },
+ { 12025036352783454153u, 3710743300451225346u, 180348282451u },
+ { 7059867105311401050u, 6424677242672030599u, 206622648756u },
+ { 12769210631552594670u, 11485842256170301861u, 227398758606u },
+ { 8328873878884556145u, 7355797963557024307u, 16344678115u },
+ { 1016565892414238685u, 6358188982569427272u, 47676276240u },
+ { 9662978461927250281u, 12475094728768767401u, 239937192751u },
+ { 13729967277551868112u, 17288154837907896182u, 45161754863u },
+ { 6371593776693359475u, 2983850577727105261u, 136754529069u },
+ { 17617208110845643245u, 13918604635001185934u, 70652322184u },
+ { 14960960225633086797u, 12033220395769876326u, 271942u },
+ { 12090634301321662558u, 5016456510113118u, 0u },
+ { 9409926148478635503u, 5016456u, 0u },
+ { 1u, 0u, 171313463296u },
+ { 4307062684900157136u, 5782377197813462996u, 168961261227u },
+ { 15300759383869911853u, 17732139848231399225u, 218196719784u },
+ { 16007534237643445447u, 3628839527415562920u, 35172859354u },
+ { 7138502295759677634u, 3188692267613601003u, 154280164899u },
+ { 8218537071653683708u, 5168130193478377351u, 164680674458u },
+ { 2254219416760329296u, 12556227529405091289u, 216817872804u },
+ { 3057410459568460683u, 15087090312791441191u, 97557377752u },
+ { 8217810929938874370u, 10281804758610642493u, 49771853153u },
+ { 11741126472498340929u, 14238177586158586579u, 238385321521u },
+ { 1175325363726654805u, 7107927498217678127u, 127208482030u },
+ { 9428843070696730900u, 3845814658485364449u, 41038721919u },
+ { 12662500978715131896u, 714293333681725945u, 101908896041u },
+ { 6443045597035184564u, 16766172658649116981u, 21044043621u },
+ { 1921385512639171183u, 812461421432632214u, 60824970773u },
+ { 10469475094355551399u, 15218024718633799195u, 32439687228u },
+ { 14679174489076953574u, 8110797782612805145u, 235864173856u },
+ { 11853074234719825644u, 15941193964933529226u, 104766762987u },
+ { 8270896886596139124u, 14144280602323277932u, 40817076584u },
+ { 16532667046659118126u, 15072402647813125244u, 254586700072u },
+ { 148341279888833483u, 10822706091283369888u, 17822033662u },
+ { 10364629296397276041u, 15163844593710966730u, 17u },
+ { 14265682585545771671u, 328758493846u, 0u },
+ { 13991741872911347878u, 328u, 0u },
+ { 1u, 0u, 63130566656u },
+ { 14029045786848724433u, 2408529687792073669u, 21215793215u },
+ { 4005878521026842341u, 3980682212356510807u, 92227827221u },
+ { 3428326338640386488u, 4202670442792148518u, 64510636636u },
+ { 1010001558294829380u, 9419583343154651921u, 184886832192u },
+ { 2012063724327403418u, 16359166491570434574u, 64681297848u },
+ { 10997154538851372612u, 12567727056384237384u, 96112127552u },
+ { 1917749645489607898u, 2068388267923286638u, 176308408672u },
+ { 9763872523711218805u, 5689135844565021195u, 152168271536u },
+ { 15875699078454059311u, 3104061965171139312u, 164431250840u },
+ { 10966529452671276106u, 7955173880156328015u, 95078343332u },
+ { 18073244132105736913u, 1445179403240833753u, 233679697247u },
+ { 4435241176994913173u, 12538201164459126714u, 173410945513u },
+ { 5464400086219074323u, 7580606719088482666u, 70442805421u },
+ { 2445909179323258812u, 8168318283218819754u, 49284582214u },
+ { 873962058644121211u, 5249615277755961675u, 143342228273u },
+ { 16675872194112650857u, 6312997372068219830u, 58497855631u },
+ { 10680102689274800355u, 9183815417025176702u, 74579172666u },
+ { 2370498083108897524u, 10683849953373876936u, 43931059274u },
+ { 15354400521451334666u, 17175012155615667567u, 49975972139u },
+ { 259991949657381021u, 18003508288378896911u, 112798111281u },
+ { 10335286558772966917u, 14722554560950996950u, 1167984u },
+ { 16337526653906757263u, 21545516652742137u, 0u },
+ { 12040967163702784894u, 21545516u, 0u },
+ { 1u, 0u, 108816367616u },
+ { 3373309160242342187u, 15059324482416394929u, 62224146796u },
+ { 13639841054510584221u, 4134778595813308311u, 82884769598u },
+ { 15898855427739708031u, 16321118342639660947u, 185082591826u },
+ { 4544387940067005419u, 1523550293123468804u, 7434568377u },
+ { 5281598644835398575u, 8016371634569878508u, 105535824647u },
+ { 13675642405083408835u, 9884220139611134109u, 180391292521u },
+ { 3973392623768015721u, 7218073002727840413u, 243870735540u },
+ { 4491285101509114191u, 16062235669481359232u, 19843403507u },
+ { 15002304272810270500u, 15558048660560338001u, 102455061267u },
+ { 17325098540619893468u, 8394398745765058608u, 14308634214u },
+ { 1137212864974584822u, 5693296366442904273u, 638784526u },
+ { 2619406097224859078u, 11783494675061161357u, 51725184512u },
+ { 8281347529729293732u, 13377293110865447893u, 91696097587u },
+ { 11344719666795450104u, 12840734051093062129u, 218380005723u },
+ { 17283870506679425783u, 7009868331566697504u, 156272117978u },
+ { 11054210518010603775u, 5019690705031194476u, 115466655644u },
+ { 6399455551799092885u, 8608277240439804983u, 68659871603u },
+ { 12930529916573967170u, 12172482590657749221u, 89900618820u },
+ { 14550097052337552404u, 16613484892678771989u, 217310162521u },
+ { 12487632712206414748u, 5721488662757049243u, 81020975577u },
+ { 5791017277843595715u, 386931106438877038u, 76545051729u },
+ { 10227264183449036113u, 10054429752182825658u, 76u },
+ { 2006055278511721441u, 1412006979354u, 0u },
+ { 128746359043876333u, 1412u, 0u },
+ { 1u, 0u, 253468082176u },
+ { 7408146306870995754u, 8634592106137071312u, 97684476157u },
+ { 8299024588195267962u, 12626356501369830730u, 128260389217u },
+ { 1497052939192040881u, 4803333258178976932u, 36737966720u },
+ { 16771714264265803747u, 13613083223558209296u, 63873160484u },
+ { 142988846654429432u, 16106967997237446988u, 43804094271u },
+ { 11839838367716104145u, 14832921244380020169u, 43746691371u },
+ { 6019646776647679765u, 13774024637717231396u, 232524375083u },
+ { 4611972391702034948u, 9673012968505228884u, 233292291816u },
+ { 16447182322205429545u, 5391832334264815666u, 126895249385u },
+ { 2113477168726764245u, 16514436292632703087u, 2651878526u },
+ { 3536261187802311516u, 12025036352783454152u, 135382716162u },
+ { 18444381860986709854u, 7059867105311401049u, 165692220295u },
+ { 4734315730275909838u, 12769210631552594669u, 51451509157u },
+ { 9974936316849658174u, 8328873878884556144u, 72055108147u },
+ { 11864423681540657642u, 1016565892414238684u, 169523831112u },
+ { 8207245621417902667u, 9662978461927250280u, 118744303017u },
+ { 7992526918695295028u, 13729967277551868111u, 237345404790u },
+ { 8679354522130259987u, 6371593776693359474u, 142955030765u },
+ { 6065763799692166461u, 17617208110845643244u, 102811035278u },
+ { 18143341109049024976u, 14960960225633086796u, 94655434598u },
+ { 15242492331283350570u, 12090634301321662557u, 136510113118u },
+ { 9986352353182266963u, 9409926148478635502u, 5016456u },
+ { 17340463289911536077u, 92537289398950870u, 0u },
+ { 7359344614214233035u, 92537289u, 0u },
+ { 1u, 0u, 212233486336u },
+ { 419091135888749535u, 4307062684900157135u, 57829455828u },
+ { 1073142712661309790u, 15300759383869911852u, 168867770169u },
+ { 11076438902195672286u, 16007534237643445446u, 235386978984u },
+ { 1820390940081322073u, 7138502295759677633u, 135445527787u },
+ { 18417808973944523597u, 8218537071653683707u, 217122201479u },
+ { 10251294197731582957u, 2254219416760329295u, 39165742553u },
+ { 1502394029870156428u, 3057410459568460682u, 61445488423u },
+ { 321014853559106075u, 8217810929938874369u, 211636487741u },
+ { 2390953058510591778u, 11741126472498340928u, 47063714515u },
+ { 10685224265907994087u, 1175325363726654804u, 225511138607u },
+ { 5967405799190505023u, 9428843070696730899u, 249686435553u },
+ { 11210723659228214761u, 12662500978715131895u, 53349278201u },
+ { 12327123641078462773u, 6443045597035184563u, 150104158517u },
+ { 1709976940107894237u, 1921385512639171182u, 27567551382u },
+ { 16607686590938553511u, 10469475094355551398u, 25795759643u },
+ { 18332088094272679457u, 14679174489076953573u, 138642556441u },
+ { 2946170632136780882u, 11853074234719825643u, 108448366218u },
+ { 4824449494694383419u, 8270896886596139123u, 124896237676u },
+ { 17008332258693407134u, 16532667046659118125u, 160008041596u },
+ { 1773419466622750661u, 148341279888833482u, 202561867680u },
+ { 3892343466023784379u, 10364629296397276040u, 150773344202u },
+ { 12001571085575422796u, 14265682585545771670u, 72758493846u },
+ { 12933506765500977582u, 13991741872911347877u, 328u },
+ { 11884830007749143734u, 6064523798049u, 0u },
+ { 9662368568096205337u, 6064u, 0u },
+ { 1u, 0u, 197760516096u },
+ { 16801499925276664442u, 14029045786848724432u, 87217159109u },
+ { 10492407990787637084u, 4005878521026842340u, 38185849943u },
+ { 7673849751013230269u, 3428326338640386487u, 17054752294u },
+ { 6046724489853072367u, 1010001558294829379u, 14109074193u },
+ { 3723941391207507903u, 2012063724327403417u, 72596156942u },
+ { 16844122108860347659u, 10997154538851372611u, 110103961416u },
+ { 10622020182694668027u, 1917749645489607897u, 11529300590u },
+ { 8741198820686854862u, 9763872523711218804u, 240860623371u },
+ { 6855480461211306807u, 15875699078454059310u, 79594496752u },
+ { 10005708458011566304u, 10966529452671276105u, 217979752527u },
+ { 8932093106442919061u, 18073244132105736912u, 186240434905u },
+ { 9062763476260756743u, 4435241176994913172u, 106296225722u },
+ { 13664977682032775521u, 5464400086219074322u, 170132593002u },
+ { 1078499125430623453u, 2445909179323258811u, 75047377578u },
+ { 6554586738078431161u, 873962058644121210u, 182904000843u },
+ { 12177313698643242883u, 16675872194112650856u, 126578969526u },
+ { 16615072271904633953u, 10680102689274800354u, 200128504958u },
+ { 16375404983106569285u, 2370498083108897523u, 111832363720u },
+ { 13552251831473522729u, 15354400521451334665u, 15014094191u },
+ { 8330500218412111874u, 259991949657381020u, 214560277007u },
+ { 7044338079053294004u, 10335286558772966916u, 249885659094u },
+ { 2688849443046530184u, 16337526653906757262u, 44652742137u },
+ { 855940991879596845u, 12040967163702784893u, 21545516u },
+ { 7344363609485825662u, 397444631628981487u, 0u },
+ { 11602660525134634992u, 397444631u, 0u },
+ { 1u, 0u, 177182867456u },
+ { 16945343208344873835u, 3373309160242342186u, 151739417265u },
+ { 9617992661337889145u, 13639841054510584220u, 147861878679u },
+ { 18280344933262742088u, 15898855427739708030u, 4246351763u },
+ { 5179975582362777795u, 4544387940067005418u, 236286316036u },
+ { 1798918997870037130u, 5281598644835398574u, 157741358060u },
+ { 6327667344756325883u, 13675642405083408834u, 157215398045u },
+ { 18380327574124007701u, 3973392623768015720u, 128243473053u },
+ { 18015447557304295289u, 4491285101509114190u, 81813276544u },
+ { 10315590748073249878u, 15002304272810270499u, 48939195473u },
+ { 7697916092577993382u, 17325098540619893467u, 209061648432u },
+ { 3124132817942110723u, 1137212864974584821u, 141141998289u },
+ { 7448238998520507049u, 2619406097224859077u, 213448932749u },
+ { 13892823322374205297u, 8281347529729293731u, 241614998485u },
+ { 11042137840046332564u, 11344719666795450103u, 32936960497u },
+ { 10513966307445593804u, 17283870506679425782u, 108599249952u },
+ { 9388437460943526958u, 11054210518010603774u, 55346915180u },
+ { 10967228614677896228u, 6399455551799092884u, 229700965431u },
+ { 2310996671540235542u, 12930529916573967169u, 21788762341u },
+ { 4989110555003898587u, 14550097052337552403u, 155676955925u },
+ { 16271452421983657679u, 12487632712206414747u, 110313931675u },
+ { 9523160181437090473u, 5791017277843595714u, 186554421102u },
+ { 13137707423765072250u, 10227264183449036112u, 26108748474u },
+ { 16846859744221860705u, 2006055278511721440u, 132006979354u },
+ { 7767140033449795569u, 128746359043876332u, 1412u },
+ { 17169456915721160017u, 26046931378436u, 0u },
+ { 17180899661833327819u, 26046u, 0u },
+ { 1u, 0u, 208401596416u },
+ { 17572520700934791416u, 7408146306870995753u, 74449891024u },
+ { 17968798858233825417u, 8299024588195267961u, 164081155402u },
+ { 15338423313945305609u, 1497052939192040880u, 16909196452u },
+ { 17895321323836726301u, 16771714264265803746u, 76007751440u },
+ { 814069333008965773u, 142988846654429431u, 201641838924u },
+ { 7200328959852723947u, 11839838367716104144u, 36326325705u },
+ { 759884557248133773u, 6019646776647679764u, 84250015524u },
+ { 13410165861863974851u, 4611972391702034947u, 50891603540u },
+ { 6278452420856351570u, 16447182322205429544u, 111114571826u },
+ { 9072115382556676442u, 2113477168726764244u, 200191701103u },
+ { 2755882551854926563u, 3536261187802311515u, 89999871944u },
+ { 8496072611504649269u, 18444381860986709853u, 237256647769u },
+ { 4122009033579215815u, 4734315730275909837u, 112540742381u },
+ { 10222217724450527221u, 9974936316849658173u, 220643171696u },
+ { 2064539481554006325u, 11864423681540657641u, 104444915676u },
+ { 7935605886598063693u, 8207245621417902666u, 207433275752u },
+ { 7805147585347548429u, 7992526918695295027u, 114470508751u },
+ { 5709020905457661273u, 8679354522130259986u, 236328825714u },
+ { 16257370307404906674u, 6065763799692166460u, 76983552492u },
+ { 14971258192939373646u, 18143341109049024975u, 93826297164u },
+ { 1133404845901376390u, 15242492331283350569u, 238541361245u },
+ { 9460827548162822047u, 9986352353182266962u, 214940028398u },
+ { 1273897659779791346u, 17340463289911536076u, 201398950870u },
+ { 7833262224435092783u, 7359344614214233034u, 92537289u },
+ { 3033420566713364587u, 1707011694817242694u, 0u },
+ { 15075466825360349103u, 1707011694u, 0u },
+ { 1u, 0u, 207022718976u },
+ { 2484134775182816690u, 419091135888749534u, 44058175183u },
+ { 18400539815335991277u, 1073142712661309789u, 198600454956u },
+ { 485494064952118286u, 11076438902195672285u, 193098683590u },
+ { 17577048805241314891u, 1820390940081322072u, 251998431425u },
+ { 2863946907557583807u, 18417808973944523596u, 79555723771u },
+ { 13045307417786230800u, 10251294197731582956u, 138081444943u },
+ { 12032088871615097766u, 1502394029870156427u, 1017402250u },
+ { 8848763446997690580u, 321014853559106074u, 64129613825u },
+ { 10031289150307672684u, 2390953058510591777u, 84579247168u },
+ { 11592215575498656563u, 10685224265907994086u, 19323493716u },
+ { 15894436747956898388u, 5967405799190505022u, 247607734547u },
+ { 2091546719588500923u, 11210723659228214760u, 179668254711u },
+ { 5863809244813756109u, 12327123641078462772u, 110092698035u },
+ { 11303008753675411245u, 1709976940107894236u, 166900304494u },
+ { 13238426537506910532u, 16607686590938553510u, 229993784486u },
+ { 17258458071023005565u, 18332088094272679456u, 235159712229u },
+ { 8385733444777075179u, 2946170632136780881u, 115261533931u },
+ { 9530757096163247300u, 4824449494694383418u, 45922023539u },
+ { 14423000845391072217u, 17008332258693407133u, 202096137261u },
+ { 10953140011159884311u, 1773419466622750660u, 136211004362u },
+ { 12228340237948264127u, 3892343466023784378u, 150650606472u },
+ { 11279134946966259189u, 12001571085575422795u, 165701126806u },
+ { 14640097792684582651u, 12933506765500977581u, 33644277925u },
+ { 6232313315128656728u, 11884830007749143733u, 176523798049u },
+ { 16136121832933322088u, 9662368568096205336u, 6064u },
+ { 15074767079673358271u, 111870718431542u, 0u },
+ { 13252722804829281908u, 111870u, 0u },
+ { 1u, 0u, 208910811136u },
+ { 7740175894281560509u, 16801499925276664441u, 228568794576u },
+ { 15670495392425593226u, 10492407990787637083u, 183416000228u },
+ { 15152257626756992778u, 7673849751013230268u, 67327793591u },
+ { 4090073428152440422u, 6046724489853072366u, 153201875267u },
+ { 14450327772834205584u, 3723941391207507902u, 67913121689u },
+ { 4466091895542494216u, 16844122108860347658u, 217575820867u },
+ { 10454115378553795377u, 10622020182694668026u, 116473861337u },
+ { 2267817233475657788u, 8741198820686854861u, 46371636340u },
+ { 5500455702636497521u, 6855480461211306806u, 73542410542u },
+ { 15178768299492252549u, 10005708458011566303u, 208484209737u },
+ { 7062359872332045590u, 8932093106442919060u, 148491293392u },
+ { 12297347290027942576u, 9062763476260756742u, 18740779924u },
+ { 8030124596941085588u, 13664977682032775520u, 187058465554u },
+ { 6526656990996654843u, 1078499125430623452u, 122355324859u },
+ { 6254287345256979850u, 6554586738078431160u, 104660133498u },
+ { 6642007136244870032u, 12177313698643242882u, 226900704872u },
+ { 2027592955437164718u, 16615072271904633952u, 243887712482u },
+ { 942718349157325567u, 16375404983106569284u, 9734669043u },
+ { 14617066671884002278u, 13552251831473522728u, 156451597321u },
+ { 6831631114396133348u, 8330500218412111873u, 4381874332u },
+ { 14603040013386939258u, 7044338079053294003u, 142145762820u },
+ { 9906106765319401103u, 2688849443046530183u, 125046400654u },
+ { 1396179595609933063u, 855940991879596844u, 239398138749u },
+ { 11524884268464976417u, 7344363609485825661u, 23628981487u },
+ { 382929570730827274u, 11602660525134634991u, 397444631u },
+ { 6109721884461301381u, 7331559403129590068u, 0u },
+ { 2390514825000339691u, 7331559403u, 0u },
+ { 6116191454763441755u, 7u, 0u },
+ { 1u, 0u, 42918608896u },
+ { 11598868771099176310u, 16945343208344873834u, 156521392426u },
+ { 14449966445520085105u, 9617992661337889144u, 126990979484u },
+ { 11675595287405614726u, 18280344933262742087u, 234280807038u },
+ { 15860796398550489897u, 5179975582362777794u, 174097519594u },
+ { 16180408435245829662u, 1798918997870037129u, 194343023534u },
+ { 13756992797154950706u, 6327667344756325882u, 104996399554u },
+ { 8830551328786758466u, 18380327574124007700u, 78976619368u },
+ { 16699955256560951264u, 18015447557304295288u, 35559209294u },
+ { 10038983627153402074u, 10315590748073249877u, 219417304867u },
+ { 15085100736692127346u, 7697916092577993381u, 245169359579u },
+ { 10007783780289711125u, 3124132817942110722u, 197403769845u },
+ { 17596907048353602192u, 7448238998520507048u, 163753131461u },
+ { 13530650344896573509u, 13892823322374205296u, 247598595491u },
+ { 6337724853398437005u, 11042137840046332563u, 246569963255u },
+ { 12768885008904063297u, 10513966307445593803u, 254508948214u },
+ { 2759773619512884114u, 9388437460943526957u, 148594534654u },
+ { 8434364600126655292u, 10967228614677896227u, 65125279380u },
+ { 3843827521199949338u, 2310996671540235541u, 19270460225u },
+ { 4661660852957808994u, 4989110555003898586u, 155882077203u },
+ { 15298044134177324417u, 16271452421983657678u, 194516251547u },
+ { 7747773274913338217u, 9523160181437090472u, 80712196546u },
+ { 10348785912020632966u, 13137707423765072249u, 224913270096u },
+ { 4175372293197190170u, 16846859744221860704u, 236421057504u },
+ { 11326064156813083145u, 7767140033449795568u, 4930758124u },
+ { 8100407170505981763u, 17169456915721160016u, 190931378436u },
+ { 1706556116319916846u, 17180899661833327818u, 26046u },
+ { 15028897280749641942u, 480481077043500u, 0u },
+ { 1421201742071739121u, 480481u, 0u },
+ { 1u, 0u, 41952608256u },
+ { 8480737406125178272u, 17572520700934791415u, 121974090537u },
+ { 10947205650755620361u, 17968798858233825416u, 176831497593u },
+ { 868577942165647781u, 15338423313945305608u, 226970107312u },
+ { 16017710019091388479u, 17895321323836726300u, 247044130786u },
+ { 6610879150827623375u, 814069333008965772u, 208390330615u },
+ { 12110095866223762092u, 7200328959852723946u, 20041193424u },
+ { 7756802952949470775u, 759884557248133772u, 3726966548u },
+ { 2941800790804618759u, 13410165861863974850u, 40340355587u },
+ { 11703600274199927522u, 6278452420856351569u, 212491800360u },
+ { 806737539257940346u, 9072115382556676441u, 91149396692u },
+ { 14579028397110132023u, 2755882551854926562u, 93460573019u },
+ { 14247808875344366934u, 8496072611504649268u, 205223454557u },
+ { 9713379923695279513u, 4122009033579215814u, 61554147533u },
+ { 2246428675703313877u, 10222217724450527220u, 233111918909u },
+ { 3549783776592680620u, 2064539481554006324u, 74430190057u },
+ { 12645029747929213033u, 7935605886598063692u, 51423117898u },
+ { 16279009267476580506u, 7805147585347548428u, 18309486643u },
+ { 343358782242907186u, 5709020905457661272u, 60881313810u },
+ { 10077054739085890321u, 16257370307404906673u, 207811593532u },
+ { 10526715404712173586u, 14971258192939373645u, 41061441999u },
+ { 11438715865125144243u, 1133404845901376389u, 82512872489u },
+ { 5040916178827294801u, 9460827548162822046u, 204069058130u },
+ { 16643761637275849508u, 1273897659779791345u, 202424641996u },
+ { 4852542977279030386u, 7833262224435092782u, 70164442058u },
+ { 7883373066544387129u, 3033420566713364586u, 110817242694u },
+ { 16699064314768500978u, 15075466825360349102u, 1707011694u },
+ { 6805863634444817214u, 13042063791413317777u, 1u },
+ { 2266540253968903500u, 31488807865u, 0u },
+ { 9016913589137908810u, 31u, 0u },
+ { 1u, 0u, 222134665216u },
+ { 11654451024602552034u, 2484134775182816689u, 93997495262u },
+ { 5299013208454526793u, 18400539815335991276u, 221026318685u },
+ { 14918550373926182540u, 485494064952118285u, 88952853725u },
+ { 6225552657491071054u, 17577048805241314890u, 76155254872u },
+ { 10344713496596235785u, 2863946907557583806u, 236707187532u },
+ { 12972405634433280209u, 13045307417786230799u, 139652260844u },
+ { 12911885282402784945u, 12032088871615097765u, 26479692427u },
+ { 6934311832970995868u, 8848763446997690579u, 33543797274u },
+ { 9975729197003430461u, 10031289150307672683u, 230628415265u },
+ { 1982857556803548935u, 11592215575498656562u, 62861639142u },
+ { 2095735223386298223u, 15894436747956898387u, 232113382974u },
+ { 7110931538347639365u, 2091546719588500922u, 52317877736u },
+ { 15822183724630969535u, 5863809244813756108u, 220612737332u },
+ { 16931982690156327501u, 11303008753675411244u, 166717656540u },
+ { 6740069226761666110u, 13238426537506910531u, 32935582886u },
+ { 3138792961008474902u, 17258458071023005564u, 81454591520u },
+ { 12154594426971851390u, 8385733444777075178u, 58516663377u },
+ { 15780127219221910902u, 9530757096163247299u, 157781872442u },
+ { 16421541930960194381u, 14423000845391072216u, 196593770909u },
+ { 7485894627196740576u, 10953140011159884310u, 186662899652u },
+ { 8897269432694476707u, 12228340237948264126u, 75611443130u },
+ { 17189823634941678805u, 11279134946966259188u, 173793641291u },
+ { 9585582064286255216u, 14640097792684582650u, 181337854381u },
+ { 12835472279575022097u, 6232313315128656727u, 24874740917u },
+ { 6776016669542754608u, 16136121832933322087u, 54817204760u },
+ { 18340015775620871027u, 15074767079673358270u, 254718431542u },
+ { 5254188752292365830u, 13252722804829281907u, 111870u },
+ { 6798802596750151183u, 2063650512248692u, 0u },
+ { 9449320530215272000u, 2063650u, 0u },
+ { 1u, 0u, 121419595776u },
+ { 17110720482574968811u, 7740175894281560508u, 91849499257u },
+ { 16172441693558688213u, 15670495392425593225u, 188821405531u },
+ { 6234654946353717320u, 15152257626756992777u, 238221723324u },
+ { 11180283100679445438u, 4090073428152440421u, 190783353838u },
+ { 14852260031176961272u, 14450327772834205583u, 10242107326u },
+ { 4481533167346438750u, 4466091895542494215u, 250566718730u },
+ { 4269718344362365664u, 10454115378553795376u, 205122938618u },
+ { 11520029752381101466u, 2267817233475657787u, 54298180301u },
+ { 16778682550309368417u, 5500455702636497520u, 223822842678u },
+ { 9687587467301363608u, 15178768299492252548u, 148382851295u },
+ { 10093971076828497318u, 7062359872332045589u, 6666640532u },
+ { 1913763026490934696u, 12297347290027942575u, 96435313926u },
+ { 12701450127613557000u, 8030124596941085587u, 220353810784u },
+ { 8974572160711134644u, 6526656990996654842u, 184339045596u },
+ { 9890000077336694124u, 6254287345256979849u, 130360063928u },
+ { 4292326716201059148u, 6642007136244870031u, 96109916034u },
+ { 14644519175104337420u, 2027592955437164717u, 68051104864u },
+ { 5051178622270136798u, 942718349157325566u, 40792392772u },
+ { 675983118348065839u, 14617066671884002277u, 1370343464u },
+ { 4431647660065117244u, 6831631114396133347u, 179791632385u },
+ { 8316115180008411962u, 14603040013386939257u, 135537011123u },
+ { 9621158095544965602u, 9906106765319401102u, 44075687047u },
+ { 15283478958951102072u, 1396179595609933062u, 125624765228u },
+ { 13981553073094447813u, 11524884268464976416u, 239020758653u },
+ { 4558368743929911607u, 382929570730827273u, 52331208687u },
+ { 15217004469858477791u, 6109721884461301380u, 235129590068u },
+ { 11589190369996515737u, 2390514825000339690u, 7331559403u },
+ { 3670624237398152929u, 6116191454763441754u, 7u },
+ { 13471713758418039777u, 135243399970u, 0u },
+ { 4489936967610296411u, 135u, 0u },
+ { 1u, 0u, 106628775936u },
+ { 9052049303222747950u, 11598868771099176309u, 120783334250u },
+ { 1011330006193020538u, 14449966445520085104u, 71632935288u },
+ { 17412075644359478612u, 11675595287405614725u, 194859815495u },
+ { 6358678384745980468u, 15860796398550489896u, 137877141698u },
+ { 15262353928842850919u, 16180408435245829661u, 250745768073u },
+ { 11145257686438581736u, 13756992797154950705u, 20478705146u },
+ { 1600562031807691890u, 8830551328786758465u, 120905306388u },
+ { 6775147337046626724u, 16699955256560951263u, 85544214392u },
+ { 15772127322106297822u, 10038983627153402073u, 165817764949u },
+ { 4141472200527441474u, 15085100736692127345u, 2542523045u },
+ { 18246007807879281267u, 10007783780289711124u, 168953930242u },
+ { 960746958654787123u, 17596907048353602191u, 112733498024u },
+ { 11355981212264408477u, 13530650344896573508u, 147343568752u },
+ { 1573078209576251481u, 6337724853398437004u, 203692202643u },
+ { 6245294478780491367u, 12768885008904063296u, 45149607627u },
+ { 7523292955659721510u, 2759773619512884113u, 35457227821u },
+ { 14454736751015226505u, 8434364600126655291u, 21208374307u },
+ { 7219786377781411316u, 3843827521199949337u, 218252709141u },
+ { 10597123082209392431u, 4661660852957808993u, 206829308634u },
+ { 6922353544343010714u, 15298044134177324416u, 168420007630u },
+ { 14317523356293377430u, 7747773274913338216u, 121561008808u },
+ { 4057766168681892717u, 10348785912020632965u, 96226347385u },
+ { 15214083611901244045u, 4175372293197190169u, 240613987168u },
+ { 8390569016883950721u, 11326064156813083144u, 80439123952u },
+ { 10680472538208175055u, 8100407170505981762u, 202092512592u },
+ { 12173567833130544927u, 1706556116319916845u, 44814718154u },
+ { 1386341248286610026u, 15028897280749641941u, 225077043500u },
+ { 12487300952797237352u, 1421201742071739120u, 480481u },
+ { 2614759871804869720u, 8863311460481781u, 0u },
+ { 8494389567327729477u, 8863311u, 0u },
+ { 1u, 0u, 247459741696u },
+ { 6260469580539185878u, 8480737406125178271u, 136593449207u },
+ { 17818573101084525841u, 10947205650755620360u, 8047085704u },
+ { 2201029069927307150u, 868577942165647780u, 28868321800u },
+ { 10397997613804897039u, 16017710019091388478u, 140358376476u },
+ { 14269915965770103741u, 6610879150827623374u, 234656489612u },
+ { 16776139909196366727u, 12110095866223762091u, 140420497130u },
+ { 6246513436385199720u, 7756802952949470774u, 194159475340u },
+ { 2926026498821554288u, 2941800790804618758u, 81634453442u },
+ { 15725499391028340982u, 11703600274199927521u, 89043733329u },
+ { 8576577277771450827u, 806737539257940345u, 226790330713u },
+ { 15523351176022259335u, 14579028397110132022u, 52772375266u },
+ { 4775158829429176134u, 14247808875344366933u, 198526563380u },
+ { 10141817222123532462u, 9713379923695279512u, 244121779142u },
+ { 12847658900242624586u, 2246428675703313876u, 52192434164u },
+ { 13708197964460514655u, 3549783776592680619u, 76685488436u },
+ { 1951540006613246932u, 12645029747929213032u, 12882486860u },
+ { 9979297327280092199u, 16279009267476580505u, 88018613516u },
+ { 15381307706282553684u, 343358782242907185u, 177546278232u },
+ { 10037428657543061177u, 10077054739085890320u, 77570654385u },
+ { 2584877324547208668u, 10526715404712173585u, 133620094029u },
+ { 1126624732730703576u, 11438715865125144242u, 158273268613u },
+ { 1501064139624981020u, 5040916178827294800u, 241902260126u },
+ { 5219661484955306109u, 16643761637275849507u, 46263056881u },
+ { 5336997298570282212u, 4852542977279030385u, 106427358510u },
+ { 12191131175733833362u, 7883373066544387128u, 174905258090u },
+ { 3707068178994436536u, 16699064314768500977u, 145368946606u },
+ { 5045484691732942022u, 6805863634444817213u, 185122869393u },
+ { 14847900542908711232u, 2266540253968903499u, 31488807865u },
+ { 9097257915916965135u, 9016913589137908809u, 31u },
+ { 2472027983230314217u, 580865979874u, 0u },
+ { 15974509111133272205u, 580u, 0u },
+ { 1u, 0u, 177631789056u },
+ { 12099486841948187399u, 11654451024602552033u, 236287260081u },
+ { 5319910566029976328u, 5299013208454526792u, 13808736236u },
+ { 11549214421017285864u, 14918550373926182539u, 74337487885u },
+ { 1998791413186046700u, 6225552657491071053u, 190560788042u },
+ { 17075171930090011210u, 10344713496596235784u, 15703235518u },
+ { 15158296003813501474u, 12972405634433280208u, 165699954703u },
+ { 1360083178079384115u, 12911885282402784944u, 211375909797u },
+ { 6167980558592741158u, 6934311832970995867u, 107540785363u },
+ { 3630180428124865653u, 9975729197003430460u, 50107490923u },
+ { 2276550099763657677u, 1982857556803548934u, 83113610034u },
+ { 407006713016100655u, 2095735223386298222u, 186385484371u },
+ { 14242579061653496002u, 7110931538347639364u, 204857722298u },
+ { 17944493332678643704u, 15822183724630969534u, 44917884620u },
+ { 987185901870869452u, 16931982690156327500u, 67365379884u },
+ { 5578665155415167745u, 6740069226761666109u, 124170154307u },
+ { 4849210377429577536u, 3138792961008474901u, 234658901884u },
+ { 10811995403388891862u, 12154594426971851389u, 195855442410u },
+ { 7051931074990177294u, 15780127219221910901u, 216890213571u },
+ { 2030832259446664275u, 16421541930960194380u, 22405811160u },
+ { 6069512651054767896u, 7485894627196740575u, 190482321942u },
+ { 10608701253763958799u, 8897269432694476706u, 244931862206u },
+ { 15700053443426906717u, 17189823634941678804u, 250519635444u },
+ { 17759719234725541222u, 9585582064286255215u, 87695812346u },
+ { 15187321568916405210u, 12835472279575022096u, 103367328599u },
+ { 11040156458113129594u, 6776016669542754607u, 190994214247u },
+ { 2800727824598008497u, 18340015775620871026u, 115284830142u },
+ { 2997236166375604479u, 5254188752292365829u, 116368563827u },
+ { 6260091886451512841u, 6798802596750151182u, 34512248692u },
+ { 17573059315228347474u, 9449320530215271999u, 2063650u },
+ { 7519453664590169251u, 38067632857031246u, 0u },
+ { 15809436065653866529u, 38067632u, 0u },
+ { 1u, 0u, 188927574016u },
+ { 228921437623588922u, 17110720482574968810u, 137876709820u },
+ { 2195862230003073884u, 16172441693558688212u, 9337981321u },
+ { 960207412233973688u, 6234654946353717319u, 101606084361u },
+ { 2464387149230492479u, 11180283100679445437u, 143805142629u },
+ { 3631866936444955213u, 14852260031176961271u, 7242944399u },
+ { 1578304441149380227u, 4481533167346438749u, 48231461895u },
+ { 18190538519673445181u, 4269718344362365663u, 59624502064u },
+ { 1271000736479934749u, 11520029752381101465u, 112909574203u },
+ { 18292963032817745634u, 16778682550309368416u, 132525165168u },
+ { 17168014021925537455u, 9687587467301363607u, 21547195268u },
+ { 18046757712870378949u, 10093971076828497317u, 175103745301u },
+ { 14857998893911743220u, 1913763026490934695u, 147688546991u },
+ { 11933607369968684575u, 12701450127613556999u, 250486512531u },
+ { 3483798509902859162u, 8974572160711134643u, 137536137978u },
+ { 7378828438829845831u, 9890000077336694123u, 143232687497u },
+ { 15791137430347699565u, 4292326716201059147u, 173793880975u },
+ { 17044141236829932641u, 14644519175104337419u, 254273824941u },
+ { 9075651910862456484u, 5051178622270136797u, 229036645118u },
+ { 17811207355884564095u, 675983118348065838u, 227240240101u },
+ { 4438638126207305937u, 4431647660065117243u, 121450817507u },
+ { 12507972635512950185u, 8316115180008411961u, 142521564025u },
+ { 14658269128098109408u, 9621158095544965601u, 6828519054u },
+ { 3642436268910286111u, 15283478958951102071u, 32757941510u },
+ { 3783099432964819561u, 13981553073094447812u, 9247109664u },
+ { 9497579866027539638u, 4558368743929911606u, 132824915465u },
+ { 3395179445046271361u, 15217004469858477790u, 234628251268u },
+ { 5938502732309497276u, 11589190369996515736u, 90198984938u },
+ { 5793671185917606255u, 3670624237398152928u, 34730303066u },
+ { 889272970253526588u, 13471713758418039776u, 135243399970u },
+ { 8594177504370135501u, 4489936967610296410u, 135u },
+ { 7374354721120724712u, 2494800386918u, 0u },
+ { 14764532643665507567u, 2494u, 0u },
+ { 1u, 0u, 117490712576u },
+ { 5392404173658087695u, 9052049303222747949u, 112054824309u },
+ { 4976586473237854316u, 1011330006193020537u, 133943910512u },
+ { 6308932742419013569u, 17412075644359478611u, 40344704645u },
+ { 4831846642430703059u, 6358678384745980467u, 29827373864u },
+ { 18139507855949846901u, 15262353928842850918u, 49604185629u },
+ { 4865833876326628410u, 11145257686438581735u, 65086766641u },
+ { 14296661839130179261u, 1600562031807691889u, 223367281473u },
+ { 9254773150378118248u, 6775147337046626723u, 217855008735u },
+ { 12174712433727875143u, 15772127322106297821u, 113224509657u },
+ { 705653145340915199u, 4141472200527441473u, 20989118065u },
+ { 17763928858962481812u, 18246007807879281266u, 143052082196u },
+ { 3982836567612046296u, 960746958654787122u, 68615608975u },
+ { 12730849277561967739u, 11355981212264408476u, 140085276740u },
+ { 17314488764367235908u, 1573078209576251480u, 64338558092u },
+ { 15951418930590301119u, 6245294478780491366u, 145407838528u },
+ { 7193356087283467261u, 7523292955659721509u, 59783592849u },
+ { 17592945625696089446u, 14454736751015226504u, 25391385403u },
+ { 3554461664875361428u, 7219786377781411315u, 97574471193u },
+ { 2213779057785318208u, 10597123082209392430u, 128375261537u },
+ { 3880940796082421148u, 6922353544343010713u, 104776154496u },
+ { 4528237545358141043u, 14317523356293377429u, 133219971944u },
+ { 11681196539088147363u, 4057766168681892716u, 25824757125u },
+ { 9835005502912643017u, 15214083611901244044u, 8454853657u },
+ { 4964088126040986696u, 8390569016883950720u, 66578989576u },
+ { 3355564873147047622u, 10680472538208175054u, 45659930434u },
+ { 1853093467828272927u, 12173567833130544926u, 213075153709u },
+ { 14755341584803008677u, 1386341248286610025u, 240676937941u },
+ { 4701571132542556621u, 12487300952797237351u, 245141746416u },
+ { 6128849686644853851u, 2614759871804869719u, 79460481781u },
+ { 12026867901170202094u, 8494389567327729476u, 8863311u },
+ { 17909760324981426303u, 163499238157084246u, 0u },
+ { 2897692901883393664u, 163499238u, 0u },
+ { 1u, 0u, 159339380736u },
+ { 12323704802554838154u, 6260469580539185877u, 8965946783u },
+ { 7135886931147821732u, 17818573101084525840u, 164119318024u },
+ { 15341283120292884947u, 2201029069927307149u, 62563676580u },
+ { 3092789040392634166u, 10397997613804897038u, 206773573694u },
+ { 8811761390822097865u, 14269915965770103740u, 171909436366u },
+ { 16870860798610218169u, 16776139909196366726u, 54338624171u },
+ { 17452041453591904833u, 6246513436385199719u, 6158620214u },
+ { 10314783684009874908u, 2926026498821554287u, 225852481030u },
+ { 4932636630789274903u, 15725499391028340981u, 121464937185u },
+ { 18143884346082124480u, 8576577277771450826u, 54841522553u },
+ { 2823209155405527322u, 15523351176022259334u, 85258861878u },
+ { 16195396106620226251u, 4775158829429176133u, 152549789013u },
+ { 1150544491807648944u, 10141817222123532461u, 212696472984u },
+ { 7767455475523884824u, 12847658900242624585u, 171743122900u },
+ { 15204378045683991808u, 13708197964460514654u, 104105793195u },
+ { 17239732561718805622u, 1951540006613246931u, 153540978792u },
+ { 12886430624522800062u, 9979297327280092198u, 49833822361u },
+ { 18162250541178258136u, 15381307706282553683u, 16544130097u },
+ { 17028935366700158084u, 10037428657543061176u, 17140126480u },
+ { 16075467823964198637u, 2584877324547208667u, 178061074449u },
+ { 9803858825574498304u, 1126624732730703575u, 80081372850u },
+ { 17464070808143041817u, 1501064139624981019u, 35282958416u },
+ { 17682703471239266776u, 5219661484955306108u, 113289319203u },
+ { 18147688354161351336u, 5336997298570282211u, 56660882545u },
+ { 6663423873348080051u, 12191131175733833361u, 241200960568u },
+ { 9417270363716235133u, 3707068178994436535u, 61273516273u },
+ { 9295013721571344179u, 5045484691732942021u, 75804906301u },
+ { 6199479138350037783u, 14847900542908711231u, 73493163339u },
+ { 887603005365085688u, 9097257915916965134u, 226134008905u },
+ { 333989628642975696u, 2472027983230314216u, 68865979874u },
+ { 4620735991403939439u, 15974509111133272204u, 580u },
+ { 12418523063962801201u, 10715086071862u, 0u },
+ { 1587745622680169419u, 10715u, 0u },
+ { 1u, 0u, 225655914496u },
+ { 10968905082284365638u, 12099486841948187398u, 72288392929u },
+ { 14076907092801977812u, 5319910566029976327u, 139626084168u },
+ { 3438322122816124202u, 11549214421017285863u, 77108354699u },
+ { 14645413324829073676u, 1998791413186046699u, 8925646925u },
+ { 12271281439492289999u, 17075171930090011209u, 208821732872u },
+ { 6233751789862708246u, 15158296003813501473u, 176073730256u },
+ { 1962644459455827991u, 1360083178079384114u, 155334366896u },
+ { 8726934184642952500u, 6167980558592741157u, 60196792475u },
+ { 4531087719737475147u, 3630180428124865652u, 6123412028u },
+ { 481513520412720775u, 2276550099763657676u, 110022063878u },
+ { 992149349835802669u, 407006713016100654u, 68772091758u },
+ { 11165474436676191361u, 14242579061653496001u, 190972772932u },
+ { 10240785855143707184u, 17944493332678643703u, 76053515454u },
+ { 10059329918238932466u, 987185901870869451u, 61302420044u },
+ { 14791716450947031886u, 5578665155415167744u, 21262876221u },
+ { 15378882314737417403u, 4849210377429577535u, 125586119445u },
+ { 14726970229242271128u, 10811995403388891861u, 117382285949u },
+ { 5090110549507128156u, 7051931074990177293u, 76110091637u },
+ { 17185220781106503841u, 2030832259446664274u, 223329028940u },
+ { 9858517691519529306u, 6069512651054767895u, 162575098847u },
+ { 5595905546638020703u, 10608701253763958798u, 212851101602u },
+ { 15555173226968030256u, 15700053443426906716u, 111962756308u },
+ { 10745236628845355771u, 17759719234725541221u, 16823306351u },
+ { 9973314042399760760u, 15187321568916405209u, 47598488080u },
+ { 4374506813558796576u, 11040156458113129593u, 114151827759u },
+ { 15960826480426749933u, 2800727824598008496u, 5162480498u },
+ { 9636454862798615738u, 2997236166375604478u, 14339360261u },
+ { 17973331528911319269u, 6260091886451512840u, 63952637454u },
+ { 7366495200039369602u, 17573059315228347473u, 78407630399u },
+ { 10505831326526933399u, 7519453664590169250u, 176857031246u },
+ { 2803218632575724145u, 15809436065653866528u, 38067632u },
+ { 8425731874431741636u, 702223880805592151u, 0u },
+ { 14860552245711912111u, 702223880u, 0u },
+ { 1u, 0u, 234012409856u },
+ { 6993664200669526994u, 228921437623588921u, 212119037930u },
+ { 4065363582031999356u, 2195862230003073883u, 71052052948u },
+ { 6899780515342669867u, 960207412233973687u, 189133594695u },
+ { 17713500890201844939u, 2464387149230492478u, 247196883901u },
+ { 6445781125105107086u, 3631866936444955212u, 93085560055u },
+ { 13563044070717478571u, 1578304441149380226u, 223986111069u },
+ { 13167612994149348885u, 18190538519673445180u, 153068901087u },
+ { 5505463469596727288u, 1271000736479934748u, 96991663513u },
+ { 12125446212518819372u, 18292963032817745633u, 151930679904u },
+ { 12537707724735421794u, 17168014021925537454u, 165978316695u },
+ { 15173675086703777069u, 18046757712870378948u, 167805453733u },
+ { 13535510174093048476u, 14857998893911743219u, 7646922151u },
+ { 10698912997087096629u, 11933607369968684574u, 179188857095u },
+ { 16952559548431933861u, 3483798509902859161u, 107400007091u },
+ { 13528255827744249993u, 7378828438829845830u, 75856039275u },
+ { 14122167436324771955u, 15791137430347699564u, 11923964747u },
+ { 13071007137740038297u, 17044141236829932640u, 221491992075u },
+ { 13011887609328904025u, 9075651910862456483u, 46965547485u },
+ { 3116434332871336590u, 17811207355884564094u, 59240619054u },
+ { 9050993820536772770u, 4438638126207305936u, 57678058555u },
+ { 11993719123438634238u, 12507972635512950184u, 225794626361u },
+ { 1414857165879849301u, 14658269128098109407u, 119197456865u },
+ { 13819438220812375094u, 3642436268910286110u, 196205082231u },
+ { 6073063033888264440u, 3783099432964819560u, 54514864836u },
+ { 6828883869150720294u, 9497579866027539637u, 222184053046u },
+ { 4548265621068768345u, 3395179445046271360u, 152321926878u },
+ { 10422524923581371874u, 5938502732309497275u, 224314075544u },
+ { 1858996082510682634u, 5793671185917606254u, 224048207584u },
+ { 890276727450878316u, 889272970253526587u, 90465891296u },
+ { 3886008133802710905u, 8594177504370135500u, 102399764570u },
+ { 612074409233016757u, 7374354721120724711u, 190800386918u },
+ { 3927020336901729264u, 14764532643665507566u, 2494u },
+ { 5298603480094474942u, 46020944252475u, 0u },
+ { 17418383752590430025u, 46020u, 0u },
+ { 1u, 0u, 45292322816u },
+ { 8973799690601597929u, 5392404173658087694u, 121269781293u },
+ { 1343055462055792431u, 4976586473237854315u, 83342007929u },
+ { 17425118728683169659u, 6308932742419013568u, 51261934931u },
+ { 18389781726026675967u, 4831846642430703058u, 102983344691u },
+ { 272526939565961561u, 18139507855949846900u, 231263777382u },
+ { 11293026845930963228u, 4865833876326628409u, 113775023591u },
+ { 13997416438903902597u, 14296661839130179260u, 163501702257u },
+ { 6186605805999441184u, 9254773150378118247u, 221659992483u },
+ { 4401776373281836138u, 12174712433727875142u, 65038253533u },
+ { 16338917089754547008u, 705653145340915198u, 114962984513u },
+ { 13337700757935003056u, 17763928858962481811u, 50215910002u },
+ { 14612496890816348693u, 3982836567612046295u, 156690140722u },
+ { 3219935399907691719u, 12730849277561967738u, 88938620316u },
+ { 10887238730052330387u, 17314488764367235907u, 102864728152u },
+ { 360256418697768294u, 15951418930590301118u, 37389952614u },
+ { 321440824631118565u, 7193356087283467260u, 136953715493u },
+ { 10069228080701402580u, 17592945625696089445u, 243192687752u },
+ { 9428069607611622975u, 3554461664875361427u, 46120009203u },
+ { 14736799017468812344u, 2213779057785318207u, 153210386222u },
+ { 10875332567307979280u, 3880940796082421147u, 149245476249u },
+ { 4611492910339012807u, 4528237545358141042u, 108633238933u },
+ { 10743508637597314786u, 11681196539088147362u, 140533156716u },
+ { 9356196315668016028u, 9835005502912643016u, 128269103756u },
+ { 15755598617722189347u, 4964088126040986695u, 206181905536u },
+ { 1275276394173375542u, 3355564873147047621u, 30100456398u },
+ { 12644999363867216251u, 1853093467828272926u, 105799888670u },
+ { 4553830511509832021u, 14755341584803008676u, 103254872681u },
+ { 8869400642218174412u, 4701571132542556620u, 87332245607u },
+ { 16570849151159054040u, 6128849686644853850u, 68651977815u },
+ { 16127119334101797673u, 12026867901170202093u, 86970890052u },
+ { 9686867250420930550u, 17909760324981426302u, 230157084246u },
+ { 10678226869774428035u, 2897692901883393663u, 163499238u },
+ { 7767227962910162068u, 3016028602530220424u, 0u },
+ { 9780840471948993674u, 3016028602u, 0u },
+ { 1u, 0u, 213668069376u },
+ { 6288709332106746357u, 12323704802554838153u, 16386837205u },
+ { 9066785620141948673u, 7135886931147821731u, 141831652624u },
+ { 8442375916704414909u, 15341283120292884946u, 14167660429u },
+ { 11604629218100425803u, 3092789040392634165u, 188477686542u },
+ { 3877248044010875762u, 8811761390822097864u, 134914571196u },
+ { 16435137704395217283u, 16870860798610218168u, 103946077062u },
+ { 14994442577577813271u, 17452041453591904832u, 111559165543u },
+ { 4410105917142436089u, 10314783684009874907u, 245267398767u },
+ { 4632574728444936970u, 4932636630789274902u, 202983581941u },
+ { 9117147535650050359u, 18143884346082124479u, 134153046474u },
+ { 588939301256904809u, 2823209155405527321u, 69877954182u },
+ { 324393982565305683u, 16195396106620226250u, 173062371141u },
+ { 9380909186923521175u, 1150544491807648943u, 73421074605u },
+ { 4463385697777230217u, 7767455475523884823u, 94824230985u },
+ { 16378985502426333808u, 15204378045683991807u, 211934567774u },
+ { 18210894922387834354u, 17239732561718805621u, 38698574803u },
+ { 1555748035329493205u, 12886430624522800061u, 83984577574u },
+ { 4277055533891898507u, 18162250541178258135u, 184923140435u },
+ { 11574429772510874408u, 17028935366700158083u, 219871452856u },
+ { 17391099253493808815u, 16075467823964198636u, 215531468251u },
+ { 5791212393959129882u, 9803858825574498303u, 27946729175u },
+ { 11254268231455680880u, 17464070808143041816u, 124958581275u },
+ { 16355477587312235322u, 17682703471239266775u, 227983788156u },
+ { 2411485149249320633u, 18147688354161351335u, 145361224931u },
+ { 12763114642070638360u, 6663423873348080050u, 183510511249u },
+ { 1147543073987366419u, 9417270363716235132u, 197503883703u },
+ { 8410777835225272692u, 9295013721571344178u, 63336074437u },
+ { 8134725822306818018u, 6199479138350037782u, 14048117055u },
+ { 8899607004752328377u, 887603005365085687u, 232018105614u },
+ { 690976506652396830u, 333989628642975695u, 140250490600u },
+ { 12281570945595192074u, 4620735991403939438u, 54673209484u },
+ { 12592957291365552899u, 12418523063962801200u, 219086071862u },
+ { 13595807339013970272u, 1587745622680169418u, 10715u },
+ { 9698096389749839992u, 197658450495420u, 0u },
+ { 8310173728816391804u, 197658u, 0u },
+};
+
+inline constexpr int __TABLE_SIZE_2 = 69;
+inline constexpr int __ADDITIONAL_BITS_2 = 120;
+
+inline constexpr uint16_t __POW10_OFFSET_2[__TABLE_SIZE_2] = {
+ 0, 2, 6, 12, 20, 29, 40, 52, 66, 80,
+ 95, 112, 130, 150, 170, 192, 215, 240, 265, 292,
+ 320, 350, 381, 413, 446, 480, 516, 552, 590, 629,
+ 670, 712, 755, 799, 845, 892, 940, 989, 1040, 1092,
+ 1145, 1199, 1254, 1311, 1369, 1428, 1488, 1550, 1613, 1678,
+ 1743, 1810, 1878, 1947, 2017, 2088, 2161, 2235, 2311, 2387,
+ 2465, 2544, 2625, 2706, 2789, 2873, 2959, 3046, 3133
+};
+
+inline constexpr uint8_t __MIN_BLOCK_2[__TABLE_SIZE_2] = {
+ 0, 0, 0, 0, 0, 0, 1, 1, 2, 3,
+ 3, 4, 4, 5, 5, 6, 6, 7, 7, 8,
+ 8, 9, 9, 10, 11, 11, 12, 12, 13, 13,
+ 14, 14, 15, 15, 16, 16, 17, 17, 18, 19,
+ 19, 20, 20, 21, 21, 22, 22, 23, 23, 24,
+ 24, 25, 26, 26, 27, 27, 28, 28, 29, 29,
+ 30, 30, 31, 31, 32, 32, 33, 34, 0
+};
+
+inline constexpr uint64_t __POW10_SPLIT_2[3133][3] = {
+ { 0u, 0u, 3906250u },
+ { 0u, 0u, 202000000000u },
+ { 0u, 11153727427136454656u, 59u },
+ { 0u, 7205759403792793600u, 59604644775u },
+ { 0u, 0u, 167390625000u },
+ { 0u, 0u, 232000000000u },
+ { 0u, 16777216000000000u, 0u },
+ { 0u, 12945425605062557696u, 909494u },
+ { 0u, 4388757836872548352u, 182701772928u },
+ { 0u, 1152921504606846976u, 128237915039u },
+ { 0u, 0u, 159062500000u },
+ { 0u, 0u, 160000000000u },
+ { 0u, 256000000000u, 0u },
+ { 0u, 16192327041775828992u, 13u },
+ { 0u, 15024075324038053888u, 13877787807u },
+ { 0u, 5449091666327633920u, 159814456755u },
+ { 0u, 2494994193563254784u, 179295395851u },
+ { 0u, 4611686018427387904u, 11135253906u },
+ { 0u, 0u, 146250000000u },
+ { 0u, 0u, 128000000000u },
+ { 0u, 3906250u, 0u },
+ { 0u, 3906250000000000u, 0u },
+ { 0u, 4368439412768899072u, 211758u },
+ { 0u, 1563676642168012800u, 46236813575u },
+ { 0u, 11532349341402398720u, 7084767080u },
+ { 0u, 9048364970084925440u, 104625169910u },
+ { 0u, 16609275425742389248u, 246490512847u },
+ { 0u, 0u, 207900390625u },
+ { 0u, 0u, 225000000000u },
+ { 11153727427136454656u, 59u, 0u },
+ { 7205759403792793600u, 59604644775u, 0u },
+ { 0u, 4264412554261970152u, 3u },
+ { 0u, 14485570586272534528u, 3231174267u },
+ { 0u, 17827675094632103936u, 123785264354u },
+ { 0u, 7347197909193981952u, 226966440203u },
+ { 0u, 13677404030777688064u, 11398292396u },
+ { 0u, 3810326759732150272u, 172741453558u },
+ { 0u, 9943947977234055168u, 246206558227u },
+ { 0u, 0u, 19539062500u },
+ { 0u, 0u, 228000000000u },
+ { 12945425605062557696u, 909494u, 0u },
+ { 4388757836872548352u, 909494701772928u, 0u },
+ { 1152921504606846976u, 14878706826214591391u, 49303u },
+ { 0u, 4387341015746028192u, 151806576313u },
+ { 0u, 651726680428265472u, 185237838233u },
+ { 0u, 2570638187944738816u, 153035330174u },
+ { 0u, 7419175577111756800u, 126139354575u },
+ { 0u, 17299322326264840192u, 207402194313u },
+ { 0u, 7990511638862102528u, 137937798142u },
+ { 0u, 16717361816799281152u, 254433166503u },
+ { 0u, 0u, 167906250000u },
+ { 0u, 0u, 16000000000u },
+ { 16192327041775828992u, 13u, 0u },
+ { 15024075324038053888u, 13877787807u, 0u },
+ { 5449091666327633920u, 13877787807814456755u, 0u },
+ { 2494994193563254784u, 9707857417284919307u, 752316384u },
+ { 4611686018427387904u, 1844515466944871826u, 224526264005u },
+ { 0u, 15167599819856275072u, 197099991383u },
+ { 0u, 14830185305589481472u, 87822237233u },
+ { 0u, 6163721531743535104u, 49803945956u },
+ { 0u, 14122847407012052992u, 228334136013u },
+ { 0u, 335491783960035328u, 205765601092u },
+ { 0u, 941252322120433664u, 68018187046u },
+ { 0u, 11529215046068469760u, 38051025390u },
+ { 0u, 0u, 238625000000u },
+ { 0u, 0u, 64000000000u },
+ { 4368439412768899072u, 211758u, 0u },
+ { 1563676642168012800u, 211758236813575u, 0u },
+ { 11532349341402398720u, 8061591463141767016u, 11479u },
+ { 9048364970084925440u, 16628725344207857142u, 215437019748u },
+ { 16609275425742389248u, 3555541870038531535u, 100901445007u },
+ { 0u, 18316647450161853665u, 143192746310u },
+ { 0u, 16709574568378075648u, 70992947447u },
+ { 0u, 7696022835795591168u, 247905827852u },
+ { 0u, 16664449640376041472u, 12417202233u },
+ { 0u, 3109186955116544000u, 57903381625u },
+ { 0u, 10515518101817131008u, 121168549362u },
+ { 0u, 9961962375743537152u, 242570047378u },
+ { 0u, 9223372036854775808u, 146540039062u },
+ { 0u, 0u, 150500000000u },
+ { 14485570586272534528u, 3231174267u, 0u },
+ { 17827675094632103936u, 3231174267785264354u, 0u },
+ { 7347197909193981952u, 748977172262750475u, 175162308u },
+ { 13677404030777688064u, 15965033457315095468u, 196040602133u },
+ { 3810326759732150272u, 16809402149066729206u, 21865466197u },
+ { 9943947977234055168u, 7563769067065700371u, 85911239516u },
+ { 0u, 13550322810840051428u, 92410032742u },
+ { 0u, 8663209637545764864u, 102734564471u },
+ { 0u, 8969247575312957440u, 119469633535u },
+ { 0u, 6193172891660451840u, 255486223885u },
+ { 0u, 3427954273864908800u, 13335732575u },
+ { 0u, 10058367555266936832u, 95185829773u },
+ { 0u, 13907115649320091648u, 141545265197u },
+ { 0u, 0u, 45753906250u },
+ { 0u, 0u, 74000000000u },
+ { 14878706826214591391u, 49303u, 0u },
+ { 4387341015746028192u, 49303806576313u, 0u },
+ { 651726680428265472u, 14106411361315920281u, 2672u },
+ { 2570638187944738816u, 3609034283485221502u, 112764710092u },
+ { 7419175577111756800u, 9896072247338192335u, 204195646140u },
+ { 17299322326264840192u, 8889095178479228297u, 188536467151u },
+ { 7990511638862102528u, 3631796911038383102u, 207481878815u },
+ { 16717361816799281152u, 898318840772166823u, 31196880105u },
+ { 0u, 17293677953982795024u, 233048697961u },
+ { 0u, 7353628266884669440u, 105937492160u },
+ { 0u, 2404693032470315008u, 192398640987u },
+ { 0u, 9191155893041889280u, 91130358670u },
+ { 0u, 6353946855033798656u, 142498253559u },
+ { 0u, 3767824038248841216u, 247344448149u },
+ { 0u, 7205759403792793600u, 149204254150u },
+ { 0u, 0u, 198390625000u },
+ { 0u, 0u, 232000000000u },
+ { 9707857417284919307u, 752316384u, 0u },
+ { 1844515466944871826u, 752316384526264005u, 0u },
+ { 15167599819856275072u, 17063068157692817751u, 40783152u },
+ { 14830185305589481472u, 5385330256507239985u, 48924990778u },
+ { 6163721531743535104u, 3373050282752075748u, 58291939338u },
+ { 14122847407012052992u, 4116064001262906061u, 10182853422u },
+ { 335491783960035328u, 11306582046748043076u, 46223132276u },
+ { 941252322120433664u, 17035410946089626406u, 116612931040u },
+ { 11529215046068469760u, 15618595715183448558u, 224923491477u },
+ { 0u, 5141740092277295680u, 149846685770u },
+ { 0u, 16973644291514990592u, 74278734288u },
+ { 0u, 14625255268443750400u, 208920143100u },
+ { 0u, 14021170507320131584u, 252792836676u },
+ { 0u, 4451355232865091584u, 68760089176u },
+ { 0u, 12891553933348044800u, 88241308450u },
+ { 0u, 1152921504606846976u, 34698852539u },
+ { 0u, 0u, 187062500000u },
+ { 0u, 0u, 160000000000u },
+ { 8061591463141767016u, 11479u, 0u },
+ { 16628725344207857142u, 11479437019748u, 0u },
+ { 3555541870038531535u, 5562205901560339855u, 622u },
+ { 18316647450161853665u, 2106077949367544134u, 110301527786u },
+ { 16709574568378075648u, 7496855998374373623u, 234114170714u },
+ { 7696022835795591168u, 229183437194837004u, 90406405378u },
+ { 16664449640376041472u, 465169186276472889u, 2012424059u },
+ { 3109186955116544000u, 2152980561625316473u, 123025216872u },
+ { 10515518101817131008u, 2059790725449340402u, 104116713310u },
+ { 9961962375743537152u, 17891190926410198930u, 94111661478u },
+ { 9223372036854775808u, 9930696175609809814u, 166969883403u },
+ { 0u, 7276914261609005312u, 11538344118u },
+ { 0u, 10539762974036983808u, 182394482312u },
+ { 0u, 12851089458992250880u, 136571361695u },
+ { 0u, 9449311677678878720u, 159696658955u },
+ { 0u, 8699564697382289408u, 11512248212u },
+ { 0u, 4224376450473525248u, 148471604347u },
+ { 0u, 4611686018427387904u, 123229003906u },
+ { 0u, 0u, 130250000000u },
+ { 0u, 0u, 128000000000u },
+ { 748977172262750475u, 175162308u, 0u },
+ { 15965033457315095468u, 175162308040602133u, 0u },
+ { 16809402149066729206u, 13756840147955779925u, 9495567u },
+ { 7563769067065700371u, 13788447602092505948u, 15745759798u },
+ { 13550322810840051428u, 4972540435632173670u, 54747473242u },
+ { 8663209637545764864u, 2844874687533091959u, 90269561957u },
+ { 8969247575312957440u, 15377573779532804095u, 101154220965u },
+ { 6193172891660451840u, 17824715805091194381u, 165833619944u },
+ { 3427954273864908800u, 18277569135638159711u, 232966279779u },
+ { 10058367555266936832u, 4254645803379752845u, 99990829008u },
+ { 13907115649320091648u, 2933643244178200621u, 208230644811u },
+ { 0u, 17188148801879487562u, 75159033118u },
+ { 0u, 11069762501163246592u, 30931771413u },
+ { 0u, 11676570643941818368u, 21600093027u },
+ { 0u, 17840016768744030208u, 99632988162u },
+ { 0u, 16463817321652158464u, 2967109246u },
+ { 0u, 6954191143357644800u, 126892505325u },
+ { 0u, 5080060379673919488u, 237376987457u },
+ { 0u, 0u, 65275390625u },
+ { 0u, 0u, 161000000000u },
+ { 14106411361315920281u, 2672u, 0u },
+ { 3609034283485221502u, 2672764710092u, 0u },
+ { 9896072247338192335u, 16433563478020213436u, 144u },
+ { 8889095178479228297u, 4194750497955655375u, 144890865261u },
+ { 3631796911038383102u, 2691539602252904735u, 109227397880u },
+ { 898318840772166823u, 3775467271962795241u, 248145908654u },
+ { 17293677953982795024u, 16980212613224918121u, 174204668490u },
+ { 7353628266884669440u, 4172857038337333440u, 74920499170u },
+ { 2404693032470315008u, 5936867627376461659u, 226226211033u },
+ { 9191155893041889280u, 17856837443266866062u, 217321838238u },
+ { 6353946855033798656u, 8956297047799810807u, 158968021097u },
+ { 3767824038248841216u, 15356974049716912789u, 105485521835u },
+ { 7205759403792793600u, 6923608913322982854u, 171832503231u },
+ { 0u, 4855902993563955944u, 191375329591u },
+ { 0u, 13835893222288330752u, 55263239028u },
+ { 0u, 9114973913760137216u, 116750045274u },
+ { 0u, 17937099003422310400u, 90494123725u },
+ { 0u, 7007960010734960640u, 205972372085u },
+ { 0u, 7683422439270776832u, 117379902273u },
+ { 0u, 720575940379279360u, 65416519165u },
+ { 0u, 0u, 253039062500u },
+ { 0u, 0u, 228000000000u },
+ { 17063068157692817751u, 40783152u, 0u },
+ { 5385330256507239985u, 40783152924990778u, 0u },
+ { 3373050282752075748u, 2768933352715741194u, 2210859u },
+ { 4116064001262906061u, 15201941611824153390u, 43150104177u },
+ { 11306582046748043076u, 1418128541727000180u, 113824098906u },
+ { 17035410946089626406u, 5353350204565757408u, 90076876902u },
+ { 15618595715183448558u, 1721001680354286741u, 102290205696u },
+ { 5141740092277295680u, 637631411660453962u, 93295688u },
+ { 16973644291514990592u, 1630012588870568400u, 72034566068u },
+ { 14625255268443750400u, 9253063571656828156u, 180088363159u },
+ { 14021170507320131584u, 6029146854993203780u, 151501609581u },
+ { 4451355232865091584u, 16987401965352759896u, 109326840705u },
+ { 12891553933348044800u, 14499131620542087970u, 129920888905u },
+ { 1152921504606846976u, 1978417255298660539u, 73785999500u },
+ { 0u, 5790079354402454176u, 140107250214u },
+ { 0u, 13748918935842078720u, 38313880830u },
+ { 0u, 18047438014740692992u, 254745330388u },
+ { 0u, 3116889656839372800u, 212978353575u },
+ { 0u, 15995952446606147584u, 167168966926u },
+ { 0u, 12530140063251562496u, 14867142319u },
+ { 0u, 16717361816799281152u, 175679260253u },
+ { 0u, 0u, 93906250000u },
+ { 0u, 0u, 16000000000u },
+ { 5562205901560339855u, 622u, 0u },
+ { 2106077949367544134u, 622301527786u, 0u },
+ { 7496855998374373623u, 13558973353698967386u, 33u },
+ { 229183437194837004u, 6228991722850501890u, 33735033418u },
+ { 465169186276472889u, 16886831391703377787u, 74337674317u },
+ { 2152980561625316473u, 1181713637872883048u, 77915436964u },
+ { 2059790725449340402u, 12393932434925221726u, 164064060824u },
+ { 17891190926410198930u, 10684799845419711910u, 152671876423u },
+ { 9930696175609809814u, 4590318792215640843u, 71579224160u },
+ { 7276914261609005312u, 6383712187366189238u, 96248841680u },
+ { 10539762974036983808u, 1904270214927675016u, 208346061731u },
+ { 12851089458992250880u, 3711506775113308575u, 163103230695u },
+ { 9449311677678878720u, 8091219444738793995u, 231201201185u },
+ { 8699564697382289408u, 39436684991068052u, 33438625885u },
+ { 4224376450473525248u, 18025182908196512891u, 93002137866u },
+ { 4611686018427387904u, 7853924592034603138u, 10977147123u },
+ { 0u, 4815749283615688320u, 243425762105u },
+ { 0u, 14242399906544287744u, 57261062291u },
+ { 0u, 76242322576113664u, 147772082046u },
+ { 0u, 10858088421377703936u, 126004133104u },
+ { 0u, 14293835879041466368u, 240588618152u },
+ { 0u, 12182236992037191680u, 168774870395u },
+ { 0u, 11529215046068469760u, 123660400390u },
+ { 0u, 0u, 6625000000u },
+ { 0u, 0u, 64000000000u },
+ { 13756840147955779925u, 9495567u, 0u },
+ { 13788447602092505948u, 9495567745759798u, 0u },
+ { 4972540435632173670u, 14000097438505379162u, 514755u },
+ { 2844874687533091959u, 16451062686452429925u, 195758946802u },
+ { 15377573779532804095u, 4009347599785716645u, 242891813895u },
+ { 17824715805091194381u, 16544162347546196456u, 7217347168u },
+ { 18277569135638159711u, 17674258299745817187u, 96896860837u },
+ { 4254645803379752845u, 5215238411201214416u, 165958123462u },
+ { 2933643244178200621u, 14253990228345322571u, 198282718640u },
+ { 17188148801879487562u, 11214836553940194590u, 176772710358u },
+ { 11069762501163246592u, 14620711348380590101u, 214607957507u },
+ { 11676570643941818368u, 6638710787931587427u, 3792590350u },
+ { 17840016768744030208u, 17320000343692853250u, 14359885232u },
+ { 16463817321652158464u, 75147386268843646u, 176938919100u },
+ { 6954191143357644800u, 17938801582125480173u, 188004073747u },
+ { 5080060379673919488u, 6573358613626446145u, 19972464382u },
+ { 0u, 8688505427903736481u, 254356342484u },
+ { 0u, 539870168696556032u, 212471004823u },
+ { 0u, 9002861336394465280u, 151029266420u },
+ { 0u, 17989846818158018560u, 244488046090u },
+ { 0u, 2700938287723315200u, 10975231550u },
+ { 0u, 17800090499088908288u, 62146418157u },
+ { 0u, 8809040871136690176u, 237964944839u },
+ { 0u, 9223372036854775808u, 199477539062u },
+ { 0u, 0u, 246500000000u },
+ { 16433563478020213436u, 144u, 0u },
+ { 4194750497955655375u, 144890865261u, 0u },
+ { 2691539602252904735u, 15763656745260536568u, 7u },
+ { 3775467271962795241u, 8787336846248645550u, 7854549544u },
+ { 16980212613224918121u, 17584084447880694346u, 40476362484u },
+ { 4172857038337333440u, 18041672551129683938u, 244953235127u },
+ { 5936867627376461659u, 14025886302294509785u, 183978041028u },
+ { 17856837443266866062u, 18430498103283160734u, 196760344819u },
+ { 8956297047799810807u, 3292348826238025833u, 243999119304u },
+ { 15356974049716912789u, 9211721212658275243u, 200178478587u },
+ { 6923608913322982854u, 10233245872666307519u, 251499368407u },
+ { 4855902993563955944u, 6200995035623311671u, 215554745370u },
+ { 13835893222288330752u, 8480542380570450804u, 26336156614u },
+ { 9114973913760137216u, 11870363864499900506u, 198459731123u },
+ { 17937099003422310400u, 9301051379839581901u, 179643493714u },
+ { 7007960010734960640u, 11456694803569638005u, 82504211005u },
+ { 7683422439270776832u, 14327208890643983169u, 61621068669u },
+ { 720575940379279360u, 4510081789599866365u, 125776679550u },
+ { 0u, 13255356976020303332u, 126244492023u },
+ { 0u, 9658806854127314944u, 247718574341u },
+ { 0u, 13708435528809971712u, 5523604968u },
+ { 0u, 1580190652103131136u, 232743135779u },
+ { 0u, 16557336970347413504u, 35085662306u },
+ { 0u, 12751520132434493440u, 98897575035u },
+ { 0u, 9295429630892703744u, 123691261291u },
+ { 0u, 0u, 107503906250u },
+ { 0u, 0u, 202000000000u },
+ { 2768933352715741194u, 2210859u, 0u },
+ { 15201941611824153390u, 2210859150104177u, 0u },
+ { 1418128541727000180u, 16872870088062921306u, 119850u },
+ { 5353350204565757408u, 5112979788807802982u, 42914680120u },
+ { 1721001680354286741u, 13742728082020150272u, 56277175189u },
+ { 637631411660453962u, 2217110934613627976u, 149744994782u },
+ { 1630012588870568400u, 11021433940188610484u, 222120189824u },
+ { 9253063571656828156u, 1713669895470733463u, 128597473131u },
+ { 6029146854993203780u, 3313382510572018285u, 107092898231u },
+ { 16987401965352759896u, 14976595232784069505u, 183179618825u },
+ { 14499131620542087970u, 7213172372862496841u, 9811882854u },
+ { 1978417255298660539u, 15836474542502248588u, 102391026857u },
+ { 5790079354402454176u, 3221099285878340134u, 169858497005u },
+ { 13748918935842078720u, 3265814602578095358u, 237174616142u },
+ { 18047438014740692992u, 6502528252282225364u, 78177040164u },
+ { 3116889656839372800u, 16392476834556790183u, 36352502762u },
+ { 15995952446606147584u, 15167629413417091342u, 234888637949u },
+ { 12530140063251562496u, 1366763272626280111u, 253822238838u },
+ { 16717361816799281152u, 8720523635169216093u, 118074092385u },
+ { 0u, 9649171375767398672u, 97472740533u },
+ { 0u, 7647980704001073152u, 181523082628u },
+ { 0u, 13286434495608651776u, 132414597864u },
+ { 0u, 4358271637167013888u, 232720259057u },
+ { 0u, 15954987941890097152u, 241236262378u },
+ { 0u, 7911135695429697536u, 234864921629u },
+ { 0u, 7205759403792793600u, 29428863525u },
+ { 0u, 0u, 37390625000u },
+ { 0u, 0u, 232000000000u },
+ { 13558973353698967386u, 33u, 0u },
+ { 6228991722850501890u, 33735033418u, 0u },
+ { 16886831391703377787u, 15288289344628122701u, 1u },
+ { 1181713637872883048u, 952589339068938148u, 1828779826u },
+ { 12393932434925221726u, 10058155040190817688u, 50051639971u },
+ { 10684799845419711910u, 5322725640026584391u, 163545253677u },
+ { 4590318792215640843u, 2269982385930389600u, 45288545535u },
+ { 6383712187366189238u, 13216683679976310224u, 255123055991u },
+ { 1904270214927675016u, 17417440642083494819u, 119716477857u },
+ { 3711506775113308575u, 3029180749090900711u, 161944201349u },
+ { 8091219444738793995u, 8315443826261908513u, 133164212217u },
+ { 39436684991068052u, 1488962797247197277u, 249450781113u },
+ { 18025182908196512891u, 18009099634999034122u, 185080716834u },
+ { 7853924592034603138u, 8092455412807497971u, 34976275247u },
+ { 4815749283615688320u, 17808458047236758329u, 47438692886u },
+ { 14242399906544287744u, 3164591817527425171u, 22965398445u },
+ { 76242322576113664u, 3314036340472350590u, 173171552866u },
+ { 10858088421377703936u, 33234902404332784u, 98179654270u },
+ { 14293835879041466368u, 12349284717857274280u, 126001801667u },
+ { 12182236992037191680u, 18209607903013119355u, 195669456065u },
+ { 11529215046068469760u, 7891549145984268038u, 193987144822u },
+ { 0u, 7703609897518594624u, 118427801736u },
+ { 0u, 6336912652634587136u, 136417613529u },
+ { 0u, 4461621834659397632u, 217343524723u },
+ { 0u, 5484660635557953536u, 115241865004u },
+ { 0u, 15142619273265938432u, 44297324048u },
+ { 0u, 12170977992968765440u, 16820883035u },
+ { 0u, 1152921504606846976u, 91659790039u },
+ { 0u, 0u, 215062500000u },
+ { 0u, 0u, 160000000000u },
+ { 14000097438505379162u, 514755u, 0u },
+ { 16451062686452429925u, 514755758946802u, 0u },
+ { 4009347599785716645u, 17812314011563521031u, 27904u },
+ { 16544162347546196456u, 7684138864490314336u, 965607477u },
+ { 17674258299745817187u, 9740522787420029605u, 53416558002u },
+ { 5215238411201214416u, 6701109407732989894u, 178528034798u },
+ { 14253990228345322571u, 16534886227502443952u, 238363267868u },
+ { 11214836553940194590u, 8908667306968317910u, 28896357978u },
+ { 14620711348380590101u, 7531472173477105155u, 90482939822u },
+ { 6638710787931587427u, 11527371604834801166u, 174408281924u },
+ { 17320000343692853250u, 15688593496691078576u, 68624900066u },
+ { 75147386268843646u, 11394944804253312188u, 226850480357u },
+ { 17938801582125480173u, 11182279880854372627u, 229617721195u },
+ { 6573358613626446145u, 150579373068361470u, 107606192607u },
+ { 8688505427903736481u, 3147220002440857300u, 223008162924u },
+ { 539870168696556032u, 3630514817795505815u, 108170611138u },
+ { 9002861336394465280u, 11708796588334233588u, 194196810602u },
+ { 17989846818158018560u, 16844495466426369546u, 106634735134u },
+ { 2700938287723315200u, 17636655472325475902u, 30913141928u },
+ { 17800090499088908288u, 17038926655686645229u, 168956085008u },
+ { 8809040871136690176u, 15602838456783529415u, 16923682064u },
+ { 9223372036854775808u, 10869815869248876790u, 16845831567u },
+ { 0u, 18407124180939800832u, 143589253898u },
+ { 0u, 5705018517251293184u, 10997852201u },
+ { 0u, 9660452258743058432u, 41309269673u },
+ { 0u, 5646292272224927744u, 169523694166u },
+ { 0u, 7410409304047484928u, 86306086117u },
+ { 0u, 5953758707383795712u, 229401719093u },
+ { 0u, 4611686018427387904u, 53322753906u },
+ { 0u, 0u, 114250000000u },
+ { 0u, 0u, 128000000000u },
+ { 15763656745260536568u, 7u, 0u },
+ { 8787336846248645550u, 7854549544u, 0u },
+ { 17584084447880694346u, 7854549544476362484u, 0u },
+ { 18041672551129683938u, 15035424419724983u, 425795984u },
+ { 14025886302294509785u, 18280822466032836292u, 144000815071u },
+ { 18430498103283160734u, 11524250747302615283u, 223991005371u },
+ { 3292348826238025833u, 15212285943691810760u, 187624730884u },
+ { 9211721212658275243u, 7951804027551297019u, 4824659673u },
+ { 10233245872666307519u, 1706416229965221847u, 217431068160u },
+ { 6200995035623311671u, 3406023111930700826u, 92505009u },
+ { 8480542380570450804u, 16132696204133391302u, 177184640882u },
+ { 11870363864499900506u, 11593846688794356915u, 114874555213u },
+ { 9301051379839581901u, 6875759884161133906u, 77628503688u },
+ { 11456694803569638005u, 3593593325323835965u, 136372735690u },
+ { 14327208890643983169u, 9542049733257388925u, 202194809084u },
+ { 4510081789599866365u, 9926551925937787518u, 252517275552u },
+ { 13255356976020303332u, 3128491553219547895u, 160538119458u },
+ { 9658806854127314944u, 17158408656931354885u, 34169595866u },
+ { 13708435528809971712u, 2065169543154992616u, 218930159197u },
+ { 1580190652103131136u, 4832622393556232739u, 93111953065u },
+ { 16557336970347413504u, 16505930714733656162u, 169261976984u },
+ { 12751520132434493440u, 18270988073492888699u, 152894788296u },
+ { 9295429630892703744u, 2525111411519708523u, 200990472248u },
+ { 0u, 16728989342518570442u, 56136886563u },
+ { 0u, 7974052022039438336u, 35906880329u },
+ { 0u, 5356554962386550784u, 73432274226u },
+ { 0u, 6693869495028547584u, 50290379426u },
+ { 0u, 8157517147199766528u, 162362875392u },
+ { 0u, 12065776720423157760u, 442219890u },
+ { 0u, 11997589407315001344u, 114654087066u },
+ { 0u, 0u, 154650390625u },
+ { 0u, 0u, 97000000000u },
+ { 16872870088062921306u, 119850u, 0u },
+ { 5112979788807802982u, 119850914680120u, 0u },
+ { 13742728082020150272u, 2418433229320326037u, 6497u },
+ { 2217110934613627976u, 1143911773589293534u, 97131103528u },
+ { 11021433940188610484u, 9276183703610924928u, 40062011581u },
+ { 1713669895470733463u, 3532180128827684715u, 189502862926u },
+ { 3313382510572018285u, 8563997501322031543u, 78191479868u },
+ { 14976595232784069505u, 14843890409658460681u, 60464255234u },
+ { 7213172372862496841u, 9489417861634552678u, 2804688911u },
+ { 15836474542502248588u, 1113198223322322089u, 15514422373u },
+ { 3221099285878340134u, 11190777557146597869u, 101060346596u },
+ { 3265814602578095358u, 17764553645932638286u, 228606653266u },
+ { 6502528252282225364u, 14900777150991234852u, 82963018382u },
+ { 16392476834556790183u, 17364899863357893610u, 142807772747u },
+ { 15167629413417091342u, 15537570181590167037u, 75941353107u },
+ { 1366763272626280111u, 5558052627121307766u, 147842293367u },
+ { 8720523635169216093u, 12095241565795232609u, 119301302636u },
+ { 9649171375767398672u, 2187936505958366389u, 108655684359u },
+ { 7647980704001073152u, 12009203621325860228u, 7118608275u },
+ { 13286434495608651776u, 14814842834750302952u, 147651020232u },
+ { 4358271637167013888u, 5965296499605198833u, 200803114239u },
+ { 15954987941890097152u, 4051026394962148842u, 255323379371u },
+ { 7911135695429697536u, 16799526299141688349u, 171219606580u },
+ { 7205759403792793600u, 9460214166646215205u, 52910704145u },
+ { 0u, 10750736995029068008u, 17512839237u },
+ { 0u, 5377963045376430080u, 69582798620u },
+ { 0u, 15996910350253424640u, 28291539960u },
+ { 0u, 13651157529655246848u, 248867194247u },
+ { 0u, 9771305410219737088u, 135740030732u },
+ { 0u, 12709439623416250368u, 12529703527u },
+ { 0u, 9943947977234055168u, 103688980102u },
+ { 0u, 0u, 134539062500u },
+ { 0u, 0u, 228000000000u },
+ { 952589339068938148u, 1828779826u, 0u },
+ { 10058155040190817688u, 1828779826051639971u, 0u },
+ { 5322725640026584391u, 371564423966525229u, 99138353u },
+ { 2269982385930389600u, 14464859121514339583u, 49020142547u },
+ { 13216683679976310224u, 3913119023023056247u, 211784141584u },
+ { 17417440642083494819u, 5493396321716566945u, 16212130607u },
+ { 3029180749090900711u, 5837454566818211973u, 47297797611u },
+ { 8315443826261908513u, 2886670683193253881u, 235316449046u },
+ { 1488962797247197277u, 5504823105587173817u, 22156486731u },
+ { 18009099634999034122u, 9431834277334851106u, 75298417058u },
+ { 8092455412807497971u, 12921661346456247087u, 162511300760u },
+ { 17808458047236758329u, 3643076516404724246u, 152700484665u },
+ { 3164591817527425171u, 12559396953196866477u, 57197491573u },
+ { 3314036340472350590u, 1626880974916825698u, 117680846273u },
+ { 33234902404332784u, 6806994170946429566u, 193088193394u },
+ { 12349284717857274280u, 7596631230206896579u, 114369007893u },
+ { 18209607903013119355u, 3100480253729502401u, 21411814204u },
+ { 7891549145984268038u, 6310570748781063286u, 60168077371u },
+ { 7703609897518594624u, 14251867077375744136u, 59342096725u },
+ { 6336912652634587136u, 6701165793751570137u, 85772595262u },
+ { 4461621834659397632u, 10856833140463959923u, 62363270925u },
+ { 5484660635557953536u, 15867563727561248556u, 13588550103u },
+ { 15142619273265938432u, 5048961008671491600u, 215860182353u },
+ { 12170977992968765440u, 13278183119599849051u, 81273704724u },
+ { 1152921504606846976u, 4547591784941053655u, 20719811749u },
+ { 0u, 11815437715887182496u, 165246525444u },
+ { 0u, 398495392178782208u, 4640516162u },
+ { 0u, 9154841240825495552u, 66021602478u },
+ { 0u, 1902683298245640192u, 174496284938u },
+ { 0u, 5081900962138816512u, 10103144668u },
+ { 0u, 3234710432358858752u, 220275490403u },
+ { 0u, 16717361816799281152u, 99175354003u },
+ { 0u, 0u, 147906250000u },
+ { 0u, 0u, 16000000000u },
+ { 17812314011563521031u, 27904u, 0u },
+ { 7684138864490314336u, 27904965607477u, 0u },
+ { 9740522787420029605u, 13488568028574514610u, 1512u },
+ { 6701109407732989894u, 275784718433886190u, 232731216738u },
+ { 16534886227502443952u, 10020568880357102364u, 98014950319u },
+ { 8908667306968317910u, 8876397213146246746u, 175543216127u },
+ { 7531472173477105155u, 2155905919114811310u, 255481190457u },
+ { 11527371604834801166u, 1087100407155601220u, 57116871894u },
+ { 15688593496691078576u, 2903498381705011170u, 214058931831u },
+ { 11394944804253312188u, 12223476257006657765u, 119157398962u },
+ { 11182279880854372627u, 12148657163736735595u, 178662635975u },
+ { 150579373068361470u, 8951241323311673823u, 199658580024u },
+ { 3147220002440857300u, 8463862715901576300u, 56485247764u },
+ { 3630514817795505815u, 3873401978748963266u, 20458826917u },
+ { 11708796588334233588u, 248364795947002730u, 165209977542u },
+ { 16844495466426369546u, 10454378025404001822u, 198013463882u },
+ { 17636655472325475902u, 6574176865628265640u, 74566732968u },
+ { 17038926655686645229u, 16703315293848336u, 168356386842u },
+ { 15602838456783529415u, 9896033222450013456u, 26000905488u },
+ { 10869815869248876790u, 17311376269334085007u, 16536465035u },
+ { 18407124180939800832u, 18378511316495639306u, 139938451587u },
+ { 5705018517251293184u, 15120796393727584297u, 131996301094u },
+ { 9660452258743058432u, 18253447805740347049u, 38819700014u },
+ { 5646292272224927744u, 5842497225601731158u, 46989521388u },
+ { 7410409304047484928u, 4369968404176723173u, 236316722409u },
+ { 5953758707383795712u, 16142207253674488117u, 233236896461u },
+ { 4611686018427387904u, 12124259227391928178u, 205875070808u },
+ { 0u, 13019483264566077056u, 88657257409u },
+ { 0u, 74901376448135168u, 193705787602u },
+ { 0u, 13897060093813325824u, 210004060411u },
+ { 0u, 4495486210810052608u, 251753361137u },
+ { 0u, 14885496280087265280u, 241243700795u },
+ { 0u, 4976477588244398080u, 59806944370u },
+ { 0u, 11529215046068469760u, 114269775390u },
+ { 0u, 0u, 30625000000u },
+ { 0u, 0u, 64000000000u },
+ { 15035424419724983u, 425795984u, 0u },
+ { 18280822466032836292u, 425795984000815071u, 0u },
+ { 11524250747302615283u, 10043594327130472635u, 23082446u },
+ { 15212285943691810760u, 8336034337032909060u, 206544464339u },
+ { 7951804027551297019u, 16717215784895280857u, 211451897326u },
+ { 1706416229965221847u, 10968831263951212032u, 238906242083u },
+ { 3406023111930700826u, 5536629379734406065u, 35594621534u },
+ { 16132696204133391302u, 1618806894932332402u, 94300141280u },
+ { 11593846688794356915u, 11363331325254998861u, 224087755697u },
+ { 6875759884161133906u, 8775167772751754888u, 177616007425u },
+ { 3593593325323835965u, 2898202945316114122u, 1475702798u },
+ { 9542049733257388925u, 8868842714495185148u, 14157111896u },
+ { 9926551925937787518u, 17052094667531999136u, 88480780926u },
+ { 3128491553219547895u, 3658615537031138594u, 126924395904u },
+ { 17158408656931354885u, 12486952437987190746u, 128198333945u },
+ { 2065169543154992616u, 912079238520577629u, 249676919048u },
+ { 4832622393556232739u, 10960072898031888041u, 8049443914u },
+ { 16505930714733656162u, 6129550094334741912u, 74594146742u },
+ { 18270988073492888699u, 7965724516573729480u, 182332283576u },
+ { 2525111411519708523u, 5801761178810791992u, 184431822791u },
+ { 16728989342518570442u, 13197466483098446115u, 199314514103u },
+ { 7974052022039438336u, 11326268638393107273u, 183715436091u },
+ { 5356554962386550784u, 3597339351794947378u, 59613998253u },
+ { 6693869495028547584u, 353880726151383714u, 173195012157u },
+ { 8157517147199766528u, 11154818162602073600u, 61019183912u },
+ { 12065776720423157760u, 5141043976157511026u, 40604703904u },
+ { 11997589407315001344u, 7188225141808859034u, 160278696552u },
+ { 0u, 13894168943295705185u, 104389674465u },
+ { 0u, 12176538069834828288u, 225753204407u },
+ { 0u, 7994239409235165184u, 183660091451u },
+ { 0u, 13707777025480065024u, 59433368586u },
+ { 0u, 10120227247676719104u, 10743100081u },
+ { 0u, 7358494763030413312u, 177548618618u },
+ { 0u, 7656119366529843200u, 122398904800u },
+ { 0u, 9223372036854775808u, 224415039062u },
+ { 0u, 0u, 86500000000u },
+ { 2418433229320326037u, 6497u, 0u },
+ { 1143911773589293534u, 6497131103528u, 0u },
+ { 9276183703610924928u, 3877189582299842749u, 352u },
+ { 3532180128827684715u, 7625565791857948238u, 96210182868u },
+ { 8563997501322031543u, 16568435163612007484u, 212413382749u },
+ { 14843890409658460681u, 17592071940521808130u, 93898176669u },
+ { 9489417861634552678u, 15158637878035490831u, 157953668130u },
+ { 1113198223322322089u, 17789243229146401893u, 34821751405u },
+ { 11190777557146597869u, 14677686051252896484u, 109964356807u },
+ { 17764553645932638286u, 3531237481269211986u, 199795678955u },
+ { 14900777150991234852u, 8074435404989280910u, 235191428767u },
+ { 17364899863357893610u, 7086549341467684427u, 159437716020u },
+ { 15537570181590167037u, 10556134770918626963u, 52384162609u },
+ { 5558052627121307766u, 10772666134712966775u, 49572249212u },
+ { 12095241565795232609u, 6195173298198112620u, 124583987401u },
+ { 2187936505958366389u, 8144773843324250887u, 201335841017u },
+ { 12009203621325860228u, 14144284817150924691u, 249441529074u },
+ { 14814842834750302952u, 6464447844648863176u, 242766763216u },
+ { 5965296499605198833u, 15760468443293179135u, 208350438419u },
+ { 4051026394962148842u, 5172191224908322475u, 19854376706u },
+ { 16799526299141688349u, 2357554307308969012u, 2280385048u },
+ { 9460214166646215205u, 1602046917604361745u, 24127803275u },
+ { 10750736995029068008u, 7830970218109515845u, 139086847137u },
+ { 5377963045376430080u, 2899479134887821084u, 161424517746u },
+ { 15996910350253424640u, 15792042302392017912u, 114157181078u },
+ { 13651157529655246848u, 11286099112296056199u, 150856088328u },
+ { 9771305410219737088u, 15161477829153947404u, 8611820658u },
+ { 12709439623416250368u, 423831848142641767u, 114821905360u },
+ { 9943947977234055168u, 9707413321046312582u, 208022975970u },
+ { 0u, 10969483299803835620u, 226526239930u },
+ { 0u, 4326479556120930304u, 186594656881u },
+ { 0u, 12876227232041795584u, 113234538926u },
+ { 0u, 16967986827791171584u, 174698021676u },
+ { 0u, 1288146316538413056u, 44919836409u },
+ { 0u, 13715290452691779584u, 249069830551u },
+ { 0u, 4683743612465315840u, 151743507385u },
+ { 0u, 0u, 185253906250u },
+ { 0u, 0u, 74000000000u },
+ { 371564423966525229u, 99138353u, 0u },
+ { 14464859121514339583u, 99138353020142547u, 0u },
+ { 3913119023023056247u, 16344805304534272784u, 5374300u },
+ { 5493396321716566945u, 26429987091348271u, 92886053671u },
+ { 5837454566818211973u, 8691371289609838059u, 39001432772u },
+ { 2886670683193253881u, 12980168378493046550u, 196471160181u },
+ { 5504823105587173817u, 14010125458129496139u, 117703656337u },
+ { 9431834277334851106u, 17061829677031795106u, 145759490422u },
+ { 12921661346456247087u, 2227928323072698520u, 118924923640u },
+ { 3643076516404724246u, 7394752319272287289u, 248120776236u },
+ { 12559396953196866477u, 8805771303577744757u, 44400870326u },
+ { 1626880974916825698u, 16371027194302248385u, 182477361818u },
+ { 6806994170946429566u, 9114324123731231602u, 154887475162u },
+ { 7596631230206896579u, 14468189808746991893u, 218494088500u },
+ { 3100480253729502401u, 2376054557800684348u, 52784322141u },
+ { 6310570748781063286u, 12462238943546048571u, 93128806175u },
+ { 14251867077375744136u, 15334855370842605909u, 31675579326u },
+ { 6701165793751570137u, 7211347914013798462u, 190831304175u },
+ { 10856833140463959923u, 13763642332572548877u, 239390927953u },
+ { 15867563727561248556u, 16868268377740071383u, 81746128545u },
+ { 5048961008671491600u, 1120013377627684177u, 161914430661u },
+ { 13278183119599849051u, 15898107650717274388u, 197060716046u },
+ { 4547591784941053655u, 12281923376333274277u, 14861838142u },
+ { 11815437715887182496u, 6383530489286615044u, 62665804400u },
+ { 398495392178782208u, 4253822060257126466u, 112346051881u },
+ { 9154841240825495552u, 17614372438391501998u, 41230600155u },
+ { 1902683298245640192u, 4309951310554333450u, 219954877043u },
+ { 5081900962138816512u, 13106185988973773020u, 115233642928u },
+ { 3234710432358858752u, 2070134359761960547u, 176710487766u },
+ { 16717361816799281152u, 9399359914137865875u, 214112222208u },
+ { 0u, 17415053284723541264u, 509540321u },
+ { 0u, 4840502610448261120u, 225944071930u },
+ { 0u, 5690599259712258048u, 250262404172u },
+ { 0u, 114769594245185536u, 76308488004u },
+ { 0u, 3150620882578178048u, 68006221672u },
+ { 0u, 5136918324969472000u, 104170795500u },
+ { 0u, 7205759403792793600u, 236278472900u },
+ { 0u, 0u, 196390625000u },
+ { 0u, 0u, 232000000000u },
+ { 13488568028574514610u, 1512u, 0u },
+ { 275784718433886190u, 1512731216738u, 0u },
+ { 10020568880357102364u, 98202693831717807u, 82u },
+ { 8876397213146246746u, 12909287260170414079u, 82005323578u },
+ { 2155905919114811310u, 11728631949380786233u, 58699813864u },
+ { 1087100407155601220u, 18263701925522197718u, 232635810411u },
+ { 2903498381705011170u, 4868886449713321591u, 107990077265u },
+ { 12223476257006657765u, 5870139507184082354u, 81263942863u },
+ { 12148657163736735595u, 5978562500822661575u, 207318220900u },
+ { 8951241323311673823u, 10821136839630268472u, 100324098522u },
+ { 8463862715901576300u, 9490907630136752916u, 218586615003u },
+ { 3873401978748963266u, 10564005678001613989u, 219514503133u },
+ { 248364795947002730u, 5754050547468481222u, 221572675895u },
+ { 10454378025404001822u, 3833909949855542602u, 55311927705u },
+ { 6574176865628265640u, 15446538552665967784u, 153207836674u },
+ { 16703315293848336u, 14924837848804399130u, 2837358532u },
+ { 9896033222450013456u, 18140170340418344208u, 196809077080u },
+ { 17311376269334085007u, 11380424819825208971u, 88983380604u },
+ { 18378511316495639306u, 12416915664152252547u, 124616934065u },
+ { 15120796393727584297u, 17195282241626289958u, 177673122346u },
+ { 18253447805740347049u, 2649541045825281326u, 42932158118u },
+ { 5842497225601731158u, 16577429864268509676u, 166143631907u },
+ { 4369968404176723173u, 12051257060168107241u, 35898664273u },
+ { 16142207253674488117u, 5363884561143470797u, 81653299954u },
+ { 12124259227391928178u, 13054029903083620184u, 242290776764u },
+ { 13019483264566077056u, 566314952158634945u, 188707660379u },
+ { 74901376448135168u, 1329472079642345682u, 91030699995u },
+ { 13897060093813325824u, 15686237486658857211u, 219072070825u },
+ { 4495486210810052608u, 1069073549290598129u, 169850352638u },
+ { 14885496280087265280u, 4323599065125928507u, 254057954593u },
+ { 4976477588244398080u, 17861823329752681586u, 33234382774u },
+ { 11529215046068469760u, 17220149985412802078u, 182968291382u },
+ { 0u, 4344934572159429184u, 54933506201u },
+ { 0u, 2252927464837120000u, 153235539375u },
+ { 0u, 10910018171964489728u, 175122131442u },
+ { 0u, 3597328585515335680u, 242591433270u },
+ { 0u, 6972808074239148032u, 54195011573u },
+ { 0u, 2227030015734710272u, 245377996683u },
+ { 0u, 1152921504606846976u, 139120727539u },
+ { 0u, 0u, 243062500000u },
+ { 0u, 0u, 160000000000u },
+ { 10043594327130472635u, 23082446u, 0u },
+ { 8336034337032909060u, 23082446544464339u, 0u },
+ { 16717215784895280857u, 17238287503805244910u, 1251301u },
+ { 10968831263951212032u, 1434575446038410275u, 229934489438u },
+ { 5536629379734406065u, 14009569747841241694u, 94077768490u },
+ { 1618806894932332402u, 14938795732275951328u, 42759460297u },
+ { 11363331325254998861u, 6687653542888983473u, 201809833739u },
+ { 8775167772751754888u, 28238723295162625u, 11362538425u },
+ { 2898202945316114122u, 4745270274832691214u, 185001530824u },
+ { 8868842714495185148u, 926478968112308824u, 200257241617u },
+ { 17052094667531999136u, 9213681606604198526u, 17050224525u },
+ { 3658615537031138594u, 13346223820579313024u, 141499474680u },
+ { 12486952437987190746u, 691642518601291257u, 248723500243u },
+ { 912079238520577629u, 1153720150033789192u, 211037494016u },
+ { 10960072898031888041u, 12089015034721780810u, 62543294u },
+ { 6129550094334741912u, 3555868702841788854u, 190655346818u },
+ { 7965724516573729480u, 11708406782758214328u, 130192764028u },
+ { 5801761178810791992u, 9417497762905343943u, 124634714003u },
+ { 13197466483098446115u, 12838336066957615287u, 147510523576u },
+ { 11326268638393107273u, 13737708142128207419u, 184695967592u },
+ { 3597339351794947378u, 11683434809834695853u, 104744722650u },
+ { 353880726151383714u, 2689114340106315837u, 218633360270u },
+ { 11154818162602073600u, 8859225263374261032u, 142145777180u },
+ { 5141043976157511026u, 15761671984578600096u, 28480259563u },
+ { 7188225141808859034u, 7087267079878005352u, 235854441950u },
+ { 13894168943295705185u, 4601291730423121377u, 222384201518u },
+ { 12176538069834828288u, 9559411037059581623u, 46249436524u },
+ { 7994239409235165184u, 12969820289641388091u, 108518216710u },
+ { 13707777025480065024u, 13628239920285957130u, 6703095366u },
+ { 10120227247676719104u, 8049893933765800625u, 70738788366u },
+ { 7358494763030413312u, 10391755948840250234u, 14436385624u },
+ { 7656119366529843200u, 14454650777462444512u, 88563338218u },
+ { 9223372036854775808u, 14244638523341127254u, 234783588188u },
+ { 0u, 12246016810439753984u, 92772203401u },
+ { 0u, 9382741764551081984u, 137663857901u },
+ { 0u, 4608696190291148800u, 237508639450u },
+ { 0u, 1696483666416369664u, 218249837921u },
+ { 0u, 15416683541605384192u, 97091966563u },
+ { 0u, 7683140964294066176u, 99835740089u },
+ { 0u, 4611686018427387904u, 185416503906u },
+ { 0u, 0u, 98250000000u },
+ { 0u, 0u, 128000000000u },
+ { 3877189582299842749u, 352u, 0u },
+ { 7625565791857948238u, 352210182868u, 0u },
+ { 16568435163612007484u, 1722045467931902045u, 19u },
+ { 17592071940521808130u, 16095324008152856733u, 19093352271u },
+ { 15158637878035490831u, 15216188060094280738u, 79872529262u },
+ { 17789243229146401893u, 10793385929903030893u, 110824871207u },
+ { 14677686051252896484u, 12613277226875940039u, 39585110623u },
+ { 3531237481269211986u, 10644539625155600107u, 95683767128u },
+ { 8074435404989280910u, 6181262895644173983u, 88577041649u },
+ { 7086549341467684427u, 148914399627082292u, 241335086933u },
+ { 10556134770918626963u, 14379289774887985969u, 85008072665u },
+ { 10772666134712966775u, 11743339675582627452u, 217779502860u },
+ { 6195173298198112620u, 7841621929809463497u, 12636607719u },
+ { 8144773843324250887u, 11168944680251236601u, 231425095176u },
+ { 14144284817150924691u, 6178560202529287410u, 8605469704u },
+ { 6464447844648863176u, 13295243308201596112u, 8334940419u },
+ { 15760468443293179135u, 17040673746172470291u, 3720736583u },
+ { 5172191224908322475u, 14957442487039409922u, 71923776774u },
+ { 2357554307308969012u, 17778155426506992152u, 6810844581u },
+ { 1602046917604361745u, 14945404984219733899u, 165963755736u },
+ { 7830970218109515845u, 11590754866058681505u, 216810192027u },
+ { 2899479134887821084u, 6020790784469412466u, 155628336080u },
+ { 15792042302392017912u, 7934351824569522326u, 208326387722u },
+ { 11286099112296056199u, 5038361112172116744u, 10430122074u },
+ { 15161477829153947404u, 3305187319649924210u, 90273130103u },
+ { 423831848142641767u, 11470175511099161552u, 119179174563u },
+ { 9707413321046312582u, 7308362160352048610u, 163621799460u },
+ { 10969483299803835620u, 10666410671225576634u, 36396187106u },
+ { 4326479556120930304u, 2181639019945820785u, 226578227281u },
+ { 12876227232041795584u, 4615749499734847918u, 81118266888u },
+ { 16967986827791171584u, 14076159200958497580u, 8250220281u },
+ { 1288146316538413056u, 5470405257862074105u, 249763070119u },
+ { 13715290452691779584u, 4565741478181339543u, 167296551263u },
+ { 4683743612465315840u, 8901832997861862329u, 95247509341u },
+ { 0u, 14190141170191714122u, 93482569333u },
+ { 0u, 4240772322245764096u, 117769249094u },
+ { 0u, 4422842195340951552u, 70229892728u },
+ { 0u, 15448426386733137920u, 120239762755u },
+ { 0u, 9203504548935630848u, 67837460872u },
+ { 0u, 5936377627571912704u, 136498922981u },
+ { 0u, 468374361246531584u, 229321811676u },
+ { 0u, 0u, 220025390625u },
+ { 0u, 0u, 33000000000u },
+ { 16344805304534272784u, 5374300u, 0u },
+ { 26429987091348271u, 5374300886053671u, 0u },
+ { 8691371289609838059u, 8020875056524075716u, 291341u },
+ { 12980168378493046550u, 1400288714762747253u, 13434812508u },
+ { 14010125458129496139u, 6136037711314764689u, 92075909803u },
+ { 17061829677031795106u, 15735488086392394102u, 171332635270u },
+ { 2227928323072698520u, 7735094782793634552u, 134853022518u },
+ { 7394752319272287289u, 7273689191766726188u, 54419320328u },
+ { 8805771303577744757u, 3410634565056431030u, 8394307481u },
+ { 16371027194302248385u, 4600927904885215898u, 153184890870u },
+ { 9114324123731231602u, 9154871331680374746u, 246249416801u },
+ { 14468189808746991893u, 6117978272461042996u, 97496286569u },
+ { 2376054557800684348u, 13116904339287496285u, 105331656266u },
+ { 12462238943546048571u, 867037205615660831u, 74711068809u },
+ { 15334855370842605909u, 1802487145191504830u, 137047002181u },
+ { 7211347914013798462u, 17242009718457409007u, 69097713023u },
+ { 13763642332572548877u, 13620802355488468049u, 127934691219u },
+ { 16868268377740071383u, 4442227880594435745u, 147738385175u },
+ { 1120013377627684177u, 17354849212854314181u, 23240813655u },
+ { 15898107650717274388u, 18202319179831567886u, 87940808260u },
+ { 12281923376333274277u, 17568634016348874558u, 68986749699u },
+ { 6383530489286615044u, 7496925598312450672u, 3952397558u },
+ { 4253822060257126466u, 601870379496813865u, 246406409151u },
+ { 17614372438391501998u, 11995106565680728027u, 191032627458u },
+ { 4309951310554333450u, 16331071694764184179u, 2650256029u },
+ { 13106185988973773020u, 9665962217000524208u, 157885309170u },
+ { 2070134359761960547u, 13682661374415474390u, 242523992861u },
+ { 9399359914137865875u, 6940361789924260864u, 29741738559u },
+ { 17415053284723541264u, 9658039831644010465u, 63376237766u },
+ { 4840502610448261120u, 6843715893910236922u, 198523563388u },
+ { 5690599259712258048u, 47089792870595660u, 124370998582u },
+ { 114769594245185536u, 14510386192097156932u, 54002552742u },
+ { 3150620882578178048u, 12059931208360040296u, 166786609611u },
+ { 5136918324969472000u, 14877013468459184620u, 203653770180u },
+ { 7205759403792793600u, 2397668560671695044u, 196806484516u },
+ { 0u, 2195572305559232232u, 36129977873u },
+ { 0u, 3261686279425953792u, 17119022213u },
+ { 0u, 9333850662059900928u, 133176816367u },
+ { 0u, 5036522340217782272u, 239505989058u },
+ { 0u, 2800120215143186432u, 194273030423u },
+ { 0u, 441634238459019264u, 23151794821u },
+ { 0u, 720575940379279360u, 133023941040u },
+ { 0u, 0u, 176039062500u },
+ { 0u, 0u, 228000000000u },
+ { 98202693831717807u, 82u, 0u },
+ { 12909287260170414079u, 82005323578u, 0u },
+ { 11728631949380786233u, 8218347283861607400u, 4u },
+ { 18263701925522197718u, 17896200385973633643u, 4445517498u },
+ { 4868886449713321591u, 16333242102094352209u, 186970154966u },
+ { 5870139507184082354u, 9981905728606788815u, 214885426828u },
+ { 5978562500822661575u, 15219470018924839012u, 140541120193u },
+ { 10821136839630268472u, 17152070168529617370u, 193825049122u },
+ { 9490907630136752916u, 17841343440958328027u, 34929815586u },
+ { 10564005678001613989u, 17291078023923990493u, 34967181165u },
+ { 5754050547468481222u, 16744804581790759223u, 109937351217u },
+ { 3833909949855542602u, 5001622214111594905u, 49907737675u },
+ { 15446538552665967784u, 9676746897435398146u, 75271138483u },
+ { 14924837848804399130u, 8109025833995118532u, 179524577500u },
+ { 18140170340418344208u, 5495826424046694744u, 220439591171u },
+ { 11380424819825208971u, 7890288164365705852u, 3297929347u },
+ { 12416915664152252547u, 8616438349039895217u, 131427733378u },
+ { 17195282241626289958u, 15787154801788760618u, 130467098058u },
+ { 2649541045825281326u, 12418659311480782502u, 202855823376u },
+ { 16577429864268509676u, 4486988874116669987u, 16673216870u },
+ { 12051257060168107241u, 4828971301551875409u, 102243240154u },
+ { 5363884561143470797u, 14769106422014442226u, 218261779058u },
+ { 13054029903083620184u, 7763933466423188156u, 114800634863u },
+ { 566314952158634945u, 10449097116253839963u, 239420883676u },
+ { 1329472079642345682u, 12870692502472900571u, 220566446689u },
+ { 15686237486658857211u, 11597479481311003817u, 97697721638u },
+ { 1069073549290598129u, 8294994869530047486u, 38628700622u },
+ { 4323599065125928507u, 16879315829924478241u, 206449672572u },
+ { 17861823329752681586u, 11873324837601439670u, 124915029544u },
+ { 17220149985412802078u, 3277599055636107318u, 40643654229u },
+ { 4344934572159429184u, 15363467897354242201u, 85177679000u },
+ { 2252927464837120000u, 10351182204479784367u, 152832855263u },
+ { 10910018171964489728u, 12811517584931924466u, 223561138711u },
+ { 3597328585515335680u, 16988930699558748726u, 23694513759u },
+ { 6972808074239148032u, 11683499918824718325u, 95920971778u },
+ { 2227030015734710272u, 13119300691281647499u, 2633363799u },
+ { 1152921504606846976u, 10125549106595354099u, 87711198715u },
+ { 0u, 17505352699870800544u, 251548907116u },
+ { 0u, 6756039242241163264u, 108948967071u },
+ { 0u, 3537338758766526464u, 159366245621u },
+ { 0u, 6522626374119718912u, 245191759518u },
+ { 0u, 4733294203482669056u, 158353592284u },
+ { 0u, 16997710893603094528u, 220256592392u },
+ { 0u, 16717361816799281152u, 8921447753u },
+ { 0u, 0u, 73906250000u },
+ { 0u, 0u, 16000000000u },
+ { 17238287503805244910u, 1251301u, 0u },
+ { 1434575446038410275u, 1251301934489438u, 0u },
+ { 14009569747841241694u, 3943737498063000362u, 67833u },
+ { 14938795732275951328u, 2870731037991212489u, 249213790438u },
+ { 6687653542888983473u, 7389433400402095883u, 230155622641u },
+ { 28238723295162625u, 5675049236146197433u, 241400581987u },
+ { 4745270274832691214u, 9953779846262904264u, 99307645035u },
+ { 926478968112308824u, 12691978937179636241u, 107539595486u },
+ { 9213681606604198526u, 15523327331528198029u, 222688033556u },
+ { 13346223820579313024u, 15722603279568118520u, 20841521260u },
+ { 691642518601291257u, 11838632364171816147u, 108852324031u },
+ { 1153720150033789192u, 7832751832367143680u, 191641773546u },
+ { 12089015034721780810u, 12167724027162940862u, 234424614327u },
+ { 3555868702841788854u, 4108211144748152962u, 183659613641u },
+ { 11708406782758214328u, 7530983398136343676u, 201222706572u },
+ { 9417497762905343943u, 1117587133956542355u, 140408255428u },
+ { 12838336066957615287u, 17134748625149490872u, 196060584519u },
+ { 13737708142128207419u, 4039918359454207848u, 71928876584u },
+ { 11683434809834695853u, 1830218764589441242u, 40219004413u },
+ { 2689114340106315837u, 637895981480825742u, 253099216358u },
+ { 8859225263374261032u, 8246879226348334620u, 230034580410u },
+ { 15761671984578600096u, 12389239568142583275u, 186447064218u },
+ { 7087267079878005352u, 14041257178803154398u, 154671622022u },
+ { 4601291730423121377u, 16312515716494630702u, 134761178076u },
+ { 9559411037059581623u, 17088522799596987756u, 220884303248u },
+ { 12969820289641388091u, 3588932524637852678u, 144926370677u },
+ { 13628239920285957130u, 107218049069817414u, 117194556422u },
+ { 8049893933765800625u, 1596707240462008334u, 6005812302u },
+ { 10391755948840250234u, 17461913142391587672u, 78086557672u },
+ { 14454650777462444512u, 4366474266651610090u, 232946612208u },
+ { 14244638523341127254u, 5539304013194805084u, 240236707044u },
+ { 12246016810439753984u, 4762470619211987849u, 228300286272u },
+ { 9382741764551081984u, 10835638458986644717u, 64258174049u },
+ { 4608696190291148800u, 16141642290510052058u, 97587401137u },
+ { 1696483666416369664u, 17390568670756355425u, 177875040181u },
+ { 15416683541605384192u, 12536768491333867107u, 181942744616u },
+ { 7683140964294066176u, 13145148522871947193u, 40679619581u },
+ { 4611686018427387904u, 5665349945233068642u, 253712599929u },
+ { 0u, 17074607537751066240u, 121307119235u },
+ { 0u, 6241525660962062336u, 131925616329u },
+ { 0u, 1142860629783085056u, 201338353784u },
+ { 0u, 16287527416870469632u, 120061954598u },
+ { 0u, 9028002014738513920u, 38882948630u },
+ { 0u, 16217462258161156096u, 22489408969u },
+ { 0u, 11529215046068469760u, 201879150390u },
+ { 0u, 0u, 54625000000u },
+ { 0u, 0u, 64000000000u },
+ { 1722045467931902045u, 19u, 0u },
+ { 16095324008152856733u, 19093352271u, 0u },
+ { 15216188060094280738u, 646608198162977646u, 1u },
+ { 10793385929903030893u, 12170458846894708007u, 1035052700u },
+ { 12613277226875940039u, 1797330480103086687u, 156659761896u },
+ { 10644539625155600107u, 10332188564497263448u, 232097433480u },
+ { 6181262895644173983u, 7524259485079594225u, 136560109064u },
+ { 148914399627082292u, 62681109059153749u, 8407890924u },
+ { 14379289774887985969u, 13480636451804037081u, 236003397949u },
+ { 11743339675582627452u, 6948168233012789004u, 61730786766u },
+ { 7841621929809463497u, 12015502974041806055u, 206376660954u },
+ { 11168944680251236601u, 7343801660689004040u, 218651361721u },
+ { 6178560202529287410u, 13670580858640731144u, 185398108285u },
+ { 13295243308201596112u, 5605073897566574851u, 125741083673u },
+ { 17040673746172470291u, 15387788940505247559u, 25303851664u },
+ { 14957442487039409922u, 17565181499678113030u, 144834173709u },
+ { 17778155426506992152u, 1893743623847493029u, 13952210397u },
+ { 14945404984219733899u, 10243498996716269784u, 221102660047u },
+ { 11590754866058681505u, 5619675836950314139u, 207555301193u },
+ { 6020790784469412466u, 10224869737511515088u, 73304643237u },
+ { 7934351824569522326u, 2574495974386198538u, 165554291299u },
+ { 5038361112172116744u, 7825756347302873178u, 99139563706u },
+ { 3305187319649924210u, 12071550103794656887u, 186424235101u },
+ { 11470175511099161552u, 7195875213867606691u, 93654400042u },
+ { 7308362160352048610u, 18271364438406891044u, 42390089176u },
+ { 10666410671225576634u, 16966521933952564706u, 216990492650u },
+ { 2181639019945820785u, 289920862029570129u, 234919756997u },
+ { 4615749499734847918u, 7804199568098625032u, 197015716641u },
+ { 14076159200958497580u, 5758118571242446585u, 33423066506u },
+ { 5470405257862074105u, 4030788293606375591u, 138312148233u },
+ { 4565741478181339543u, 4387716460037196127u, 9218509471u },
+ { 8901832997861862329u, 16807506478881285981u, 159237858585u },
+ { 14190141170191714122u, 17033060604413529717u, 25911136751u },
+ { 4240772322245764096u, 10498418508292170054u, 239923364065u },
+ { 4422842195340951552u, 13237752038744465016u, 225569120407u },
+ { 15448426386733137920u, 17737618428304633155u, 151717619975u },
+ { 9203504548935630848u, 13546183833248825736u, 7961558221u },
+ { 5936377627571912704u, 826778452978976229u, 205734340097u },
+ { 468374361246531584u, 13728076626990147292u, 1044819749u },
+ { 0u, 2794860281883592225u, 37744200525u },
+ { 0u, 8680705720425908736u, 77151509679u },
+ { 0u, 731520517439488000u, 175470582000u },
+ { 0u, 13120812320768917504u, 240039655806u },
+ { 0u, 2722954908557901824u, 126711280661u },
+ { 0u, 6860847004205973504u, 21147611681u },
+ { 0u, 6503197861922996224u, 33371927261u },
+ { 0u, 9223372036854775808u, 221352539062u },
+ { 0u, 0u, 182500000000u },
+ { 8020875056524075716u, 291341u, 0u },
+ { 1400288714762747253u, 291341434812508u, 0u },
+ { 6136037711314764689u, 12005656413127238315u, 15793u },
+ { 15735488086392394102u, 4821130826186787462u, 177650827938u },
+ { 7735094782793634552u, 14377899467066168118u, 162261354025u },
+ { 7273689191766726188u, 16575613239625444872u, 41779427491u },
+ { 3410634565056431030u, 4317827099179284377u, 163898565794u },
+ { 4600927904885215898u, 1242354770412171254u, 162234069876u },
+ { 9154871331680374746u, 994838588328896609u, 116067348187u },
+ { 6117978272461042996u, 17283309862013060457u, 219053930307u },
+ { 13116904339287496285u, 124242522249856586u, 67936930105u },
+ { 867037205615660831u, 11564608014666985609u, 57006735200u },
+ { 1802487145191504830u, 12401028575581654085u, 96626918656u },
+ { 17242009718457409007u, 2490725392961465727u, 672261106u },
+ { 13620802355488468049u, 1949482237120640915u, 242135022494u },
+ { 4442227880594435745u, 15410502396166200087u, 158105681643u },
+ { 17354849212854314181u, 15694919529799920727u, 235835405008u },
+ { 18202319179831567886u, 10324869370171768388u, 208850823292u },
+ { 17568634016348874558u, 1631866459122189059u, 124559712290u },
+ { 7496925598312450672u, 172020494461226230u, 34088463658u },
+ { 601870379496813865u, 12734610307908856767u, 42009325249u },
+ { 11995106565680728027u, 1467513250829340930u, 193690344608u },
+ { 16331071694764184179u, 13558759428494307997u, 160079554052u },
+ { 9665962217000524208u, 7915355143999496434u, 4735021821u },
+ { 13682661374415474390u, 2876370200608797469u, 253429092262u },
+ { 6940361789924260864u, 343685370404989503u, 166155928341u },
+ { 9658039831644010465u, 4837266557407634630u, 21018631221u },
+ { 6843715893910236922u, 9622591415747161468u, 53262228745u },
+ { 47089792870595660u, 16503783814424220982u, 9521641725u },
+ { 14510386192097156932u, 5377083431343591334u, 253894671913u },
+ { 12059931208360040296u, 16508482371299291595u, 41291492276u },
+ { 14877013468459184620u, 10515883558812249028u, 180894926622u },
+ { 2397668560671695044u, 63492062913405476u, 30570067190u },
+ { 2195572305559232232u, 11571919759617799697u, 246003441911u },
+ { 3261686279425953792u, 2956602334970088581u, 247627315027u },
+ { 9333850662059900928u, 13604736747717849839u, 83160277733u },
+ { 5036522340217782272u, 16573540719338151362u, 229737514256u },
+ { 2800120215143186432u, 12620703004601168151u, 16898453442u },
+ { 441634238459019264u, 14649407809089591941u, 194684169680u },
+ { 720575940379279360u, 11290375247898624432u, 208794145988u },
+ { 0u, 11020319450292874212u, 196612052468u },
+ { 0u, 8754634933362354176u, 244597412714u },
+ { 0u, 12976319450332528640u, 106474589710u },
+ { 0u, 17447331119627239424u, 14703447686u },
+ { 0u, 3665184902673858560u, 134945821715u },
+ { 0u, 12949678516038795264u, 19198690071u },
+ { 0u, 72057594037927936u, 23702003479u },
+ { 0u, 0u, 23003906250u },
+ { 0u, 0u, 202000000000u },
+ { 8218347283861607400u, 4u, 0u },
+ { 17896200385973633643u, 4445517498u, 0u },
+ { 16333242102094352209u, 4445517498970154966u, 0u },
+ { 9981905728606788815u, 9413159735776077452u, 240991986u },
+ { 15219470018924839012u, 14279163482889998017u, 242510288411u },
+ { 17152070168529617370u, 8693044629541194274u, 27774075003u },
+ { 17841343440958328027u, 11863110253260222498u, 123471250893u },
+ { 17291078023923990493u, 8319293368489531245u, 205643100495u },
+ { 16744804581790759223u, 3376307525676489265u, 79450989797u },
+ { 5001622214111594905u, 13205662254759912523u, 229183029997u },
+ { 9676746897435398146u, 5276250334231686323u, 237715880385u },
+ { 8109025833995118532u, 13790198520922745052u, 193286026103u },
+ { 5495826424046694744u, 14195535250150996227u, 119747568159u },
+ { 7890288164365705852u, 16425228796427004035u, 31769541507u },
+ { 8616438349039895217u, 4295900841296269186u, 131890413437u },
+ { 15787154801788760618u, 4533952595483946442u, 125232881251u },
+ { 12418659311480782502u, 12885038019373447184u, 99245786062u },
+ { 4486988874116669987u, 12140736240487831910u, 206698499310u },
+ { 4828971301551875409u, 6927124077155322074u, 238658150630u },
+ { 14769106422014442226u, 12477788342407819890u, 230375520148u },
+ { 7763933466423188156u, 7980854329409711087u, 148676422261u },
+ { 10449097116253839963u, 2062671021810827996u, 117432642980u },
+ { 12870692502472900571u, 2739521363598172769u, 164111817620u },
+ { 11597479481311003817u, 12897585686593465638u, 148148509750u },
+ { 8294994869530047486u, 1127632646629044686u, 54699179521u },
+ { 16879315829924478241u, 4833775019274666364u, 1061129088u },
+ { 11873324837601439670u, 15867662672939849256u, 128262039468u },
+ { 3277599055636107318u, 2092350330982953557u, 172860187717u },
+ { 15363467897354242201u, 13330062299842493592u, 69113426538u },
+ { 10351182204479784367u, 4479193352178519263u, 106722624125u },
+ { 12811517584931924466u, 3149393938889064983u, 125242817558u },
+ { 16988930699558748726u, 9736379904070620767u, 22170728987u },
+ { 11683499918824718325u, 3816238703055069186u, 27527810212u },
+ { 13119300691281647499u, 11598915938798661975u, 164206878714u },
+ { 10125549106595354099u, 17821633264606555643u, 250628778492u },
+ { 17505352699870800544u, 2514623558764574316u, 252966112675u },
+ { 6756039242241163264u, 4976730480406253215u, 163136318016u },
+ { 3537338758766526464u, 17276563697191611637u, 64269789099u },
+ { 6522626374119718912u, 12524734095940998814u, 171936564394u },
+ { 4733294203482669056u, 15331551308930355164u, 170678967195u },
+ { 16997710893603094528u, 15417115581125943816u, 155831125061u },
+ { 16717361816799281152u, 6010750237807115593u, 69835763510u },
+ { 0u, 5624630987553628432u, 54325843423u },
+ { 0u, 14881848243837640704u, 223304911856u },
+ { 0u, 15281613886881529856u, 240806746609u },
+ { 0u, 14057902358273196032u, 241828417948u },
+ { 0u, 16075318494433902592u, 156762080413u },
+ { 0u, 13891916000577716224u, 157871444761u },
+ { 0u, 7205759403792793600u, 25753082275u },
+ { 0u, 0u, 163390625000u },
+ { 0u, 0u, 232000000000u },
+ { 3943737498063000362u, 67833u, 0u },
+ { 2870731037991212489u, 67833213790438u, 0u },
+ { 7389433400402095883u, 4535831408134330609u, 3677u },
+ { 5675049236146197433u, 6204770794376564579u, 93245887913u },
+ { 9953779846262904264u, 13869812122751887467u, 169336361298u },
+ { 12691978937179636241u, 14253229412394467550u, 82751884021u },
+ { 15523327331528198029u, 12776557610216045332u, 245772669114u },
+ { 15722603279568118520u, 16493640728678654060u, 186692618575u },
+ { 11838632364171816147u, 9434398296825833151u, 79894122055u },
+ { 7832751832367143680u, 8773374058285327850u, 71511439756u },
+ { 12167724027162940862u, 12932015276748029367u, 140475605560u },
+ { 4108211144748152962u, 16293958583527755209u, 56701045952u },
+ { 7530983398136343676u, 13511893936143127948u, 192883297264u },
+ { 1117587133956542355u, 18409936402005226436u, 240732481237u },
+ { 17134748625149490872u, 2189663026458466887u, 213998004652u },
+ { 4039918359454207848u, 9497725274248154664u, 172118701870u },
+ { 1830218764589441242u, 14766925481127792125u, 46514872718u },
+ { 637895981480825742u, 6982373971809635814u, 142800516634u },
+ { 8246879226348334620u, 8616702383006884794u, 26378515251u },
+ { 12389239568142583275u, 3059473300040871066u, 51467112372u },
+ { 14041257178803154398u, 17123843157031495558u, 180165854379u },
+ { 16312515716494630702u, 11210627174210626524u, 171928285397u },
+ { 17088522799596987756u, 15868067138625928592u, 213607729316u },
+ { 3588932524637852678u, 4467869511636937589u, 164860209643u },
+ { 107218049069817414u, 10052108125844341766u, 235242203691u },
+ { 1596707240462008334u, 7470588003218451534u, 43544925873u },
+ { 17461913142391587672u, 2613527085490786280u, 177404981387u },
+ { 4366474266651610090u, 3632919450036549616u, 139141679587u },
+ { 5539304013194805084u, 179367907231218916u, 227196940958u },
+ { 4762470619211987849u, 13553068184555874624u, 158009723553u },
+ { 10835638458986644717u, 8798774862365584481u, 161734713298u },
+ { 16141642290510052058u, 910911255817064881u, 210476982541u },
+ { 17390568670756355425u, 2304331144765093813u, 13049380598u },
+ { 12536768491333867107u, 12248937023083640360u, 246124918041u },
+ { 13145148522871947193u, 10206039550662130685u, 25664016206u },
+ { 5665349945233068642u, 12267881323837852537u, 78553270512u },
+ { 17074607537751066240u, 2858642007937891971u, 240665043179u },
+ { 6241525660962062336u, 14171330289750320841u, 235154967293u },
+ { 1142860629783085056u, 6601103619749017720u, 253768229354u },
+ { 16287527416870469632u, 4919573414486739494u, 234357846544u },
+ { 9028002014738513920u, 3401998285294974486u, 16266690609u },
+ { 16217462258161156096u, 10799436256515532233u, 49184422696u },
+ { 11529215046068469760u, 10083786644665753398u, 40585438612u },
+ { 0u, 6481194517685688896u, 148546643169u },
+ { 0u, 15104161756860547072u, 225351346258u },
+ { 0u, 9556039274244079616u, 82818798249u },
+ { 0u, 1376343134954323968u, 169518033927u },
+ { 0u, 15682488278596976640u, 7074611710u },
+ { 0u, 1506454075355430912u, 254850149393u },
+ { 0u, 1152921504606846976u, 17081665039u },
+ { 0u, 0u, 15062500000u },
+ { 0u, 0u, 160000000000u },
+ { 12170458846894708007u, 1035052700u, 0u },
+ { 1797330480103086687u, 1035052700659761896u, 0u },
+ { 10332188564497263448u, 6172559441576707976u, 56110319u },
+ { 7524259485079594225u, 15083329738554729992u, 239334615117u },
+ { 62681109059153749u, 10013126833549229036u, 77817668943u },
+ { 13480636451804037081u, 5817156823499936061u, 79542812693u },
+ { 6948168233012789004u, 5282692560913632718u, 21315348703u },
+ { 12015502974041806055u, 10252307034225766362u, 223286375337u },
+ { 7343801660689004040u, 17981881283247669689u, 169555778677u },
+ { 13670580858640731144u, 11689290159733383293u, 117974799737u },
+ { 5605073897566574851u, 5530668968487988249u, 121633677689u },
+ { 15387788940505247559u, 10083765740821947024u, 121299818165u },
+ { 17565181499678113030u, 2798423656816843533u, 181546642036u },
+ { 1893743623847493029u, 7614494481582904797u, 116151702850u },
+ { 10243498996716269784u, 17811318500083423695u, 66412782572u },
+ { 5619675836950314139u, 11641467412200329033u, 236965553510u },
+ { 10224869737511515088u, 17733593025296340645u, 102631085212u },
+ { 2574495974386198538u, 3689424000190644835u, 156961340004u },
+ { 7825756347302873178u, 14966634145516728506u, 100200004075u },
+ { 12071550103794656887u, 14171681941562070109u, 235811342862u },
+ { 7195875213867606691u, 8130575762882608170u, 14768248417u },
+ { 18271364438406891044u, 5234550794400656856u, 97440759395u },
+ { 16966521933952564706u, 3020576149360486378u, 99283765567u },
+ { 289920862029570129u, 3038675756589057221u, 63163745761u },
+ { 7804199568098625032u, 15470260187120878369u, 225164726942u },
+ { 5758118571242446585u, 3497929414841828746u, 158838644485u },
+ { 4030788293606375591u, 9935840636861015305u, 5189623133u },
+ { 4387716460037196127u, 3647355485153741471u, 93538623000u },
+ { 16807506478881285981u, 766100215038272793u, 24197723537u },
+ { 17033060604413529717u, 16128087474216800751u, 145041530375u },
+ { 10498418508292170054u, 16216631732633731297u, 7874305373u },
+ { 13237752038744465016u, 13760220872779997335u, 93879105367u },
+ { 17737618428304633155u, 3826276262374222087u, 87745943068u },
+ { 13546183833248825736u, 14938032745839181005u, 28207422851u },
+ { 826778452978976229u, 14479259995009508865u, 131809792377u },
+ { 13728076626990147292u, 2372033248156102437u, 121784922257u },
+ { 2794860281883592225u, 792005346826701645u, 145128588180u },
+ { 8680705720425908736u, 16278924527931792559u, 148042934695u },
+ { 731520517439488000u, 17442516423538940144u, 167882482266u },
+ { 13120812320768917504u, 13844184233048446u, 90945560710u },
+ { 2722954908557901824u, 13486193870480782357u, 134000750494u },
+ { 6860847004205973504u, 11931315179184648737u, 158731088034u },
+ { 6503197861922996224u, 16492562205587485405u, 162646797891u },
+ { 9223372036854775808u, 12128987217680380854u, 67894063588u },
+ { 0u, 10568123814189138176u, 228657513714u },
+ { 0u, 17007583519117541376u, 242572899139u },
+ { 0u, 143791533903052800u, 67921982950u },
+ { 0u, 12398714235792654336u, 230007794954u },
+ { 0u, 9659957317919047680u, 10672135645u },
+ { 0u, 9412523221204336640u, 221523667335u },
+ { 0u, 4611686018427387904u, 135510253906u },
+ { 0u, 0u, 82250000000u },
+ { 0u, 0u, 128000000000u },
+ { 12005656413127238315u, 15793u, 0u },
+ { 4821130826186787462u, 15793650827938u, 0u },
+ { 14377899467066168118u, 3237900842885170729u, 856u },
+ { 16575613239625444872u, 7515893506498066595u, 88175526956u },
+ { 4317827099179284377u, 7300206309181072546u, 44407437403u },
+ { 1242354770412171254u, 5999737279837044u, 91395744977u },
+ { 994838588328896609u, 7556839307242450651u, 209000325246u },
+ { 17283309862013060457u, 12946035041643640643u, 126409657079u },
+ { 124242522249856586u, 15885877642352740665u, 247701805965u },
+ { 11564608014666985609u, 10770818348246089568u, 141861175152u },
+ { 12401028575581654085u, 11635415503599551744u, 112583887232u },
+ { 2490725392961465727u, 6248053924100826098u, 128630757138u },
+ { 1949482237120640915u, 16894170802729859998u, 18338707681u },
+ { 15410502396166200087u, 6143589029651889899u, 225915834834u },
+ { 15694919529799920727u, 11812087701837886160u, 210333044628u },
+ { 10324869370171768388u, 7306705080150829180u, 148640334557u },
+ { 1631866459122189059u, 1485332570280714274u, 221396097276u },
+ { 172020494461226230u, 18042602303295630634u, 252080520039u },
+ { 12734610307908856767u, 13397029889257074369u, 103978091430u },
+ { 1467513250829340930u, 9948104869613411488u, 166726254445u },
+ { 13558759428494307997u, 10836066241170646532u, 109539287845u },
+ { 7915355143999496434u, 18330574781234459389u, 37587424327u },
+ { 2876370200608797469u, 666297360208433062u, 71993702450u },
+ { 343685370404989503u, 5035352224889324309u, 50036120052u },
+ { 4837266557407634630u, 1341745796439923765u, 244272966991u },
+ { 9622591415747161468u, 6846932182653803785u, 79072736185u },
+ { 16503783814424220982u, 6727685027257825533u, 185371172937u },
+ { 5377083431343591334u, 2168538874806877737u, 73364708536u },
+ { 16508482371299291595u, 17694936100676971444u, 184117556727u },
+ { 10515883558812249028u, 2163944241059563294u, 247959244408u },
+ { 63492062913405476u, 6727780864524301558u, 120117307652u },
+ { 11571919759617799697u, 8599551977795002615u, 4364713731u },
+ { 2956602334970088581u, 15428264807806859091u, 3466182646u },
+ { 13604736747717849839u, 2126771385339683557u, 246836367911u },
+ { 16573540719338151362u, 15094316562082972944u, 39115292507u },
+ { 12620703004601168151u, 8111300598225956802u, 91818264540u },
+ { 14649407809089591941u, 9481215200564260304u, 220439714486u },
+ { 11290375247898624432u, 16836674128623424708u, 182513977705u },
+ { 11020319450292874212u, 7087243115299722740u, 105912717933u },
+ { 8754634933362354176u, 2343560867338408810u, 109384200219u },
+ { 12976319450332528640u, 3431385749090422286u, 27127044689u },
+ { 17447331119627239424u, 3504545517469224582u, 81186015794u },
+ { 3665184902673858560u, 3333759805712094227u, 50189981793u },
+ { 12949678516038795264u, 3595183476205994775u, 97180723481u },
+ { 72057594037927936u, 14191566632569921303u, 25194895286u },
+ { 0u, 12917427671358095562u, 182769326368u },
+ { 0u, 3883793922738316288u, 32700255157u },
+ { 0u, 7857281689266421760u, 181210540890u },
+ { 0u, 15987081651486195712u, 90425944093u },
+ { 0u, 16827562156399525888u, 29866661432u },
+ { 0u, 7012737938513461248u, 56912223972u },
+ { 0u, 7385903388887613440u, 228380161285u },
+ { 0u, 0u, 5400390625u },
+ { 0u, 0u, 225000000000u },
+ { 9413159735776077452u, 240991986u, 0u },
+ { 14279163482889998017u, 240991986510288411u, 0u },
+ { 8693044629541194274u, 14135788013842776187u, 13064201u },
+ { 11863110253260222498u, 13284322918167594445u, 9766302603u },
+ { 8319293368489531245u, 7264587765474046287u, 139720144588u },
+ { 3376307525676489265u, 16176482219778368741u, 204393814091u },
+ { 13205662254759912523u, 5401983818872095469u, 75876928858u },
+ { 5276250334231686323u, 11208857446851049921u, 90292842129u },
+ { 13790198520922745052u, 13794690008281035639u, 145607633379u },
+ { 14195535250150996227u, 14519782740993303071u, 227747811643u },
+ { 16425228796427004035u, 10885858587044789123u, 59787118999u },
+ { 4295900841296269186u, 8710500938899914621u, 151590123576u },
+ { 4533952595483946442u, 1284182587483102819u, 56472197202u },
+ { 12885038019373447184u, 10346074482131502030u, 82069615677u },
+ { 12140736240487831910u, 9429804686255246574u, 61560861821u },
+ { 6927124077155322074u, 6412022633845121254u, 125511190736u },
+ { 12477788342407819890u, 8892351297529018260u, 208347596443u },
+ { 7980854329409711087u, 14098160105983060597u, 155482055329u },
+ { 2062671021810827996u, 13793833029739474340u, 161764262790u },
+ { 2739521363598172769u, 16367653765996977044u, 134747765186u },
+ { 12897585686593465638u, 10684788343333772342u, 194887292288u },
+ { 1127632646629044686u, 13272681218705145345u, 128579223536u },
+ { 4833775019274666364u, 11093568615497829248u, 240719513490u },
+ { 15867662672939849256u, 12488220765137758124u, 146601383559u },
+ { 2092350330982953557u, 3727114642519696453u, 135676987804u },
+ { 13330062299842493592u, 11549865375695057514u, 156202047289u },
+ { 4479193352178519263u, 11292809154908783229u, 57626119456u },
+ { 3149393938889064983u, 17723904861837310998u, 32612184410u },
+ { 9736379904070620767u, 14877674388187150875u, 90960814807u },
+ { 3816238703055069186u, 12178961950105734308u, 215806520344u },
+ { 11598915938798661975u, 4540604068069253114u, 24660222850u },
+ { 17821633264606555643u, 13832478722153359868u, 130246146639u },
+ { 2514623558764574316u, 1308046668730371491u, 79749860174u },
+ { 4976730480406253215u, 18400531023544756800u, 78070909351u },
+ { 17276563697191611637u, 9789823458621466539u, 167997494785u },
+ { 12524734095940998814u, 1924870562610267306u, 1530707393u },
+ { 15331551308930355164u, 5290016144582400923u, 193104347442u },
+ { 15417115581125943816u, 15162883663174059077u, 50286772349u },
+ { 6010750237807115593u, 8078086116520046390u, 125821981570u },
+ { 5624630987553628432u, 15731407332173190623u, 130437913925u },
+ { 14881848243837640704u, 5346389182763011056u, 69852801300u },
+ { 15281613886881529856u, 6368422217216252401u, 20289828338u },
+ { 14057902358273196032u, 2961453088119116188u, 242345232860u },
+ { 16075318494433902592u, 10932141691610170525u, 220160540693u },
+ { 13891916000577716224u, 11034016191361782553u, 21592632588u },
+ { 7205759403792793600u, 5455325785621453219u, 12598155216u },
+ { 0u, 7735615202566149352u, 208295733803u },
+ { 0u, 7502396497775759360u, 43419348540u },
+ { 0u, 1601286435751591936u, 60406705729u },
+ { 0u, 11449383158571597824u, 65086805911u },
+ { 0u, 13043944595690356736u, 151620672304u },
+ { 0u, 7773494431818186752u, 48707113653u },
+ { 0u, 9943947977234055168u, 181421401977u },
+ { 0u, 0u, 121539062500u },
+ { 0u, 0u, 228000000000u },
+ { 4535831408134330609u, 3677u, 0u },
+ { 6204770794376564579u, 3677245887913u, 0u },
+ { 13869812122751887467u, 6343817245135589714u, 199u },
+ { 14253229412394467550u, 17549323075660516085u, 199343899021u },
+ { 12776557610216045332u, 3948641822109421754u, 141951350710u },
+ { 16493640728678654060u, 1750739713693534543u, 182214056302u },
+ { 9434398296825833151u, 962163898128633415u, 110094907790u },
+ { 8773374058285327850u, 7967320249386531212u, 142052159009u },
+ { 12932015276748029367u, 3018466665533383224u, 33431909296u },
+ { 16293958583527755209u, 15076865731854945472u, 176163631405u },
+ { 13511893936143127948u, 691187172844604400u, 45817318529u },
+ { 18409936402005226436u, 13274492813370992341u, 129037469331u },
+ { 2189663026458466887u, 6364168818499152300u, 147719611697u },
+ { 9497725274248154664u, 17599380787401914158u, 49345002282u },
+ { 14766925481127792125u, 3782323149461692814u, 42954064344u },
+ { 6982373971809635814u, 14470163442442237466u, 216205040148u },
+ { 8616702383006884794u, 476109872130437939u, 20784429132u },
+ { 3059473300040871066u, 16330548844673355700u, 76025809967u },
+ { 17123843157031495558u, 14089158961463739563u, 47885280826u },
+ { 11210627174210626524u, 13385510793074798805u, 58763774837u },
+ { 15868067138625928592u, 1549401308746959012u, 117725629994u },
+ { 4467869511636937589u, 4607384943843027435u, 42083993213u },
+ { 10052108125844341766u, 5157353797716093483u, 125249766838u },
+ { 7470588003218451534u, 10846828782671550129u, 182279580709u },
+ { 2613527085490786280u, 9915857350819131531u, 37588007766u },
+ { 3632919450036549616u, 1673544973504317923u, 86537539704u },
+ { 179367907231218916u, 14780986291622785694u, 120090723054u },
+ { 13553068184555874624u, 8168111319515466401u, 238801278872u },
+ { 8798774862365584481u, 16345760387859734482u, 152442794201u },
+ { 910911255817064881u, 3177475373321281805u, 217886105446u },
+ { 2304331144765093813u, 2558676822419554038u, 102172251285u },
+ { 12248937023083640360u, 8813474062662382873u, 149138706148u },
+ { 10206039550662130685u, 5426294560236228430u, 228477779386u },
+ { 12267881323837852537u, 9919177474128333040u, 186294160017u },
+ { 2858642007937891971u, 6197383943089627371u, 145537719688u },
+ { 14171330289750320841u, 13673239314867423997u, 136335960856u },
+ { 6601103619749017720u, 9309584098968723946u, 24741227788u },
+ { 4919573414486739494u, 4647101757759615504u, 12504673565u },
+ { 3401998285294974486u, 1405809295505096753u, 29251919891u },
+ { 10799436256515532233u, 11332704079573859112u, 19076209074u },
+ { 10083786644665753398u, 2960072434514044308u, 178614347119u },
+ { 6481194517685688896u, 3887266602785432801u, 111160465848u },
+ { 15104161756860547072u, 14545546084687849554u, 184210729144u },
+ { 9556039274244079616u, 4617763804182385321u, 184788515633u },
+ { 1376343134954323968u, 7857823815580249095u, 49250329477u },
+ { 15682488278596976640u, 10939326736548364798u, 133425973482u },
+ { 1506454075355430912u, 12262012446566951953u, 234593022090u },
+ { 1152921504606846976u, 12555024338687723023u, 138664725026u },
+ { 0u, 3332969632922829472u, 34680609233u },
+ { 0u, 15535060143360327680u, 209180680645u },
+ { 0u, 15794322927987458048u, 197842157297u },
+ { 0u, 10571474314433921024u, 241856211961u },
+ { 0u, 16679514427547975680u, 249573080770u },
+ { 0u, 16925653299565166592u, 194904198288u },
+ { 0u, 16717361816799281152u, 144917541503u },
+ { 0u, 0u, 127906250000u },
+ { 0u, 0u, 16000000000u },
+ { 6172559441576707976u, 56110319u, 0u },
+ { 15083329738554729992u, 56110319334615117u, 0u },
+ { 10013126833549229036u, 9335385384027907407u, 3041746u },
+ { 5817156823499936061u, 13237828406194798613u, 210506072255u },
+ { 5282692560913632718u, 15667486867836528863u, 191717624115u },
+ { 10252307034225766362u, 17982325043592934313u, 51849336164u },
+ { 17981881283247669689u, 17159117626917379189u, 100974823793u },
+ { 11689290159733383293u, 8336208968408929657u, 113930197630u },
+ { 5530668968487988249u, 12767090573379150201u, 126451906793u },
+ { 10083765740821947024u, 14736070002412246709u, 233692105366u },
+ { 2798423656816843533u, 9697296975344560756u, 150798843955u },
+ { 7614494481582904797u, 7291706381199103298u, 51525691522u },
+ { 17811318500083423695u, 18098546597780825068u, 130395284194u },
+ { 11641467412200329033u, 132913902678533478u, 226981124177u },
+ { 17733593025296340645u, 1879347741692007580u, 81007205277u },
+ { 3689424000190644835u, 4056624629214083684u, 157101879645u },
+ { 14966634145516728506u, 14713227692042795499u, 93219910061u },
+ { 14171681941562070109u, 7366415124022528526u, 173797605671u },
+ { 8130575762882608170u, 825770353378039393u, 39399334164u },
+ { 5234550794400656856u, 10244023944395357795u, 20044765100u },
+ { 3020576149360486378u, 14302658294713551167u, 172555329650u },
+ { 3038675756589057221u, 14246653166206862817u, 114775348659u },
+ { 15470260187120878369u, 12404486258134291102u, 179772312615u },
+ { 3497929414841828746u, 8887442218637942533u, 39672448547u },
+ { 9935840636861015305u, 1186724038081863005u, 35481789208u },
+ { 3647355485153741471u, 211331772484951576u, 24064332439u },
+ { 766100215038272793u, 6311919513247413649u, 151011456318u },
+ { 16128087474216800751u, 8131780018703965703u, 62342169842u },
+ { 16216631732633731297u, 2262544347226725725u, 242440824678u },
+ { 13760220872779997335u, 15318188749880522583u, 102122652774u },
+ { 3826276262374222087u, 1073117094162650652u, 102830400676u },
+ { 14938032745839181005u, 4447950380665871747u, 164058173794u },
+ { 14479259995009508865u, 5373227185066463609u, 98241123873u },
+ { 2372033248156102437u, 6739731406934274193u, 33291283229u },
+ { 792005346826701645u, 12328812617001239444u, 29365361571u },
+ { 16278924527931792559u, 3246111484407310759u, 163668346271u },
+ { 17442516423538940144u, 3250825415176839770u, 159175972056u },
+ { 13844184233048446u, 16146270540000862342u, 216176227598u },
+ { 13486193870480782357u, 15686773375425916830u, 14875291079u },
+ { 11931315179184648737u, 11920791905793880226u, 199850381688u },
+ { 16492562205587485405u, 1853290561644080707u, 120646227424u },
+ { 12128987217680380854u, 12157689141506159076u, 224100467082u },
+ { 10568123814189138176u, 18100318838862562546u, 138659069648u },
+ { 17007583519117541376u, 7171257882533475139u, 208981220250u },
+ { 143791533903052800u, 14477550873015039462u, 154388754668u },
+ { 12398714235792654336u, 8109481182495403274u, 236784829605u },
+ { 9659957317919047680u, 14565395719337663965u, 165439615855u },
+ { 9412523221204336640u, 1860318978161305991u, 111789591684u },
+ { 4611686018427387904u, 16268646275151585618u, 132100848093u },
+ { 0u, 13759019338835519104u, 221881925081u },
+ { 0u, 17003783176010661888u, 217745877932u },
+ { 0u, 18357489540307877888u, 172921776932u },
+ { 0u, 905481790074912768u, 36995161502u },
+ { 0u, 3638882110636294144u, 158049086266u },
+ { 0u, 9011702854368362496u, 58197264194u },
+ { 0u, 11529215046068469760u, 66488525390u },
+ { 0u, 0u, 78625000000u },
+ { 0u, 0u, 64000000000u },
+ { 3237900842885170729u, 856u, 0u },
+ { 7515893506498066595u, 856175526956u, 0u },
+ { 7300206309181072546u, 7625299565768063067u, 46u },
+ { 5999737279837044u, 13889021769065194705u, 46413368317u },
+ { 7556839307242450651u, 14498170692313014398u, 253752925378u },
+ { 12946035041643640643u, 1541631360972245751u, 194785947408u },
+ { 15885877642352740665u, 9903958882920799117u, 16083572003u },
+ { 10770818348246089568u, 15744148547788062576u, 35536894686u },
+ { 11635415503599551744u, 17936061801321712000u, 222853492002u },
+ { 6248053924100826098u, 9986394078324430610u, 34972315858u },
+ { 16894170802729859998u, 13849561248103430369u, 210541363507u },
+ { 6143589029651889899u, 12142378807953854930u, 51750786219u },
+ { 11812087701837886160u, 2513847703931031444u, 171658239674u },
+ { 7306705080150829180u, 1752183758129038045u, 186136275957u },
+ { 1485332570280714274u, 15824833342220556540u, 245094986071u },
+ { 18042602303295630634u, 8168747198299470695u, 87857865934u },
+ { 13397029889257074369u, 17414799840149357478u, 206442828672u },
+ { 9948104869613411488u, 83147520704167789u, 128944058191u },
+ { 10836066241170646532u, 2383542703041471269u, 79004507436u },
+ { 18330574781234459389u, 15540952725549257799u, 44129212108u },
+ { 666297360208433062u, 6949835416232048690u, 204842476735u },
+ { 5035352224889324309u, 15398868937585367540u, 191376751332u },
+ { 1341745796439923765u, 14710915985268256079u, 228834774357u },
+ { 6846932182653803785u, 9665704836873335737u, 85797480353u },
+ { 6727685027257825533u, 2528789298740305993u, 161523978909u },
+ { 2168538874806877737u, 10562914675687726264u, 157137085942u },
+ { 17694936100676971444u, 17671658300096837111u, 246572616751u },
+ { 2163944241059563294u, 356471401631698552u, 47957982516u },
+ { 6727780864524301558u, 7450677157218003204u, 52019324353u },
+ { 8599551977795002615u, 317174560787152643u, 193403902018u },
+ { 15428264807806859091u, 7251937674440720374u, 66017194067u },
+ { 2126771385339683557u, 1252631516699038247u, 83393128329u },
+ { 15094316562082972944u, 10818009768860843867u, 137067905290u },
+ { 8111300598225956802u, 12330114194950162396u, 10586445484u },
+ { 9481215200564260304u, 15826681638261168822u, 172668416829u },
+ { 16836674128623424708u, 14240150078499211625u, 61857966130u },
+ { 7087243115299722740u, 10725372116242125421u, 50771960082u },
+ { 2343560867338408810u, 8434925524647833627u, 18581423587u },
+ { 3431385749090422286u, 17133902668520348241u, 227457258228u },
+ { 3504545517469224582u, 15093996047981365810u, 244928830724u },
+ { 3333759805712094227u, 6187974166976813153u, 4818247165u },
+ { 3595183476205994775u, 13946144707720259865u, 253335450751u },
+ { 14191566632569921303u, 9138079832881862582u, 127756022019u },
+ { 12917427671358095562u, 6600697628576225568u, 3495376300u },
+ { 3883793922738316288u, 8137099536646556597u, 172357824535u },
+ { 7857281689266421760u, 14169855543453903706u, 23441113049u },
+ { 15987081651486195712u, 3706403268650100765u, 217768149408u },
+ { 16827562156399525888u, 14736932266877982264u, 160200924523u },
+ { 7012737938513461248u, 18004795125138956004u, 107798890698u },
+ { 7385903388887613440u, 9068489270661002501u, 202976041899u },
+ { 0u, 7758835715193269217u, 171491603788u },
+ { 0u, 16943947811135261184u, 76420607326u },
+ { 0u, 6745843108403216384u, 94918533251u },
+ { 0u, 12338229654069444608u, 131365692887u },
+ { 0u, 14358176069683511296u, 215668856769u },
+ { 0u, 7083775185760813056u, 193778358284u },
+ { 0u, 5350276357316149248u, 12384012222u },
+ { 0u, 9223372036854775808u, 190290039062u },
+ { 0u, 0u, 22500000000u },
+ { 14135788013842776187u, 13064201u, 0u },
+ { 13284322918167594445u, 13064201766302603u, 0u },
+ { 7264587765474046287u, 14699116688460625612u, 708211u },
+ { 16176482219778368741u, 6684126021499623499u, 115796840712u },
+ { 5401983818872095469u, 12614606079692508506u, 8362347197u },
+ { 11208857446851049921u, 15358270276683001489u, 189683839165u },
+ { 13794690008281035639u, 18077126190953408995u, 189832573499u },
+ { 14519782740993303071u, 7864121581925945659u, 59979962974u },
+ { 10885858587044789123u, 3518026639210514839u, 94426314885u },
+ { 8710500938899914621u, 4698310163811252280u, 133190712606u },
+ { 1284182587483102819u, 6101155398200416338u, 30254695904u },
+ { 10346074482131502030u, 16049178580360033341u, 224330744296u },
+ { 9429804686255246574u, 3167464649127375997u, 232870027714u },
+ { 6412022633845121254u, 12778923935480989904u, 194171708602u },
+ { 8892351297529018260u, 11875553912612980379u, 186692746854u },
+ { 14098160105983060597u, 10628760849351697057u, 102643775067u },
+ { 13793833029739474340u, 3408944711673234310u, 91576186280u },
+ { 16367653765996977044u, 2102091496050506178u, 168184799263u },
+ { 10684788343333772342u, 6254611118630245760u, 31113954608u },
+ { 13272681218705145345u, 2647941151989776368u, 48339063148u },
+ { 11093568615497829248u, 8855437735410157458u, 108143545177u },
+ { 12488220765137758124u, 10184270603132180103u, 89480054241u },
+ { 3727114642519696453u, 12079083162535627164u, 225552090415u },
+ { 11549865375695057514u, 5952952868716156729u, 47654808410u },
+ { 11292809154908783229u, 11958907037815852320u, 90322710221u },
+ { 17723904861837310998u, 10101562137321697626u, 205648293649u },
+ { 14877674388187150875u, 13633527411279258327u, 17547606780u },
+ { 12178961950105734308u, 16555627393501768728u, 252739075001u },
+ { 4540604068069253114u, 6359650463500280706u, 185897482359u },
+ { 13832478722153359868u, 8093923611102181967u, 119344757342u },
+ { 1308046668730371491u, 2848827352928635726u, 94438772478u },
+ { 18400531023544756800u, 4686723431961561511u, 254154435240u },
+ { 9789823458621466539u, 6245554925867652609u, 168254067786u },
+ { 1924870562610267306u, 17527406820792516033u, 74338572210u },
+ { 5290016144582400923u, 12119966834653692210u, 178950162627u },
+ { 15162883663174059077u, 11606502845877928061u, 195657024718u },
+ { 8078086116520046390u, 424311496652297090u, 206629189780u },
+ { 15731407332173190623u, 5977664048034127173u, 148023001972u },
+ { 5346389182763011056u, 6702712461535947028u, 116324049817u },
+ { 6368422217216252401u, 11384349854055020018u, 153363354770u },
+ { 2961453088119116188u, 3782955013294836188u, 146617146842u },
+ { 10932141691610170525u, 3531805968821207061u, 218205074402u },
+ { 11034016191361782553u, 3867566898657193228u, 226191459585u },
+ { 5455325785621453219u, 12688734637425072080u, 1209661221u },
+ { 7735615202566149352u, 18435982764454619691u, 37687857682u },
+ { 7502396497775759360u, 4728836163964677692u, 18999416628u },
+ { 1601286435751591936u, 2120012917348838977u, 52256350722u },
+ { 11449383158571597824u, 9856965465824679831u, 2114926130u },
+ { 13043944595690356736u, 11217197671061248816u, 50534347168u },
+ { 7773494431818186752u, 3840562972677739189u, 160608085504u },
+ { 9943947977234055168u, 17104366978925258617u, 208197335u },
+ { 0u, 16177877219841993444u, 215927229591u },
+ { 0u, 7338522384267208704u, 151877004481u },
+ { 0u, 10935240458612244480u, 193397822095u },
+ { 0u, 1732868046462124032u, 143592800573u },
+ { 0u, 557965042578882560u, 61093938965u },
+ { 0u, 10454684322475540480u, 21030247345u },
+ { 0u, 13907115649320091648u, 177566749572u },
+ { 0u, 0u, 132753906250u },
+ { 0u, 0u, 74000000000u },
+ { 6343817245135589714u, 199u, 0u },
+ { 17549323075660516085u, 199343899021u, 0u },
+ { 3948641822109421754u, 14876458284855834550u, 10u },
+ { 1750739713693534543u, 10450704926982265198u, 10806454419u },
+ { 962163898128633415u, 5385653213018257806u, 147566533849u },
+ { 7967320249386531212u, 12735569669880147489u, 217291956845u },
+ { 3018466665533383224u, 3619762560577729456u, 109690396615u },
+ { 15076865731854945472u, 11123448126624084269u, 199196227721u },
+ { 691187172844604400u, 4072715118852885633u, 137603003331u },
+ { 13274492813370992341u, 18239087231420827283u, 195220782328u },
+ { 6364168818499152300u, 423431461216085297u, 248988742900u },
+ { 17599380787401914158u, 9360976716520160042u, 244022954265u },
+ { 3782323149461692814u, 11655927117263208920u, 25507459564u },
+ { 14470163442442237466u, 2646622721938364948u, 236631869075u },
+ { 476109872130437939u, 4496462484548171852u, 147143473705u },
+ { 16330548844673355700u, 13140258519803350063u, 41243753719u },
+ { 14089158961463739563u, 13089764333320627770u, 247712334841u },
+ { 13385510793074798805u, 6926286827289840501u, 249709597546u },
+ { 1549401308746959012u, 4985580225290866218u, 106375474761u },
+ { 4607384943843027435u, 10478790837359789693u, 73270268845u },
+ { 5157353797716093483u, 10041191967455692214u, 173568056389u },
+ { 10846828782671550129u, 5035461258013813797u, 69544334107u },
+ { 9915857350819131531u, 14208759661559249750u, 27272972901u },
+ { 1673544973504317923u, 12347272163241758840u, 101770258404u },
+ { 14780986291622785694u, 3372534174410277614u, 228669346965u },
+ { 8168111319515466401u, 17226704187274712984u, 149182825443u },
+ { 16345760387859734482u, 4250480179449852121u, 227933861505u },
+ { 3177475373321281805u, 4303723537755414374u, 129230418992u },
+ { 2558676822419554038u, 8680503847344854165u, 48233305320u },
+ { 8813474062662382873u, 8817608623911079652u, 232470571056u },
+ { 5426294560236228430u, 5692030448698539450u, 48478003521u },
+ { 9919177474128333040u, 16908836314686769809u, 65308565588u },
+ { 6197383943089627371u, 6073762347067727240u, 84916629853u },
+ { 13673239314867423997u, 10931066692585106200u, 93329259316u },
+ { 9309584098968723946u, 14466591364061539596u, 52592574312u },
+ { 4647101757759615504u, 4958077340960173341u, 104784235489u },
+ { 1405809295505096753u, 4076890037156765715u, 225268777911u },
+ { 11332704079573859112u, 14083973146609179058u, 183221008651u },
+ { 2960072434514044308u, 2565183738039805295u, 11763493714u },
+ { 3887266602785432801u, 1482420938751351224u, 82139058889u },
+ { 14545546084687849554u, 2151089495335413944u, 201080362200u },
+ { 4617763804182385321u, 3738604531753220913u, 216116610795u },
+ { 7857823815580249095u, 14195686514836005765u, 235202670157u },
+ { 10939326736548364798u, 17808833916231796970u, 77769549707u },
+ { 12262012446566951953u, 1302384553035657354u, 139965418821u },
+ { 12555024338687723023u, 1672033517974833698u, 69070602408u },
+ { 3332969632922829472u, 11673925532927662545u, 168090641118u },
+ { 15535060143360327680u, 3905334232240480709u, 222632844771u },
+ { 15794322927987458048u, 17411087320267472625u, 227211708592u },
+ { 10571474314433921024u, 16573305231063706617u, 176943856934u },
+ { 16679514427547975680u, 15481103236037148354u, 38898440676u },
+ { 16925653299565166592u, 907440704754420880u, 228839232288u },
+ { 16717361816799281152u, 3224970785139077759u, 32049192459u },
+ { 0u, 10560826509734608144u, 11174826016u },
+ { 0u, 4700940027512659968u, 32572503552u },
+ { 0u, 9733694683502084096u, 254838469u },
+ { 0u, 1995535635724632064u, 197527664646u },
+ { 0u, 10629833226245373952u, 6108178203u },
+ { 0u, 15729384648544878592u, 27576244413u },
+ { 0u, 7205759403792793600u, 189852691650u },
+ { 0u, 0u, 194390625000u },
+ { 0u, 0u, 232000000000u },
+ { 9335385384027907407u, 3041746u, 0u },
+ { 13237828406194798613u, 3041746506072255u, 0u },
+ { 15667486867836528863u, 7535526066623007027u, 164893u },
+ { 17982325043592934313u, 11302146918409311588u, 29408501686u },
+ { 17159117626917379189u, 2480833299122194801u, 182612690612u },
+ { 8336208968408929657u, 11513226205589330558u, 180134486242u },
+ { 12767090573379150201u, 4073957068281936105u, 226624133243u },
+ { 14736070002412246709u, 3729887061093812886u, 123220849655u },
+ { 9697296975344560756u, 13616911779739451443u, 247202197582u },
+ { 7291706381199103298u, 13039053282195777666u, 78738174266u },
+ { 18098546597780825068u, 14490756113210417890u, 58706848494u },
+ { 132913902678533478u, 17432486112977557585u, 238785545462u },
+ { 1879347741692007580u, 14308820825344039837u, 246945016965u },
+ { 4056624629214083684u, 4190949538817536349u, 133775682731u },
+ { 14713227692042795499u, 13616552502810964397u, 171227191829u },
+ { 7366415124022528526u, 4898145803694965031u, 21738154790u },
+ { 825770353378039393u, 1399036321001644308u, 38265529016u },
+ { 10244023944395357795u, 17170331128243738540u, 184075841910u },
+ { 14302658294713551167u, 10641321388205367410u, 118930805515u },
+ { 14246653166206862817u, 6648873641312572851u, 11576867188u },
+ { 12404486258134291102u, 5988456964560374823u, 116360436162u },
+ { 8887442218637942533u, 9972593758348346915u, 194324634902u },
+ { 1186724038081863005u, 16709668921872818968u, 22540615390u },
+ { 211331772484951576u, 6094829131503407767u, 222905832967u },
+ { 6311919513247413649u, 4892016478899926334u, 7330401349u },
+ { 8131780018703965703u, 13150857244079031538u, 69265196744u },
+ { 2262544347226725725u, 12983943395318785894u, 200712909399u },
+ { 15318188749880522583u, 15341644584614757478u, 87703860981u },
+ { 1073117094162650652u, 7507635124856644772u, 245831672219u },
+ { 4447950380665871747u, 11619655367084544354u, 155406989715u },
+ { 5373227185066463609u, 11553116952478783009u, 147629902779u },
+ { 6739731406934274193u, 17392150014233193245u, 187626295724u },
+ { 12328812617001239444u, 8877887560294980515u, 172942830341u },
+ { 3246111484407310759u, 18404180619915609503u, 5481271248u },
+ { 3250825415176839770u, 10079413095288181976u, 208997692630u },
+ { 16146270540000862342u, 14102802966539105550u, 214546406078u },
+ { 15686773375425916830u, 13333966026135891399u, 190764514480u },
+ { 11920791905793880226u, 12344968670173516152u, 176722835746u },
+ { 1853290561644080707u, 10577007819804726752u, 34669222092u },
+ { 12157689141506159076u, 15337041354031088010u, 204573380742u },
+ { 18100318838862562546u, 14333607285614673616u, 134831422677u },
+ { 7171257882533475139u, 17171597563219696538u, 213777026407u },
+ { 14477550873015039462u, 2849642930482147564u, 103930874169u },
+ { 8109481182495403274u, 14791248423979435173u, 57154479452u },
+ { 14565395719337663965u, 13882371364576310127u, 92801835183u },
+ { 1860318978161305991u, 11735995808941329540u, 175752564859u },
+ { 16268646275151585618u, 11376996674339273181u, 123636209607u },
+ { 13759019338835519104u, 9849638057168043481u, 199616748225u },
+ { 17003783176010661888u, 18241520229279361964u, 193533949948u },
+ { 18357489540307877888u, 1865852368526961444u, 252988874793u },
+ { 905481790074912768u, 10601487369276448158u, 41101148059u },
+ { 3638882110636294144u, 15999931310312762170u, 155574707781u },
+ { 9011702854368362496u, 5773775867713013570u, 69867358014u },
+ { 11529215046068469760u, 17726239863982547534u, 62312997016u },
+ { 0u, 9711316695888316992u, 152960941388u },
+ { 0u, 17872002620723724288u, 76526451532u },
+ { 0u, 7429694208660733952u, 76968843203u },
+ { 0u, 1782821038871019520u, 195402764530u },
+ { 0u, 3225250234313474048u, 242096646922u },
+ { 0u, 10009250171830927360u, 10174841165u },
+ { 0u, 1152921504606846976u, 77542602539u },
+ { 0u, 0u, 43062500000u },
+ { 0u, 0u, 160000000000u },
+ { 7625299565768063067u, 46u, 0u },
+ { 13889021769065194705u, 46413368317u, 0u },
+ { 14498170692313014398u, 9519880170333822146u, 2u },
+ { 1541631360972245751u, 2285186318012886800u, 2516073738u },
+ { 9903958882920799117u, 9706420951402272035u, 10123880198u },
+ { 15744148547788062576u, 2369632031840402142u, 6526186134u },
+ { 17936061801321712000u, 15599123897979399458u, 150128458009u },
+ { 9986394078324430610u, 17579576584023912658u, 25845630200u },
+ { 13849561248103430369u, 3480927339588501811u, 248952990756u },
+ { 12142378807953854930u, 3547346616671294635u, 36188701449u },
+ { 2513847703931031444u, 7705317123868384954u, 9192302045u },
+ { 1752183758129038045u, 4969425237478353909u, 221417706078u },
+ { 15824833342220556540u, 17043246700132217175u, 94269393081u },
+ { 8168747198299470695u, 17053788362783499470u, 185923916254u },
+ { 17414799840149357478u, 11102988228454224768u, 222924487719u },
+ { 83147520704167789u, 16944305387801685839u, 39601894197u },
+ { 2383542703041471269u, 11725142977459199276u, 53918552635u },
+ { 15540952725549257799u, 8175984171998533324u, 59635621274u },
+ { 6949835416232048690u, 1372352885142856895u, 154443220990u },
+ { 15398868937585367540u, 17975093466502888164u, 254074395398u },
+ { 14710915985268256079u, 6467823391459085653u, 6974431769u },
+ { 9665704836873335737u, 11319386883146885025u, 25350621408u },
+ { 2528789298740305993u, 9141999262922068637u, 224613625192u },
+ { 10562914675687726264u, 1587330393383478774u, 104495588773u },
+ { 17671658300096837111u, 884187548095712303u, 165086049353u },
+ { 356471401631698552u, 488841225726377268u, 73047931903u },
+ { 7450677157218003204u, 17462624199405856193u, 255026500135u },
+ { 317174560787152643u, 13183677579115583554u, 39946650754u },
+ { 7251937674440720374u, 11645015818917277779u, 130714688593u },
+ { 1252631516699038247u, 8760523002035971977u, 81631277572u },
+ { 10818009768860843867u, 10068817678491468042u, 4474908903u },
+ { 12330114194950162396u, 1273658177787418284u, 231545831700u },
+ { 15826681638261168822u, 3100019384328057661u, 20069045148u },
+ { 14240150078499211625u, 10363063568089458738u, 156168052387u },
+ { 10725372116242125421u, 13030756371481403666u, 163561782801u },
+ { 8434925524647833627u, 6538878900684195299u, 17706398718u },
+ { 17133902668520348241u, 8984884716779098868u, 254354473335u },
+ { 15093996047981365810u, 8728727397070363908u, 119487071576u },
+ { 6187974166976813153u, 6398650562917867005u, 88473185260u },
+ { 13946144707720259865u, 1190873176164938879u, 236346871542u },
+ { 9138079832881862582u, 4383628525805121795u, 246064557364u },
+ { 6600697628576225568u, 10189374699734119852u, 52237636978u },
+ { 8137099536646556597u, 5276291920541626391u, 114552367109u },
+ { 14169855543453903706u, 2692252373800386521u, 5286028358u },
+ { 3706403268650100765u, 11578684995169173920u, 70145947293u },
+ { 14736932266877982264u, 5799408022254132587u, 157627681771u },
+ { 18004795125138956004u, 15548569837712345290u, 235314386538u },
+ { 9068489270661002501u, 15763030464322902955u, 106842889659u },
+ { 7758835715193269217u, 13257749746581255500u, 187854515593u },
+ { 16943947811135261184u, 16152470009188707678u, 137718704053u },
+ { 6745843108403216384u, 13806790848493904003u, 181875627153u },
+ { 12338229654069444608u, 11981226523265951191u, 145748467631u },
+ { 14358176069683511296u, 5133628726077003713u, 175649503591u },
+ { 7083775185760813056u, 16183955741910833164u, 103278294570u },
+ { 5350276357316149248u, 13640425554331371454u, 42877333998u },
+ { 9223372036854775808u, 18108120906868035862u, 238739448950u },
+ { 0u, 6324011669895037184u, 118981643201u },
+ { 0u, 10444437689515769856u, 193342825359u },
+ { 0u, 12324712543665782784u, 143566194101u },
+ { 0u, 13928941951563857920u, 181668124005u },
+ { 0u, 3975288688270639104u, 101755089456u },
+ { 0u, 11141905478114607104u, 48215500831u },
+ { 0u, 4611686018427387904u, 31604003906u },
+ { 0u, 0u, 66250000000u },
+ { 0u, 0u, 128000000000u },
+ { 14699116688460625612u, 708211u, 0u },
+ { 6684126021499623499u, 708211796840712u, 0u },
+ { 12614606079692508506u, 4398362855256705725u, 38392u },
+ { 15358270276683001489u, 2812083125569302717u, 248238435728u },
+ { 18077126190953408995u, 12868509142973100603u, 144152443331u },
+ { 7864121581925945659u, 8726243776748165726u, 195697603278u },
+ { 3518026639210514839u, 358304413426858117u, 206473050623u },
+ { 4698310163811252280u, 3180720351566429470u, 255019423721u },
+ { 6101155398200416338u, 14053818240400098784u, 233172427195u },
+ { 16049178580360033341u, 7340140541492429288u, 187761859013u },
+ { 3167464649127375997u, 1323571167904965058u, 197397909816u },
+ { 12778923935480989904u, 14463851737583396026u, 56071750936u },
+ { 11875553912612980379u, 15122784818916048486u, 24784086973u },
+ { 10628760849351697057u, 13557974621377508955u, 189819807807u },
+ { 3408944711673234310u, 17525172074563876264u, 63734979276u },
+ { 2102091496050506178u, 15148880683074215967u, 204950041481u },
+ { 6254611118630245760u, 6744828147558597936u, 137821222467u },
+ { 2647941151989776368u, 9799290779647971692u, 67365637866u },
+ { 8855437735410157458u, 11170890203898678105u, 234531220617u },
+ { 10184270603132180103u, 7068779781287527905u, 137605575171u },
+ { 12079083162535627164u, 14474741922505540911u, 3383199319u },
+ { 5952952868716156729u, 17107062680405191514u, 87784677331u },
+ { 11958907037815852320u, 2712598571300237005u, 211927375726u },
+ { 10101562137321697626u, 3767556054903418641u, 110147050263u },
+ { 13633527411279258327u, 18158239681706277628u, 23204239622u },
+ { 16555627393501768728u, 10531652712128330681u, 6984360145u },
+ { 6359650463500280706u, 9548395326934120567u, 209570922037u },
+ { 8093923611102181967u, 15875647850297719390u, 53517619547u },
+ { 2848827352928635726u, 8215825295203192574u, 91860620594u },
+ { 4686723431961561511u, 12747310908260543144u, 50445380781u },
+ { 6245554925867652609u, 77706528053613642u, 173691033109u },
+ { 17527406820792516033u, 6024737704056756146u, 21004212479u },
+ { 12119966834653692210u, 6819452388570089667u, 255326601685u },
+ { 11606502845877928061u, 13695926775373186254u, 213369683254u },
+ { 424311496652297090u, 3746531715392682132u, 54742457678u },
+ { 5977664048034127173u, 4717376233154528116u, 78203099891u },
+ { 6702712461535947028u, 385190957950313369u, 243255729478u },
+ { 11384349854055020018u, 12388374310648616082u, 70020881243u },
+ { 3782955013294836188u, 1078067332084407770u, 91671575117u },
+ { 3531805968821207061u, 3257295319358714850u, 77058442147u },
+ { 3867566898657193228u, 1545453099660723457u, 163176578333u },
+ { 12688734637425072080u, 7495477664653506341u, 29083779180u },
+ { 18435982764454619691u, 7225503732673614354u, 108406330658u },
+ { 4728836163964677692u, 3935478326103643956u, 34391695342u },
+ { 2120012917348838977u, 10082240682742686210u, 238213342707u },
+ { 9856965465824679831u, 10838712705567897138u, 243546559362u },
+ { 11217197671061248816u, 2142546572501643680u, 130587567793u },
+ { 3840562972677739189u, 7893042119150331392u, 177116147682u },
+ { 17104366978925258617u, 12084811642251302615u, 226427882670u },
+ { 16177877219841993444u, 15317234482572954775u, 174655118951u },
+ { 7338522384267208704u, 2283226355108359361u, 103830348945u },
+ { 10935240458612244480u, 13359725152575722127u, 145123773948u },
+ { 1732868046462124032u, 13126551011491594557u, 252724232151u },
+ { 557965042578882560u, 3598021288691861269u, 215711591756u },
+ { 10454684322475540480u, 16462621795896662961u, 76195049124u },
+ { 13907115649320091648u, 14682112756964627332u, 164892440515u },
+ { 0u, 7174112100896070218u, 195795918927u },
+ { 0u, 5023109019590616064u, 79388909396u },
+ { 0u, 10765223023086141440u, 84272303285u },
+ { 0u, 8228137177297453056u, 181583583909u },
+ { 0u, 2891199497780592640u, 165446048210u },
+ { 0u, 15294857653247803392u, 210156732238u },
+ { 0u, 14303432416528695296u, 78829135894u },
+ { 0u, 0u, 22775390625u },
+ { 0u, 0u, 161000000000u },
+ { 14876458284855834550u, 10u, 0u },
+ { 10450704926982265198u, 10806454419u, 0u },
+ { 5385653213018257806u, 10806454419566533849u, 0u },
+ { 12735569669880147489u, 17118225092618494573u, 585819067u },
+ { 3619762560577729456u, 13385738875341807559u, 187927980841u },
+ { 11123448126624084269u, 8272682717439277193u, 41725642358u },
+ { 4072715118852885633u, 13402436483369350083u, 118448463028u },
+ { 18239087231420827283u, 10946328903241612536u, 180726547537u },
+ { 423431461216085297u, 16265808923426731252u, 81593401678u },
+ { 9360976716520160042u, 11080374459871185177u, 78881771268u },
+ { 11655927117263208920u, 1240761893433831916u, 4600668303u },
+ { 2646622721938364948u, 367264070493390483u, 143067261837u },
+ { 4496462484548171852u, 2863675693461092905u, 141019909425u },
+ { 13140258519803350063u, 7511929581752138999u, 49155240170u },
+ { 13089764333320627770u, 11154557789993845753u, 234407222518u },
+ { 6926286827289840501u, 8325416539745948522u, 246604689789u },
+ { 4985580225290866218u, 17745129874679852617u, 125451321734u },
+ { 10478790837359789693u, 1074820986392253357u, 134961965418u },
+ { 10041191967455692214u, 7820952682162838597u, 106058266162u },
+ { 5035461258013813797u, 8215518006273528603u, 50423974694u },
+ { 14208759661559249750u, 9680426791089900133u, 38445364123u },
+ { 12347272163241758840u, 16128495723604797412u, 155524776987u },
+ { 3372534174410277614u, 2264789053583348885u, 27874327505u },
+ { 17226704187274712984u, 11175458488686298083u, 209122774460u },
+ { 4250480179449852121u, 11026777810412287617u, 188605822818u },
+ { 4303723537755414374u, 16199890034895598640u, 98597762822u },
+ { 8680503847344854165u, 9094320719494763752u, 6878197798u },
+ { 8817608623911079652u, 1250835564687222832u, 38493004114u },
+ { 5692030448698539450u, 15362466642459337025u, 82067807931u },
+ { 16908836314686769809u, 7831109835595423828u, 187832800985u },
+ { 6073762347067727240u, 15426237284335022429u, 217424525314u },
+ { 10931066692585106200u, 15636308361455434548u, 2836257998u },
+ { 14466591364061539596u, 13967173875944980328u, 206847645974u },
+ { 4958077340960173341u, 18245979923595824097u, 22757162012u },
+ { 4076890037156765715u, 11335054479675278263u, 28989116553u },
+ { 14083973146609179058u, 11165339882630461707u, 137614474534u },
+ { 2565183738039805295u, 15944437408299395922u, 38605274287u },
+ { 1482420938751351224u, 15806416348777321161u, 175864349683u },
+ { 2151089495335413944u, 4201030477408556248u, 243856867547u },
+ { 3738604531753220913u, 9485474942554588907u, 219227738318u },
+ { 14195686514836005765u, 18238757647663230541u, 206514208626u },
+ { 17808833916231796970u, 4642199687824746379u, 114988725033u },
+ { 1302384553035657354u, 6134575894869364037u, 41251654149u },
+ { 1672033517974833698u, 11524208547121316008u, 5332556025u },
+ { 11673925532927662545u, 2734683241527878366u, 249624728597u },
+ { 3905334232240480709u, 10629223456178675171u, 21148247475u },
+ { 17411087320267472625u, 2788042336985254064u, 179576211358u },
+ { 16573305231063706617u, 17285498758066142502u, 158151140077u },
+ { 15481103236037148354u, 5525538192421886436u, 237937048765u },
+ { 907440704754420880u, 11414325503043801888u, 189299540025u },
+ { 3224970785139077759u, 7246608114685173259u, 57618771825u },
+ { 10560826509734608144u, 1007884269852184608u, 113392839413u },
+ { 4700940027512659968u, 13823717876510029312u, 245054637515u },
+ { 9733694683502084096u, 12487410768239429317u, 203749385247u },
+ { 1995535635724632064u, 3361062421598631942u, 31676943894u },
+ { 10629833226245373952u, 17853337379088328475u, 22182203558u },
+ { 15729384648544878592u, 11551561037491869885u, 166967831358u },
+ { 7205759403792793600u, 11480877996635204802u, 62626211378u },
+ { 0u, 5527488381934471912u, 50622379643u },
+ { 0u, 11143438404407726080u, 123299645745u },
+ { 0u, 6472279730688098304u, 49604087006u },
+ { 0u, 4561816853579563008u, 222350862987u },
+ { 0u, 2888714464062865408u, 139247296587u },
+ { 0u, 16258276129784201216u, 75156597524u },
+ { 0u, 720575940379279360u, 20881362915u },
+ { 0u, 0u, 227039062500u },
+ { 0u, 0u, 228000000000u },
+ { 7535526066623007027u, 164893u, 0u },
+ { 11302146918409311588u, 164893408501686u, 0u },
+ { 2480833299122194801u, 16409970870640346804u, 8938u },
+ { 11513226205589330558u, 7721907286269370594u, 234889586303u },
+ { 4073957068281936105u, 14300743897882155131u, 127418605432u },
+ { 3729887061093812886u, 2068482633821123575u, 120775244880u },
+ { 13616911779739451443u, 4922882895416406094u, 80112132668u },
+ { 13039053282195777666u, 9317632875623428410u, 60266870016u },
+ { 14490756113210417890u, 5693844901999766254u, 505109890u },
+ { 17432486112977557585u, 11569484900262102262u, 130308663950u },
+ { 14308820825344039837u, 3138170119352085637u, 142627183033u },
+ { 4190949538817536349u, 950584692575235243u, 185170120543u },
+ { 13616552502810964397u, 8136430299747162645u, 95051531299u },
+ { 4898145803694965031u, 6698711700804594470u, 35441076770u },
+ { 1399036321001644308u, 17401191571004302008u, 34363137888u },
+ { 17170331128243738540u, 4721732028538188150u, 96943320485u },
+ { 10641321388205367410u, 2984214103553086219u, 165255965606u },
+ { 6648873641312572851u, 13128675202005662068u, 166161774570u },
+ { 5988456964560374823u, 14638512997670672834u, 234711706908u },
+ { 9972593758348346915u, 12942085665769692438u, 28793555379u },
+ { 16709668921872818968u, 14131134357119205086u, 179701591869u },
+ { 6094829131503407767u, 8921946894736102919u, 61766050328u },
+ { 4892016478899926334u, 5601522560505809989u, 24483659710u },
+ { 13150857244079031538u, 8602606493507716808u, 190303659146u },
+ { 12983943395318785894u, 8576789731078566487u, 138466348232u },
+ { 15341644584614757478u, 17881118138842658549u, 200464948702u },
+ { 7507635124856644772u, 11624372674432704923u, 222969337356u },
+ { 11619655367084544354u, 6826284072848095635u, 12630158505u },
+ { 11553116952478783009u, 1646466632033733563u, 169370053601u },
+ { 17392150014233193245u, 17871081657060299180u, 225089255134u },
+ { 8877887560294980515u, 15910893124677544709u, 222968793277u },
+ { 18404180619915609503u, 11031217459450580944u, 189862531244u },
+ { 10079413095288181976u, 13554987390037243094u, 172598003496u },
+ { 14102802966539105550u, 15026714590903687870u, 40734817338u },
+ { 13333966026135891399u, 4406379654994689200u, 58814599830u },
+ { 12344968670173516152u, 13596329092861950242u, 150238870319u },
+ { 10577007819804726752u, 284812388227373260u, 47737058477u },
+ { 15337041354031088010u, 9285079159392309382u, 173015439710u },
+ { 14333607285614673616u, 15046108141952711893u, 94503345149u },
+ { 17171597563219696538u, 13795366909944958311u, 253815651156u },
+ { 2849642930482147564u, 12909920641180059961u, 84747848338u },
+ { 14791248423979435173u, 5333762939889788252u, 146699848200u },
+ { 13882371364576310127u, 6411331390005944495u, 8289143868u },
+ { 11735995808941329540u, 1447104583224217723u, 60347558971u },
+ { 11376996674339273181u, 11940049226167932871u, 59078447696u },
+ { 9849638057168043481u, 9772290783590472385u, 80647271365u },
+ { 18241520229279361964u, 16351989577831528444u, 197529756944u },
+ { 1865852368526961444u, 4376738725895725097u, 16886443131u },
+ { 10601487369276448158u, 13851276297739812763u, 123237263481u },
+ { 15999931310312762170u, 12641996203470333509u, 121750879192u },
+ { 5773775867713013570u, 7707081716407945022u, 216685323987u },
+ { 17726239863982547534u, 417638323657040024u, 211417801737u },
+ { 9711316695888316992u, 16438047707692449100u, 9022640218u },
+ { 17872002620723724288u, 14850108107043306316u, 90891108351u },
+ { 7429694208660733952u, 10423290807904720835u, 255805025973u },
+ { 1782821038871019520u, 16951162310302339314u, 181565047726u },
+ { 3225250234313474048u, 2752437506572397322u, 174918924350u },
+ { 10009250171830927360u, 3925815842962784589u, 62149209936u },
+ { 1152921504606846976u, 5274166674003605291u, 80212818903u },
+ { 0u, 5538963350863452832u, 215285913148u },
+ { 0u, 16900671634439028736u, 60300267804u },
+ { 0u, 2326997710751662080u, 28916187245u },
+ { 0u, 12327726161625874432u, 109126146798u },
+ { 0u, 5756455743825903616u, 238668287374u },
+ { 0u, 3018537650245074944u, 142312058091u },
+ { 0u, 16717361816799281152u, 235163635253u },
+ { 0u, 0u, 53906250000u },
+ { 0u, 0u, 16000000000u },
+ { 2285186318012886800u, 2516073738u, 0u },
+ { 9706420951402272035u, 2516073738123880198u, 0u },
+ { 2369632031840402142u, 11997425759292732054u, 136396630u },
+ { 15599123897979399458u, 11491152661270395161u, 86650381753u },
+ { 17579576584023912658u, 18181063258234881272u, 185622936633u },
+ { 3480927339588501811u, 2466921813123869732u, 57985597414u },
+ { 3547346616671294635u, 8430880678232179465u, 230133732099u },
+ { 7705317123868384954u, 6738034873677997533u, 3457038957u },
+ { 4969425237478353909u, 7678250951042929246u, 109365269602u },
+ { 17043246700132217175u, 1853560606315563193u, 98416238818u },
+ { 17053788362783499470u, 14942676593409905118u, 226100481721u },
+ { 11102988228454224768u, 4909892170837638183u, 185810044121u },
+ { 16944305387801685839u, 16871149368312132405u, 217266165787u },
+ { 11725142977459199276u, 16096130589333770811u, 27914586839u },
+ { 8175984171998533324u, 12512479187631824282u, 215872572987u },
+ { 1372352885142856895u, 16980304980540557310u, 59678302855u },
+ { 17975093466502888164u, 8640919162749295366u, 135920504177u },
+ { 6467823391459085653u, 7862382415464063513u, 113468425166u },
+ { 11319386883146885025u, 14534157903009925344u, 206426220604u },
+ { 9141999262922068637u, 12627464554215107944u, 60787898278u },
+ { 1587330393383478774u, 2456849734836299173u, 166684536225u },
+ { 884187548095712303u, 18428252197697827913u, 161133186090u },
+ { 488841225726377268u, 7244734215936736255u, 42998997553u },
+ { 17462624199405856193u, 14756175050504770087u, 49392737828u },
+ { 13183677579115583554u, 6764116534566945922u, 36799933852u },
+ { 11645015818917277779u, 1588822142405565521u, 156366683492u },
+ { 8760523002035971977u, 17053265624843842052u, 100086130220u },
+ { 10068817678491468042u, 16996891591759999207u, 44924459381u },
+ { 1273658177787418284u, 8565556232370585876u, 117921403339u },
+ { 3100019384328057661u, 14464960359145886620u, 203464339733u },
+ { 10363063568089458738u, 5813189542048784035u, 21784147072u },
+ { 13030756371481403666u, 9739241026882027025u, 128315133636u },
+ { 6538878900684195299u, 18175068535675302910u, 196527965313u },
+ { 8984884716779098868u, 10562697212061761911u, 129985272439u },
+ { 8728727397070363908u, 4264834835660801368u, 119572604963u },
+ { 6398650562917867005u, 13019066443690126316u, 35231197159u },
+ { 1190873176164938879u, 1828040177823321846u, 231705765006u },
+ { 4383628525805121795u, 11240369830376975668u, 142099098256u },
+ { 10189374699734119852u, 8886938465302549874u, 144609341669u },
+ { 5276291920541626391u, 9985240313589688325u, 229481761899u },
+ { 2692252373800386521u, 722909126956573766u, 107541300962u },
+ { 11578684995169173920u, 5493363474638452381u, 226039188982u },
+ { 5799408022254132587u, 12410535279213120491u, 246297795830u },
+ { 15548569837712345290u, 10543108918366869098u, 246672776465u },
+ { 15763030464322902955u, 12953909016524823995u, 17571543079u },
+ { 13257749746581255500u, 16505942145872588169u, 39702232814u },
+ { 16152470009188707678u, 12428594380392015797u, 238894788916u },
+ { 13806790848493904003u, 7528259605829768337u, 52673755451u },
+ { 11981226523265951191u, 18147447600042811311u, 59408107770u },
+ { 5133628726077003713u, 12021069431116183911u, 250983775105u },
+ { 16183955741910833164u, 11819985069665662506u, 129651663479u },
+ { 13640425554331371454u, 10401877114068152814u, 119640762674u },
+ { 18108120906868035862u, 4611631138117837942u, 50563886888u },
+ { 6324011669895037184u, 17200813398607252417u, 40249997024u },
+ { 10444437689515769856u, 14100466137553658767u, 224932457962u },
+ { 12324712543665782784u, 17887776768825509301u, 234764387800u },
+ { 13928941951563857920u, 12632656857970087269u, 216969698321u },
+ { 3975288688270639104u, 8923681664054686256u, 17684817700u },
+ { 11141905478114607104u, 6213926103737837599u, 36483753752u },
+ { 4611686018427387904u, 1233118281776157762u, 24336857609u },
+ { 0u, 30716279628678784u, 9066847476u },
+ { 0u, 15775734650898546688u, 244001665132u },
+ { 0u, 976806005729918976u, 108855204289u },
+ { 0u, 12460098853279891456u, 193052952759u },
+ { 0u, 5635665595421687808u, 183675463312u },
+ { 0u, 1805943450575568896u, 144305510044u },
+ { 0u, 11529215046068469760u, 156097900390u },
+ { 0u, 0u, 102625000000u },
+ { 0u, 0u, 64000000000u },
+ { 4398362855256705725u, 38392u, 0u },
+ { 2812083125569302717u, 38392238435728u, 0u },
+ { 12868509142973100603u, 4564018338575530435u, 2081u },
+ { 8726243776748165726u, 16553437246451512014u, 33247415929u },
+ { 358304413426858117u, 4339777136957372927u, 121897363631u },
+ { 3180720351566429470u, 18439463366554654697u, 175235259789u },
+ { 14053818240400098784u, 1370067356680643003u, 141999605312u },
+ { 7340140541492429288u, 4210124040914115013u, 64074271500u },
+ { 1323571167904965058u, 10692225626142609720u, 12228231281u },
+ { 14463851737583396026u, 11592856673895384344u, 113579626712u },
+ { 15122784818916048486u, 10284479231227406269u, 216628450019u },
+ { 13557974621377508955u, 4961071383534266431u, 227557522736u },
+ { 17525172074563876264u, 10960611551445686988u, 48268940218u },
+ { 15148880683074215967u, 14616396723115619209u, 186594175942u },
+ { 6744828147558597936u, 1025604265437492803u, 198792356454u },
+ { 9799290779647971692u, 11711588454892179178u, 102055598118u },
+ { 11170890203898678105u, 5580373263251565705u, 38634886482u },
+ { 7068779781287527905u, 14109334653033148931u, 82302512640u },
+ { 14474741922505540911u, 2899414033769399895u, 764868564u },
+ { 17107062680405191514u, 13233457234892808147u, 212157177549u },
+ { 2712598571300237005u, 3287946691509034862u, 205717387154u },
+ { 3767556054903418641u, 5488480288717445911u, 146178239947u },
+ { 18158239681706277628u, 11687233053874362630u, 203297531112u },
+ { 10531652712128330681u, 6783772100089274577u, 232633566173u },
+ { 9548395326934120567u, 7898291058728402485u, 221367749022u },
+ { 15875647850297719390u, 4423684977486598491u, 158428167216u },
+ { 8215825295203192574u, 2750833684599526706u, 48239808443u },
+ { 12747310908260543144u, 15669689830489025709u, 187149122992u },
+ { 77706528053613642u, 15117307274214954517u, 176849455587u },
+ { 6024737704056756146u, 8148639818575698175u, 227819510869u },
+ { 6819452388570089667u, 13006484426078994901u, 85441738649u },
+ { 13695926775373186254u, 10287496057845513526u, 153705082933u },
+ { 3746531715392682132u, 14159876032966532430u, 53557686278u },
+ { 4717376233154528116u, 15742212196465548019u, 6767608417u },
+ { 385190957950313369u, 2892220461917134150u, 97853387033u },
+ { 12388374310648616082u, 7487151560715393883u, 25156787585u },
+ { 1078067332084407770u, 7245756744165177933u, 129405879299u },
+ { 3257295319358714850u, 3067122860671533987u, 3392793260u },
+ { 1545453099660723457u, 8135043905834122525u, 172166269063u },
+ { 7495477664653506341u, 14730019368921022572u, 135441001613u },
+ { 7225503732673614354u, 495969939682055458u, 141798515950u },
+ { 3935478326103643956u, 5617761407265775598u, 238026886584u },
+ { 10082240682742686210u, 2087044847072781811u, 184304539456u },
+ { 10838712705567897138u, 15929674232061203330u, 64113138927u },
+ { 2142546572501643680u, 8658086469608285873u, 239863549370u },
+ { 7893042119150331392u, 18369871790780313570u, 186469355807u },
+ { 12084811642251302615u, 3545648451947416750u, 31995832745u },
+ { 15317234482572954775u, 13347376792767929959u, 169192209987u },
+ { 2283226355108359361u, 14482164459838203025u, 67723562745u },
+ { 13359725152575722127u, 8899577765623565820u, 249785079708u },
+ { 13126551011491594557u, 7095320096604405719u, 156482447077u },
+ { 3598021288691861269u, 2968593824439315788u, 229384638073u },
+ { 16462621795896662961u, 12621408323612585636u, 121160927793u },
+ { 14682112756964627332u, 3954422936414648259u, 49684207916u },
+ { 7174112100896070218u, 17143730087577690191u, 44214369696u },
+ { 5023109019590616064u, 5033045529399041876u, 160929363470u },
+ { 10765223023086141440u, 15857648521994521781u, 14272841944u },
+ { 8228137177297453056u, 16655573486499109541u, 216859644848u },
+ { 2891199497780592640u, 16652154439190075858u, 176902900447u },
+ { 15294857653247803392u, 18016950600164130638u, 223902715100u },
+ { 14303432416528695296u, 2086292996072613910u, 220976700849u },
+ { 0u, 17324462585194799521u, 177113098169u },
+ { 0u, 11079151463184927232u, 185939160998u },
+ { 0u, 5239846817488961536u, 166600602004u },
+ { 0u, 2778806963520143360u, 148284052665u },
+ { 0u, 6240890740138835968u, 185150639427u },
+ { 0u, 17250651344549707776u, 67338319364u },
+ { 0u, 4197354852709302272u, 4935159683u },
+ { 0u, 9223372036854775808u, 131227539062u },
+ { 0u, 0u, 118500000000u },
+ { 17118225092618494573u, 585819067u, 0u },
+ { 13385738875341807559u, 585819067927980841u, 0u },
+ { 8272682717439277193u, 5654803392547571318u, 31757315u },
+ { 13402436483369350083u, 2931628102185393332u, 3306547506u },
+ { 10946328903241612536u, 15964697617980212305u, 50158923877u },
+ { 16265808923426731252u, 450380868305846606u, 101865447992u },
+ { 11080374459871185177u, 14631133530814566148u, 56024415195u },
+ { 1240761893433831916u, 31969822783742095u, 219793155338u },
+ { 367264070493390483u, 10437269029385743245u, 10001733087u },
+ { 2863675693461092905u, 15196146496377392433u, 223565805487u },
+ { 7511929581752138999u, 4409099735137480938u, 175823784752u },
+ { 11154557789993845753u, 10644987914903248118u, 48239017775u },
+ { 8325416539745948522u, 3154431617534062973u, 47577065951u },
+ { 17745129874679852617u, 11702056331247960454u, 223171002080u },
+ { 1074820986392253357u, 15575315065965259114u, 224634369744u },
+ { 7820952682162838597u, 10759747609480050226u, 208844339521u },
+ { 8215518006273528603u, 12538236653960743718u, 65583287086u },
+ { 9680426791089900133u, 17857942663978005403u, 46679699170u },
+ { 16128495723604797412u, 11443004154750813211u, 226968081011u },
+ { 2264789053583348885u, 4004313188770806737u, 115620326498u },
+ { 11175458488686298083u, 17134872954824183228u, 98217074252u },
+ { 11026777810412287617u, 2659553912986171234u, 76928883324u },
+ { 16199890034895598640u, 9501854300969137926u, 124144174706u },
+ { 9094320719494763752u, 14528169966301018150u, 114515096553u },
+ { 1250835564687222832u, 18172091996515901778u, 233787573671u },
+ { 15362466642459337025u, 1133541705604751035u, 167985111081u },
+ { 7831109835595423828u, 18280349987988641497u, 41061449418u },
+ { 15426237284335022429u, 9936015874712336386u, 202990979758u },
+ { 15636308361455434548u, 15876720399740689614u, 174538632499u },
+ { 13967173875944980328u, 8618117825152456982u, 51860678737u },
+ { 18245979923595824097u, 8085525680745921564u, 81467189103u },
+ { 11335054479675278263u, 8072355444669730953u, 111438317225u },
+ { 11165339882630461707u, 9395030504766848294u, 169437603265u },
+ { 15944437408299395922u, 3537903114058185903u, 193509305624u },
+ { 15806416348777321161u, 2126094743961928691u, 24191790112u },
+ { 4201030477408556248u, 289185362555601115u, 32115255827u },
+ { 9485474942554588907u, 16909937501450129614u, 19015676769u },
+ { 18238757647663230541u, 14449642060360499058u, 97916689548u },
+ { 4642199687824746379u, 12433818908498244393u, 140783316665u },
+ { 6134575894869364037u, 11884444034578008581u, 185674038673u },
+ { 11524208547121316008u, 988625838444140793u, 145644257002u },
+ { 2734683241527878366u, 1675370907158909973u, 234053593514u },
+ { 10629223456178675171u, 15920186275316934067u, 170090822038u },
+ { 2788042336985254064u, 5600921198503757726u, 150863035027u },
+ { 17285498758066142502u, 10457357161776341741u, 147303626546u },
+ { 5525538192421886436u, 12225356765775740093u, 50566894467u },
+ { 11414325503043801888u, 4486633318598164537u, 131662737918u },
+ { 7246608114685173259u, 10302486602879381361u, 254243220879u },
+ { 1007884269852184608u, 15536428611301239541u, 143558498917u },
+ { 13823717876510029312u, 12026126645955462603u, 101842231482u },
+ { 12487410768239429317u, 14877968141142123551u, 186651937631u },
+ { 3361062421598631942u, 734560801645383190u, 95806536269u },
+ { 17853337379088328475u, 15648943144911081638u, 77039820620u },
+ { 11551561037491869885u, 13664182862003235646u, 76848330907u },
+ { 11480877996635204802u, 3895127525902132786u, 155740736837u },
+ { 5527488381934471912u, 5249187334214137467u, 69211155286u },
+ { 11143438404407726080u, 10642260063359027505u, 86284559015u },
+ { 6472279730688098304u, 783598951897779422u, 167576918074u },
+ { 4561816853579563008u, 5538576558607624843u, 58042478984u },
+ { 2888714464062865408u, 15974581187564609611u, 136300246836u },
+ { 16258276129784201216u, 7474269406918257428u, 52865983781u },
+ { 720575940379279360u, 8045286838779138019u, 37405180956u },
+ { 0u, 8184246376556341732u, 28436135873u },
+ { 0u, 1493267152679331840u, 193443668885u },
+ { 0u, 10179074811222818816u, 149080950174u },
+ { 0u, 3892499202005008384u, 158551808751u },
+ { 0u, 10341173215925108736u, 239211012804u },
+ { 0u, 6230307872002015232u, 196560596123u },
+ { 0u, 9295429630892703744u, 155337745666u },
+ { 0u, 0u, 2503906250u },
+ { 0u, 0u, 202000000000u },
+ { 16409970870640346804u, 8938u, 0u },
+ { 7721907286269370594u, 8938889586303u, 0u },
+ { 14300743897882155131u, 10665454627995623288u, 484u },
+ { 2068482633821123575u, 16803537892767562832u, 228578175453u },
+ { 4922882895416406094u, 8099123106849104444u, 221910921614u },
+ { 9317632875623428410u, 7077413686679401728u, 142439054343u },
+ { 5693844901999766254u, 13536636358372449666u, 7383667364u },
+ { 11569484900262102262u, 7280632235418610318u, 164733822527u },
+ { 3138170119352085637u, 6187823673116858809u, 63394683864u },
+ { 950584692575235243u, 8624343686231740255u, 216335442593u },
+ { 8136430299747162645u, 806211610822132771u, 161467526608u },
+ { 6698711700804594470u, 18388078233202190882u, 208043704818u },
+ { 17401191571004302008u, 7628864426595573600u, 242996819718u },
+ { 4721732028538188150u, 4530799784343874981u, 6413561569u },
+ { 2984214103553086219u, 8561580552078486438u, 225245615148u },
+ { 13128675202005662068u, 13349114951221999594u, 44464124211u },
+ { 14638512997670672834u, 10029144738508991772u, 51723656971u },
+ { 12942085665769692438u, 12601907197916268979u, 11543681025u },
+ { 14131134357119205086u, 1329580921391066941u, 1683150758u },
+ { 8921946894736102919u, 3198179786356761112u, 166072076726u },
+ { 5601522560505809989u, 11406753413634654142u, 182173373673u },
+ { 8602606493507716808u, 11131812960525182090u, 233618361341u },
+ { 8576789731078566487u, 14299636753645227208u, 253603456789u },
+ { 17881118138842658549u, 12964114684643663326u, 21775184861u },
+ { 11624372674432704923u, 5019257593846306316u, 221702786065u },
+ { 6826284072848095635u, 6929086798159998121u, 17272094499u },
+ { 1646466632033733563u, 18359765766933703649u, 35375626547u },
+ { 17871081657060299180u, 9993076234752063198u, 51995284896u },
+ { 15910893124677544709u, 3257189215046584509u, 160541725748u },
+ { 11031217459450580944u, 2905234736672690348u, 52176572581u },
+ { 13554987390037243094u, 12064985302079670056u, 165157493090u },
+ { 15026714590903687870u, 14315096064942799930u, 98654044163u },
+ { 4406379654994689200u, 11943971043551974038u, 3776022912u },
+ { 13596329092861950242u, 12472773152119929647u, 128647483967u },
+ { 284812388227373260u, 7791259796982183085u, 63676150387u },
+ { 9285079159392309382u, 16866829442051086686u, 115422365039u },
+ { 15046108141952711893u, 3702498393844653053u, 111914352656u },
+ { 13795366909944958311u, 2057239613841701716u, 16200712840u },
+ { 12909920641180059961u, 17201969976738286226u, 136111523182u },
+ { 5333762939889788252u, 18271566505443461640u, 110932520660u },
+ { 6411331390005944495u, 18368509115417119804u, 212990503604u },
+ { 1447104583224217723u, 7613923684154518587u, 180995758874u },
+ { 11940049226167932871u, 17984805084714865232u, 26412751629u },
+ { 9772290783590472385u, 4220802739051410373u, 13974958237u },
+ { 16351989577831528444u, 17812459042810815760u, 157228810174u },
+ { 4376738725895725097u, 10629526089664605307u, 190965615339u },
+ { 13851276297739812763u, 17437443267816548473u, 235576227763u },
+ { 12641996203470333509u, 12506371893701049304u, 179945285693u },
+ { 7707081716407945022u, 15737221540003030739u, 61677971778u },
+ { 417638323657040024u, 2358380859011605513u, 66853116489u },
+ { 16438047707692449100u, 10042972713837039706u, 73127848082u },
+ { 14850108107043306316u, 13424397272769642495u, 146544430641u },
+ { 10423290807904720835u, 6867102315755663029u, 49727738034u },
+ { 16951162310302339314u, 8690748404825506734u, 178372266362u },
+ { 2752437506572397322u, 956229930815387710u, 122471126415u },
+ { 3925815842962784589u, 7734449506297687888u, 143051837328u },
+ { 5274166674003605291u, 16332184961683848151u, 144419285347u },
+ { 5538963350863452832u, 15580777817612768828u, 99885369520u },
+ { 16900671634439028736u, 17404245271944696092u, 176844635657u },
+ { 2326997710751662080u, 13201420160494469229u, 9943486026u },
+ { 12327726161625874432u, 16511717657124068078u, 74715650420u },
+ { 5756455743825903616u, 14131292492116594062u, 116895102007u },
+ { 3018537650245074944u, 18429136031865875691u, 55766058900u },
+ { 16717361816799281152u, 2563978348305862197u, 148999045466u },
+ { 0u, 14239974392147482896u, 90138993544u },
+ { 0u, 11164201396098998272u, 136771950558u },
+ { 0u, 7116971104932986880u, 222605212570u },
+ { 0u, 12437629862867369984u, 154385811776u },
+ { 0u, 16501893821638901760u, 64674245265u },
+ { 0u, 10649324268870959104u, 145894569456u },
+ { 0u, 7205759403792793600u, 240577301025u },
+ { 0u, 0u, 33390625000u },
+ { 0u, 0u, 232000000000u },
+ { 11997425759292732054u, 136396630u, 0u },
+ { 11491152661270395161u, 136396630650381753u, 0u },
+ { 18181063258234881272u, 3016823727048309817u, 7394076u },
+ { 2466921813123869732u, 17405973192644624358u, 28163542341u },
+ { 8430880678232179465u, 8937219978302591747u, 69943579697u },
+ { 6738034873677997533u, 15178463196824222317u, 49484487665u },
+ { 7678250951042929246u, 11979404627460330594u, 241822826138u },
+ { 1853560606315563193u, 2006448052689740002u, 154649404826u },
+ { 14942676593409905118u, 16330465320863239865u, 154108769766u },
+ { 4909892170837638183u, 17136208883957646553u, 230885276298u },
+ { 16871149368312132405u, 140455118208931867u, 138928955745u },
+ { 16096130589333770811u, 3964972929179372247u, 97007614087u },
+ { 12512479187631824282u, 3378050330022776379u, 135214941613u },
+ { 16980304980540557310u, 6065353437512901255u, 173183124475u },
+ { 8640919162749295366u, 12768753059854699889u, 251328803468u },
+ { 7862382415464063513u, 6848720690951013326u, 140692195490u },
+ { 14534157903009925344u, 10953228058585475132u, 162371269892u },
+ { 12627464554215107944u, 15539127852083296166u, 4593775682u },
+ { 2456849734836299173u, 14534853647735598497u, 66842377808u },
+ { 18428252197697827913u, 1506909603576368170u, 80787935995u },
+ { 7244734215936736255u, 5475702579938239025u, 251081689733u },
+ { 14756175050504770087u, 12039747373985783332u, 133296838431u },
+ { 6764116534566945922u, 17572399137760898460u, 31652676012u },
+ { 1588822142405565521u, 869552790852091236u, 172952601666u },
+ { 17053265624843842052u, 4549585778048181804u, 66047138551u },
+ { 16996891591759999207u, 4121918231767210357u, 247246633539u },
+ { 8565556232370585876u, 1558397953312543179u, 67223449635u },
+ { 14464960359145886620u, 6067524298738069781u, 35084480922u },
+ { 5813189542048784035u, 5811095224555517056u, 154328921151u },
+ { 9739241026882027025u, 6440894514158997188u, 63315020103u },
+ { 18175068535675302910u, 4612748874388784257u, 71349161591u },
+ { 10562697212061761911u, 9908101430749813367u, 119250057617u },
+ { 4264834835660801368u, 15150017990912190499u, 145537119254u },
+ { 13019066443690126316u, 17470426264690059239u, 22821284120u },
+ { 1828040177823321846u, 9615161096851907726u, 24947073705u },
+ { 11240369830376975668u, 9227932132124142224u, 169521238927u },
+ { 8886938465302549874u, 4794113194321211621u, 143500247203u },
+ { 9985240313589688325u, 391512698859146347u, 163259889397u },
+ { 722909126956573766u, 17209658878068655842u, 245021223945u },
+ { 5493363474638452381u, 3077364726606876150u, 9932937477u },
+ { 12410535279213120491u, 1952989567673965814u, 5166824276u },
+ { 10543108918366869098u, 11172860676923186449u, 84105871776u },
+ { 12953909016524823995u, 17338078544784947239u, 160605681990u },
+ { 16505942145872588169u, 4593380466519703278u, 70939899121u },
+ { 12428594380392015797u, 786884753602720052u, 241249007654u },
+ { 7528259605829768337u, 17848875822468020539u, 38042657107u },
+ { 18147447600042811311u, 2899664567187130618u, 83967589497u },
+ { 12021069431116183911u, 2973178834961857409u, 121157191131u },
+ { 11819985069665662506u, 11117453141176836727u, 219161176347u },
+ { 10401877114068152814u, 7535238370146462002u, 27602678342u },
+ { 4611631138117837942u, 10246175467290865448u, 70408486090u },
+ { 17200813398607252417u, 1203128834127050464u, 202555446285u },
+ { 14100466137553658767u, 14518048959078919658u, 13065221744u },
+ { 17887776768825509301u, 1553474987376920024u, 112787025011u },
+ { 12632656857970087269u, 14956572380830948369u, 115084214047u },
+ { 8923681664054686256u, 7594162606042048292u, 31810797413u },
+ { 6213926103737837599u, 14461296147288811288u, 101411680379u },
+ { 1233118281776157762u, 18305427728131488265u, 123783948434u },
+ { 30716279628678784u, 10253208939347909876u, 146992339225u },
+ { 15775734650898546688u, 6446028915490812012u, 25555827570u },
+ { 976806005729918976u, 12986063676957432257u, 114349439927u },
+ { 12460098853279891456u, 9769714697972762807u, 183703975922u },
+ { 5635665595421687808u, 97429465146664592u, 242529617295u },
+ { 1805943450575568896u, 16395571728207795868u, 143005281661u },
+ { 11529215046068469760u, 6331668478323650406u, 125888805724u },
+ { 0u, 18129911846294207040u, 92343240435u },
+ { 0u, 9890094564876124160u, 243982824490u },
+ { 0u, 12290856656987750400u, 42536143100u },
+ { 0u, 8498454992640802816u, 252666288674u },
+ { 0u, 5341660584200896512u, 34460702168u },
+ { 0u, 9288674231451648000u, 216289572000u },
+ { 0u, 1152921504606846976u, 160503540039u },
+ { 0u, 0u, 71062500000u },
+ { 0u, 0u, 160000000000u },
+ { 4564018338575530435u, 2081u, 0u },
+ { 16553437246451512014u, 2081247415929u, 0u },
+ { 4339777136957372927u, 15212079674427582639u, 112u },
+ { 18439463366554654697u, 10179808126814248333u, 112824648491u },
+ { 1370067356680643003u, 6066766544199222848u, 43551848504u },
+ { 4210124040914115013u, 6625308131806923532u, 56328880073u },
+ { 10692225626142609720u, 9122786786400665713u, 201359158673u },
+ { 11592856673895384344u, 11932880778639151320u, 145494547262u },
+ { 10284479231227406269u, 3884040911779255011u, 62646882763u },
+ { 4961071383534266431u, 13441817515637357872u, 203210554279u },
+ { 10960611551445686988u, 11628577856022352826u, 167728682387u },
+ { 14616396723115619209u, 13296656925520243654u, 147630386468u },
+ { 1025604265437492803u, 5020720704545399398u, 36720813216u },
+ { 11711588454892179178u, 14121973606499014694u, 160272173814u },
+ { 5580373263251565705u, 3642481034345420114u, 246765553723u },
+ { 14109334653033148931u, 9845536238569696768u, 59197459292u },
+ { 2899414033769399895u, 17655403572195686356u, 92533727588u },
+ { 13233457234892808147u, 8377495365136654029u, 100957101345u },
+ { 3287946691509034862u, 13713682649609025426u, 33454144933u },
+ { 5488480288717445911u, 1367709905452854731u, 165743420226u },
+ { 11687233053874362630u, 9981467701727208680u, 66074143702u },
+ { 6783772100089274577u, 6277920117543306205u, 214541096448u },
+ { 7898291058728402485u, 9344111460418701726u, 340326731u },
+ { 4423684977486598491u, 4918507011364617264u, 75506545297u },
+ { 2750833684599526706u, 6554777203830755259u, 145266632799u },
+ { 15669689830489025709u, 4198262173120265648u, 95355335184u },
+ { 15117307274214954517u, 8080325935698446819u, 16227588248u },
+ { 8148639818575698175u, 12797633874200091733u, 152438035346u },
+ { 13006484426078994901u, 8376502502208665497u, 146693761122u },
+ { 10287496057845513526u, 9891973386793349173u, 98454091110u },
+ { 14159876032966532430u, 14877430279003795462u, 102536244951u },
+ { 15742212196465548019u, 8759933935842067041u, 215806507111u },
+ { 2892220461917134150u, 3753418510388703513u, 103474876970u },
+ { 7487151560715393883u, 2961383332545305985u, 42203473225u },
+ { 7245756744165177933u, 2497674184068629507u, 73160536912u },
+ { 3067122860671533987u, 15244544070742305452u, 80135399188u },
+ { 8135043905834122525u, 45953573565810823u, 20826408390u },
+ { 14730019368921022572u, 3960077421351906445u, 198002491148u },
+ { 495969939682055458u, 3173330011013883118u, 12214676227u },
+ { 5617761407265775598u, 11026266219545759160u, 3172026564u },
+ { 2087044847072781811u, 8886757764964685632u, 196597735089u },
+ { 15929674232061203330u, 13952322129918090479u, 177481752103u },
+ { 8658086469608285873u, 4127250666614902202u, 39756356898u },
+ { 18369871790780313570u, 17649958504065306911u, 34223738706u },
+ { 3545648451947416750u, 13269305359002216873u, 82956806167u },
+ { 13347376792767929959u, 16236593433831947843u, 23719330484u },
+ { 14482164459838203025u, 13580930396682424057u, 180880187493u },
+ { 8899577765623565820u, 421976357197961116u, 101736223712u },
+ { 7095320096604405719u, 2962130818798626533u, 224022875384u },
+ { 2968593824439315788u, 8234383947306356345u, 248160577433u },
+ { 12621408323612585636u, 4380469931801381425u, 153446386848u },
+ { 3954422936414648259u, 15279887469027055916u, 160237465750u },
+ { 17143730087577690191u, 8534542821713755552u, 150828324359u },
+ { 5033045529399041876u, 7814613482565088782u, 7462658493u },
+ { 15857648521994521781u, 13771954404705323224u, 189423631045u },
+ { 16655573486499109541u, 4568173274762548144u, 197746579144u },
+ { 16652154439190075858u, 8105292616250821343u, 200247641169u },
+ { 18016950600164130638u, 2923678426777275612u, 81439388793u },
+ { 2086292996072613910u, 1808633176918384049u, 121158492925u },
+ { 17324462585194799521u, 18118642609460438969u, 253098046200u },
+ { 11079151463184927232u, 18138164175864360870u, 248982213583u },
+ { 5239846817488961536u, 4031433690465792404u, 207983271850u },
+ { 2778806963520143360u, 5012226396942308537u, 170218544458u },
+ { 6240890740138835968u, 7889712298793536835u, 74271713337u },
+ { 17250651344549707776u, 13500762396543628804u, 57427702160u },
+ { 4197354852709302272u, 501020624068841347u, 144731877796u },
+ { 9223372036854775808u, 8370653768288261750u, 164027160382u },
+ { 0u, 647579990023635200u, 62453774050u },
+ { 0u, 11106569307181154304u, 226035105381u },
+ { 0u, 10797461613892861952u, 101602088328u },
+ { 0u, 17627230675448889344u, 136585331566u },
+ { 0u, 12197735707942322176u, 110955574089u },
+ { 0u, 12871287735024877568u, 73661240577u },
+ { 0u, 4611686018427387904u, 1697753906u },
+ { 0u, 0u, 50250000000u },
+ { 0u, 0u, 128000000000u },
+ { 5654803392547571318u, 31757315u, 0u },
+ { 2931628102185393332u, 31757315306547506u, 0u },
+ { 15964697617980212305u, 9451803574512021605u, 1721567u },
+ { 450380868305846606u, 8662766454758138424u, 223512383298u },
+ { 14631133530814566148u, 9207992007314947035u, 66469609510u },
+ { 31969822783742095u, 17118602861291201802u, 38499166246u },
+ { 10437269029385743245u, 11186560605745599967u, 38928001320u },
+ { 15196146496377392433u, 10505549821532796847u, 40606424665u },
+ { 4409099735137480938u, 18133667530488679216u, 89569506996u },
+ { 10644987914903248118u, 10778135771244330799u, 180983028086u },
+ { 3154431617534062973u, 17087985777033767391u, 118584283910u },
+ { 11702056331247960454u, 2639185991757283040u, 6926341565u },
+ { 15575315065965259114u, 5401720287293896400u, 189143070559u },
+ { 10759747609480050226u, 9816495392633895233u, 95292827843u },
+ { 12538236653960743718u, 10042051500090034990u, 195532153281u },
+ { 17857942663978005403u, 11629689537856384738u, 193544380702u },
+ { 11443004154750813211u, 2099086731766010483u, 30630446733u },
+ { 4004313188770806737u, 13665537898516458594u, 141113791719u },
+ { 17134872954824183228u, 16375672064669490764u, 231740810293u },
+ { 2659553912986171234u, 7770550512184564348u, 53887726961u },
+ { 9501854300969137926u, 6197048880720627314u, 113421242387u },
+ { 14528169966301018150u, 17963594118523106281u, 19335942692u },
+ { 18172091996515901778u, 8255454642407818663u, 36973808388u },
+ { 1133541705604751035u, 16744201957549498409u, 4447529092u },
+ { 18280349987988641497u, 17442505417202859722u, 132907705006u },
+ { 9936015874712336386u, 6383975767786687150u, 174945560113u },
+ { 15876720399740689614u, 15245442964998335795u, 49346076019u },
+ { 8618117825152456982u, 2910016124519524433u, 115826457119u },
+ { 8085525680745921564u, 3847913871169988463u, 31157752290u },
+ { 8072355444669730953u, 17210451512590059177u, 226208595828u },
+ { 9395030504766848294u, 17899408909991454145u, 116932980445u },
+ { 3537903114058185903u, 5920601932753251608u, 221970328901u },
+ { 2126094743961928691u, 16521781895108979744u, 69320956473u },
+ { 289185362555601115u, 3697493405554698771u, 57895647591u },
+ { 16909937501450129614u, 2816108280295732065u, 103200441519u },
+ { 14449642060360499058u, 14251078772056398988u, 175152661535u },
+ { 12433818908498244393u, 4543066550096031417u, 31772552528u },
+ { 11884444034578008581u, 3099369389734296977u, 80246280131u },
+ { 988625838444140793u, 5243484113636490986u, 195168017151u },
+ { 1675370907158909973u, 6823370511605197226u, 255284249843u },
+ { 15920186275316934067u, 11396290277624641942u, 243369895656u },
+ { 5600921198503757726u, 15934361408437566099u, 232617794133u },
+ { 10457357161776341741u, 14939272230935131954u, 85863803462u },
+ { 12225356765775740093u, 7500666177940329347u, 70809859570u },
+ { 4486633318598164537u, 4806714453065462270u, 242406611928u },
+ { 10302486602879381361u, 11557851247268441487u, 216260572512u },
+ { 15536428611301239541u, 10655523157206817381u, 96626552371u },
+ { 12026126645955462603u, 14769600176490881210u, 51577637067u },
+ { 14877968141142123551u, 16688495540925795167u, 203800661629u },
+ { 734560801645383190u, 909793965395524173u, 125904685156u },
+ { 15648943144911081638u, 12724590949761703756u, 100049320029u },
+ { 13664182862003235646u, 10810739657314826395u, 93689801457u },
+ { 3895127525902132786u, 2431218615388671301u, 241586051371u },
+ { 5249187334214137467u, 4235001167959059286u, 43131796625u },
+ { 10642260063359027505u, 6253317787396334247u, 145229579873u },
+ { 783598951897779422u, 9534525563070371898u, 97338993036u },
+ { 5538576558607624843u, 8392783992374030728u, 140516867666u },
+ { 15974581187564609611u, 16356257019231647540u, 82454973731u },
+ { 7474269406918257428u, 12896334001521091877u, 35886674469u },
+ { 8045286838779138019u, 1427636373320877084u, 37699111667u },
+ { 8184246376556341732u, 16116755731295043521u, 243077392322u },
+ { 1493267152679331840u, 15945633911163986837u, 194873691078u },
+ { 10179074811222818816u, 7510154241072743838u, 198864414546u },
+ { 3892499202005008384u, 3571560509790395119u, 82407126277u },
+ { 10341173215925108736u, 3576991649007035076u, 5193614683u },
+ { 6230307872002015232u, 15509961892750732443u, 91193909105u },
+ { 9295429630892703744u, 17789791359353349378u, 113840796718u },
+ { 0u, 18331227331079738314u, 46964386521u },
+ { 0u, 15386712883100476416u, 217993737824u },
+ { 0u, 14082462055028752384u, 96834115376u },
+ { 0u, 12919043128765186048u, 48763411797u },
+ { 0u, 6125373368465096704u, 85700342731u },
+ { 0u, 12335992698065387520u, 203332057155u },
+ { 0u, 2774217370460225536u, 67668735504u },
+ { 0u, 0u, 16150390625u },
+ { 0u, 0u, 97000000000u },
+ { 10665454627995623288u, 484u, 0u },
+ { 16803537892767562832u, 484578175453u, 0u },
+ { 8099123106849104444u, 4962829537462579598u, 26u },
+ { 7077413686679401728u, 5711259460785241095u, 26269035528u },
+ { 13536636358372449666u, 13845894607204897444u, 8309607995u },
+ { 7280632235418610318u, 12116633056637003327u, 59750587450u },
+ { 6187823673116858809u, 2965791047992089560u, 58656843994u },
+ { 8624343686231740255u, 16021997451315962529u, 218160775854u },
+ { 806211610822132771u, 3942052271663803856u, 174868554222u },
+ { 18388078233202190882u, 15669876414782439922u, 238213699081u },
+ { 7628864426595573600u, 10594415915406145286u, 9849465702u },
+ { 4530799784343874981u, 10789820553031921377u, 102574324437u },
+ { 8561580552078486438u, 3989990218583987244u, 213584917344u },
+ { 13349114951221999594u, 2937341169808224563u, 96216297803u },
+ { 10029144738508991772u, 16267436558584536843u, 75159233583u },
+ { 12601907197916268979u, 16221580362814625793u, 47881859502u },
+ { 1329580921391066941u, 9695437602320209830u, 174879373633u },
+ { 3198179786356761112u, 10729753156793715126u, 65525590725u },
+ { 11406753413634654142u, 2609241432056861929u, 197581661084u },
+ { 11131812960525182090u, 8462663743997037565u, 156141447261u },
+ { 14299636753645227208u, 14993422143908194069u, 93458761920u },
+ { 12964114684643663326u, 1307443894537745373u, 192812795043u },
+ { 5019257593846306316u, 10017257439419829265u, 163070876675u },
+ { 6929086798159998121u, 16754772009970777891u, 3543036613u },
+ { 18359765766933703649u, 11722573031602862387u, 197908278010u },
+ { 9993076234752063198u, 7363764277467092384u, 250635481957u },
+ { 3257189215046584509u, 6733958494847390772u, 101399190461u },
+ { 2905234736672690348u, 8799796600227451045u, 189365048621u },
+ { 12064985302079670056u, 10512023194742249826u, 45477037929u },
+ { 14315096064942799930u, 4572542132337197059u, 105569857919u },
+ { 11943971043551974038u, 12600500455757416832u, 127247878005u },
+ { 12472773152119929647u, 7873789864743195199u, 117683074498u },
+ { 7791259796982183085u, 15724851676325671539u, 194426839003u },
+ { 16866829442051086686u, 8748017220462413167u, 219852445917u },
+ { 3702498393844653053u, 14172589522760466448u, 221474230963u },
+ { 2057239613841701716u, 9520545591489413768u, 179768297617u },
+ { 17201969976738286226u, 12488551088392570222u, 145516109810u },
+ { 18271566505443461640u, 1135798823651241684u, 242677005711u },
+ { 18368509115417119804u, 11168725610120161972u, 143061571777u },
+ { 7613923684154518587u, 9580104948718508826u, 193605457828u },
+ { 17984805084714865232u, 16638722716909738765u, 164519338529u },
+ { 4220802739051410373u, 15732724012348272797u, 33901986965u },
+ { 17812459042810815760u, 12269722190021214142u, 149852872677u },
+ { 10629526089664605307u, 13110655916311972587u, 229665142972u },
+ { 17437443267816548473u, 6618112997062866867u, 188710730081u },
+ { 12506371893701049304u, 8457936459015989309u, 97358768624u },
+ { 15737221540003030739u, 3329167139937134914u, 240458505654u },
+ { 2358380859011605513u, 5245511557216705097u, 182180474512u },
+ { 10042972713837039706u, 5655931353280440466u, 144284359751u },
+ { 13424397272769642495u, 604622132328697393u, 71306608653u },
+ { 6867102315755663029u, 8673282619234652338u, 13032776631u },
+ { 8690748404825506734u, 16929477433058445690u, 183470179592u },
+ { 956229930815387710u, 11036952409253549455u, 8917748810u },
+ { 7734449506297687888u, 18199392190170386320u, 74598314388u },
+ { 16332184961683848151u, 9683116091880335715u, 148986591027u },
+ { 15580777817612768828u, 2993913337608915120u, 51524922775u },
+ { 17404245271944696092u, 4490779842162392585u, 151162300367u },
+ { 13201420160494469229u, 946849923353644618u, 207243445663u },
+ { 16511717657124068078u, 3613491058474899828u, 159051328837u },
+ { 14131292492116594062u, 14624054199004410935u, 69195887742u },
+ { 18429136031865875691u, 12088470271991908244u, 126792771566u },
+ { 2563978348305862197u, 10071980927725011290u, 238655317286u },
+ { 14239974392147482896u, 2833441711428854664u, 38546003180u },
+ { 11164201396098998272u, 17655572411864340446u, 236153601182u },
+ { 7116971104932986880u, 4997642792058747802u, 158957110498u },
+ { 12437629862867369984u, 11489200787635734848u, 226270922758u },
+ { 16501893821638901760u, 12983586226429536913u, 6622830822u },
+ { 10649324268870959104u, 12311150768725063152u, 230703841619u },
+ { 7205759403792793600u, 8530052476845967905u, 83667388820u },
+ { 0u, 6282736361499820264u, 148462415071u },
+ { 0u, 11337164765929082880u, 223340587820u },
+ { 0u, 8343856200414134272u, 44614588933u },
+ { 0u, 17889330377156198400u, 5452321350u },
+ { 0u, 17730714064155312128u, 70969782542u },
+ { 0u, 7449235258647511040u, 14961183935u },
+ { 0u, 9943947977234055168u, 191403823852u },
+ { 0u, 0u, 236539062500u },
+ { 0u, 0u, 228000000000u },
+ { 3016823727048309817u, 7394076u, 0u },
+ { 17405973192644624358u, 7394076163542341u, 0u },
+ { 8937219978302591747u, 12396245121240683569u, 400833u },
+ { 15178463196824222317u, 10248996648596888561u, 193672001794u },
+ { 11979404627460330594u, 11257495103713935002u, 2555599221u },
+ { 2006448052689740002u, 7555396579247433114u, 117610270032u },
+ { 16330465320863239865u, 4805022328730367462u, 80409578869u },
+ { 17136208883957646553u, 7056637817080232586u, 117260480782u },
+ { 140455118208931867u, 10811411483818434913u, 14382541102u },
+ { 3964972929179372247u, 16962406704495245447u, 46586087790u },
+ { 3378050330022776379u, 18074517319117194669u, 110919533909u },
+ { 6065353437512901255u, 3702019776117654523u, 85979821547u },
+ { 12768753059854699889u, 3551977551381082764u, 235200686894u },
+ { 6848720690951013326u, 16442608985936005282u, 46192553088u },
+ { 10953228058585475132u, 3580046275479139588u, 128891355619u },
+ { 15539127852083296166u, 8737412692712715330u, 227194074697u },
+ { 14534853647735598497u, 3082033243045084752u, 73473656091u },
+ { 1506909603576368170u, 16401023756841128699u, 27167077356u },
+ { 5475702579938239025u, 7520296082779572869u, 236889101279u },
+ { 12039747373985783332u, 9854104766152464159u, 223407676067u },
+ { 17572399137760898460u, 14169188802648310188u, 163534192089u },
+ { 869552790852091236u, 2018609909210367042u, 217768113264u },
+ { 4549585778048181804u, 8270271948267674359u, 112109429062u },
+ { 4121918231767210357u, 12320338602894572099u, 70448332340u },
+ { 1558397953312543179u, 17538536685990080547u, 52667886893u },
+ { 6067524298738069781u, 15833914616956760474u, 45950765978u },
+ { 5811095224555517056u, 6137696141415969855u, 154858358231u },
+ { 6440894514158997188u, 9757490468419438919u, 215332725174u },
+ { 4612748874388784257u, 3566639201356598903u, 182528954618u },
+ { 9908101430749813367u, 9760900035773954449u, 250193347898u },
+ { 15150017990912190499u, 3873778773990716438u, 58529139451u },
+ { 17470426264690059239u, 2295668377270167832u, 251209997968u },
+ { 9615161096851907726u, 1791721710912807593u, 144124448432u },
+ { 9227932132124142224u, 10571009006922683279u, 176097129428u },
+ { 4794113194321211621u, 9840791932778184867u, 212573055546u },
+ { 391512698859146347u, 11525464956561274613u, 58533470399u },
+ { 17209658878068655842u, 4435781488897895433u, 191624796707u },
+ { 3077364726606876150u, 6395563367070996741u, 35240464196u },
+ { 1952989567673965814u, 15538690795135662932u, 68346704184u },
+ { 11172860676923186449u, 16294558813563371936u, 56842354115u },
+ { 17338078544784947239u, 4942096228426070342u, 195883329803u },
+ { 4593380466519703278u, 6910116424372647153u, 11267911573u },
+ { 786884753602720052u, 17923400669760829478u, 149374598161u },
+ { 17848875822468020539u, 4134686917293039955u, 17971629497u },
+ { 2899664567187130618u, 16857102463116098681u, 185224141826u },
+ { 2973178834961857409u, 11364321508775167451u, 2913825355u },
+ { 11117453141176836727u, 7966947780972783899u, 75616061103u },
+ { 7535238370146462002u, 11261055695926686278u, 175431889104u },
+ { 10246175467290865448u, 9227040437353594058u, 208610463052u },
+ { 1203128834127050464u, 7185344074282882061u, 76500198864u },
+ { 14518048959078919658u, 14197856148610578032u, 208389518282u },
+ { 1553474987376920024u, 885688687260429427u, 202769667324u },
+ { 14956572380830948369u, 17407816160380305183u, 252048013279u },
+ { 7594162606042048292u, 17812728703806357349u, 223943679604u },
+ { 14461296147288811288u, 17120198191964319867u, 116965629957u },
+ { 18305427728131488265u, 12091952048375408786u, 5928087803u },
+ { 10253208939347909876u, 405056939269888281u, 251655506034u },
+ { 6446028915490812012u, 12485440679452408690u, 114021958180u },
+ { 12986063676957432257u, 8394369900823444407u, 36676837095u },
+ { 9769714697972762807u, 2877421667354294258u, 231455059704u },
+ { 97429465146664592u, 2676980714750756239u, 248155985341u },
+ { 16395571728207795868u, 6119309228579057021u, 189145119415u },
+ { 6331668478323650406u, 18203256146533333852u, 183331728417u },
+ { 18129911846294207040u, 351919978865493747u, 33986800493u },
+ { 9890094564876124160u, 5190010931882390570u, 109019077620u },
+ { 12290856656987750400u, 6982466386088036604u, 244281351056u },
+ { 8498454992640802816u, 4707293888784996898u, 144378520261u },
+ { 5341660584200896512u, 690306801165964760u, 197255182913u },
+ { 9288674231451648000u, 12456770961278956704u, 65037421606u },
+ { 1152921504606846976u, 16946092489294063943u, 38675282906u },
+ { 0u, 11098404173866185376u, 218918649514u },
+ { 0u, 15152070965853306880u, 170601645695u },
+ { 0u, 17370091362040414208u, 127821395412u },
+ { 0u, 10141938552171134976u, 212941634539u },
+ { 0u, 10586988556645826560u, 235549795590u },
+ { 0u, 12169852093061922816u, 6573921799u },
+ { 0u, 16717361816799281152u, 7659729003u },
+ { 0u, 0u, 107906250000u },
+ { 0u, 0u, 16000000000u },
+ { 15212079674427582639u, 112u, 0u },
+ { 10179808126814248333u, 112824648491u, 0u },
+ { 6066766544199222848u, 2144184049294538808u, 6u },
+ { 6625308131806923532u, 4108002197393276873u, 6116236450u },
+ { 9122786786400665713u, 6446230217393892753u, 162222695245u },
+ { 11932880778639151320u, 5571068025259989822u, 77349450840u },
+ { 3884040911779255011u, 14804812668872528331u, 88302008202u },
+ { 13441817515637357872u, 17369928488562523047u, 138802570502u },
+ { 11628577856022352826u, 2967474173531035027u, 6941625710u },
+ { 13296656925520243654u, 5291425437992807716u, 110160867097u },
+ { 5020720704545399398u, 14219547193739388064u, 25286848747u },
+ { 14121973606499014694u, 17720313647158217462u, 235770843197u },
+ { 3642481034345420114u, 12334850628290578491u, 61960620127u },
+ { 9845536238569696768u, 7818499847417334620u, 95668673592u },
+ { 17655403572195686356u, 136007040922198372u, 56423841726u },
+ { 8377495365136654029u, 8523477092112604449u, 190007372956u },
+ { 13713682649609025426u, 367934822655966629u, 156462058619u },
+ { 1367709905452854731u, 12964987687054730050u, 123019945786u },
+ { 9981467701727208680u, 15267036012420885462u, 58702833390u },
+ { 6277920117543306205u, 11142900264750765568u, 238827627680u },
+ { 9344111460418701726u, 13680181547777718603u, 160604057833u },
+ { 4918507011364617264u, 13001922925761426065u, 233741604127u },
+ { 6554777203830755259u, 2397730045956515935u, 31704835654u },
+ { 4198262173120265648u, 4482395522588406288u, 70129981206u },
+ { 8080325935698446819u, 3255525722490493080u, 22242991148u },
+ { 12797633874200091733u, 836222287193822098u, 44176482403u },
+ { 8376502502208665497u, 420898743993182306u, 99045331701u },
+ { 9891973386793349173u, 11652649973356574054u, 245022816966u },
+ { 14877430279003795462u, 15058402726661910231u, 198631691420u },
+ { 8759933935842067041u, 9600134495208339559u, 156816317647u },
+ { 3753418510388703513u, 14626343323989004842u, 207520424333u },
+ { 2961383332545305985u, 6813981265331086665u, 141792895660u },
+ { 2497674184068629507u, 10281745288790487888u, 172369386664u },
+ { 15244544070742305452u, 17569829347075761940u, 168557374528u },
+ { 45953573565810823u, 7654580675237889478u, 64952462357u },
+ { 3960077421351906445u, 16194838649686212364u, 21414955649u },
+ { 3173330011013883118u, 6495102772252453635u, 129877923962u },
+ { 11026266219545759160u, 14935159852819761348u, 122352100226u },
+ { 8886757764964685632u, 17381879863441579697u, 130809636637u },
+ { 13952322129918090479u, 9062335510435372583u, 29942273595u },
+ { 4127250666614902202u, 7569219009130126626u, 59491270192u },
+ { 17649958504065306911u, 12652124168176193362u, 48410328184u },
+ { 13269305359002216873u, 8940200224697247767u, 120685873025u },
+ { 16236593433831947843u, 5600570701927432884u, 129484649225u },
+ { 13580930396682424057u, 2018432801986093157u, 9303607546u },
+ { 421976357197961116u, 8235849749361824736u, 250109419461u },
+ { 2962130818798626533u, 9705097287982370040u, 197446466309u },
+ { 8234383947306356345u, 3517483139049842585u, 5526114378u },
+ { 4380469931801381425u, 958281614186777760u, 74190683143u },
+ { 15279887469027055916u, 7336473432636108950u, 7051948550u },
+ { 8534542821713755552u, 12955383920176764423u, 6397711021u },
+ { 7814613482565088782u, 10735469126281273789u, 173702312769u },
+ { 13771954404705323224u, 8637888232514730693u, 65581970947u },
+ { 4568173274762548144u, 6806336737533581000u, 3468260859u },
+ { 8105292616250821343u, 16142569672872330321u, 251368972253u },
+ { 2923678426777275612u, 8141285259947963513u, 221875090455u },
+ { 1808633176918384049u, 5220241098754220797u, 23441339958u },
+ { 18118642609460438969u, 154438799943119608u, 54282989837u },
+ { 18138164175864360870u, 2226876628677628879u, 13008372144u },
+ { 4031433690465792404u, 17219557081221357482u, 176120719223u },
+ { 5012226396942308537u, 15401507148161015114u, 119933474059u },
+ { 7889712298793536835u, 8842629766613985337u, 11834917375u },
+ { 13500762396543628804u, 3180100571546071440u, 255479359920u },
+ { 501020624068841347u, 7740848704392475044u, 176172393597u },
+ { 8370653768288261750u, 2014314126623495998u, 125419632249u },
+ { 647579990023635200u, 11209566016506885858u, 121109196187u },
+ { 11106569307181154304u, 7117166613733441125u, 155607671791u },
+ { 10797461613892861952u, 4197646860931880328u, 239385822375u },
+ { 17627230675448889344u, 5487263271238026094u, 167227554892u },
+ { 12197735707942322176u, 18148076225293562697u, 76297465137u },
+ { 12871287735024877568u, 9127276943027950849u, 49983809183u },
+ { 4611686018427387904u, 9691696125379324722u, 159494790674u },
+ { 0u, 13102362262487705216u, 18525387899u },
+ { 0u, 8929385439893192704u, 123710280481u },
+ { 0u, 11891353410743566336u, 33484062954u },
+ { 0u, 1587423090877399040u, 234644631560u },
+ { 0u, 3489137423026225152u, 8086054378u },
+ { 0u, 13046928120492326912u, 234189146518u },
+ { 0u, 11529215046068469760u, 150707275390u },
+ { 0u, 0u, 126625000000u },
+ { 0u, 0u, 64000000000u },
+ { 9451803574512021605u, 1721567u, 0u },
+ { 8662766454758138424u, 1721567512383298u, 0u },
+ { 9207992007314947035u, 6674960280855494694u, 93326u },
+ { 17118602861291201802u, 16378845781483497510u, 142361850321u },
+ { 11186560605745599967u, 17606907750956804392u, 209887899008u },
+ { 10505549821532796847u, 13225609159240506969u, 128954472381u },
+ { 18133667530488679216u, 2668084873338435252u, 189716961709u },
+ { 10778135771244330799u, 14802814305275861366u, 173144637170u },
+ { 17087985777033767391u, 8005510553372365574u, 242802462171u },
+ { 2639185991757283040u, 12748500143273514429u, 219433979596u },
+ { 5401720287293896400u, 10393733905569036127u, 204691097577u },
+ { 9816495392633895233u, 603389089974790339u, 233563445444u },
+ { 10042051500090034990u, 2033494532597735873u, 196032709788u },
+ { 11629689537856384738u, 9204796763694620958u, 156110235959u },
+ { 2099086731766010483u, 7826260310402107021u, 55498993032u },
+ { 13665537898516458594u, 10122690201685169383u, 136424262421u },
+ { 16375672064669490764u, 7438455564568110133u, 21548752135u },
+ { 7770550512184564348u, 2805412574380520817u, 7403239484u },
+ { 6197048880720627314u, 7250965427231182867u, 60152081720u },
+ { 17963594118523106281u, 8136242944826085924u, 56393075623u },
+ { 8255454642407818663u, 15357191647956011780u, 167441066613u },
+ { 16744201957549498409u, 7369614426695395460u, 117832515027u },
+ { 17442505417202859722u, 10886957545142526638u, 211399507598u },
+ { 6383975767786687150u, 2030047207417538097u, 142590183151u },
+ { 15245442964998335795u, 11557093828502314355u, 239110049079u },
+ { 2910016124519524433u, 15201062539664128543u, 55626511311u },
+ { 3847913871169988463u, 8846936323343880674u, 207824051251u },
+ { 17210451512590059177u, 1485291750116245364u, 51479593379u },
+ { 17899408909991454145u, 2076024439668322013u, 163080517827u },
+ { 5920601932753251608u, 7029497773682748741u, 195112541510u },
+ { 16521781895108979744u, 16333533921668749881u, 70381069837u },
+ { 3697493405554698771u, 2065057316131928423u, 13885442648u },
+ { 2816108280295732065u, 7800502648925570223u, 88111946981u },
+ { 14251078772056398988u, 17011619967093802015u, 229422866095u },
+ { 4543066550096031417u, 5368819344429198672u, 175922201766u },
+ { 3099369389734296977u, 15598879366754275267u, 166291044279u },
+ { 5243484113636490986u, 16393893486035835647u, 183845616944u },
+ { 6823370511605197226u, 12042046205096920307u, 48888714746u },
+ { 11396290277624641942u, 15437070428008474344u, 250652800632u },
+ { 15934361408437566099u, 13704569163204647509u, 120836845264u },
+ { 14939272230935131954u, 18192483750856993350u, 208742926182u },
+ { 7500666177940329347u, 5152535865317963250u, 102986216520u },
+ { 4806714453065462270u, 17512614083933854680u, 72279319528u },
+ { 11557851247268441487u, 14481918350603613536u, 232949360711u },
+ { 10655523157206817381u, 16124419709964004915u, 71785066366u },
+ { 14769600176490881210u, 18088011566435813579u, 126874106543u },
+ { 16688495540925795167u, 15008862380698848893u, 175980553071u },
+ { 909793965395524173u, 18160498644611827812u, 111813632059u },
+ { 12724590949761703756u, 3604680497457231965u, 59984482604u },
+ { 10810739657314826395u, 5957615565551495921u, 44195410121u },
+ { 2431218615388671301u, 17528455034961565995u, 201322962986u },
+ { 4235001167959059286u, 8503772325120113809u, 42950219451u },
+ { 6253317787396334247u, 8501492578048509537u, 187460990421u },
+ { 9534525563070371898u, 2296237701094386060u, 213460866836u },
+ { 8392783992374030728u, 3753593040591076946u, 20124479295u },
+ { 16356257019231647540u, 8518075399775653155u, 63203482686u },
+ { 12896334001521091877u, 12757855675959554597u, 62461765792u },
+ { 1427636373320877084u, 121631169379748595u, 160691604742u },
+ { 16116755731295043521u, 16679062494579173314u, 6006593638u },
+ { 15945633911163986837u, 10739912744743898054u, 102904173789u },
+ { 7510154241072743838u, 9367340677776287570u, 221582211836u },
+ { 3571560509790395119u, 12227321512794715397u, 252507804555u },
+ { 3576991649007035076u, 7241061891859170651u, 139662844427u },
+ { 15509961892750732443u, 13148571323079237489u, 11392538751u },
+ { 17789791359353349378u, 12509763434355012654u, 127712785479u },
+ { 18331227331079738314u, 11812768946960181977u, 71678155634u },
+ { 15386712883100476416u, 14170358803552564832u, 114640371487u },
+ { 14082462055028752384u, 18179989524780635952u, 31768176689u },
+ { 12919043128765186048u, 17091718978514754901u, 49985539206u },
+ { 6125373368465096704u, 7394768384359232459u, 134926543942u },
+ { 12335992698065387520u, 6778628272692852803u, 70400871197u },
+ { 2774217370460225536u, 18193335045875234320u, 29367470174u },
+ { 0u, 1378519212560967521u, 94986262669u },
+ { 0u, 4677732610631043584u, 141074729676u },
+ { 0u, 17296098591070486528u, 204253580392u },
+ { 0u, 7343735382392963072u, 104937623383u },
+ { 0u, 14525996728454217728u, 87398104692u },
+ { 0u, 9691359370008330240u, 116787455860u },
+ { 0u, 3044433348102455296u, 116525369644u },
+ { 0u, 9223372036854775808u, 44165039062u },
+ { 0u, 0u, 214500000000u },
+ { 4962829537462579598u, 26u, 0u },
+ { 5711259460785241095u, 26269035528u, 0u },
+ { 13845894607204897444u, 7822291454600056379u, 1u },
+ { 12116633056637003327u, 8201586317771250746u, 1424047269u },
+ { 2965791047992089560u, 3278889188817135834u, 165444608885u },
+ { 16021997451315962529u, 1710725240251040430u, 117177748939u },
+ { 3942052271663803856u, 1850175733663425006u, 203092738601u },
+ { 15669876414782439922u, 9147599666163914249u, 41100298227u },
+ { 10594415915406145286u, 10221885933644344166u, 243495892371u },
+ { 10789820553031921377u, 14901479793736678101u, 147554129546u },
+ { 3989990218583987244u, 5181831442059703136u, 138807810838u },
+ { 2937341169808224563u, 6396246577759793483u, 22280907645u },
+ { 16267436558584536843u, 14167229556464870447u, 125346741221u },
+ { 16221580362814625793u, 2969982933326311854u, 229768007053u },
+ { 9695437602320209830u, 7892677766222018881u, 141161003097u },
+ { 10729753156793715126u, 798698968922663621u, 89427862919u },
+ { 2609241432056861929u, 15926812109043458972u, 135043297557u },
+ { 8462663743997037565u, 8663842590352697437u, 21863394214u },
+ { 14993422143908194069u, 17093523026636671168u, 166469667847u },
+ { 1307443894537745373u, 839764004742743203u, 7926641740u },
+ { 10017257439419829265u, 16894643909298232323u, 76045523697u },
+ { 16754772009970777891u, 9066702926218949317u, 241915860481u },
+ { 11722573031602862387u, 9119392417260546810u, 1491506950u },
+ { 7363764277467092384u, 9723021096578315109u, 6494363253u },
+ { 6733958494847390772u, 14787464248751217597u, 117527086029u },
+ { 8799796600227451045u, 3733434565920249133u, 205801630043u },
+ { 10512023194742249826u, 6643788868836820841u, 91202389893u },
+ { 4572542132337197059u, 4729646697422664063u, 133360160516u },
+ { 12600500455757416832u, 4090144564201555829u, 4256394661u },
+ { 7873789864743195199u, 2109480737093400002u, 165221727181u },
+ { 15724851676325671539u, 16577155033369419739u, 205114355179u },
+ { 8748017220462413167u, 745377248603805917u, 235898649375u },
+ { 14172589522760466448u, 11305561465807999667u, 31040406981u },
+ { 9520545591489413768u, 2211245518782892177u, 197612875715u },
+ { 12488551088392570222u, 14170095199249735666u, 195119871859u },
+ { 1135798823651241684u, 17849973668116118927u, 115768162399u },
+ { 11168725610120161972u, 9020960204585720001u, 95967649011u },
+ { 9580104948718508826u, 10807134002871850916u, 243489027232u },
+ { 16638722716909738765u, 3925122626254791201u, 160585855908u },
+ { 15732724012348272797u, 17208463291312718997u, 164212781323u },
+ { 12269722190021214142u, 5145077219589447653u, 11932872664u },
+ { 13110655916311972587u, 17602397765035489468u, 216278915194u },
+ { 6618112997062866867u, 16422643262490753377u, 122954227894u },
+ { 8457936459015989309u, 2902509461400906224u, 182890273275u },
+ { 3329167139937134914u, 3422418805967265206u, 251157345353u },
+ { 5245511557216705097u, 4228874576277237392u, 73185529695u },
+ { 5655931353280440466u, 2553488530807495751u, 95229247750u },
+ { 604622132328697393u, 11546099176912486413u, 6138424890u },
+ { 8673282619234652338u, 10460791037534167991u, 58625915290u },
+ { 16929477433058445690u, 8127117908566000904u, 154567080618u },
+ { 11036952409253549455u, 11541304458088287306u, 170440571944u },
+ { 18199392190170386320u, 6249718665174839700u, 40625655368u },
+ { 9683116091880335715u, 13102508413386290995u, 72338797927u },
+ { 2993913337608915120u, 6274675218640661911u, 103710288404u },
+ { 4490779842162392585u, 3404497118599817167u, 20340150825u },
+ { 946849923353644618u, 11258566093988562335u, 41184558158u },
+ { 3613491058474899828u, 16762592482501635397u, 78610328090u },
+ { 14624054199004410935u, 5550125446725071998u, 26908701959u },
+ { 12088470271991908244u, 6370033225258510318u, 7300872903u },
+ { 10071980927725011290u, 1503521728674735398u, 199345320193u },
+ { 2833441711428854664u, 4250415082606384364u, 1081506076u },
+ { 17655572411864340446u, 6020091901030562974u, 28230415463u },
+ { 4997642792058747802u, 16288222967151527138u, 103326349835u },
+ { 11489200787635734848u, 6377016228656203782u, 11882986336u },
+ { 12983586226429536913u, 8378856515587563750u, 96345698742u },
+ { 12311150768725063152u, 15812881490200838483u, 182454218721u },
+ { 8530052476845967905u, 4548570371183413652u, 225857218023u },
+ { 6282736361499820264u, 16731431495283420383u, 231246578493u },
+ { 11337164765929082880u, 14737727629551135532u, 61907012718u },
+ { 8343856200414134272u, 12413722258104293893u, 110798933815u },
+ { 17889330377156198400u, 800899742400762438u, 55672949232u },
+ { 17730714064155312128u, 603197008376033550u, 240043416862u },
+ { 7449235258647511040u, 6380777281587743935u, 30032699375u },
+ { 9943947977234055168u, 10001440249018225388u, 239345902629u },
+ { 0u, 5505914461980436708u, 37542179162u },
+ { 0u, 1105464290051876864u, 90298476221u },
+ { 0u, 4500443576769970176u, 189059927339u },
+ { 0u, 2843045143185981440u, 43243969535u },
+ { 0u, 660949699682893824u, 255154121786u },
+ { 0u, 276549164618219520u, 58035830155u },
+ { 0u, 4683743612465315840u, 139014991760u },
+ { 0u, 0u, 144253906250u },
+ { 0u, 0u, 74000000000u },
+ { 12396245121240683569u, 400833u, 0u },
+ { 10248996648596888561u, 400833672001794u, 0u },
+ { 11257495103713935002u, 4370024159708535157u, 21729u },
+ { 7555396579247433114u, 7166684413908503888u, 225236899484u },
+ { 4805022328730367462u, 10217286283215687029u, 156388506740u },
+ { 7056637817080232586u, 4767369911989629198u, 116553880199u },
+ { 10811411483818434913u, 14407999214182082862u, 135258439640u },
+ { 16962406704495245447u, 8472271297615317358u, 216781059202u },
+ { 18074517319117194669u, 6236024012584764757u, 130459282747u },
+ { 3702019776117654523u, 1951826556984620523u, 59338055539u },
+ { 3551977551381082764u, 12357130551551830830u, 115105808729u },
+ { 16442608985936005282u, 8927758011099278464u, 89669881389u },
+ { 3580046275479139588u, 10199854049407140323u, 45483974731u },
+ { 8737412692712715330u, 17895455027038549577u, 75552935195u },
+ { 3082033243045084752u, 16539200343720527131u, 27970114560u },
+ { 16401023756841128699u, 3536976106235802604u, 896591847u },
+ { 7520296082779572869u, 16980391644793590751u, 231191739858u },
+ { 9854104766152464159u, 10090294316609084067u, 210920508875u },
+ { 14169188802648310188u, 17603457857266236889u, 203546995950u },
+ { 2018609909210367042u, 11164962743035868272u, 238954285362u },
+ { 8270271948267674359u, 1585686890718568774u, 50605253843u },
+ { 12320338602894572099u, 10882524700472655412u, 211085960258u },
+ { 17538536685990080547u, 2194808754940947757u, 66589942846u },
+ { 15833914616956760474u, 274100791137209242u, 62118980821u },
+ { 6137696141415969855u, 12203404582981010903u, 213014859033u },
+ { 9757490468419438919u, 541940706340938166u, 25661547888u },
+ { 3566639201356598903u, 10305434016011833594u, 112029378664u },
+ { 9760900035773954449u, 7900783531944543546u, 104558658697u },
+ { 3873778773990716438u, 8920818625012419323u, 137428302333u },
+ { 2295668377270167832u, 12532363335400447632u, 253483598546u },
+ { 1791721710912807593u, 13483507182924762800u, 210679380777u },
+ { 10571009006922683279u, 415911049779278804u, 41730942389u },
+ { 9840791932778184867u, 3441628281170127418u, 181022546583u },
+ { 11525464956561274613u, 17830811568183566527u, 151186571042u },
+ { 4435781488897895433u, 17897295813176613411u, 34966610231u },
+ { 6395563367070996741u, 2086148701331574596u, 55970214350u },
+ { 15538690795135662932u, 13015567826878853432u, 206113090347u },
+ { 16294558813563371936u, 12944531121587846595u, 43705575345u },
+ { 4942096228426070342u, 3534180912913737995u, 177701724438u },
+ { 6910116424372647153u, 3447584022400118677u, 22191588331u },
+ { 17923400669760829478u, 6375676813770849297u, 235186893904u },
+ { 4134686917293039955u, 11580694081479200185u, 80345626132u },
+ { 16857102463116098681u, 1872134358882196482u, 20627790684u },
+ { 11364321508775167451u, 17602652840520938059u, 92101488606u },
+ { 7966947780972783899u, 10331040597716338351u, 222954241722u },
+ { 11261055695926686278u, 73785407041056976u, 186560046833u },
+ { 9227040437353594058u, 17166209109167902028u, 241003999914u },
+ { 7185344074282882061u, 8762475644006589904u, 170930582060u },
+ { 14197856148610578032u, 8839001228645872586u, 44475014756u },
+ { 885688687260429427u, 13558262784529110268u, 100479163216u },
+ { 17407816160380305183u, 5640853896420358111u, 80734994898u },
+ { 17812728703806357349u, 8459930353450835572u, 210305791302u },
+ { 17120198191964319867u, 7643830211500171269u, 70458613743u },
+ { 12091952048375408786u, 1308629115231236347u, 239414372866u },
+ { 405056939269888281u, 8957268500971669618u, 2070940926u },
+ { 12485440679452408690u, 7645679094277669412u, 254485574498u },
+ { 8394369900823444407u, 3821107497040617191u, 98414473094u },
+ { 2877421667354294258u, 8847137191985934072u, 134207142652u },
+ { 2676980714750756239u, 3531126524756088253u, 252479604268u },
+ { 6119309228579057021u, 8726915034124352183u, 44191422752u },
+ { 18203256146533333852u, 17611136727168068641u, 32473087011u },
+ { 351919978865493747u, 18017743272784259949u, 35954701634u },
+ { 5190010931882390570u, 18113575006829616116u, 66976743819u },
+ { 6982466386088036604u, 12805550441678740368u, 139981938868u },
+ { 4707293888784996898u, 8061966093393027781u, 180694190280u },
+ { 690306801165964760u, 11954593141554100801u, 200437040057u },
+ { 12456770961278956704u, 14068656112359197734u, 185648059792u },
+ { 16946092489294063943u, 895878255770467290u, 144762663376u },
+ { 11098404173866185376u, 10319906489512197802u, 208048565657u },
+ { 15152070965853306880u, 14551142616794302079u, 153559443251u },
+ { 17370091362040414208u, 15933181735739307476u, 51788819021u },
+ { 10141938552171134976u, 11524527334398983147u, 77863739512u },
+ { 10586988556645826560u, 11828012606225556742u, 120624745878u },
+ { 12169852093061922816u, 3556238869349799431u, 150641197848u },
+ { 16717361816799281152u, 7403090230513381483u, 24192784095u },
+ { 0u, 10172292854665622800u, 223401322325u },
+ { 0u, 11240746576366182400u, 85551441100u },
+ { 0u, 17021927826892259328u, 204609362092u },
+ { 0u, 9046328496309141504u, 172922760556u },
+ { 0u, 8038996803112140800u, 108490402450u },
+ { 0u, 17098478935265509376u, 146435794889u },
+ { 0u, 7205759403792793600u, 201926910400u },
+ { 0u, 0u, 192390625000u },
+ { 0u, 0u, 232000000000u },
+ { 2144184049294538808u, 6u, 0u },
+ { 4108002197393276873u, 6116236450u, 0u },
+ { 6446230217393892753u, 6116236450222695245u, 0u },
+ { 5571068025259989822u, 6240972538554414168u, 331561842u },
+ { 14804812668872528331u, 4356262642990299018u, 114338323799u },
+ { 17369928488562523047u, 1335108558830511366u, 87236153471u },
+ { 2967474173531035027u, 18435704923261947246u, 127072376379u },
+ { 5291425437992807716u, 8395401931972636441u, 59999401566u },
+ { 14219547193739388064u, 12482665946362458347u, 94455115650u },
+ { 17720313647158217462u, 16101242875289374781u, 130676686676u },
+ { 12334850628290578491u, 4708983440241068127u, 84872850125u },
+ { 7818499847417334620u, 14856666972541426744u, 205255274503u },
+ { 136007040922198372u, 6938795288315789246u, 7805381530u },
+ { 8523477092112604449u, 5556307628265073820u, 154376152846u },
+ { 367934822655966629u, 1441404248927865979u, 14301208040u },
+ { 12964987687054730050u, 16710378912353838906u, 232078138680u },
+ { 15267036012420885462u, 18289940136919312110u, 56905871455u },
+ { 11142900264750765568u, 10217414145292657824u, 95991499641u },
+ { 13680181547777718603u, 12461165826430955753u, 121553887130u },
+ { 13001922925761426065u, 662762458988270879u, 154675521153u },
+ { 2397730045956515935u, 16488546856395302470u, 129035928424u },
+ { 4482395522588406288u, 2612816787977180950u, 104893845916u },
+ { 3255525722490493080u, 16446616379327454252u, 156141641081u },
+ { 836222287193822098u, 7842178508581740643u, 121891572860u },
+ { 420898743993182306u, 14779029861369369333u, 124425125348u },
+ { 11652649973356574054u, 2697664446153849542u, 228801172814u },
+ { 15058402726661910231u, 12135106444393649308u, 78146240682u },
+ { 9600134495208339559u, 9550285041205189839u, 170657845438u },
+ { 14626343323989004842u, 8790318168586740109u, 190517721989u },
+ { 6813981265331086665u, 14038474217155846828u, 133476524102u },
+ { 10281745288790487888u, 4263144264274812072u, 70761027212u },
+ { 17569829347075761940u, 11940456333341715520u, 140231105513u },
+ { 7654580675237889478u, 15751110736831573013u, 233647293434u },
+ { 16194838649686212364u, 18384528705472318081u, 250853869423u },
+ { 6495102772252453635u, 2393654818032310394u, 111996627298u },
+ { 14935159852819761348u, 12812209822018626434u, 98129760287u },
+ { 17381879863441579697u, 3110778569433458461u, 31694551286u },
+ { 9062335510435372583u, 2860264756226872891u, 246168635644u },
+ { 7569219009130126626u, 2384146980060315184u, 252155055263u },
+ { 12652124168176193362u, 14117430062880324728u, 159129244866u },
+ { 8940200224697247767u, 3769610173216737153u, 194765307417u },
+ { 5600570701927432884u, 17731974340232672009u, 25204350976u },
+ { 2018432801986093157u, 1971479303384713466u, 961252255u },
+ { 8235849749361824736u, 3449462959779012549u, 159106874107u },
+ { 9705097287982370040u, 13743454852043766533u, 251186995761u },
+ { 3517483139049842585u, 7417711187131879498u, 49745034180u },
+ { 958281614186777760u, 3650992383501007879u, 196402114929u },
+ { 7336473432636108950u, 12838770342493958662u, 113197920693u },
+ { 12955383920176764423u, 16025068246546338477u, 181695991134u },
+ { 10735469126281273789u, 6579965938260177729u, 94868720690u },
+ { 8637888232514730693u, 4742939430174291459u, 50356700668u },
+ { 6806336737533581000u, 13062256857527449083u, 252257115261u },
+ { 16142569672872330321u, 2301174570202439645u, 125708106363u },
+ { 8141285259947963513u, 7638687886069412887u, 123124746923u },
+ { 5220241098754220797u, 936322449610274358u, 171414094100u },
+ { 154438799943119608u, 12926010544311283981u, 20050758141u },
+ { 2226876628677628879u, 12647854908989899184u, 253700720435u },
+ { 17219557081221357482u, 8862093163358513015u, 51685641588u },
+ { 15401507148161015114u, 444784343917630731u, 116480415033u },
+ { 8842629766613985337u, 11033952249213387263u, 57024111807u },
+ { 3180100571546071440u, 18168634046363183536u, 191598151749u },
+ { 7740848704392475044u, 3837904761417065597u, 69984923625u },
+ { 2014314126623495998u, 111459007020906105u, 233208053234u },
+ { 11209566016506885858u, 16191761957496794523u, 242006042204u },
+ { 7117166613733441125u, 9856250800340378607u, 92877757174u },
+ { 4197646860931880328u, 9491800102275105959u, 246534308426u },
+ { 5487263271238026094u, 10777328578953608268u, 74514551514u },
+ { 18148076225293562697u, 17424440628313779505u, 218584240152u },
+ { 9127276943027950849u, 3285814872419755679u, 24944580819u },
+ { 9691696125379324722u, 2824823424107240978u, 211178124381u },
+ { 13102362262487705216u, 12271707680713669755u, 93153133984u },
+ { 8929385439893192704u, 6951481875178001185u, 160665250606u },
+ { 11891353410743566336u, 10202522487003824362u, 46376840587u },
+ { 1587423090877399040u, 4834668463880990728u, 139553079852u },
+ { 3489137423026225152u, 10871520987687904746u, 44262087902u },
+ { 13046928120492326912u, 12057698794225322390u, 222589346333u },
+ { 11529215046068469760u, 7263351819222681214u, 29653649161u },
+ { 0u, 1778055686910650944u, 9393747091u },
+ { 0u, 17108187120491986944u, 147096388591u },
+ { 0u, 3067636961549221888u, 239927436682u },
+ { 0u, 16702141595163557888u, 138166296932u },
+ { 0u, 2432053749942845440u, 100905424910u },
+ { 0u, 17791470327927144448u, 14131841897u },
+ { 0u, 1152921504606846976u, 105964477539u },
+ { 0u, 0u, 99062500000u },
+ { 0u, 0u, 160000000000u },
+ { 6674960280855494694u, 93326u, 0u },
+ { 16378845781483497510u, 93326361850321u, 0u },
+ { 17606907750956804392u, 4283581425266273664u, 5059u },
+ { 13225609159240506969u, 6725911039793895357u, 195232213414u },
+ { 2668084873338435252u, 1188689198788975021u, 166364612368u },
+ { 14802814305275861366u, 10825527435847761650u, 16064438970u },
+ { 8005510553372365574u, 3917696829526085083u, 186586853018u },
+ { 12748500143273514429u, 12646861173976387276u, 154212378770u },
+ { 10393733905569036127u, 18398576063183996905u, 146685587717u },
+ { 603389089974790339u, 16919251228485834948u, 5997388806u },
+ { 2033494532597735873u, 17296019588687185052u, 6917194446u },
+ { 9204796763694620958u, 12365301604512770359u, 206937619100u },
+ { 7826260310402107021u, 2814271599679204744u, 156670324343u },
+ { 10122690201685169383u, 2154994415780170517u, 119152561969u },
+ { 7438455564568110133u, 6717373824370072839u, 49116822481u },
+ { 2805412574380520817u, 12709155755801344060u, 209364149564u },
+ { 7250965427231182867u, 826847911966403896u, 60688964714u },
+ { 8136242944826085924u, 2277322703890025383u, 106044823515u },
+ { 15357191647956011780u, 2774508958389496437u, 219123453911u },
+ { 7369614426695395460u, 245697774950120915u, 215150406432u },
+ { 10886957545142526638u, 1268929063431863950u, 32013319303u },
+ { 2030047207417538097u, 6735665673159411439u, 135068788782u },
+ { 11557093828502314355u, 14734771742997073207u, 46365141167u },
+ { 15201062539664128543u, 13683287077957612495u, 175798773576u },
+ { 8846936323343880674u, 15370263741354826803u, 72741772478u },
+ { 1485291750116245364u, 48035913070297507u, 190833223667u },
+ { 2076024439668322013u, 1206547475966802115u, 243002604032u },
+ { 7029497773682748741u, 13512340386605768006u, 65407069u },
+ { 16333533921668749881u, 2325760467700278797u, 93732505440u },
+ { 2065057316131928423u, 10848110652847753816u, 96126079727u },
+ { 7800502648925570223u, 15846378960784301285u, 239588077256u },
+ { 17011619967093802015u, 14121839924449844911u, 200859033924u },
+ { 5368819344429198672u, 5147613424753296550u, 68765546476u },
+ { 15598879366754275267u, 16817040482828810167u, 236279052682u },
+ { 16393893486035835647u, 5773528746119363888u, 138911653591u },
+ { 12042046205096920307u, 8716201595536184826u, 215312983620u },
+ { 15437070428008474344u, 5259122109038474872u, 68472506235u },
+ { 13704569163204647509u, 14744540084230155984u, 123285097580u },
+ { 18192483750856993350u, 10719345477982635878u, 108799303119u },
+ { 5152535865317963250u, 13698037261310555208u, 207581096882u },
+ { 17512614083933854680u, 16141171632951976936u, 178742572087u },
+ { 14481918350603613536u, 10060790174955808839u, 55875014667u },
+ { 16124419709964004915u, 4250043307981877118u, 11545396528u },
+ { 18088011566435813579u, 7075646198054337199u, 48230395309u },
+ { 15008862380698848893u, 18141738384245531503u, 173383571548u },
+ { 18160498644611827812u, 8174370508376809531u, 92983465608u },
+ { 3604680497457231965u, 3581964982731575596u, 136443133513u },
+ { 5957615565551495921u, 14798509948722114761u, 73194178710u },
+ { 17528455034961565995u, 14713923334885122090u, 150802228831u },
+ { 8503772325120113809u, 5042978054260414139u, 95797643382u },
+ { 8501492578048509537u, 2052996319372883413u, 118273380388u },
+ { 2296237701094386060u, 8825683007899981588u, 36111293153u },
+ { 3753593040591076946u, 9992196755378745151u, 225478441234u },
+ { 8518075399775653155u, 9301073417573669950u, 18541678071u },
+ { 12757855675959554597u, 5331614769144850592u, 247504212200u },
+ { 121631169379748595u, 14354009428310052102u, 232289027415u },
+ { 16679062494579173314u, 5581221063029119078u, 87778132410u },
+ { 10739912744743898054u, 1529260335339476189u, 186302558600u },
+ { 9367340677776287570u, 16483061525949201148u, 136082901368u },
+ { 12227321512794715397u, 14431217812333089675u, 120893548555u },
+ { 7241061891859170651u, 3452349151135392267u, 11782317885u },
+ { 13148571323079237489u, 9075317899834447999u, 61187152222u },
+ { 12509763434355012654u, 2764331337978901575u, 94491973969u },
+ { 11812768946960181977u, 1942890683708857202u, 81149854702u },
+ { 14170358803552564832u, 165089169728028447u, 238105324315u },
+ { 18179989524780635952u, 15193620741871233073u, 27008949501u },
+ { 17091718978514754901u, 14995000835194145926u, 253823647830u },
+ { 7394768384359232459u, 1788823614552255558u, 86812880624u },
+ { 6778628272692852803u, 8384901184618498845u, 240096972322u },
+ { 18193335045875234320u, 405511217862281310u, 34454546404u },
+ { 1378519212560967521u, 3111530463755196557u, 228021982807u },
+ { 4677732610631043584u, 7893558450035460812u, 87168676404u },
+ { 17296098591070486528u, 156573858237402216u, 52427910661u },
+ { 7343735382392963072u, 15915324019419451223u, 5008487885u },
+ { 14525996728454217728u, 16293363012778802804u, 205862771443u },
+ { 9691359370008330240u, 14342105318291351412u, 243883264978u },
+ { 3044433348102455296u, 3788398842525387052u, 210777487087u },
+ { 9223372036854775808u, 14118764407048307670u, 239205369512u },
+ { 0u, 2705021334614720768u, 168765379752u },
+ { 0u, 7017988973805568000u, 168146639500u },
+ { 0u, 10956732053634154496u, 140380445944u },
+ { 0u, 14657517938546835456u, 248593965634u },
+ { 0u, 11268868284797157376u, 66794585639u },
+ { 0u, 14600669991935148032u, 39610886573u },
+ { 0u, 4611686018427387904u, 173791503906u },
+ { 0u, 0u, 34250000000u },
+ { 0u, 0u, 128000000000u },
+ { 8201586317771250746u, 1424047269u, 0u },
+ { 3278889188817135834u, 1424047269444608885u, 0u },
+ { 1710725240251040430u, 3001188830946823627u, 77197757u },
+ { 1850175733663425006u, 9732296932705387049u, 189162694772u },
+ { 9147599666163914249u, 16337535782679529459u, 116527588873u },
+ { 10221885933644344166u, 7969742269895046547u, 9885659589u },
+ { 14901479793736678101u, 2923592083903829642u, 197432040594u },
+ { 5181831442059703136u, 8144196241160608534u, 146158488244u },
+ { 6396246577759793483u, 16431078457793424253u, 180441497762u },
+ { 14167229556464870447u, 202362949592775653u, 162890730548u },
+ { 2969982933326311854u, 8835125248522947981u, 52010970117u },
+ { 7892677766222018881u, 7959873808777345113u, 5478953099u },
+ { 798698968922663621u, 14929747122315126151u, 139431505623u },
+ { 15926812109043458972u, 4310328817360515349u, 215809343213u },
+ { 8663842590352697437u, 7294899422760201126u, 237233663393u },
+ { 17093523026636671168u, 2047461597291187207u, 161395457290u },
+ { 839764004742743203u, 10942374468813517900u, 10110993115u },
+ { 16894643909298232323u, 10364795403063433969u, 219593187308u },
+ { 9066702926218949317u, 12330859528790939137u, 236561876684u },
+ { 9119392417260546810u, 8973160144879916806u, 204668457234u },
+ { 9723021096578315109u, 2895354388547509877u, 18486435986u },
+ { 14787464248751217597u, 16766844772497556429u, 146156957475u },
+ { 3733434565920249133u, 7442407174620948827u, 35908932476u },
+ { 6643788868836820841u, 6683013428676659077u, 124403453701u },
+ { 4729646697422664063u, 16713703375071907588u, 5362286883u },
+ { 4090144564201555829u, 8791044883080637861u, 35906051675u },
+ { 2109480737093400002u, 602844107089214413u, 91476563498u },
+ { 16577155033369419739u, 9754832281172880875u, 42032680244u },
+ { 745377248603805917u, 10587846778003503903u, 52528810517u },
+ { 11305561465807999667u, 17206244172922947013u, 21573968323u },
+ { 2211245518782892177u, 11620628420699303875u, 195932752365u },
+ { 14170095199249735666u, 17864732368219338611u, 237629955528u },
+ { 17849973668116118927u, 4146383014621345887u, 200968449082u },
+ { 9020960204585720001u, 11445705075042688243u, 58224775873u },
+ { 10807134002871850916u, 7369147888966546592u, 193620472915u },
+ { 3925122626254791201u, 9762476865090597796u, 83399482307u },
+ { 17208463291312718997u, 5507001428194242827u, 195529224931u },
+ { 5145077219589447653u, 11371471148365328344u, 227298535145u },
+ { 17602397765035489468u, 3148788104946538618u, 233616448686u },
+ { 16422643262490753377u, 3762722308424507574u, 174170696145u },
+ { 2902509461400906224u, 1156171244825745915u, 209203977585u },
+ { 3422418805967265206u, 14208921674868257865u, 113062676168u },
+ { 4228874576277237392u, 7903080886897905503u, 200770267187u },
+ { 2553488530807495751u, 6367240794154270982u, 51428426873u },
+ { 11546099176912486413u, 1623672396662369850u, 121345168815u },
+ { 10460791037534167991u, 18323231215381674394u, 175088019456u },
+ { 8127117908566000904u, 9842279843006544554u, 993304354u },
+ { 11541304458088287306u, 7376839231308610600u, 34533551059u },
+ { 6249718665174839700u, 609751749293657672u, 211399899256u },
+ { 13102508413386290995u, 10386457966860989799u, 120033054708u },
+ { 6274675218640661911u, 11160336020836149780u, 244563051014u },
+ { 3404497118599817167u, 17947559933847409193u, 6605003027u },
+ { 11258566093988562335u, 10229787001712704590u, 19972939173u },
+ { 16762592482501635397u, 10441677090043619866u, 165554557864u },
+ { 5550125446725071998u, 4996681336392922375u, 168566044449u },
+ { 6370033225258510318u, 124497102381021895u, 33270870638u },
+ { 1503521728674735398u, 8180812057779384577u, 110006749001u },
+ { 4250415082606384364u, 5294232873532946716u, 73443482710u },
+ { 6020091901030562974u, 2885620189169448039u, 86287000939u },
+ { 16288222967151527138u, 16662526875008170507u, 107156429783u },
+ { 6377016228656203782u, 15663095032402672480u, 215903277391u },
+ { 8378856515587563750u, 1824281504410546614u, 79849098083u },
+ { 15812881490200838483u, 9506565509584809953u, 99098894498u },
+ { 4548570371183413652u, 16941136942345070055u, 162515351948u },
+ { 16731431495283420383u, 15924115693705937725u, 140918380873u },
+ { 14737727629551135532u, 9247807690406628462u, 73863248041u },
+ { 12413722258104293893u, 7993916633864834871u, 169501324659u },
+ { 800899742400762438u, 1018504409177639408u, 115433351089u },
+ { 603197008376033550u, 12097800686634130718u, 177055213234u },
+ { 6380777281587743935u, 6221488888422637551u, 178655823089u },
+ { 10001440249018225388u, 8229322865256080421u, 241337267588u },
+ { 5505914461980436708u, 7927745108183101786u, 132446112486u },
+ { 1105464290051876864u, 8488683721235326653u, 230429763923u },
+ { 4500443576769970176u, 11165516518170922283u, 83460172466u },
+ { 2843045143185981440u, 5463648141113596927u, 178605283863u },
+ { 660949699682893824u, 3958440403860778042u, 23296184959u },
+ { 276549164618219520u, 5091534813990256011u, 127214587484u },
+ { 4683743612465315840u, 6100166970623291280u, 92276012655u },
+ { 0u, 1913011027739012426u, 111330690714u },
+ { 0u, 11310957650604221440u, 154103704535u },
+ { 0u, 16303817257009020928u, 215613168242u },
+ { 0u, 9090406322154766336u, 114883831704u },
+ { 0u, 3003279315069566976u, 152492791914u },
+ { 0u, 16582887146675765248u, 106162808097u },
+ { 0u, 9691746398101307392u, 33898960113u },
+ { 0u, 0u, 241525390625u },
+ { 0u, 0u, 33000000000u },
+};
+
+_LIBCPP_END_NAMESPACE_STD
+
+// clang-format on
+
+#endif // _LIBCPP_SRC_INCLUDE_RYU_D2FIXED_FULL_TABLE_H
diff --git a/contrib/llvm-project/libcxx/src/include/ryu/d2s.h b/contrib/llvm-project/libcxx/src/include/ryu/d2s.h
new file mode 100644
index 000000000000..3d9f10c0f15a
--- /dev/null
+++ b/contrib/llvm-project/libcxx/src/include/ryu/d2s.h
@@ -0,0 +1,62 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// Copyright (c) Microsoft Corporation.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+// Copyright 2018 Ulf Adams
+// Copyright (c) Microsoft Corporation. All rights reserved.
+
+// Boost Software License - Version 1.0 - August 17th, 2003
+
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+
+#ifndef _LIBCPP_SRC_INCLUDE_RYU_DS2_H
+#define _LIBCPP_SRC_INCLUDE_RYU_DS2_H
+
+// Avoid formatting to keep the changes with the original code minimal.
+// clang-format off
+
+#include <__config>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+inline constexpr int __DOUBLE_MANTISSA_BITS = 52;
+inline constexpr int __DOUBLE_EXPONENT_BITS = 11;
+inline constexpr int __DOUBLE_BIAS = 1023;
+
+inline constexpr int __DOUBLE_POW5_INV_BITCOUNT = 122;
+inline constexpr int __DOUBLE_POW5_BITCOUNT = 121;
+
+[[nodiscard]] to_chars_result __d2s_buffered_n(char* const _First, char* const _Last, const double __f, const chars_format _Fmt);
+
+_LIBCPP_END_NAMESPACE_STD
+
+// clang-format on
+
+#endif // _LIBCPP_SRC_INCLUDE_RYU_DS2_H
diff --git a/contrib/llvm-project/libcxx/src/include/ryu/d2s_full_table.h b/contrib/llvm-project/libcxx/src/include/ryu/d2s_full_table.h
new file mode 100644
index 000000000000..96307f698627
--- /dev/null
+++ b/contrib/llvm-project/libcxx/src/include/ryu/d2s_full_table.h
@@ -0,0 +1,368 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// Copyright (c) Microsoft Corporation.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+// Copyright 2018 Ulf Adams
+// Copyright (c) Microsoft Corporation. All rights reserved.
+
+// Boost Software License - Version 1.0 - August 17th, 2003
+
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+
+#ifndef _LIBCPP_SRC_INCLUDE_RYU_D2S_FULL_TABLE_H
+#define _LIBCPP_SRC_INCLUDE_RYU_D2S_FULL_TABLE_H
+
+// Avoid formatting to keep the changes with the original code minimal.
+// clang-format off
+
+#include <__config>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+inline constexpr uint64_t __DOUBLE_POW5_INV_SPLIT[292][2] = {
+ { 1u, 288230376151711744u }, { 3689348814741910324u, 230584300921369395u },
+ { 2951479051793528259u, 184467440737095516u }, { 17118578500402463900u, 147573952589676412u },
+ { 12632330341676300947u, 236118324143482260u }, { 10105864273341040758u, 188894659314785808u },
+ { 15463389048156653253u, 151115727451828646u }, { 17362724847566824558u, 241785163922925834u },
+ { 17579528692795369969u, 193428131138340667u }, { 6684925324752475329u, 154742504910672534u },
+ { 18074578149087781173u, 247588007857076054u }, { 18149011334012135262u, 198070406285660843u },
+ { 3451162622983977240u, 158456325028528675u }, { 5521860196774363583u, 253530120045645880u },
+ { 4417488157419490867u, 202824096036516704u }, { 7223339340677503017u, 162259276829213363u },
+ { 7867994130342094503u, 259614842926741381u }, { 2605046489531765280u, 207691874341393105u },
+ { 2084037191625412224u, 166153499473114484u }, { 10713157136084480204u, 265845599156983174u },
+ { 12259874523609494487u, 212676479325586539u }, { 13497248433629505913u, 170141183460469231u },
+ { 14216899864323388813u, 272225893536750770u }, { 11373519891458711051u, 217780714829400616u },
+ { 5409467098425058518u, 174224571863520493u }, { 4965798542738183305u, 278759314981632789u },
+ { 7661987648932456967u, 223007451985306231u }, { 2440241304404055250u, 178405961588244985u },
+ { 3904386087046488400u, 285449538541191976u }, { 17880904128604832013u, 228359630832953580u },
+ { 14304723302883865611u, 182687704666362864u }, { 15133127457049002812u, 146150163733090291u },
+ { 16834306301794583852u, 233840261972944466u }, { 9778096226693756759u, 187072209578355573u },
+ { 15201174610838826053u, 149657767662684458u }, { 2185786488890659746u, 239452428260295134u },
+ { 5437978005854438120u, 191561942608236107u }, { 15418428848909281466u, 153249554086588885u },
+ { 6222742084545298729u, 245199286538542217u }, { 16046240111861969953u, 196159429230833773u },
+ { 1768945645263844993u, 156927543384667019u }, { 10209010661905972635u, 251084069415467230u },
+ { 8167208529524778108u, 200867255532373784u }, { 10223115638361732810u, 160693804425899027u },
+ { 1599589762411131202u, 257110087081438444u }, { 4969020624670815285u, 205688069665150755u },
+ { 3975216499736652228u, 164550455732120604u }, { 13739044029062464211u, 263280729171392966u },
+ { 7301886408508061046u, 210624583337114373u }, { 13220206756290269483u, 168499666669691498u },
+ { 17462981995322520850u, 269599466671506397u }, { 6591687966774196033u, 215679573337205118u },
+ { 12652048002903177473u, 172543658669764094u }, { 9175230360419352987u, 276069853871622551u },
+ { 3650835473593572067u, 220855883097298041u }, { 17678063637842498946u, 176684706477838432u },
+ { 13527506561580357021u, 282695530364541492u }, { 3443307619780464970u, 226156424291633194u },
+ { 6443994910566282300u, 180925139433306555u }, { 5155195928453025840u, 144740111546645244u },
+ { 15627011115008661990u, 231584178474632390u }, { 12501608892006929592u, 185267342779705912u },
+ { 2622589484121723027u, 148213874223764730u }, { 4196143174594756843u, 237142198758023568u },
+ { 10735612169159626121u, 189713759006418854u }, { 12277838550069611220u, 151771007205135083u },
+ { 15955192865369467629u, 242833611528216133u }, { 1696107848069843133u, 194266889222572907u },
+ { 12424932722681605476u, 155413511378058325u }, { 1433148282581017146u, 248661618204893321u },
+ { 15903913885032455010u, 198929294563914656u }, { 9033782293284053685u, 159143435651131725u },
+ { 14454051669254485895u, 254629497041810760u }, { 11563241335403588716u, 203703597633448608u },
+ { 16629290697806691620u, 162962878106758886u }, { 781423413297334329u, 260740604970814219u },
+ { 4314487545379777786u, 208592483976651375u }, { 3451590036303822229u, 166873987181321100u },
+ { 5522544058086115566u, 266998379490113760u }, { 4418035246468892453u, 213598703592091008u },
+ { 10913125826658934609u, 170878962873672806u }, { 10082303693170474728u, 273406340597876490u },
+ { 8065842954536379782u, 218725072478301192u }, { 17520720807854834795u, 174980057982640953u },
+ { 5897060404116273733u, 279968092772225526u }, { 1028299508551108663u, 223974474217780421u },
+ { 15580034865808528224u, 179179579374224336u }, { 17549358155809824511u, 286687326998758938u },
+ { 2971440080422128639u, 229349861599007151u }, { 17134547323305344204u, 183479889279205720u },
+ { 13707637858644275364u, 146783911423364576u }, { 14553522944347019935u, 234854258277383322u },
+ { 4264120725993795302u, 187883406621906658u }, { 10789994210278856888u, 150306725297525326u },
+ { 9885293106962350374u, 240490760476040522u }, { 529536856086059653u, 192392608380832418u },
+ { 7802327114352668369u, 153914086704665934u }, { 1415676938738538420u, 246262538727465495u },
+ { 1132541550990830736u, 197010030981972396u }, { 15663428499760305882u, 157608024785577916u },
+ { 17682787970132668764u, 252172839656924666u }, { 10456881561364224688u, 201738271725539733u },
+ { 15744202878575200397u, 161390617380431786u }, { 17812026976236499989u, 258224987808690858u },
+ { 3181575136763469022u, 206579990246952687u }, { 13613306553636506187u, 165263992197562149u },
+ { 10713244041592678929u, 264422387516099439u }, { 12259944048016053467u, 211537910012879551u },
+ { 6118606423670932450u, 169230328010303641u }, { 2411072648389671274u, 270768524816485826u },
+ { 16686253377679378312u, 216614819853188660u }, { 13349002702143502650u, 173291855882550928u },
+ { 17669055508687693916u, 277266969412081485u }, { 14135244406950155133u, 221813575529665188u },
+ { 240149081334393137u, 177450860423732151u }, { 11452284974360759988u, 283921376677971441u },
+ { 5472479164746697667u, 227137101342377153u }, { 11756680961281178780u, 181709681073901722u },
+ { 2026647139541122378u, 145367744859121378u }, { 18000030682233437097u, 232588391774594204u },
+ { 18089373360528660001u, 186070713419675363u }, { 3403452244197197031u, 148856570735740291u },
+ { 16513570034941246220u, 238170513177184465u }, { 13210856027952996976u, 190536410541747572u },
+ { 3189987192878576934u, 152429128433398058u }, { 1414630693863812771u, 243886605493436893u },
+ { 8510402184574870864u, 195109284394749514u }, { 10497670562401807014u, 156087427515799611u },
+ { 9417575270359070576u, 249739884025279378u }, { 14912757845771077107u, 199791907220223502u },
+ { 4551508647133041040u, 159833525776178802u }, { 10971762650154775986u, 255733641241886083u },
+ { 16156107749607641435u, 204586912993508866u }, { 9235537384944202825u, 163669530394807093u },
+ { 11087511001168814197u, 261871248631691349u }, { 12559357615676961681u, 209496998905353079u },
+ { 13736834907283479668u, 167597599124282463u }, { 18289587036911657145u, 268156158598851941u },
+ { 10942320814787415393u, 214524926879081553u }, { 16132554281313752961u, 171619941503265242u },
+ { 11054691591134363444u, 274591906405224388u }, { 16222450902391311402u, 219673525124179510u },
+ { 12977960721913049122u, 175738820099343608u }, { 17075388340318968271u, 281182112158949773u },
+ { 2592264228029443648u, 224945689727159819u }, { 5763160197165465241u, 179956551781727855u },
+ { 9221056315464744386u, 287930482850764568u }, { 14755542681855616155u, 230344386280611654u },
+ { 15493782960226403247u, 184275509024489323u }, { 1326979923955391628u, 147420407219591459u },
+ { 9501865507812447252u, 235872651551346334u }, { 11290841220991868125u, 188698121241077067u },
+ { 1653975347309673853u, 150958496992861654u }, { 10025058185179298811u, 241533595188578646u },
+ { 4330697733401528726u, 193226876150862917u }, { 14532604630946953951u, 154581500920690333u },
+ { 1116074521063664381u, 247330401473104534u }, { 4582208431592841828u, 197864321178483627u },
+ { 14733813189500004432u, 158291456942786901u }, { 16195403473716186445u, 253266331108459042u },
+ { 5577625149489128510u, 202613064886767234u }, { 8151448934333213131u, 162090451909413787u },
+ { 16731667109675051333u, 259344723055062059u }, { 17074682502481951390u, 207475778444049647u },
+ { 6281048372501740465u, 165980622755239718u }, { 6360328581260874421u, 265568996408383549u },
+ { 8777611679750609860u, 212455197126706839u }, { 10711438158542398211u, 169964157701365471u },
+ { 9759603424184016492u, 271942652322184754u }, { 11497031554089123517u, 217554121857747803u },
+ { 16576322872755119460u, 174043297486198242u }, { 11764721337440549842u, 278469275977917188u },
+ { 16790474699436260520u, 222775420782333750u }, { 13432379759549008416u, 178220336625867000u },
+ { 3045063541568861850u, 285152538601387201u }, { 17193446092222730773u, 228122030881109760u },
+ { 13754756873778184618u, 182497624704887808u }, { 18382503128506368341u, 145998099763910246u },
+ { 3586563302416817083u, 233596959622256395u }, { 2869250641933453667u, 186877567697805116u },
+ { 17052795772514404226u, 149502054158244092u }, { 12527077977055405469u, 239203286653190548u },
+ { 17400360011128145022u, 191362629322552438u }, { 2852241564676785048u, 153090103458041951u },
+ { 15631632947708587046u, 244944165532867121u }, { 8815957543424959314u, 195955332426293697u },
+ { 18120812478965698421u, 156764265941034957u }, { 14235904707377476180u, 250822825505655932u },
+ { 4010026136418160298u, 200658260404524746u }, { 17965416168102169531u, 160526608323619796u },
+ { 2919224165770098987u, 256842573317791675u }, { 2335379332616079190u, 205474058654233340u },
+ { 1868303466092863352u, 164379246923386672u }, { 6678634360490491686u, 263006795077418675u },
+ { 5342907488392393349u, 210405436061934940u }, { 4274325990713914679u, 168324348849547952u },
+ { 10528270399884173809u, 269318958159276723u }, { 15801313949391159694u, 215455166527421378u },
+ { 1573004715287196786u, 172364133221937103u }, { 17274202803427156150u, 275782613155099364u },
+ { 17508711057483635243u, 220626090524079491u }, { 10317620031244997871u, 176500872419263593u },
+ { 12818843235250086271u, 282401395870821749u }, { 13944423402941979340u, 225921116696657399u },
+ { 14844887537095493795u, 180736893357325919u }, { 15565258844418305359u, 144589514685860735u },
+ { 6457670077359736959u, 231343223497377177u }, { 16234182506113520537u, 185074578797901741u },
+ { 9297997190148906106u, 148059663038321393u }, { 11187446689496339446u, 236895460861314229u },
+ { 12639306166338981880u, 189516368689051383u }, { 17490142562555006151u, 151613094951241106u },
+ { 2158786396894637579u, 242580951921985771u }, { 16484424376483351356u, 194064761537588616u },
+ { 9498190686444770762u, 155251809230070893u }, { 11507756283569722895u, 248402894768113429u },
+ { 12895553841597688639u, 198722315814490743u }, { 17695140702761971558u, 158977852651592594u },
+ { 17244178680193423523u, 254364564242548151u }, { 10105994129412828495u, 203491651394038521u },
+ { 4395446488788352473u, 162793321115230817u }, { 10722063196803274280u, 260469313784369307u },
+ { 1198952927958798777u, 208375451027495446u }, { 15716557601334680315u, 166700360821996356u },
+ { 17767794532651667857u, 266720577315194170u }, { 14214235626121334286u, 213376461852155336u },
+ { 7682039686155157106u, 170701169481724269u }, { 1223217053622520399u, 273121871170758831u },
+ { 15735968901865657612u, 218497496936607064u }, { 16278123936234436413u, 174797997549285651u },
+ { 219556594781725998u, 279676796078857043u }, { 7554342905309201445u, 223741436863085634u },
+ { 9732823138989271479u, 178993149490468507u }, { 815121763415193074u, 286389039184749612u },
+ { 11720143854957885429u, 229111231347799689u }, { 13065463898708218666u, 183288985078239751u },
+ { 6763022304224664610u, 146631188062591801u }, { 3442138057275642729u, 234609900900146882u },
+ { 13821756890046245153u, 187687920720117505u }, { 11057405512036996122u, 150150336576094004u },
+ { 6623802375033462826u, 240240538521750407u }, { 16367088344252501231u, 192192430817400325u },
+ { 13093670675402000985u, 153753944653920260u }, { 2503129006933649959u, 246006311446272417u },
+ { 13070549649772650937u, 196805049157017933u }, { 17835137349301941396u, 157444039325614346u },
+ { 2710778055689733971u, 251910462920982955u }, { 2168622444551787177u, 201528370336786364u },
+ { 5424246770383340065u, 161222696269429091u }, { 1300097203129523457u, 257956314031086546u },
+ { 15797473021471260058u, 206365051224869236u }, { 8948629602435097724u, 165092040979895389u },
+ { 3249760919670425388u, 264147265567832623u }, { 9978506365220160957u, 211317812454266098u },
+ { 15361502721659949412u, 169054249963412878u }, { 2442311466204457120u, 270486799941460606u },
+ { 16711244431931206989u, 216389439953168484u }, { 17058344360286875914u, 173111551962534787u },
+ { 12535955717491360170u, 276978483140055660u }, { 10028764573993088136u, 221582786512044528u },
+ { 15401709288678291155u, 177266229209635622u }, { 9885339602917624555u, 283625966735416996u },
+ { 4218922867592189321u, 226900773388333597u }, { 14443184738299482427u, 181520618710666877u },
+ { 4175850161155765295u, 145216494968533502u }, { 10370709072591134795u, 232346391949653603u },
+ { 15675264887556728482u, 185877113559722882u }, { 5161514280561562140u, 148701690847778306u },
+ { 879725219414678777u, 237922705356445290u }, { 703780175531743021u, 190338164285156232u },
+ { 11631070584651125387u, 152270531428124985u }, { 162968861732249003u, 243632850284999977u },
+ { 11198421533611530172u, 194906280227999981u }, { 5269388412147313814u, 155925024182399985u },
+ { 8431021459435702103u, 249480038691839976u }, { 3055468352806651359u, 199584030953471981u },
+ { 17201769941212962380u, 159667224762777584u }, { 16454785461715008838u, 255467559620444135u },
+ { 13163828369372007071u, 204374047696355308u }, { 17909760324981426303u, 163499238157084246u },
+ { 2830174816776909822u, 261598781051334795u }, { 2264139853421527858u, 209279024841067836u },
+ { 16568707141704863579u, 167423219872854268u }, { 4373838538276319787u, 267877151796566830u },
+ { 3499070830621055830u, 214301721437253464u }, { 6488605479238754987u, 171441377149802771u },
+ { 3003071137298187333u, 274306203439684434u }, { 6091805724580460189u, 219444962751747547u },
+ { 15941491023890099121u, 175555970201398037u }, { 10748990379256517301u, 280889552322236860u },
+ { 8599192303405213841u, 224711641857789488u }, { 14258051472207991719u, 179769313486231590u }
+};
+
+inline constexpr uint64_t __DOUBLE_POW5_SPLIT[326][2] = {
+ { 0u, 72057594037927936u }, { 0u, 90071992547409920u },
+ { 0u, 112589990684262400u }, { 0u, 140737488355328000u },
+ { 0u, 87960930222080000u }, { 0u, 109951162777600000u },
+ { 0u, 137438953472000000u }, { 0u, 85899345920000000u },
+ { 0u, 107374182400000000u }, { 0u, 134217728000000000u },
+ { 0u, 83886080000000000u }, { 0u, 104857600000000000u },
+ { 0u, 131072000000000000u }, { 0u, 81920000000000000u },
+ { 0u, 102400000000000000u }, { 0u, 128000000000000000u },
+ { 0u, 80000000000000000u }, { 0u, 100000000000000000u },
+ { 0u, 125000000000000000u }, { 0u, 78125000000000000u },
+ { 0u, 97656250000000000u }, { 0u, 122070312500000000u },
+ { 0u, 76293945312500000u }, { 0u, 95367431640625000u },
+ { 0u, 119209289550781250u }, { 4611686018427387904u, 74505805969238281u },
+ { 10376293541461622784u, 93132257461547851u }, { 8358680908399640576u, 116415321826934814u },
+ { 612489549322387456u, 72759576141834259u }, { 14600669991935148032u, 90949470177292823u },
+ { 13639151471491547136u, 113686837721616029u }, { 3213881284082270208u, 142108547152020037u },
+ { 4314518811765112832u, 88817841970012523u }, { 781462496279003136u, 111022302462515654u },
+ { 10200200157203529728u, 138777878078144567u }, { 13292654125893287936u, 86736173798840354u },
+ { 7392445620511834112u, 108420217248550443u }, { 4628871007212404736u, 135525271560688054u },
+ { 16728102434789916672u, 84703294725430033u }, { 7075069988205232128u, 105879118406787542u },
+ { 18067209522111315968u, 132348898008484427u }, { 8986162942105878528u, 82718061255302767u },
+ { 6621017659204960256u, 103397576569128459u }, { 3664586055578812416u, 129246970711410574u },
+ { 16125424340018921472u, 80779356694631608u }, { 1710036351314100224u, 100974195868289511u },
+ { 15972603494424788992u, 126217744835361888u }, { 9982877184015493120u, 78886090522101180u },
+ { 12478596480019366400u, 98607613152626475u }, { 10986559581596820096u, 123259516440783094u },
+ { 2254913720070624656u, 77037197775489434u }, { 12042014186943056628u, 96296497219361792u },
+ { 15052517733678820785u, 120370621524202240u }, { 9407823583549262990u, 75231638452626400u },
+ { 11759779479436578738u, 94039548065783000u }, { 14699724349295723422u, 117549435082228750u },
+ { 4575641699882439235u, 73468396926392969u }, { 10331238143280436948u, 91835496157991211u },
+ { 8302361660673158281u, 114794370197489014u }, { 1154580038986672043u, 143492962746861268u },
+ { 9944984561221445835u, 89683101716788292u }, { 12431230701526807293u, 112103877145985365u },
+ { 1703980321626345405u, 140129846432481707u }, { 17205888765512323542u, 87581154020301066u },
+ { 12283988920035628619u, 109476442525376333u }, { 1519928094762372062u, 136845553156720417u },
+ { 12479170105294952299u, 85528470722950260u }, { 15598962631618690374u, 106910588403687825u },
+ { 5663645234241199255u, 133638235504609782u }, { 17374836326682913246u, 83523897190381113u },
+ { 7883487353071477846u, 104404871487976392u }, { 9854359191339347308u, 130506089359970490u },
+ { 10770660513014479971u, 81566305849981556u }, { 13463325641268099964u, 101957882312476945u },
+ { 2994098996302961243u, 127447352890596182u }, { 15706369927971514489u, 79654595556622613u },
+ { 5797904354682229399u, 99568244445778267u }, { 2635694424925398845u, 124460305557222834u },
+ { 6258995034005762182u, 77787690973264271u }, { 3212057774079814824u, 97234613716580339u },
+ { 17850130272881932242u, 121543267145725423u }, { 18073860448192289507u, 75964541966078389u },
+ { 8757267504958198172u, 94955677457597987u }, { 6334898362770359811u, 118694596821997484u },
+ { 13182683513586250689u, 74184123013748427u }, { 11866668373555425458u, 92730153767185534u },
+ { 5609963430089506015u, 115912692208981918u }, { 17341285199088104971u, 72445432630613698u },
+ { 12453234462005355406u, 90556790788267123u }, { 10954857059079306353u, 113195988485333904u },
+ { 13693571323849132942u, 141494985606667380u }, { 17781854114260483896u, 88434366004167112u },
+ { 3780573569116053255u, 110542957505208891u }, { 114030942967678664u, 138178696881511114u },
+ { 4682955357782187069u, 86361685550944446u }, { 15077066234082509644u, 107952106938680557u },
+ { 5011274737320973344u, 134940133673350697u }, { 14661261756894078100u, 84337583545844185u },
+ { 4491519140835433913u, 105421979432305232u }, { 5614398926044292391u, 131777474290381540u },
+ { 12732371365632458552u, 82360921431488462u }, { 6692092170185797382u, 102951151789360578u },
+ { 17588487249587022536u, 128688939736700722u }, { 15604490549419276989u, 80430587335437951u },
+ { 14893927168346708332u, 100538234169297439u }, { 14005722942005997511u, 125672792711621799u },
+ { 15671105866394830300u, 78545495444763624u }, { 1142138259283986260u, 98181869305954531u },
+ { 15262730879387146537u, 122727336632443163u }, { 7233363790403272633u, 76704585395276977u },
+ { 13653390756431478696u, 95880731744096221u }, { 3231680390257184658u, 119850914680120277u },
+ { 4325643253124434363u, 74906821675075173u }, { 10018740084832930858u, 93633527093843966u },
+ { 3300053069186387764u, 117041908867304958u }, { 15897591223523656064u, 73151193042065598u },
+ { 10648616992549794273u, 91438991302581998u }, { 4087399203832467033u, 114298739128227498u },
+ { 14332621041645359599u, 142873423910284372u }, { 18181260187883125557u, 89295889943927732u },
+ { 4279831161144355331u, 111619862429909666u }, { 14573160988285219972u, 139524828037387082u },
+ { 13719911636105650386u, 87203017523366926u }, { 7926517508277287175u, 109003771904208658u },
+ { 684774848491833161u, 136254714880260823u }, { 7345513307948477581u, 85159196800163014u },
+ { 18405263671790372785u, 106448996000203767u }, { 18394893571310578077u, 133061245000254709u },
+ { 13802651491282805250u, 83163278125159193u }, { 3418256308821342851u, 103954097656448992u },
+ { 4272820386026678563u, 129942622070561240u }, { 2670512741266674102u, 81214138794100775u },
+ { 17173198981865506339u, 101517673492625968u }, { 3019754653622331308u, 126897091865782461u },
+ { 4193189667727651020u, 79310682416114038u }, { 14464859121514339583u, 99138353020142547u },
+ { 13469387883465536574u, 123922941275178184u }, { 8418367427165960359u, 77451838296986365u },
+ { 15134645302384838353u, 96814797871232956u }, { 471562554271496325u, 121018497339041196u },
+ { 9518098633274461011u, 75636560836900747u }, { 7285937273165688360u, 94545701046125934u },
+ { 18330793628311886258u, 118182126307657417u }, { 4539216990053847055u, 73863828942285886u },
+ { 14897393274422084627u, 92329786177857357u }, { 4786683537745442072u, 115412232722321697u },
+ { 14520892257159371055u, 72132645451451060u }, { 18151115321449213818u, 90165806814313825u },
+ { 8853836096529353561u, 112707258517892282u }, { 1843923083806916143u, 140884073147365353u },
+ { 12681666973447792349u, 88052545717103345u }, { 2017025661527576725u, 110065682146379182u },
+ { 11744654113764246714u, 137582102682973977u }, { 422879793461572340u, 85988814176858736u },
+ { 528599741826965425u, 107486017721073420u }, { 660749677283706782u, 134357522151341775u },
+ { 7330497575943398595u, 83973451344588609u }, { 13774807988356636147u, 104966814180735761u },
+ { 3383451930163631472u, 131208517725919702u }, { 15949715511634433382u, 82005323578699813u },
+ { 6102086334260878016u, 102506654473374767u }, { 3015921899398709616u, 128133318091718459u },
+ { 18025852251620051174u, 80083323807324036u }, { 4085571240815512351u, 100104154759155046u },
+ { 14330336087874166247u, 125130193448943807u }, { 15873989082562435760u, 78206370905589879u },
+ { 15230800334775656796u, 97757963631987349u }, { 5203442363187407284u, 122197454539984187u },
+ { 946308467778435600u, 76373409087490117u }, { 5794571603150432404u, 95466761359362646u },
+ { 16466586540792816313u, 119333451699203307u }, { 7985773578781816244u, 74583407312002067u },
+ { 5370530955049882401u, 93229259140002584u }, { 6713163693812353001u, 116536573925003230u },
+ { 18030785363914884337u, 72835358703127018u }, { 13315109668038829614u, 91044198378908773u },
+ { 2808829029766373305u, 113805247973635967u }, { 17346094342490130344u, 142256559967044958u },
+ { 6229622945628943561u, 88910349979403099u }, { 3175342663608791547u, 111137937474253874u },
+ { 13192550366365765242u, 138922421842817342u }, { 3633657960551215372u, 86826513651760839u },
+ { 18377130505971182927u, 108533142064701048u }, { 4524669058754427043u, 135666427580876311u },
+ { 9745447189362598758u, 84791517238047694u }, { 2958436949848472639u, 105989396547559618u },
+ { 12921418224165366607u, 132486745684449522u }, { 12687572408530742033u, 82804216052780951u },
+ { 11247779492236039638u, 103505270065976189u }, { 224666310012885835u, 129381587582470237u },
+ { 2446259452971747599u, 80863492239043898u }, { 12281196353069460307u, 101079365298804872u },
+ { 15351495441336825384u, 126349206623506090u }, { 14206370669262903769u, 78968254139691306u },
+ { 8534591299723853903u, 98710317674614133u }, { 15279925143082205283u, 123387897093267666u },
+ { 14161639232853766206u, 77117435683292291u }, { 13090363022639819853u, 96396794604115364u },
+ { 16362953778299774816u, 120495993255144205u }, { 12532689120651053212u, 75309995784465128u },
+ { 15665861400813816515u, 94137494730581410u }, { 10358954714162494836u, 117671868413226763u },
+ { 4168503687137865320u, 73544917758266727u }, { 598943590494943747u, 91931147197833409u },
+ { 5360365506546067587u, 114913933997291761u }, { 11312142901609972388u, 143642417496614701u },
+ { 9375932322719926695u, 89776510935384188u }, { 11719915403399908368u, 112220638669230235u },
+ { 10038208235822497557u, 140275798336537794u }, { 10885566165816448877u, 87672373960336121u },
+ { 18218643725697949000u, 109590467450420151u }, { 18161618638695048346u, 136988084313025189u },
+ { 13656854658398099168u, 85617552695640743u }, { 12459382304570236056u, 107021940869550929u },
+ { 1739169825430631358u, 133777426086938662u }, { 14922039196176308311u, 83610891304336663u },
+ { 14040862976792997485u, 104513614130420829u }, { 3716020665709083144u, 130642017663026037u },
+ { 4628355925281870917u, 81651261039391273u }, { 10397130925029726550u, 102064076299239091u },
+ { 8384727637859770284u, 127580095374048864u }, { 5240454773662356427u, 79737559608780540u },
+ { 6550568467077945534u, 99671949510975675u }, { 3576524565420044014u, 124589936888719594u },
+ { 6847013871814915412u, 77868710555449746u }, { 17782139376623420074u, 97335888194312182u },
+ { 13004302183924499284u, 121669860242890228u }, { 17351060901807587860u, 76043662651806392u },
+ { 3242082053549933210u, 95054578314757991u }, { 17887660622219580224u, 118818222893447488u },
+ { 11179787888887237640u, 74261389308404680u }, { 13974734861109047050u, 92826736635505850u },
+ { 8245046539531533005u, 116033420794382313u }, { 16682369133275677888u, 72520887996488945u },
+ { 7017903361312433648u, 90651109995611182u }, { 17995751238495317868u, 113313887494513977u },
+ { 8659630992836983623u, 141642359368142472u }, { 5412269370523114764u, 88526474605089045u },
+ { 11377022731581281359u, 110658093256361306u }, { 4997906377621825891u, 138322616570451633u },
+ { 14652906532082110942u, 86451635356532270u }, { 9092761128247862869u, 108064544195665338u },
+ { 2142579373455052779u, 135080680244581673u }, { 12868327154477877747u, 84425425152863545u },
+ { 2250350887815183471u, 105531781441079432u }, { 2812938609768979339u, 131914726801349290u },
+ { 6369772649532999991u, 82446704250843306u }, { 17185587848771025797u, 103058380313554132u },
+ { 3035240737254230630u, 128822975391942666u }, { 6508711479211282048u, 80514359619964166u },
+ { 17359261385868878368u, 100642949524955207u }, { 17087390713908710056u, 125803686906194009u },
+ { 3762090168551861929u, 78627304316371256u }, { 4702612710689827411u, 98284130395464070u },
+ { 15101637925217060072u, 122855162994330087u }, { 16356052730901744401u, 76784476871456304u },
+ { 1998321839917628885u, 95980596089320381u }, { 7109588318324424010u, 119975745111650476u },
+ { 13666864735807540814u, 74984840694781547u }, { 12471894901332038114u, 93731050868476934u },
+ { 6366496589810271835u, 117163813585596168u }, { 3979060368631419896u, 73227383490997605u },
+ { 9585511479216662775u, 91534229363747006u }, { 2758517312166052660u, 114417786704683758u },
+ { 12671518677062341634u, 143022233380854697u }, { 1002170145522881665u, 89388895863034186u },
+ { 10476084718758377889u, 111736119828792732u }, { 13095105898447972362u, 139670149785990915u },
+ { 5878598177316288774u, 87293843616244322u }, { 16571619758500136775u, 109117304520305402u },
+ { 11491152661270395161u, 136396630650381753u }, { 264441385652915120u, 85247894156488596u },
+ { 330551732066143900u, 106559867695610745u }, { 5024875683510067779u, 133199834619513431u },
+ { 10058076329834874218u, 83249896637195894u }, { 3349223375438816964u, 104062370796494868u },
+ { 4186529219298521205u, 130077963495618585u }, { 14145795808130045513u, 81298727184761615u },
+ { 13070558741735168987u, 101623408980952019u }, { 11726512408741573330u, 127029261226190024u },
+ { 7329070255463483331u, 79393288266368765u }, { 13773023837756742068u, 99241610332960956u },
+ { 17216279797195927585u, 124052012916201195u }, { 8454331864033760789u, 77532508072625747u },
+ { 5956228811614813082u, 96915635090782184u }, { 7445286014518516353u, 121144543863477730u },
+ { 9264989777501460624u, 75715339914673581u }, { 16192923240304213684u, 94644174893341976u },
+ { 1794409976670715490u, 118305218616677471u }, { 8039035263060279037u, 73940761635423419u },
+ { 5437108060397960892u, 92425952044279274u }, { 16019757112352226923u, 115532440055349092u },
+ { 788976158365366019u, 72207775034593183u }, { 14821278253238871236u, 90259718793241478u },
+ { 9303225779693813237u, 112824648491551848u }, { 11629032224617266546u, 141030810614439810u },
+ { 11879831158813179495u, 88144256634024881u }, { 1014730893234310657u, 110180320792531102u },
+ { 10491785653397664129u, 137725400990663877u }, { 8863209042587234033u, 86078375619164923u },
+ { 6467325284806654637u, 107597969523956154u }, { 17307528642863094104u, 134497461904945192u },
+ { 10817205401789433815u, 84060913690590745u }, { 18133192770664180173u, 105076142113238431u },
+ { 18054804944902837312u, 131345177641548039u }, { 18201782118205355176u, 82090736025967524u },
+ { 4305483574047142354u, 102613420032459406u }, { 14605226504413703751u, 128266775040574257u },
+ { 2210737537617482988u, 80166734400358911u }, { 16598479977304017447u, 100208418000448638u },
+ { 11524727934775246001u, 125260522500560798u }, { 2591268940807140847u, 78287826562850499u },
+ { 17074144231291089770u, 97859783203563123u }, { 16730994270686474309u, 122324729004453904u },
+ { 10456871419179046443u, 76452955627783690u }, { 3847717237119032246u, 95566194534729613u },
+ { 9421332564826178211u, 119457743168412016u }, { 5888332853016361382u, 74661089480257510u },
+ { 16583788103125227536u, 93326361850321887u }, { 16118049110479146516u, 116657952312902359u },
+ { 16991309721690548428u, 72911220195563974u }, { 12015765115258409727u, 91139025244454968u },
+ { 15019706394073012159u, 113923781555568710u }, { 9551260955736489391u, 142404726944460888u },
+ { 5969538097335305869u, 89002954340288055u }, { 2850236603241744433u, 111253692925360069u }
+};
+
+_LIBCPP_END_NAMESPACE_STD
+
+// clang-format on
+
+#endif // _LIBCPP_SRC_INCLUDE_RYU_D2S_FULL_TABLE_H
diff --git a/contrib/llvm-project/libcxx/src/include/ryu/d2s_intrinsics.h b/contrib/llvm-project/libcxx/src/include/ryu/d2s_intrinsics.h
new file mode 100644
index 000000000000..be50361fb3b3
--- /dev/null
+++ b/contrib/llvm-project/libcxx/src/include/ryu/d2s_intrinsics.h
@@ -0,0 +1,260 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// Copyright (c) Microsoft Corporation.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+// Copyright 2018 Ulf Adams
+// Copyright (c) Microsoft Corporation. All rights reserved.
+
+// Boost Software License - Version 1.0 - August 17th, 2003
+
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+
+#ifndef _LIBCPP_SRC_INCLUDE_RYU_DS2_INTRINSICS_H
+#define _LIBCPP_SRC_INCLUDE_RYU_DS2_INTRINSICS_H
+
+// Avoid formatting to keep the changes with the original code minimal.
+// clang-format off
+
+#include <__assert>
+#include <__config>
+
+#include "include/ryu/ryu.h"
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if defined(_M_X64) && defined(_MSC_VER)
+#define _LIBCPP_INTRINSIC128 1
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __ryu_umul128(const uint64_t __a, const uint64_t __b, uint64_t* const __productHi) {
+ return _umul128(__a, __b, __productHi);
+}
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __ryu_shiftright128(const uint64_t __lo, const uint64_t __hi, const uint32_t __dist) {
+ // For the __shiftright128 intrinsic, the shift value is always
+ // modulo 64.
+ // In the current implementation of the double-precision version
+ // of Ryu, the shift value is always < 64.
+ // (The shift value is in the range [49, 58].)
+ // Check this here in case a future change requires larger shift
+ // values. In this case this function needs to be adjusted.
+ _LIBCPP_ASSERT_INTERNAL(__dist < 64, "");
+ return __shiftright128(__lo, __hi, static_cast<unsigned char>(__dist));
+}
+
+// ^^^ intrinsics available ^^^ / vvv __int128 available vvv
+#elif defined(__SIZEOF_INT128__) && ( \
+ (defined(__clang__) && !defined(_MSC_VER)) || \
+ (defined(__GNUC__) && !defined(__clang__) && !defined(__CUDACC__)))
+#define _LIBCPP_INTRINSIC128 1
+ // We have __uint128 support in clang or gcc
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __ryu_umul128(const uint64_t __a, const uint64_t __b, uint64_t* const __productHi) {
+ auto __temp = __a * (unsigned __int128)__b;
+ *__productHi = __temp >> 64;
+ return static_cast<uint64_t>(__temp);
+}
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __ryu_shiftright128(const uint64_t __lo, const uint64_t __hi, const uint32_t __dist) {
+ // In the current implementation of the double-precision version
+ // of Ryu, the shift value is always < 64.
+ // (The shift value is in the range [49, 58].)
+ // Check this here in case a future change requires larger shift
+ // values. In this case this function needs to be adjusted.
+ _LIBCPP_ASSERT_INTERNAL(__dist < 64, "");
+ auto __temp = __lo | ((unsigned __int128)__hi << 64);
+ // For x64 128-bit shfits using the `shrd` instruction and two 64-bit
+ // registers, the shift value is modulo 64. Thus the `& 63` is free.
+ return static_cast<uint64_t>(__temp >> (__dist & 63));
+}
+#else // ^^^ __int128 available ^^^ / vvv intrinsics unavailable vvv
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline _LIBCPP_ALWAYS_INLINE uint64_t __ryu_umul128(const uint64_t __a, const uint64_t __b, uint64_t* const __productHi) {
+ // TRANSITION, VSO-634761
+ // The casts here help MSVC to avoid calls to the __allmul library function.
+ const uint32_t __aLo = static_cast<uint32_t>(__a);
+ const uint32_t __aHi = static_cast<uint32_t>(__a >> 32);
+ const uint32_t __bLo = static_cast<uint32_t>(__b);
+ const uint32_t __bHi = static_cast<uint32_t>(__b >> 32);
+
+ const uint64_t __b00 = static_cast<uint64_t>(__aLo) * __bLo;
+ const uint64_t __b01 = static_cast<uint64_t>(__aLo) * __bHi;
+ const uint64_t __b10 = static_cast<uint64_t>(__aHi) * __bLo;
+ const uint64_t __b11 = static_cast<uint64_t>(__aHi) * __bHi;
+
+ const uint32_t __b00Lo = static_cast<uint32_t>(__b00);
+ const uint32_t __b00Hi = static_cast<uint32_t>(__b00 >> 32);
+
+ const uint64_t __mid1 = __b10 + __b00Hi;
+ const uint32_t __mid1Lo = static_cast<uint32_t>(__mid1);
+ const uint32_t __mid1Hi = static_cast<uint32_t>(__mid1 >> 32);
+
+ const uint64_t __mid2 = __b01 + __mid1Lo;
+ const uint32_t __mid2Lo = static_cast<uint32_t>(__mid2);
+ const uint32_t __mid2Hi = static_cast<uint32_t>(__mid2 >> 32);
+
+ const uint64_t __pHi = __b11 + __mid1Hi + __mid2Hi;
+ const uint64_t __pLo = (static_cast<uint64_t>(__mid2Lo) << 32) | __b00Lo;
+
+ *__productHi = __pHi;
+ return __pLo;
+}
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __ryu_shiftright128(const uint64_t __lo, const uint64_t __hi, const uint32_t __dist) {
+ // We don't need to handle the case __dist >= 64 here (see above).
+ _LIBCPP_ASSERT_INTERNAL(__dist < 64, "");
+#ifdef _LIBCPP_64_BIT
+ _LIBCPP_ASSERT_INTERNAL(__dist > 0, "");
+ return (__hi << (64 - __dist)) | (__lo >> __dist);
+#else // ^^^ 64-bit ^^^ / vvv 32-bit vvv
+ // Avoid a 64-bit shift by taking advantage of the range of shift values.
+ _LIBCPP_ASSERT_INTERNAL(__dist >= 32, "");
+ return (__hi << (64 - __dist)) | (static_cast<uint32_t>(__lo >> 32) >> (__dist - 32));
+#endif // ^^^ 32-bit ^^^
+}
+
+#endif // ^^^ intrinsics unavailable ^^^
+
+#ifndef _LIBCPP_64_BIT
+
+// Returns the high 64 bits of the 128-bit product of __a and __b.
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __umulh(const uint64_t __a, const uint64_t __b) {
+ // Reuse the __ryu_umul128 implementation.
+ // Optimizers will likely eliminate the instructions used to compute the
+ // low part of the product.
+ uint64_t __hi;
+ (void) __ryu_umul128(__a, __b, &__hi);
+ return __hi;
+}
+
+// On 32-bit platforms, compilers typically generate calls to library
+// functions for 64-bit divisions, even if the divisor is a constant.
+//
+// TRANSITION, LLVM-37932
+//
+// The functions here perform division-by-constant using multiplications
+// in the same way as 64-bit compilers would do.
+//
+// NB:
+// The multipliers and shift values are the ones generated by clang x64
+// for expressions like x/5, x/10, etc.
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __div5(const uint64_t __x) {
+ return __umulh(__x, 0xCCCCCCCCCCCCCCCDu) >> 2;
+}
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __div10(const uint64_t __x) {
+ return __umulh(__x, 0xCCCCCCCCCCCCCCCDu) >> 3;
+}
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __div100(const uint64_t __x) {
+ return __umulh(__x >> 2, 0x28F5C28F5C28F5C3u) >> 2;
+}
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __div1e8(const uint64_t __x) {
+ return __umulh(__x, 0xABCC77118461CEFDu) >> 26;
+}
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __div1e9(const uint64_t __x) {
+ return __umulh(__x >> 9, 0x44B82FA09B5A53u) >> 11;
+}
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint32_t __mod1e9(const uint64_t __x) {
+ // Avoid 64-bit math as much as possible.
+ // Returning static_cast<uint32_t>(__x - 1000000000 * __div1e9(__x)) would
+ // perform 32x64-bit multiplication and 64-bit subtraction.
+ // __x and 1000000000 * __div1e9(__x) are guaranteed to differ by
+ // less than 10^9, so their highest 32 bits must be identical,
+ // so we can truncate both sides to uint32_t before subtracting.
+ // We can also simplify static_cast<uint32_t>(1000000000 * __div1e9(__x)).
+ // We can truncate before multiplying instead of after, as multiplying
+ // the highest 32 bits of __div1e9(__x) can't affect the lowest 32 bits.
+ return static_cast<uint32_t>(__x) - 1000000000 * static_cast<uint32_t>(__div1e9(__x));
+}
+
+#else // ^^^ 32-bit ^^^ / vvv 64-bit vvv
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __div5(const uint64_t __x) {
+ return __x / 5;
+}
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __div10(const uint64_t __x) {
+ return __x / 10;
+}
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __div100(const uint64_t __x) {
+ return __x / 100;
+}
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __div1e8(const uint64_t __x) {
+ return __x / 100000000;
+}
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __div1e9(const uint64_t __x) {
+ return __x / 1000000000;
+}
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint32_t __mod1e9(const uint64_t __x) {
+ return static_cast<uint32_t>(__x - 1000000000 * __div1e9(__x));
+}
+
+#endif // ^^^ 64-bit ^^^
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint32_t __pow5Factor(uint64_t __value) {
+ uint32_t __count = 0;
+ for (;;) {
+ _LIBCPP_ASSERT_INTERNAL(__value != 0, "");
+ const uint64_t __q = __div5(__value);
+ const uint32_t __r = static_cast<uint32_t>(__value) - 5 * static_cast<uint32_t>(__q);
+ if (__r != 0) {
+ break;
+ }
+ __value = __q;
+ ++__count;
+ }
+ return __count;
+}
+
+// Returns true if __value is divisible by 5^__p.
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline bool __multipleOfPowerOf5(const uint64_t __value, const uint32_t __p) {
+ // I tried a case distinction on __p, but there was no performance difference.
+ return __pow5Factor(__value) >= __p;
+}
+
+// Returns true if __value is divisible by 2^__p.
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline bool __multipleOfPowerOf2(const uint64_t __value, const uint32_t __p) {
+ _LIBCPP_ASSERT_INTERNAL(__value != 0, "");
+ _LIBCPP_ASSERT_INTERNAL(__p < 64, "");
+ // __builtin_ctzll doesn't appear to be faster here.
+ return (__value & ((1ull << __p) - 1)) == 0;
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+// clang-format on
+
+#endif // _LIBCPP_SRC_INCLUDE_RYU_DS2_INTRINSICS_H
diff --git a/contrib/llvm-project/libcxx/src/include/ryu/digit_table.h b/contrib/llvm-project/libcxx/src/include/ryu/digit_table.h
new file mode 100644
index 000000000000..bf660b0be785
--- /dev/null
+++ b/contrib/llvm-project/libcxx/src/include/ryu/digit_table.h
@@ -0,0 +1,57 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// Copyright (c) Microsoft Corporation.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+// Copyright 2018 Ulf Adams
+// Copyright (c) Microsoft Corporation. All rights reserved.
+
+// Boost Software License - Version 1.0 - August 17th, 2003
+
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+
+#ifndef _LIBCPP_SRC_INCLUDE_RYU_DIGIT_TABLE_H
+#define _LIBCPP_SRC_INCLUDE_RYU_DIGIT_TABLE_H
+
+#include <__charconv/tables.h>
+#include <__config>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+// A table of all two-digit numbers. This is used to speed up decimal digit
+// generation by copying pairs of digits into the final output.
+//
+// In order to minimize the diff in the Ryu code between MSVC STL and libc++
+// the code uses the name __DIGIT_TABLE. In order to avoid code duplication it
+// reuses the table already available in libc++.
+inline constexpr auto& __DIGIT_TABLE = __itoa::__digits_base_10;
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP_SRC_INCLUDE_RYU_DIGIT_TABLE_H
diff --git a/contrib/llvm-project/libcxx/src/include/ryu/f2s.h b/contrib/llvm-project/libcxx/src/include/ryu/f2s.h
new file mode 100644
index 000000000000..be304c2f9c63
--- /dev/null
+++ b/contrib/llvm-project/libcxx/src/include/ryu/f2s.h
@@ -0,0 +1,55 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// Copyright (c) Microsoft Corporation.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+// Copyright 2018 Ulf Adams
+// Copyright (c) Microsoft Corporation. All rights reserved.
+
+// Boost Software License - Version 1.0 - August 17th, 2003
+
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+
+#ifndef _LIBCPP_SRC_INCLUDE_RYU_FS2_H
+#define _LIBCPP_SRC_INCLUDE_RYU_FS2_H
+
+// Avoid formatting to keep the changes with the original code minimal.
+// clang-format off
+
+#include <__config>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+[[nodiscard]] to_chars_result __f2s_buffered_n(char* const _First, char* const _Last, const float __f, const chars_format _Fmt);
+
+_LIBCPP_END_NAMESPACE_STD
+
+// clang-format on
+
+#endif // _LIBCPP_SRC_INCLUDE_RYU_FS2_H
diff --git a/contrib/llvm-project/libcxx/src/include/ryu/ryu.h b/contrib/llvm-project/libcxx/src/include/ryu/ryu.h
new file mode 100644
index 000000000000..7b19ecfec591
--- /dev/null
+++ b/contrib/llvm-project/libcxx/src/include/ryu/ryu.h
@@ -0,0 +1,147 @@
+// -*- 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
+//
+//===----------------------------------------------------------------------===//
+
+// Copyright (c) Microsoft Corporation.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+// Copyright 2018 Ulf Adams
+// Copyright (c) Microsoft Corporation. All rights reserved.
+
+// Boost Software License - Version 1.0 - August 17th, 2003
+
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+
+#ifndef _LIBCPP_SRC_INCLUDE_RYU_RYU_H
+#define _LIBCPP_SRC_INCLUDE_RYU_RYU_H
+
+// Avoid formatting to keep the changes with the original code minimal.
+// clang-format off
+
+#include <__charconv/chars_format.h>
+#include <__charconv/to_chars_result.h>
+#include <__config>
+#include <__system_error/errc.h>
+#include <cstdint>
+#include <cstring>
+#include <type_traits>
+
+#include "include/ryu/f2s.h"
+#include "include/ryu/d2s.h"
+#include "include/ryu/d2fixed.h"
+
+#if defined(_MSC_VER)
+#include <intrin.h> // for _umul128(), __shiftright128(), _BitScanForward{,64}
+#endif // defined(_MSC_VER)
+
+#if defined(_WIN64) || defined(_M_AMD64) || defined(__x86_64__) || defined(__aarch64__)
+#define _LIBCPP_64_BIT
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+// https://github.com/ulfjack/ryu/tree/59661c3/ryu
+
+#if !defined(_MSC_VER)
+_LIBCPP_HIDE_FROM_ABI inline unsigned char _BitScanForward64(unsigned long* __index, unsigned long long __mask) {
+ if (__mask == 0) {
+ return false;
+ }
+ *__index = __builtin_ctzll(__mask);
+ return true;
+}
+
+_LIBCPP_HIDE_FROM_ABI inline unsigned char _BitScanForward(unsigned long* __index, unsigned int __mask) {
+ if (__mask == 0) {
+ return false;
+ }
+ *__index = __builtin_ctz(__mask);
+ return true;
+}
+#endif // !_MSC_VER
+
+template <class _Floating>
+[[nodiscard]] to_chars_result _Floating_to_chars_ryu(
+ char* const _First, char* const _Last, const _Floating _Value, const chars_format _Fmt) noexcept {
+ if constexpr (_IsSame<_Floating, float>::value) {
+ return __f2s_buffered_n(_First, _Last, _Value, _Fmt);
+ } else {
+ return __d2s_buffered_n(_First, _Last, _Value, _Fmt);
+ }
+}
+
+template <class _Floating>
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI to_chars_result _Floating_to_chars_scientific_precision(
+ char* const _First, char* const _Last, const _Floating _Value, int _Precision) noexcept {
+
+ // C11 7.21.6.1 "The fprintf function"/5:
+ // "A negative precision argument is taken as if the precision were omitted."
+ // /8: "e,E [...] if the precision is missing, it is taken as 6"
+
+ if (_Precision < 0) {
+ _Precision = 6;
+ } else if (_Precision < 1'000'000'000) { // Match ' to fix compilation with GCC in C++11 mode
+ // _Precision is ok.
+ } else {
+ // Avoid integer overflow.
+ // (This defensive check is slightly nonconformant; it can be carefully improved in the future.)
+ return {_Last, errc::value_too_large};
+ }
+
+ return __d2exp_buffered_n(_First, _Last, _Value, static_cast<uint32_t>(_Precision));
+}
+
+template <class _Floating>
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI to_chars_result _Floating_to_chars_fixed_precision(
+ char* const _First, char* const _Last, const _Floating _Value, int _Precision) noexcept {
+
+ // C11 7.21.6.1 "The fprintf function"/5:
+ // "A negative precision argument is taken as if the precision were omitted."
+ // /8: "f,F [...] If the precision is missing, it is taken as 6"
+
+ if (_Precision < 0) {
+ _Precision = 6;
+ } else if (_Precision < 1'000'000'000) { // Match ' to fix compilation with GCC in C++11 mode
+ // _Precision is ok.
+ } else {
+ // Avoid integer overflow.
+ // (This defensive check is slightly nonconformant; it can be carefully improved in the future.)
+ return {_Last, errc::value_too_large};
+ }
+
+ return __d2fixed_buffered_n(_First, _Last, _Value, static_cast<uint32_t>(_Precision));
+}
+
+#undef _LIBCPP_64_BIT
+#undef _LIBCPP_INTRINSIC128
+
+_LIBCPP_END_NAMESPACE_STD
+
+// clang-format on
+
+#endif // _LIBCPP_SRC_INCLUDE_RYU_RYU_H
diff --git a/contrib/llvm-project/libcxx/src/include/sso_allocator.h b/contrib/llvm-project/libcxx/src/include/sso_allocator.h
new file mode 100644
index 000000000000..4e6761c580b5
--- /dev/null
+++ b/contrib/llvm-project/libcxx/src/include/sso_allocator.h
@@ -0,0 +1,80 @@
+// -*- 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_SSO_ALLOCATOR_H
+#define _LIBCPP_SSO_ALLOCATOR_H
+
+#include <__config>
+#include <cstddef>
+#include <memory>
+#include <new>
+#include <type_traits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+# pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class _Tp, size_t _Np>
+class _LIBCPP_HIDDEN __sso_allocator;
+
+template <size_t _Np>
+class _LIBCPP_HIDDEN __sso_allocator<void, _Np> {
+public:
+ typedef const void* const_pointer;
+ typedef void value_type;
+};
+
+template <class _Tp, size_t _Np>
+class _LIBCPP_HIDDEN __sso_allocator {
+ alignas(_Tp) std::byte buf_[sizeof(_Tp) * _Np];
+ bool __allocated_;
+
+public:
+ typedef size_t size_type;
+ typedef _Tp* pointer;
+ typedef _Tp value_type;
+
+ template <class U>
+ struct rebind {
+ using other = __sso_allocator<U, _Np>;
+ };
+
+ _LIBCPP_HIDE_FROM_ABI __sso_allocator() throw() : __allocated_(false) {}
+ _LIBCPP_HIDE_FROM_ABI __sso_allocator(const __sso_allocator&) throw() : __allocated_(false) {}
+ template <class _Up>
+ _LIBCPP_HIDE_FROM_ABI __sso_allocator(const __sso_allocator<_Up, _Np>&) throw() : __allocated_(false) {}
+
+private:
+ __sso_allocator& operator=(const __sso_allocator&);
+
+public:
+ _LIBCPP_HIDE_FROM_ABI pointer allocate(size_type __n, typename __sso_allocator<void, _Np>::const_pointer = nullptr) {
+ if (!__allocated_ && __n <= _Np) {
+ __allocated_ = true;
+ return (pointer)&buf_;
+ }
+ return allocator<_Tp>().allocate(__n);
+ }
+ _LIBCPP_HIDE_FROM_ABI void deallocate(pointer __p, size_type __n) {
+ if (__p == (pointer)&buf_)
+ __allocated_ = false;
+ else
+ allocator<_Tp>().deallocate(__p, __n);
+ }
+ _LIBCPP_HIDE_FROM_ABI size_type max_size() const throw() { return size_type(~0) / sizeof(_Tp); }
+
+ _LIBCPP_HIDE_FROM_ABI bool operator==(const __sso_allocator& __a) const { return &buf_ == &__a.buf_; }
+ _LIBCPP_HIDE_FROM_ABI bool operator!=(const __sso_allocator& __a) const { return &buf_ != &__a.buf_; }
+};
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP_SSO_ALLOCATOR_H
diff --git a/contrib/llvm-project/libcxx/src/include/to_chars_floating_point.h b/contrib/llvm-project/libcxx/src/include/to_chars_floating_point.h
new file mode 100644
index 000000000000..01c26181697b
--- /dev/null
+++ b/contrib/llvm-project/libcxx/src/include/to_chars_floating_point.h
@@ -0,0 +1,1079 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// Copyright (c) Microsoft Corporation.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+// This implementation is dedicated to the memory of Mary and Thavatchai.
+
+#ifndef _LIBCPP_SRC_INCLUDE_TO_CHARS_FLOATING_POINT_H
+#define _LIBCPP_SRC_INCLUDE_TO_CHARS_FLOATING_POINT_H
+
+// Avoid formatting to keep the changes with the original code minimal.
+// clang-format off
+
+#include <__algorithm/find.h>
+#include <__algorithm/find_if.h>
+#include <__algorithm/lower_bound.h>
+#include <__algorithm/min.h>
+#include <__assert>
+#include <__config>
+#include <__functional/operations.h>
+#include <__iterator/access.h>
+#include <__iterator/size.h>
+#include <bit>
+#include <cfloat>
+#include <climits>
+
+#include "include/ryu/ryu.h"
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+namespace __itoa {
+inline constexpr char _Charconv_digits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e',
+ 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
+static_assert(std::size(_Charconv_digits) == 36);
+} // __itoa
+
+// vvvvvvvvvv DERIVED FROM corecrt_internal_fltintrn.h vvvvvvvvvv
+
+template <class _FloatingType>
+struct _Floating_type_traits;
+
+template <>
+struct _Floating_type_traits<float> {
+ static constexpr int32_t _Mantissa_bits = FLT_MANT_DIG;
+ static constexpr int32_t _Exponent_bits = sizeof(float) * CHAR_BIT - FLT_MANT_DIG;
+
+ static constexpr int32_t _Maximum_binary_exponent = FLT_MAX_EXP - 1;
+ static constexpr int32_t _Minimum_binary_exponent = FLT_MIN_EXP - 1;
+
+ static constexpr int32_t _Exponent_bias = 127;
+
+ static constexpr int32_t _Sign_shift = _Exponent_bits + _Mantissa_bits - 1;
+ static constexpr int32_t _Exponent_shift = _Mantissa_bits - 1;
+
+ using _Uint_type = uint32_t;
+
+ static constexpr uint32_t _Exponent_mask = (1u << _Exponent_bits) - 1;
+ static constexpr uint32_t _Normal_mantissa_mask = (1u << _Mantissa_bits) - 1;
+ static constexpr uint32_t _Denormal_mantissa_mask = (1u << (_Mantissa_bits - 1)) - 1;
+ static constexpr uint32_t _Special_nan_mantissa_mask = 1u << (_Mantissa_bits - 2);
+ static constexpr uint32_t _Shifted_sign_mask = 1u << _Sign_shift;
+ static constexpr uint32_t _Shifted_exponent_mask = _Exponent_mask << _Exponent_shift;
+};
+
+template <>
+struct _Floating_type_traits<double> {
+ static constexpr int32_t _Mantissa_bits = DBL_MANT_DIG;
+ static constexpr int32_t _Exponent_bits = sizeof(double) * CHAR_BIT - DBL_MANT_DIG;
+
+ static constexpr int32_t _Maximum_binary_exponent = DBL_MAX_EXP - 1;
+ static constexpr int32_t _Minimum_binary_exponent = DBL_MIN_EXP - 1;
+
+ static constexpr int32_t _Exponent_bias = 1023;
+
+ static constexpr int32_t _Sign_shift = _Exponent_bits + _Mantissa_bits - 1;
+ static constexpr int32_t _Exponent_shift = _Mantissa_bits - 1;
+
+ using _Uint_type = uint64_t;
+
+ static constexpr uint64_t _Exponent_mask = (1ULL << _Exponent_bits) - 1;
+ static constexpr uint64_t _Normal_mantissa_mask = (1ULL << _Mantissa_bits) - 1;
+ static constexpr uint64_t _Denormal_mantissa_mask = (1ULL << (_Mantissa_bits - 1)) - 1;
+ static constexpr uint64_t _Special_nan_mantissa_mask = 1ULL << (_Mantissa_bits - 2);
+ static constexpr uint64_t _Shifted_sign_mask = 1ULL << _Sign_shift;
+ static constexpr uint64_t _Shifted_exponent_mask = _Exponent_mask << _Exponent_shift;
+};
+
+// ^^^^^^^^^^ DERIVED FROM corecrt_internal_fltintrn.h ^^^^^^^^^^
+
+// FUNCTION to_chars (FLOATING-POINT TO STRING)
+template <class _Floating>
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI
+to_chars_result _Floating_to_chars_hex_precision(
+ char* _First, char* const _Last, const _Floating _Value, int _Precision) noexcept {
+
+ // * Determine the effective _Precision.
+ // * Later, we'll decrement _Precision when printing each hexit after the decimal point.
+
+ // The hexits after the decimal point correspond to the explicitly stored fraction bits.
+ // float explicitly stores 23 fraction bits. 23 / 4 == 5.75, which is 6 hexits.
+ // double explicitly stores 52 fraction bits. 52 / 4 == 13, which is 13 hexits.
+ constexpr int _Full_precision = _IsSame<_Floating, float>::value ? 6 : 13;
+ constexpr int _Adjusted_explicit_bits = _Full_precision * 4;
+
+ if (_Precision < 0) {
+ // C11 7.21.6.1 "The fprintf function"/5: "A negative precision argument is taken as if the precision were
+ // omitted." /8: "if the precision is missing and FLT_RADIX is a power of 2, then the precision is sufficient
+ // for an exact representation of the value"
+ _Precision = _Full_precision;
+ }
+
+ // * Extract the _Ieee_mantissa and _Ieee_exponent.
+ using _Traits = _Floating_type_traits<_Floating>;
+ using _Uint_type = typename _Traits::_Uint_type;
+
+ const _Uint_type _Uint_value = std::bit_cast<_Uint_type>(_Value);
+ const _Uint_type _Ieee_mantissa = _Uint_value & _Traits::_Denormal_mantissa_mask;
+ const int32_t _Ieee_exponent = static_cast<int32_t>(_Uint_value >> _Traits::_Exponent_shift);
+
+ // * Prepare the _Adjusted_mantissa. This is aligned to hexit boundaries,
+ // * with the implicit bit restored (0 for zero values and subnormal values, 1 for normal values).
+ // * Also calculate the _Unbiased_exponent. This unifies the processing of zero, subnormal, and normal values.
+ _Uint_type _Adjusted_mantissa;
+
+ if constexpr (_IsSame<_Floating, float>::value) {
+ _Adjusted_mantissa = _Ieee_mantissa << 1; // align to hexit boundary (23 isn't divisible by 4)
+ } else {
+ _Adjusted_mantissa = _Ieee_mantissa; // already aligned (52 is divisible by 4)
+ }
+
+ int32_t _Unbiased_exponent;
+
+ if (_Ieee_exponent == 0) { // zero or subnormal
+ // implicit bit is 0
+
+ if (_Ieee_mantissa == 0) { // zero
+ // C11 7.21.6.1 "The fprintf function"/8: "If the value is zero, the exponent is zero."
+ _Unbiased_exponent = 0;
+ } else { // subnormal
+ _Unbiased_exponent = 1 - _Traits::_Exponent_bias;
+ }
+ } else { // normal
+ _Adjusted_mantissa |= _Uint_type{1} << _Adjusted_explicit_bits; // implicit bit is 1
+ _Unbiased_exponent = _Ieee_exponent - _Traits::_Exponent_bias;
+ }
+
+ // _Unbiased_exponent is within [-126, 127] for float, [-1022, 1023] for double.
+
+ // * Decompose _Unbiased_exponent into _Sign_character and _Absolute_exponent.
+ char _Sign_character;
+ uint32_t _Absolute_exponent;
+
+ if (_Unbiased_exponent < 0) {
+ _Sign_character = '-';
+ _Absolute_exponent = static_cast<uint32_t>(-_Unbiased_exponent);
+ } else {
+ _Sign_character = '+';
+ _Absolute_exponent = static_cast<uint32_t>(_Unbiased_exponent);
+ }
+
+ // _Absolute_exponent is within [0, 127] for float, [0, 1023] for double.
+
+ // * Perform a single bounds check.
+ {
+ int32_t _Exponent_length;
+
+ if (_Absolute_exponent < 10) {
+ _Exponent_length = 1;
+ } else if (_Absolute_exponent < 100) {
+ _Exponent_length = 2;
+ } else if constexpr (_IsSame<_Floating, float>::value) {
+ _Exponent_length = 3;
+ } else if (_Absolute_exponent < 1000) {
+ _Exponent_length = 3;
+ } else {
+ _Exponent_length = 4;
+ }
+
+ // _Precision might be enormous; avoid integer overflow by testing it separately.
+ ptrdiff_t _Buffer_size = _Last - _First;
+
+ if (_Buffer_size < _Precision) {
+ return {_Last, errc::value_too_large};
+ }
+
+ _Buffer_size -= _Precision;
+
+ const int32_t _Length_excluding_precision = 1 // leading hexit
+ + static_cast<int32_t>(_Precision > 0) // possible decimal point
+ // excluding `+ _Precision`, hexits after decimal point
+ + 2 // "p+" or "p-"
+ + _Exponent_length; // exponent
+
+ if (_Buffer_size < _Length_excluding_precision) {
+ return {_Last, errc::value_too_large};
+ }
+ }
+
+ // * Perform rounding when we've been asked to omit hexits.
+ if (_Precision < _Full_precision) {
+ // _Precision is within [0, 5] for float, [0, 12] for double.
+
+ // _Dropped_bits is within [4, 24] for float, [4, 52] for double.
+ const int _Dropped_bits = (_Full_precision - _Precision) * 4;
+
+ // Perform rounding by adding an appropriately-shifted bit.
+
+ // This can propagate carries all the way into the leading hexit. Examples:
+ // "0.ff9" rounded to a precision of 2 is "1.00".
+ // "1.ff9" rounded to a precision of 2 is "2.00".
+
+ // Note that the leading hexit participates in the rounding decision. Examples:
+ // "0.8" rounded to a precision of 0 is "0".
+ // "1.8" rounded to a precision of 0 is "2".
+
+ // Reference implementation with suboptimal codegen:
+ // bool _Should_round_up(bool _Lsb_bit, bool _Round_bit, bool _Has_tail_bits) {
+ // // If there are no insignificant set bits, the value is exactly-representable and should not be rounded.
+ // //
+ // // If there are insignificant set bits, we need to round according to round_to_nearest.
+ // // We need to handle two cases: we round up if either [1] the value is slightly greater
+ // // than the midpoint between two exactly-representable values or [2] the value is exactly the midpoint
+ // // between two exactly-representable values and the greater of the two is even (this is "round-to-even").
+ // return _Round_bit && (_Has_tail_bits || _Lsb_bit);
+ //}
+ // const bool _Lsb_bit = (_Adjusted_mantissa & (_Uint_type{1} << _Dropped_bits)) != 0;
+ // const bool _Round_bit = (_Adjusted_mantissa & (_Uint_type{1} << (_Dropped_bits - 1))) != 0;
+ // const bool _Has_tail_bits = (_Adjusted_mantissa & ((_Uint_type{1} << (_Dropped_bits - 1)) - 1)) != 0;
+ // const bool _Should_round = _Should_round_up(_Lsb_bit, _Round_bit, _Has_tail_bits);
+ // _Adjusted_mantissa += _Uint_type{_Should_round} << _Dropped_bits;
+
+ // Example for optimized implementation: Let _Dropped_bits be 8.
+ // Bit index: ...[8]76543210
+ // _Adjusted_mantissa: ...[L]RTTTTTTT (not depicting known details, like hexit alignment)
+ // By focusing on the bit at index _Dropped_bits, we can avoid unnecessary branching and shifting.
+
+ // Bit index: ...[8]76543210
+ // _Lsb_bit: ...[L]RTTTTTTT
+ const _Uint_type _Lsb_bit = _Adjusted_mantissa;
+
+ // Bit index: ...9[8]76543210
+ // _Round_bit: ...L[R]TTTTTTT0
+ const _Uint_type _Round_bit = _Adjusted_mantissa << 1;
+
+ // We can detect (without branching) whether any of the trailing bits are set.
+ // Due to _Should_round below, this computation will be used if and only if R is 1, so we can assume that here.
+ // Bit index: ...9[8]76543210
+ // _Round_bit: ...L[1]TTTTTTT0
+ // _Has_tail_bits: ....[H]........
+
+ // If all of the trailing bits T are 0, then `_Round_bit - 1` will produce 0 for H (due to R being 1).
+ // If any of the trailing bits T are 1, then `_Round_bit - 1` will produce 1 for H (due to R being 1).
+ const _Uint_type _Has_tail_bits = _Round_bit - 1;
+
+ // Finally, we can use _Should_round_up() logic with bitwise-AND and bitwise-OR,
+ // selecting just the bit at index _Dropped_bits. This is the appropriately-shifted bit that we want.
+ const _Uint_type _Should_round = _Round_bit & (_Has_tail_bits | _Lsb_bit) & (_Uint_type{1} << _Dropped_bits);
+
+ // This rounding technique is dedicated to the memory of Peppermint. =^..^=
+ _Adjusted_mantissa += _Should_round;
+ }
+
+ // * Print the leading hexit, then mask it away.
+ {
+ const uint32_t _Nibble = static_cast<uint32_t>(_Adjusted_mantissa >> _Adjusted_explicit_bits);
+ _LIBCPP_ASSERT_INTERNAL(_Nibble < 3, "");
+ const char _Leading_hexit = static_cast<char>('0' + _Nibble);
+
+ *_First++ = _Leading_hexit;
+
+ constexpr _Uint_type _Mask = (_Uint_type{1} << _Adjusted_explicit_bits) - 1;
+ _Adjusted_mantissa &= _Mask;
+ }
+
+ // * Print the decimal point and trailing hexits.
+
+ // C11 7.21.6.1 "The fprintf function"/8:
+ // "if the precision is zero and the # flag is not specified, no decimal-point character appears."
+ if (_Precision > 0) {
+ *_First++ = '.';
+
+ int32_t _Number_of_bits_remaining = _Adjusted_explicit_bits; // 24 for float, 52 for double
+
+ for (;;) {
+ _LIBCPP_ASSERT_INTERNAL(_Number_of_bits_remaining >= 4, "");
+ _LIBCPP_ASSERT_INTERNAL(_Number_of_bits_remaining % 4 == 0, "");
+ _Number_of_bits_remaining -= 4;
+
+ const uint32_t _Nibble = static_cast<uint32_t>(_Adjusted_mantissa >> _Number_of_bits_remaining);
+ _LIBCPP_ASSERT_INTERNAL(_Nibble < 16, "");
+ const char _Hexit = __itoa::_Charconv_digits[_Nibble];
+
+ *_First++ = _Hexit;
+
+ // _Precision is the number of hexits that still need to be printed.
+ --_Precision;
+ if (_Precision == 0) {
+ break; // We're completely done with this phase.
+ }
+ // Otherwise, we need to keep printing hexits.
+
+ if (_Number_of_bits_remaining == 0) {
+ // We've finished printing _Adjusted_mantissa, so all remaining hexits are '0'.
+ std::memset(_First, '0', static_cast<size_t>(_Precision));
+ _First += _Precision;
+ break;
+ }
+
+ // Mask away the hexit that we just printed, then keep looping.
+ // (We skip this when breaking out of the loop above, because _Adjusted_mantissa isn't used later.)
+ const _Uint_type _Mask = (_Uint_type{1} << _Number_of_bits_remaining) - 1;
+ _Adjusted_mantissa &= _Mask;
+ }
+ }
+
+ // * Print the exponent.
+
+ // C11 7.21.6.1 "The fprintf function"/8: "The exponent always contains at least one digit, and only as many more
+ // digits as necessary to represent the decimal exponent of 2."
+
+ // Performance note: We should take advantage of the known ranges of possible exponents.
+
+ *_First++ = 'p';
+ *_First++ = _Sign_character;
+
+ // We've already printed '-' if necessary, so uint32_t _Absolute_exponent avoids testing that again.
+ return std::to_chars(_First, _Last, _Absolute_exponent);
+}
+
+template <class _Floating>
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI
+to_chars_result _Floating_to_chars_hex_shortest(
+ char* _First, char* const _Last, const _Floating _Value) noexcept {
+
+ // This prints "1.728p+0" instead of "2.e5p-1".
+ // This prints "0.000002p-126" instead of "1p-149" for float.
+ // This prints "0.0000000000001p-1022" instead of "1p-1074" for double.
+ // This prioritizes being consistent with printf's de facto behavior (and hex-precision's behavior)
+ // over minimizing the number of characters printed.
+
+ using _Traits = _Floating_type_traits<_Floating>;
+ using _Uint_type = typename _Traits::_Uint_type;
+
+ const _Uint_type _Uint_value = std::bit_cast<_Uint_type>(_Value);
+
+ if (_Uint_value == 0) { // zero detected; write "0p+0" and return
+ // C11 7.21.6.1 "The fprintf function"/8: "If the value is zero, the exponent is zero."
+ // Special-casing zero is necessary because of the exponent.
+ const char* const _Str = "0p+0";
+ const size_t _Len = 4;
+
+ if (_Last - _First < static_cast<ptrdiff_t>(_Len)) {
+ return {_Last, errc::value_too_large};
+ }
+
+ std::memcpy(_First, _Str, _Len);
+
+ return {_First + _Len, errc{}};
+ }
+
+ const _Uint_type _Ieee_mantissa = _Uint_value & _Traits::_Denormal_mantissa_mask;
+ const int32_t _Ieee_exponent = static_cast<int32_t>(_Uint_value >> _Traits::_Exponent_shift);
+
+ char _Leading_hexit; // implicit bit
+ int32_t _Unbiased_exponent;
+
+ if (_Ieee_exponent == 0) { // subnormal
+ _Leading_hexit = '0';
+ _Unbiased_exponent = 1 - _Traits::_Exponent_bias;
+ } else { // normal
+ _Leading_hexit = '1';
+ _Unbiased_exponent = _Ieee_exponent - _Traits::_Exponent_bias;
+ }
+
+ // Performance note: Consider avoiding per-character bounds checking when there's plenty of space.
+
+ if (_First == _Last) {
+ return {_Last, errc::value_too_large};
+ }
+
+ *_First++ = _Leading_hexit;
+
+ if (_Ieee_mantissa == 0) {
+ // The fraction bits are all 0. Trim them away, including the decimal point.
+ } else {
+ if (_First == _Last) {
+ return {_Last, errc::value_too_large};
+ }
+
+ *_First++ = '.';
+
+ // The hexits after the decimal point correspond to the explicitly stored fraction bits.
+ // float explicitly stores 23 fraction bits. 23 / 4 == 5.75, so we'll print at most 6 hexits.
+ // double explicitly stores 52 fraction bits. 52 / 4 == 13, so we'll print at most 13 hexits.
+ _Uint_type _Adjusted_mantissa;
+ int32_t _Number_of_bits_remaining;
+
+ if constexpr (_IsSame<_Floating, float>::value) {
+ _Adjusted_mantissa = _Ieee_mantissa << 1; // align to hexit boundary (23 isn't divisible by 4)
+ _Number_of_bits_remaining = 24; // 23 fraction bits + 1 alignment bit
+ } else {
+ _Adjusted_mantissa = _Ieee_mantissa; // already aligned (52 is divisible by 4)
+ _Number_of_bits_remaining = 52; // 52 fraction bits
+ }
+
+ // do-while: The condition _Adjusted_mantissa != 0 is initially true - we have nonzero fraction bits and we've
+ // printed the decimal point. Each iteration, we print a hexit, mask it away, and keep looping if we still have
+ // nonzero fraction bits. If there would be trailing '0' hexits, this trims them. If there wouldn't be trailing
+ // '0' hexits, the same condition works (as we print the final hexit and mask it away); we don't need to test
+ // _Number_of_bits_remaining.
+ do {
+ _LIBCPP_ASSERT_INTERNAL(_Number_of_bits_remaining >= 4, "");
+ _LIBCPP_ASSERT_INTERNAL(_Number_of_bits_remaining % 4 == 0, "");
+ _Number_of_bits_remaining -= 4;
+
+ const uint32_t _Nibble = static_cast<uint32_t>(_Adjusted_mantissa >> _Number_of_bits_remaining);
+ _LIBCPP_ASSERT_INTERNAL(_Nibble < 16, "");
+ const char _Hexit = __itoa::_Charconv_digits[_Nibble];
+
+ if (_First == _Last) {
+ return {_Last, errc::value_too_large};
+ }
+
+ *_First++ = _Hexit;
+
+ const _Uint_type _Mask = (_Uint_type{1} << _Number_of_bits_remaining) - 1;
+ _Adjusted_mantissa &= _Mask;
+
+ } while (_Adjusted_mantissa != 0);
+ }
+
+ // C11 7.21.6.1 "The fprintf function"/8: "The exponent always contains at least one digit, and only as many more
+ // digits as necessary to represent the decimal exponent of 2."
+
+ // Performance note: We should take advantage of the known ranges of possible exponents.
+
+ // float: _Unbiased_exponent is within [-126, 127].
+ // double: _Unbiased_exponent is within [-1022, 1023].
+
+ if (_Last - _First < 2) {
+ return {_Last, errc::value_too_large};
+ }
+
+ *_First++ = 'p';
+
+ if (_Unbiased_exponent < 0) {
+ *_First++ = '-';
+ _Unbiased_exponent = -_Unbiased_exponent;
+ } else {
+ *_First++ = '+';
+ }
+
+ // We've already printed '-' if necessary, so static_cast<uint32_t> avoids testing that again.
+ return std::to_chars(_First, _Last, static_cast<uint32_t>(_Unbiased_exponent));
+}
+
+// For general precision, we can use lookup tables to avoid performing trial formatting.
+
+// For a simple example, imagine counting the number of digits D in an integer, and needing to know
+// whether D is less than 3, equal to 3/4/5/6, or greater than 6. We could use a lookup table:
+// D | Largest integer with D digits
+// 2 | 99
+// 3 | 999
+// 4 | 9'999
+// 5 | 99'999
+// 6 | 999'999
+// 7 | table end
+// Looking up an integer in this table with lower_bound() will work:
+// * Too-small integers, like 7, 70, and 99, will cause lower_bound() to return the D == 2 row. (If all we care
+// about is whether D is less than 3, then it's okay to smash the D == 1 and D == 2 cases together.)
+// * Integers in [100, 999] will cause lower_bound() to return the D == 3 row, and so forth.
+// * Too-large integers, like 1'000'000 and above, will cause lower_bound() to return the end of the table. If we
+// compute D from that index, this will be considered D == 7, which will activate any "greater than 6" logic.
+
+// Floating-point is slightly more complicated.
+
+// The ordinary lookup tables are for X within [-5, 38] for float, and [-5, 308] for double.
+// (-5 absorbs too-negative exponents, outside the P > X >= -4 criterion. 38 and 308 are the maximum exponents.)
+// Due to the P > X condition, we can use a subset of the table for X within [-5, P - 1], suitably clamped.
+
+// When P is small, rounding can affect X. For example:
+// For P == 1, the largest double with X == 0 is: 9.4999999999999982236431605997495353221893310546875
+// For P == 2, the largest double with X == 0 is: 9.949999999999999289457264239899814128875732421875
+// For P == 3, the largest double with X == 0 is: 9.9949999999999992184029906638897955417633056640625
+
+// Exponent adjustment is a concern for P within [1, 7] for float, and [1, 15] for double (determined via
+// brute force). While larger values of P still perform rounding, they can't trigger exponent adjustment.
+// This is because only values with repeated '9' digits can undergo exponent adjustment during rounding,
+// and floating-point granularity limits the number of consecutive '9' digits that can appear.
+
+// So, we need special lookup tables for small values of P.
+// These tables have varying lengths due to the P > X >= -4 criterion. For example:
+// For P == 1, need table entries for X: -5, -4, -3, -2, -1, 0
+// For P == 2, need table entries for X: -5, -4, -3, -2, -1, 0, 1
+// For P == 3, need table entries for X: -5, -4, -3, -2, -1, 0, 1, 2
+// For P == 4, need table entries for X: -5, -4, -3, -2, -1, 0, 1, 2, 3
+
+// We can concatenate these tables for compact storage, using triangular numbers to access them.
+// The table for P begins at index (P - 1) * (P + 10) / 2 with length P + 5.
+
+// For both the ordinary and special lookup tables, after an index I is returned by lower_bound(), X is I - 5.
+
+// We need to special-case the floating-point value 0.0, which is considered to have X == 0.
+// Otherwise, the lookup tables would consider it to have a highly negative X.
+
+// Finally, because we're working with positive floating-point values,
+// representation comparisons behave identically to floating-point comparisons.
+
+// The following code generated the lookup tables for the scientific exponent X. Don't remove this code.
+#if 0
+// cl /EHsc /nologo /W4 /MT /O2 /std:c++17 generate_tables.cpp && generate_tables
+
+#include <algorithm>
+#include <assert.h>
+#include <charconv>
+#include <cmath>
+#include <limits>
+#include <map>
+#include <stdint.h>
+#include <stdio.h>
+#include <system_error>
+#include <type_traits>
+#include <vector>
+using namespace std;
+
+template <typename UInt, typename Pred>
+[[nodiscard]] UInt uint_partition_point(UInt first, const UInt last, Pred pred) {
+ // Find the beginning of the false partition in [first, last).
+ // [first, last) is partitioned when all of the true values occur before all of the false values.
+
+ static_assert(is_unsigned_v<UInt>);
+ assert(first <= last);
+
+ for (UInt n = last - first; n > 0;) {
+ const UInt n2 = n / 2;
+ const UInt mid = first + n2;
+
+ if (pred(mid)) {
+ first = mid + 1;
+ n = n - n2 - 1;
+ } else {
+ n = n2;
+ }
+ }
+
+ return first;
+}
+
+template <typename Floating>
+[[nodiscard]] int scientific_exponent_X(const int P, const Floating flt) {
+ char buf[400]; // more than enough
+
+ // C11 7.21.6.1 "The fprintf function"/8 performs trial formatting with scientific precision P - 1.
+ const auto to_result = to_chars(buf, end(buf), flt, chars_format::scientific, P - 1);
+ assert(to_result.ec == errc{});
+
+ const char* exp_ptr = find(buf, to_result.ptr, 'e');
+ assert(exp_ptr != to_result.ptr);
+
+ ++exp_ptr; // advance past 'e'
+
+ if (*exp_ptr == '+') {
+ ++exp_ptr; // advance past '+' which from_chars() won't parse
+ }
+
+ int X;
+ const auto from_result = from_chars(exp_ptr, to_result.ptr, X);
+ assert(from_result.ec == errc{});
+ return X;
+}
+
+template <typename UInt>
+void print_table(const vector<UInt>& v, const char* const name) {
+ constexpr const char* UIntName = _IsSame<UInt, uint32_t>::value ? "uint32_t" : "uint64_t";
+
+ printf("static constexpr %s %s[%zu] = {\n", UIntName, name, v.size());
+
+ for (const auto& val : v) {
+ if constexpr (_IsSame<UInt, uint32_t>::value) {
+ printf("0x%08Xu,\n", val);
+ } else {
+ printf("0x%016llXu,\n", val);
+ }
+ }
+
+ printf("};\n");
+}
+
+enum class Mode { Tables, Tests };
+
+template <typename Floating>
+void generate_tables(const Mode mode) {
+ using Limits = numeric_limits<Floating>;
+ using UInt = conditional_t<_IsSame<Floating, float>::value, uint32_t, uint64_t>;
+
+ map<int, map<int, UInt>> P_X_LargestValWithX;
+
+ constexpr int MaxP = Limits::max_exponent10 + 1; // MaxP performs no rounding during trial formatting
+
+ for (int P = 1; P <= MaxP; ++P) {
+ for (int X = -5; X < P; ++X) {
+ constexpr Floating first = static_cast<Floating>(9e-5); // well below 9.5e-5, otherwise arbitrary
+ constexpr Floating last = Limits::infinity(); // one bit above Limits::max()
+
+ const UInt val_beyond_X = uint_partition_point(reinterpret_cast<const UInt&>(first),
+ reinterpret_cast<const UInt&>(last),
+ [P, X](const UInt u) { return scientific_exponent_X(P, reinterpret_cast<const Floating&>(u)) <= X; });
+
+ P_X_LargestValWithX[P][X] = val_beyond_X - 1;
+ }
+ }
+
+ constexpr const char* FloatingName = _IsSame<Floating, float>::value ? "float" : "double";
+
+ constexpr int MaxSpecialP = _IsSame<Floating, float>::value ? 7 : 15; // MaxSpecialP is affected by exponent adjustment
+
+ if (mode == Mode::Tables) {
+ printf("template <>\n");
+ printf("struct _General_precision_tables<%s> {\n", FloatingName);
+
+ printf("static constexpr int _Max_special_P = %d;\n", MaxSpecialP);
+
+ vector<UInt> special;
+
+ for (int P = 1; P <= MaxSpecialP; ++P) {
+ for (int X = -5; X < P; ++X) {
+ const UInt val = P_X_LargestValWithX[P][X];
+ special.push_back(val);
+ }
+ }
+
+ print_table(special, "_Special_X_table");
+
+ for (int P = MaxSpecialP + 1; P < MaxP; ++P) {
+ for (int X = -5; X < P; ++X) {
+ const UInt val = P_X_LargestValWithX[P][X];
+ assert(val == P_X_LargestValWithX[MaxP][X]);
+ }
+ }
+
+ printf("static constexpr int _Max_P = %d;\n", MaxP);
+
+ vector<UInt> ordinary;
+
+ for (int X = -5; X < MaxP; ++X) {
+ const UInt val = P_X_LargestValWithX[MaxP][X];
+ ordinary.push_back(val);
+ }
+
+ print_table(ordinary, "_Ordinary_X_table");
+
+ printf("};\n");
+ } else {
+ printf("==========\n");
+ printf("Test cases for %s:\n", FloatingName);
+
+ constexpr int Hexits = _IsSame<Floating, float>::value ? 6 : 13;
+ constexpr const char* Suffix = _IsSame<Floating, float>::value ? "f" : "";
+
+ for (int P = 1; P <= MaxP; ++P) {
+ for (int X = -5; X < P; ++X) {
+ if (P <= MaxSpecialP || P == 25 || P == MaxP || X == P - 1) {
+ const UInt val1 = P_X_LargestValWithX[P][X];
+ const Floating f1 = reinterpret_cast<const Floating&>(val1);
+ const UInt val2 = val1 + 1;
+ const Floating f2 = reinterpret_cast<const Floating&>(val2);
+
+ printf("{%.*a%s, chars_format::general, %d, \"%.*g\"},\n", Hexits, f1, Suffix, P, P, f1);
+ if (isfinite(f2)) {
+ printf("{%.*a%s, chars_format::general, %d, \"%.*g\"},\n", Hexits, f2, Suffix, P, P, f2);
+ }
+ }
+ }
+ }
+ }
+}
+
+int main() {
+ printf("template <class _Floating>\n");
+ printf("struct _General_precision_tables;\n");
+ generate_tables<float>(Mode::Tables);
+ generate_tables<double>(Mode::Tables);
+ generate_tables<float>(Mode::Tests);
+ generate_tables<double>(Mode::Tests);
+}
+#endif // 0
+
+template <class _Floating>
+struct _General_precision_tables;
+
+template <>
+struct _General_precision_tables<float> {
+ static constexpr int _Max_special_P = 7;
+
+ static constexpr uint32_t _Special_X_table[63] = {0x38C73ABCu, 0x3A79096Bu, 0x3C1BA5E3u, 0x3DC28F5Cu, 0x3F733333u,
+ 0x4117FFFFu, 0x38D0AAA7u, 0x3A826AA8u, 0x3C230553u, 0x3DCBC6A7u, 0x3F7EB851u, 0x411F3333u, 0x42C6FFFFu,
+ 0x38D19C3Fu, 0x3A8301A7u, 0x3C23C211u, 0x3DCCB295u, 0x3F7FDF3Bu, 0x411FEB85u, 0x42C7E666u, 0x4479DFFFu,
+ 0x38D1B468u, 0x3A8310C1u, 0x3C23D4F1u, 0x3DCCCA2Du, 0x3F7FFCB9u, 0x411FFDF3u, 0x42C7FD70u, 0x4479FCCCu,
+ 0x461C3DFFu, 0x38D1B6D2u, 0x3A831243u, 0x3C23D6D4u, 0x3DCCCC89u, 0x3F7FFFACu, 0x411FFFCBu, 0x42C7FFBEu,
+ 0x4479FFAEu, 0x461C3FCCu, 0x47C34FBFu, 0x38D1B710u, 0x3A83126Au, 0x3C23D704u, 0x3DCCCCC6u, 0x3F7FFFF7u,
+ 0x411FFFFAu, 0x42C7FFF9u, 0x4479FFF7u, 0x461C3FFAu, 0x47C34FF9u, 0x497423F7u, 0x38D1B716u, 0x3A83126Eu,
+ 0x3C23D709u, 0x3DCCCCCCu, 0x3F7FFFFFu, 0x411FFFFFu, 0x42C7FFFFu, 0x4479FFFFu, 0x461C3FFFu, 0x47C34FFFu,
+ 0x497423FFu, 0x4B18967Fu};
+
+ static constexpr int _Max_P = 39;
+
+ static constexpr uint32_t _Ordinary_X_table[44] = {0x38D1B717u, 0x3A83126Eu, 0x3C23D70Au, 0x3DCCCCCCu, 0x3F7FFFFFu,
+ 0x411FFFFFu, 0x42C7FFFFu, 0x4479FFFFu, 0x461C3FFFu, 0x47C34FFFu, 0x497423FFu, 0x4B18967Fu, 0x4CBEBC1Fu,
+ 0x4E6E6B27u, 0x501502F8u, 0x51BA43B7u, 0x5368D4A5u, 0x551184E7u, 0x56B5E620u, 0x58635FA9u, 0x5A0E1BC9u,
+ 0x5BB1A2BCu, 0x5D5E0B6Bu, 0x5F0AC723u, 0x60AD78EBu, 0x6258D726u, 0x64078678u, 0x65A96816u, 0x6753C21Bu,
+ 0x69045951u, 0x6AA56FA5u, 0x6C4ECB8Fu, 0x6E013F39u, 0x6FA18F07u, 0x7149F2C9u, 0x72FC6F7Cu, 0x749DC5ADu,
+ 0x76453719u, 0x77F684DFu, 0x799A130Bu, 0x7B4097CEu, 0x7CF0BDC2u, 0x7E967699u, 0x7F7FFFFFu};
+};
+
+template <>
+struct _General_precision_tables<double> {
+ static constexpr int _Max_special_P = 15;
+
+ static constexpr uint64_t _Special_X_table[195] = {0x3F18E757928E0C9Du, 0x3F4F212D77318FC5u, 0x3F8374BC6A7EF9DBu,
+ 0x3FB851EB851EB851u, 0x3FEE666666666666u, 0x4022FFFFFFFFFFFFu, 0x3F1A1554FBDAD751u, 0x3F504D551D68C692u,
+ 0x3F8460AA64C2F837u, 0x3FB978D4FDF3B645u, 0x3FEFD70A3D70A3D7u, 0x4023E66666666666u, 0x4058DFFFFFFFFFFFu,
+ 0x3F1A3387ECC8EB96u, 0x3F506034F3FD933Eu, 0x3F84784230FCF80Du, 0x3FB99652BD3C3611u, 0x3FEFFBE76C8B4395u,
+ 0x4023FD70A3D70A3Du, 0x4058FCCCCCCCCCCCu, 0x408F3BFFFFFFFFFFu, 0x3F1A368D04E0BA6Au, 0x3F506218230C7482u,
+ 0x3F847A9E2BCF91A3u, 0x3FB99945B6C3760Bu, 0x3FEFFF972474538Eu, 0x4023FFBE76C8B439u, 0x4058FFAE147AE147u,
+ 0x408F3F9999999999u, 0x40C387BFFFFFFFFFu, 0x3F1A36DA54164F19u, 0x3F506248748DF16Fu, 0x3F847ADA91B16DCBu,
+ 0x3FB99991361DC93Eu, 0x3FEFFFF583A53B8Eu, 0x4023FFF972474538u, 0x4058FFF7CED91687u, 0x408F3FF5C28F5C28u,
+ 0x40C387F999999999u, 0x40F869F7FFFFFFFFu, 0x3F1A36E20F35445Du, 0x3F50624D49814ABAu, 0x3F847AE09BE19D69u,
+ 0x3FB99998C2DA04C3u, 0x3FEFFFFEF39085F4u, 0x4023FFFF583A53B8u, 0x4058FFFF2E48E8A7u, 0x408F3FFEF9DB22D0u,
+ 0x40C387FF5C28F5C2u, 0x40F869FF33333333u, 0x412E847EFFFFFFFFu, 0x3F1A36E2D51EC34Bu, 0x3F50624DC5333A0Eu,
+ 0x3F847AE136800892u, 0x3FB9999984200AB7u, 0x3FEFFFFFE5280D65u, 0x4023FFFFEF39085Fu, 0x4058FFFFEB074A77u,
+ 0x408F3FFFE5C91D14u, 0x40C387FFEF9DB22Du, 0x40F869FFEB851EB8u, 0x412E847FE6666666u, 0x416312CFEFFFFFFFu,
+ 0x3F1A36E2E8E94FFCu, 0x3F50624DD191D1FDu, 0x3F847AE145F6467Du, 0x3FB999999773D81Cu, 0x3FEFFFFFFD50CE23u,
+ 0x4023FFFFFE5280D6u, 0x4058FFFFFDE7210Bu, 0x408F3FFFFD60E94Eu, 0x40C387FFFE5C91D1u, 0x40F869FFFDF3B645u,
+ 0x412E847FFD70A3D7u, 0x416312CFFE666666u, 0x4197D783FDFFFFFFu, 0x3F1A36E2EAE3F7A7u, 0x3F50624DD2CE7AC8u,
+ 0x3F847AE14782197Bu, 0x3FB9999999629FD9u, 0x3FEFFFFFFFBB47D0u, 0x4023FFFFFFD50CE2u, 0x4058FFFFFFCA501Au,
+ 0x408F3FFFFFBCE421u, 0x40C387FFFFD60E94u, 0x40F869FFFFCB923Au, 0x412E847FFFBE76C8u, 0x416312CFFFD70A3Du,
+ 0x4197D783FFCCCCCCu, 0x41CDCD64FFBFFFFFu, 0x3F1A36E2EB16A205u, 0x3F50624DD2EE2543u, 0x3F847AE147A9AE94u,
+ 0x3FB9999999941A39u, 0x3FEFFFFFFFF920C8u, 0x4023FFFFFFFBB47Du, 0x4058FFFFFFFAA19Cu, 0x408F3FFFFFF94A03u,
+ 0x40C387FFFFFBCE42u, 0x40F869FFFFFAC1D2u, 0x412E847FFFF97247u, 0x416312CFFFFBE76Cu, 0x4197D783FFFAE147u,
+ 0x41CDCD64FFF99999u, 0x4202A05F1FFBFFFFu, 0x3F1A36E2EB1BB30Fu, 0x3F50624DD2F14FE9u, 0x3F847AE147ADA3E3u,
+ 0x3FB9999999990CDCu, 0x3FEFFFFFFFFF5014u, 0x4023FFFFFFFF920Cu, 0x4058FFFFFFFF768Fu, 0x408F3FFFFFFF5433u,
+ 0x40C387FFFFFF94A0u, 0x40F869FFFFFF79C8u, 0x412E847FFFFF583Au, 0x416312CFFFFF9724u, 0x4197D783FFFF7CEDu,
+ 0x41CDCD64FFFF5C28u, 0x4202A05F1FFF9999u, 0x42374876E7FF7FFFu, 0x3F1A36E2EB1C34C3u, 0x3F50624DD2F1A0FAu,
+ 0x3F847AE147AE0938u, 0x3FB9999999998B86u, 0x3FEFFFFFFFFFEE68u, 0x4023FFFFFFFFF501u, 0x4058FFFFFFFFF241u,
+ 0x408F3FFFFFFFEED1u, 0x40C387FFFFFFF543u, 0x40F869FFFFFFF294u, 0x412E847FFFFFEF39u, 0x416312CFFFFFF583u,
+ 0x4197D783FFFFF2E4u, 0x41CDCD64FFFFEF9Du, 0x4202A05F1FFFF5C2u, 0x42374876E7FFF333u, 0x426D1A94A1FFEFFFu,
+ 0x3F1A36E2EB1C41BBu, 0x3F50624DD2F1A915u, 0x3F847AE147AE135Au, 0x3FB9999999999831u, 0x3FEFFFFFFFFFFE3Du,
+ 0x4023FFFFFFFFFEE6u, 0x4058FFFFFFFFFEA0u, 0x408F3FFFFFFFFE48u, 0x40C387FFFFFFFEEDu, 0x40F869FFFFFFFEA8u,
+ 0x412E847FFFFFFE52u, 0x416312CFFFFFFEF3u, 0x4197D783FFFFFEB0u, 0x41CDCD64FFFFFE5Cu, 0x4202A05F1FFFFEF9u,
+ 0x42374876E7FFFEB8u, 0x426D1A94A1FFFE66u, 0x42A2309CE53FFEFFu, 0x3F1A36E2EB1C4307u, 0x3F50624DD2F1A9E4u,
+ 0x3F847AE147AE145Eu, 0x3FB9999999999975u, 0x3FEFFFFFFFFFFFD2u, 0x4023FFFFFFFFFFE3u, 0x4058FFFFFFFFFFDCu,
+ 0x408F3FFFFFFFFFD4u, 0x40C387FFFFFFFFE4u, 0x40F869FFFFFFFFDDu, 0x412E847FFFFFFFD5u, 0x416312CFFFFFFFE5u,
+ 0x4197D783FFFFFFDEu, 0x41CDCD64FFFFFFD6u, 0x4202A05F1FFFFFE5u, 0x42374876E7FFFFDFu, 0x426D1A94A1FFFFD7u,
+ 0x42A2309CE53FFFE6u, 0x42D6BCC41E8FFFDFu, 0x3F1A36E2EB1C4328u, 0x3F50624DD2F1A9F9u, 0x3F847AE147AE1477u,
+ 0x3FB9999999999995u, 0x3FEFFFFFFFFFFFFBu, 0x4023FFFFFFFFFFFDu, 0x4058FFFFFFFFFFFCu, 0x408F3FFFFFFFFFFBu,
+ 0x40C387FFFFFFFFFDu, 0x40F869FFFFFFFFFCu, 0x412E847FFFFFFFFBu, 0x416312CFFFFFFFFDu, 0x4197D783FFFFFFFCu,
+ 0x41CDCD64FFFFFFFBu, 0x4202A05F1FFFFFFDu, 0x42374876E7FFFFFCu, 0x426D1A94A1FFFFFBu, 0x42A2309CE53FFFFDu,
+ 0x42D6BCC41E8FFFFCu, 0x430C6BF52633FFFBu};
+
+ static constexpr int _Max_P = 309;
+
+ static constexpr uint64_t _Ordinary_X_table[314] = {0x3F1A36E2EB1C432Cu, 0x3F50624DD2F1A9FBu, 0x3F847AE147AE147Au,
+ 0x3FB9999999999999u, 0x3FEFFFFFFFFFFFFFu, 0x4023FFFFFFFFFFFFu, 0x4058FFFFFFFFFFFFu, 0x408F3FFFFFFFFFFFu,
+ 0x40C387FFFFFFFFFFu, 0x40F869FFFFFFFFFFu, 0x412E847FFFFFFFFFu, 0x416312CFFFFFFFFFu, 0x4197D783FFFFFFFFu,
+ 0x41CDCD64FFFFFFFFu, 0x4202A05F1FFFFFFFu, 0x42374876E7FFFFFFu, 0x426D1A94A1FFFFFFu, 0x42A2309CE53FFFFFu,
+ 0x42D6BCC41E8FFFFFu, 0x430C6BF52633FFFFu, 0x4341C37937E07FFFu, 0x4376345785D89FFFu, 0x43ABC16D674EC7FFu,
+ 0x43E158E460913CFFu, 0x4415AF1D78B58C3Fu, 0x444B1AE4D6E2EF4Fu, 0x4480F0CF064DD591u, 0x44B52D02C7E14AF6u,
+ 0x44EA784379D99DB4u, 0x45208B2A2C280290u, 0x4554ADF4B7320334u, 0x4589D971E4FE8401u, 0x45C027E72F1F1281u,
+ 0x45F431E0FAE6D721u, 0x46293E5939A08CE9u, 0x465F8DEF8808B024u, 0x4693B8B5B5056E16u, 0x46C8A6E32246C99Cu,
+ 0x46FED09BEAD87C03u, 0x4733426172C74D82u, 0x476812F9CF7920E2u, 0x479E17B84357691Bu, 0x47D2CED32A16A1B1u,
+ 0x48078287F49C4A1Du, 0x483D6329F1C35CA4u, 0x48725DFA371A19E6u, 0x48A6F578C4E0A060u, 0x48DCB2D6F618C878u,
+ 0x4911EFC659CF7D4Bu, 0x49466BB7F0435C9Eu, 0x497C06A5EC5433C6u, 0x49B18427B3B4A05Bu, 0x49E5E531A0A1C872u,
+ 0x4A1B5E7E08CA3A8Fu, 0x4A511B0EC57E6499u, 0x4A8561D276DDFDC0u, 0x4ABABA4714957D30u, 0x4AF0B46C6CDD6E3Eu,
+ 0x4B24E1878814C9CDu, 0x4B5A19E96A19FC40u, 0x4B905031E2503DA8u, 0x4BC4643E5AE44D12u, 0x4BF97D4DF19D6057u,
+ 0x4C2FDCA16E04B86Du, 0x4C63E9E4E4C2F344u, 0x4C98E45E1DF3B015u, 0x4CCF1D75A5709C1Au, 0x4D03726987666190u,
+ 0x4D384F03E93FF9F4u, 0x4D6E62C4E38FF872u, 0x4DA2FDBB0E39FB47u, 0x4DD7BD29D1C87A19u, 0x4E0DAC74463A989Fu,
+ 0x4E428BC8ABE49F63u, 0x4E772EBAD6DDC73Cu, 0x4EACFA698C95390Bu, 0x4EE21C81F7DD43A7u, 0x4F16A3A275D49491u,
+ 0x4F4C4C8B1349B9B5u, 0x4F81AFD6EC0E1411u, 0x4FB61BCCA7119915u, 0x4FEBA2BFD0D5FF5Bu, 0x502145B7E285BF98u,
+ 0x50559725DB272F7Fu, 0x508AFCEF51F0FB5Eu, 0x50C0DE1593369D1Bu, 0x50F5159AF8044462u, 0x512A5B01B605557Au,
+ 0x516078E111C3556Cu, 0x5194971956342AC7u, 0x51C9BCDFABC13579u, 0x5200160BCB58C16Cu, 0x52341B8EBE2EF1C7u,
+ 0x526922726DBAAE39u, 0x529F6B0F092959C7u, 0x52D3A2E965B9D81Cu, 0x53088BA3BF284E23u, 0x533EAE8CAEF261ACu,
+ 0x53732D17ED577D0Bu, 0x53A7F85DE8AD5C4Eu, 0x53DDF67562D8B362u, 0x5412BA095DC7701Du, 0x5447688BB5394C25u,
+ 0x547D42AEA2879F2Eu, 0x54B249AD2594C37Cu, 0x54E6DC186EF9F45Cu, 0x551C931E8AB87173u, 0x5551DBF316B346E7u,
+ 0x558652EFDC6018A1u, 0x55BBE7ABD3781ECAu, 0x55F170CB642B133Eu, 0x5625CCFE3D35D80Eu, 0x565B403DCC834E11u,
+ 0x569108269FD210CBu, 0x56C54A3047C694FDu, 0x56FA9CBC59B83A3Du, 0x5730A1F5B8132466u, 0x5764CA732617ED7Fu,
+ 0x5799FD0FEF9DE8DFu, 0x57D03E29F5C2B18Bu, 0x58044DB473335DEEu, 0x583961219000356Au, 0x586FB969F40042C5u,
+ 0x58A3D3E2388029BBu, 0x58D8C8DAC6A0342Au, 0x590EFB1178484134u, 0x59435CEAEB2D28C0u, 0x59783425A5F872F1u,
+ 0x59AE412F0F768FADu, 0x59E2E8BD69AA19CCu, 0x5A17A2ECC414A03Fu, 0x5A4D8BA7F519C84Fu, 0x5A827748F9301D31u,
+ 0x5AB7151B377C247Eu, 0x5AECDA62055B2D9Du, 0x5B22087D4358FC82u, 0x5B568A9C942F3BA3u, 0x5B8C2D43B93B0A8Bu,
+ 0x5BC19C4A53C4E697u, 0x5BF6035CE8B6203Du, 0x5C2B843422E3A84Cu, 0x5C6132A095CE492Fu, 0x5C957F48BB41DB7Bu,
+ 0x5CCADF1AEA12525Au, 0x5D00CB70D24B7378u, 0x5D34FE4D06DE5056u, 0x5D6A3DE04895E46Cu, 0x5DA066AC2D5DAEC3u,
+ 0x5DD4805738B51A74u, 0x5E09A06D06E26112u, 0x5E400444244D7CABu, 0x5E7405552D60DBD6u, 0x5EA906AA78B912CBu,
+ 0x5EDF485516E7577Eu, 0x5F138D352E5096AFu, 0x5F48708279E4BC5Au, 0x5F7E8CA3185DEB71u, 0x5FB317E5EF3AB327u,
+ 0x5FE7DDDF6B095FF0u, 0x601DD55745CBB7ECu, 0x6052A5568B9F52F4u, 0x60874EAC2E8727B1u, 0x60BD22573A28F19Du,
+ 0x60F2357684599702u, 0x6126C2D4256FFCC2u, 0x615C73892ECBFBF3u, 0x6191C835BD3F7D78u, 0x61C63A432C8F5CD6u,
+ 0x61FBC8D3F7B3340Bu, 0x62315D847AD00087u, 0x6265B4E5998400A9u, 0x629B221EFFE500D3u, 0x62D0F5535FEF2084u,
+ 0x630532A837EAE8A5u, 0x633A7F5245E5A2CEu, 0x63708F936BAF85C1u, 0x63A4B378469B6731u, 0x63D9E056584240FDu,
+ 0x64102C35F729689Eu, 0x6444374374F3C2C6u, 0x647945145230B377u, 0x64AF965966BCE055u, 0x64E3BDF7E0360C35u,
+ 0x6518AD75D8438F43u, 0x654ED8D34E547313u, 0x6583478410F4C7ECu, 0x65B819651531F9E7u, 0x65EE1FBE5A7E7861u,
+ 0x6622D3D6F88F0B3Cu, 0x665788CCB6B2CE0Cu, 0x668D6AFFE45F818Fu, 0x66C262DFEEBBB0F9u, 0x66F6FB97EA6A9D37u,
+ 0x672CBA7DE5054485u, 0x6761F48EAF234AD3u, 0x679671B25AEC1D88u, 0x67CC0E1EF1A724EAu, 0x680188D357087712u,
+ 0x6835EB082CCA94D7u, 0x686B65CA37FD3A0Du, 0x68A11F9E62FE4448u, 0x68D56785FBBDD55Au, 0x690AC1677AAD4AB0u,
+ 0x6940B8E0ACAC4EAEu, 0x6974E718D7D7625Au, 0x69AA20DF0DCD3AF0u, 0x69E0548B68A044D6u, 0x6A1469AE42C8560Cu,
+ 0x6A498419D37A6B8Fu, 0x6A7FE52048590672u, 0x6AB3EF342D37A407u, 0x6AE8EB0138858D09u, 0x6B1F25C186A6F04Cu,
+ 0x6B537798F428562Fu, 0x6B88557F31326BBBu, 0x6BBE6ADEFD7F06AAu, 0x6BF302CB5E6F642Au, 0x6C27C37E360B3D35u,
+ 0x6C5DB45DC38E0C82u, 0x6C9290BA9A38C7D1u, 0x6CC734E940C6F9C5u, 0x6CFD022390F8B837u, 0x6D3221563A9B7322u,
+ 0x6D66A9ABC9424FEBu, 0x6D9C5416BB92E3E6u, 0x6DD1B48E353BCE6Fu, 0x6E0621B1C28AC20Bu, 0x6E3BAA1E332D728Eu,
+ 0x6E714A52DFFC6799u, 0x6EA59CE797FB817Fu, 0x6EDB04217DFA61DFu, 0x6F10E294EEBC7D2Bu, 0x6F451B3A2A6B9C76u,
+ 0x6F7A6208B5068394u, 0x6FB07D457124123Cu, 0x6FE49C96CD6D16CBu, 0x7019C3BC80C85C7Eu, 0x70501A55D07D39CFu,
+ 0x708420EB449C8842u, 0x70B9292615C3AA53u, 0x70EF736F9B3494E8u, 0x7123A825C100DD11u, 0x7158922F31411455u,
+ 0x718EB6BAFD91596Bu, 0x71C33234DE7AD7E2u, 0x71F7FEC216198DDBu, 0x722DFE729B9FF152u, 0x7262BF07A143F6D3u,
+ 0x72976EC98994F488u, 0x72CD4A7BEBFA31AAu, 0x73024E8D737C5F0Au, 0x7336E230D05B76CDu, 0x736C9ABD04725480u,
+ 0x73A1E0B622C774D0u, 0x73D658E3AB795204u, 0x740BEF1C9657A685u, 0x74417571DDF6C813u, 0x7475D2CE55747A18u,
+ 0x74AB4781EAD1989Eu, 0x74E10CB132C2FF63u, 0x75154FDD7F73BF3Bu, 0x754AA3D4DF50AF0Au, 0x7580A6650B926D66u,
+ 0x75B4CFFE4E7708C0u, 0x75EA03FDE214CAF0u, 0x7620427EAD4CFED6u, 0x7654531E58A03E8Bu, 0x768967E5EEC84E2Eu,
+ 0x76BFC1DF6A7A61BAu, 0x76F3D92BA28C7D14u, 0x7728CF768B2F9C59u, 0x775F03542DFB8370u, 0x779362149CBD3226u,
+ 0x77C83A99C3EC7EAFu, 0x77FE494034E79E5Bu, 0x7832EDC82110C2F9u, 0x7867A93A2954F3B7u, 0x789D9388B3AA30A5u,
+ 0x78D27C35704A5E67u, 0x79071B42CC5CF601u, 0x793CE2137F743381u, 0x79720D4C2FA8A030u, 0x79A6909F3B92C83Du,
+ 0x79DC34C70A777A4Cu, 0x7A11A0FC668AAC6Fu, 0x7A46093B802D578Bu, 0x7A7B8B8A6038AD6Eu, 0x7AB137367C236C65u,
+ 0x7AE585041B2C477Eu, 0x7B1AE64521F7595Eu, 0x7B50CFEB353A97DAu, 0x7B8503E602893DD1u, 0x7BBA44DF832B8D45u,
+ 0x7BF06B0BB1FB384Bu, 0x7C2485CE9E7A065Eu, 0x7C59A742461887F6u, 0x7C9008896BCF54F9u, 0x7CC40AABC6C32A38u,
+ 0x7CF90D56B873F4C6u, 0x7D2F50AC6690F1F8u, 0x7D63926BC01A973Bu, 0x7D987706B0213D09u, 0x7DCE94C85C298C4Cu,
+ 0x7E031CFD3999F7AFu, 0x7E37E43C8800759Bu, 0x7E6DDD4BAA009302u, 0x7EA2AA4F4A405BE1u, 0x7ED754E31CD072D9u,
+ 0x7F0D2A1BE4048F90u, 0x7F423A516E82D9BAu, 0x7F76C8E5CA239028u, 0x7FAC7B1F3CAC7433u, 0x7FE1CCF385EBC89Fu,
+ 0x7FEFFFFFFFFFFFFFu};
+};
+
+template <class _Floating>
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI
+to_chars_result _Floating_to_chars_general_precision(
+ char* _First, char* const _Last, const _Floating _Value, int _Precision) noexcept {
+
+ using _Traits = _Floating_type_traits<_Floating>;
+ using _Uint_type = typename _Traits::_Uint_type;
+
+ const _Uint_type _Uint_value = std::bit_cast<_Uint_type>(_Value);
+
+ if (_Uint_value == 0) { // zero detected; write "0" and return; _Precision is irrelevant due to zero-trimming
+ if (_First == _Last) {
+ return {_Last, errc::value_too_large};
+ }
+
+ *_First++ = '0';
+
+ return {_First, errc{}};
+ }
+
+ // C11 7.21.6.1 "The fprintf function"/5:
+ // "A negative precision argument is taken as if the precision were omitted."
+ // /8: "g,G [...] Let P equal the precision if nonzero, 6 if the precision is omitted,
+ // or 1 if the precision is zero."
+
+ // Performance note: It's possible to rewrite this for branchless codegen,
+ // but profiling will be necessary to determine whether that's faster.
+ if (_Precision < 0) {
+ _Precision = 6;
+ } else if (_Precision == 0) {
+ _Precision = 1;
+ } else if (_Precision < 1'000'000) {
+ // _Precision is ok.
+ } else {
+ // Avoid integer overflow.
+ // Due to general notation's zero-trimming behavior, we can simply clamp _Precision.
+ // This is further clamped below.
+ _Precision = 1'000'000;
+ }
+
+ // _Precision is now the Standard's P.
+
+ // /8: "Then, if a conversion with style E would have an exponent of X:
+ // - if P > X >= -4, the conversion is with style f (or F) and precision P - (X + 1).
+ // - otherwise, the conversion is with style e (or E) and precision P - 1."
+
+ // /8: "Finally, [...] any trailing zeros are removed from the fractional portion of the result
+ // and the decimal-point character is removed if there is no fractional portion remaining."
+
+ using _Tables = _General_precision_tables<_Floating>;
+
+ const _Uint_type* _Table_begin;
+ const _Uint_type* _Table_end;
+
+ if (_Precision <= _Tables::_Max_special_P) {
+ _Table_begin = _Tables::_Special_X_table + (_Precision - 1) * (_Precision + 10) / 2;
+ _Table_end = _Table_begin + _Precision + 5;
+ } else {
+ _Table_begin = _Tables::_Ordinary_X_table;
+ _Table_end = _Table_begin + std::min(_Precision, _Tables::_Max_P) + 5;
+ }
+
+ // Profiling indicates that linear search is faster than binary search for small tables.
+ // Performance note: lambda captures may have a small performance cost.
+ const _Uint_type* const _Table_lower_bound = [=] {
+ if constexpr (!_IsSame<_Floating, float>::value) {
+ if (_Precision > 155) { // threshold determined via profiling
+ return std::lower_bound(_Table_begin, _Table_end, _Uint_value, less{});
+ }
+ }
+
+ return std::find_if(_Table_begin, _Table_end, [=](const _Uint_type _Elem) { return _Uint_value <= _Elem; });
+ }();
+
+ const ptrdiff_t _Table_index = _Table_lower_bound - _Table_begin;
+ const int _Scientific_exponent_X = static_cast<int>(_Table_index - 5);
+ const bool _Use_fixed_notation = _Precision > _Scientific_exponent_X && _Scientific_exponent_X >= -4;
+
+ // Performance note: it might (or might not) be faster to modify Ryu Printf to perform zero-trimming.
+ // Such modifications would involve a fairly complicated state machine (notably, both '0' and '9' digits would
+ // need to be buffered, due to rounding), and that would have performance costs due to increased branching.
+ // Here, we're using a simpler approach: writing into a local buffer, manually zero-trimming, and then copying into
+ // the output range. The necessary buffer size is reasonably small, the zero-trimming logic is simple and fast,
+ // and the final copying is also fast.
+
+ constexpr int _Max_output_length =
+ _IsSame<_Floating, float>::value ? 117 : 773; // cases: 0x1.fffffep-126f and 0x1.fffffffffffffp-1022
+ constexpr int _Max_fixed_precision =
+ _IsSame<_Floating, float>::value ? 37 : 66; // cases: 0x1.fffffep-14f and 0x1.fffffffffffffp-14
+ constexpr int _Max_scientific_precision =
+ _IsSame<_Floating, float>::value ? 111 : 766; // cases: 0x1.fffffep-126f and 0x1.fffffffffffffp-1022
+
+ // Note that _Max_output_length is determined by scientific notation and is more than enough for fixed notation.
+ // 0x1.fffffep+127f is 39 digits, plus 1 for '.', plus _Max_fixed_precision for '0' digits, equals 77.
+ // 0x1.fffffffffffffp+1023 is 309 digits, plus 1 for '.', plus _Max_fixed_precision for '0' digits, equals 376.
+
+ char _Buffer[_Max_output_length];
+ const char* const _Significand_first = _Buffer; // e.g. "1.234"
+ const char* _Significand_last = nullptr;
+ const char* _Exponent_first = nullptr; // e.g. "e-05"
+ const char* _Exponent_last = nullptr;
+ int _Effective_precision; // number of digits printed after the decimal point, before trimming
+
+ // Write into the local buffer.
+ // Clamping _Effective_precision allows _Buffer to be as small as possible, and increases efficiency.
+ if (_Use_fixed_notation) {
+ _Effective_precision = std::min(_Precision - (_Scientific_exponent_X + 1), _Max_fixed_precision);
+ const to_chars_result _Buf_result =
+ _Floating_to_chars_fixed_precision(_Buffer, std::end(_Buffer), _Value, _Effective_precision);
+ _LIBCPP_ASSERT_INTERNAL(_Buf_result.ec == errc{}, "");
+ _Significand_last = _Buf_result.ptr;
+ } else {
+ _Effective_precision = std::min(_Precision - 1, _Max_scientific_precision);
+ const to_chars_result _Buf_result =
+ _Floating_to_chars_scientific_precision(_Buffer, std::end(_Buffer), _Value, _Effective_precision);
+ _LIBCPP_ASSERT_INTERNAL(_Buf_result.ec == errc{}, "");
+ _Significand_last = std::find(_Buffer, _Buf_result.ptr, 'e');
+ _Exponent_first = _Significand_last;
+ _Exponent_last = _Buf_result.ptr;
+ }
+
+ // If we printed a decimal point followed by digits, perform zero-trimming.
+ if (_Effective_precision > 0) {
+ while (_Significand_last[-1] == '0') { // will stop at '.' or a nonzero digit
+ --_Significand_last;
+ }
+
+ if (_Significand_last[-1] == '.') {
+ --_Significand_last;
+ }
+ }
+
+ // Copy the significand to the output range.
+ const ptrdiff_t _Significand_distance = _Significand_last - _Significand_first;
+ if (_Last - _First < _Significand_distance) {
+ return {_Last, errc::value_too_large};
+ }
+ std::memcpy(_First, _Significand_first, static_cast<size_t>(_Significand_distance));
+ _First += _Significand_distance;
+
+ // Copy the exponent to the output range.
+ if (!_Use_fixed_notation) {
+ const ptrdiff_t _Exponent_distance = _Exponent_last - _Exponent_first;
+ if (_Last - _First < _Exponent_distance) {
+ return {_Last, errc::value_too_large};
+ }
+ std::memcpy(_First, _Exponent_first, static_cast<size_t>(_Exponent_distance));
+ _First += _Exponent_distance;
+ }
+
+ return {_First, errc{}};
+}
+
+enum class _Floating_to_chars_overload { _Plain, _Format_only, _Format_precision };
+
+template <_Floating_to_chars_overload _Overload, class _Floating>
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI
+to_chars_result _Floating_to_chars(
+ char* _First, char* const _Last, _Floating _Value, const chars_format _Fmt, const int _Precision) noexcept {
+
+ if constexpr (_Overload == _Floating_to_chars_overload::_Plain) {
+ _LIBCPP_ASSERT_INTERNAL(_Fmt == chars_format{}, ""); // plain overload must pass chars_format{} internally
+ } else {
+ _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(_Fmt == chars_format::general || _Fmt == chars_format::scientific
+ || _Fmt == chars_format::fixed || _Fmt == chars_format::hex,
+ "invalid format in to_chars()");
+ }
+
+ using _Traits = _Floating_type_traits<_Floating>;
+ using _Uint_type = typename _Traits::_Uint_type;
+
+ _Uint_type _Uint_value = std::bit_cast<_Uint_type>(_Value);
+
+ const bool _Was_negative = (_Uint_value & _Traits::_Shifted_sign_mask) != 0;
+
+ if (_Was_negative) { // sign bit detected; write minus sign and clear sign bit
+ if (_First == _Last) {
+ return {_Last, errc::value_too_large};
+ }
+
+ *_First++ = '-';
+
+ _Uint_value &= ~_Traits::_Shifted_sign_mask;
+ _Value = std::bit_cast<_Floating>(_Uint_value);
+ }
+
+ if ((_Uint_value & _Traits::_Shifted_exponent_mask) == _Traits::_Shifted_exponent_mask) {
+ // inf/nan detected; write appropriate string and return
+ const char* _Str;
+ size_t _Len;
+
+ const _Uint_type _Mantissa = _Uint_value & _Traits::_Denormal_mantissa_mask;
+
+ if (_Mantissa == 0) {
+ _Str = "inf";
+ _Len = 3;
+ } else if (_Was_negative && _Mantissa == _Traits::_Special_nan_mantissa_mask) {
+ // When a NaN value has the sign bit set, the quiet bit set, and all other mantissa bits cleared,
+ // the UCRT interprets it to mean "indeterminate", and indicates this by printing "-nan(ind)".
+ _Str = "nan(ind)";
+ _Len = 8;
+ } else if ((_Mantissa & _Traits::_Special_nan_mantissa_mask) != 0) {
+ _Str = "nan";
+ _Len = 3;
+ } else {
+ _Str = "nan(snan)";
+ _Len = 9;
+ }
+
+ if (_Last - _First < static_cast<ptrdiff_t>(_Len)) {
+ return {_Last, errc::value_too_large};
+ }
+
+ std::memcpy(_First, _Str, _Len);
+
+ return {_First + _Len, errc{}};
+ }
+
+ if constexpr (_Overload == _Floating_to_chars_overload::_Plain) {
+ return _Floating_to_chars_ryu(_First, _Last, _Value, chars_format{});
+ } else if constexpr (_Overload == _Floating_to_chars_overload::_Format_only) {
+ if (_Fmt == chars_format::hex) {
+ return _Floating_to_chars_hex_shortest(_First, _Last, _Value);
+ }
+
+ return _Floating_to_chars_ryu(_First, _Last, _Value, _Fmt);
+ } else if constexpr (_Overload == _Floating_to_chars_overload::_Format_precision) {
+ switch (_Fmt) {
+ case chars_format::scientific:
+ return _Floating_to_chars_scientific_precision(_First, _Last, _Value, _Precision);
+ case chars_format::fixed:
+ return _Floating_to_chars_fixed_precision(_First, _Last, _Value, _Precision);
+ case chars_format::general:
+ return _Floating_to_chars_general_precision(_First, _Last, _Value, _Precision);
+ case chars_format::hex:
+ default: // avoid MSVC warning C4715: not all control paths return a value
+ return _Floating_to_chars_hex_precision(_First, _Last, _Value, _Precision);
+ }
+ }
+}
+
+// clang-format on
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP_SRC_INCLUDE_TO_CHARS_FLOATING_POINT_H
diff --git a/contrib/llvm-project/libcxx/src/ios.cpp b/contrib/llvm-project/libcxx/src/ios.cpp
index 3a9296465777..d58827fa1255 100644
--- a/contrib/llvm-project/libcxx/src/ios.cpp
+++ b/contrib/llvm-project/libcxx/src/ios.cpp
@@ -1,4 +1,4 @@
-//===-------------------------- ios.cpp -----------------------------------===//
+//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -6,71 +6,58 @@
//
//===----------------------------------------------------------------------===//
-#include "__config"
-
-#include "ios"
-
+#include <__config>
+#include <__locale>
+#include <algorithm>
+#include <ios>
+#include <limits>
+#include <memory>
+#include <new>
#include <stdlib.h>
+#include <string>
-#include "__locale"
-#include "algorithm"
#include "include/config_elast.h"
-#include "limits"
-#include "memory"
-#include "new"
-#include "string"
-#include "__undef_macros"
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
_LIBCPP_BEGIN_NAMESPACE_STD
-class _LIBCPP_HIDDEN __iostream_category
- : public __do_message
-{
+class _LIBCPP_HIDDEN __iostream_category : public __do_message {
public:
- virtual const char* name() const _NOEXCEPT;
- virtual string message(int ev) const;
+ virtual const char* name() const noexcept;
+ virtual string message(int ev) const;
};
-const char*
-__iostream_category::name() const _NOEXCEPT
-{
- return "iostream";
-}
+const char* __iostream_category::name() const noexcept { return "iostream"; }
-string
-__iostream_category::message(int ev) const
-{
- if (ev != static_cast<int>(io_errc::stream)
+string __iostream_category::message(int ev) const {
+ if (ev != static_cast<int>(io_errc::stream)
#ifdef _LIBCPP_ELAST
- && ev <= _LIBCPP_ELAST
-#endif // _LIBCPP_ELAST
- )
- return __do_message::message(ev);
- return string("unspecified iostream_category error");
+ && ev <= _LIBCPP_ELAST
+#endif // _LIBCPP_ELAST
+ )
+ return __do_message::message(ev);
+ return string("unspecified iostream_category error");
}
-const error_category&
-iostream_category() _NOEXCEPT
-{
- static __iostream_category s;
- return s;
+const error_category& iostream_category() noexcept {
+ 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
-ios_base::failure::failure(const string& msg, const error_code& ec)
- : system_error(ec, msg)
-{
-}
+ios_base::failure::failure(const string& msg, const error_code& ec) : system_error(ec, msg) {}
-ios_base::failure::failure(const char* msg, const error_code& ec)
- : system_error(ec, msg)
-{
-}
+ios_base::failure::failure(const char* msg, const error_code& ec) : system_error(ec, msg) {}
-ios_base::failure::~failure() throw()
-{
-}
+ios_base::failure::~failure() throw() {}
// ios_base locale
@@ -105,337 +92,292 @@ const ios_base::openmode ios_base::in;
const ios_base::openmode ios_base::out;
const ios_base::openmode ios_base::trunc;
-void
-ios_base::__call_callbacks(event ev)
-{
- for (size_t i = __event_size_; i;)
- {
- --i;
- __fn_[i](ev, *this, __index_[i]);
- }
+void ios_base::__call_callbacks(event ev) {
+ for (size_t i = __event_size_; i;) {
+ --i;
+ __fn_[i](ev, *this, __index_[i]);
+ }
}
// locale
-locale
-ios_base::imbue(const locale& newloc)
-{
- static_assert(sizeof(locale) == sizeof(__loc_), "");
- locale& loc_storage = *reinterpret_cast<locale*>(&__loc_);
- locale oldloc = loc_storage;
- loc_storage = newloc;
- __call_callbacks(imbue_event);
- return oldloc;
+locale ios_base::imbue(const locale& newloc) {
+ static_assert(sizeof(locale) == sizeof(__loc_), "");
+ locale& loc_storage = *reinterpret_cast<locale*>(&__loc_);
+ locale oldloc = loc_storage;
+ loc_storage = newloc;
+ __call_callbacks(imbue_event);
+ return oldloc;
}
-locale
-ios_base::getloc() const
-{
- const locale& loc_storage = *reinterpret_cast<const locale*>(&__loc_);
- return loc_storage;
+locale ios_base::getloc() const {
+ const locale& loc_storage = *reinterpret_cast<const locale*>(&__loc_);
+ return loc_storage;
}
// xalloc
#if defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_NO_THREADS)
-atomic<int> ios_base::__xindex_ = ATOMIC_VAR_INIT(0);
+atomic<int> ios_base::__xindex_{0};
#else
int ios_base::__xindex_ = 0;
#endif
template <typename _Tp>
-static size_t __ios_new_cap(size_t __req_size, size_t __current_cap)
-{ // Precondition: __req_size > __current_cap
- const size_t mx = std::numeric_limits<size_t>::max() / sizeof(_Tp);
- if (__req_size < mx/2)
- return _VSTD::max(2 * __current_cap, __req_size);
- else
- return mx;
-}
-
-int
-ios_base::xalloc()
-{
- return __xindex_++;
+static size_t __ios_new_cap(size_t __req_size, size_t __current_cap) { // Precondition: __req_size > __current_cap
+ const size_t mx = std::numeric_limits<size_t>::max() / sizeof(_Tp);
+ if (__req_size < mx / 2)
+ return std::max(2 * __current_cap, __req_size);
+ else
+ return mx;
}
-long&
-ios_base::iword(int index)
-{
- size_t req_size = static_cast<size_t>(index)+1;
- if (req_size > __iarray_cap_)
- {
- size_t newcap = __ios_new_cap<long>(req_size, __iarray_cap_);
- long* iarray = static_cast<long*>(realloc(__iarray_, newcap * sizeof(long)));
- if (iarray == 0)
- {
- setstate(badbit);
- static long error;
- error = 0;
- return error;
- }
- __iarray_ = iarray;
- for (long* p = __iarray_ + __iarray_size_; p < __iarray_ + newcap; ++p)
- *p = 0;
- __iarray_cap_ = newcap;
+int ios_base::xalloc() { return __xindex_++; }
+
+long& ios_base::iword(int index) {
+ size_t req_size = static_cast<size_t>(index) + 1;
+ if (req_size > __iarray_cap_) {
+ size_t newcap = __ios_new_cap<long>(req_size, __iarray_cap_);
+ long* iarray = static_cast<long*>(realloc(__iarray_, newcap * sizeof(long)));
+ if (iarray == 0) {
+ setstate(badbit);
+ static long error;
+ error = 0;
+ return error;
}
- __iarray_size_ = max<size_t>(__iarray_size_, req_size);
- return __iarray_[index];
+ __iarray_ = iarray;
+ for (long* p = __iarray_ + __iarray_size_; p < __iarray_ + newcap; ++p)
+ *p = 0;
+ __iarray_cap_ = newcap;
+ }
+ __iarray_size_ = max<size_t>(__iarray_size_, req_size);
+ return __iarray_[index];
}
-void*&
-ios_base::pword(int index)
-{
- size_t req_size = static_cast<size_t>(index)+1;
- if (req_size > __parray_cap_)
- {
- size_t newcap = __ios_new_cap<void *>(req_size, __iarray_cap_);
- void** parray = static_cast<void**>(realloc(__parray_, newcap * sizeof(void *)));
- if (parray == 0)
- {
- setstate(badbit);
- static void* error;
- error = 0;
- return error;
- }
- __parray_ = parray;
- for (void** p = __parray_ + __parray_size_; p < __parray_ + newcap; ++p)
- *p = 0;
- __parray_cap_ = newcap;
+void*& ios_base::pword(int index) {
+ size_t req_size = static_cast<size_t>(index) + 1;
+ if (req_size > __parray_cap_) {
+ size_t newcap = __ios_new_cap<void*>(req_size, __iarray_cap_);
+ void** parray = static_cast<void**>(realloc(__parray_, newcap * sizeof(void*)));
+ if (parray == 0) {
+ setstate(badbit);
+ static void* error;
+ error = 0;
+ return error;
}
- __parray_size_ = max<size_t>(__parray_size_, req_size);
- return __parray_[index];
+ __parray_ = parray;
+ for (void** p = __parray_ + __parray_size_; p < __parray_ + newcap; ++p)
+ *p = 0;
+ __parray_cap_ = newcap;
+ }
+ __parray_size_ = max<size_t>(__parray_size_, req_size);
+ return __parray_[index];
}
// register_callback
-void
-ios_base::register_callback(event_callback fn, int index)
-{
- size_t req_size = __event_size_ + 1;
- if (req_size > __event_cap_)
- {
- size_t newcap = __ios_new_cap<event_callback>(req_size, __event_cap_);
- event_callback* fns = static_cast<event_callback*>(realloc(__fn_, newcap * sizeof(event_callback)));
- if (fns == 0)
- setstate(badbit);
- __fn_ = fns;
- int* indxs = static_cast<int *>(realloc(__index_, newcap * sizeof(int)));
- if (indxs == 0)
- setstate(badbit);
- __index_ = indxs;
- __event_cap_ = newcap;
- }
- __fn_[__event_size_] = fn;
- __index_[__event_size_] = index;
- ++__event_size_;
+void ios_base::register_callback(event_callback fn, int index) {
+ size_t req_size = __event_size_ + 1;
+ if (req_size > __event_cap_) {
+ size_t newcap = __ios_new_cap<event_callback>(req_size, __event_cap_);
+ event_callback* fns = static_cast<event_callback*>(realloc(__fn_, newcap * sizeof(event_callback)));
+ if (fns == 0)
+ setstate(badbit);
+ __fn_ = fns;
+ int* indxs = static_cast<int*>(realloc(__index_, newcap * sizeof(int)));
+ if (indxs == 0)
+ setstate(badbit);
+ __index_ = indxs;
+ __event_cap_ = newcap;
+ }
+ __fn_[__event_size_] = fn;
+ __index_[__event_size_] = index;
+ ++__event_size_;
}
-ios_base::~ios_base()
-{
- __call_callbacks(erase_event);
- locale& loc_storage = *reinterpret_cast<locale*>(&__loc_);
- loc_storage.~locale();
- free(__fn_);
- free(__index_);
- free(__iarray_);
- free(__parray_);
+ios_base::~ios_base() {
+ __call_callbacks(erase_event);
+ locale& loc_storage = *reinterpret_cast<locale*>(&__loc_);
+ loc_storage.~locale();
+ free(__fn_);
+ free(__index_);
+ free(__iarray_);
+ free(__parray_);
}
// iostate
-void
-ios_base::clear(iostate state)
-{
- if (__rdbuf_)
- __rdstate_ = state;
- else
- __rdstate_ = state | badbit;
+void ios_base::clear(iostate state) {
+ if (__rdbuf_)
+ __rdstate_ = state;
+ else
+ __rdstate_ = state | badbit;
- if (((state | (__rdbuf_ ? goodbit : badbit)) & __exceptions_) != 0)
- __throw_failure("ios_base::clear");
+ if (((state | (__rdbuf_ ? goodbit : badbit)) & __exceptions_) != 0)
+ __throw_failure("ios_base::clear");
}
// init
-void
-ios_base::init(void* sb)
-{
- __rdbuf_ = sb;
- __rdstate_ = __rdbuf_ ? goodbit : badbit;
- __exceptions_ = goodbit;
- __fmtflags_ = skipws | dec;
- __width_ = 0;
- __precision_ = 6;
- __fn_ = 0;
- __index_ = 0;
- __event_size_ = 0;
- __event_cap_ = 0;
- __iarray_ = 0;
- __iarray_size_ = 0;
- __iarray_cap_ = 0;
- __parray_ = 0;
- __parray_size_ = 0;
- __parray_cap_ = 0;
- ::new(&__loc_) locale;
+void ios_base::init(void* sb) {
+ __rdbuf_ = sb;
+ __rdstate_ = __rdbuf_ ? goodbit : badbit;
+ __exceptions_ = goodbit;
+ __fmtflags_ = skipws | dec;
+ __width_ = 0;
+ __precision_ = 6;
+ __fn_ = 0;
+ __index_ = 0;
+ __event_size_ = 0;
+ __event_cap_ = 0;
+ __iarray_ = 0;
+ __iarray_size_ = 0;
+ __iarray_cap_ = 0;
+ __parray_ = 0;
+ __parray_size_ = 0;
+ __parray_cap_ = 0;
+ ::new (&__loc_) locale;
}
-void
-ios_base::copyfmt(const ios_base& rhs)
-{
- // If we can't acquire the needed resources, throw bad_alloc (can't set badbit)
- // Don't alter *this until all needed resources are acquired
- unique_ptr<event_callback, void (*)(void*)> new_callbacks(0, free);
- unique_ptr<int, void (*)(void*)> new_ints(0, free);
- unique_ptr<long, void (*)(void*)> new_longs(0, free);
- unique_ptr<void*, void (*)(void*)> new_pointers(0, free);
- if (__event_cap_ < rhs.__event_size_)
- {
- size_t newesize = sizeof(event_callback) * rhs.__event_size_;
- new_callbacks.reset(static_cast<event_callback*>(malloc(newesize)));
- if (!new_callbacks)
- __throw_bad_alloc();
-
- size_t newisize = sizeof(int) * rhs.__event_size_;
- new_ints.reset(static_cast<int *>(malloc(newisize)));
- if (!new_ints)
- __throw_bad_alloc();
- }
- if (__iarray_cap_ < rhs.__iarray_size_)
- {
- size_t newsize = sizeof(long) * rhs.__iarray_size_;
- new_longs.reset(static_cast<long*>(malloc(newsize)));
- if (!new_longs)
- __throw_bad_alloc();
- }
- if (__parray_cap_ < rhs.__parray_size_)
- {
- size_t newsize = sizeof(void*) * rhs.__parray_size_;
- new_pointers.reset(static_cast<void**>(malloc(newsize)));
- if (!new_pointers)
- __throw_bad_alloc();
- }
- // Got everything we need. Copy everything but __rdstate_, __rdbuf_ and __exceptions_
- __fmtflags_ = rhs.__fmtflags_;
- __precision_ = rhs.__precision_;
- __width_ = rhs.__width_;
- locale& lhs_loc = *reinterpret_cast<locale*>(&__loc_);
- const locale& rhs_loc = *reinterpret_cast<const locale*>(&rhs.__loc_);
- lhs_loc = rhs_loc;
- if (__event_cap_ < rhs.__event_size_)
- {
- free(__fn_);
- __fn_ = new_callbacks.release();
- free(__index_);
- __index_ = new_ints.release();
- __event_cap_ = rhs.__event_size_;
- }
- for (__event_size_ = 0; __event_size_ < rhs.__event_size_; ++__event_size_)
- {
- __fn_[__event_size_] = rhs.__fn_[__event_size_];
- __index_[__event_size_] = rhs.__index_[__event_size_];
- }
- if (__iarray_cap_ < rhs.__iarray_size_)
- {
- free(__iarray_);
- __iarray_ = new_longs.release();
- __iarray_cap_ = rhs.__iarray_size_;
- }
- for (__iarray_size_ = 0; __iarray_size_ < rhs.__iarray_size_; ++__iarray_size_)
- __iarray_[__iarray_size_] = rhs.__iarray_[__iarray_size_];
- if (__parray_cap_ < rhs.__parray_size_)
- {
- free(__parray_);
- __parray_ = new_pointers.release();
- __parray_cap_ = rhs.__parray_size_;
- }
- for (__parray_size_ = 0; __parray_size_ < rhs.__parray_size_; ++__parray_size_)
- __parray_[__parray_size_] = rhs.__parray_[__parray_size_];
+void ios_base::copyfmt(const ios_base& rhs) {
+ // If we can't acquire the needed resources, throw bad_alloc (can't set badbit)
+ // Don't alter *this until all needed resources are acquired
+ unique_ptr<event_callback, void (*)(void*)> new_callbacks(0, free);
+ unique_ptr<int, void (*)(void*)> new_ints(0, free);
+ unique_ptr<long, void (*)(void*)> new_longs(0, free);
+ unique_ptr<void*, void (*)(void*)> new_pointers(0, free);
+ if (__event_cap_ < rhs.__event_size_) {
+ size_t newesize = sizeof(event_callback) * rhs.__event_size_;
+ new_callbacks.reset(static_cast<event_callback*>(malloc(newesize)));
+ if (!new_callbacks)
+ __throw_bad_alloc();
+
+ size_t newisize = sizeof(int) * rhs.__event_size_;
+ new_ints.reset(static_cast<int*>(malloc(newisize)));
+ if (!new_ints)
+ __throw_bad_alloc();
+ }
+ if (__iarray_cap_ < rhs.__iarray_size_) {
+ size_t newsize = sizeof(long) * rhs.__iarray_size_;
+ new_longs.reset(static_cast<long*>(malloc(newsize)));
+ if (!new_longs)
+ __throw_bad_alloc();
+ }
+ if (__parray_cap_ < rhs.__parray_size_) {
+ size_t newsize = sizeof(void*) * rhs.__parray_size_;
+ new_pointers.reset(static_cast<void**>(malloc(newsize)));
+ if (!new_pointers)
+ __throw_bad_alloc();
+ }
+ // Got everything we need. Copy everything but __rdstate_, __rdbuf_ and __exceptions_
+ __fmtflags_ = rhs.__fmtflags_;
+ __precision_ = rhs.__precision_;
+ __width_ = rhs.__width_;
+ locale& lhs_loc = *reinterpret_cast<locale*>(&__loc_);
+ const locale& rhs_loc = *reinterpret_cast<const locale*>(&rhs.__loc_);
+ lhs_loc = rhs_loc;
+ if (__event_cap_ < rhs.__event_size_) {
+ free(__fn_);
+ __fn_ = new_callbacks.release();
+ free(__index_);
+ __index_ = new_ints.release();
+ __event_cap_ = rhs.__event_size_;
+ }
+ for (__event_size_ = 0; __event_size_ < rhs.__event_size_; ++__event_size_) {
+ __fn_[__event_size_] = rhs.__fn_[__event_size_];
+ __index_[__event_size_] = rhs.__index_[__event_size_];
+ }
+ if (__iarray_cap_ < rhs.__iarray_size_) {
+ free(__iarray_);
+ __iarray_ = new_longs.release();
+ __iarray_cap_ = rhs.__iarray_size_;
+ }
+ for (__iarray_size_ = 0; __iarray_size_ < rhs.__iarray_size_; ++__iarray_size_)
+ __iarray_[__iarray_size_] = rhs.__iarray_[__iarray_size_];
+ if (__parray_cap_ < rhs.__parray_size_) {
+ free(__parray_);
+ __parray_ = new_pointers.release();
+ __parray_cap_ = rhs.__parray_size_;
+ }
+ for (__parray_size_ = 0; __parray_size_ < rhs.__parray_size_; ++__parray_size_)
+ __parray_[__parray_size_] = rhs.__parray_[__parray_size_];
}
-void
-ios_base::move(ios_base& rhs)
-{
- // *this is uninitialized
- __fmtflags_ = rhs.__fmtflags_;
- __precision_ = rhs.__precision_;
- __width_ = rhs.__width_;
- __rdstate_ = rhs.__rdstate_;
- __exceptions_ = rhs.__exceptions_;
- __rdbuf_ = 0;
- locale& rhs_loc = *reinterpret_cast<locale*>(&rhs.__loc_);
- ::new(&__loc_) locale(rhs_loc);
- __fn_ = rhs.__fn_;
- rhs.__fn_ = 0;
- __index_ = rhs.__index_;
- rhs.__index_ = 0;
- __event_size_ = rhs.__event_size_;
- rhs.__event_size_ = 0;
- __event_cap_ = rhs.__event_cap_;
- rhs.__event_cap_ = 0;
- __iarray_ = rhs.__iarray_;
- rhs.__iarray_ = 0;
- __iarray_size_ = rhs.__iarray_size_;
- rhs.__iarray_size_ = 0;
- __iarray_cap_ = rhs.__iarray_cap_;
- rhs.__iarray_cap_ = 0;
- __parray_ = rhs.__parray_;
- rhs.__parray_ = 0;
- __parray_size_ = rhs.__parray_size_;
- rhs.__parray_size_ = 0;
- __parray_cap_ = rhs.__parray_cap_;
- rhs.__parray_cap_ = 0;
+void ios_base::move(ios_base& rhs) {
+ // *this is uninitialized
+ __fmtflags_ = rhs.__fmtflags_;
+ __precision_ = rhs.__precision_;
+ __width_ = rhs.__width_;
+ __rdstate_ = rhs.__rdstate_;
+ __exceptions_ = rhs.__exceptions_;
+ __rdbuf_ = 0;
+ locale& rhs_loc = *reinterpret_cast<locale*>(&rhs.__loc_);
+ ::new (&__loc_) locale(rhs_loc);
+ __fn_ = rhs.__fn_;
+ rhs.__fn_ = 0;
+ __index_ = rhs.__index_;
+ rhs.__index_ = 0;
+ __event_size_ = rhs.__event_size_;
+ rhs.__event_size_ = 0;
+ __event_cap_ = rhs.__event_cap_;
+ rhs.__event_cap_ = 0;
+ __iarray_ = rhs.__iarray_;
+ rhs.__iarray_ = 0;
+ __iarray_size_ = rhs.__iarray_size_;
+ rhs.__iarray_size_ = 0;
+ __iarray_cap_ = rhs.__iarray_cap_;
+ rhs.__iarray_cap_ = 0;
+ __parray_ = rhs.__parray_;
+ rhs.__parray_ = 0;
+ __parray_size_ = rhs.__parray_size_;
+ rhs.__parray_size_ = 0;
+ __parray_cap_ = rhs.__parray_cap_;
+ rhs.__parray_cap_ = 0;
}
-void
-ios_base::swap(ios_base& rhs) _NOEXCEPT
-{
- _VSTD::swap(__fmtflags_, rhs.__fmtflags_);
- _VSTD::swap(__precision_, rhs.__precision_);
- _VSTD::swap(__width_, rhs.__width_);
- _VSTD::swap(__rdstate_, rhs.__rdstate_);
- _VSTD::swap(__exceptions_, rhs.__exceptions_);
- locale& lhs_loc = *reinterpret_cast<locale*>(&__loc_);
- locale& rhs_loc = *reinterpret_cast<locale*>(&rhs.__loc_);
- _VSTD::swap(lhs_loc, rhs_loc);
- _VSTD::swap(__fn_, rhs.__fn_);
- _VSTD::swap(__index_, rhs.__index_);
- _VSTD::swap(__event_size_, rhs.__event_size_);
- _VSTD::swap(__event_cap_, rhs.__event_cap_);
- _VSTD::swap(__iarray_, rhs.__iarray_);
- _VSTD::swap(__iarray_size_, rhs.__iarray_size_);
- _VSTD::swap(__iarray_cap_, rhs.__iarray_cap_);
- _VSTD::swap(__parray_, rhs.__parray_);
- _VSTD::swap(__parray_size_, rhs.__parray_size_);
- _VSTD::swap(__parray_cap_, rhs.__parray_cap_);
+void ios_base::swap(ios_base& rhs) noexcept {
+ std::swap(__fmtflags_, rhs.__fmtflags_);
+ std::swap(__precision_, rhs.__precision_);
+ std::swap(__width_, rhs.__width_);
+ std::swap(__rdstate_, rhs.__rdstate_);
+ std::swap(__exceptions_, rhs.__exceptions_);
+ locale& lhs_loc = *reinterpret_cast<locale*>(&__loc_);
+ locale& rhs_loc = *reinterpret_cast<locale*>(&rhs.__loc_);
+ std::swap(lhs_loc, rhs_loc);
+ std::swap(__fn_, rhs.__fn_);
+ std::swap(__index_, rhs.__index_);
+ std::swap(__event_size_, rhs.__event_size_);
+ std::swap(__event_cap_, rhs.__event_cap_);
+ std::swap(__iarray_, rhs.__iarray_);
+ std::swap(__iarray_size_, rhs.__iarray_size_);
+ std::swap(__iarray_cap_, rhs.__iarray_cap_);
+ std::swap(__parray_, rhs.__parray_);
+ std::swap(__parray_size_, rhs.__parray_size_);
+ std::swap(__parray_cap_, rhs.__parray_cap_);
}
-void
-ios_base::__set_badbit_and_consider_rethrow()
-{
- __rdstate_ |= badbit;
-#ifndef _LIBCPP_NO_EXCEPTIONS
- if (__exceptions_ & badbit)
- throw;
-#endif // _LIBCPP_NO_EXCEPTIONS
+void ios_base::__set_badbit_and_consider_rethrow() {
+ __rdstate_ |= badbit;
+#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
+ if (__exceptions_ & badbit)
+ throw;
+#endif // _LIBCPP_HAS_NO_EXCEPTIONS
}
-void
-ios_base::__set_failbit_and_consider_rethrow()
-{
- __rdstate_ |= failbit;
-#ifndef _LIBCPP_NO_EXCEPTIONS
- if (__exceptions_ & failbit)
- throw;
-#endif // _LIBCPP_NO_EXCEPTIONS
+void ios_base::__set_failbit_and_consider_rethrow() {
+ __rdstate_ |= failbit;
+#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
+ if (__exceptions_ & failbit)
+ throw;
+#endif // _LIBCPP_HAS_NO_EXCEPTIONS
}
-bool
-ios_base::sync_with_stdio(bool sync)
-{
- static bool previous_state = true;
- bool r = previous_state;
- previous_state = sync;
- return r;
+bool ios_base::sync_with_stdio(bool sync) {
+ static bool previous_state = true;
+ bool r = previous_state;
+ previous_state = sync;
+ return r;
}
_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
diff --git a/contrib/llvm-project/libcxx/src/ios.instantiations.cpp b/contrib/llvm-project/libcxx/src/ios.instantiations.cpp
index 1a23687d128d..aac7a68684ce 100644
--- a/contrib/llvm-project/libcxx/src/ios.instantiations.cpp
+++ b/contrib/llvm-project/libcxx/src/ios.instantiations.cpp
@@ -6,37 +6,42 @@
//
//===----------------------------------------------------------------------===//
-#include "__config"
-#include "fstream"
-#include "ios"
-#include "istream"
-#include "ostream"
-#include "sstream"
-#include "streambuf"
-
+#include <__config>
+#include <fstream>
+#include <ios>
+#include <istream>
+#include <ostream>
+#include <sstream>
+#include <streambuf>
_LIBCPP_BEGIN_NAMESPACE_STD
// Original explicit instantiations provided in the library
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_ios<char>;
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_ios<wchar_t>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_streambuf<char>;
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_streambuf<wchar_t>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_istream<char>;
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_istream<wchar_t>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_ostream<char>;
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_ostream<wchar_t>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_iostream<char>;
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_ios<wchar_t>;
+template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_streambuf<wchar_t>;
+template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_istream<wchar_t>;
+template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_ostream<wchar_t>;
+#endif
+
// Additional instantiations added later. Whether programs rely on these being
-// available is protected by _LIBCPP_ABI_ENABLE_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1.
+// available is protected by _LIBCPP_AVAILABILITY_HAS_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1.
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_stringbuf<char>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_stringstream<char>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_ostringstream<char>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_istringstream<char>;
+
+#ifndef _LIBCPP_HAS_NO_FILESYSTEM
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_ifstream<char>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_ofstream<char>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_filebuf<char>;
+#endif
// Add more here if needed...
diff --git a/contrib/llvm-project/libcxx/src/iostream.cpp b/contrib/llvm-project/libcxx/src/iostream.cpp
index ea95534c7667..bb49e265ba0e 100644
--- a/contrib/llvm-project/libcxx/src/iostream.cpp
+++ b/contrib/llvm-project/libcxx/src/iostream.cpp
@@ -1,4 +1,4 @@
-//===------------------------ iostream.cpp --------------------------------===//
+//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -6,10 +6,14 @@
//
//===----------------------------------------------------------------------===//
-#include "__std_stream"
-#include "__locale"
-#include "string"
-#include "new"
+#include "std_stream.h"
+#include <__locale>
+#include <new>
+#include <string>
+
+#ifdef _LIBCPP_MSVCRT_LIKE
+# include <__locale_dir/locale_base_api/locale_guard.h>
+#endif
#define _str(s) #s
#define str(s) _str(s)
@@ -17,67 +21,93 @@
_LIBCPP_BEGIN_NAMESPACE_STD
-#ifndef _LIBCPP_HAS_NO_STDIN
-_ALIGNAS_TYPE (istream) _LIBCPP_FUNC_VIS char cin[sizeof(istream)]
+_ALIGNAS_TYPE(istream)
+_LIBCPP_EXPORTED_FROM_ABI char cin[sizeof(istream)]
#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
-__asm__("?cin@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_istream@DU?$char_traits@D@" _LIBCPP_ABI_NAMESPACE_STR "@std@@@12@A")
+ __asm__("?cin@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_istream@DU?$char_traits@D@" _LIBCPP_ABI_NAMESPACE_STR
+ "@std@@@12@A")
#endif
-;
-_ALIGNAS_TYPE (__stdinbuf<char> ) static char __cin[sizeof(__stdinbuf <char>)];
+ ;
+_ALIGNAS_TYPE(__stdinbuf<char>) static char __cin[sizeof(__stdinbuf<char>)];
static mbstate_t mb_cin;
-_ALIGNAS_TYPE (wistream) _LIBCPP_FUNC_VIS char wcin[sizeof(wistream)]
-#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
-__asm__("?wcin@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_istream@_WU?$char_traits@_W@" _LIBCPP_ABI_NAMESPACE_STR "@std@@@12@A")
-#endif
-;
-_ALIGNAS_TYPE (__stdinbuf<wchar_t> ) static char __wcin[sizeof(__stdinbuf <wchar_t>)];
+
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+_ALIGNAS_TYPE(wistream)
+_LIBCPP_EXPORTED_FROM_ABI char wcin[sizeof(wistream)]
+# if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
+ __asm__("?wcin@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_istream@_WU?$char_traits@_W@" _LIBCPP_ABI_NAMESPACE_STR
+ "@std@@@12@A")
+# endif
+ ;
+_ALIGNAS_TYPE(__stdinbuf<wchar_t>) static char __wcin[sizeof(__stdinbuf<wchar_t>)];
static mbstate_t mb_wcin;
-#endif
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
-#ifndef _LIBCPP_HAS_NO_STDOUT
-_ALIGNAS_TYPE (ostream) _LIBCPP_FUNC_VIS char cout[sizeof(ostream)]
+_ALIGNAS_TYPE(ostream)
+_LIBCPP_EXPORTED_FROM_ABI char cout[sizeof(ostream)]
#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
-__asm__("?cout@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@DU?$char_traits@D@" _LIBCPP_ABI_NAMESPACE_STR "@std@@@12@A")
+ __asm__("?cout@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@DU?$char_traits@D@" _LIBCPP_ABI_NAMESPACE_STR
+ "@std@@@12@A")
#endif
-;
-_ALIGNAS_TYPE (__stdoutbuf<char>) static char __cout[sizeof(__stdoutbuf<char>)];
+ ;
+_ALIGNAS_TYPE(__stdoutbuf<char>) static char __cout[sizeof(__stdoutbuf<char>)];
static mbstate_t mb_cout;
-_ALIGNAS_TYPE (wostream) _LIBCPP_FUNC_VIS char wcout[sizeof(wostream)]
-#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
-__asm__("?wcout@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@_WU?$char_traits@_W@" _LIBCPP_ABI_NAMESPACE_STR "@std@@@12@A")
-#endif
-;
-_ALIGNAS_TYPE (__stdoutbuf<wchar_t>) static char __wcout[sizeof(__stdoutbuf<wchar_t>)];
+
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+_ALIGNAS_TYPE(wostream)
+_LIBCPP_EXPORTED_FROM_ABI char wcout[sizeof(wostream)]
+# if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
+ __asm__("?wcout@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@_WU?$char_traits@_W@" _LIBCPP_ABI_NAMESPACE_STR
+ "@std@@@12@A")
+# endif
+ ;
+_ALIGNAS_TYPE(__stdoutbuf<wchar_t>) static char __wcout[sizeof(__stdoutbuf<wchar_t>)];
static mbstate_t mb_wcout;
-#endif
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
-_ALIGNAS_TYPE (ostream) _LIBCPP_FUNC_VIS char cerr[sizeof(ostream)]
+_ALIGNAS_TYPE(ostream)
+_LIBCPP_EXPORTED_FROM_ABI char cerr[sizeof(ostream)]
#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
-__asm__("?cerr@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@DU?$char_traits@D@" _LIBCPP_ABI_NAMESPACE_STR "@std@@@12@A")
+ __asm__("?cerr@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@DU?$char_traits@D@" _LIBCPP_ABI_NAMESPACE_STR
+ "@std@@@12@A")
#endif
-;
-_ALIGNAS_TYPE (__stdoutbuf<char>) static char __cerr[sizeof(__stdoutbuf<char>)];
+ ;
+_ALIGNAS_TYPE(__stdoutbuf<char>) static char __cerr[sizeof(__stdoutbuf<char>)];
static mbstate_t mb_cerr;
-_ALIGNAS_TYPE (wostream) _LIBCPP_FUNC_VIS char wcerr[sizeof(wostream)]
-#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
-__asm__("?wcerr@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@_WU?$char_traits@_W@" _LIBCPP_ABI_NAMESPACE_STR "@std@@@12@A")
-#endif
-;
-_ALIGNAS_TYPE (__stdoutbuf<wchar_t>) static char __wcerr[sizeof(__stdoutbuf<wchar_t>)];
+
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+_ALIGNAS_TYPE(wostream)
+_LIBCPP_EXPORTED_FROM_ABI char wcerr[sizeof(wostream)]
+# if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
+ __asm__("?wcerr@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@_WU?$char_traits@_W@" _LIBCPP_ABI_NAMESPACE_STR
+ "@std@@@12@A")
+# endif
+ ;
+_ALIGNAS_TYPE(__stdoutbuf<wchar_t>) static char __wcerr[sizeof(__stdoutbuf<wchar_t>)];
static mbstate_t mb_wcerr;
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
-_ALIGNAS_TYPE (ostream) _LIBCPP_FUNC_VIS char clog[sizeof(ostream)]
-#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
-__asm__("?clog@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@DU?$char_traits@D@" _LIBCPP_ABI_NAMESPACE_STR "@std@@@12@A")
-#endif
-;
-_ALIGNAS_TYPE (wostream) _LIBCPP_FUNC_VIS char wclog[sizeof(wostream)]
+_ALIGNAS_TYPE(ostream)
+_LIBCPP_EXPORTED_FROM_ABI char clog[sizeof(ostream)]
#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
-__asm__("?wclog@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@_WU?$char_traits@_W@" _LIBCPP_ABI_NAMESPACE_STR "@std@@@12@A")
+ __asm__("?clog@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@DU?$char_traits@D@" _LIBCPP_ABI_NAMESPACE_STR
+ "@std@@@12@A")
#endif
-;
+ ;
-_LIBCPP_HIDDEN ios_base::Init __start_std_streams _LIBCPP_INIT_PRIORITY_MAX;
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+_ALIGNAS_TYPE(wostream)
+_LIBCPP_EXPORTED_FROM_ABI char wclog[sizeof(wostream)]
+# if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
+ __asm__("?wclog@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@_WU?$char_traits@_W@" _LIBCPP_ABI_NAMESPACE_STR
+ "@std@@@12@A")
+# endif
+ ;
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
+
+// Pretend we're inside a system header so the compiler doesn't flag the use of the init_priority
+// attribute with a value that's reserved for the implementation (we're the implementation).
+#include "iostream_init.h"
// On Windows the TLS storage for locales needs to be initialized before we create
// the standard streams, otherwise it may not be alive during program termination
@@ -87,8 +117,8 @@ static void force_locale_initialization() {
static bool once = []() {
auto loc = newlocale(LC_ALL_MASK, "C", 0);
{
- __libcpp_locale_guard g(loc); // forces initialization of locale TLS
- ((void)g);
+ __libcpp_locale_guard g(loc); // forces initialization of locale TLS
+ ((void)g);
}
freelocale(loc);
return true;
@@ -99,61 +129,51 @@ static void force_locale_initialization() {
class DoIOSInit {
public:
- DoIOSInit();
- ~DoIOSInit();
+ DoIOSInit();
+ ~DoIOSInit();
};
-DoIOSInit::DoIOSInit()
-{
- force_locale_initialization();
+DoIOSInit::DoIOSInit() {
+ force_locale_initialization();
-#ifndef _LIBCPP_HAS_NO_STDIN
- istream* cin_ptr = ::new(cin) istream(::new(__cin) __stdinbuf <char>(stdin, &mb_cin));
- wistream* wcin_ptr = ::new(wcin) wistream(::new(__wcin) __stdinbuf <wchar_t>(stdin, &mb_wcin));
-#endif
-#ifndef _LIBCPP_HAS_NO_STDOUT
- ostream* cout_ptr = ::new(cout) ostream(::new(__cout) __stdoutbuf<char>(stdout, &mb_cout));
- wostream* wcout_ptr = ::new(wcout) wostream(::new(__wcout) __stdoutbuf<wchar_t>(stdout, &mb_wcout));
-#endif
- ostream* cerr_ptr = ::new(cerr) ostream(::new(__cerr) __stdoutbuf<char>(stderr, &mb_cerr));
- ::new(clog) ostream(cerr_ptr->rdbuf());
- wostream* wcerr_ptr = ::new(wcerr) wostream(::new(__wcerr) __stdoutbuf<wchar_t>(stderr, &mb_wcerr));
- ::new(wclog) wostream(wcerr_ptr->rdbuf());
-
-#if !defined(_LIBCPP_HAS_NO_STDIN) && !defined(_LIBCPP_HAS_NO_STDOUT)
- cin_ptr->tie(cout_ptr);
- wcin_ptr->tie(wcout_ptr);
-#endif
- _VSTD::unitbuf(*cerr_ptr);
- _VSTD::unitbuf(*wcerr_ptr);
-#ifndef _LIBCPP_HAS_NO_STDOUT
- cerr_ptr->tie(cout_ptr);
- wcerr_ptr->tie(wcout_ptr);
+ istream* cin_ptr = ::new (cin) istream(::new (__cin) __stdinbuf<char>(stdin, &mb_cin));
+ ostream* cout_ptr = ::new (cout) ostream(::new (__cout) __stdoutbuf<char>(stdout, &mb_cout));
+ ostream* cerr_ptr = ::new (cerr) ostream(::new (__cerr) __stdoutbuf<char>(stderr, &mb_cerr));
+ ::new (clog) ostream(cerr_ptr->rdbuf());
+ cin_ptr->tie(cout_ptr);
+ std::unitbuf(*cerr_ptr);
+ cerr_ptr->tie(cout_ptr);
+
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+ wistream* wcin_ptr = ::new (wcin) wistream(::new (__wcin) __stdinbuf<wchar_t>(stdin, &mb_wcin));
+ wostream* wcout_ptr = ::new (wcout) wostream(::new (__wcout) __stdoutbuf<wchar_t>(stdout, &mb_wcout));
+ wostream* wcerr_ptr = ::new (wcerr) wostream(::new (__wcerr) __stdoutbuf<wchar_t>(stderr, &mb_wcerr));
+ ::new (wclog) wostream(wcerr_ptr->rdbuf());
+
+ wcin_ptr->tie(wcout_ptr);
+ std::unitbuf(*wcerr_ptr);
+ wcerr_ptr->tie(wcout_ptr);
#endif
}
-DoIOSInit::~DoIOSInit()
-{
-#ifndef _LIBCPP_HAS_NO_STDOUT
- ostream* cout_ptr = reinterpret_cast<ostream*>(cout);
- wostream* wcout_ptr = reinterpret_cast<wostream*>(wcout);
- cout_ptr->flush();
- wcout_ptr->flush();
-#endif
+DoIOSInit::~DoIOSInit() {
+ ostream* cout_ptr = reinterpret_cast<ostream*>(cout);
+ cout_ptr->flush();
+ ostream* clog_ptr = reinterpret_cast<ostream*>(clog);
+ clog_ptr->flush();
- ostream* clog_ptr = reinterpret_cast<ostream*>(clog);
- wostream* wclog_ptr = reinterpret_cast<wostream*>(wclog);
- clog_ptr->flush();
- wclog_ptr->flush();
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+ wostream* wcout_ptr = reinterpret_cast<wostream*>(wcout);
+ wcout_ptr->flush();
+ wostream* wclog_ptr = reinterpret_cast<wostream*>(wclog);
+ wclog_ptr->flush();
+#endif
}
-ios_base::Init::Init()
-{
- static DoIOSInit init_the_streams; // gets initialized once
+ios_base::Init::Init() {
+ static DoIOSInit init_the_streams; // gets initialized once
}
-ios_base::Init::~Init()
-{
-}
+ios_base::Init::~Init() {}
_LIBCPP_END_NAMESPACE_STD
diff --git a/contrib/llvm-project/libcxx/src/iostream_init.h b/contrib/llvm-project/libcxx/src/iostream_init.h
new file mode 100644
index 000000000000..7d1bb5c2d7d8
--- /dev/null
+++ b/contrib/llvm-project/libcxx/src/iostream_init.h
@@ -0,0 +1,2 @@
+#pragma GCC system_header
+_LIBCPP_HIDDEN ios_base::Init __start_std_streams _LIBCPP_INIT_PRIORITY_MAX;
diff --git a/contrib/llvm-project/libcxx/src/legacy_pointer_safety.cpp b/contrib/llvm-project/libcxx/src/legacy_pointer_safety.cpp
new file mode 100644
index 000000000000..a9361ca879bb
--- /dev/null
+++ b/contrib/llvm-project/libcxx/src/legacy_pointer_safety.cpp
@@ -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
+//
+//===----------------------------------------------------------------------===//
+
+#include <__config>
+#include <memory>
+
+// Support for garbage collection was removed in C++23 by https://wg21.link/P2186R2. Libc++ implements
+// that removal as an extension in all Standard versions. However, we still define the functions that
+// were once part of the library's ABI for backwards compatibility.
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+_LIBCPP_EXPORTED_FROM_ABI void declare_reachable(void*) {}
+_LIBCPP_EXPORTED_FROM_ABI void declare_no_pointers(char*, size_t) {}
+_LIBCPP_EXPORTED_FROM_ABI void undeclare_no_pointers(char*, size_t) {}
+_LIBCPP_EXPORTED_FROM_ABI void* __undeclare_reachable(void* p) { return p; }
+
+_LIBCPP_END_NAMESPACE_STD
diff --git a/contrib/llvm-project/libcxx/src/locale.cpp b/contrib/llvm-project/libcxx/src/locale.cpp
index a0209d0ce8cf..73b24dbf595a 100644
--- a/contrib/llvm-project/libcxx/src/locale.cpp
+++ b/contrib/llvm-project/libcxx/src/locale.cpp
@@ -1,4 +1,4 @@
-//===------------------------- locale.cpp ---------------------------------===//
+//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -6,43 +6,49 @@
//
//===----------------------------------------------------------------------===//
-// On Solaris, we need to define something to make the C99 parts of localeconv
-// visible.
-#ifdef __sun__
-#define _LCONV_C99
+#include <__utility/no_destroy.h>
+#include <algorithm>
+#include <clocale>
+#include <codecvt>
+#include <cstddef>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+#include <locale>
+#include <new>
+#include <string>
+#include <type_traits>
+#include <typeinfo>
+#include <utility>
+#include <vector>
+
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+# include <cwctype>
#endif
-#include "string"
-#include "locale"
-#include "codecvt"
-#include "vector"
-#include "algorithm"
-#include "typeinfo"
-#ifndef _LIBCPP_NO_EXCEPTIONS
-# include "type_traits"
+#if defined(_AIX)
+# include <sys/localedef.h> // for __lc_ctype_ptr
#endif
-#include "clocale"
-#include "cstring"
+
#if defined(_LIBCPP_MSVCRT)
-#define _CTYPE_DISABLE_MACROS
+# define _CTYPE_DISABLE_MACROS
#endif
-#include "cwctype"
-#include "__sso_allocator"
+
#if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
-#include "__support/win32/locale_win32.h"
+# include "__support/win32/locale_win32.h"
#elif !defined(__BIONIC__) && !defined(__NuttX__)
-#include <langinfo.h>
+# include <langinfo.h>
#endif
-#include <stdlib.h>
-#include <stdio.h>
+
#include "include/atomic_support.h"
-#include "__undef_macros"
+#include "include/sso_allocator.h"
// 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.
-#if defined(__clang__)
-#pragma clang diagnostic ignored "-Wsign-conversion"
-#endif
+_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wsign-conversion")
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -59,6 +65,7 @@ struct __libcpp_unique_locale {
locale_t& get() { return __loc_; }
locale_t __loc_;
+
private:
__libcpp_unique_locale(__libcpp_unique_locale const&);
__libcpp_unique_locale& operator=(__libcpp_unique_locale const&);
@@ -76,75 +83,39 @@ locale_t __cloc() {
namespace {
-struct release
-{
- void operator()(locale::facet* p) {p->__release_shared();}
+struct releaser {
+ void operator()(locale::facet* p) { p->__release_shared(); }
};
-template <class T, class A0>
-inline
-T&
-make(A0 a0)
-{
- static typename aligned_storage<sizeof(T)>::type buf;
- auto *obj = ::new (&buf) T(a0);
- return *obj;
-}
-
-template <class T, class A0, class A1>
-inline
-T&
-make(A0 a0, A1 a1)
-{
- static typename aligned_storage<sizeof(T)>::type buf;
- ::new (&buf) T(a0, a1);
- return *reinterpret_cast<T*>(&buf);
-}
-
-template <class T, class A0, class A1, class A2>
-inline
-T&
-make(A0 a0, A1 a1, A2 a2)
-{
- static typename aligned_storage<sizeof(T)>::type buf;
- auto *obj = ::new (&buf) T(a0, a1, a2);
- return *obj;
+template <class T, class... Args>
+T& make(Args... args) {
+ alignas(T) static std::byte buf[sizeof(T)];
+ auto* obj = ::new (&buf) T(args...);
+ return *obj;
}
template <typename T, size_t N>
-inline
-_LIBCPP_CONSTEXPR
-size_t
-countof(const T (&)[N])
-{
- return N;
+inline constexpr size_t countof(const T (&)[N]) {
+ return N;
}
template <typename T>
-inline
-_LIBCPP_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_NO_EXCEPTIONS
- throw runtime_error(msg);
-#else
- (void)msg;
- _VSTD::abort();
-#endif
+inline constexpr size_t countof(const T* const begin, const T* const end) {
+ return static_cast<size_t>(end - begin);
}
-}
+} // namespace
-#if defined(_AIX)
-// Set priority to INT_MIN + 256 + 150
-# pragma priority ( -2147483242 )
-#endif
+string build_name(const string& other, const string& one, locale::category c) {
+ if (other == "*" || one == "*")
+ return "*";
+ if (c == locale::none || other == one)
+ return other;
+
+ // FIXME: Handle the more complicated cases, such as when the locale has
+ // different names for different categories.
+ return "*";
+}
const locale::category locale::none;
const locale::category locale::collate;
@@ -155,632 +126,567 @@ const locale::category locale::time;
const locale::category locale::messages;
const locale::category locale::all;
-class _LIBCPP_HIDDEN locale::__imp
- : public facet
-{
- enum {N = 30};
-#if defined(_LIBCPP_COMPILER_MSVC)
-// FIXME: MSVC doesn't support aligned parameters by value.
-// I can't get the __sso_allocator to work here
-// for MSVC I think for this reason.
- vector<facet*> facets_;
-#else
- vector<facet*, __sso_allocator<facet*, N> > facets_;
-#endif
- string name_;
+class _LIBCPP_HIDDEN locale::__imp : public facet {
+ enum { N = 30 };
+ vector<facet*, __sso_allocator<facet*, N> > facets_;
+ string name_;
+
public:
- explicit __imp(size_t refs = 0);
- explicit __imp(const string& name, size_t refs = 0);
- __imp(const __imp&);
- __imp(const __imp&, const string&, locale::category c);
- __imp(const __imp& other, const __imp& one, locale::category c);
- __imp(const __imp&, facet* f, long id);
- ~__imp();
-
- const string& name() const {return name_;}
- bool has_facet(long id) const
- {return static_cast<size_t>(id) < facets_.size() && facets_[static_cast<size_t>(id)];}
- const locale::facet* use_facet(long id) const;
-
- static const locale& make_classic();
- static locale& make_global();
+ explicit __imp(size_t refs = 0);
+ explicit __imp(const string& name, size_t refs = 0);
+ __imp(const __imp&);
+ __imp(const __imp&, const string&, locale::category c);
+ __imp(const __imp& other, const __imp& one, locale::category c);
+ __imp(const __imp&, facet* f, long id);
+ ~__imp();
+
+ const string& name() const { return name_; }
+ bool has_facet(long id) const { return static_cast<size_t>(id) < facets_.size() && facets_[static_cast<size_t>(id)]; }
+ const locale::facet* use_facet(long id) const;
+
+ void acquire();
+ void release();
+ static __no_destroy<__imp> classic_locale_imp_;
+
private:
- void install(facet* f, long id);
- template <class F> void install(F* f) {install(f, f->id.__get());}
- template <class F> void install_from(const __imp& other);
+ void install(facet* f, long id);
+ template <class F>
+ void install(F* f) {
+ install(f, f->id.__get());
+ }
+ template <class F>
+ void install_from(const __imp& other);
};
-locale::__imp::__imp(size_t refs)
- : facet(refs),
- facets_(N),
- name_("C")
-{
- facets_.clear();
- install(&make<_VSTD::collate<char> >(1u));
- install(&make<_VSTD::collate<wchar_t> >(1u));
- install(&make<_VSTD::ctype<char> >(nullptr, false, 1u));
- install(&make<_VSTD::ctype<wchar_t> >(1u));
- install(&make<codecvt<char, char, mbstate_t> >(1u));
- install(&make<codecvt<wchar_t, char, mbstate_t> >(1u));
-_LIBCPP_SUPPRESS_DEPRECATED_PUSH
- install(&make<codecvt<char16_t, char, mbstate_t> >(1u));
- install(&make<codecvt<char32_t, char, mbstate_t> >(1u));
-_LIBCPP_SUPPRESS_DEPRECATED_POP
-#ifndef _LIBCPP_NO_HAS_CHAR8_T
- install(&make<codecvt<char16_t, char8_t, mbstate_t> >(1u));
- install(&make<codecvt<char32_t, char8_t, mbstate_t> >(1u));
+locale::__imp::__imp(size_t refs) : facet(refs), facets_(N), name_("C") {
+ facets_.clear();
+ install(&make<std::collate<char> >(1u));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+ install(&make<std::collate<wchar_t> >(1u));
#endif
- install(&make<numpunct<char> >(1u));
- install(&make<numpunct<wchar_t> >(1u));
- install(&make<num_get<char> >(1u));
- install(&make<num_get<wchar_t> >(1u));
- install(&make<num_put<char> >(1u));
- install(&make<num_put<wchar_t> >(1u));
- install(&make<moneypunct<char, false> >(1u));
- install(&make<moneypunct<char, true> >(1u));
- install(&make<moneypunct<wchar_t, false> >(1u));
- install(&make<moneypunct<wchar_t, true> >(1u));
- install(&make<money_get<char> >(1u));
- install(&make<money_get<wchar_t> >(1u));
- install(&make<money_put<char> >(1u));
- install(&make<money_put<wchar_t> >(1u));
- install(&make<time_get<char> >(1u));
- install(&make<time_get<wchar_t> >(1u));
- install(&make<time_put<char> >(1u));
- install(&make<time_put<wchar_t> >(1u));
- install(&make<_VSTD::messages<char> >(1u));
- install(&make<_VSTD::messages<wchar_t> >(1u));
-}
-
-locale::__imp::__imp(const string& name, size_t refs)
- : facet(refs),
- facets_(N),
- name_(name)
-{
-#ifndef _LIBCPP_NO_EXCEPTIONS
- try
- {
-#endif // _LIBCPP_NO_EXCEPTIONS
- facets_ = locale::classic().__locale_->facets_;
- for (unsigned i = 0; i < facets_.size(); ++i)
- if (facets_[i])
- facets_[i]->__add_shared();
- install(new collate_byname<char>(name_));
- install(new collate_byname<wchar_t>(name_));
- install(new ctype_byname<char>(name_));
- install(new ctype_byname<wchar_t>(name_));
- install(new codecvt_byname<char, char, mbstate_t>(name_));
- install(new codecvt_byname<wchar_t, char, mbstate_t>(name_));
-_LIBCPP_SUPPRESS_DEPRECATED_PUSH
- install(new codecvt_byname<char16_t, char, mbstate_t>(name_));
- install(new codecvt_byname<char32_t, char, mbstate_t>(name_));
-_LIBCPP_SUPPRESS_DEPRECATED_POP
-#ifndef _LIBCPP_NO_HAS_CHAR8_T
- install(new codecvt_byname<char16_t, char8_t, mbstate_t>(name_));
- install(new codecvt_byname<char32_t, char8_t, mbstate_t>(name_));
+ install(&make<std::ctype<char> >(nullptr, false, 1u));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+ install(&make<std::ctype<wchar_t> >(1u));
+#endif
+ install(&make<codecvt<char, char, mbstate_t> >(1u));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+ install(&make<codecvt<wchar_t, char, mbstate_t> >(1u));
+#endif
+ _LIBCPP_SUPPRESS_DEPRECATED_PUSH
+ install(&make<codecvt<char16_t, char, mbstate_t> >(1u));
+ install(&make<codecvt<char32_t, char, mbstate_t> >(1u));
+ _LIBCPP_SUPPRESS_DEPRECATED_POP
+#ifndef _LIBCPP_HAS_NO_CHAR8_T
+ install(&make<codecvt<char16_t, char8_t, mbstate_t> >(1u));
+ install(&make<codecvt<char32_t, char8_t, mbstate_t> >(1u));
+#endif
+ install(&make<numpunct<char> >(1u));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+ install(&make<numpunct<wchar_t> >(1u));
+#endif
+ install(&make<num_get<char> >(1u));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+ install(&make<num_get<wchar_t> >(1u));
+#endif
+ install(&make<num_put<char> >(1u));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+ install(&make<num_put<wchar_t> >(1u));
+#endif
+ install(&make<moneypunct<char, false> >(1u));
+ install(&make<moneypunct<char, true> >(1u));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+ install(&make<moneypunct<wchar_t, false> >(1u));
+ install(&make<moneypunct<wchar_t, true> >(1u));
+#endif
+ install(&make<money_get<char> >(1u));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+ install(&make<money_get<wchar_t> >(1u));
+#endif
+ install(&make<money_put<char> >(1u));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+ install(&make<money_put<wchar_t> >(1u));
+#endif
+ install(&make<time_get<char> >(1u));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+ install(&make<time_get<wchar_t> >(1u));
+#endif
+ install(&make<time_put<char> >(1u));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+ install(&make<time_put<wchar_t> >(1u));
+#endif
+ install(&make<std::messages<char> >(1u));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+ install(&make<std::messages<wchar_t> >(1u));
#endif
- install(new numpunct_byname<char>(name_));
- install(new numpunct_byname<wchar_t>(name_));
- install(new moneypunct_byname<char, false>(name_));
- install(new moneypunct_byname<char, true>(name_));
- install(new moneypunct_byname<wchar_t, false>(name_));
- install(new moneypunct_byname<wchar_t, true>(name_));
- install(new time_get_byname<char>(name_));
- install(new time_get_byname<wchar_t>(name_));
- install(new time_put_byname<char>(name_));
- install(new time_put_byname<wchar_t>(name_));
- install(new messages_byname<char>(name_));
- install(new messages_byname<wchar_t>(name_));
-#ifndef _LIBCPP_NO_EXCEPTIONS
- }
- catch (...)
- {
- for (unsigned i = 0; i < facets_.size(); ++i)
- if (facets_[i])
- facets_[i]->__release_shared();
- throw;
- }
-#endif // _LIBCPP_NO_EXCEPTIONS
}
-// NOTE avoid the `base class should be explicitly initialized in the
-// copy constructor` warning emitted by GCC
-#if defined(__clang__) || _GNUC_VER >= 406
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wextra"
+locale::__imp::__imp(const string& name, size_t refs) : facet(refs), facets_(N), name_(name) {
+#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
+ try {
+#endif // _LIBCPP_HAS_NO_EXCEPTIONS
+ facets_ = locale::classic().__locale_->facets_;
+ for (unsigned i = 0; i < facets_.size(); ++i)
+ if (facets_[i])
+ facets_[i]->__add_shared();
+ install(new collate_byname<char>(name_));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+ install(new collate_byname<wchar_t>(name_));
#endif
-
-locale::__imp::__imp(const __imp& other)
- : facets_(max<size_t>(N, other.facets_.size())),
- name_(other.name_)
-{
- facets_ = other.facets_;
+ install(new ctype_byname<char>(name_));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+ install(new ctype_byname<wchar_t>(name_));
+#endif
+ install(new codecvt_byname<char, char, mbstate_t>(name_));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+ install(new codecvt_byname<wchar_t, char, mbstate_t>(name_));
+#endif
+ _LIBCPP_SUPPRESS_DEPRECATED_PUSH
+ install(new codecvt_byname<char16_t, char, mbstate_t>(name_));
+ install(new codecvt_byname<char32_t, char, mbstate_t>(name_));
+ _LIBCPP_SUPPRESS_DEPRECATED_POP
+#ifndef _LIBCPP_HAS_NO_CHAR8_T
+ install(new codecvt_byname<char16_t, char8_t, mbstate_t>(name_));
+ install(new codecvt_byname<char32_t, char8_t, mbstate_t>(name_));
+#endif
+ install(new numpunct_byname<char>(name_));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+ install(new numpunct_byname<wchar_t>(name_));
+#endif
+ install(new moneypunct_byname<char, false>(name_));
+ install(new moneypunct_byname<char, true>(name_));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+ install(new moneypunct_byname<wchar_t, false>(name_));
+ install(new moneypunct_byname<wchar_t, true>(name_));
+#endif
+ install(new time_get_byname<char>(name_));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+ install(new time_get_byname<wchar_t>(name_));
+#endif
+ install(new time_put_byname<char>(name_));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+ install(new time_put_byname<wchar_t>(name_));
+#endif
+ install(new messages_byname<char>(name_));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+ install(new messages_byname<wchar_t>(name_));
+#endif
+#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
+ } catch (...) {
for (unsigned i = 0; i < facets_.size(); ++i)
- if (facets_[i])
- facets_[i]->__add_shared();
+ if (facets_[i])
+ facets_[i]->__release_shared();
+ throw;
+ }
+#endif // _LIBCPP_HAS_NO_EXCEPTIONS
}
-#if defined(__clang__) || _GNUC_VER >= 406
-#pragma GCC diagnostic pop
-#endif
+locale::__imp::__imp(const __imp& other) : facets_(max<size_t>(N, other.facets_.size())), name_(other.name_) {
+ facets_ = other.facets_;
+ for (unsigned i = 0; i < facets_.size(); ++i)
+ if (facets_[i])
+ facets_[i]->__add_shared();
+}
locale::__imp::__imp(const __imp& other, const string& name, locale::category c)
- : facets_(N),
- name_("*")
-{
- facets_ = other.facets_;
- for (unsigned i = 0; i < facets_.size(); ++i)
- if (facets_[i])
- facets_[i]->__add_shared();
-#ifndef _LIBCPP_NO_EXCEPTIONS
- try
- {
-#endif // _LIBCPP_NO_EXCEPTIONS
- if (c & locale::collate)
- {
- install(new collate_byname<char>(name));
- install(new collate_byname<wchar_t>(name));
- }
- if (c & locale::ctype)
- {
- install(new ctype_byname<char>(name));
- install(new ctype_byname<wchar_t>(name));
- install(new codecvt_byname<char, char, mbstate_t>(name));
- install(new codecvt_byname<wchar_t, char, mbstate_t>(name));
-_LIBCPP_SUPPRESS_DEPRECATED_PUSH
- install(new codecvt_byname<char16_t, char, mbstate_t>(name));
- install(new codecvt_byname<char32_t, char, mbstate_t>(name));
-_LIBCPP_SUPPRESS_DEPRECATED_POP
-#ifndef _LIBCPP_NO_HAS_CHAR8_T
- install(new codecvt_byname<char16_t, char8_t, mbstate_t>(name));
- install(new codecvt_byname<char32_t, char8_t, mbstate_t>(name));
+ : facets_(N), name_(build_name(other.name_, name, c)) {
+ facets_ = other.facets_;
+ for (unsigned i = 0; i < facets_.size(); ++i)
+ if (facets_[i])
+ facets_[i]->__add_shared();
+#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
+ try {
+#endif // _LIBCPP_HAS_NO_EXCEPTIONS
+ if (c & locale::collate) {
+ install(new collate_byname<char>(name));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+ install(new collate_byname<wchar_t>(name));
#endif
- }
- if (c & locale::monetary)
- {
- install(new moneypunct_byname<char, false>(name));
- install(new moneypunct_byname<char, true>(name));
- install(new moneypunct_byname<wchar_t, false>(name));
- install(new moneypunct_byname<wchar_t, true>(name));
- }
- if (c & locale::numeric)
- {
- install(new numpunct_byname<char>(name));
- install(new numpunct_byname<wchar_t>(name));
- }
- if (c & locale::time)
- {
- install(new time_get_byname<char>(name));
- install(new time_get_byname<wchar_t>(name));
- install(new time_put_byname<char>(name));
- install(new time_put_byname<wchar_t>(name));
- }
- if (c & locale::messages)
- {
- install(new messages_byname<char>(name));
- install(new messages_byname<wchar_t>(name));
- }
-#ifndef _LIBCPP_NO_EXCEPTIONS
}
- catch (...)
- {
- for (unsigned i = 0; i < facets_.size(); ++i)
- if (facets_[i])
- facets_[i]->__release_shared();
- throw;
+ if (c & locale::ctype) {
+ install(new ctype_byname<char>(name));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+ install(new ctype_byname<wchar_t>(name));
+#endif
+ install(new codecvt_byname<char, char, mbstate_t>(name));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+ install(new codecvt_byname<wchar_t, char, mbstate_t>(name));
+#endif
+ _LIBCPP_SUPPRESS_DEPRECATED_PUSH
+ install(new codecvt_byname<char16_t, char, mbstate_t>(name));
+ install(new codecvt_byname<char32_t, char, mbstate_t>(name));
+ _LIBCPP_SUPPRESS_DEPRECATED_POP
+#ifndef _LIBCPP_HAS_NO_CHAR8_T
+ install(new codecvt_byname<char16_t, char8_t, mbstate_t>(name));
+ install(new codecvt_byname<char32_t, char8_t, mbstate_t>(name));
+#endif
}
-#endif // _LIBCPP_NO_EXCEPTIONS
+ if (c & locale::monetary) {
+ install(new moneypunct_byname<char, false>(name));
+ install(new moneypunct_byname<char, true>(name));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+ install(new moneypunct_byname<wchar_t, false>(name));
+ install(new moneypunct_byname<wchar_t, true>(name));
+#endif
+ }
+ if (c & locale::numeric) {
+ install(new numpunct_byname<char>(name));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+ install(new numpunct_byname<wchar_t>(name));
+#endif
+ }
+ if (c & locale::time) {
+ install(new time_get_byname<char>(name));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+ install(new time_get_byname<wchar_t>(name));
+#endif
+ install(new time_put_byname<char>(name));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+ install(new time_put_byname<wchar_t>(name));
+#endif
+ }
+ if (c & locale::messages) {
+ install(new messages_byname<char>(name));
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+ install(new messages_byname<wchar_t>(name));
+#endif
+ }
+#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
+ } catch (...) {
+ for (unsigned i = 0; i < facets_.size(); ++i)
+ if (facets_[i])
+ facets_[i]->__release_shared();
+ throw;
+ }
+#endif // _LIBCPP_HAS_NO_EXCEPTIONS
}
-template<class F>
-inline
-void
-locale::__imp::install_from(const locale::__imp& one)
-{
- long id = F::id.__get();
- install(const_cast<F*>(static_cast<const F*>(one.use_facet(id))), id);
+template <class F>
+inline void locale::__imp::install_from(const locale::__imp& one) {
+ long id = F::id.__get();
+ install(const_cast<F*>(static_cast<const F*>(one.use_facet(id))), id);
}
locale::__imp::__imp(const __imp& other, const __imp& one, locale::category c)
- : facets_(N),
- name_("*")
-{
- facets_ = other.facets_;
- for (unsigned i = 0; i < facets_.size(); ++i)
- if (facets_[i])
- facets_[i]->__add_shared();
-#ifndef _LIBCPP_NO_EXCEPTIONS
- try
- {
-#endif // _LIBCPP_NO_EXCEPTIONS
- if (c & locale::collate)
- {
- install_from<_VSTD::collate<char> >(one);
- install_from<_VSTD::collate<wchar_t> >(one);
- }
- if (c & locale::ctype)
- {
- install_from<_VSTD::ctype<char> >(one);
- install_from<_VSTD::ctype<wchar_t> >(one);
- install_from<_VSTD::codecvt<char, char, mbstate_t> >(one);
-_LIBCPP_SUPPRESS_DEPRECATED_PUSH
- install_from<_VSTD::codecvt<char16_t, char, mbstate_t> >(one);
- install_from<_VSTD::codecvt<char32_t, char, mbstate_t> >(one);
-_LIBCPP_SUPPRESS_DEPRECATED_POP
-#ifndef _LIBCPP_NO_HAS_CHAR8_T
- install_from<_VSTD::codecvt<char16_t, char8_t, mbstate_t> >(one);
- install_from<_VSTD::codecvt<char32_t, char8_t, mbstate_t> >(one);
+ : facets_(N), name_(build_name(other.name_, one.name_, c)) {
+ facets_ = other.facets_;
+ for (unsigned i = 0; i < facets_.size(); ++i)
+ if (facets_[i])
+ facets_[i]->__add_shared();
+#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
+ try {
+#endif // _LIBCPP_HAS_NO_EXCEPTIONS
+ if (c & locale::collate) {
+ install_from<std::collate<char> >(one);
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+ install_from<std::collate<wchar_t> >(one);
#endif
- install_from<_VSTD::codecvt<wchar_t, char, mbstate_t> >(one);
- }
- if (c & locale::monetary)
- {
- install_from<moneypunct<char, false> >(one);
- install_from<moneypunct<char, true> >(one);
- install_from<moneypunct<wchar_t, false> >(one);
- install_from<moneypunct<wchar_t, true> >(one);
- install_from<money_get<char> >(one);
- install_from<money_get<wchar_t> >(one);
- install_from<money_put<char> >(one);
- install_from<money_put<wchar_t> >(one);
- }
- if (c & locale::numeric)
- {
- install_from<numpunct<char> >(one);
- install_from<numpunct<wchar_t> >(one);
- install_from<num_get<char> >(one);
- install_from<num_get<wchar_t> >(one);
- install_from<num_put<char> >(one);
- install_from<num_put<wchar_t> >(one);
- }
- if (c & locale::time)
- {
- install_from<time_get<char> >(one);
- install_from<time_get<wchar_t> >(one);
- install_from<time_put<char> >(one);
- install_from<time_put<wchar_t> >(one);
- }
- if (c & locale::messages)
- {
- install_from<_VSTD::messages<char> >(one);
- install_from<_VSTD::messages<wchar_t> >(one);
- }
-#ifndef _LIBCPP_NO_EXCEPTIONS
}
- catch (...)
- {
- for (unsigned i = 0; i < facets_.size(); ++i)
- if (facets_[i])
- facets_[i]->__release_shared();
- throw;
+ if (c & locale::ctype) {
+ install_from<std::ctype<char> >(one);
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+ install_from<std::ctype<wchar_t> >(one);
+#endif
+ install_from<std::codecvt<char, char, mbstate_t> >(one);
+ _LIBCPP_SUPPRESS_DEPRECATED_PUSH
+ install_from<std::codecvt<char16_t, char, mbstate_t> >(one);
+ install_from<std::codecvt<char32_t, char, mbstate_t> >(one);
+ _LIBCPP_SUPPRESS_DEPRECATED_POP
+#ifndef _LIBCPP_HAS_NO_CHAR8_T
+ install_from<std::codecvt<char16_t, char8_t, mbstate_t> >(one);
+ install_from<std::codecvt<char32_t, char8_t, mbstate_t> >(one);
+#endif
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+ install_from<std::codecvt<wchar_t, char, mbstate_t> >(one);
+#endif
+ }
+ if (c & locale::monetary) {
+ install_from<moneypunct<char, false> >(one);
+ install_from<moneypunct<char, true> >(one);
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+ install_from<moneypunct<wchar_t, false> >(one);
+ install_from<moneypunct<wchar_t, true> >(one);
+#endif
+ install_from<money_get<char> >(one);
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+ install_from<money_get<wchar_t> >(one);
+#endif
+ install_from<money_put<char> >(one);
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+ install_from<money_put<wchar_t> >(one);
+#endif
}
-#endif // _LIBCPP_NO_EXCEPTIONS
+ if (c & locale::numeric) {
+ install_from<numpunct<char> >(one);
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+ install_from<numpunct<wchar_t> >(one);
+#endif
+ install_from<num_get<char> >(one);
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+ install_from<num_get<wchar_t> >(one);
+#endif
+ install_from<num_put<char> >(one);
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+ install_from<num_put<wchar_t> >(one);
+#endif
+ }
+ if (c & locale::time) {
+ install_from<time_get<char> >(one);
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+ install_from<time_get<wchar_t> >(one);
+#endif
+ install_from<time_put<char> >(one);
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+ install_from<time_put<wchar_t> >(one);
+#endif
+ }
+ if (c & locale::messages) {
+ install_from<std::messages<char> >(one);
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+ install_from<std::messages<wchar_t> >(one);
+#endif
+ }
+#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
+ } catch (...) {
+ for (unsigned i = 0; i < facets_.size(); ++i)
+ if (facets_[i])
+ facets_[i]->__release_shared();
+ throw;
+ }
+#endif // _LIBCPP_HAS_NO_EXCEPTIONS
}
locale::__imp::__imp(const __imp& other, facet* f, long id)
- : facets_(max<size_t>(N, other.facets_.size()+1)),
- name_("*")
-{
- f->__add_shared();
- unique_ptr<facet, release> hold(f);
- facets_ = other.facets_;
- for (unsigned i = 0; i < other.facets_.size(); ++i)
- if (facets_[i])
- facets_[i]->__add_shared();
- install(hold.get(), id);
-}
-
-locale::__imp::~__imp()
-{
- for (unsigned i = 0; i < facets_.size(); ++i)
- if (facets_[i])
- facets_[i]->__release_shared();
+ : facets_(max<size_t>(N, other.facets_.size() + 1)), name_("*") {
+ f->__add_shared();
+ unique_ptr<facet, releaser> hold(f);
+ facets_ = other.facets_;
+ for (unsigned i = 0; i < other.facets_.size(); ++i)
+ if (facets_[i])
+ facets_[i]->__add_shared();
+ install(hold.get(), id);
+}
+
+locale::__imp::~__imp() {
+ for (unsigned i = 0; i < facets_.size(); ++i)
+ if (facets_[i])
+ facets_[i]->__release_shared();
}
-void
-locale::__imp::install(facet* f, long id)
-{
- f->__add_shared();
- unique_ptr<facet, release> hold(f);
- if (static_cast<size_t>(id) >= facets_.size())
- facets_.resize(static_cast<size_t>(id+1));
- if (facets_[static_cast<size_t>(id)])
- facets_[static_cast<size_t>(id)]->__release_shared();
- facets_[static_cast<size_t>(id)] = hold.release();
+void locale::__imp::install(facet* f, long id) {
+ f->__add_shared();
+ unique_ptr<facet, releaser> hold(f);
+ if (static_cast<size_t>(id) >= facets_.size())
+ facets_.resize(static_cast<size_t>(id + 1));
+ if (facets_[static_cast<size_t>(id)])
+ facets_[static_cast<size_t>(id)]->__release_shared();
+ facets_[static_cast<size_t>(id)] = hold.release();
}
-const locale::facet*
-locale::__imp::use_facet(long id) const
-{
- if (!has_facet(id))
- __throw_bad_cast();
- return facets_[static_cast<size_t>(id)];
+const locale::facet* locale::__imp::use_facet(long id) const {
+ if (!has_facet(id))
+ __throw_bad_cast();
+ return facets_[static_cast<size_t>(id)];
}
// locale
-const locale&
-locale::__imp::make_classic()
-{
- // only one thread can get in here and it only gets in once
- static aligned_storage<sizeof(locale)>::type buf;
- locale* c = reinterpret_cast<locale*>(&buf);
- c->__locale_ = &make<__imp>(1u);
- return *c;
-}
+// We don't do reference counting on the classic locale.
+// It's never destroyed anyway, but atomic reference counting may be very
+// expensive in parallel applications. The classic locale is used by default
+// in all streams. Note: if a new global locale is installed, then we lose
+// the benefit of no reference counting.
+constinit __no_destroy<locale::__imp>
+ locale::__imp::classic_locale_imp_(__uninitialized_tag{}); // initialized below in classic()
-const locale&
-locale::classic()
-{
- static const locale& c = __imp::make_classic();
- return c;
+const locale& locale::classic() {
+ static const __no_destroy<locale> classic_locale(__private_tag{}, [] {
+ // executed exactly once on first initialization of `classic_locale`
+ locale::__imp::classic_locale_imp_.__emplace(1u);
+ return &locale::__imp::classic_locale_imp_.__get();
+ }());
+ return classic_locale.__get();
}
-locale&
-locale::__imp::make_global()
-{
- // only one thread can get in here and it only gets in once
- static aligned_storage<sizeof(locale)>::type buf;
- auto *obj = ::new (&buf) locale(locale::classic());
- return *obj;
+locale& locale::__global() {
+ static __no_destroy<locale> g(locale::classic());
+ return g.__get();
}
-locale&
-locale::__global()
-{
- static locale& g = __imp::make_global();
- return g;
+void locale::__imp::acquire() {
+ if (this != &locale::__imp::classic_locale_imp_.__get())
+ __add_shared();
}
-locale::locale() _NOEXCEPT
- : __locale_(__global().__locale_)
-{
- __locale_->__add_shared();
+void locale::__imp::release() {
+ if (this != &locale::__imp::classic_locale_imp_.__get())
+ __release_shared();
}
-locale::locale(const locale& l) _NOEXCEPT
- : __locale_(l.__locale_)
-{
- __locale_->__add_shared();
-}
+locale::locale() noexcept : __locale_(__global().__locale_) { __locale_->acquire(); }
-locale::~locale()
-{
- __locale_->__release_shared();
-}
+locale::locale(const locale& l) noexcept : __locale_(l.__locale_) { __locale_->acquire(); }
-const locale&
-locale::operator=(const locale& other) _NOEXCEPT
-{
- other.__locale_->__add_shared();
- __locale_->__release_shared();
- __locale_ = other.__locale_;
- return *this;
+locale::~locale() { __locale_->release(); }
+
+const locale& locale::operator=(const locale& other) noexcept {
+ other.__locale_->acquire();
+ __locale_->release();
+ __locale_ = other.__locale_;
+ return *this;
}
locale::locale(const char* name)
- : __locale_(name ? new __imp(name)
- : (__throw_runtime_error("locale constructed with null"), nullptr))
-{
- __locale_->__add_shared();
+ : __locale_(name ? new __imp(name) : (__throw_runtime_error("locale constructed with null"), nullptr)) {
+ __locale_->acquire();
}
-locale::locale(const string& name)
- : __locale_(new __imp(name))
-{
- __locale_->__add_shared();
-}
+locale::locale(const string& name) : __locale_(new __imp(name)) { __locale_->acquire(); }
locale::locale(const locale& other, const char* name, category c)
: __locale_(name ? new __imp(*other.__locale_, name, c)
- : (__throw_runtime_error("locale constructed with null"), nullptr))
-{
- __locale_->__add_shared();
+ : (__throw_runtime_error("locale constructed with null"), nullptr)) {
+ __locale_->acquire();
}
-locale::locale(const locale& other, const string& name, category c)
- : __locale_(new __imp(*other.__locale_, name, c))
-{
- __locale_->__add_shared();
+locale::locale(const locale& other, const string& name, category c) : __locale_(new __imp(*other.__locale_, name, c)) {
+ __locale_->acquire();
}
locale::locale(const locale& other, const locale& one, category c)
- : __locale_(new __imp(*other.__locale_, *one.__locale_, c))
-{
- __locale_->__add_shared();
+ : __locale_(new __imp(*other.__locale_, *one.__locale_, c)) {
+ __locale_->acquire();
}
-string
-locale::name() const
-{
- return __locale_->name();
-}
+string locale::name() const { return __locale_->name(); }
-void
-locale::__install_ctor(const locale& other, facet* f, long id)
-{
- if (f)
- __locale_ = new __imp(*other.__locale_, f, id);
- else
- __locale_ = other.__locale_;
- __locale_->__add_shared();
+void locale::__install_ctor(const locale& other, facet* f, long id) {
+ if (f)
+ __locale_ = new __imp(*other.__locale_, f, id);
+ else
+ __locale_ = other.__locale_;
+ __locale_->acquire();
}
-locale
-locale::global(const locale& loc)
-{
- locale& g = __global();
- locale r = g;
- g = loc;
- if (g.name() != "*")
- setlocale(LC_ALL, g.name().c_str());
- return r;
+locale locale::global(const locale& loc) {
+ locale& g = __global();
+ locale r = g;
+ g = loc;
+ if (g.name() != "*")
+ setlocale(LC_ALL, g.name().c_str());
+ return r;
}
-bool
-locale::has_facet(id& x) const
-{
- return __locale_->has_facet(x.__get());
-}
+bool locale::has_facet(id& x) const { return __locale_->has_facet(x.__get()); }
-const locale::facet*
-locale::use_facet(id& x) const
-{
- return __locale_->use_facet(x.__get());
-}
+const locale::facet* locale::use_facet(id& x) const { return __locale_->use_facet(x.__get()); }
-bool
-locale::operator==(const locale& y) const
-{
- return (__locale_ == y.__locale_)
- || (__locale_->name() != "*" && __locale_->name() == y.__locale_->name());
+bool locale::operator==(const locale& y) const {
+ return (__locale_ == y.__locale_) || (__locale_->name() != "*" && __locale_->name() == y.__locale_->name());
}
// locale::facet
-locale::facet::~facet()
-{
-}
+locale::facet::~facet() {}
-void
-locale::facet::__on_zero_shared() _NOEXCEPT
-{
- delete this;
-}
+void locale::facet::__on_zero_shared() noexcept { delete this; }
// locale::id
-int32_t locale::id::__next_id = 0;
-
-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) {}
+constinit int32_t locale::id::__next_id = 0;
- void operator()() const
- {
- (id_->*pmf_)();
- }
-};
-
-}
-
-long
-locale::id::__get()
-{
- call_once(__flag_, __fake_bind(&locale::id::__init, this));
- return __id_ - 1;
-}
-
-void
-locale::id::__init()
-{
- __id_ = __libcpp_atomic_add(&__next_id, 1);
+long locale::id::__get() {
+ call_once(__flag_, [&] { __id_ = __libcpp_atomic_add(&__next_id, 1); });
+ return __id_ - 1;
}
// template <> class collate_byname<char>
collate_byname<char>::collate_byname(const char* n, size_t refs)
- : collate<char>(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));
+ : collate<char>(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))
+ .c_str());
}
collate_byname<char>::collate_byname(const string& name, size_t refs)
- : collate<char>(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);
-}
-
-collate_byname<char>::~collate_byname()
-{
- freelocale(__l);
-}
-
-int
-collate_byname<char>::do_compare(const char_type* __lo1, const char_type* __hi1,
- const char_type* __lo2, const char_type* __hi2) const
-{
- string_type lhs(__lo1, __hi1);
- string_type rhs(__lo2, __hi2);
- int r = strcoll_l(lhs.c_str(), rhs.c_str(), __l);
- if (r < 0)
- return -1;
- if (r > 0)
- return 1;
- return r;
-}
-
-collate_byname<char>::string_type
-collate_byname<char>::do_transform(const char_type* lo, const char_type* hi) const
-{
- const string_type in(lo, hi);
- string_type out(strxfrm_l(0, in.c_str(), 0, __l), char());
- strxfrm_l(const_cast<char*>(out.c_str()), in.c_str(), out.size()+1, __l);
- return out;
+ : collate<char>(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)
+ .c_str());
+}
+
+collate_byname<char>::~collate_byname() { freelocale(__l_); }
+
+int collate_byname<char>::do_compare(
+ const char_type* __lo1, const char_type* __hi1, const char_type* __lo2, const char_type* __hi2) const {
+ string_type lhs(__lo1, __hi1);
+ string_type rhs(__lo2, __hi2);
+ int r = strcoll_l(lhs.c_str(), rhs.c_str(), __l_);
+ if (r < 0)
+ return -1;
+ if (r > 0)
+ return 1;
+ return r;
+}
+
+collate_byname<char>::string_type collate_byname<char>::do_transform(const char_type* lo, const char_type* hi) const {
+ const string_type in(lo, hi);
+ string_type out(strxfrm_l(0, in.c_str(), 0, __l_), char());
+ strxfrm_l(const_cast<char*>(out.c_str()), in.c_str(), out.size() + 1, __l_);
+ return out;
}
// template <> class collate_byname<wchar_t>
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
collate_byname<wchar_t>::collate_byname(const char* n, size_t refs)
- : collate<wchar_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));
+ : collate<wchar_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))
+ .c_str());
}
collate_byname<wchar_t>::collate_byname(const string& name, size_t refs)
- : collate<wchar_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);
-}
-
-collate_byname<wchar_t>::~collate_byname()
-{
- freelocale(__l);
-}
-
-int
-collate_byname<wchar_t>::do_compare(const char_type* __lo1, const char_type* __hi1,
- const char_type* __lo2, const char_type* __hi2) const
-{
- string_type lhs(__lo1, __hi1);
- string_type rhs(__lo2, __hi2);
- int r = wcscoll_l(lhs.c_str(), rhs.c_str(), __l);
- if (r < 0)
- return -1;
- if (r > 0)
- return 1;
- return r;
+ : collate<wchar_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)
+ .c_str());
+}
+
+collate_byname<wchar_t>::~collate_byname() { freelocale(__l_); }
+
+int collate_byname<wchar_t>::do_compare(
+ const char_type* __lo1, const char_type* __hi1, const char_type* __lo2, const char_type* __hi2) const {
+ string_type lhs(__lo1, __hi1);
+ string_type rhs(__lo2, __hi2);
+ int r = wcscoll_l(lhs.c_str(), rhs.c_str(), __l_);
+ if (r < 0)
+ return -1;
+ if (r > 0)
+ return 1;
+ return r;
}
collate_byname<wchar_t>::string_type
-collate_byname<wchar_t>::do_transform(const char_type* lo, const char_type* hi) const
-{
- const string_type in(lo, hi);
- string_type out(wcsxfrm_l(0, in.c_str(), 0, __l), wchar_t());
- wcsxfrm_l(const_cast<wchar_t*>(out.c_str()), in.c_str(), out.size()+1, __l);
- return out;
+collate_byname<wchar_t>::do_transform(const char_type* lo, const char_type* hi) const {
+ const string_type in(lo, hi);
+ string_type out(wcsxfrm_l(0, in.c_str(), 0, __l_), wchar_t());
+ wcsxfrm_l(const_cast<wchar_t*>(out.c_str()), in.c_str(), out.size() + 1, __l_);
+ return out;
}
-
-// template <> class ctype<wchar_t>;
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
const ctype_base::mask ctype_base::space;
const ctype_base::mask ctype_base::print;
@@ -795,265 +701,206 @@ const ctype_base::mask ctype_base::blank;
const ctype_base::mask ctype_base::alnum;
const ctype_base::mask ctype_base::graph;
-locale::id ctype<wchar_t>::id;
+// template <> class ctype<wchar_t>;
-ctype<wchar_t>::~ctype()
-{
-}
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+constinit locale::id ctype<wchar_t>::id;
-bool
-ctype<wchar_t>::do_is(mask m, char_type c) const
-{
- return isascii(c) ? (ctype<char>::classic_table()[c] & m) != 0 : false;
-}
+ctype<wchar_t>::~ctype() {}
-const wchar_t*
-ctype<wchar_t>::do_is(const char_type* low, const char_type* high, mask* vec) const
-{
- for (; low != high; ++low, ++vec)
- *vec = static_cast<mask>(isascii(*low) ?
- ctype<char>::classic_table()[*low] : 0);
- return low;
+bool ctype<wchar_t>::do_is(mask m, char_type c) const {
+ return isascii(c) ? (ctype<char>::classic_table()[c] & m) != 0 : false;
}
-const wchar_t*
-ctype<wchar_t>::do_scan_is(mask m, const char_type* low, const char_type* high) const
-{
- for (; low != high; ++low)
- if (isascii(*low) && (ctype<char>::classic_table()[*low] & m))
- break;
- return low;
+const wchar_t* ctype<wchar_t>::do_is(const char_type* low, const char_type* high, mask* vec) const {
+ for (; low != high; ++low, ++vec)
+ *vec = static_cast<mask>(isascii(*low) ? ctype<char>::classic_table()[*low] : 0);
+ return low;
}
-const wchar_t*
-ctype<wchar_t>::do_scan_not(mask m, const char_type* low, const char_type* high) const
-{
- for (; low != high; ++low)
- if (!(isascii(*low) && (ctype<char>::classic_table()[*low] & m)))
- break;
- return low;
+const wchar_t* ctype<wchar_t>::do_scan_is(mask m, const char_type* low, const char_type* high) const {
+ for (; low != high; ++low)
+ if (isascii(*low) && (ctype<char>::classic_table()[*low] & m))
+ break;
+ return low;
}
-wchar_t
-ctype<wchar_t>::do_toupper(char_type c) const
-{
-#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
- return isascii(c) ? _DefaultRuneLocale.__mapupper[c] : c;
-#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || \
- defined(__NetBSD__)
- return isascii(c) ? ctype<char>::__classic_upper_table()[c] : c;
-#else
- return (isascii(c) && iswlower_l(c, _LIBCPP_GET_C_LOCALE)) ? c-L'a'+L'A' : c;
-#endif
+const wchar_t* ctype<wchar_t>::do_scan_not(mask m, const char_type* low, const char_type* high) const {
+ for (; low != high; ++low)
+ if (!(isascii(*low) && (ctype<char>::classic_table()[*low] & m)))
+ break;
+ return low;
}
-const wchar_t*
-ctype<wchar_t>::do_toupper(char_type* low, const char_type* high) const
-{
- for (; low != high; ++low)
-#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
- *low = isascii(*low) ? _DefaultRuneLocale.__mapupper[*low] : *low;
-#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || \
- defined(__NetBSD__)
- *low = isascii(*low) ? ctype<char>::__classic_upper_table()[*low]
- : *low;
-#else
- *low = (isascii(*low) && islower_l(*low, _LIBCPP_GET_C_LOCALE)) ? (*low-L'a'+L'A') : *low;
-#endif
- return low;
+wchar_t ctype<wchar_t>::do_toupper(char_type c) const {
+# ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
+ return isascii(c) ? _DefaultRuneLocale.__mapupper[c] : c;
+# elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__) || defined(__MVS__)
+ return isascii(c) ? ctype<char>::__classic_upper_table()[c] : c;
+# else
+ return (isascii(c) && iswlower_l(c, _LIBCPP_GET_C_LOCALE)) ? c - L'a' + L'A' : c;
+# endif
}
-wchar_t
-ctype<wchar_t>::do_tolower(char_type c) const
-{
-#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
- return isascii(c) ? _DefaultRuneLocale.__maplower[c] : c;
-#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || \
- defined(__NetBSD__)
- return isascii(c) ? ctype<char>::__classic_lower_table()[c] : c;
-#else
- return (isascii(c) && isupper_l(c, _LIBCPP_GET_C_LOCALE)) ? c-L'A'+'a' : c;
-#endif
+const wchar_t* ctype<wchar_t>::do_toupper(char_type* low, const char_type* high) const {
+ for (; low != high; ++low)
+# ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
+ *low = isascii(*low) ? _DefaultRuneLocale.__mapupper[*low] : *low;
+# elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__) || defined(__MVS__)
+ *low = isascii(*low) ? ctype<char>::__classic_upper_table()[*low] : *low;
+# else
+ *low = (isascii(*low) && islower_l(*low, _LIBCPP_GET_C_LOCALE)) ? (*low - L'a' + L'A') : *low;
+# endif
+ return low;
}
-const wchar_t*
-ctype<wchar_t>::do_tolower(char_type* low, const char_type* high) const
-{
- for (; low != high; ++low)
-#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
- *low = isascii(*low) ? _DefaultRuneLocale.__maplower[*low] : *low;
-#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || \
- defined(__NetBSD__)
- *low = isascii(*low) ? ctype<char>::__classic_lower_table()[*low]
- : *low;
-#else
- *low = (isascii(*low) && isupper_l(*low, _LIBCPP_GET_C_LOCALE)) ? *low-L'A'+L'a' : *low;
-#endif
- return low;
+wchar_t ctype<wchar_t>::do_tolower(char_type c) const {
+# ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
+ return isascii(c) ? _DefaultRuneLocale.__maplower[c] : c;
+# elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__) || defined(__MVS__)
+ return isascii(c) ? ctype<char>::__classic_lower_table()[c] : c;
+# else
+ return (isascii(c) && isupper_l(c, _LIBCPP_GET_C_LOCALE)) ? c - L'A' + 'a' : c;
+# endif
}
-wchar_t
-ctype<wchar_t>::do_widen(char c) const
-{
- return c;
+const wchar_t* ctype<wchar_t>::do_tolower(char_type* low, const char_type* high) const {
+ for (; low != high; ++low)
+# ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
+ *low = isascii(*low) ? _DefaultRuneLocale.__maplower[*low] : *low;
+# elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__) || defined(__MVS__)
+ *low = isascii(*low) ? ctype<char>::__classic_lower_table()[*low] : *low;
+# else
+ *low = (isascii(*low) && isupper_l(*low, _LIBCPP_GET_C_LOCALE)) ? *low - L'A' + L'a' : *low;
+# endif
+ return low;
}
-const char*
-ctype<wchar_t>::do_widen(const char* low, const char* high, char_type* dest) const
-{
- for (; low != high; ++low, ++dest)
- *dest = *low;
- return low;
+wchar_t ctype<wchar_t>::do_widen(char c) const { return c; }
+
+const char* ctype<wchar_t>::do_widen(const char* low, const char* high, char_type* dest) const {
+ for (; low != high; ++low, ++dest)
+ *dest = *low;
+ return low;
}
-char
-ctype<wchar_t>::do_narrow(char_type c, char dfault) const
-{
- if (isascii(c))
- return static_cast<char>(c);
- return dfault;
+char ctype<wchar_t>::do_narrow(char_type c, char dfault) const {
+ if (isascii(c))
+ return static_cast<char>(c);
+ return dfault;
}
-const wchar_t*
-ctype<wchar_t>::do_narrow(const char_type* low, const char_type* high, char dfault, char* dest) const
-{
- for (; low != high; ++low, ++dest)
- if (isascii(*low))
- *dest = static_cast<char>(*low);
- else
- *dest = dfault;
- return low;
+const wchar_t* ctype<wchar_t>::do_narrow(const char_type* low, const char_type* high, char dfault, char* dest) const {
+ for (; low != high; ++low, ++dest)
+ if (isascii(*low))
+ *dest = static_cast<char>(*low);
+ else
+ *dest = dfault;
+ return low;
}
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
// template <> class ctype<char>;
-locale::id ctype<char>::id;
+constinit locale::id ctype<char>::id;
-ctype<char>::ctype(const mask* tab, bool del, size_t refs)
- : locale::facet(refs),
- __tab_(tab),
- __del_(del)
-{
+const size_t ctype<char>::table_size;
+
+ctype<char>::ctype(const mask* tab, bool del, size_t refs) : locale::facet(refs), __tab_(tab), __del_(del) {
if (__tab_ == 0)
- __tab_ = classic_table();
+ __tab_ = classic_table();
}
-ctype<char>::~ctype()
-{
- if (__tab_ && __del_)
- delete [] __tab_;
+ctype<char>::~ctype() {
+ if (__tab_ && __del_)
+ delete[] __tab_;
}
-char
-ctype<char>::do_toupper(char_type c) const
-{
+char ctype<char>::do_toupper(char_type c) const {
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
- return isascii(c) ?
- static_cast<char>(_DefaultRuneLocale.__mapupper[static_cast<ptrdiff_t>(c)]) : c;
+ return isascii(c) ? static_cast<char>(_DefaultRuneLocale.__mapupper[static_cast<ptrdiff_t>(c)]) : c;
#elif defined(__NetBSD__)
- return static_cast<char>(__classic_upper_table()[static_cast<unsigned char>(c)]);
-#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__)
- return isascii(c) ?
- static_cast<char>(__classic_upper_table()[static_cast<unsigned char>(c)]) : c;
+ return static_cast<char>(__classic_upper_table()[static_cast<unsigned char>(c)]);
+#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || defined(__MVS__)
+ return isascii(c) ? static_cast<char>(__classic_upper_table()[static_cast<unsigned char>(c)]) : c;
#else
- return (isascii(c) && islower_l(c, _LIBCPP_GET_C_LOCALE)) ? c-'a'+'A' : c;
+ return (isascii(c) && islower_l(c, _LIBCPP_GET_C_LOCALE)) ? c - 'a' + 'A' : c;
#endif
}
-const char*
-ctype<char>::do_toupper(char_type* low, const char_type* high) const
-{
- for (; low != high; ++low)
+const char* ctype<char>::do_toupper(char_type* low, const char_type* high) const {
+ for (; low != high; ++low)
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
- *low = isascii(*low) ?
- static_cast<char>(_DefaultRuneLocale.__mapupper[static_cast<ptrdiff_t>(*low)]) : *low;
+ *low = isascii(*low) ? static_cast<char>(_DefaultRuneLocale.__mapupper[static_cast<ptrdiff_t>(*low)]) : *low;
#elif defined(__NetBSD__)
- *low = static_cast<char>(__classic_upper_table()[static_cast<unsigned char>(*low)]);
-#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__)
- *low = isascii(*low) ?
- static_cast<char>(__classic_upper_table()[static_cast<size_t>(*low)]) : *low;
+ *low = static_cast<char>(__classic_upper_table()[static_cast<unsigned char>(*low)]);
+#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || defined(__MVS__)
+ *low = isascii(*low) ? static_cast<char>(__classic_upper_table()[static_cast<size_t>(*low)]) : *low;
#else
- *low = (isascii(*low) && islower_l(*low, _LIBCPP_GET_C_LOCALE)) ? *low-'a'+'A' : *low;
+ *low = (isascii(*low) && islower_l(*low, _LIBCPP_GET_C_LOCALE)) ? *low - 'a' + 'A' : *low;
#endif
- return low;
+ return low;
}
-char
-ctype<char>::do_tolower(char_type c) const
-{
+char ctype<char>::do_tolower(char_type c) const {
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
- return isascii(c) ?
- static_cast<char>(_DefaultRuneLocale.__maplower[static_cast<ptrdiff_t>(c)]) : c;
+ return isascii(c) ? static_cast<char>(_DefaultRuneLocale.__maplower[static_cast<ptrdiff_t>(c)]) : c;
#elif defined(__NetBSD__)
- return static_cast<char>(__classic_lower_table()[static_cast<unsigned char>(c)]);
-#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__)
- return isascii(c) ?
- static_cast<char>(__classic_lower_table()[static_cast<size_t>(c)]) : c;
+ return static_cast<char>(__classic_lower_table()[static_cast<unsigned char>(c)]);
+#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || defined(__MVS__)
+ return isascii(c) ? static_cast<char>(__classic_lower_table()[static_cast<size_t>(c)]) : c;
#else
- return (isascii(c) && isupper_l(c, _LIBCPP_GET_C_LOCALE)) ? c-'A'+'a' : c;
+ return (isascii(c) && isupper_l(c, _LIBCPP_GET_C_LOCALE)) ? c - 'A' + 'a' : c;
#endif
}
-const char*
-ctype<char>::do_tolower(char_type* low, const char_type* high) const
-{
- for (; low != high; ++low)
+const char* ctype<char>::do_tolower(char_type* low, const char_type* high) const {
+ for (; low != high; ++low)
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
- *low = isascii(*low) ? static_cast<char>(_DefaultRuneLocale.__maplower[static_cast<ptrdiff_t>(*low)]) : *low;
+ *low = isascii(*low) ? static_cast<char>(_DefaultRuneLocale.__maplower[static_cast<ptrdiff_t>(*low)]) : *low;
#elif defined(__NetBSD__)
- *low = static_cast<char>(__classic_lower_table()[static_cast<unsigned char>(*low)]);
-#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__)
- *low = isascii(*low) ? static_cast<char>(__classic_lower_table()[static_cast<size_t>(*low)]) : *low;
+ *low = static_cast<char>(__classic_lower_table()[static_cast<unsigned char>(*low)]);
+#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || defined(__MVS__)
+ *low = isascii(*low) ? static_cast<char>(__classic_lower_table()[static_cast<size_t>(*low)]) : *low;
#else
- *low = (isascii(*low) && isupper_l(*low, _LIBCPP_GET_C_LOCALE)) ? *low-'A'+'a' : *low;
+ *low = (isascii(*low) && isupper_l(*low, _LIBCPP_GET_C_LOCALE)) ? *low - 'A' + 'a' : *low;
#endif
- return low;
+ return low;
}
-char
-ctype<char>::do_widen(char c) const
-{
- return c;
-}
+char ctype<char>::do_widen(char c) const { return c; }
-const char*
-ctype<char>::do_widen(const char* low, const char* high, char_type* dest) const
-{
- for (; low != high; ++low, ++dest)
- *dest = *low;
- return low;
+const char* ctype<char>::do_widen(const char* low, const char* high, char_type* dest) const {
+ for (; low != high; ++low, ++dest)
+ *dest = *low;
+ return low;
}
-char
-ctype<char>::do_narrow(char_type c, char dfault) const
-{
- if (isascii(c))
- return static_cast<char>(c);
- return dfault;
+char ctype<char>::do_narrow(char_type c, char dfault) const {
+ if (isascii(c))
+ return static_cast<char>(c);
+ return dfault;
}
-const char*
-ctype<char>::do_narrow(const char_type* low, const char_type* high, char dfault, char* dest) const
-{
- for (; low != high; ++low, ++dest)
- if (isascii(*low))
- *dest = *low;
- else
- *dest = dfault;
- return low;
+const char* ctype<char>::do_narrow(const char_type* low, const char_type* high, char dfault, char* dest) const {
+ for (; low != high; ++low, ++dest)
+ if (isascii(*low))
+ *dest = *low;
+ else
+ *dest = dfault;
+ return low;
}
#if defined(__EMSCRIPTEN__)
-extern "C" const unsigned short ** __ctype_b_loc();
-extern "C" const int ** __ctype_tolower_loc();
-extern "C" const int ** __ctype_toupper_loc();
+extern "C" const unsigned short** __ctype_b_loc();
+extern "C" const int** __ctype_tolower_loc();
+extern "C" const int** __ctype_toupper_loc();
#endif
#ifdef _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE
-const ctype<char>::mask*
-ctype<char>::classic_table() _NOEXCEPT
-{
- static _LIBCPP_CONSTEXPR const ctype<char>::mask builtin_table[table_size] = {
+const ctype<char>::mask* ctype<char>::classic_table() noexcept {
+ // clang-format off
+ static constexpr const ctype<char>::mask builtin_table[table_size] = {
cntrl, cntrl,
cntrl, cntrl,
cntrl, cntrl,
@@ -1127,609 +974,559 @@ ctype<char>::classic_table() _NOEXCEPT
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
- return builtin_table;
+ // clang-format on
+ return builtin_table;
}
#else
-const ctype<char>::mask*
-ctype<char>::classic_table() _NOEXCEPT
-{
-#if defined(__APPLE__) || defined(__FreeBSD__)
- return _DefaultRuneLocale.__runetype;
-#elif defined(__NetBSD__)
- return _C_ctype_tab_ + 1;
-#elif defined(__GLIBC__)
- return _LIBCPP_GET_C_LOCALE->__ctype_b;
-#elif __sun__
- return __ctype_mask;
-#elif defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
- return __pctype_func();
-#elif defined(__EMSCRIPTEN__)
- return *__ctype_b_loc();
-#elif defined(_NEWLIB_VERSION)
- // Newlib has a 257-entry table in ctype_.c, where (char)0 starts at [1].
- return _ctype_ + 1;
-#elif defined(_AIX)
- return (const unsigned int *)__lc_ctype_ptr->obj->mask;
-#else
- // Platform not supported: abort so the person doing the port knows what to
- // fix
-# warning ctype<char>::classic_table() is not implemented
- printf("ctype<char>::classic_table() is not implemented\n");
- abort();
- return NULL;
-#endif
+const ctype<char>::mask* ctype<char>::classic_table() noexcept {
+# if defined(__APPLE__) || defined(__FreeBSD__)
+ return _DefaultRuneLocale.__runetype;
+# elif defined(__NetBSD__)
+ return _C_ctype_tab_ + 1;
+# elif defined(__GLIBC__)
+ return _LIBCPP_GET_C_LOCALE->__ctype_b;
+# elif defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
+ return __pctype_func();
+# elif defined(__EMSCRIPTEN__)
+ return *__ctype_b_loc();
+# elif defined(_NEWLIB_VERSION)
+ // Newlib has a 257-entry table in ctype_.c, where (char)0 starts at [1].
+ return _ctype_ + 1;
+# elif defined(_AIX)
+ return (const unsigned int*)__lc_ctype_ptr->obj->mask;
+# elif defined(__MVS__)
+# if defined(__NATIVE_ASCII_F)
+ return const_cast<const ctype<char>::mask*>(__OBJ_DATA(__lc_ctype_a)->mask);
+# else
+ return const_cast<const ctype<char>::mask*>(__ctypec);
+# endif
+# else
+ // Platform not supported: abort so the person doing the port knows what to
+ // fix
+# warning ctype<char>::classic_table() is not implemented
+ printf("ctype<char>::classic_table() is not implemented\n");
+ abort();
+ return NULL;
+# endif
}
#endif
#if defined(__GLIBC__)
-const int*
-ctype<char>::__classic_lower_table() _NOEXCEPT
-{
- return _LIBCPP_GET_C_LOCALE->__ctype_tolower;
-}
+const int* ctype<char>::__classic_lower_table() noexcept { return _LIBCPP_GET_C_LOCALE->__ctype_tolower; }
-const int*
-ctype<char>::__classic_upper_table() _NOEXCEPT
-{
- return _LIBCPP_GET_C_LOCALE->__ctype_toupper;
-}
+const int* ctype<char>::__classic_upper_table() noexcept { return _LIBCPP_GET_C_LOCALE->__ctype_toupper; }
#elif defined(__NetBSD__)
-const short*
-ctype<char>::__classic_lower_table() _NOEXCEPT
-{
- return _C_tolower_tab_ + 1;
-}
+const short* ctype<char>::__classic_lower_table() noexcept { return _C_tolower_tab_ + 1; }
-const short*
-ctype<char>::__classic_upper_table() _NOEXCEPT
-{
- return _C_toupper_tab_ + 1;
-}
+const short* ctype<char>::__classic_upper_table() noexcept { return _C_toupper_tab_ + 1; }
#elif defined(__EMSCRIPTEN__)
-const int*
-ctype<char>::__classic_lower_table() _NOEXCEPT
-{
- return *__ctype_tolower_loc();
-}
-
-const int*
-ctype<char>::__classic_upper_table() _NOEXCEPT
-{
- return *__ctype_toupper_loc();
-}
-#endif // __GLIBC__ || __NETBSD__ || __EMSCRIPTEN__
+const int* ctype<char>::__classic_lower_table() noexcept { return *__ctype_tolower_loc(); }
+
+const int* ctype<char>::__classic_upper_table() noexcept { return *__ctype_toupper_loc(); }
+#elif defined(__MVS__)
+const unsigned short* ctype<char>::__classic_lower_table() _NOEXCEPT {
+# if defined(__NATIVE_ASCII_F)
+ return const_cast<const unsigned short*>(__OBJ_DATA(__lc_ctype_a)->lower);
+# else
+ return const_cast<const unsigned short*>(__ctype + __TOLOWER_INDEX);
+# endif
+}
+const unsigned short* ctype<char>::__classic_upper_table() _NOEXCEPT {
+# if defined(__NATIVE_ASCII_F)
+ return const_cast<const unsigned short*>(__OBJ_DATA(__lc_ctype_a)->upper);
+# else
+ return const_cast<const unsigned short*>(__ctype + __TOUPPER_INDEX);
+# endif
+}
+#endif // __GLIBC__ || __NETBSD__ || __EMSCRIPTEN__ || __MVS__
// template <> class ctype_byname<char>
ctype_byname<char>::ctype_byname(const char* name, size_t refs)
- : ctype<char>(0, false, 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));
+ : ctype<char>(0, false, 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))
+ .c_str());
}
ctype_byname<char>::ctype_byname(const string& name, size_t refs)
- : ctype<char>(0, false, 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);
+ : ctype<char>(0, false, 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)
+ .c_str());
}
-ctype_byname<char>::~ctype_byname()
-{
- freelocale(__l);
-}
+ctype_byname<char>::~ctype_byname() { freelocale(__l_); }
-char
-ctype_byname<char>::do_toupper(char_type c) const
-{
- return static_cast<char>(toupper_l(static_cast<unsigned char>(c), __l));
+char ctype_byname<char>::do_toupper(char_type c) const {
+ return static_cast<char>(toupper_l(static_cast<unsigned char>(c), __l_));
}
-const char*
-ctype_byname<char>::do_toupper(char_type* low, const char_type* high) const
-{
- for (; low != high; ++low)
- *low = static_cast<char>(toupper_l(static_cast<unsigned char>(*low), __l));
- return low;
+const char* ctype_byname<char>::do_toupper(char_type* low, const char_type* high) const {
+ for (; low != high; ++low)
+ *low = static_cast<char>(toupper_l(static_cast<unsigned char>(*low), __l_));
+ return low;
}
-char
-ctype_byname<char>::do_tolower(char_type c) const
-{
- return static_cast<char>(tolower_l(static_cast<unsigned char>(c), __l));
+char ctype_byname<char>::do_tolower(char_type c) const {
+ return static_cast<char>(tolower_l(static_cast<unsigned char>(c), __l_));
}
-const char*
-ctype_byname<char>::do_tolower(char_type* low, const char_type* high) const
-{
- for (; low != high; ++low)
- *low = static_cast<char>(tolower_l(static_cast<unsigned char>(*low), __l));
- return low;
+const char* ctype_byname<char>::do_tolower(char_type* low, const char_type* high) const {
+ for (; low != high; ++low)
+ *low = static_cast<char>(tolower_l(static_cast<unsigned char>(*low), __l_));
+ return low;
}
// template <> class ctype_byname<wchar_t>
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
ctype_byname<wchar_t>::ctype_byname(const char* name, size_t refs)
- : ctype<wchar_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));
+ : ctype<wchar_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))
+ .c_str());
}
ctype_byname<wchar_t>::ctype_byname(const string& name, size_t refs)
- : ctype<wchar_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);
-}
-
-ctype_byname<wchar_t>::~ctype_byname()
-{
- freelocale(__l);
-}
-
-bool
-ctype_byname<wchar_t>::do_is(mask m, char_type c) const
-{
-#ifdef _LIBCPP_WCTYPE_IS_MASK
- return static_cast<bool>(iswctype_l(c, m, __l));
-#else
- bool result = false;
- wint_t ch = static_cast<wint_t>(c);
- if ((m & space) == space) result |= (iswspace_l(ch, __l) != 0);
- if ((m & print) == print) result |= (iswprint_l(ch, __l) != 0);
- if ((m & cntrl) == cntrl) result |= (iswcntrl_l(ch, __l) != 0);
- if ((m & upper) == upper) result |= (iswupper_l(ch, __l) != 0);
- if ((m & lower) == lower) result |= (iswlower_l(ch, __l) != 0);
- if ((m & alpha) == alpha) result |= (iswalpha_l(ch, __l) != 0);
- if ((m & digit) == digit) result |= (iswdigit_l(ch, __l) != 0);
- if ((m & punct) == punct) result |= (iswpunct_l(ch, __l) != 0);
- if ((m & xdigit) == xdigit) result |= (iswxdigit_l(ch, __l) != 0);
- if ((m & blank) == blank) result |= (iswblank_l(ch, __l) != 0);
- return result;
-#endif
-}
-
-const wchar_t*
-ctype_byname<wchar_t>::do_is(const char_type* low, const char_type* high, mask* vec) const
-{
- for (; low != high; ++low, ++vec)
- {
- if (isascii(*low))
- *vec = static_cast<mask>(ctype<char>::classic_table()[*low]);
- else
- {
- *vec = 0;
- wint_t ch = static_cast<wint_t>(*low);
- if (iswspace_l(ch, __l))
- *vec |= space;
-#ifndef _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT
- if (iswprint_l(ch, __l))
- *vec |= print;
-#endif
- if (iswcntrl_l(ch, __l))
- *vec |= cntrl;
- if (iswupper_l(ch, __l))
- *vec |= upper;
- if (iswlower_l(ch, __l))
- *vec |= lower;
-#ifndef _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA
- if (iswalpha_l(ch, __l))
- *vec |= alpha;
-#endif
- if (iswdigit_l(ch, __l))
- *vec |= digit;
- if (iswpunct_l(ch, __l))
- *vec |= punct;
-#ifndef _LIBCPP_CTYPE_MASK_IS_COMPOSITE_XDIGIT
- if (iswxdigit_l(ch, __l))
- *vec |= xdigit;
-#endif
-#if !defined(__sun__)
- if (iswblank_l(ch, __l))
- *vec |= blank;
-#endif
- }
- }
- return low;
-}
-
-const wchar_t*
-ctype_byname<wchar_t>::do_scan_is(mask m, const char_type* low, const char_type* high) const
-{
- for (; low != high; ++low)
- {
-#ifdef _LIBCPP_WCTYPE_IS_MASK
- if (iswctype_l(*low, m, __l))
- break;
-#else
- wint_t ch = static_cast<wint_t>(*low);
- if ((m & space) == space && iswspace_l(ch, __l)) break;
- if ((m & print) == print && iswprint_l(ch, __l)) break;
- if ((m & cntrl) == cntrl && iswcntrl_l(ch, __l)) break;
- if ((m & upper) == upper && iswupper_l(ch, __l)) break;
- if ((m & lower) == lower && iswlower_l(ch, __l)) break;
- if ((m & alpha) == alpha && iswalpha_l(ch, __l)) break;
- if ((m & digit) == digit && iswdigit_l(ch, __l)) break;
- if ((m & punct) == punct && iswpunct_l(ch, __l)) break;
- if ((m & xdigit) == xdigit && iswxdigit_l(ch, __l)) break;
- if ((m & blank) == blank && iswblank_l(ch, __l)) break;
-#endif
- }
- return low;
-}
-
-const wchar_t*
-ctype_byname<wchar_t>::do_scan_not(mask m, const char_type* low, const char_type* high) const
-{
- for (; low != high; ++low)
- {
-#ifdef _LIBCPP_WCTYPE_IS_MASK
- if (!iswctype_l(*low, m, __l))
- break;
-#else
- wint_t ch = static_cast<wint_t>(*low);
- if ((m & space) == space && iswspace_l(ch, __l)) continue;
- if ((m & print) == print && iswprint_l(ch, __l)) continue;
- if ((m & cntrl) == cntrl && iswcntrl_l(ch, __l)) continue;
- if ((m & upper) == upper && iswupper_l(ch, __l)) continue;
- if ((m & lower) == lower && iswlower_l(ch, __l)) continue;
- if ((m & alpha) == alpha && iswalpha_l(ch, __l)) continue;
- if ((m & digit) == digit && iswdigit_l(ch, __l)) continue;
- if ((m & punct) == punct && iswpunct_l(ch, __l)) continue;
- if ((m & xdigit) == xdigit && iswxdigit_l(ch, __l)) continue;
- if ((m & blank) == blank && iswblank_l(ch, __l)) continue;
- break;
-#endif
+ : ctype<wchar_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)
+ .c_str());
+}
+
+ctype_byname<wchar_t>::~ctype_byname() { freelocale(__l_); }
+
+bool ctype_byname<wchar_t>::do_is(mask m, char_type c) const {
+# ifdef _LIBCPP_WCTYPE_IS_MASK
+ return static_cast<bool>(iswctype_l(c, m, __l_));
+# else
+ bool result = false;
+ wint_t ch = static_cast<wint_t>(c);
+ if ((m & space) == space)
+ result |= (iswspace_l(ch, __l_) != 0);
+ if ((m & print) == print)
+ result |= (iswprint_l(ch, __l_) != 0);
+ if ((m & cntrl) == cntrl)
+ result |= (iswcntrl_l(ch, __l_) != 0);
+ if ((m & upper) == upper)
+ result |= (iswupper_l(ch, __l_) != 0);
+ if ((m & lower) == lower)
+ result |= (iswlower_l(ch, __l_) != 0);
+ if ((m & alpha) == alpha)
+ result |= (iswalpha_l(ch, __l_) != 0);
+ if ((m & digit) == digit)
+ result |= (iswdigit_l(ch, __l_) != 0);
+ if ((m & punct) == punct)
+ result |= (iswpunct_l(ch, __l_) != 0);
+ if ((m & xdigit) == xdigit)
+ result |= (iswxdigit_l(ch, __l_) != 0);
+ if ((m & blank) == blank)
+ result |= (iswblank_l(ch, __l_) != 0);
+ return result;
+# endif
+}
+
+const wchar_t* ctype_byname<wchar_t>::do_is(const char_type* low, const char_type* high, mask* vec) const {
+ for (; low != high; ++low, ++vec) {
+ if (isascii(*low))
+ *vec = static_cast<mask>(ctype<char>::classic_table()[*low]);
+ else {
+ *vec = 0;
+ wint_t ch = static_cast<wint_t>(*low);
+ if (iswspace_l(ch, __l_))
+ *vec |= space;
+# ifndef _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT
+ if (iswprint_l(ch, __l_))
+ *vec |= print;
+# endif
+ if (iswcntrl_l(ch, __l_))
+ *vec |= cntrl;
+ if (iswupper_l(ch, __l_))
+ *vec |= upper;
+ if (iswlower_l(ch, __l_))
+ *vec |= lower;
+# ifndef _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA
+ if (iswalpha_l(ch, __l_))
+ *vec |= alpha;
+# endif
+ if (iswdigit_l(ch, __l_))
+ *vec |= digit;
+ if (iswpunct_l(ch, __l_))
+ *vec |= punct;
+# ifndef _LIBCPP_CTYPE_MASK_IS_COMPOSITE_XDIGIT
+ if (iswxdigit_l(ch, __l_))
+ *vec |= xdigit;
+# endif
+ if (iswblank_l(ch, __l_))
+ *vec |= blank;
}
- return low;
+ }
+ return low;
+}
+
+const wchar_t* ctype_byname<wchar_t>::do_scan_is(mask m, const char_type* low, const char_type* high) const {
+ for (; low != high; ++low) {
+# ifdef _LIBCPP_WCTYPE_IS_MASK
+ if (iswctype_l(*low, m, __l_))
+ break;
+# else
+ wint_t ch = static_cast<wint_t>(*low);
+ if ((m & space) == space && iswspace_l(ch, __l_))
+ break;
+ if ((m & print) == print && iswprint_l(ch, __l_))
+ break;
+ if ((m & cntrl) == cntrl && iswcntrl_l(ch, __l_))
+ break;
+ if ((m & upper) == upper && iswupper_l(ch, __l_))
+ break;
+ if ((m & lower) == lower && iswlower_l(ch, __l_))
+ break;
+ if ((m & alpha) == alpha && iswalpha_l(ch, __l_))
+ break;
+ if ((m & digit) == digit && iswdigit_l(ch, __l_))
+ break;
+ if ((m & punct) == punct && iswpunct_l(ch, __l_))
+ break;
+ if ((m & xdigit) == xdigit && iswxdigit_l(ch, __l_))
+ break;
+ if ((m & blank) == blank && iswblank_l(ch, __l_))
+ break;
+# endif
+ }
+ return low;
+}
+
+const wchar_t* ctype_byname<wchar_t>::do_scan_not(mask m, const char_type* low, const char_type* high) const {
+ for (; low != high; ++low) {
+# ifdef _LIBCPP_WCTYPE_IS_MASK
+ if (!iswctype_l(*low, m, __l_))
+ break;
+# else
+ wint_t ch = static_cast<wint_t>(*low);
+ if ((m & space) == space && iswspace_l(ch, __l_))
+ continue;
+ if ((m & print) == print && iswprint_l(ch, __l_))
+ continue;
+ if ((m & cntrl) == cntrl && iswcntrl_l(ch, __l_))
+ continue;
+ if ((m & upper) == upper && iswupper_l(ch, __l_))
+ continue;
+ if ((m & lower) == lower && iswlower_l(ch, __l_))
+ continue;
+ if ((m & alpha) == alpha && iswalpha_l(ch, __l_))
+ continue;
+ if ((m & digit) == digit && iswdigit_l(ch, __l_))
+ continue;
+ if ((m & punct) == punct && iswpunct_l(ch, __l_))
+ continue;
+ if ((m & xdigit) == xdigit && iswxdigit_l(ch, __l_))
+ continue;
+ if ((m & blank) == blank && iswblank_l(ch, __l_))
+ continue;
+ break;
+# endif
+ }
+ return low;
}
-wchar_t
-ctype_byname<wchar_t>::do_toupper(char_type c) const
-{
- return towupper_l(c, __l);
-}
+wchar_t ctype_byname<wchar_t>::do_toupper(char_type c) const { return towupper_l(c, __l_); }
-const wchar_t*
-ctype_byname<wchar_t>::do_toupper(char_type* low, const char_type* high) const
-{
- for (; low != high; ++low)
- *low = towupper_l(*low, __l);
- return low;
+const wchar_t* ctype_byname<wchar_t>::do_toupper(char_type* low, const char_type* high) const {
+ for (; low != high; ++low)
+ *low = towupper_l(*low, __l_);
+ return low;
}
-wchar_t
-ctype_byname<wchar_t>::do_tolower(char_type c) const
-{
- return towlower_l(c, __l);
-}
+wchar_t ctype_byname<wchar_t>::do_tolower(char_type c) const { return towlower_l(c, __l_); }
-const wchar_t*
-ctype_byname<wchar_t>::do_tolower(char_type* low, const char_type* high) const
-{
- for (; low != high; ++low)
- *low = towlower_l(*low, __l);
- return low;
+const wchar_t* ctype_byname<wchar_t>::do_tolower(char_type* low, const char_type* high) const {
+ for (; low != high; ++low)
+ *low = towlower_l(*low, __l_);
+ return low;
}
-wchar_t
-ctype_byname<wchar_t>::do_widen(char c) const
-{
- return __libcpp_btowc_l(c, __l);
-}
+wchar_t ctype_byname<wchar_t>::do_widen(char c) const { return __libcpp_btowc_l(c, __l_); }
-const char*
-ctype_byname<wchar_t>::do_widen(const char* low, const char* high, char_type* dest) const
-{
- for (; low != high; ++low, ++dest)
- *dest = __libcpp_btowc_l(*low, __l);
- return low;
+const char* ctype_byname<wchar_t>::do_widen(const char* low, const char* high, char_type* dest) const {
+ for (; low != high; ++low, ++dest)
+ *dest = __libcpp_btowc_l(*low, __l_);
+ return low;
}
-char
-ctype_byname<wchar_t>::do_narrow(char_type c, char dfault) const
-{
- int r = __libcpp_wctob_l(c, __l);
- return r != static_cast<int>(WEOF) ? static_cast<char>(r) : dfault;
+char ctype_byname<wchar_t>::do_narrow(char_type c, char dfault) const {
+ int r = __libcpp_wctob_l(c, __l_);
+ return (r != EOF) ? static_cast<char>(r) : dfault;
}
const wchar_t*
-ctype_byname<wchar_t>::do_narrow(const char_type* low, const char_type* high, char dfault, char* dest) const
-{
- for (; low != high; ++low, ++dest)
- {
- int r = __libcpp_wctob_l(*low, __l);
- *dest = r != static_cast<int>(WEOF) ? static_cast<char>(r) : dfault;
- }
- return low;
+ctype_byname<wchar_t>::do_narrow(const char_type* low, const char_type* high, char dfault, char* dest) const {
+ for (; low != high; ++low, ++dest) {
+ int r = __libcpp_wctob_l(*low, __l_);
+ *dest = (r != EOF) ? static_cast<char>(r) : dfault;
+ }
+ return low;
}
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
// 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()
-{
-}
+codecvt<char, char, mbstate_t>::~codecvt() {}
-codecvt<char, char, mbstate_t>::result
-codecvt<char, char, mbstate_t>::do_out(state_type&,
- const intern_type* frm, const intern_type*, const intern_type*& frm_nxt,
- extern_type* to, extern_type*, extern_type*& to_nxt) const
-{
- frm_nxt = frm;
- to_nxt = to;
- return noconv;
+codecvt<char, char, mbstate_t>::result codecvt<char, char, mbstate_t>::do_out(
+ state_type&,
+ const intern_type* frm,
+ const intern_type*,
+ const intern_type*& frm_nxt,
+ extern_type* to,
+ extern_type*,
+ extern_type*& to_nxt) const {
+ frm_nxt = frm;
+ to_nxt = to;
+ return noconv;
}
-codecvt<char, char, mbstate_t>::result
-codecvt<char, char, mbstate_t>::do_in(state_type&,
- const extern_type* frm, const extern_type*, const extern_type*& frm_nxt,
- intern_type* to, intern_type*, intern_type*& to_nxt) const
-{
- frm_nxt = frm;
- to_nxt = to;
- return noconv;
+codecvt<char, char, mbstate_t>::result codecvt<char, char, mbstate_t>::do_in(
+ state_type&,
+ const extern_type* frm,
+ const extern_type*,
+ const extern_type*& frm_nxt,
+ intern_type* to,
+ intern_type*,
+ intern_type*& to_nxt) const {
+ frm_nxt = frm;
+ to_nxt = to;
+ return noconv;
}
codecvt<char, char, mbstate_t>::result
-codecvt<char, char, mbstate_t>::do_unshift(state_type&,
- extern_type* to, extern_type*, extern_type*& to_nxt) const
-{
- to_nxt = to;
- return noconv;
+codecvt<char, char, mbstate_t>::do_unshift(state_type&, extern_type* to, extern_type*, extern_type*& to_nxt) const {
+ to_nxt = to;
+ return noconv;
}
-int
-codecvt<char, char, mbstate_t>::do_encoding() const _NOEXCEPT
-{
- return 1;
-}
+int codecvt<char, char, mbstate_t>::do_encoding() const noexcept { return 1; }
-bool
-codecvt<char, char, mbstate_t>::do_always_noconv() const _NOEXCEPT
-{
- return true;
-}
+bool codecvt<char, char, mbstate_t>::do_always_noconv() const noexcept { return true; }
-int
-codecvt<char, char, mbstate_t>::do_length(state_type&,
- const extern_type* frm, const extern_type* end, size_t mx) const
-{
- return static_cast<int>(min<size_t>(mx, static_cast<size_t>(end-frm)));
+int codecvt<char, char, mbstate_t>::do_length(
+ state_type&, const extern_type* frm, const extern_type* end, size_t mx) const {
+ return static_cast<int>(min<size_t>(mx, static_cast<size_t>(end - frm)));
}
-int
-codecvt<char, char, mbstate_t>::do_max_length() const _NOEXCEPT
-{
- return 1;
-}
+int codecvt<char, char, mbstate_t>::do_max_length() const noexcept { return 1; }
// template <> class codecvt<wchar_t, char, mbstate_t>
-locale::id codecvt<wchar_t, char, mbstate_t>::id;
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+constinit locale::id codecvt<wchar_t, char, mbstate_t>::id;
-codecvt<wchar_t, char, mbstate_t>::codecvt(size_t refs)
- : locale::facet(refs),
- __l(_LIBCPP_GET_C_LOCALE)
-{
-}
+codecvt<wchar_t, char, mbstate_t>::codecvt(size_t refs) : locale::facet(refs), __l_(_LIBCPP_GET_C_LOCALE) {}
codecvt<wchar_t, char, mbstate_t>::codecvt(const char* nm, size_t refs)
- : locale::facet(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));
-}
-
-codecvt<wchar_t, char, mbstate_t>::~codecvt()
-{
- if (__l != _LIBCPP_GET_C_LOCALE)
- freelocale(__l);
-}
-
-codecvt<wchar_t, char, mbstate_t>::result
-codecvt<wchar_t, char, mbstate_t>::do_out(state_type& st,
- const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
- extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
-{
- // look for first internal null in frm
- const intern_type* fend = frm;
- for (; fend != frm_end; ++fend)
- if (*fend == 0)
- break;
- // loop over all null-terminated sequences in frm
- to_nxt = to;
- for (frm_nxt = frm; frm != frm_end && to != to_end; frm = frm_nxt, to = to_nxt)
- {
- // save state in case it is needed to recover to_nxt on error
- mbstate_t save_state = st;
- size_t n = __libcpp_wcsnrtombs_l(to, &frm_nxt, static_cast<size_t>(fend-frm),
- static_cast<size_t>(to_end-to), &st, __l);
+ : locale::facet(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))
+ .c_str());
+}
+
+codecvt<wchar_t, char, mbstate_t>::~codecvt() {
+ if (__l_ != _LIBCPP_GET_C_LOCALE)
+ freelocale(__l_);
+}
+
+codecvt<wchar_t, char, mbstate_t>::result codecvt<wchar_t, char, mbstate_t>::do_out(
+ state_type& st,
+ const intern_type* frm,
+ const intern_type* frm_end,
+ const intern_type*& frm_nxt,
+ extern_type* to,
+ extern_type* to_end,
+ extern_type*& to_nxt) const {
+ // look for first internal null in frm
+ const intern_type* fend = frm;
+ for (; fend != frm_end; ++fend)
+ if (*fend == 0)
+ break;
+ // loop over all null-terminated sequences in frm
+ to_nxt = to;
+ for (frm_nxt = frm; frm != frm_end && to != to_end; frm = frm_nxt, to = to_nxt) {
+ // save state in case it is needed to recover to_nxt on error
+ mbstate_t save_state = st;
+ size_t n = __libcpp_wcsnrtombs_l(
+ to, &frm_nxt, static_cast<size_t>(fend - frm), static_cast<size_t>(to_end - to), &st, __l_);
+ if (n == size_t(-1)) {
+ // need to recover to_nxt
+ for (to_nxt = to; frm != frm_nxt; ++frm) {
+ n = __libcpp_wcrtomb_l(to_nxt, *frm, &save_state, __l_);
if (n == size_t(-1))
- {
- // need to recover to_nxt
- for (to_nxt = to; frm != frm_nxt; ++frm)
- {
- n = __libcpp_wcrtomb_l(to_nxt, *frm, &save_state, __l);
- if (n == size_t(-1))
- break;
- to_nxt += n;
- }
- frm_nxt = frm;
- return error;
- }
- if (n == 0)
- return partial;
+ break;
to_nxt += n;
- if (to_nxt == to_end)
- break;
- if (fend != frm_end) // set up next null terminated sequence
- {
- // Try to write the terminating null
- extern_type tmp[MB_LEN_MAX];
- n = __libcpp_wcrtomb_l(tmp, intern_type(), &st, __l);
- if (n == size_t(-1)) // on error
- return error;
- if (n > static_cast<size_t>(to_end-to_nxt)) // is there room?
- return partial;
- for (extern_type* p = tmp; n; --n) // write it
- *to_nxt++ = *p++;
- ++frm_nxt;
- // look for next null in frm
- for (fend = frm_nxt; fend != frm_end; ++fend)
- if (*fend == 0)
- break;
- }
+ }
+ frm_nxt = frm;
+ return error;
}
- return frm_nxt == frm_end ? ok : partial;
-}
-
-codecvt<wchar_t, char, mbstate_t>::result
-codecvt<wchar_t, char, mbstate_t>::do_in(state_type& st,
- const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
- intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
-{
- // look for first internal null in frm
- const extern_type* fend = frm;
- for (; fend != frm_end; ++fend)
- if (*fend == 0)
- break;
- // loop over all null-terminated sequences in frm
- to_nxt = to;
- for (frm_nxt = frm; frm != frm_end && to != to_end; frm = frm_nxt, to = to_nxt)
+ if (n == 0)
+ return partial;
+ to_nxt += n;
+ if (to_nxt == to_end)
+ break;
+ if (fend != frm_end) // set up next null terminated sequence
{
- // save state in case it is needed to recover to_nxt on error
- mbstate_t save_state = st;
- size_t n = __libcpp_mbsnrtowcs_l(to, &frm_nxt, static_cast<size_t>(fend-frm),
- static_cast<size_t>(to_end-to), &st, __l);
- if (n == size_t(-1))
- {
- // need to recover to_nxt
- for (to_nxt = to; frm != frm_nxt; ++to_nxt)
- {
- n = __libcpp_mbrtowc_l(to_nxt, frm, static_cast<size_t>(fend-frm),
- &save_state, __l);
- switch (n)
- {
- case 0:
- ++frm;
- break;
- case size_t(-1):
- frm_nxt = frm;
- return error;
- case size_t(-2):
- frm_nxt = frm;
- return partial;
- default:
- frm += n;
- break;
- }
- }
- frm_nxt = frm;
- return frm_nxt == frm_end ? ok : partial;
- }
- if (n == size_t(-1))
- return error;
- to_nxt += n;
- if (to_nxt == to_end)
- break;
- if (fend != frm_end) // set up next null terminated sequence
- {
- // Try to write the terminating null
- n = __libcpp_mbrtowc_l(to_nxt, frm_nxt, 1, &st, __l);
- if (n != 0) // on error
- return error;
- ++to_nxt;
- ++frm_nxt;
- // look for next null in frm
- for (fend = frm_nxt; fend != frm_end; ++fend)
- if (*fend == 0)
- break;
- }
- }
- return frm_nxt == frm_end ? ok : partial;
-}
-
-codecvt<wchar_t, char, mbstate_t>::result
-codecvt<wchar_t, char, mbstate_t>::do_unshift(state_type& st,
- extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
-{
- to_nxt = to;
- extern_type tmp[MB_LEN_MAX];
- size_t n = __libcpp_wcrtomb_l(tmp, intern_type(), &st, __l);
- if (n == size_t(-1) || n == 0) // on error
+ // Try to write the terminating null
+ extern_type tmp[MB_LEN_MAX];
+ n = __libcpp_wcrtomb_l(tmp, intern_type(), &st, __l_);
+ if (n == size_t(-1)) // on error
return error;
- --n;
- if (n > static_cast<size_t>(to_end-to_nxt)) // is there room?
+ if (n > static_cast<size_t>(to_end - to_nxt)) // is there room?
return partial;
- for (extern_type* p = tmp; n; --n) // write it
+ for (extern_type* p = tmp; n; --n) // write it
*to_nxt++ = *p++;
- return ok;
-}
-
-int
-codecvt<wchar_t, char, mbstate_t>::do_encoding() const _NOEXCEPT
-{
- if (__libcpp_mbtowc_l(nullptr, nullptr, MB_LEN_MAX, __l) != 0)
- return -1;
-
- // stateless encoding
- if (__l == 0 || __libcpp_mb_cur_max_l(__l) == 1) // there are no known constant length encodings
- return 1; // which take more than 1 char to form a wchar_t
- return 0;
-}
-
-bool
-codecvt<wchar_t, char, mbstate_t>::do_always_noconv() const _NOEXCEPT
-{
- return false;
-}
-
-int
-codecvt<wchar_t, char, mbstate_t>::do_length(state_type& st,
- const extern_type* frm, const extern_type* frm_end, size_t mx) const
-{
- int nbytes = 0;
- for (size_t nwchar_t = 0; nwchar_t < mx && frm != frm_end; ++nwchar_t)
- {
- size_t n = __libcpp_mbrlen_l(frm, static_cast<size_t>(frm_end-frm), &st, __l);
- switch (n)
- {
+ ++frm_nxt;
+ // look for next null in frm
+ for (fend = frm_nxt; fend != frm_end; ++fend)
+ if (*fend == 0)
+ break;
+ }
+ }
+ return frm_nxt == frm_end ? ok : partial;
+}
+
+codecvt<wchar_t, char, mbstate_t>::result codecvt<wchar_t, char, mbstate_t>::do_in(
+ state_type& st,
+ const extern_type* frm,
+ const extern_type* frm_end,
+ const extern_type*& frm_nxt,
+ intern_type* to,
+ intern_type* to_end,
+ intern_type*& to_nxt) const {
+ // look for first internal null in frm
+ const extern_type* fend = frm;
+ for (; fend != frm_end; ++fend)
+ if (*fend == 0)
+ break;
+ // loop over all null-terminated sequences in frm
+ to_nxt = to;
+ for (frm_nxt = frm; frm != frm_end && to != to_end; frm = frm_nxt, to = to_nxt) {
+ // save state in case it is needed to recover to_nxt on error
+ mbstate_t save_state = st;
+ size_t n = __libcpp_mbsnrtowcs_l(
+ to, &frm_nxt, static_cast<size_t>(fend - frm), static_cast<size_t>(to_end - to), &st, __l_);
+ if (n == size_t(-1)) {
+ // need to recover to_nxt
+ for (to_nxt = to; frm != frm_nxt; ++to_nxt) {
+ n = __libcpp_mbrtowc_l(to_nxt, frm, static_cast<size_t>(fend - frm), &save_state, __l_);
+ switch (n) {
case 0:
- ++nbytes;
- ++frm;
- break;
+ ++frm;
+ break;
case size_t(-1):
+ frm_nxt = frm;
+ return error;
case size_t(-2):
- return nbytes;
+ frm_nxt = frm;
+ return partial;
default:
- nbytes += n;
- frm += n;
- break;
+ frm += n;
+ break;
}
+ }
+ frm_nxt = frm;
+ return frm_nxt == frm_end ? ok : partial;
+ }
+ if (n == size_t(-1))
+ return error;
+ to_nxt += n;
+ if (to_nxt == to_end)
+ break;
+ if (fend != frm_end) // set up next null terminated sequence
+ {
+ // Try to write the terminating null
+ n = __libcpp_mbrtowc_l(to_nxt, frm_nxt, 1, &st, __l_);
+ if (n != 0) // on error
+ return error;
+ ++to_nxt;
+ ++frm_nxt;
+ // look for next null in frm
+ for (fend = frm_nxt; fend != frm_end; ++fend)
+ if (*fend == 0)
+ break;
+ }
+ }
+ return frm_nxt == frm_end ? ok : partial;
+}
+
+codecvt<wchar_t, char, mbstate_t>::result codecvt<wchar_t, char, mbstate_t>::do_unshift(
+ state_type& st, extern_type* to, extern_type* to_end, extern_type*& to_nxt) const {
+ to_nxt = to;
+ extern_type tmp[MB_LEN_MAX];
+ size_t n = __libcpp_wcrtomb_l(tmp, intern_type(), &st, __l_);
+ if (n == size_t(-1) || n == 0) // on error
+ return error;
+ --n;
+ if (n > static_cast<size_t>(to_end - to_nxt)) // is there room?
+ return partial;
+ for (extern_type* p = tmp; n; --n) // write it
+ *to_nxt++ = *p++;
+ return ok;
+}
+
+int codecvt<wchar_t, char, mbstate_t>::do_encoding() const noexcept {
+ if (__libcpp_mbtowc_l(nullptr, nullptr, MB_LEN_MAX, __l_) != 0)
+ return -1;
+
+ // stateless encoding
+ if (__l_ == 0 || __libcpp_mb_cur_max_l(__l_) == 1) // there are no known constant length encodings
+ return 1; // which take more than 1 char to form a wchar_t
+ return 0;
+}
+
+bool codecvt<wchar_t, char, mbstate_t>::do_always_noconv() const noexcept { return false; }
+
+int codecvt<wchar_t, char, mbstate_t>::do_length(
+ state_type& st, const extern_type* frm, const extern_type* frm_end, size_t mx) const {
+ int nbytes = 0;
+ for (size_t nwchar_t = 0; nwchar_t < mx && frm != frm_end; ++nwchar_t) {
+ size_t n = __libcpp_mbrlen_l(frm, static_cast<size_t>(frm_end - frm), &st, __l_);
+ switch (n) {
+ case 0:
+ ++nbytes;
+ ++frm;
+ break;
+ case size_t(-1):
+ case size_t(-2):
+ return nbytes;
+ default:
+ nbytes += n;
+ frm += n;
+ break;
}
- return nbytes;
+ }
+ return nbytes;
}
-int
-codecvt<wchar_t, char, mbstate_t>::do_max_length() const _NOEXCEPT
-{
- return __l == 0 ? 1 : static_cast<int>(__libcpp_mb_cur_max_l(__l));
+int codecvt<wchar_t, char, mbstate_t>::do_max_length() const noexcept {
+ return __l_ == 0 ? 1 : static_cast<int>(__libcpp_mb_cur_max_l(__l_));
}
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
// Valid UTF ranges
// UTF-32 UTF-16 UTF-8 # of code points
@@ -1745,2642 +1542,2398 @@ codecvt<wchar_t, char, mbstate_t>::do_max_length() const _NOEXCEPT
// 040000 - 0FFFFF D8C0 - DBBF, DC00 - DFFF F1 - F3, 80 - BF, 80 - BF, 80 - BF 786432
// 100000 - 10FFFF DBC0 - DBFF, DC00 - DFFF F4 - F4, 80 - 8F, 80 - BF, 80 - BF 65536
-static
-codecvt_base::result
-utf16_to_utf8(const uint16_t* frm, const uint16_t* frm_end, const uint16_t*& frm_nxt,
- uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
- unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
-{
- frm_nxt = frm;
- to_nxt = to;
- if (mode & generate_header)
- {
- if (to_end-to_nxt < 3)
- return codecvt_base::partial;
- *to_nxt++ = static_cast<uint8_t>(0xEF);
- *to_nxt++ = static_cast<uint8_t>(0xBB);
- *to_nxt++ = static_cast<uint8_t>(0xBF);
- }
- for (; frm_nxt < frm_end; ++frm_nxt)
- {
- uint16_t wc1 = *frm_nxt;
- if (wc1 > Maxcode)
- return codecvt_base::error;
- if (wc1 < 0x0080)
- {
- if (to_end-to_nxt < 1)
- return codecvt_base::partial;
- *to_nxt++ = static_cast<uint8_t>(wc1);
- }
- else if (wc1 < 0x0800)
- {
- if (to_end-to_nxt < 2)
- return codecvt_base::partial;
- *to_nxt++ = static_cast<uint8_t>(0xC0 | (wc1 >> 6));
- *to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x03F));
- }
- else if (wc1 < 0xD800)
- {
- if (to_end-to_nxt < 3)
- return codecvt_base::partial;
- *to_nxt++ = static_cast<uint8_t>(0xE0 | (wc1 >> 12));
- *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0FC0) >> 6));
- *to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x003F));
- }
- else if (wc1 < 0xDC00)
- {
- if (frm_end-frm_nxt < 2)
- return codecvt_base::partial;
- uint16_t wc2 = frm_nxt[1];
- if ((wc2 & 0xFC00) != 0xDC00)
- return codecvt_base::error;
- if (to_end-to_nxt < 4)
- return codecvt_base::partial;
- if (((((wc1 & 0x03C0UL) >> 6) + 1) << 16) +
- ((wc1 & 0x003FUL) << 10) + (wc2 & 0x03FF) > Maxcode)
- return codecvt_base::error;
- ++frm_nxt;
- uint8_t z = ((wc1 & 0x03C0) >> 6) + 1;
- *to_nxt++ = static_cast<uint8_t>(0xF0 | (z >> 2));
- *to_nxt++ = static_cast<uint8_t>(0x80 | ((z & 0x03) << 4) | ((wc1 & 0x003C) >> 2));
- *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0003) << 4) | ((wc2 & 0x03C0) >> 6));
- *to_nxt++ = static_cast<uint8_t>(0x80 | (wc2 & 0x003F));
- }
- else if (wc1 < 0xE000)
- {
- return codecvt_base::error;
- }
- else
- {
- if (to_end-to_nxt < 3)
- return codecvt_base::partial;
- *to_nxt++ = static_cast<uint8_t>(0xE0 | (wc1 >> 12));
- *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0FC0) >> 6));
- *to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x003F));
- }
- }
- return codecvt_base::ok;
-}
-
-static
-codecvt_base::result
-utf16_to_utf8(const uint32_t* frm, const uint32_t* frm_end, const uint32_t*& frm_nxt,
- uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
- unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
-{
- frm_nxt = frm;
- to_nxt = to;
- if (mode & generate_header)
- {
- if (to_end-to_nxt < 3)
- return codecvt_base::partial;
- *to_nxt++ = static_cast<uint8_t>(0xEF);
- *to_nxt++ = static_cast<uint8_t>(0xBB);
- *to_nxt++ = static_cast<uint8_t>(0xBF);
- }
- for (; frm_nxt < frm_end; ++frm_nxt)
- {
- uint16_t wc1 = static_cast<uint16_t>(*frm_nxt);
- if (wc1 > Maxcode)
- return codecvt_base::error;
- if (wc1 < 0x0080)
- {
- if (to_end-to_nxt < 1)
- return codecvt_base::partial;
- *to_nxt++ = static_cast<uint8_t>(wc1);
- }
- else if (wc1 < 0x0800)
- {
- if (to_end-to_nxt < 2)
- return codecvt_base::partial;
- *to_nxt++ = static_cast<uint8_t>(0xC0 | (wc1 >> 6));
- *to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x03F));
- }
- else if (wc1 < 0xD800)
- {
- if (to_end-to_nxt < 3)
- return codecvt_base::partial;
- *to_nxt++ = static_cast<uint8_t>(0xE0 | (wc1 >> 12));
- *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0FC0) >> 6));
- *to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x003F));
- }
- else if (wc1 < 0xDC00)
- {
- if (frm_end-frm_nxt < 2)
- return codecvt_base::partial;
- uint16_t wc2 = static_cast<uint16_t>(frm_nxt[1]);
- if ((wc2 & 0xFC00) != 0xDC00)
- return codecvt_base::error;
- if (to_end-to_nxt < 4)
- return codecvt_base::partial;
- if (((((wc1 & 0x03C0UL) >> 6) + 1) << 16) +
- ((wc1 & 0x003FUL) << 10) + (wc2 & 0x03FF) > Maxcode)
- return codecvt_base::error;
- ++frm_nxt;
- uint8_t z = ((wc1 & 0x03C0) >> 6) + 1;
- *to_nxt++ = static_cast<uint8_t>(0xF0 | (z >> 2));
- *to_nxt++ = static_cast<uint8_t>(0x80 | ((z & 0x03) << 4) | ((wc1 & 0x003C) >> 2));
- *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0003) << 4) | ((wc2 & 0x03C0) >> 6));
- *to_nxt++ = static_cast<uint8_t>(0x80 | (wc2 & 0x003F));
- }
- else if (wc1 < 0xE000)
- {
- return codecvt_base::error;
- }
- else
- {
- if (to_end-to_nxt < 3)
- return codecvt_base::partial;
- *to_nxt++ = static_cast<uint8_t>(0xE0 | (wc1 >> 12));
- *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0FC0) >> 6));
- *to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x003F));
- }
- }
- return codecvt_base::ok;
-}
-
-static
-codecvt_base::result
-utf8_to_utf16(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
- uint16_t* to, uint16_t* to_end, uint16_t*& to_nxt,
- unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
-{
- frm_nxt = frm;
- to_nxt = to;
- if (mode & consume_header)
- {
- if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
- frm_nxt[2] == 0xBF)
- frm_nxt += 3;
- }
- for (; frm_nxt < frm_end && to_nxt < to_end; ++to_nxt)
- {
- uint8_t c1 = *frm_nxt;
- if (c1 > Maxcode)
- return codecvt_base::error;
- if (c1 < 0x80)
- {
- *to_nxt = static_cast<uint16_t>(c1);
- ++frm_nxt;
- }
- else if (c1 < 0xC2)
- {
- return codecvt_base::error;
- }
- else if (c1 < 0xE0)
- {
- if (frm_end-frm_nxt < 2)
- return codecvt_base::partial;
- uint8_t c2 = frm_nxt[1];
- if ((c2 & 0xC0) != 0x80)
- return codecvt_base::error;
- uint16_t t = static_cast<uint16_t>(((c1 & 0x1F) << 6) | (c2 & 0x3F));
- if (t > Maxcode)
- return codecvt_base::error;
- *to_nxt = t;
- frm_nxt += 2;
- }
- else if (c1 < 0xF0)
- {
- if (frm_end-frm_nxt < 3)
- return codecvt_base::partial;
- uint8_t c2 = frm_nxt[1];
- uint8_t c3 = frm_nxt[2];
- switch (c1)
- {
- case 0xE0:
- if ((c2 & 0xE0) != 0xA0)
- return codecvt_base::error;
- break;
- case 0xED:
- if ((c2 & 0xE0) != 0x80)
- return codecvt_base::error;
- break;
- default:
- if ((c2 & 0xC0) != 0x80)
- return codecvt_base::error;
- break;
- }
- if ((c3 & 0xC0) != 0x80)
- return codecvt_base::error;
- uint16_t t = static_cast<uint16_t>(((c1 & 0x0F) << 12)
- | ((c2 & 0x3F) << 6)
- | (c3 & 0x3F));
- if (t > Maxcode)
- return codecvt_base::error;
- *to_nxt = t;
- frm_nxt += 3;
- }
- else if (c1 < 0xF5)
- {
- if (frm_end-frm_nxt < 4)
- return codecvt_base::partial;
- uint8_t c2 = frm_nxt[1];
- uint8_t c3 = frm_nxt[2];
- uint8_t c4 = frm_nxt[3];
- switch (c1)
- {
- case 0xF0:
- if (!(0x90 <= c2 && c2 <= 0xBF))
- return codecvt_base::error;
- break;
- case 0xF4:
- if ((c2 & 0xF0) != 0x80)
- return codecvt_base::error;
- break;
- default:
- if ((c2 & 0xC0) != 0x80)
- return codecvt_base::error;
- break;
- }
- if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80)
- return codecvt_base::error;
- if (to_end-to_nxt < 2)
- return codecvt_base::partial;
- if ((((c1 & 7UL) << 18) +
- ((c2 & 0x3FUL) << 12) +
- ((c3 & 0x3FUL) << 6) + (c4 & 0x3F)) > Maxcode)
- return codecvt_base::error;
- *to_nxt = static_cast<uint16_t>(
- 0xD800
- | (((((c1 & 0x07) << 2) | ((c2 & 0x30) >> 4)) - 1) << 6)
- | ((c2 & 0x0F) << 2)
- | ((c3 & 0x30) >> 4));
- *++to_nxt = static_cast<uint16_t>(
- 0xDC00
- | ((c3 & 0x0F) << 6)
- | (c4 & 0x3F));
- frm_nxt += 4;
- }
- else
- {
- return codecvt_base::error;
- }
- }
- return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
-}
-
-static
-codecvt_base::result
-utf8_to_utf16(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
- uint32_t* to, uint32_t* to_end, uint32_t*& to_nxt,
- unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
-{
- frm_nxt = frm;
- to_nxt = to;
- if (mode & consume_header)
- {
- if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
- frm_nxt[2] == 0xBF)
- frm_nxt += 3;
- }
- for (; frm_nxt < frm_end && to_nxt < to_end; ++to_nxt)
- {
- uint8_t c1 = *frm_nxt;
- if (c1 > Maxcode)
- return codecvt_base::error;
- if (c1 < 0x80)
- {
- *to_nxt = static_cast<uint32_t>(c1);
- ++frm_nxt;
- }
- else if (c1 < 0xC2)
- {
- return codecvt_base::error;
- }
- else if (c1 < 0xE0)
- {
- if (frm_end-frm_nxt < 2)
- return codecvt_base::partial;
- uint8_t c2 = frm_nxt[1];
- if ((c2 & 0xC0) != 0x80)
- return codecvt_base::error;
- uint16_t t = static_cast<uint16_t>(((c1 & 0x1F) << 6) | (c2 & 0x3F));
- if (t > Maxcode)
- return codecvt_base::error;
- *to_nxt = static_cast<uint32_t>(t);
- frm_nxt += 2;
- }
- else if (c1 < 0xF0)
- {
- if (frm_end-frm_nxt < 3)
- return codecvt_base::partial;
- uint8_t c2 = frm_nxt[1];
- uint8_t c3 = frm_nxt[2];
- switch (c1)
- {
- case 0xE0:
- if ((c2 & 0xE0) != 0xA0)
- return codecvt_base::error;
- break;
- case 0xED:
- if ((c2 & 0xE0) != 0x80)
- return codecvt_base::error;
- break;
- default:
- if ((c2 & 0xC0) != 0x80)
- return codecvt_base::error;
- break;
- }
- if ((c3 & 0xC0) != 0x80)
- return codecvt_base::error;
- uint16_t t = static_cast<uint16_t>(((c1 & 0x0F) << 12)
- | ((c2 & 0x3F) << 6)
- | (c3 & 0x3F));
- if (t > Maxcode)
- return codecvt_base::error;
- *to_nxt = static_cast<uint32_t>(t);
- frm_nxt += 3;
- }
- else if (c1 < 0xF5)
- {
- if (frm_end-frm_nxt < 4)
- return codecvt_base::partial;
- uint8_t c2 = frm_nxt[1];
- uint8_t c3 = frm_nxt[2];
- uint8_t c4 = frm_nxt[3];
- switch (c1)
- {
- case 0xF0:
- if (!(0x90 <= c2 && c2 <= 0xBF))
- return codecvt_base::error;
- break;
- case 0xF4:
- if ((c2 & 0xF0) != 0x80)
- return codecvt_base::error;
- break;
- default:
- if ((c2 & 0xC0) != 0x80)
- return codecvt_base::error;
- break;
- }
- if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80)
- return codecvt_base::error;
- if (to_end-to_nxt < 2)
- return codecvt_base::partial;
- if ((((c1 & 7UL) << 18) +
- ((c2 & 0x3FUL) << 12) +
- ((c3 & 0x3FUL) << 6) + (c4 & 0x3F)) > Maxcode)
- return codecvt_base::error;
- *to_nxt = static_cast<uint32_t>(
- 0xD800
- | (((((c1 & 0x07) << 2) | ((c2 & 0x30) >> 4)) - 1) << 6)
- | ((c2 & 0x0F) << 2)
- | ((c3 & 0x30) >> 4));
- *++to_nxt = static_cast<uint32_t>(
- 0xDC00
- | ((c3 & 0x0F) << 6)
- | (c4 & 0x3F));
- frm_nxt += 4;
- }
- else
- {
- return codecvt_base::error;
- }
- }
- return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
-}
-
-static
-int
-utf8_to_utf16_length(const uint8_t* frm, const uint8_t* frm_end,
- size_t mx, unsigned long Maxcode = 0x10FFFF,
- codecvt_mode mode = codecvt_mode(0))
-{
- const uint8_t* frm_nxt = frm;
- if (mode & consume_header)
- {
- if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
- frm_nxt[2] == 0xBF)
- frm_nxt += 3;
- }
- for (size_t nchar16_t = 0; frm_nxt < frm_end && nchar16_t < mx; ++nchar16_t)
- {
- uint8_t c1 = *frm_nxt;
- if (c1 > Maxcode)
- break;
- if (c1 < 0x80)
- {
- ++frm_nxt;
- }
- else if (c1 < 0xC2)
- {
- break;
- }
- else if (c1 < 0xE0)
- {
- if ((frm_end-frm_nxt < 2) || (frm_nxt[1] & 0xC0) != 0x80)
- break;
- uint16_t t = static_cast<uint16_t>(((c1 & 0x1F) << 6) | (frm_nxt[1] & 0x3F));
- if (t > Maxcode)
- break;
- frm_nxt += 2;
- }
- else if (c1 < 0xF0)
- {
- if (frm_end-frm_nxt < 3)
- break;
- uint8_t c2 = frm_nxt[1];
- uint8_t c3 = frm_nxt[2];
- switch (c1)
- {
- case 0xE0:
- if ((c2 & 0xE0) != 0xA0)
- return static_cast<int>(frm_nxt - frm);
- break;
- case 0xED:
- if ((c2 & 0xE0) != 0x80)
- return static_cast<int>(frm_nxt - frm);
- break;
- default:
- if ((c2 & 0xC0) != 0x80)
- return static_cast<int>(frm_nxt - frm);
- break;
- }
- if ((c3 & 0xC0) != 0x80)
- break;
- if ((((c1 & 0x0Fu) << 12) | ((c2 & 0x3Fu) << 6) | (c3 & 0x3Fu)) > Maxcode)
- break;
- frm_nxt += 3;
- }
- else if (c1 < 0xF5)
- {
- if (frm_end-frm_nxt < 4 || mx-nchar16_t < 2)
- break;
- uint8_t c2 = frm_nxt[1];
- uint8_t c3 = frm_nxt[2];
- uint8_t c4 = frm_nxt[3];
- switch (c1)
- {
- case 0xF0:
- if (!(0x90 <= c2 && c2 <= 0xBF))
- return static_cast<int>(frm_nxt - frm);
- break;
- case 0xF4:
- if ((c2 & 0xF0) != 0x80)
- return static_cast<int>(frm_nxt - frm);
- break;
- default:
- if ((c2 & 0xC0) != 0x80)
- return static_cast<int>(frm_nxt - frm);
- break;
- }
- if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80)
- break;
- if ((((c1 & 7UL) << 18) +
- ((c2 & 0x3FUL) << 12) +
- ((c3 & 0x3FUL) << 6) + (c4 & 0x3F)) > Maxcode)
- break;
- ++nchar16_t;
- frm_nxt += 4;
- }
- else
- {
- break;
- }
- }
- return static_cast<int>(frm_nxt - frm);
-}
-
-static
-codecvt_base::result
-ucs4_to_utf8(const uint32_t* frm, const uint32_t* frm_end, const uint32_t*& frm_nxt,
- uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
- unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
-{
- frm_nxt = frm;
- to_nxt = to;
- if (mode & generate_header)
- {
- if (to_end-to_nxt < 3)
- return codecvt_base::partial;
- *to_nxt++ = static_cast<uint8_t>(0xEF);
- *to_nxt++ = static_cast<uint8_t>(0xBB);
- *to_nxt++ = static_cast<uint8_t>(0xBF);
- }
- for (; frm_nxt < frm_end; ++frm_nxt)
- {
- uint32_t wc = *frm_nxt;
- if ((wc & 0xFFFFF800) == 0x00D800 || wc > Maxcode)
- return codecvt_base::error;
- if (wc < 0x000080)
- {
- if (to_end-to_nxt < 1)
- return codecvt_base::partial;
- *to_nxt++ = static_cast<uint8_t>(wc);
- }
- else if (wc < 0x000800)
- {
- if (to_end-to_nxt < 2)
- return codecvt_base::partial;
- *to_nxt++ = static_cast<uint8_t>(0xC0 | (wc >> 6));
- *to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x03F));
- }
- else if (wc < 0x010000)
- {
- if (to_end-to_nxt < 3)
- return codecvt_base::partial;
- *to_nxt++ = static_cast<uint8_t>(0xE0 | (wc >> 12));
- *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc & 0x0FC0) >> 6));
- *to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x003F));
- }
- else // if (wc < 0x110000)
- {
- if (to_end-to_nxt < 4)
- return codecvt_base::partial;
- *to_nxt++ = static_cast<uint8_t>(0xF0 | (wc >> 18));
- *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc & 0x03F000) >> 12));
- *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc & 0x000FC0) >> 6));
- *to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x00003F));
- }
- }
- return codecvt_base::ok;
-}
-
-static
-codecvt_base::result
-utf8_to_ucs4(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
- uint32_t* to, uint32_t* to_end, uint32_t*& to_nxt,
- unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
-{
- frm_nxt = frm;
- to_nxt = to;
- if (mode & consume_header)
- {
- if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
- frm_nxt[2] == 0xBF)
- frm_nxt += 3;
- }
- for (; frm_nxt < frm_end && to_nxt < to_end; ++to_nxt)
- {
- uint8_t c1 = static_cast<uint8_t>(*frm_nxt);
- if (c1 < 0x80)
- {
- if (c1 > Maxcode)
- return codecvt_base::error;
- *to_nxt = static_cast<uint32_t>(c1);
- ++frm_nxt;
- }
- else if (c1 < 0xC2)
- {
- return codecvt_base::error;
- }
- else if (c1 < 0xE0)
- {
- if (frm_end-frm_nxt < 2)
- return codecvt_base::partial;
- uint8_t c2 = frm_nxt[1];
- if ((c2 & 0xC0) != 0x80)
- return codecvt_base::error;
- uint32_t t = static_cast<uint32_t>(((c1 & 0x1F) << 6)
- | (c2 & 0x3F));
- if (t > Maxcode)
- return codecvt_base::error;
- *to_nxt = t;
- frm_nxt += 2;
- }
- else if (c1 < 0xF0)
- {
- if (frm_end-frm_nxt < 3)
- return codecvt_base::partial;
- uint8_t c2 = frm_nxt[1];
- uint8_t c3 = frm_nxt[2];
- switch (c1)
- {
- case 0xE0:
- if ((c2 & 0xE0) != 0xA0)
- return codecvt_base::error;
- break;
- case 0xED:
- if ((c2 & 0xE0) != 0x80)
- return codecvt_base::error;
- break;
- default:
- if ((c2 & 0xC0) != 0x80)
- return codecvt_base::error;
- break;
- }
- if ((c3 & 0xC0) != 0x80)
- return codecvt_base::error;
- uint32_t t = static_cast<uint32_t>(((c1 & 0x0F) << 12)
- | ((c2 & 0x3F) << 6)
- | (c3 & 0x3F));
- if (t > Maxcode)
- return codecvt_base::error;
- *to_nxt = t;
- frm_nxt += 3;
- }
- else if (c1 < 0xF5)
- {
- if (frm_end-frm_nxt < 4)
- return codecvt_base::partial;
- uint8_t c2 = frm_nxt[1];
- uint8_t c3 = frm_nxt[2];
- uint8_t c4 = frm_nxt[3];
- switch (c1)
- {
- case 0xF0:
- if (!(0x90 <= c2 && c2 <= 0xBF))
- return codecvt_base::error;
- break;
- case 0xF4:
- if ((c2 & 0xF0) != 0x80)
- return codecvt_base::error;
- break;
- default:
- if ((c2 & 0xC0) != 0x80)
- return codecvt_base::error;
- break;
- }
- if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80)
- return codecvt_base::error;
- uint32_t t = static_cast<uint32_t>(((c1 & 0x07) << 18)
- | ((c2 & 0x3F) << 12)
- | ((c3 & 0x3F) << 6)
- | (c4 & 0x3F));
- if (t > Maxcode)
- return codecvt_base::error;
- *to_nxt = t;
- frm_nxt += 4;
- }
- else
- {
- return codecvt_base::error;
- }
- }
- return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
-}
-
-static
-int
-utf8_to_ucs4_length(const uint8_t* frm, const uint8_t* frm_end,
- size_t mx, unsigned long Maxcode = 0x10FFFF,
- codecvt_mode mode = codecvt_mode(0))
-{
- const uint8_t* frm_nxt = frm;
- if (mode & consume_header)
- {
- if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
- frm_nxt[2] == 0xBF)
- frm_nxt += 3;
- }
- for (size_t nchar32_t = 0; frm_nxt < frm_end && nchar32_t < mx; ++nchar32_t)
- {
- uint8_t c1 = static_cast<uint8_t>(*frm_nxt);
- if (c1 < 0x80)
- {
- if (c1 > Maxcode)
- break;
- ++frm_nxt;
- }
- else if (c1 < 0xC2)
- {
- break;
- }
- else if (c1 < 0xE0)
- {
- if ((frm_end-frm_nxt < 2) || ((frm_nxt[1] & 0xC0) != 0x80))
- break;
- if ((((c1 & 0x1Fu) << 6) | (frm_nxt[1] & 0x3Fu)) > Maxcode)
- break;
- frm_nxt += 2;
- }
- else if (c1 < 0xF0)
- {
- if (frm_end-frm_nxt < 3)
- break;
- uint8_t c2 = frm_nxt[1];
- uint8_t c3 = frm_nxt[2];
- switch (c1)
- {
- case 0xE0:
- if ((c2 & 0xE0) != 0xA0)
- return static_cast<int>(frm_nxt - frm);
- break;
- case 0xED:
- if ((c2 & 0xE0) != 0x80)
- return static_cast<int>(frm_nxt - frm);
- break;
- default:
- if ((c2 & 0xC0) != 0x80)
- return static_cast<int>(frm_nxt - frm);
- break;
- }
- if ((c3 & 0xC0) != 0x80)
- break;
- if ((((c1 & 0x0Fu) << 12) | ((c2 & 0x3Fu) << 6) | (c3 & 0x3Fu)) > Maxcode)
- break;
- frm_nxt += 3;
- }
- else if (c1 < 0xF5)
- {
- if (frm_end-frm_nxt < 4)
- break;
- uint8_t c2 = frm_nxt[1];
- uint8_t c3 = frm_nxt[2];
- uint8_t c4 = frm_nxt[3];
- switch (c1)
- {
- case 0xF0:
- if (!(0x90 <= c2 && c2 <= 0xBF))
- return static_cast<int>(frm_nxt - frm);
- break;
- case 0xF4:
- if ((c2 & 0xF0) != 0x80)
- return static_cast<int>(frm_nxt - frm);
- break;
- default:
- if ((c2 & 0xC0) != 0x80)
- return static_cast<int>(frm_nxt - frm);
- break;
- }
- if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80)
- break;
- if ((((c1 & 0x07u) << 18) | ((c2 & 0x3Fu) << 12) |
- ((c3 & 0x3Fu) << 6) | (c4 & 0x3Fu)) > Maxcode)
- break;
- frm_nxt += 4;
- }
- else
- {
- break;
- }
- }
- return static_cast<int>(frm_nxt - frm);
-}
-
-static
-codecvt_base::result
-ucs2_to_utf8(const uint16_t* frm, const uint16_t* frm_end, const uint16_t*& frm_nxt,
- uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
- unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
-{
- frm_nxt = frm;
- to_nxt = to;
- if (mode & generate_header)
- {
- if (to_end-to_nxt < 3)
- return codecvt_base::partial;
- *to_nxt++ = static_cast<uint8_t>(0xEF);
- *to_nxt++ = static_cast<uint8_t>(0xBB);
- *to_nxt++ = static_cast<uint8_t>(0xBF);
- }
- for (; frm_nxt < frm_end; ++frm_nxt)
- {
- uint16_t wc = *frm_nxt;
- if ((wc & 0xF800) == 0xD800 || wc > Maxcode)
- return codecvt_base::error;
- if (wc < 0x0080)
- {
- if (to_end-to_nxt < 1)
- return codecvt_base::partial;
- *to_nxt++ = static_cast<uint8_t>(wc);
- }
- else if (wc < 0x0800)
- {
- if (to_end-to_nxt < 2)
- return codecvt_base::partial;
- *to_nxt++ = static_cast<uint8_t>(0xC0 | (wc >> 6));
- *to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x03F));
- }
- else // if (wc <= 0xFFFF)
- {
- if (to_end-to_nxt < 3)
- return codecvt_base::partial;
- *to_nxt++ = static_cast<uint8_t>(0xE0 | (wc >> 12));
- *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc & 0x0FC0) >> 6));
- *to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x003F));
- }
- }
- return codecvt_base::ok;
-}
-
-static
-codecvt_base::result
-utf8_to_ucs2(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
- uint16_t* to, uint16_t* to_end, uint16_t*& to_nxt,
- unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
-{
- frm_nxt = frm;
- to_nxt = to;
- if (mode & consume_header)
- {
- if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
- frm_nxt[2] == 0xBF)
- frm_nxt += 3;
- }
- for (; frm_nxt < frm_end && to_nxt < to_end; ++to_nxt)
- {
- uint8_t c1 = static_cast<uint8_t>(*frm_nxt);
- if (c1 < 0x80)
- {
- if (c1 > Maxcode)
- return codecvt_base::error;
- *to_nxt = static_cast<uint16_t>(c1);
- ++frm_nxt;
- }
- else if (c1 < 0xC2)
- {
- return codecvt_base::error;
- }
- else if (c1 < 0xE0)
- {
- if (frm_end-frm_nxt < 2)
- return codecvt_base::partial;
- uint8_t c2 = frm_nxt[1];
- if ((c2 & 0xC0) != 0x80)
- return codecvt_base::error;
- uint16_t t = static_cast<uint16_t>(((c1 & 0x1F) << 6)
- | (c2 & 0x3F));
- if (t > Maxcode)
- return codecvt_base::error;
- *to_nxt = t;
- frm_nxt += 2;
- }
- else if (c1 < 0xF0)
- {
- if (frm_end-frm_nxt < 3)
- return codecvt_base::partial;
- uint8_t c2 = frm_nxt[1];
- uint8_t c3 = frm_nxt[2];
- switch (c1)
- {
- case 0xE0:
- if ((c2 & 0xE0) != 0xA0)
- return codecvt_base::error;
- break;
- case 0xED:
- if ((c2 & 0xE0) != 0x80)
- return codecvt_base::error;
- break;
- default:
- if ((c2 & 0xC0) != 0x80)
- return codecvt_base::error;
- break;
- }
- if ((c3 & 0xC0) != 0x80)
- return codecvt_base::error;
- uint16_t t = static_cast<uint16_t>(((c1 & 0x0F) << 12)
- | ((c2 & 0x3F) << 6)
- | (c3 & 0x3F));
- if (t > Maxcode)
- return codecvt_base::error;
- *to_nxt = t;
- frm_nxt += 3;
- }
- else
- {
- return codecvt_base::error;
- }
- }
- return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
-}
-
-static
-int
-utf8_to_ucs2_length(const uint8_t* frm, const uint8_t* frm_end,
- size_t mx, unsigned long Maxcode = 0x10FFFF,
- codecvt_mode mode = codecvt_mode(0))
-{
- const uint8_t* frm_nxt = frm;
- if (mode & consume_header)
- {
- if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
- frm_nxt[2] == 0xBF)
- frm_nxt += 3;
- }
- for (size_t nchar32_t = 0; frm_nxt < frm_end && nchar32_t < mx; ++nchar32_t)
- {
- uint8_t c1 = static_cast<uint8_t>(*frm_nxt);
- if (c1 < 0x80)
- {
- if (c1 > Maxcode)
- break;
- ++frm_nxt;
- }
- else if (c1 < 0xC2)
- {
- break;
- }
- else if (c1 < 0xE0)
- {
- if ((frm_end-frm_nxt < 2) || ((frm_nxt[1] & 0xC0) != 0x80))
- break;
- if ((((c1 & 0x1Fu) << 6) | (frm_nxt[1] & 0x3Fu)) > Maxcode)
- break;
- frm_nxt += 2;
- }
- else if (c1 < 0xF0)
- {
- if (frm_end-frm_nxt < 3)
- break;
- uint8_t c2 = frm_nxt[1];
- uint8_t c3 = frm_nxt[2];
- switch (c1)
- {
- case 0xE0:
- if ((c2 & 0xE0) != 0xA0)
- return static_cast<int>(frm_nxt - frm);
- break;
- case 0xED:
- if ((c2 & 0xE0) != 0x80)
- return static_cast<int>(frm_nxt - frm);
- break;
- default:
- if ((c2 & 0xC0) != 0x80)
- return static_cast<int>(frm_nxt - frm);
- break;
- }
- if ((c3 & 0xC0) != 0x80)
- break;
- if ((((c1 & 0x0Fu) << 12) | ((c2 & 0x3Fu) << 6) | (c3 & 0x3Fu)) > Maxcode)
- break;
- frm_nxt += 3;
- }
- else
- {
- break;
- }
+_LIBCPP_SUPPRESS_DEPRECATED_PUSH
+static codecvt_base::result utf16_to_utf8(
+ const uint16_t* frm,
+ const uint16_t* frm_end,
+ const uint16_t*& frm_nxt,
+ uint8_t* to,
+ uint8_t* to_end,
+ uint8_t*& to_nxt,
+ unsigned long Maxcode = 0x10FFFF,
+ codecvt_mode mode = codecvt_mode(0)) {
+ frm_nxt = frm;
+ to_nxt = to;
+ if (mode & generate_header) {
+ if (to_end - to_nxt < 3)
+ return codecvt_base::partial;
+ *to_nxt++ = static_cast<uint8_t>(0xEF);
+ *to_nxt++ = static_cast<uint8_t>(0xBB);
+ *to_nxt++ = static_cast<uint8_t>(0xBF);
+ }
+ for (; frm_nxt < frm_end; ++frm_nxt) {
+ uint16_t wc1 = *frm_nxt;
+ if (wc1 > Maxcode)
+ return codecvt_base::error;
+ if (wc1 < 0x0080) {
+ if (to_end - to_nxt < 1)
+ return codecvt_base::partial;
+ *to_nxt++ = static_cast<uint8_t>(wc1);
+ } else if (wc1 < 0x0800) {
+ if (to_end - to_nxt < 2)
+ return codecvt_base::partial;
+ *to_nxt++ = static_cast<uint8_t>(0xC0 | (wc1 >> 6));
+ *to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x03F));
+ } else if (wc1 < 0xD800) {
+ if (to_end - to_nxt < 3)
+ return codecvt_base::partial;
+ *to_nxt++ = static_cast<uint8_t>(0xE0 | (wc1 >> 12));
+ *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0FC0) >> 6));
+ *to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x003F));
+ } else if (wc1 < 0xDC00) {
+ if (frm_end - frm_nxt < 2)
+ return codecvt_base::partial;
+ uint16_t wc2 = frm_nxt[1];
+ if ((wc2 & 0xFC00) != 0xDC00)
+ return codecvt_base::error;
+ if (to_end - to_nxt < 4)
+ return codecvt_base::partial;
+ if (((((wc1 & 0x03C0UL) >> 6) + 1) << 16) + ((wc1 & 0x003FUL) << 10) + (wc2 & 0x03FF) > Maxcode)
+ return codecvt_base::error;
+ ++frm_nxt;
+ uint8_t z = ((wc1 & 0x03C0) >> 6) + 1;
+ *to_nxt++ = static_cast<uint8_t>(0xF0 | (z >> 2));
+ *to_nxt++ = static_cast<uint8_t>(0x80 | ((z & 0x03) << 4) | ((wc1 & 0x003C) >> 2));
+ *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0003) << 4) | ((wc2 & 0x03C0) >> 6));
+ *to_nxt++ = static_cast<uint8_t>(0x80 | (wc2 & 0x003F));
+ } else if (wc1 < 0xE000) {
+ return codecvt_base::error;
+ } else {
+ if (to_end - to_nxt < 3)
+ return codecvt_base::partial;
+ *to_nxt++ = static_cast<uint8_t>(0xE0 | (wc1 >> 12));
+ *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0FC0) >> 6));
+ *to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x003F));
}
- return static_cast<int>(frm_nxt - frm);
-}
-
-static
-codecvt_base::result
-ucs4_to_utf16be(const uint32_t* frm, const uint32_t* frm_end, const uint32_t*& frm_nxt,
- uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
- unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
-{
- frm_nxt = frm;
- to_nxt = to;
- if (mode & generate_header)
- {
- if (to_end-to_nxt < 2)
- return codecvt_base::partial;
- *to_nxt++ = static_cast<uint8_t>(0xFE);
- *to_nxt++ = static_cast<uint8_t>(0xFF);
+ }
+ return codecvt_base::ok;
+}
+
+static codecvt_base::result utf16_to_utf8(
+ const uint32_t* frm,
+ const uint32_t* frm_end,
+ const uint32_t*& frm_nxt,
+ uint8_t* to,
+ uint8_t* to_end,
+ uint8_t*& to_nxt,
+ unsigned long Maxcode = 0x10FFFF,
+ codecvt_mode mode = codecvt_mode(0)) {
+ frm_nxt = frm;
+ to_nxt = to;
+ if (mode & generate_header) {
+ if (to_end - to_nxt < 3)
+ return codecvt_base::partial;
+ *to_nxt++ = static_cast<uint8_t>(0xEF);
+ *to_nxt++ = static_cast<uint8_t>(0xBB);
+ *to_nxt++ = static_cast<uint8_t>(0xBF);
+ }
+ for (; frm_nxt < frm_end; ++frm_nxt) {
+ uint16_t wc1 = static_cast<uint16_t>(*frm_nxt);
+ if (wc1 > Maxcode)
+ return codecvt_base::error;
+ if (wc1 < 0x0080) {
+ if (to_end - to_nxt < 1)
+ return codecvt_base::partial;
+ *to_nxt++ = static_cast<uint8_t>(wc1);
+ } else if (wc1 < 0x0800) {
+ if (to_end - to_nxt < 2)
+ return codecvt_base::partial;
+ *to_nxt++ = static_cast<uint8_t>(0xC0 | (wc1 >> 6));
+ *to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x03F));
+ } else if (wc1 < 0xD800) {
+ if (to_end - to_nxt < 3)
+ return codecvt_base::partial;
+ *to_nxt++ = static_cast<uint8_t>(0xE0 | (wc1 >> 12));
+ *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0FC0) >> 6));
+ *to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x003F));
+ } else if (wc1 < 0xDC00) {
+ if (frm_end - frm_nxt < 2)
+ return codecvt_base::partial;
+ uint16_t wc2 = static_cast<uint16_t>(frm_nxt[1]);
+ if ((wc2 & 0xFC00) != 0xDC00)
+ return codecvt_base::error;
+ if (to_end - to_nxt < 4)
+ return codecvt_base::partial;
+ if (((((wc1 & 0x03C0UL) >> 6) + 1) << 16) + ((wc1 & 0x003FUL) << 10) + (wc2 & 0x03FF) > Maxcode)
+ return codecvt_base::error;
+ ++frm_nxt;
+ uint8_t z = ((wc1 & 0x03C0) >> 6) + 1;
+ *to_nxt++ = static_cast<uint8_t>(0xF0 | (z >> 2));
+ *to_nxt++ = static_cast<uint8_t>(0x80 | ((z & 0x03) << 4) | ((wc1 & 0x003C) >> 2));
+ *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0003) << 4) | ((wc2 & 0x03C0) >> 6));
+ *to_nxt++ = static_cast<uint8_t>(0x80 | (wc2 & 0x003F));
+ } else if (wc1 < 0xE000) {
+ return codecvt_base::error;
+ } else {
+ if (to_end - to_nxt < 3)
+ return codecvt_base::partial;
+ *to_nxt++ = static_cast<uint8_t>(0xE0 | (wc1 >> 12));
+ *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0FC0) >> 6));
+ *to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x003F));
}
- for (; frm_nxt < frm_end; ++frm_nxt)
- {
- uint32_t wc = *frm_nxt;
- if ((wc & 0xFFFFF800) == 0x00D800 || wc > Maxcode)
- return codecvt_base::error;
- if (wc < 0x010000)
- {
- if (to_end-to_nxt < 2)
- return codecvt_base::partial;
- *to_nxt++ = static_cast<uint8_t>(wc >> 8);
- *to_nxt++ = static_cast<uint8_t>(wc);
- }
- else
- {
- if (to_end-to_nxt < 4)
- return codecvt_base::partial;
- uint16_t t = static_cast<uint16_t>(
- 0xD800
- | ((((wc & 0x1F0000) >> 16) - 1) << 6)
- | ((wc & 0x00FC00) >> 10));
- *to_nxt++ = static_cast<uint8_t>(t >> 8);
- *to_nxt++ = static_cast<uint8_t>(t);
- t = static_cast<uint16_t>(0xDC00 | (wc & 0x03FF));
- *to_nxt++ = static_cast<uint8_t>(t >> 8);
- *to_nxt++ = static_cast<uint8_t>(t);
- }
+ }
+ return codecvt_base::ok;
+}
+
+static codecvt_base::result utf8_to_utf16(
+ const uint8_t* frm,
+ const uint8_t* frm_end,
+ const uint8_t*& frm_nxt,
+ uint16_t* to,
+ uint16_t* to_end,
+ uint16_t*& to_nxt,
+ unsigned long Maxcode = 0x10FFFF,
+ codecvt_mode mode = codecvt_mode(0)) {
+ frm_nxt = frm;
+ to_nxt = to;
+ if (mode & consume_header) {
+ if (frm_end - frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB && frm_nxt[2] == 0xBF)
+ frm_nxt += 3;
+ }
+ for (; frm_nxt < frm_end && to_nxt < to_end; ++to_nxt) {
+ uint8_t c1 = *frm_nxt;
+ if (c1 > Maxcode)
+ return codecvt_base::error;
+ if (c1 < 0x80) {
+ *to_nxt = static_cast<uint16_t>(c1);
+ ++frm_nxt;
+ } else if (c1 < 0xC2) {
+ return codecvt_base::error;
+ } else if (c1 < 0xE0) {
+ if (frm_end - frm_nxt < 2)
+ return codecvt_base::partial;
+ uint8_t c2 = frm_nxt[1];
+ if ((c2 & 0xC0) != 0x80)
+ return codecvt_base::error;
+ uint16_t t = static_cast<uint16_t>(((c1 & 0x1F) << 6) | (c2 & 0x3F));
+ if (t > Maxcode)
+ return codecvt_base::error;
+ *to_nxt = t;
+ frm_nxt += 2;
+ } else if (c1 < 0xF0) {
+ if (frm_end - frm_nxt < 2)
+ return codecvt_base::partial;
+ uint8_t c2 = frm_nxt[1];
+ switch (c1) {
+ case 0xE0:
+ if ((c2 & 0xE0) != 0xA0)
+ return codecvt_base::error;
+ break;
+ case 0xED:
+ if ((c2 & 0xE0) != 0x80)
+ return codecvt_base::error;
+ break;
+ default:
+ if ((c2 & 0xC0) != 0x80)
+ return codecvt_base::error;
+ break;
+ }
+ if (frm_end - frm_nxt < 3)
+ return codecvt_base::partial;
+ uint8_t c3 = frm_nxt[2];
+ if ((c3 & 0xC0) != 0x80)
+ return codecvt_base::error;
+ uint16_t t = static_cast<uint16_t>(((c1 & 0x0F) << 12) | ((c2 & 0x3F) << 6) | (c3 & 0x3F));
+ if (t > Maxcode)
+ return codecvt_base::error;
+ *to_nxt = t;
+ frm_nxt += 3;
+ } else if (c1 < 0xF5) {
+ if (frm_end - frm_nxt < 2)
+ return codecvt_base::partial;
+ uint8_t c2 = frm_nxt[1];
+ switch (c1) {
+ case 0xF0:
+ if (!(0x90 <= c2 && c2 <= 0xBF))
+ return codecvt_base::error;
+ break;
+ case 0xF4:
+ if ((c2 & 0xF0) != 0x80)
+ return codecvt_base::error;
+ break;
+ default:
+ if ((c2 & 0xC0) != 0x80)
+ return codecvt_base::error;
+ break;
+ }
+ if (frm_end - frm_nxt < 3)
+ return codecvt_base::partial;
+ uint8_t c3 = frm_nxt[2];
+ if ((c3 & 0xC0) != 0x80)
+ return codecvt_base::error;
+ if (frm_end - frm_nxt < 4)
+ return codecvt_base::partial;
+ uint8_t c4 = frm_nxt[3];
+ if ((c4 & 0xC0) != 0x80)
+ return codecvt_base::error;
+ if (to_end - to_nxt < 2)
+ return codecvt_base::partial;
+ if ((((c1 & 7UL) << 18) + ((c2 & 0x3FUL) << 12) + ((c3 & 0x3FUL) << 6) + (c4 & 0x3F)) > Maxcode)
+ return codecvt_base::error;
+ *to_nxt = static_cast<uint16_t>(
+ 0xD800 | (((((c1 & 0x07) << 2) | ((c2 & 0x30) >> 4)) - 1) << 6) | ((c2 & 0x0F) << 2) | ((c3 & 0x30) >> 4));
+ *++to_nxt = static_cast<uint16_t>(0xDC00 | ((c3 & 0x0F) << 6) | (c4 & 0x3F));
+ frm_nxt += 4;
+ } else {
+ return codecvt_base::error;
}
- return codecvt_base::ok;
-}
-
-static
-codecvt_base::result
-utf16be_to_ucs4(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
- uint32_t* to, uint32_t* to_end, uint32_t*& to_nxt,
- unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
-{
- frm_nxt = frm;
- to_nxt = to;
- if (mode & consume_header)
- {
- if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFE && frm_nxt[1] == 0xFF)
- frm_nxt += 2;
+ }
+ return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
+}
+
+static codecvt_base::result utf8_to_utf16(
+ const uint8_t* frm,
+ const uint8_t* frm_end,
+ const uint8_t*& frm_nxt,
+ uint32_t* to,
+ uint32_t* to_end,
+ uint32_t*& to_nxt,
+ unsigned long Maxcode = 0x10FFFF,
+ codecvt_mode mode = codecvt_mode(0)) {
+ frm_nxt = frm;
+ to_nxt = to;
+ if (mode & consume_header) {
+ if (frm_end - frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB && frm_nxt[2] == 0xBF)
+ frm_nxt += 3;
+ }
+ for (; frm_nxt < frm_end && to_nxt < to_end; ++to_nxt) {
+ uint8_t c1 = *frm_nxt;
+ if (c1 > Maxcode)
+ return codecvt_base::error;
+ if (c1 < 0x80) {
+ *to_nxt = static_cast<uint32_t>(c1);
+ ++frm_nxt;
+ } else if (c1 < 0xC2) {
+ return codecvt_base::error;
+ } else if (c1 < 0xE0) {
+ if (frm_end - frm_nxt < 2)
+ return codecvt_base::partial;
+ uint8_t c2 = frm_nxt[1];
+ if ((c2 & 0xC0) != 0x80)
+ return codecvt_base::error;
+ uint16_t t = static_cast<uint16_t>(((c1 & 0x1F) << 6) | (c2 & 0x3F));
+ if (t > Maxcode)
+ return codecvt_base::error;
+ *to_nxt = static_cast<uint32_t>(t);
+ frm_nxt += 2;
+ } else if (c1 < 0xF0) {
+ if (frm_end - frm_nxt < 2)
+ return codecvt_base::partial;
+ uint8_t c2 = frm_nxt[1];
+ switch (c1) {
+ case 0xE0:
+ if ((c2 & 0xE0) != 0xA0)
+ return codecvt_base::error;
+ break;
+ case 0xED:
+ if ((c2 & 0xE0) != 0x80)
+ return codecvt_base::error;
+ break;
+ default:
+ if ((c2 & 0xC0) != 0x80)
+ return codecvt_base::error;
+ break;
+ }
+ if (frm_end - frm_nxt < 3)
+ return codecvt_base::partial;
+ uint8_t c3 = frm_nxt[2];
+ if ((c3 & 0xC0) != 0x80)
+ return codecvt_base::error;
+ uint16_t t = static_cast<uint16_t>(((c1 & 0x0F) << 12) | ((c2 & 0x3F) << 6) | (c3 & 0x3F));
+ if (t > Maxcode)
+ return codecvt_base::error;
+ *to_nxt = static_cast<uint32_t>(t);
+ frm_nxt += 3;
+ } else if (c1 < 0xF5) {
+ if (frm_end - frm_nxt < 2)
+ return codecvt_base::partial;
+ uint8_t c2 = frm_nxt[1];
+ switch (c1) {
+ case 0xF0:
+ if (!(0x90 <= c2 && c2 <= 0xBF))
+ return codecvt_base::error;
+ break;
+ case 0xF4:
+ if ((c2 & 0xF0) != 0x80)
+ return codecvt_base::error;
+ break;
+ default:
+ if ((c2 & 0xC0) != 0x80)
+ return codecvt_base::error;
+ break;
+ }
+ if (frm_end - frm_nxt < 3)
+ return codecvt_base::partial;
+ uint8_t c3 = frm_nxt[2];
+ if ((c3 & 0xC0) != 0x80)
+ return codecvt_base::error;
+ if (frm_end - frm_nxt < 4)
+ return codecvt_base::partial;
+ uint8_t c4 = frm_nxt[3];
+ if ((c4 & 0xC0) != 0x80)
+ return codecvt_base::error;
+ if (to_end - to_nxt < 2)
+ return codecvt_base::partial;
+ if ((((c1 & 7UL) << 18) + ((c2 & 0x3FUL) << 12) + ((c3 & 0x3FUL) << 6) + (c4 & 0x3F)) > Maxcode)
+ return codecvt_base::error;
+ *to_nxt = static_cast<uint32_t>(
+ 0xD800 | (((((c1 & 0x07) << 2) | ((c2 & 0x30) >> 4)) - 1) << 6) | ((c2 & 0x0F) << 2) | ((c3 & 0x30) >> 4));
+ *++to_nxt = static_cast<uint32_t>(0xDC00 | ((c3 & 0x0F) << 6) | (c4 & 0x3F));
+ frm_nxt += 4;
+ } else {
+ return codecvt_base::error;
}
- for (; frm_nxt < frm_end - 1 && to_nxt < to_end; ++to_nxt)
- {
- uint16_t c1 = static_cast<uint16_t>(frm_nxt[0] << 8 | frm_nxt[1]);
- if ((c1 & 0xFC00) == 0xDC00)
- return codecvt_base::error;
- if ((c1 & 0xFC00) != 0xD800)
- {
- if (c1 > Maxcode)
- return codecvt_base::error;
- *to_nxt = static_cast<uint32_t>(c1);
- frm_nxt += 2;
- }
- else
- {
- if (frm_end-frm_nxt < 4)
- return codecvt_base::partial;
- uint16_t c2 = static_cast<uint16_t>(frm_nxt[2] << 8 | frm_nxt[3]);
- if ((c2 & 0xFC00) != 0xDC00)
- return codecvt_base::error;
- uint32_t t = static_cast<uint32_t>(
- ((((c1 & 0x03C0) >> 6) + 1) << 16)
- | ((c1 & 0x003F) << 10)
- | (c2 & 0x03FF));
- if (t > Maxcode)
- return codecvt_base::error;
- *to_nxt = t;
- frm_nxt += 4;
- }
+ }
+ return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
+}
+
+static int utf8_to_utf16_length(
+ const uint8_t* frm,
+ const uint8_t* frm_end,
+ size_t mx,
+ unsigned long Maxcode = 0x10FFFF,
+ codecvt_mode mode = codecvt_mode(0)) {
+ const uint8_t* frm_nxt = frm;
+ if (mode & consume_header) {
+ if (frm_end - frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB && frm_nxt[2] == 0xBF)
+ frm_nxt += 3;
+ }
+ for (size_t nchar16_t = 0; frm_nxt < frm_end && nchar16_t < mx; ++nchar16_t) {
+ uint8_t c1 = *frm_nxt;
+ if (c1 > Maxcode)
+ break;
+ if (c1 < 0x80) {
+ ++frm_nxt;
+ } else if (c1 < 0xC2) {
+ break;
+ } else if (c1 < 0xE0) {
+ if ((frm_end - frm_nxt < 2) || (frm_nxt[1] & 0xC0) != 0x80)
+ break;
+ uint16_t t = static_cast<uint16_t>(((c1 & 0x1F) << 6) | (frm_nxt[1] & 0x3F));
+ if (t > Maxcode)
+ break;
+ frm_nxt += 2;
+ } else if (c1 < 0xF0) {
+ if (frm_end - frm_nxt < 3)
+ break;
+ uint8_t c2 = frm_nxt[1];
+ uint8_t c3 = frm_nxt[2];
+ switch (c1) {
+ case 0xE0:
+ if ((c2 & 0xE0) != 0xA0)
+ return static_cast<int>(frm_nxt - frm);
+ break;
+ case 0xED:
+ if ((c2 & 0xE0) != 0x80)
+ return static_cast<int>(frm_nxt - frm);
+ break;
+ default:
+ if ((c2 & 0xC0) != 0x80)
+ return static_cast<int>(frm_nxt - frm);
+ break;
+ }
+ if ((c3 & 0xC0) != 0x80)
+ break;
+ if ((((c1 & 0x0Fu) << 12) | ((c2 & 0x3Fu) << 6) | (c3 & 0x3Fu)) > Maxcode)
+ break;
+ frm_nxt += 3;
+ } else if (c1 < 0xF5) {
+ if (frm_end - frm_nxt < 4 || mx - nchar16_t < 2)
+ break;
+ uint8_t c2 = frm_nxt[1];
+ uint8_t c3 = frm_nxt[2];
+ uint8_t c4 = frm_nxt[3];
+ switch (c1) {
+ case 0xF0:
+ if (!(0x90 <= c2 && c2 <= 0xBF))
+ return static_cast<int>(frm_nxt - frm);
+ break;
+ case 0xF4:
+ if ((c2 & 0xF0) != 0x80)
+ return static_cast<int>(frm_nxt - frm);
+ break;
+ default:
+ if ((c2 & 0xC0) != 0x80)
+ return static_cast<int>(frm_nxt - frm);
+ break;
+ }
+ if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80)
+ break;
+ if ((((c1 & 7UL) << 18) + ((c2 & 0x3FUL) << 12) + ((c3 & 0x3FUL) << 6) + (c4 & 0x3F)) > Maxcode)
+ break;
+ ++nchar16_t;
+ frm_nxt += 4;
+ } else {
+ break;
}
- return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
-}
-
-static
-int
-utf16be_to_ucs4_length(const uint8_t* frm, const uint8_t* frm_end,
- size_t mx, unsigned long Maxcode = 0x10FFFF,
- codecvt_mode mode = codecvt_mode(0))
-{
- const uint8_t* frm_nxt = frm;
- if (mode & consume_header)
+ }
+ return static_cast<int>(frm_nxt - frm);
+}
+
+static codecvt_base::result ucs4_to_utf8(
+ const uint32_t* frm,
+ const uint32_t* frm_end,
+ const uint32_t*& frm_nxt,
+ uint8_t* to,
+ uint8_t* to_end,
+ uint8_t*& to_nxt,
+ unsigned long Maxcode = 0x10FFFF,
+ codecvt_mode mode = codecvt_mode(0)) {
+ frm_nxt = frm;
+ to_nxt = to;
+ if (mode & generate_header) {
+ if (to_end - to_nxt < 3)
+ return codecvt_base::partial;
+ *to_nxt++ = static_cast<uint8_t>(0xEF);
+ *to_nxt++ = static_cast<uint8_t>(0xBB);
+ *to_nxt++ = static_cast<uint8_t>(0xBF);
+ }
+ for (; frm_nxt < frm_end; ++frm_nxt) {
+ uint32_t wc = *frm_nxt;
+ if ((wc & 0xFFFFF800) == 0x00D800 || wc > Maxcode)
+ return codecvt_base::error;
+ if (wc < 0x000080) {
+ if (to_end - to_nxt < 1)
+ return codecvt_base::partial;
+ *to_nxt++ = static_cast<uint8_t>(wc);
+ } else if (wc < 0x000800) {
+ if (to_end - to_nxt < 2)
+ return codecvt_base::partial;
+ *to_nxt++ = static_cast<uint8_t>(0xC0 | (wc >> 6));
+ *to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x03F));
+ } else if (wc < 0x010000) {
+ if (to_end - to_nxt < 3)
+ return codecvt_base::partial;
+ *to_nxt++ = static_cast<uint8_t>(0xE0 | (wc >> 12));
+ *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc & 0x0FC0) >> 6));
+ *to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x003F));
+ } else // if (wc < 0x110000)
{
- if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFE && frm_nxt[1] == 0xFF)
- frm_nxt += 2;
+ if (to_end - to_nxt < 4)
+ return codecvt_base::partial;
+ *to_nxt++ = static_cast<uint8_t>(0xF0 | (wc >> 18));
+ *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc & 0x03F000) >> 12));
+ *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc & 0x000FC0) >> 6));
+ *to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x00003F));
}
- for (size_t nchar32_t = 0; frm_nxt < frm_end - 1 && nchar32_t < mx; ++nchar32_t)
- {
- uint16_t c1 = static_cast<uint16_t>(frm_nxt[0] << 8 | frm_nxt[1]);
- if ((c1 & 0xFC00) == 0xDC00)
- break;
- if ((c1 & 0xFC00) != 0xD800)
- {
- if (c1 > Maxcode)
- break;
- frm_nxt += 2;
- }
- else
- {
- if (frm_end-frm_nxt < 4)
- break;
- uint16_t c2 = static_cast<uint16_t>(frm_nxt[2] << 8 | frm_nxt[3]);
- if ((c2 & 0xFC00) != 0xDC00)
- break;
- uint32_t t = static_cast<uint32_t>(
- ((((c1 & 0x03C0) >> 6) + 1) << 16)
- | ((c1 & 0x003F) << 10)
- | (c2 & 0x03FF));
- if (t > Maxcode)
- break;
- frm_nxt += 4;
- }
+ }
+ return codecvt_base::ok;
+}
+
+static codecvt_base::result utf8_to_ucs4(
+ const uint8_t* frm,
+ const uint8_t* frm_end,
+ const uint8_t*& frm_nxt,
+ uint32_t* to,
+ uint32_t* to_end,
+ uint32_t*& to_nxt,
+ unsigned long Maxcode = 0x10FFFF,
+ codecvt_mode mode = codecvt_mode(0)) {
+ frm_nxt = frm;
+ to_nxt = to;
+ if (mode & consume_header) {
+ if (frm_end - frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB && frm_nxt[2] == 0xBF)
+ frm_nxt += 3;
+ }
+ for (; frm_nxt < frm_end && to_nxt < to_end; ++to_nxt) {
+ uint8_t c1 = static_cast<uint8_t>(*frm_nxt);
+ if (c1 < 0x80) {
+ if (c1 > Maxcode)
+ return codecvt_base::error;
+ *to_nxt = static_cast<uint32_t>(c1);
+ ++frm_nxt;
+ } else if (c1 < 0xC2) {
+ return codecvt_base::error;
+ } else if (c1 < 0xE0) {
+ if (frm_end - frm_nxt < 2)
+ return codecvt_base::partial;
+ uint8_t c2 = frm_nxt[1];
+ if ((c2 & 0xC0) != 0x80)
+ return codecvt_base::error;
+ uint32_t t = static_cast<uint32_t>(((c1 & 0x1F) << 6) | (c2 & 0x3F));
+ if (t > Maxcode)
+ return codecvt_base::error;
+ *to_nxt = t;
+ frm_nxt += 2;
+ } else if (c1 < 0xF0) {
+ if (frm_end - frm_nxt < 2)
+ return codecvt_base::partial;
+ uint8_t c2 = frm_nxt[1];
+ switch (c1) {
+ case 0xE0:
+ if ((c2 & 0xE0) != 0xA0)
+ return codecvt_base::error;
+ break;
+ case 0xED:
+ if ((c2 & 0xE0) != 0x80)
+ return codecvt_base::error;
+ break;
+ default:
+ if ((c2 & 0xC0) != 0x80)
+ return codecvt_base::error;
+ break;
+ }
+ if (frm_end - frm_nxt < 3)
+ return codecvt_base::partial;
+ uint8_t c3 = frm_nxt[2];
+ if ((c3 & 0xC0) != 0x80)
+ return codecvt_base::error;
+ uint32_t t = static_cast<uint32_t>(((c1 & 0x0F) << 12) | ((c2 & 0x3F) << 6) | (c3 & 0x3F));
+ if (t > Maxcode)
+ return codecvt_base::error;
+ *to_nxt = t;
+ frm_nxt += 3;
+ } else if (c1 < 0xF5) {
+ if (frm_end - frm_nxt < 2)
+ return codecvt_base::partial;
+ uint8_t c2 = frm_nxt[1];
+ switch (c1) {
+ case 0xF0:
+ if (!(0x90 <= c2 && c2 <= 0xBF))
+ return codecvt_base::error;
+ break;
+ case 0xF4:
+ if ((c2 & 0xF0) != 0x80)
+ return codecvt_base::error;
+ break;
+ default:
+ if ((c2 & 0xC0) != 0x80)
+ return codecvt_base::error;
+ break;
+ }
+ if (frm_end - frm_nxt < 3)
+ return codecvt_base::partial;
+ uint8_t c3 = frm_nxt[2];
+ if ((c3 & 0xC0) != 0x80)
+ return codecvt_base::error;
+ if (frm_end - frm_nxt < 4)
+ return codecvt_base::partial;
+ uint8_t c4 = frm_nxt[3];
+ if ((c4 & 0xC0) != 0x80)
+ return codecvt_base::error;
+ uint32_t t = static_cast<uint32_t>(((c1 & 0x07) << 18) | ((c2 & 0x3F) << 12) | ((c3 & 0x3F) << 6) | (c4 & 0x3F));
+ if (t > Maxcode)
+ return codecvt_base::error;
+ *to_nxt = t;
+ frm_nxt += 4;
+ } else {
+ return codecvt_base::error;
}
- return static_cast<int>(frm_nxt - frm);
-}
-
-static
-codecvt_base::result
-ucs4_to_utf16le(const uint32_t* frm, const uint32_t* frm_end, const uint32_t*& frm_nxt,
- uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
- unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
-{
- frm_nxt = frm;
- to_nxt = to;
- if (mode & generate_header)
- {
- if (to_end - to_nxt < 2)
- return codecvt_base::partial;
- *to_nxt++ = static_cast<uint8_t>(0xFF);
- *to_nxt++ = static_cast<uint8_t>(0xFE);
+ }
+ return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
+}
+
+static int utf8_to_ucs4_length(
+ const uint8_t* frm,
+ const uint8_t* frm_end,
+ size_t mx,
+ unsigned long Maxcode = 0x10FFFF,
+ codecvt_mode mode = codecvt_mode(0)) {
+ const uint8_t* frm_nxt = frm;
+ if (mode & consume_header) {
+ if (frm_end - frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB && frm_nxt[2] == 0xBF)
+ frm_nxt += 3;
+ }
+ for (size_t nchar32_t = 0; frm_nxt < frm_end && nchar32_t < mx; ++nchar32_t) {
+ uint8_t c1 = static_cast<uint8_t>(*frm_nxt);
+ if (c1 < 0x80) {
+ if (c1 > Maxcode)
+ break;
+ ++frm_nxt;
+ } else if (c1 < 0xC2) {
+ break;
+ } else if (c1 < 0xE0) {
+ if ((frm_end - frm_nxt < 2) || ((frm_nxt[1] & 0xC0) != 0x80))
+ break;
+ if ((((c1 & 0x1Fu) << 6) | (frm_nxt[1] & 0x3Fu)) > Maxcode)
+ break;
+ frm_nxt += 2;
+ } else if (c1 < 0xF0) {
+ if (frm_end - frm_nxt < 3)
+ break;
+ uint8_t c2 = frm_nxt[1];
+ uint8_t c3 = frm_nxt[2];
+ switch (c1) {
+ case 0xE0:
+ if ((c2 & 0xE0) != 0xA0)
+ return static_cast<int>(frm_nxt - frm);
+ break;
+ case 0xED:
+ if ((c2 & 0xE0) != 0x80)
+ return static_cast<int>(frm_nxt - frm);
+ break;
+ default:
+ if ((c2 & 0xC0) != 0x80)
+ return static_cast<int>(frm_nxt - frm);
+ break;
+ }
+ if ((c3 & 0xC0) != 0x80)
+ break;
+ if ((((c1 & 0x0Fu) << 12) | ((c2 & 0x3Fu) << 6) | (c3 & 0x3Fu)) > Maxcode)
+ break;
+ frm_nxt += 3;
+ } else if (c1 < 0xF5) {
+ if (frm_end - frm_nxt < 4)
+ break;
+ uint8_t c2 = frm_nxt[1];
+ uint8_t c3 = frm_nxt[2];
+ uint8_t c4 = frm_nxt[3];
+ switch (c1) {
+ case 0xF0:
+ if (!(0x90 <= c2 && c2 <= 0xBF))
+ return static_cast<int>(frm_nxt - frm);
+ break;
+ case 0xF4:
+ if ((c2 & 0xF0) != 0x80)
+ return static_cast<int>(frm_nxt - frm);
+ break;
+ default:
+ if ((c2 & 0xC0) != 0x80)
+ return static_cast<int>(frm_nxt - frm);
+ break;
+ }
+ if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80)
+ break;
+ if ((((c1 & 0x07u) << 18) | ((c2 & 0x3Fu) << 12) | ((c3 & 0x3Fu) << 6) | (c4 & 0x3Fu)) > Maxcode)
+ break;
+ frm_nxt += 4;
+ } else {
+ break;
}
- for (; frm_nxt < frm_end; ++frm_nxt)
+ }
+ return static_cast<int>(frm_nxt - frm);
+}
+
+static codecvt_base::result ucs2_to_utf8(
+ const uint16_t* frm,
+ const uint16_t* frm_end,
+ const uint16_t*& frm_nxt,
+ uint8_t* to,
+ uint8_t* to_end,
+ uint8_t*& to_nxt,
+ unsigned long Maxcode = 0x10FFFF,
+ codecvt_mode mode = codecvt_mode(0)) {
+ frm_nxt = frm;
+ to_nxt = to;
+ if (mode & generate_header) {
+ if (to_end - to_nxt < 3)
+ return codecvt_base::partial;
+ *to_nxt++ = static_cast<uint8_t>(0xEF);
+ *to_nxt++ = static_cast<uint8_t>(0xBB);
+ *to_nxt++ = static_cast<uint8_t>(0xBF);
+ }
+ for (; frm_nxt < frm_end; ++frm_nxt) {
+ uint16_t wc = *frm_nxt;
+ if ((wc & 0xF800) == 0xD800 || wc > Maxcode)
+ return codecvt_base::error;
+ if (wc < 0x0080) {
+ if (to_end - to_nxt < 1)
+ return codecvt_base::partial;
+ *to_nxt++ = static_cast<uint8_t>(wc);
+ } else if (wc < 0x0800) {
+ if (to_end - to_nxt < 2)
+ return codecvt_base::partial;
+ *to_nxt++ = static_cast<uint8_t>(0xC0 | (wc >> 6));
+ *to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x03F));
+ } else // if (wc <= 0xFFFF)
{
- uint32_t wc = *frm_nxt;
- if ((wc & 0xFFFFF800) == 0x00D800 || wc > Maxcode)
- return codecvt_base::error;
- if (wc < 0x010000)
- {
- if (to_end-to_nxt < 2)
- return codecvt_base::partial;
- *to_nxt++ = static_cast<uint8_t>(wc);
- *to_nxt++ = static_cast<uint8_t>(wc >> 8);
- }
- else
- {
- if (to_end-to_nxt < 4)
- return codecvt_base::partial;
- uint16_t t = static_cast<uint16_t>(
- 0xD800
- | ((((wc & 0x1F0000) >> 16) - 1) << 6)
- | ((wc & 0x00FC00) >> 10));
- *to_nxt++ = static_cast<uint8_t>(t);
- *to_nxt++ = static_cast<uint8_t>(t >> 8);
- t = static_cast<uint16_t>(0xDC00 | (wc & 0x03FF));
- *to_nxt++ = static_cast<uint8_t>(t);
- *to_nxt++ = static_cast<uint8_t>(t >> 8);
- }
+ if (to_end - to_nxt < 3)
+ return codecvt_base::partial;
+ *to_nxt++ = static_cast<uint8_t>(0xE0 | (wc >> 12));
+ *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc & 0x0FC0) >> 6));
+ *to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x003F));
}
- return codecvt_base::ok;
-}
-
-static
-codecvt_base::result
-utf16le_to_ucs4(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
- uint32_t* to, uint32_t* to_end, uint32_t*& to_nxt,
- unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
-{
- frm_nxt = frm;
- to_nxt = to;
- if (mode & consume_header)
- {
- if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFF && frm_nxt[1] == 0xFE)
- frm_nxt += 2;
+ }
+ return codecvt_base::ok;
+}
+
+static codecvt_base::result utf8_to_ucs2(
+ const uint8_t* frm,
+ const uint8_t* frm_end,
+ const uint8_t*& frm_nxt,
+ uint16_t* to,
+ uint16_t* to_end,
+ uint16_t*& to_nxt,
+ unsigned long Maxcode = 0x10FFFF,
+ codecvt_mode mode = codecvt_mode(0)) {
+ frm_nxt = frm;
+ to_nxt = to;
+ if (mode & consume_header) {
+ if (frm_end - frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB && frm_nxt[2] == 0xBF)
+ frm_nxt += 3;
+ }
+ for (; frm_nxt < frm_end && to_nxt < to_end; ++to_nxt) {
+ uint8_t c1 = static_cast<uint8_t>(*frm_nxt);
+ if (c1 < 0x80) {
+ if (c1 > Maxcode)
+ return codecvt_base::error;
+ *to_nxt = static_cast<uint16_t>(c1);
+ ++frm_nxt;
+ } else if (c1 < 0xC2) {
+ return codecvt_base::error;
+ } else if (c1 < 0xE0) {
+ if (frm_end - frm_nxt < 2)
+ return codecvt_base::partial;
+ uint8_t c2 = frm_nxt[1];
+ if ((c2 & 0xC0) != 0x80)
+ return codecvt_base::error;
+ uint16_t t = static_cast<uint16_t>(((c1 & 0x1F) << 6) | (c2 & 0x3F));
+ if (t > Maxcode)
+ return codecvt_base::error;
+ *to_nxt = t;
+ frm_nxt += 2;
+ } else if (c1 < 0xF0) {
+ if (frm_end - frm_nxt < 2)
+ return codecvt_base::partial;
+ uint8_t c2 = frm_nxt[1];
+ switch (c1) {
+ case 0xE0:
+ if ((c2 & 0xE0) != 0xA0)
+ return codecvt_base::error;
+ break;
+ case 0xED:
+ if ((c2 & 0xE0) != 0x80)
+ return codecvt_base::error;
+ break;
+ default:
+ if ((c2 & 0xC0) != 0x80)
+ return codecvt_base::error;
+ break;
+ }
+ if (frm_end - frm_nxt < 3)
+ return codecvt_base::partial;
+ uint8_t c3 = frm_nxt[2];
+ if ((c3 & 0xC0) != 0x80)
+ return codecvt_base::error;
+ uint16_t t = static_cast<uint16_t>(((c1 & 0x0F) << 12) | ((c2 & 0x3F) << 6) | (c3 & 0x3F));
+ if (t > Maxcode)
+ return codecvt_base::error;
+ *to_nxt = t;
+ frm_nxt += 3;
+ } else {
+ return codecvt_base::error;
}
- for (; frm_nxt < frm_end - 1 && to_nxt < to_end; ++to_nxt)
- {
- uint16_t c1 = static_cast<uint16_t>(frm_nxt[1] << 8 | frm_nxt[0]);
- if ((c1 & 0xFC00) == 0xDC00)
- return codecvt_base::error;
- if ((c1 & 0xFC00) != 0xD800)
- {
- if (c1 > Maxcode)
- return codecvt_base::error;
- *to_nxt = static_cast<uint32_t>(c1);
- frm_nxt += 2;
- }
- else
- {
- if (frm_end-frm_nxt < 4)
- return codecvt_base::partial;
- uint16_t c2 = static_cast<uint16_t>(frm_nxt[3] << 8 | frm_nxt[2]);
- if ((c2 & 0xFC00) != 0xDC00)
- return codecvt_base::error;
- uint32_t t = static_cast<uint32_t>(
- ((((c1 & 0x03C0) >> 6) + 1) << 16)
- | ((c1 & 0x003F) << 10)
- | (c2 & 0x03FF));
- if (t > Maxcode)
- return codecvt_base::error;
- *to_nxt = t;
- frm_nxt += 4;
- }
+ }
+ return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
+}
+
+static int utf8_to_ucs2_length(
+ const uint8_t* frm,
+ const uint8_t* frm_end,
+ size_t mx,
+ unsigned long Maxcode = 0x10FFFF,
+ codecvt_mode mode = codecvt_mode(0)) {
+ const uint8_t* frm_nxt = frm;
+ if (mode & consume_header) {
+ if (frm_end - frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB && frm_nxt[2] == 0xBF)
+ frm_nxt += 3;
+ }
+ for (size_t nchar32_t = 0; frm_nxt < frm_end && nchar32_t < mx; ++nchar32_t) {
+ uint8_t c1 = static_cast<uint8_t>(*frm_nxt);
+ if (c1 < 0x80) {
+ if (c1 > Maxcode)
+ break;
+ ++frm_nxt;
+ } else if (c1 < 0xC2) {
+ break;
+ } else if (c1 < 0xE0) {
+ if ((frm_end - frm_nxt < 2) || ((frm_nxt[1] & 0xC0) != 0x80))
+ break;
+ if ((((c1 & 0x1Fu) << 6) | (frm_nxt[1] & 0x3Fu)) > Maxcode)
+ break;
+ frm_nxt += 2;
+ } else if (c1 < 0xF0) {
+ if (frm_end - frm_nxt < 3)
+ break;
+ uint8_t c2 = frm_nxt[1];
+ uint8_t c3 = frm_nxt[2];
+ switch (c1) {
+ case 0xE0:
+ if ((c2 & 0xE0) != 0xA0)
+ return static_cast<int>(frm_nxt - frm);
+ break;
+ case 0xED:
+ if ((c2 & 0xE0) != 0x80)
+ return static_cast<int>(frm_nxt - frm);
+ break;
+ default:
+ if ((c2 & 0xC0) != 0x80)
+ return static_cast<int>(frm_nxt - frm);
+ break;
+ }
+ if ((c3 & 0xC0) != 0x80)
+ break;
+ if ((((c1 & 0x0Fu) << 12) | ((c2 & 0x3Fu) << 6) | (c3 & 0x3Fu)) > Maxcode)
+ break;
+ frm_nxt += 3;
+ } else {
+ break;
}
- return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
-}
-
-static
-int
-utf16le_to_ucs4_length(const uint8_t* frm, const uint8_t* frm_end,
- size_t mx, unsigned long Maxcode = 0x10FFFF,
- codecvt_mode mode = codecvt_mode(0))
-{
- const uint8_t* frm_nxt = frm;
- if (mode & consume_header)
- {
- if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFF && frm_nxt[1] == 0xFE)
- frm_nxt += 2;
+ }
+ return static_cast<int>(frm_nxt - frm);
+}
+
+static codecvt_base::result ucs4_to_utf16be(
+ const uint32_t* frm,
+ const uint32_t* frm_end,
+ const uint32_t*& frm_nxt,
+ uint8_t* to,
+ uint8_t* to_end,
+ uint8_t*& to_nxt,
+ unsigned long Maxcode = 0x10FFFF,
+ codecvt_mode mode = codecvt_mode(0)) {
+ frm_nxt = frm;
+ to_nxt = to;
+ if (mode & generate_header) {
+ if (to_end - to_nxt < 2)
+ return codecvt_base::partial;
+ *to_nxt++ = static_cast<uint8_t>(0xFE);
+ *to_nxt++ = static_cast<uint8_t>(0xFF);
+ }
+ for (; frm_nxt < frm_end; ++frm_nxt) {
+ uint32_t wc = *frm_nxt;
+ if ((wc & 0xFFFFF800) == 0x00D800 || wc > Maxcode)
+ return codecvt_base::error;
+ if (wc < 0x010000) {
+ if (to_end - to_nxt < 2)
+ return codecvt_base::partial;
+ *to_nxt++ = static_cast<uint8_t>(wc >> 8);
+ *to_nxt++ = static_cast<uint8_t>(wc);
+ } else {
+ if (to_end - to_nxt < 4)
+ return codecvt_base::partial;
+ uint16_t t = static_cast<uint16_t>(0xD800 | ((((wc & 0x1F0000) >> 16) - 1) << 6) | ((wc & 0x00FC00) >> 10));
+ *to_nxt++ = static_cast<uint8_t>(t >> 8);
+ *to_nxt++ = static_cast<uint8_t>(t);
+ t = static_cast<uint16_t>(0xDC00 | (wc & 0x03FF));
+ *to_nxt++ = static_cast<uint8_t>(t >> 8);
+ *to_nxt++ = static_cast<uint8_t>(t);
}
- for (size_t nchar32_t = 0; frm_nxt < frm_end - 1 && nchar32_t < mx; ++nchar32_t)
- {
- uint16_t c1 = static_cast<uint16_t>(frm_nxt[1] << 8 | frm_nxt[0]);
- if ((c1 & 0xFC00) == 0xDC00)
- break;
- if ((c1 & 0xFC00) != 0xD800)
- {
- if (c1 > Maxcode)
- break;
- frm_nxt += 2;
- }
- else
- {
- if (frm_end-frm_nxt < 4)
- break;
- uint16_t c2 = static_cast<uint16_t>(frm_nxt[3] << 8 | frm_nxt[2]);
- if ((c2 & 0xFC00) != 0xDC00)
- break;
- uint32_t t = static_cast<uint32_t>(
- ((((c1 & 0x03C0) >> 6) + 1) << 16)
- | ((c1 & 0x003F) << 10)
- | (c2 & 0x03FF));
- if (t > Maxcode)
- break;
- frm_nxt += 4;
- }
+ }
+ return codecvt_base::ok;
+}
+
+static codecvt_base::result utf16be_to_ucs4(
+ const uint8_t* frm,
+ const uint8_t* frm_end,
+ const uint8_t*& frm_nxt,
+ uint32_t* to,
+ uint32_t* to_end,
+ uint32_t*& to_nxt,
+ unsigned long Maxcode = 0x10FFFF,
+ codecvt_mode mode = codecvt_mode(0)) {
+ frm_nxt = frm;
+ to_nxt = to;
+ if (mode & consume_header) {
+ if (frm_end - frm_nxt >= 2 && frm_nxt[0] == 0xFE && frm_nxt[1] == 0xFF)
+ frm_nxt += 2;
+ }
+ for (; frm_nxt < frm_end - 1 && to_nxt < to_end; ++to_nxt) {
+ uint16_t c1 = static_cast<uint16_t>(frm_nxt[0] << 8 | frm_nxt[1]);
+ if ((c1 & 0xFC00) == 0xDC00)
+ return codecvt_base::error;
+ if ((c1 & 0xFC00) != 0xD800) {
+ if (c1 > Maxcode)
+ return codecvt_base::error;
+ *to_nxt = static_cast<uint32_t>(c1);
+ frm_nxt += 2;
+ } else {
+ if (frm_end - frm_nxt < 4)
+ return codecvt_base::partial;
+ uint16_t c2 = static_cast<uint16_t>(frm_nxt[2] << 8 | frm_nxt[3]);
+ if ((c2 & 0xFC00) != 0xDC00)
+ return codecvt_base::error;
+ uint32_t t = static_cast<uint32_t>(((((c1 & 0x03C0) >> 6) + 1) << 16) | ((c1 & 0x003F) << 10) | (c2 & 0x03FF));
+ if (t > Maxcode)
+ return codecvt_base::error;
+ *to_nxt = t;
+ frm_nxt += 4;
}
- return static_cast<int>(frm_nxt - frm);
-}
-
-static
-codecvt_base::result
-ucs2_to_utf16be(const uint16_t* frm, const uint16_t* frm_end, const uint16_t*& frm_nxt,
- uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
- unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
-{
- frm_nxt = frm;
- to_nxt = to;
- if (mode & generate_header)
- {
- if (to_end-to_nxt < 2)
- return codecvt_base::partial;
- *to_nxt++ = static_cast<uint8_t>(0xFE);
- *to_nxt++ = static_cast<uint8_t>(0xFF);
+ }
+ return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
+}
+
+static int utf16be_to_ucs4_length(
+ const uint8_t* frm,
+ const uint8_t* frm_end,
+ size_t mx,
+ unsigned long Maxcode = 0x10FFFF,
+ codecvt_mode mode = codecvt_mode(0)) {
+ const uint8_t* frm_nxt = frm;
+ if (mode & consume_header) {
+ if (frm_end - frm_nxt >= 2 && frm_nxt[0] == 0xFE && frm_nxt[1] == 0xFF)
+ frm_nxt += 2;
+ }
+ for (size_t nchar32_t = 0; frm_nxt < frm_end - 1 && nchar32_t < mx; ++nchar32_t) {
+ uint16_t c1 = static_cast<uint16_t>(frm_nxt[0] << 8 | frm_nxt[1]);
+ if ((c1 & 0xFC00) == 0xDC00)
+ break;
+ if ((c1 & 0xFC00) != 0xD800) {
+ if (c1 > Maxcode)
+ break;
+ frm_nxt += 2;
+ } else {
+ if (frm_end - frm_nxt < 4)
+ break;
+ uint16_t c2 = static_cast<uint16_t>(frm_nxt[2] << 8 | frm_nxt[3]);
+ if ((c2 & 0xFC00) != 0xDC00)
+ break;
+ uint32_t t = static_cast<uint32_t>(((((c1 & 0x03C0) >> 6) + 1) << 16) | ((c1 & 0x003F) << 10) | (c2 & 0x03FF));
+ if (t > Maxcode)
+ break;
+ frm_nxt += 4;
}
- for (; frm_nxt < frm_end; ++frm_nxt)
- {
- uint16_t wc = *frm_nxt;
- if ((wc & 0xF800) == 0xD800 || wc > Maxcode)
- return codecvt_base::error;
- if (to_end-to_nxt < 2)
- return codecvt_base::partial;
- *to_nxt++ = static_cast<uint8_t>(wc >> 8);
- *to_nxt++ = static_cast<uint8_t>(wc);
+ }
+ return static_cast<int>(frm_nxt - frm);
+}
+
+static codecvt_base::result ucs4_to_utf16le(
+ const uint32_t* frm,
+ const uint32_t* frm_end,
+ const uint32_t*& frm_nxt,
+ uint8_t* to,
+ uint8_t* to_end,
+ uint8_t*& to_nxt,
+ unsigned long Maxcode = 0x10FFFF,
+ codecvt_mode mode = codecvt_mode(0)) {
+ frm_nxt = frm;
+ to_nxt = to;
+ if (mode & generate_header) {
+ if (to_end - to_nxt < 2)
+ return codecvt_base::partial;
+ *to_nxt++ = static_cast<uint8_t>(0xFF);
+ *to_nxt++ = static_cast<uint8_t>(0xFE);
+ }
+ for (; frm_nxt < frm_end; ++frm_nxt) {
+ uint32_t wc = *frm_nxt;
+ if ((wc & 0xFFFFF800) == 0x00D800 || wc > Maxcode)
+ return codecvt_base::error;
+ if (wc < 0x010000) {
+ if (to_end - to_nxt < 2)
+ return codecvt_base::partial;
+ *to_nxt++ = static_cast<uint8_t>(wc);
+ *to_nxt++ = static_cast<uint8_t>(wc >> 8);
+ } else {
+ if (to_end - to_nxt < 4)
+ return codecvt_base::partial;
+ uint16_t t = static_cast<uint16_t>(0xD800 | ((((wc & 0x1F0000) >> 16) - 1) << 6) | ((wc & 0x00FC00) >> 10));
+ *to_nxt++ = static_cast<uint8_t>(t);
+ *to_nxt++ = static_cast<uint8_t>(t >> 8);
+ t = static_cast<uint16_t>(0xDC00 | (wc & 0x03FF));
+ *to_nxt++ = static_cast<uint8_t>(t);
+ *to_nxt++ = static_cast<uint8_t>(t >> 8);
}
- return codecvt_base::ok;
-}
-
-static
-codecvt_base::result
-utf16be_to_ucs2(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
- uint16_t* to, uint16_t* to_end, uint16_t*& to_nxt,
- unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
-{
- frm_nxt = frm;
- to_nxt = to;
- if (mode & consume_header)
- {
- if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFE && frm_nxt[1] == 0xFF)
- frm_nxt += 2;
+ }
+ return codecvt_base::ok;
+}
+
+static codecvt_base::result utf16le_to_ucs4(
+ const uint8_t* frm,
+ const uint8_t* frm_end,
+ const uint8_t*& frm_nxt,
+ uint32_t* to,
+ uint32_t* to_end,
+ uint32_t*& to_nxt,
+ unsigned long Maxcode = 0x10FFFF,
+ codecvt_mode mode = codecvt_mode(0)) {
+ frm_nxt = frm;
+ to_nxt = to;
+ if (mode & consume_header) {
+ if (frm_end - frm_nxt >= 2 && frm_nxt[0] == 0xFF && frm_nxt[1] == 0xFE)
+ frm_nxt += 2;
+ }
+ for (; frm_nxt < frm_end - 1 && to_nxt < to_end; ++to_nxt) {
+ uint16_t c1 = static_cast<uint16_t>(frm_nxt[1] << 8 | frm_nxt[0]);
+ if ((c1 & 0xFC00) == 0xDC00)
+ return codecvt_base::error;
+ if ((c1 & 0xFC00) != 0xD800) {
+ if (c1 > Maxcode)
+ return codecvt_base::error;
+ *to_nxt = static_cast<uint32_t>(c1);
+ frm_nxt += 2;
+ } else {
+ if (frm_end - frm_nxt < 4)
+ return codecvt_base::partial;
+ uint16_t c2 = static_cast<uint16_t>(frm_nxt[3] << 8 | frm_nxt[2]);
+ if ((c2 & 0xFC00) != 0xDC00)
+ return codecvt_base::error;
+ uint32_t t = static_cast<uint32_t>(((((c1 & 0x03C0) >> 6) + 1) << 16) | ((c1 & 0x003F) << 10) | (c2 & 0x03FF));
+ if (t > Maxcode)
+ return codecvt_base::error;
+ *to_nxt = t;
+ frm_nxt += 4;
}
- for (; frm_nxt < frm_end - 1 && to_nxt < to_end; ++to_nxt)
- {
- uint16_t c1 = static_cast<uint16_t>(frm_nxt[0] << 8 | frm_nxt[1]);
- if ((c1 & 0xF800) == 0xD800 || c1 > Maxcode)
- return codecvt_base::error;
- *to_nxt = c1;
- frm_nxt += 2;
+ }
+ return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
+}
+
+static int utf16le_to_ucs4_length(
+ const uint8_t* frm,
+ const uint8_t* frm_end,
+ size_t mx,
+ unsigned long Maxcode = 0x10FFFF,
+ codecvt_mode mode = codecvt_mode(0)) {
+ const uint8_t* frm_nxt = frm;
+ if (mode & consume_header) {
+ if (frm_end - frm_nxt >= 2 && frm_nxt[0] == 0xFF && frm_nxt[1] == 0xFE)
+ frm_nxt += 2;
+ }
+ for (size_t nchar32_t = 0; frm_nxt < frm_end - 1 && nchar32_t < mx; ++nchar32_t) {
+ uint16_t c1 = static_cast<uint16_t>(frm_nxt[1] << 8 | frm_nxt[0]);
+ if ((c1 & 0xFC00) == 0xDC00)
+ break;
+ if ((c1 & 0xFC00) != 0xD800) {
+ if (c1 > Maxcode)
+ break;
+ frm_nxt += 2;
+ } else {
+ if (frm_end - frm_nxt < 4)
+ break;
+ uint16_t c2 = static_cast<uint16_t>(frm_nxt[3] << 8 | frm_nxt[2]);
+ if ((c2 & 0xFC00) != 0xDC00)
+ break;
+ uint32_t t = static_cast<uint32_t>(((((c1 & 0x03C0) >> 6) + 1) << 16) | ((c1 & 0x003F) << 10) | (c2 & 0x03FF));
+ if (t > Maxcode)
+ break;
+ frm_nxt += 4;
}
- return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
+ }
+ return static_cast<int>(frm_nxt - frm);
+}
+
+static codecvt_base::result ucs2_to_utf16be(
+ const uint16_t* frm,
+ const uint16_t* frm_end,
+ const uint16_t*& frm_nxt,
+ uint8_t* to,
+ uint8_t* to_end,
+ uint8_t*& to_nxt,
+ unsigned long Maxcode = 0x10FFFF,
+ codecvt_mode mode = codecvt_mode(0)) {
+ frm_nxt = frm;
+ to_nxt = to;
+ if (mode & generate_header) {
+ if (to_end - to_nxt < 2)
+ return codecvt_base::partial;
+ *to_nxt++ = static_cast<uint8_t>(0xFE);
+ *to_nxt++ = static_cast<uint8_t>(0xFF);
+ }
+ for (; frm_nxt < frm_end; ++frm_nxt) {
+ uint16_t wc = *frm_nxt;
+ if ((wc & 0xF800) == 0xD800 || wc > Maxcode)
+ return codecvt_base::error;
+ if (to_end - to_nxt < 2)
+ return codecvt_base::partial;
+ *to_nxt++ = static_cast<uint8_t>(wc >> 8);
+ *to_nxt++ = static_cast<uint8_t>(wc);
+ }
+ return codecvt_base::ok;
+}
+
+static codecvt_base::result utf16be_to_ucs2(
+ const uint8_t* frm,
+ const uint8_t* frm_end,
+ const uint8_t*& frm_nxt,
+ uint16_t* to,
+ uint16_t* to_end,
+ uint16_t*& to_nxt,
+ unsigned long Maxcode = 0x10FFFF,
+ codecvt_mode mode = codecvt_mode(0)) {
+ frm_nxt = frm;
+ to_nxt = to;
+ if (mode & consume_header) {
+ if (frm_end - frm_nxt >= 2 && frm_nxt[0] == 0xFE && frm_nxt[1] == 0xFF)
+ frm_nxt += 2;
+ }
+ for (; frm_nxt < frm_end - 1 && to_nxt < to_end; ++to_nxt) {
+ uint16_t c1 = static_cast<uint16_t>(frm_nxt[0] << 8 | frm_nxt[1]);
+ if ((c1 & 0xF800) == 0xD800 || c1 > Maxcode)
+ return codecvt_base::error;
+ *to_nxt = c1;
+ frm_nxt += 2;
+ }
+ return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
+}
+
+static int utf16be_to_ucs2_length(
+ const uint8_t* frm,
+ const uint8_t* frm_end,
+ size_t mx,
+ unsigned long Maxcode = 0x10FFFF,
+ codecvt_mode mode = codecvt_mode(0)) {
+ const uint8_t* frm_nxt = frm;
+ if (mode & consume_header) {
+ if (frm_end - frm_nxt >= 2 && frm_nxt[0] == 0xFE && frm_nxt[1] == 0xFF)
+ frm_nxt += 2;
+ }
+ for (size_t nchar16_t = 0; frm_nxt < frm_end - 1 && nchar16_t < mx; ++nchar16_t) {
+ uint16_t c1 = static_cast<uint16_t>(frm_nxt[0] << 8 | frm_nxt[1]);
+ if ((c1 & 0xF800) == 0xD800 || c1 > Maxcode)
+ break;
+ frm_nxt += 2;
+ }
+ return static_cast<int>(frm_nxt - frm);
+}
+
+static codecvt_base::result ucs2_to_utf16le(
+ const uint16_t* frm,
+ const uint16_t* frm_end,
+ const uint16_t*& frm_nxt,
+ uint8_t* to,
+ uint8_t* to_end,
+ uint8_t*& to_nxt,
+ unsigned long Maxcode = 0x10FFFF,
+ codecvt_mode mode = codecvt_mode(0)) {
+ frm_nxt = frm;
+ to_nxt = to;
+ if (mode & generate_header) {
+ if (to_end - to_nxt < 2)
+ return codecvt_base::partial;
+ *to_nxt++ = static_cast<uint8_t>(0xFF);
+ *to_nxt++ = static_cast<uint8_t>(0xFE);
+ }
+ for (; frm_nxt < frm_end; ++frm_nxt) {
+ uint16_t wc = *frm_nxt;
+ if ((wc & 0xF800) == 0xD800 || wc > Maxcode)
+ return codecvt_base::error;
+ if (to_end - to_nxt < 2)
+ return codecvt_base::partial;
+ *to_nxt++ = static_cast<uint8_t>(wc);
+ *to_nxt++ = static_cast<uint8_t>(wc >> 8);
+ }
+ return codecvt_base::ok;
+}
+
+static codecvt_base::result utf16le_to_ucs2(
+ const uint8_t* frm,
+ const uint8_t* frm_end,
+ const uint8_t*& frm_nxt,
+ uint16_t* to,
+ uint16_t* to_end,
+ uint16_t*& to_nxt,
+ unsigned long Maxcode = 0x10FFFF,
+ codecvt_mode mode = codecvt_mode(0)) {
+ frm_nxt = frm;
+ to_nxt = to;
+ if (mode & consume_header) {
+ if (frm_end - frm_nxt >= 2 && frm_nxt[0] == 0xFF && frm_nxt[1] == 0xFE)
+ frm_nxt += 2;
+ }
+ for (; frm_nxt < frm_end - 1 && to_nxt < to_end; ++to_nxt) {
+ uint16_t c1 = static_cast<uint16_t>(frm_nxt[1] << 8 | frm_nxt[0]);
+ if ((c1 & 0xF800) == 0xD800 || c1 > Maxcode)
+ return codecvt_base::error;
+ *to_nxt = c1;
+ frm_nxt += 2;
+ }
+ return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
+}
+
+static int utf16le_to_ucs2_length(
+ const uint8_t* frm,
+ const uint8_t* frm_end,
+ size_t mx,
+ unsigned long Maxcode = 0x10FFFF,
+ codecvt_mode mode = codecvt_mode(0)) {
+ const uint8_t* frm_nxt = frm;
+ frm_nxt = frm;
+ if (mode & consume_header) {
+ if (frm_end - frm_nxt >= 2 && frm_nxt[0] == 0xFF && frm_nxt[1] == 0xFE)
+ frm_nxt += 2;
+ }
+ for (size_t nchar16_t = 0; frm_nxt < frm_end - 1 && nchar16_t < mx; ++nchar16_t) {
+ uint16_t c1 = static_cast<uint16_t>(frm_nxt[1] << 8 | frm_nxt[0]);
+ if ((c1 & 0xF800) == 0xD800 || c1 > Maxcode)
+ break;
+ frm_nxt += 2;
+ }
+ return static_cast<int>(frm_nxt - frm);
}
-static
-int
-utf16be_to_ucs2_length(const uint8_t* frm, const uint8_t* frm_end,
- size_t mx, unsigned long Maxcode = 0x10FFFF,
- codecvt_mode mode = codecvt_mode(0))
-{
- const uint8_t* frm_nxt = frm;
- if (mode & consume_header)
- {
- if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFE && frm_nxt[1] == 0xFF)
- frm_nxt += 2;
- }
- for (size_t nchar16_t = 0; frm_nxt < frm_end - 1 && nchar16_t < mx; ++nchar16_t)
- {
- uint16_t c1 = static_cast<uint16_t>(frm_nxt[0] << 8 | frm_nxt[1]);
- if ((c1 & 0xF800) == 0xD800 || c1 > Maxcode)
- break;
- frm_nxt += 2;
- }
- return static_cast<int>(frm_nxt - frm);
-}
-
-static
-codecvt_base::result
-ucs2_to_utf16le(const uint16_t* frm, const uint16_t* frm_end, const uint16_t*& frm_nxt,
- uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
- unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
-{
- frm_nxt = frm;
- to_nxt = to;
- if (mode & generate_header)
- {
- if (to_end-to_nxt < 2)
- return codecvt_base::partial;
- *to_nxt++ = static_cast<uint8_t>(0xFF);
- *to_nxt++ = static_cast<uint8_t>(0xFE);
- }
- for (; frm_nxt < frm_end; ++frm_nxt)
- {
- uint16_t wc = *frm_nxt;
- if ((wc & 0xF800) == 0xD800 || wc > Maxcode)
- return codecvt_base::error;
- if (to_end-to_nxt < 2)
- return codecvt_base::partial;
- *to_nxt++ = static_cast<uint8_t>(wc);
- *to_nxt++ = static_cast<uint8_t>(wc >> 8);
- }
- return codecvt_base::ok;
-}
-
-static
-codecvt_base::result
-utf16le_to_ucs2(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
- uint16_t* to, uint16_t* to_end, uint16_t*& to_nxt,
- unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
-{
- frm_nxt = frm;
- to_nxt = to;
- if (mode & consume_header)
- {
- if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFF && frm_nxt[1] == 0xFE)
- frm_nxt += 2;
- }
- for (; frm_nxt < frm_end - 1 && to_nxt < to_end; ++to_nxt)
- {
- uint16_t c1 = static_cast<uint16_t>(frm_nxt[1] << 8 | frm_nxt[0]);
- if ((c1 & 0xF800) == 0xD800 || c1 > Maxcode)
- return codecvt_base::error;
- *to_nxt = c1;
- frm_nxt += 2;
- }
- return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
-}
-
-static
-int
-utf16le_to_ucs2_length(const uint8_t* frm, const uint8_t* frm_end,
- size_t mx, unsigned long Maxcode = 0x10FFFF,
- codecvt_mode mode = codecvt_mode(0))
-{
- const uint8_t* frm_nxt = frm;
- frm_nxt = frm;
- if (mode & consume_header)
- {
- if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFF && frm_nxt[1] == 0xFE)
- frm_nxt += 2;
- }
- for (size_t nchar16_t = 0; frm_nxt < frm_end - 1 && nchar16_t < mx; ++nchar16_t)
- {
- uint16_t c1 = static_cast<uint16_t>(frm_nxt[1] << 8 | frm_nxt[0]);
- if ((c1 & 0xF800) == 0xD800 || c1 > Maxcode)
- break;
- frm_nxt += 2;
- }
- return static_cast<int>(frm_nxt - frm);
-}
+_LIBCPP_SUPPRESS_DEPRECATED_POP
// template <> class codecvt<char16_t, char, mbstate_t>
-locale::id codecvt<char16_t, char, mbstate_t>::id;
-
-codecvt<char16_t, char, mbstate_t>::~codecvt()
-{
-}
-
-codecvt<char16_t, char, mbstate_t>::result
-codecvt<char16_t, char, mbstate_t>::do_out(state_type&,
- const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
- extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
-{
- const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
- const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
- const uint16_t* _frm_nxt = _frm;
- uint8_t* _to = reinterpret_cast<uint8_t*>(to);
- uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
- uint8_t* _to_nxt = _to;
- result r = utf16_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
-}
-
-codecvt<char16_t, char, mbstate_t>::result
-codecvt<char16_t, char, mbstate_t>::do_in(state_type&,
- const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
- intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
-{
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- const uint8_t* _frm_nxt = _frm;
- uint16_t* _to = reinterpret_cast<uint16_t*>(to);
- uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
- uint16_t* _to_nxt = _to;
- result r = utf8_to_utf16(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
+constinit locale::id codecvt<char16_t, char, mbstate_t>::id;
+
+codecvt<char16_t, char, mbstate_t>::~codecvt() {}
+
+codecvt<char16_t, char, mbstate_t>::result codecvt<char16_t, char, mbstate_t>::do_out(
+ state_type&,
+ const intern_type* frm,
+ const intern_type* frm_end,
+ const intern_type*& frm_nxt,
+ extern_type* to,
+ extern_type* to_end,
+ extern_type*& to_nxt) const {
+ const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
+ const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
+ const uint16_t* _frm_nxt = _frm;
+ uint8_t* _to = reinterpret_cast<uint8_t*>(to);
+ uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
+ uint8_t* _to_nxt = _to;
+ result r = utf16_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt);
+ frm_nxt = frm + (_frm_nxt - _frm);
+ to_nxt = to + (_to_nxt - _to);
+ return r;
+}
+
+codecvt<char16_t, char, mbstate_t>::result codecvt<char16_t, char, mbstate_t>::do_in(
+ state_type&,
+ const extern_type* frm,
+ const extern_type* frm_end,
+ const extern_type*& frm_nxt,
+ intern_type* to,
+ intern_type* to_end,
+ intern_type*& to_nxt) const {
+ const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
+ const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
+ const uint8_t* _frm_nxt = _frm;
+ uint16_t* _to = reinterpret_cast<uint16_t*>(to);
+ uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
+ uint16_t* _to_nxt = _to;
+ result r = utf8_to_utf16(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt);
+ frm_nxt = frm + (_frm_nxt - _frm);
+ to_nxt = to + (_to_nxt - _to);
+ return r;
}
codecvt<char16_t, char, mbstate_t>::result
-codecvt<char16_t, char, mbstate_t>::do_unshift(state_type&,
- extern_type* to, extern_type*, extern_type*& to_nxt) const
-{
- to_nxt = to;
- return noconv;
+codecvt<char16_t, char, mbstate_t>::do_unshift(state_type&, extern_type* to, extern_type*, extern_type*& to_nxt) const {
+ to_nxt = to;
+ return noconv;
}
-int
-codecvt<char16_t, char, mbstate_t>::do_encoding() const _NOEXCEPT
-{
- return 0;
-}
+int codecvt<char16_t, char, mbstate_t>::do_encoding() const noexcept { return 0; }
-bool
-codecvt<char16_t, char, mbstate_t>::do_always_noconv() const _NOEXCEPT
-{
- return false;
-}
+bool codecvt<char16_t, char, mbstate_t>::do_always_noconv() const noexcept { return false; }
-int
-codecvt<char16_t, char, mbstate_t>::do_length(state_type&,
- const extern_type* frm, const extern_type* frm_end, size_t mx) const
-{
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- return utf8_to_utf16_length(_frm, _frm_end, mx);
+int codecvt<char16_t, char, mbstate_t>::do_length(
+ state_type&, const extern_type* frm, const extern_type* frm_end, size_t mx) const {
+ const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
+ const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
+ return utf8_to_utf16_length(_frm, _frm_end, mx);
}
-int
-codecvt<char16_t, char, mbstate_t>::do_max_length() const _NOEXCEPT
-{
- return 4;
-}
+int codecvt<char16_t, char, mbstate_t>::do_max_length() const noexcept { return 4; }
-#ifndef _LIBCPP_NO_HAS_CHAR8_T
+#ifndef _LIBCPP_HAS_NO_CHAR8_T
// template <> class codecvt<char16_t, char8_t, mbstate_t>
-locale::id codecvt<char16_t, char8_t, mbstate_t>::id;
-
-codecvt<char16_t, char8_t, mbstate_t>::~codecvt()
-{
-}
-
-codecvt<char16_t, char8_t, mbstate_t>::result
-codecvt<char16_t, char8_t, mbstate_t>::do_out(state_type&,
- const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
- extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
-{
- const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
- const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
- const uint16_t* _frm_nxt = _frm;
- uint8_t* _to = reinterpret_cast<uint8_t*>(to);
- uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
- uint8_t* _to_nxt = _to;
- result r = utf16_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
-}
-
-codecvt<char16_t, char8_t, mbstate_t>::result
-codecvt<char16_t, char8_t, mbstate_t>::do_in(state_type&,
- const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
- intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
-{
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- const uint8_t* _frm_nxt = _frm;
- uint16_t* _to = reinterpret_cast<uint16_t*>(to);
- uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
- uint16_t* _to_nxt = _to;
- result r = utf8_to_utf16(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
-}
-
-codecvt<char16_t, char8_t, mbstate_t>::result
-codecvt<char16_t, char8_t, mbstate_t>::do_unshift(state_type&,
- extern_type* to, extern_type*, extern_type*& to_nxt) const
-{
- to_nxt = to;
- return noconv;
-}
-
-int
-codecvt<char16_t, char8_t, mbstate_t>::do_encoding() const _NOEXCEPT
-{
- return 0;
-}
-
-bool
-codecvt<char16_t, char8_t, mbstate_t>::do_always_noconv() const _NOEXCEPT
-{
- return false;
-}
-
-int
-codecvt<char16_t, char8_t, mbstate_t>::do_length(state_type&,
- const extern_type* frm, const extern_type* frm_end, size_t mx) const
-{
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- return utf8_to_utf16_length(_frm, _frm_end, mx);
-}
-
-int
-codecvt<char16_t, char8_t, mbstate_t>::do_max_length() const _NOEXCEPT
-{
- return 4;
-}
+constinit locale::id codecvt<char16_t, char8_t, mbstate_t>::id;
+
+codecvt<char16_t, char8_t, mbstate_t>::~codecvt() {}
+
+codecvt<char16_t, char8_t, mbstate_t>::result codecvt<char16_t, char8_t, mbstate_t>::do_out(
+ state_type&,
+ const intern_type* frm,
+ const intern_type* frm_end,
+ const intern_type*& frm_nxt,
+ extern_type* to,
+ extern_type* to_end,
+ extern_type*& to_nxt) const {
+ const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
+ const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
+ const uint16_t* _frm_nxt = _frm;
+ uint8_t* _to = reinterpret_cast<uint8_t*>(to);
+ uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
+ uint8_t* _to_nxt = _to;
+ result r = utf16_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt);
+ frm_nxt = frm + (_frm_nxt - _frm);
+ to_nxt = to + (_to_nxt - _to);
+ return r;
+}
+
+codecvt<char16_t, char8_t, mbstate_t>::result codecvt<char16_t, char8_t, mbstate_t>::do_in(
+ state_type&,
+ const extern_type* frm,
+ const extern_type* frm_end,
+ const extern_type*& frm_nxt,
+ intern_type* to,
+ intern_type* to_end,
+ intern_type*& to_nxt) const {
+ const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
+ const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
+ const uint8_t* _frm_nxt = _frm;
+ uint16_t* _to = reinterpret_cast<uint16_t*>(to);
+ uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
+ uint16_t* _to_nxt = _to;
+ result r = utf8_to_utf16(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt);
+ frm_nxt = frm + (_frm_nxt - _frm);
+ to_nxt = to + (_to_nxt - _to);
+ return r;
+}
+
+codecvt<char16_t, char8_t, mbstate_t>::result codecvt<char16_t, char8_t, mbstate_t>::do_unshift(
+ state_type&, extern_type* to, extern_type*, extern_type*& to_nxt) const {
+ to_nxt = to;
+ return noconv;
+}
+
+int codecvt<char16_t, char8_t, mbstate_t>::do_encoding() const noexcept { return 0; }
+
+bool codecvt<char16_t, char8_t, mbstate_t>::do_always_noconv() const noexcept { return false; }
+
+int codecvt<char16_t, char8_t, mbstate_t>::do_length(
+ state_type&, const extern_type* frm, const extern_type* frm_end, size_t mx) const {
+ const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
+ const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
+ return utf8_to_utf16_length(_frm, _frm_end, mx);
+}
+
+int codecvt<char16_t, char8_t, mbstate_t>::do_max_length() const noexcept { return 4; }
#endif
// template <> class codecvt<char32_t, char, mbstate_t>
-locale::id codecvt<char32_t, char, mbstate_t>::id;
-
-codecvt<char32_t, char, mbstate_t>::~codecvt()
-{
+constinit locale::id codecvt<char32_t, char, mbstate_t>::id;
+
+codecvt<char32_t, char, mbstate_t>::~codecvt() {}
+
+codecvt<char32_t, char, mbstate_t>::result codecvt<char32_t, char, mbstate_t>::do_out(
+ state_type&,
+ const intern_type* frm,
+ const intern_type* frm_end,
+ const intern_type*& frm_nxt,
+ extern_type* to,
+ extern_type* to_end,
+ extern_type*& to_nxt) const {
+ const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
+ const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
+ const uint32_t* _frm_nxt = _frm;
+ uint8_t* _to = reinterpret_cast<uint8_t*>(to);
+ uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
+ uint8_t* _to_nxt = _to;
+ result r = ucs4_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt);
+ frm_nxt = frm + (_frm_nxt - _frm);
+ to_nxt = to + (_to_nxt - _to);
+ return r;
+}
+
+codecvt<char32_t, char, mbstate_t>::result codecvt<char32_t, char, mbstate_t>::do_in(
+ state_type&,
+ const extern_type* frm,
+ const extern_type* frm_end,
+ const extern_type*& frm_nxt,
+ intern_type* to,
+ intern_type* to_end,
+ intern_type*& to_nxt) const {
+ const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
+ const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
+ const uint8_t* _frm_nxt = _frm;
+ uint32_t* _to = reinterpret_cast<uint32_t*>(to);
+ uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
+ uint32_t* _to_nxt = _to;
+ result r = utf8_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt);
+ frm_nxt = frm + (_frm_nxt - _frm);
+ to_nxt = to + (_to_nxt - _to);
+ return r;
}
codecvt<char32_t, char, mbstate_t>::result
-codecvt<char32_t, char, mbstate_t>::do_out(state_type&,
- const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
- extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
-{
- const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
- const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
- const uint32_t* _frm_nxt = _frm;
- uint8_t* _to = reinterpret_cast<uint8_t*>(to);
- uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
- uint8_t* _to_nxt = _to;
- result r = ucs4_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
+codecvt<char32_t, char, mbstate_t>::do_unshift(state_type&, extern_type* to, extern_type*, extern_type*& to_nxt) const {
+ to_nxt = to;
+ return noconv;
}
-codecvt<char32_t, char, mbstate_t>::result
-codecvt<char32_t, char, mbstate_t>::do_in(state_type&,
- const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
- intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
-{
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- const uint8_t* _frm_nxt = _frm;
- uint32_t* _to = reinterpret_cast<uint32_t*>(to);
- uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
- uint32_t* _to_nxt = _to;
- result r = utf8_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
-}
+int codecvt<char32_t, char, mbstate_t>::do_encoding() const noexcept { return 0; }
-codecvt<char32_t, char, mbstate_t>::result
-codecvt<char32_t, char, mbstate_t>::do_unshift(state_type&,
- extern_type* to, extern_type*, extern_type*& to_nxt) const
-{
- to_nxt = to;
- return noconv;
-}
+bool codecvt<char32_t, char, mbstate_t>::do_always_noconv() const noexcept { return false; }
-int
-codecvt<char32_t, char, mbstate_t>::do_encoding() const _NOEXCEPT
-{
- return 0;
+int codecvt<char32_t, char, mbstate_t>::do_length(
+ state_type&, const extern_type* frm, const extern_type* frm_end, size_t mx) const {
+ const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
+ const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
+ return utf8_to_ucs4_length(_frm, _frm_end, mx);
}
-bool
-codecvt<char32_t, char, mbstate_t>::do_always_noconv() const _NOEXCEPT
-{
- return false;
-}
+int codecvt<char32_t, char, mbstate_t>::do_max_length() const noexcept { return 4; }
-int
-codecvt<char32_t, char, mbstate_t>::do_length(state_type&,
- const extern_type* frm, const extern_type* frm_end, size_t mx) const
-{
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- return utf8_to_ucs4_length(_frm, _frm_end, mx);
-}
-
-int
-codecvt<char32_t, char, mbstate_t>::do_max_length() const _NOEXCEPT
-{
- return 4;
-}
-
-#ifndef _LIBCPP_NO_HAS_CHAR8_T
+#ifndef _LIBCPP_HAS_NO_CHAR8_T
// template <> class codecvt<char32_t, char8_t, mbstate_t>
-locale::id codecvt<char32_t, char8_t, mbstate_t>::id;
-
-codecvt<char32_t, char8_t, mbstate_t>::~codecvt()
-{
-}
-
-codecvt<char32_t, char8_t, mbstate_t>::result
-codecvt<char32_t, char8_t, mbstate_t>::do_out(state_type&,
- const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
- extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
-{
- const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
- const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
- const uint32_t* _frm_nxt = _frm;
- uint8_t* _to = reinterpret_cast<uint8_t*>(to);
- uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
- uint8_t* _to_nxt = _to;
- result r = ucs4_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
-}
-
-codecvt<char32_t, char8_t, mbstate_t>::result
-codecvt<char32_t, char8_t, mbstate_t>::do_in(state_type&,
- const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
- intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
-{
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- const uint8_t* _frm_nxt = _frm;
- uint32_t* _to = reinterpret_cast<uint32_t*>(to);
- uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
- uint32_t* _to_nxt = _to;
- result r = utf8_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
-}
-
-codecvt<char32_t, char8_t, mbstate_t>::result
-codecvt<char32_t, char8_t, mbstate_t>::do_unshift(state_type&,
- extern_type* to, extern_type*, extern_type*& to_nxt) const
-{
- to_nxt = to;
- return noconv;
-}
-
-int
-codecvt<char32_t, char8_t, mbstate_t>::do_encoding() const _NOEXCEPT
-{
- return 0;
-}
-
-bool
-codecvt<char32_t, char8_t, mbstate_t>::do_always_noconv() const _NOEXCEPT
-{
- return false;
-}
-
-int
-codecvt<char32_t, char8_t, mbstate_t>::do_length(state_type&,
- const extern_type* frm, const extern_type* frm_end, size_t mx) const
-{
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- return utf8_to_ucs4_length(_frm, _frm_end, mx);
-}
-
-int
-codecvt<char32_t, char8_t, mbstate_t>::do_max_length() const _NOEXCEPT
-{
- return 4;
-}
+constinit locale::id codecvt<char32_t, char8_t, mbstate_t>::id;
+
+codecvt<char32_t, char8_t, mbstate_t>::~codecvt() {}
+
+codecvt<char32_t, char8_t, mbstate_t>::result codecvt<char32_t, char8_t, mbstate_t>::do_out(
+ state_type&,
+ const intern_type* frm,
+ const intern_type* frm_end,
+ const intern_type*& frm_nxt,
+ extern_type* to,
+ extern_type* to_end,
+ extern_type*& to_nxt) const {
+ const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
+ const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
+ const uint32_t* _frm_nxt = _frm;
+ uint8_t* _to = reinterpret_cast<uint8_t*>(to);
+ uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
+ uint8_t* _to_nxt = _to;
+ result r = ucs4_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt);
+ frm_nxt = frm + (_frm_nxt - _frm);
+ to_nxt = to + (_to_nxt - _to);
+ return r;
+}
+
+codecvt<char32_t, char8_t, mbstate_t>::result codecvt<char32_t, char8_t, mbstate_t>::do_in(
+ state_type&,
+ const extern_type* frm,
+ const extern_type* frm_end,
+ const extern_type*& frm_nxt,
+ intern_type* to,
+ intern_type* to_end,
+ intern_type*& to_nxt) const {
+ const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
+ const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
+ const uint8_t* _frm_nxt = _frm;
+ uint32_t* _to = reinterpret_cast<uint32_t*>(to);
+ uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
+ uint32_t* _to_nxt = _to;
+ result r = utf8_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt);
+ frm_nxt = frm + (_frm_nxt - _frm);
+ to_nxt = to + (_to_nxt - _to);
+ return r;
+}
+
+codecvt<char32_t, char8_t, mbstate_t>::result codecvt<char32_t, char8_t, mbstate_t>::do_unshift(
+ state_type&, extern_type* to, extern_type*, extern_type*& to_nxt) const {
+ to_nxt = to;
+ return noconv;
+}
+
+int codecvt<char32_t, char8_t, mbstate_t>::do_encoding() const noexcept { return 0; }
+
+bool codecvt<char32_t, char8_t, mbstate_t>::do_always_noconv() const noexcept { return false; }
+
+int codecvt<char32_t, char8_t, mbstate_t>::do_length(
+ state_type&, const extern_type* frm, const extern_type* frm_end, size_t mx) const {
+ const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
+ const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
+ return utf8_to_ucs4_length(_frm, _frm_end, mx);
+}
+
+int codecvt<char32_t, char8_t, mbstate_t>::do_max_length() const noexcept { return 4; }
#endif
// __codecvt_utf8<wchar_t>
-__codecvt_utf8<wchar_t>::result
-__codecvt_utf8<wchar_t>::do_out(state_type&,
- const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
- extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
-{
-#if defined(_LIBCPP_SHORT_WCHAR)
- const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
- const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
- const uint16_t* _frm_nxt = _frm;
-#else
- const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
- const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
- const uint32_t* _frm_nxt = _frm;
-#endif
- uint8_t* _to = reinterpret_cast<uint8_t*>(to);
- uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
- uint8_t* _to_nxt = _to;
-#if defined(_LIBCPP_SHORT_WCHAR)
- result r = ucs2_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
- _Maxcode_, _Mode_);
-#else
- result r = ucs4_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
- _Maxcode_, _Mode_);
-#endif
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+__codecvt_utf8<wchar_t>::result __codecvt_utf8<wchar_t>::do_out(
+ state_type&,
+ const intern_type* frm,
+ const intern_type* frm_end,
+ const intern_type*& frm_nxt,
+ extern_type* to,
+ extern_type* to_end,
+ extern_type*& to_nxt) const {
+# if defined(_LIBCPP_SHORT_WCHAR)
+ const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
+ const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
+ const uint16_t* _frm_nxt = _frm;
+# else
+ const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
+ const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
+ const uint32_t* _frm_nxt = _frm;
+# endif
+ uint8_t* _to = reinterpret_cast<uint8_t*>(to);
+ uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
+ uint8_t* _to_nxt = _to;
+# if defined(_LIBCPP_SHORT_WCHAR)
+ result r = ucs2_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);
+# else
+ result r = ucs4_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);
+# endif
+ frm_nxt = frm + (_frm_nxt - _frm);
+ to_nxt = to + (_to_nxt - _to);
+ return r;
+}
+
+__codecvt_utf8<wchar_t>::result __codecvt_utf8<wchar_t>::do_in(
+ state_type&,
+ const extern_type* frm,
+ const extern_type* frm_end,
+ const extern_type*& frm_nxt,
+ intern_type* to,
+ intern_type* to_end,
+ intern_type*& to_nxt) const {
+ const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
+ const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
+ const uint8_t* _frm_nxt = _frm;
+# if defined(_LIBCPP_SHORT_WCHAR)
+ uint16_t* _to = reinterpret_cast<uint16_t*>(to);
+ uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
+ uint16_t* _to_nxt = _to;
+ result r = utf8_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);
+# else
+ uint32_t* _to = reinterpret_cast<uint32_t*>(to);
+ uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
+ uint32_t* _to_nxt = _to;
+ result r = utf8_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);
+# endif
+ frm_nxt = frm + (_frm_nxt - _frm);
+ to_nxt = to + (_to_nxt - _to);
+ return r;
}
__codecvt_utf8<wchar_t>::result
-__codecvt_utf8<wchar_t>::do_in(state_type&,
- const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
- intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
-{
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- const uint8_t* _frm_nxt = _frm;
-#if defined(_LIBCPP_SHORT_WCHAR)
- uint16_t* _to = reinterpret_cast<uint16_t*>(to);
- uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
- uint16_t* _to_nxt = _to;
- result r = utf8_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
- _Maxcode_, _Mode_);
-#else
- uint32_t* _to = reinterpret_cast<uint32_t*>(to);
- uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
- uint32_t* _to_nxt = _to;
- result r = utf8_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
- _Maxcode_, _Mode_);
-#endif
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
+__codecvt_utf8<wchar_t>::do_unshift(state_type&, extern_type* to, extern_type*, extern_type*& to_nxt) const {
+ to_nxt = to;
+ return noconv;
}
-__codecvt_utf8<wchar_t>::result
-__codecvt_utf8<wchar_t>::do_unshift(state_type&,
- extern_type* to, extern_type*, extern_type*& to_nxt) const
-{
- to_nxt = to;
- return noconv;
-}
+int __codecvt_utf8<wchar_t>::do_encoding() const noexcept { return 0; }
-int
-__codecvt_utf8<wchar_t>::do_encoding() const _NOEXCEPT
-{
- return 0;
-}
+bool __codecvt_utf8<wchar_t>::do_always_noconv() const noexcept { return false; }
-bool
-__codecvt_utf8<wchar_t>::do_always_noconv() const _NOEXCEPT
-{
- return false;
-}
-
-int
-__codecvt_utf8<wchar_t>::do_length(state_type&,
- const extern_type* frm, const extern_type* frm_end, size_t mx) const
-{
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- return utf8_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
+int __codecvt_utf8<wchar_t>::do_length(
+ state_type&, const extern_type* frm, const extern_type* frm_end, size_t mx) const {
+ const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
+ const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
+# if defined(_LIBCPP_SHORT_WCHAR)
+ return utf8_to_ucs2_length(_frm, _frm_end, mx, __maxcode_, __mode_);
+# else
+ return utf8_to_ucs4_length(_frm, _frm_end, mx, __maxcode_, __mode_);
+# endif
}
-int
-__codecvt_utf8<wchar_t>::do_max_length() const _NOEXCEPT
-{
- if (_Mode_ & consume_header)
- return 7;
- return 4;
-}
+_LIBCPP_SUPPRESS_DEPRECATED_PUSH
+int __codecvt_utf8<wchar_t>::do_max_length() const noexcept {
+# if defined(_LIBCPP_SHORT_WCHAR)
+ if (__mode_ & consume_header)
+ return 6;
+ return 3;
+# else
+ if (__mode_ & consume_header)
+ return 7;
+ return 4;
+# endif
+}
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
// __codecvt_utf8<char16_t>
-__codecvt_utf8<char16_t>::result
-__codecvt_utf8<char16_t>::do_out(state_type&,
- const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
- extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
-{
- const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
- const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
- const uint16_t* _frm_nxt = _frm;
- uint8_t* _to = reinterpret_cast<uint8_t*>(to);
- uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
- uint8_t* _to_nxt = _to;
- result r = ucs2_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
- _Maxcode_, _Mode_);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
+__codecvt_utf8<char16_t>::result __codecvt_utf8<char16_t>::do_out(
+ state_type&,
+ const intern_type* frm,
+ const intern_type* frm_end,
+ const intern_type*& frm_nxt,
+ extern_type* to,
+ extern_type* to_end,
+ extern_type*& to_nxt) const {
+ const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
+ const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
+ const uint16_t* _frm_nxt = _frm;
+ uint8_t* _to = reinterpret_cast<uint8_t*>(to);
+ uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
+ uint8_t* _to_nxt = _to;
+ result r = ucs2_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);
+ frm_nxt = frm + (_frm_nxt - _frm);
+ to_nxt = to + (_to_nxt - _to);
+ return r;
+}
+
+__codecvt_utf8<char16_t>::result __codecvt_utf8<char16_t>::do_in(
+ state_type&,
+ const extern_type* frm,
+ const extern_type* frm_end,
+ const extern_type*& frm_nxt,
+ intern_type* to,
+ intern_type* to_end,
+ intern_type*& to_nxt) const {
+ const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
+ const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
+ const uint8_t* _frm_nxt = _frm;
+ uint16_t* _to = reinterpret_cast<uint16_t*>(to);
+ uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
+ uint16_t* _to_nxt = _to;
+ result r = utf8_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);
+ frm_nxt = frm + (_frm_nxt - _frm);
+ to_nxt = to + (_to_nxt - _to);
+ return r;
}
__codecvt_utf8<char16_t>::result
-__codecvt_utf8<char16_t>::do_in(state_type&,
- const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
- intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
-{
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- const uint8_t* _frm_nxt = _frm;
- uint16_t* _to = reinterpret_cast<uint16_t*>(to);
- uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
- uint16_t* _to_nxt = _to;
- result r = utf8_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
- _Maxcode_, _Mode_);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
+__codecvt_utf8<char16_t>::do_unshift(state_type&, extern_type* to, extern_type*, extern_type*& to_nxt) const {
+ to_nxt = to;
+ return noconv;
}
-__codecvt_utf8<char16_t>::result
-__codecvt_utf8<char16_t>::do_unshift(state_type&,
- extern_type* to, extern_type*, extern_type*& to_nxt) const
-{
- to_nxt = to;
- return noconv;
-}
-
-int
-__codecvt_utf8<char16_t>::do_encoding() const _NOEXCEPT
-{
- return 0;
-}
+int __codecvt_utf8<char16_t>::do_encoding() const noexcept { return 0; }
-bool
-__codecvt_utf8<char16_t>::do_always_noconv() const _NOEXCEPT
-{
- return false;
-}
+bool __codecvt_utf8<char16_t>::do_always_noconv() const noexcept { return false; }
-int
-__codecvt_utf8<char16_t>::do_length(state_type&,
- const extern_type* frm, const extern_type* frm_end, size_t mx) const
-{
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- return utf8_to_ucs2_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
+int __codecvt_utf8<char16_t>::do_length(
+ state_type&, const extern_type* frm, const extern_type* frm_end, size_t mx) const {
+ const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
+ const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
+ return utf8_to_ucs2_length(_frm, _frm_end, mx, __maxcode_, __mode_);
}
-int
-__codecvt_utf8<char16_t>::do_max_length() const _NOEXCEPT
-{
- if (_Mode_ & consume_header)
- return 6;
- return 3;
+_LIBCPP_SUPPRESS_DEPRECATED_PUSH
+int __codecvt_utf8<char16_t>::do_max_length() const noexcept {
+ if (__mode_ & consume_header)
+ return 6;
+ return 3;
}
+_LIBCPP_SUPPRESS_DEPRECATED_POP
// __codecvt_utf8<char32_t>
-__codecvt_utf8<char32_t>::result
-__codecvt_utf8<char32_t>::do_out(state_type&,
- const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
- extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
-{
- const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
- const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
- const uint32_t* _frm_nxt = _frm;
- uint8_t* _to = reinterpret_cast<uint8_t*>(to);
- uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
- uint8_t* _to_nxt = _to;
- result r = ucs4_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
- _Maxcode_, _Mode_);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
-}
-
-__codecvt_utf8<char32_t>::result
-__codecvt_utf8<char32_t>::do_in(state_type&,
- const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
- intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
-{
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- const uint8_t* _frm_nxt = _frm;
- uint32_t* _to = reinterpret_cast<uint32_t*>(to);
- uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
- uint32_t* _to_nxt = _to;
- result r = utf8_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
- _Maxcode_, _Mode_);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
+__codecvt_utf8<char32_t>::result __codecvt_utf8<char32_t>::do_out(
+ state_type&,
+ const intern_type* frm,
+ const intern_type* frm_end,
+ const intern_type*& frm_nxt,
+ extern_type* to,
+ extern_type* to_end,
+ extern_type*& to_nxt) const {
+ const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
+ const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
+ const uint32_t* _frm_nxt = _frm;
+ uint8_t* _to = reinterpret_cast<uint8_t*>(to);
+ uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
+ uint8_t* _to_nxt = _to;
+ result r = ucs4_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);
+ frm_nxt = frm + (_frm_nxt - _frm);
+ to_nxt = to + (_to_nxt - _to);
+ return r;
+}
+
+__codecvt_utf8<char32_t>::result __codecvt_utf8<char32_t>::do_in(
+ state_type&,
+ const extern_type* frm,
+ const extern_type* frm_end,
+ const extern_type*& frm_nxt,
+ intern_type* to,
+ intern_type* to_end,
+ intern_type*& to_nxt) const {
+ const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
+ const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
+ const uint8_t* _frm_nxt = _frm;
+ uint32_t* _to = reinterpret_cast<uint32_t*>(to);
+ uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
+ uint32_t* _to_nxt = _to;
+ result r = utf8_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);
+ frm_nxt = frm + (_frm_nxt - _frm);
+ to_nxt = to + (_to_nxt - _to);
+ return r;
}
__codecvt_utf8<char32_t>::result
-__codecvt_utf8<char32_t>::do_unshift(state_type&,
- extern_type* to, extern_type*, extern_type*& to_nxt) const
-{
- to_nxt = to;
- return noconv;
+__codecvt_utf8<char32_t>::do_unshift(state_type&, extern_type* to, extern_type*, extern_type*& to_nxt) const {
+ to_nxt = to;
+ return noconv;
}
-int
-__codecvt_utf8<char32_t>::do_encoding() const _NOEXCEPT
-{
- return 0;
-}
+int __codecvt_utf8<char32_t>::do_encoding() const noexcept { return 0; }
-bool
-__codecvt_utf8<char32_t>::do_always_noconv() const _NOEXCEPT
-{
- return false;
-}
+bool __codecvt_utf8<char32_t>::do_always_noconv() const noexcept { return false; }
-int
-__codecvt_utf8<char32_t>::do_length(state_type&,
- const extern_type* frm, const extern_type* frm_end, size_t mx) const
-{
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- return utf8_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
+int __codecvt_utf8<char32_t>::do_length(
+ state_type&, const extern_type* frm, const extern_type* frm_end, size_t mx) const {
+ const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
+ const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
+ return utf8_to_ucs4_length(_frm, _frm_end, mx, __maxcode_, __mode_);
}
-int
-__codecvt_utf8<char32_t>::do_max_length() const _NOEXCEPT
-{
- if (_Mode_ & consume_header)
- return 7;
- return 4;
+_LIBCPP_SUPPRESS_DEPRECATED_PUSH
+int __codecvt_utf8<char32_t>::do_max_length() const noexcept {
+ if (__mode_ & consume_header)
+ return 7;
+ return 4;
}
+_LIBCPP_SUPPRESS_DEPRECATED_POP
// __codecvt_utf16<wchar_t, false>
-__codecvt_utf16<wchar_t, false>::result
-__codecvt_utf16<wchar_t, false>::do_out(state_type&,
- const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
- extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
-{
- const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
- const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
- const uint32_t* _frm_nxt = _frm;
- uint8_t* _to = reinterpret_cast<uint8_t*>(to);
- uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
- uint8_t* _to_nxt = _to;
- result r = ucs4_to_utf16be(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
- _Maxcode_, _Mode_);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
-}
-
-__codecvt_utf16<wchar_t, false>::result
-__codecvt_utf16<wchar_t, false>::do_in(state_type&,
- const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
- intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
-{
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- const uint8_t* _frm_nxt = _frm;
- uint32_t* _to = reinterpret_cast<uint32_t*>(to);
- uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
- uint32_t* _to_nxt = _to;
- result r = utf16be_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
- _Maxcode_, _Mode_);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+__codecvt_utf16<wchar_t, false>::result __codecvt_utf16<wchar_t, false>::do_out(
+ state_type&,
+ const intern_type* frm,
+ const intern_type* frm_end,
+ const intern_type*& frm_nxt,
+ extern_type* to,
+ extern_type* to_end,
+ extern_type*& to_nxt) const {
+# if defined(_LIBCPP_SHORT_WCHAR)
+ const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
+ const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
+ const uint16_t* _frm_nxt = _frm;
+# else
+ const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
+ const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
+ const uint32_t* _frm_nxt = _frm;
+# endif
+ uint8_t* _to = reinterpret_cast<uint8_t*>(to);
+ uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
+ uint8_t* _to_nxt = _to;
+# if defined(_LIBCPP_SHORT_WCHAR)
+ result r = ucs2_to_utf16be(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);
+# else
+ result r = ucs4_to_utf16be(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);
+# endif
+ frm_nxt = frm + (_frm_nxt - _frm);
+ to_nxt = to + (_to_nxt - _to);
+ return r;
+}
+
+__codecvt_utf16<wchar_t, false>::result __codecvt_utf16<wchar_t, false>::do_in(
+ state_type&,
+ const extern_type* frm,
+ const extern_type* frm_end,
+ const extern_type*& frm_nxt,
+ intern_type* to,
+ intern_type* to_end,
+ intern_type*& to_nxt) const {
+ const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
+ const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
+ const uint8_t* _frm_nxt = _frm;
+# if defined(_LIBCPP_SHORT_WCHAR)
+ uint16_t* _to = reinterpret_cast<uint16_t*>(to);
+ uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
+ uint16_t* _to_nxt = _to;
+ result r = utf16be_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);
+# else
+ uint32_t* _to = reinterpret_cast<uint32_t*>(to);
+ uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
+ uint32_t* _to_nxt = _to;
+ result r = utf16be_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);
+# endif
+ frm_nxt = frm + (_frm_nxt - _frm);
+ to_nxt = to + (_to_nxt - _to);
+ return r;
}
__codecvt_utf16<wchar_t, false>::result
-__codecvt_utf16<wchar_t, false>::do_unshift(state_type&,
- extern_type* to, extern_type*, extern_type*& to_nxt) const
-{
- to_nxt = to;
- return noconv;
+__codecvt_utf16<wchar_t, false>::do_unshift(state_type&, extern_type* to, extern_type*, extern_type*& to_nxt) const {
+ to_nxt = to;
+ return noconv;
}
-int
-__codecvt_utf16<wchar_t, false>::do_encoding() const _NOEXCEPT
-{
- return 0;
-}
+int __codecvt_utf16<wchar_t, false>::do_encoding() const noexcept { return 0; }
-bool
-__codecvt_utf16<wchar_t, false>::do_always_noconv() const _NOEXCEPT
-{
- return false;
-}
+bool __codecvt_utf16<wchar_t, false>::do_always_noconv() const noexcept { return false; }
-int
-__codecvt_utf16<wchar_t, false>::do_length(state_type&,
- const extern_type* frm, const extern_type* frm_end, size_t mx) const
-{
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- return utf16be_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
+int __codecvt_utf16<wchar_t, false>::do_length(
+ state_type&, const extern_type* frm, const extern_type* frm_end, size_t mx) const {
+ const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
+ const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
+# if defined(_LIBCPP_SHORT_WCHAR)
+ return utf16be_to_ucs2_length(_frm, _frm_end, mx, __maxcode_, __mode_);
+# else
+ return utf16be_to_ucs4_length(_frm, _frm_end, mx, __maxcode_, __mode_);
+# endif
}
-int
-__codecvt_utf16<wchar_t, false>::do_max_length() const _NOEXCEPT
-{
- if (_Mode_ & consume_header)
- return 6;
+int __codecvt_utf16<wchar_t, false>::do_max_length() const noexcept {
+# if defined(_LIBCPP_SHORT_WCHAR)
+ if (__mode_ & consume_header)
return 4;
+ return 2;
+# else
+ if (__mode_ & consume_header)
+ return 6;
+ return 4;
+# endif
}
// __codecvt_utf16<wchar_t, true>
-__codecvt_utf16<wchar_t, true>::result
-__codecvt_utf16<wchar_t, true>::do_out(state_type&,
- const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
- extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
-{
- const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
- const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
- const uint32_t* _frm_nxt = _frm;
- uint8_t* _to = reinterpret_cast<uint8_t*>(to);
- uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
- uint8_t* _to_nxt = _to;
- result r = ucs4_to_utf16le(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
- _Maxcode_, _Mode_);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
-}
-
-__codecvt_utf16<wchar_t, true>::result
-__codecvt_utf16<wchar_t, true>::do_in(state_type&,
- const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
- intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
-{
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- const uint8_t* _frm_nxt = _frm;
- uint32_t* _to = reinterpret_cast<uint32_t*>(to);
- uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
- uint32_t* _to_nxt = _to;
- result r = utf16le_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
- _Maxcode_, _Mode_);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
+__codecvt_utf16<wchar_t, true>::result __codecvt_utf16<wchar_t, true>::do_out(
+ state_type&,
+ const intern_type* frm,
+ const intern_type* frm_end,
+ const intern_type*& frm_nxt,
+ extern_type* to,
+ extern_type* to_end,
+ extern_type*& to_nxt) const {
+# if defined(_LIBCPP_SHORT_WCHAR)
+ const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
+ const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
+ const uint16_t* _frm_nxt = _frm;
+# else
+ const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
+ const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
+ const uint32_t* _frm_nxt = _frm;
+# endif
+ uint8_t* _to = reinterpret_cast<uint8_t*>(to);
+ uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
+ uint8_t* _to_nxt = _to;
+# if defined(_LIBCPP_SHORT_WCHAR)
+ result r = ucs2_to_utf16le(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);
+# else
+ result r = ucs4_to_utf16le(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);
+# endif
+ frm_nxt = frm + (_frm_nxt - _frm);
+ to_nxt = to + (_to_nxt - _to);
+ return r;
+}
+
+__codecvt_utf16<wchar_t, true>::result __codecvt_utf16<wchar_t, true>::do_in(
+ state_type&,
+ const extern_type* frm,
+ const extern_type* frm_end,
+ const extern_type*& frm_nxt,
+ intern_type* to,
+ intern_type* to_end,
+ intern_type*& to_nxt) const {
+ const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
+ const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
+ const uint8_t* _frm_nxt = _frm;
+# if defined(_LIBCPP_SHORT_WCHAR)
+ uint16_t* _to = reinterpret_cast<uint16_t*>(to);
+ uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
+ uint16_t* _to_nxt = _to;
+ result r = utf16le_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);
+# else
+ uint32_t* _to = reinterpret_cast<uint32_t*>(to);
+ uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
+ uint32_t* _to_nxt = _to;
+ result r = utf16le_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);
+# endif
+ frm_nxt = frm + (_frm_nxt - _frm);
+ to_nxt = to + (_to_nxt - _to);
+ return r;
}
__codecvt_utf16<wchar_t, true>::result
-__codecvt_utf16<wchar_t, true>::do_unshift(state_type&,
- extern_type* to, extern_type*, extern_type*& to_nxt) const
-{
- to_nxt = to;
- return noconv;
+__codecvt_utf16<wchar_t, true>::do_unshift(state_type&, extern_type* to, extern_type*, extern_type*& to_nxt) const {
+ to_nxt = to;
+ return noconv;
}
-int
-__codecvt_utf16<wchar_t, true>::do_encoding() const _NOEXCEPT
-{
- return 0;
-}
+int __codecvt_utf16<wchar_t, true>::do_encoding() const noexcept { return 0; }
-bool
-__codecvt_utf16<wchar_t, true>::do_always_noconv() const _NOEXCEPT
-{
- return false;
-}
+bool __codecvt_utf16<wchar_t, true>::do_always_noconv() const noexcept { return false; }
-int
-__codecvt_utf16<wchar_t, true>::do_length(state_type&,
- const extern_type* frm, const extern_type* frm_end, size_t mx) const
-{
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- return utf16le_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
+int __codecvt_utf16<wchar_t, true>::do_length(
+ state_type&, const extern_type* frm, const extern_type* frm_end, size_t mx) const {
+ const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
+ const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
+# if defined(_LIBCPP_SHORT_WCHAR)
+ return utf16le_to_ucs2_length(_frm, _frm_end, mx, __maxcode_, __mode_);
+# else
+ return utf16le_to_ucs4_length(_frm, _frm_end, mx, __maxcode_, __mode_);
+# endif
}
-int
-__codecvt_utf16<wchar_t, true>::do_max_length() const _NOEXCEPT
-{
- if (_Mode_ & consume_header)
- return 6;
+int __codecvt_utf16<wchar_t, true>::do_max_length() const noexcept {
+# if defined(_LIBCPP_SHORT_WCHAR)
+ if (__mode_ & consume_header)
return 4;
+ return 2;
+# else
+ if (__mode_ & consume_header)
+ return 6;
+ return 4;
+# endif
}
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
// __codecvt_utf16<char16_t, false>
-__codecvt_utf16<char16_t, false>::result
-__codecvt_utf16<char16_t, false>::do_out(state_type&,
- const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
- extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
-{
- const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
- const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
- const uint16_t* _frm_nxt = _frm;
- uint8_t* _to = reinterpret_cast<uint8_t*>(to);
- uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
- uint8_t* _to_nxt = _to;
- result r = ucs2_to_utf16be(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
- _Maxcode_, _Mode_);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
-}
-
-__codecvt_utf16<char16_t, false>::result
-__codecvt_utf16<char16_t, false>::do_in(state_type&,
- const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
- intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
-{
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- const uint8_t* _frm_nxt = _frm;
- uint16_t* _to = reinterpret_cast<uint16_t*>(to);
- uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
- uint16_t* _to_nxt = _to;
- result r = utf16be_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
- _Maxcode_, _Mode_);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
+__codecvt_utf16<char16_t, false>::result __codecvt_utf16<char16_t, false>::do_out(
+ state_type&,
+ const intern_type* frm,
+ const intern_type* frm_end,
+ const intern_type*& frm_nxt,
+ extern_type* to,
+ extern_type* to_end,
+ extern_type*& to_nxt) const {
+ const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
+ const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
+ const uint16_t* _frm_nxt = _frm;
+ uint8_t* _to = reinterpret_cast<uint8_t*>(to);
+ uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
+ uint8_t* _to_nxt = _to;
+ result r = ucs2_to_utf16be(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);
+ frm_nxt = frm + (_frm_nxt - _frm);
+ to_nxt = to + (_to_nxt - _to);
+ return r;
+}
+
+__codecvt_utf16<char16_t, false>::result __codecvt_utf16<char16_t, false>::do_in(
+ state_type&,
+ const extern_type* frm,
+ const extern_type* frm_end,
+ const extern_type*& frm_nxt,
+ intern_type* to,
+ intern_type* to_end,
+ intern_type*& to_nxt) const {
+ const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
+ const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
+ const uint8_t* _frm_nxt = _frm;
+ uint16_t* _to = reinterpret_cast<uint16_t*>(to);
+ uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
+ uint16_t* _to_nxt = _to;
+ result r = utf16be_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);
+ frm_nxt = frm + (_frm_nxt - _frm);
+ to_nxt = to + (_to_nxt - _to);
+ return r;
}
__codecvt_utf16<char16_t, false>::result
-__codecvt_utf16<char16_t, false>::do_unshift(state_type&,
- extern_type* to, extern_type*, extern_type*& to_nxt) const
-{
- to_nxt = to;
- return noconv;
+__codecvt_utf16<char16_t, false>::do_unshift(state_type&, extern_type* to, extern_type*, extern_type*& to_nxt) const {
+ to_nxt = to;
+ return noconv;
}
-int
-__codecvt_utf16<char16_t, false>::do_encoding() const _NOEXCEPT
-{
- return 0;
-}
+int __codecvt_utf16<char16_t, false>::do_encoding() const noexcept { return 0; }
-bool
-__codecvt_utf16<char16_t, false>::do_always_noconv() const _NOEXCEPT
-{
- return false;
-}
+bool __codecvt_utf16<char16_t, false>::do_always_noconv() const noexcept { return false; }
-int
-__codecvt_utf16<char16_t, false>::do_length(state_type&,
- const extern_type* frm, const extern_type* frm_end, size_t mx) const
-{
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- return utf16be_to_ucs2_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
+int __codecvt_utf16<char16_t, false>::do_length(
+ state_type&, const extern_type* frm, const extern_type* frm_end, size_t mx) const {
+ const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
+ const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
+ return utf16be_to_ucs2_length(_frm, _frm_end, mx, __maxcode_, __mode_);
}
-int
-__codecvt_utf16<char16_t, false>::do_max_length() const _NOEXCEPT
-{
- if (_Mode_ & consume_header)
- return 4;
- return 2;
+_LIBCPP_SUPPRESS_DEPRECATED_PUSH
+int __codecvt_utf16<char16_t, false>::do_max_length() const noexcept {
+ if (__mode_ & consume_header)
+ return 4;
+ return 2;
}
+_LIBCPP_SUPPRESS_DEPRECATED_POP
// __codecvt_utf16<char16_t, true>
-__codecvt_utf16<char16_t, true>::result
-__codecvt_utf16<char16_t, true>::do_out(state_type&,
- const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
- extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
-{
- const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
- const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
- const uint16_t* _frm_nxt = _frm;
- uint8_t* _to = reinterpret_cast<uint8_t*>(to);
- uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
- uint8_t* _to_nxt = _to;
- result r = ucs2_to_utf16le(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
- _Maxcode_, _Mode_);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
-}
-
-__codecvt_utf16<char16_t, true>::result
-__codecvt_utf16<char16_t, true>::do_in(state_type&,
- const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
- intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
-{
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- const uint8_t* _frm_nxt = _frm;
- uint16_t* _to = reinterpret_cast<uint16_t*>(to);
- uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
- uint16_t* _to_nxt = _to;
- result r = utf16le_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
- _Maxcode_, _Mode_);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
+__codecvt_utf16<char16_t, true>::result __codecvt_utf16<char16_t, true>::do_out(
+ state_type&,
+ const intern_type* frm,
+ const intern_type* frm_end,
+ const intern_type*& frm_nxt,
+ extern_type* to,
+ extern_type* to_end,
+ extern_type*& to_nxt) const {
+ const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
+ const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
+ const uint16_t* _frm_nxt = _frm;
+ uint8_t* _to = reinterpret_cast<uint8_t*>(to);
+ uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
+ uint8_t* _to_nxt = _to;
+ result r = ucs2_to_utf16le(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);
+ frm_nxt = frm + (_frm_nxt - _frm);
+ to_nxt = to + (_to_nxt - _to);
+ return r;
+}
+
+__codecvt_utf16<char16_t, true>::result __codecvt_utf16<char16_t, true>::do_in(
+ state_type&,
+ const extern_type* frm,
+ const extern_type* frm_end,
+ const extern_type*& frm_nxt,
+ intern_type* to,
+ intern_type* to_end,
+ intern_type*& to_nxt) const {
+ const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
+ const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
+ const uint8_t* _frm_nxt = _frm;
+ uint16_t* _to = reinterpret_cast<uint16_t*>(to);
+ uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
+ uint16_t* _to_nxt = _to;
+ result r = utf16le_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);
+ frm_nxt = frm + (_frm_nxt - _frm);
+ to_nxt = to + (_to_nxt - _to);
+ return r;
}
__codecvt_utf16<char16_t, true>::result
-__codecvt_utf16<char16_t, true>::do_unshift(state_type&,
- extern_type* to, extern_type*, extern_type*& to_nxt) const
-{
- to_nxt = to;
- return noconv;
+__codecvt_utf16<char16_t, true>::do_unshift(state_type&, extern_type* to, extern_type*, extern_type*& to_nxt) const {
+ to_nxt = to;
+ return noconv;
}
-int
-__codecvt_utf16<char16_t, true>::do_encoding() const _NOEXCEPT
-{
- return 0;
-}
+int __codecvt_utf16<char16_t, true>::do_encoding() const noexcept { return 0; }
-bool
-__codecvt_utf16<char16_t, true>::do_always_noconv() const _NOEXCEPT
-{
- return false;
-}
+bool __codecvt_utf16<char16_t, true>::do_always_noconv() const noexcept { return false; }
-int
-__codecvt_utf16<char16_t, true>::do_length(state_type&,
- const extern_type* frm, const extern_type* frm_end, size_t mx) const
-{
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- return utf16le_to_ucs2_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
+int __codecvt_utf16<char16_t, true>::do_length(
+ state_type&, const extern_type* frm, const extern_type* frm_end, size_t mx) const {
+ const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
+ const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
+ return utf16le_to_ucs2_length(_frm, _frm_end, mx, __maxcode_, __mode_);
}
-int
-__codecvt_utf16<char16_t, true>::do_max_length() const _NOEXCEPT
-{
- if (_Mode_ & consume_header)
- return 4;
- return 2;
+_LIBCPP_SUPPRESS_DEPRECATED_PUSH
+int __codecvt_utf16<char16_t, true>::do_max_length() const noexcept {
+ if (__mode_ & consume_header)
+ return 4;
+ return 2;
}
+_LIBCPP_SUPPRESS_DEPRECATED_POP
// __codecvt_utf16<char32_t, false>
-__codecvt_utf16<char32_t, false>::result
-__codecvt_utf16<char32_t, false>::do_out(state_type&,
- const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
- extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
-{
- const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
- const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
- const uint32_t* _frm_nxt = _frm;
- uint8_t* _to = reinterpret_cast<uint8_t*>(to);
- uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
- uint8_t* _to_nxt = _to;
- result r = ucs4_to_utf16be(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
- _Maxcode_, _Mode_);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
-}
-
-__codecvt_utf16<char32_t, false>::result
-__codecvt_utf16<char32_t, false>::do_in(state_type&,
- const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
- intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
-{
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- const uint8_t* _frm_nxt = _frm;
- uint32_t* _to = reinterpret_cast<uint32_t*>(to);
- uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
- uint32_t* _to_nxt = _to;
- result r = utf16be_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
- _Maxcode_, _Mode_);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
+__codecvt_utf16<char32_t, false>::result __codecvt_utf16<char32_t, false>::do_out(
+ state_type&,
+ const intern_type* frm,
+ const intern_type* frm_end,
+ const intern_type*& frm_nxt,
+ extern_type* to,
+ extern_type* to_end,
+ extern_type*& to_nxt) const {
+ const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
+ const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
+ const uint32_t* _frm_nxt = _frm;
+ uint8_t* _to = reinterpret_cast<uint8_t*>(to);
+ uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
+ uint8_t* _to_nxt = _to;
+ result r = ucs4_to_utf16be(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);
+ frm_nxt = frm + (_frm_nxt - _frm);
+ to_nxt = to + (_to_nxt - _to);
+ return r;
+}
+
+__codecvt_utf16<char32_t, false>::result __codecvt_utf16<char32_t, false>::do_in(
+ state_type&,
+ const extern_type* frm,
+ const extern_type* frm_end,
+ const extern_type*& frm_nxt,
+ intern_type* to,
+ intern_type* to_end,
+ intern_type*& to_nxt) const {
+ const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
+ const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
+ const uint8_t* _frm_nxt = _frm;
+ uint32_t* _to = reinterpret_cast<uint32_t*>(to);
+ uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
+ uint32_t* _to_nxt = _to;
+ result r = utf16be_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);
+ frm_nxt = frm + (_frm_nxt - _frm);
+ to_nxt = to + (_to_nxt - _to);
+ return r;
}
__codecvt_utf16<char32_t, false>::result
-__codecvt_utf16<char32_t, false>::do_unshift(state_type&,
- extern_type* to, extern_type*, extern_type*& to_nxt) const
-{
- to_nxt = to;
- return noconv;
+__codecvt_utf16<char32_t, false>::do_unshift(state_type&, extern_type* to, extern_type*, extern_type*& to_nxt) const {
+ to_nxt = to;
+ return noconv;
}
-int
-__codecvt_utf16<char32_t, false>::do_encoding() const _NOEXCEPT
-{
- return 0;
-}
+int __codecvt_utf16<char32_t, false>::do_encoding() const noexcept { return 0; }
-bool
-__codecvt_utf16<char32_t, false>::do_always_noconv() const _NOEXCEPT
-{
- return false;
-}
+bool __codecvt_utf16<char32_t, false>::do_always_noconv() const noexcept { return false; }
-int
-__codecvt_utf16<char32_t, false>::do_length(state_type&,
- const extern_type* frm, const extern_type* frm_end, size_t mx) const
-{
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- return utf16be_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
+int __codecvt_utf16<char32_t, false>::do_length(
+ state_type&, const extern_type* frm, const extern_type* frm_end, size_t mx) const {
+ const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
+ const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
+ return utf16be_to_ucs4_length(_frm, _frm_end, mx, __maxcode_, __mode_);
}
-int
-__codecvt_utf16<char32_t, false>::do_max_length() const _NOEXCEPT
-{
- if (_Mode_ & consume_header)
- return 6;
- return 4;
+_LIBCPP_SUPPRESS_DEPRECATED_PUSH
+int __codecvt_utf16<char32_t, false>::do_max_length() const noexcept {
+ if (__mode_ & consume_header)
+ return 6;
+ return 4;
}
+_LIBCPP_SUPPRESS_DEPRECATED_POP
// __codecvt_utf16<char32_t, true>
-__codecvt_utf16<char32_t, true>::result
-__codecvt_utf16<char32_t, true>::do_out(state_type&,
- const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
- extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
-{
- const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
- const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
- const uint32_t* _frm_nxt = _frm;
- uint8_t* _to = reinterpret_cast<uint8_t*>(to);
- uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
- uint8_t* _to_nxt = _to;
- result r = ucs4_to_utf16le(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
- _Maxcode_, _Mode_);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
-}
-
-__codecvt_utf16<char32_t, true>::result
-__codecvt_utf16<char32_t, true>::do_in(state_type&,
- const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
- intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
-{
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- const uint8_t* _frm_nxt = _frm;
- uint32_t* _to = reinterpret_cast<uint32_t*>(to);
- uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
- uint32_t* _to_nxt = _to;
- result r = utf16le_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
- _Maxcode_, _Mode_);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
+__codecvt_utf16<char32_t, true>::result __codecvt_utf16<char32_t, true>::do_out(
+ state_type&,
+ const intern_type* frm,
+ const intern_type* frm_end,
+ const intern_type*& frm_nxt,
+ extern_type* to,
+ extern_type* to_end,
+ extern_type*& to_nxt) const {
+ const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
+ const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
+ const uint32_t* _frm_nxt = _frm;
+ uint8_t* _to = reinterpret_cast<uint8_t*>(to);
+ uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
+ uint8_t* _to_nxt = _to;
+ result r = ucs4_to_utf16le(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);
+ frm_nxt = frm + (_frm_nxt - _frm);
+ to_nxt = to + (_to_nxt - _to);
+ return r;
+}
+
+__codecvt_utf16<char32_t, true>::result __codecvt_utf16<char32_t, true>::do_in(
+ state_type&,
+ const extern_type* frm,
+ const extern_type* frm_end,
+ const extern_type*& frm_nxt,
+ intern_type* to,
+ intern_type* to_end,
+ intern_type*& to_nxt) const {
+ const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
+ const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
+ const uint8_t* _frm_nxt = _frm;
+ uint32_t* _to = reinterpret_cast<uint32_t*>(to);
+ uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
+ uint32_t* _to_nxt = _to;
+ result r = utf16le_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);
+ frm_nxt = frm + (_frm_nxt - _frm);
+ to_nxt = to + (_to_nxt - _to);
+ return r;
}
__codecvt_utf16<char32_t, true>::result
-__codecvt_utf16<char32_t, true>::do_unshift(state_type&,
- extern_type* to, extern_type*, extern_type*& to_nxt) const
-{
- to_nxt = to;
- return noconv;
+__codecvt_utf16<char32_t, true>::do_unshift(state_type&, extern_type* to, extern_type*, extern_type*& to_nxt) const {
+ to_nxt = to;
+ return noconv;
}
-int
-__codecvt_utf16<char32_t, true>::do_encoding() const _NOEXCEPT
-{
- return 0;
-}
+int __codecvt_utf16<char32_t, true>::do_encoding() const noexcept { return 0; }
-bool
-__codecvt_utf16<char32_t, true>::do_always_noconv() const _NOEXCEPT
-{
- return false;
-}
+bool __codecvt_utf16<char32_t, true>::do_always_noconv() const noexcept { return false; }
-int
-__codecvt_utf16<char32_t, true>::do_length(state_type&,
- const extern_type* frm, const extern_type* frm_end, size_t mx) const
-{
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- return utf16le_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
+int __codecvt_utf16<char32_t, true>::do_length(
+ state_type&, const extern_type* frm, const extern_type* frm_end, size_t mx) const {
+ const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
+ const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
+ return utf16le_to_ucs4_length(_frm, _frm_end, mx, __maxcode_, __mode_);
}
-int
-__codecvt_utf16<char32_t, true>::do_max_length() const _NOEXCEPT
-{
- if (_Mode_ & consume_header)
- return 6;
- return 4;
+_LIBCPP_SUPPRESS_DEPRECATED_PUSH
+int __codecvt_utf16<char32_t, true>::do_max_length() const noexcept {
+ if (__mode_ & consume_header)
+ return 6;
+ return 4;
}
+_LIBCPP_SUPPRESS_DEPRECATED_POP
// __codecvt_utf8_utf16<wchar_t>
-__codecvt_utf8_utf16<wchar_t>::result
-__codecvt_utf8_utf16<wchar_t>::do_out(state_type&,
- const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
- extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
-{
- const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
- const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
- const uint32_t* _frm_nxt = _frm;
- uint8_t* _to = reinterpret_cast<uint8_t*>(to);
- uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
- uint8_t* _to_nxt = _to;
- result r = utf16_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
- _Maxcode_, _Mode_);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
-}
-
-__codecvt_utf8_utf16<wchar_t>::result
-__codecvt_utf8_utf16<wchar_t>::do_in(state_type&,
- const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
- intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
-{
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- const uint8_t* _frm_nxt = _frm;
- uint32_t* _to = reinterpret_cast<uint32_t*>(to);
- uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
- uint32_t* _to_nxt = _to;
- result r = utf8_to_utf16(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
- _Maxcode_, _Mode_);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+__codecvt_utf8_utf16<wchar_t>::result __codecvt_utf8_utf16<wchar_t>::do_out(
+ state_type&,
+ const intern_type* frm,
+ const intern_type* frm_end,
+ const intern_type*& frm_nxt,
+ extern_type* to,
+ extern_type* to_end,
+ extern_type*& to_nxt) const {
+# if defined(_LIBCPP_SHORT_WCHAR)
+ const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
+ const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
+ const uint16_t* _frm_nxt = _frm;
+# else
+ const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
+ const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
+ const uint32_t* _frm_nxt = _frm;
+# endif
+ uint8_t* _to = reinterpret_cast<uint8_t*>(to);
+ uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
+ uint8_t* _to_nxt = _to;
+ result r = utf16_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);
+ frm_nxt = frm + (_frm_nxt - _frm);
+ to_nxt = to + (_to_nxt - _to);
+ return r;
+}
+
+__codecvt_utf8_utf16<wchar_t>::result __codecvt_utf8_utf16<wchar_t>::do_in(
+ state_type&,
+ const extern_type* frm,
+ const extern_type* frm_end,
+ const extern_type*& frm_nxt,
+ intern_type* to,
+ intern_type* to_end,
+ intern_type*& to_nxt) const {
+ const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
+ const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
+ const uint8_t* _frm_nxt = _frm;
+# if defined(_LIBCPP_SHORT_WCHAR)
+ uint16_t* _to = reinterpret_cast<uint16_t*>(to);
+ uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
+ uint16_t* _to_nxt = _to;
+# else
+ uint32_t* _to = reinterpret_cast<uint32_t*>(to);
+ uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
+ uint32_t* _to_nxt = _to;
+# endif
+ result r = utf8_to_utf16(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);
+ frm_nxt = frm + (_frm_nxt - _frm);
+ to_nxt = to + (_to_nxt - _to);
+ return r;
}
__codecvt_utf8_utf16<wchar_t>::result
-__codecvt_utf8_utf16<wchar_t>::do_unshift(state_type&,
- extern_type* to, extern_type*, extern_type*& to_nxt) const
-{
- to_nxt = to;
- return noconv;
+__codecvt_utf8_utf16<wchar_t>::do_unshift(state_type&, extern_type* to, extern_type*, extern_type*& to_nxt) const {
+ to_nxt = to;
+ return noconv;
}
-int
-__codecvt_utf8_utf16<wchar_t>::do_encoding() const _NOEXCEPT
-{
- return 0;
-}
+int __codecvt_utf8_utf16<wchar_t>::do_encoding() const noexcept { return 0; }
-bool
-__codecvt_utf8_utf16<wchar_t>::do_always_noconv() const _NOEXCEPT
-{
- return false;
-}
+bool __codecvt_utf8_utf16<wchar_t>::do_always_noconv() const noexcept { return false; }
-int
-__codecvt_utf8_utf16<wchar_t>::do_length(state_type&,
- const extern_type* frm, const extern_type* frm_end, size_t mx) const
-{
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- return utf8_to_utf16_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
+int __codecvt_utf8_utf16<wchar_t>::do_length(
+ state_type&, const extern_type* frm, const extern_type* frm_end, size_t mx) const {
+ const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
+ const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
+ return utf8_to_utf16_length(_frm, _frm_end, mx, __maxcode_, __mode_);
}
-int
-__codecvt_utf8_utf16<wchar_t>::do_max_length() const _NOEXCEPT
-{
- if (_Mode_ & consume_header)
- return 7;
- return 4;
+int __codecvt_utf8_utf16<wchar_t>::do_max_length() const noexcept {
+ if (__mode_ & consume_header)
+ return 7;
+ return 4;
}
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
// __codecvt_utf8_utf16<char16_t>
-__codecvt_utf8_utf16<char16_t>::result
-__codecvt_utf8_utf16<char16_t>::do_out(state_type&,
- const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
- extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
-{
- const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
- const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
- const uint16_t* _frm_nxt = _frm;
- uint8_t* _to = reinterpret_cast<uint8_t*>(to);
- uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
- uint8_t* _to_nxt = _to;
- result r = utf16_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
- _Maxcode_, _Mode_);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
+__codecvt_utf8_utf16<char16_t>::result __codecvt_utf8_utf16<char16_t>::do_out(
+ state_type&,
+ const intern_type* frm,
+ const intern_type* frm_end,
+ const intern_type*& frm_nxt,
+ extern_type* to,
+ extern_type* to_end,
+ extern_type*& to_nxt) const {
+ const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
+ const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
+ const uint16_t* _frm_nxt = _frm;
+ uint8_t* _to = reinterpret_cast<uint8_t*>(to);
+ uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
+ uint8_t* _to_nxt = _to;
+ result r = utf16_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);
+ frm_nxt = frm + (_frm_nxt - _frm);
+ to_nxt = to + (_to_nxt - _to);
+ return r;
+}
+
+__codecvt_utf8_utf16<char16_t>::result __codecvt_utf8_utf16<char16_t>::do_in(
+ state_type&,
+ const extern_type* frm,
+ const extern_type* frm_end,
+ const extern_type*& frm_nxt,
+ intern_type* to,
+ intern_type* to_end,
+ intern_type*& to_nxt) const {
+ const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
+ const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
+ const uint8_t* _frm_nxt = _frm;
+ uint16_t* _to = reinterpret_cast<uint16_t*>(to);
+ uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
+ uint16_t* _to_nxt = _to;
+ result r = utf8_to_utf16(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);
+ frm_nxt = frm + (_frm_nxt - _frm);
+ to_nxt = to + (_to_nxt - _to);
+ return r;
}
__codecvt_utf8_utf16<char16_t>::result
-__codecvt_utf8_utf16<char16_t>::do_in(state_type&,
- const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
- intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
-{
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- const uint8_t* _frm_nxt = _frm;
- uint16_t* _to = reinterpret_cast<uint16_t*>(to);
- uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
- uint16_t* _to_nxt = _to;
- result r = utf8_to_utf16(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
- _Maxcode_, _Mode_);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
+__codecvt_utf8_utf16<char16_t>::do_unshift(state_type&, extern_type* to, extern_type*, extern_type*& to_nxt) const {
+ to_nxt = to;
+ return noconv;
}
-__codecvt_utf8_utf16<char16_t>::result
-__codecvt_utf8_utf16<char16_t>::do_unshift(state_type&,
- extern_type* to, extern_type*, extern_type*& to_nxt) const
-{
- to_nxt = to;
- return noconv;
-}
-
-int
-__codecvt_utf8_utf16<char16_t>::do_encoding() const _NOEXCEPT
-{
- return 0;
-}
+int __codecvt_utf8_utf16<char16_t>::do_encoding() const noexcept { return 0; }
-bool
-__codecvt_utf8_utf16<char16_t>::do_always_noconv() const _NOEXCEPT
-{
- return false;
-}
+bool __codecvt_utf8_utf16<char16_t>::do_always_noconv() const noexcept { return false; }
-int
-__codecvt_utf8_utf16<char16_t>::do_length(state_type&,
- const extern_type* frm, const extern_type* frm_end, size_t mx) const
-{
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- return utf8_to_utf16_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
+int __codecvt_utf8_utf16<char16_t>::do_length(
+ state_type&, const extern_type* frm, const extern_type* frm_end, size_t mx) const {
+ const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
+ const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
+ return utf8_to_utf16_length(_frm, _frm_end, mx, __maxcode_, __mode_);
}
-int
-__codecvt_utf8_utf16<char16_t>::do_max_length() const _NOEXCEPT
-{
- if (_Mode_ & consume_header)
- return 7;
- return 4;
+_LIBCPP_SUPPRESS_DEPRECATED_PUSH
+int __codecvt_utf8_utf16<char16_t>::do_max_length() const noexcept {
+ if (__mode_ & consume_header)
+ return 7;
+ return 4;
}
+_LIBCPP_SUPPRESS_DEPRECATED_POP
// __codecvt_utf8_utf16<char32_t>
-__codecvt_utf8_utf16<char32_t>::result
-__codecvt_utf8_utf16<char32_t>::do_out(state_type&,
- const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
- extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
-{
- const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
- const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
- const uint32_t* _frm_nxt = _frm;
- uint8_t* _to = reinterpret_cast<uint8_t*>(to);
- uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
- uint8_t* _to_nxt = _to;
- result r = utf16_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
- _Maxcode_, _Mode_);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
-}
-
-__codecvt_utf8_utf16<char32_t>::result
-__codecvt_utf8_utf16<char32_t>::do_in(state_type&,
- const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
- intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
-{
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- const uint8_t* _frm_nxt = _frm;
- uint32_t* _to = reinterpret_cast<uint32_t*>(to);
- uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
- uint32_t* _to_nxt = _to;
- result r = utf8_to_utf16(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
- _Maxcode_, _Mode_);
- frm_nxt = frm + (_frm_nxt - _frm);
- to_nxt = to + (_to_nxt - _to);
- return r;
+__codecvt_utf8_utf16<char32_t>::result __codecvt_utf8_utf16<char32_t>::do_out(
+ state_type&,
+ const intern_type* frm,
+ const intern_type* frm_end,
+ const intern_type*& frm_nxt,
+ extern_type* to,
+ extern_type* to_end,
+ extern_type*& to_nxt) const {
+ const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
+ const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
+ const uint32_t* _frm_nxt = _frm;
+ uint8_t* _to = reinterpret_cast<uint8_t*>(to);
+ uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
+ uint8_t* _to_nxt = _to;
+ result r = utf16_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);
+ frm_nxt = frm + (_frm_nxt - _frm);
+ to_nxt = to + (_to_nxt - _to);
+ return r;
+}
+
+__codecvt_utf8_utf16<char32_t>::result __codecvt_utf8_utf16<char32_t>::do_in(
+ state_type&,
+ const extern_type* frm,
+ const extern_type* frm_end,
+ const extern_type*& frm_nxt,
+ intern_type* to,
+ intern_type* to_end,
+ intern_type*& to_nxt) const {
+ const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
+ const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
+ const uint8_t* _frm_nxt = _frm;
+ uint32_t* _to = reinterpret_cast<uint32_t*>(to);
+ uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
+ uint32_t* _to_nxt = _to;
+ result r = utf8_to_utf16(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);
+ frm_nxt = frm + (_frm_nxt - _frm);
+ to_nxt = to + (_to_nxt - _to);
+ return r;
}
__codecvt_utf8_utf16<char32_t>::result
-__codecvt_utf8_utf16<char32_t>::do_unshift(state_type&,
- extern_type* to, extern_type*, extern_type*& to_nxt) const
-{
- to_nxt = to;
- return noconv;
+__codecvt_utf8_utf16<char32_t>::do_unshift(state_type&, extern_type* to, extern_type*, extern_type*& to_nxt) const {
+ to_nxt = to;
+ return noconv;
}
-int
-__codecvt_utf8_utf16<char32_t>::do_encoding() const _NOEXCEPT
-{
- return 0;
-}
+int __codecvt_utf8_utf16<char32_t>::do_encoding() const noexcept { return 0; }
-bool
-__codecvt_utf8_utf16<char32_t>::do_always_noconv() const _NOEXCEPT
-{
- return false;
-}
+bool __codecvt_utf8_utf16<char32_t>::do_always_noconv() const noexcept { return false; }
-int
-__codecvt_utf8_utf16<char32_t>::do_length(state_type&,
- const extern_type* frm, const extern_type* frm_end, size_t mx) const
-{
- const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
- const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
- return utf8_to_utf16_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
+int __codecvt_utf8_utf16<char32_t>::do_length(
+ state_type&, const extern_type* frm, const extern_type* frm_end, size_t mx) const {
+ const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
+ const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
+ return utf8_to_utf16_length(_frm, _frm_end, mx, __maxcode_, __mode_);
}
-int
-__codecvt_utf8_utf16<char32_t>::do_max_length() const _NOEXCEPT
-{
- if (_Mode_ & consume_header)
- return 7;
- return 4;
+_LIBCPP_SUPPRESS_DEPRECATED_PUSH
+int __codecvt_utf8_utf16<char32_t>::do_max_length() const noexcept {
+ if (__mode_ & consume_header)
+ return 7;
+ return 4;
}
+_LIBCPP_SUPPRESS_DEPRECATED_POP
// __narrow_to_utf8<16>
-__narrow_to_utf8<16>::~__narrow_to_utf8()
-{
-}
+__narrow_to_utf8<16>::~__narrow_to_utf8() {}
// __narrow_to_utf8<32>
-__narrow_to_utf8<32>::~__narrow_to_utf8()
-{
-}
+__narrow_to_utf8<32>::~__narrow_to_utf8() {}
// __widen_from_utf8<16>
-__widen_from_utf8<16>::~__widen_from_utf8()
-{
-}
+__widen_from_utf8<16>::~__widen_from_utf8() {}
// __widen_from_utf8<32>
-__widen_from_utf8<32>::~__widen_from_utf8()
-{
-}
+__widen_from_utf8<32>::~__widen_from_utf8() {}
-
-static bool checked_string_to_wchar_convert(wchar_t& dest,
- const char* ptr,
- locale_t loc) {
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+static bool checked_string_to_wchar_convert(wchar_t& dest, const char* ptr, locale_t loc) {
if (*ptr == '\0')
return false;
mbstate_t mb = {};
@@ -4392,16 +3945,29 @@ static bool checked_string_to_wchar_convert(wchar_t& dest,
dest = out;
return true;
}
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
+
+#ifdef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+static bool is_narrow_non_breaking_space(const char* ptr) {
+ // https://www.fileformat.info/info/unicode/char/202f/index.htm
+ return ptr[0] == '\xe2' && ptr[1] == '\x80' && ptr[2] == '\xaf';
+}
+
+static bool is_non_breaking_space(const char* ptr) {
+ // https://www.fileformat.info/info/unicode/char/0a/index.htm
+ return ptr[0] == '\xc2' && ptr[1] == '\xa0';
+}
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
-static bool checked_string_to_char_convert(char& dest,
- const char* ptr,
- locale_t __loc) {
+static bool checked_string_to_char_convert(char& dest, const char* ptr, locale_t __loc) {
if (*ptr == '\0')
return false;
if (!ptr[1]) {
dest = *ptr;
return true;
}
+
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
// First convert the MBS into a wide char then attempt to narrow it using
// wctob_l.
wchar_t wout;
@@ -4412,7 +3978,7 @@ static bool checked_string_to_char_convert(char& dest,
dest = res;
return true;
}
- // FIXME: Work around specific multibyte sequences that we can reasonable
+ // FIXME: Work around specific multibyte sequences that we can reasonably
// translate into a different single byte.
switch (wout) {
case L'\u202F': // narrow non-breaking space
@@ -4422,1923 +3988,1732 @@ static bool checked_string_to_char_convert(char& dest,
default:
return false;
}
- _LIBCPP_UNREACHABLE();
-}
+#else // _LIBCPP_HAS_NO_WIDE_CHARACTERS
+ // FIXME: Work around specific multibyte sequences that we can reasonably
+ // translate into a different single byte.
+ if (is_narrow_non_breaking_space(ptr) || is_non_breaking_space(ptr)) {
+ dest = ' ';
+ return true;
+ }
+ return false;
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
+ __libcpp_unreachable();
+}
// numpunct<char> && numpunct<wchar_t>
-locale::id numpunct< char >::id;
-locale::id numpunct<wchar_t>::id;
+constinit locale::id numpunct<char>::id;
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+constinit locale::id numpunct<wchar_t>::id;
+#endif
-numpunct<char>::numpunct(size_t refs)
- : locale::facet(refs),
- __decimal_point_('.'),
- __thousands_sep_(',')
-{
-}
+numpunct<char>::numpunct(size_t refs) : locale::facet(refs), __decimal_point_('.'), __thousands_sep_(',') {}
-numpunct<wchar_t>::numpunct(size_t refs)
- : locale::facet(refs),
- __decimal_point_(L'.'),
- __thousands_sep_(L',')
-{
-}
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+numpunct<wchar_t>::numpunct(size_t refs) : locale::facet(refs), __decimal_point_(L'.'), __thousands_sep_(L',') {}
+#endif
-numpunct<char>::~numpunct()
-{
-}
+numpunct<char>::~numpunct() {}
-numpunct<wchar_t>::~numpunct()
-{
-}
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+numpunct<wchar_t>::~numpunct() {}
+#endif
- char numpunct< char >::do_decimal_point() const {return __decimal_point_;}
-wchar_t numpunct<wchar_t>::do_decimal_point() const {return __decimal_point_;}
+char numpunct< char >::do_decimal_point() const { return __decimal_point_; }
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+wchar_t numpunct<wchar_t>::do_decimal_point() const { return __decimal_point_; }
+#endif
- char numpunct< char >::do_thousands_sep() const {return __thousands_sep_;}
-wchar_t numpunct<wchar_t>::do_thousands_sep() const {return __thousands_sep_;}
+char numpunct< char >::do_thousands_sep() const { return __thousands_sep_; }
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+wchar_t numpunct<wchar_t>::do_thousands_sep() const { return __thousands_sep_; }
+#endif
-string numpunct< char >::do_grouping() const {return __grouping_;}
-string numpunct<wchar_t>::do_grouping() const {return __grouping_;}
+string numpunct< char >::do_grouping() const { return __grouping_; }
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+string numpunct<wchar_t>::do_grouping() const { return __grouping_; }
+#endif
- string numpunct< char >::do_truename() const {return "true";}
-wstring numpunct<wchar_t>::do_truename() const {return L"true";}
+string numpunct< char >::do_truename() const { return "true"; }
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+wstring numpunct<wchar_t>::do_truename() const { return L"true"; }
+#endif
- string numpunct< char >::do_falsename() const {return "false";}
-wstring numpunct<wchar_t>::do_falsename() const {return L"false";}
+string numpunct< char >::do_falsename() const { return "false"; }
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+wstring numpunct<wchar_t>::do_falsename() const { return L"false"; }
+#endif
// numpunct_byname<char>
-numpunct_byname<char>::numpunct_byname(const char* nm, size_t refs)
- : numpunct<char>(refs)
-{
- __init(nm);
-}
+numpunct_byname<char>::numpunct_byname(const char* nm, size_t refs) : numpunct<char>(refs) { __init(nm); }
-numpunct_byname<char>::numpunct_byname(const string& nm, size_t refs)
- : numpunct<char>(refs)
-{
- __init(nm.c_str());
-}
+numpunct_byname<char>::numpunct_byname(const string& nm, size_t refs) : numpunct<char>(refs) { __init(nm.c_str()); }
-numpunct_byname<char>::~numpunct_byname()
-{
-}
+numpunct_byname<char>::~numpunct_byname() {}
-void
-numpunct_byname<char>::__init(const char* nm)
-{
- if (strcmp(nm, "C") != 0)
- {
- __libcpp_unique_locale loc(nm);
- if (!loc)
- __throw_runtime_error("numpunct_byname<char>::numpunct_byname"
- " failed to construct for " + string(nm));
-
- lconv* lc = __libcpp_localeconv_l(loc.get());
- checked_string_to_char_convert(__decimal_point_, lc->decimal_point,
- loc.get());
- checked_string_to_char_convert(__thousands_sep_, lc->thousands_sep,
- loc.get());
- __grouping_ = lc->grouping;
- // localization for truename and falsename is not available
- }
+void numpunct_byname<char>::__init(const char* nm) {
+ typedef numpunct<char> base;
+ if (strcmp(nm, "C") != 0) {
+ __libcpp_unique_locale loc(nm);
+ if (!loc)
+ __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, loc.get()))
+ __decimal_point_ = base::do_decimal_point();
+ if (!checked_string_to_char_convert(__thousands_sep_, lc->thousands_sep, loc.get()))
+ __thousands_sep_ = base::do_thousands_sep();
+ __grouping_ = lc->grouping;
+ // localization for truename and falsename is not available
+ }
}
// numpunct_byname<wchar_t>
-numpunct_byname<wchar_t>::numpunct_byname(const char* nm, size_t refs)
- : numpunct<wchar_t>(refs)
-{
- __init(nm);
-}
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+numpunct_byname<wchar_t>::numpunct_byname(const char* nm, size_t refs) : numpunct<wchar_t>(refs) { __init(nm); }
-numpunct_byname<wchar_t>::numpunct_byname(const string& nm, size_t refs)
- : numpunct<wchar_t>(refs)
-{
- __init(nm.c_str());
+numpunct_byname<wchar_t>::numpunct_byname(const string& nm, size_t refs) : numpunct<wchar_t>(refs) {
+ __init(nm.c_str());
}
-numpunct_byname<wchar_t>::~numpunct_byname()
-{
-}
+numpunct_byname<wchar_t>::~numpunct_byname() {}
-void
-numpunct_byname<wchar_t>::__init(const char* nm)
-{
- if (strcmp(nm, "C") != 0)
- {
- __libcpp_unique_locale loc(nm);
- if (!loc)
- __throw_runtime_error("numpunct_byname<wchar_t>::numpunct_byname"
- " failed to construct for " + string(nm));
-
- lconv* lc = __libcpp_localeconv_l(loc.get());
- checked_string_to_wchar_convert(__decimal_point_, lc->decimal_point,
- loc.get());
- checked_string_to_wchar_convert(__thousands_sep_, lc->thousands_sep,
- loc.get());
- __grouping_ = lc->grouping;
- // localization for truename and falsename is not available
- }
+void numpunct_byname<wchar_t>::__init(const char* nm) {
+ if (strcmp(nm, "C") != 0) {
+ __libcpp_unique_locale loc(nm);
+ if (!loc)
+ __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, loc.get());
+ checked_string_to_wchar_convert(__thousands_sep_, lc->thousands_sep, loc.get());
+ __grouping_ = lc->grouping;
+ // localization for truename and falsename is not available
+ }
}
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
// num_get helpers
-int
-__num_get_base::__get_base(ios_base& iob)
-{
- ios_base::fmtflags __basefield = iob.flags() & ios_base::basefield;
- if (__basefield == ios_base::oct)
- return 8;
- else if (__basefield == ios_base::hex)
- return 16;
- else if (__basefield == 0)
- return 0;
- return 10;
+int __num_get_base::__get_base(ios_base& iob) {
+ ios_base::fmtflags __basefield = iob.flags() & ios_base::basefield;
+ if (__basefield == ios_base::oct)
+ return 8;
+ else if (__basefield == ios_base::hex)
+ return 16;
+ else if (__basefield == 0)
+ return 0;
+ return 10;
}
const char __num_get_base::__src[33] = "0123456789abcdefABCDEFxX+-pPiInN";
-void
-__check_grouping(const string& __grouping, unsigned* __g, unsigned* __g_end,
- ios_base::iostate& __err)
-{
-// if the grouping pattern is empty _or_ there are no grouping bits, then do nothing
-// we always have at least a single entry in [__g, __g_end); the end of the input sequence
- if (__grouping.size() != 0 && __g_end - __g > 1)
- {
- reverse(__g, __g_end);
- const char* __ig = __grouping.data();
- const char* __eg = __ig + __grouping.size();
- for (unsigned* __r = __g; __r < __g_end-1; ++__r)
- {
- if (0 < *__ig && *__ig < numeric_limits<char>::max())
- {
- if (static_cast<unsigned>(*__ig) != *__r)
- {
- __err = ios_base::failbit;
- return;
- }
- }
- if (__eg - __ig > 1)
- ++__ig;
- }
- if (0 < *__ig && *__ig < numeric_limits<char>::max())
- {
- if (static_cast<unsigned>(*__ig) < __g_end[-1] || __g_end[-1] == 0)
- __err = ios_base::failbit;
+void __check_grouping(const string& __grouping, unsigned* __g, unsigned* __g_end, ios_base::iostate& __err) {
+ // if the grouping pattern is empty _or_ there are no grouping bits, then do nothing
+ // we always have at least a single entry in [__g, __g_end); the end of the input sequence
+ if (__grouping.size() != 0 && __g_end - __g > 1) {
+ reverse(__g, __g_end);
+ const char* __ig = __grouping.data();
+ const char* __eg = __ig + __grouping.size();
+ for (unsigned* __r = __g; __r < __g_end - 1; ++__r) {
+ if (0 < *__ig && *__ig < numeric_limits<char>::max()) {
+ if (static_cast<unsigned>(*__ig) != *__r) {
+ __err = ios_base::failbit;
+ return;
}
+ }
+ if (__eg - __ig > 1)
+ ++__ig;
+ }
+ if (0 < *__ig && *__ig < numeric_limits<char>::max()) {
+ if (static_cast<unsigned>(*__ig) < __g_end[-1] || __g_end[-1] == 0)
+ __err = ios_base::failbit;
}
+ }
}
-void
-__num_put_base::__format_int(char* __fmtp, const char* __len, bool __signd,
- ios_base::fmtflags __flags)
-{
- if (__flags & ios_base::showpos)
- *__fmtp++ = '+';
- if (__flags & ios_base::showbase)
- *__fmtp++ = '#';
- while(*__len)
- *__fmtp++ = *__len++;
- if ((__flags & ios_base::basefield) == ios_base::oct)
- *__fmtp = 'o';
- else if ((__flags & ios_base::basefield) == ios_base::hex)
- {
- if (__flags & ios_base::uppercase)
- *__fmtp = 'X';
- else
- *__fmtp = 'x';
- }
- else if (__signd)
- *__fmtp = 'd';
+void __num_put_base::__format_int(char* __fmtp, const char* __len, bool __signd, ios_base::fmtflags __flags) {
+ if ((__flags & ios_base::showpos) && (__flags & ios_base::basefield) != ios_base::oct &&
+ (__flags & ios_base::basefield) != ios_base::hex && __signd)
+ *__fmtp++ = '+';
+ if (__flags & ios_base::showbase)
+ *__fmtp++ = '#';
+ while (*__len)
+ *__fmtp++ = *__len++;
+ if ((__flags & ios_base::basefield) == ios_base::oct)
+ *__fmtp = 'o';
+ else if ((__flags & ios_base::basefield) == ios_base::hex) {
+ if (__flags & ios_base::uppercase)
+ *__fmtp = 'X';
else
- *__fmtp = 'u';
-}
-
-bool
-__num_put_base::__format_float(char* __fmtp, const char* __len,
- ios_base::fmtflags __flags)
-{
- bool specify_precision = true;
- if (__flags & ios_base::showpos)
- *__fmtp++ = '+';
- if (__flags & ios_base::showpoint)
- *__fmtp++ = '#';
- ios_base::fmtflags floatfield = __flags & ios_base::floatfield;
- bool uppercase = (__flags & ios_base::uppercase) != 0;
- if (floatfield == (ios_base::fixed | ios_base::scientific))
- specify_precision = false;
+ *__fmtp = 'x';
+ } else if (__signd)
+ *__fmtp = 'd';
+ else
+ *__fmtp = 'u';
+}
+
+bool __num_put_base::__format_float(char* __fmtp, const char* __len, ios_base::fmtflags __flags) {
+ bool specify_precision = true;
+ if (__flags & ios_base::showpos)
+ *__fmtp++ = '+';
+ if (__flags & ios_base::showpoint)
+ *__fmtp++ = '#';
+ ios_base::fmtflags floatfield = __flags & ios_base::floatfield;
+ bool uppercase = (__flags & ios_base::uppercase) != 0;
+ if (floatfield == (ios_base::fixed | ios_base::scientific))
+ specify_precision = false;
+ else {
+ *__fmtp++ = '.';
+ *__fmtp++ = '*';
+ }
+ while (*__len)
+ *__fmtp++ = *__len++;
+ if (floatfield == ios_base::fixed) {
+ if (uppercase)
+ *__fmtp = 'F';
else
- {
- *__fmtp++ = '.';
- *__fmtp++ = '*';
- }
- while(*__len)
- *__fmtp++ = *__len++;
- if (floatfield == ios_base::fixed)
- {
- if (uppercase)
- *__fmtp = 'F';
- else
- *__fmtp = 'f';
- }
- else if (floatfield == ios_base::scientific)
- {
- if (uppercase)
- *__fmtp = 'E';
- else
- *__fmtp = 'e';
- }
- else if (floatfield == (ios_base::fixed | ios_base::scientific))
- {
- if (uppercase)
- *__fmtp = 'A';
- else
- *__fmtp = 'a';
- }
+ *__fmtp = 'f';
+ } else if (floatfield == ios_base::scientific) {
+ if (uppercase)
+ *__fmtp = 'E';
else
- {
- if (uppercase)
- *__fmtp = 'G';
- else
- *__fmtp = 'g';
- }
- return specify_precision;
-}
-
-char*
-__num_put_base::__identify_padding(char* __nb, char* __ne,
- const ios_base& __iob)
-{
- switch (__iob.flags() & ios_base::adjustfield)
- {
- case ios_base::internal:
- if (__nb[0] == '-' || __nb[0] == '+')
- return __nb+1;
- if (__ne - __nb >= 2 && __nb[0] == '0'
- && (__nb[1] == 'x' || __nb[1] == 'X'))
- return __nb+2;
- break;
- case ios_base::left:
- return __ne;
- case ios_base::right:
- default:
- break;
- }
- return __nb;
+ *__fmtp = 'e';
+ } else if (floatfield == (ios_base::fixed | ios_base::scientific)) {
+ if (uppercase)
+ *__fmtp = 'A';
+ else
+ *__fmtp = 'a';
+ } else {
+ if (uppercase)
+ *__fmtp = 'G';
+ else
+ *__fmtp = 'g';
+ }
+ return specify_precision;
+}
+
+char* __num_put_base::__identify_padding(char* __nb, char* __ne, const ios_base& __iob) {
+ switch (__iob.flags() & ios_base::adjustfield) {
+ case ios_base::internal:
+ if (__nb[0] == '-' || __nb[0] == '+')
+ return __nb + 1;
+ if (__ne - __nb >= 2 && __nb[0] == '0' && (__nb[1] == 'x' || __nb[1] == 'X'))
+ return __nb + 2;
+ break;
+ case ios_base::left:
+ return __ne;
+ case ios_base::right:
+ default:
+ break;
+ }
+ return __nb;
}
// time_get
-static
-string*
-init_weeks()
-{
- static string weeks[14];
- weeks[0] = "Sunday";
- weeks[1] = "Monday";
- weeks[2] = "Tuesday";
- weeks[3] = "Wednesday";
- weeks[4] = "Thursday";
- weeks[5] = "Friday";
- weeks[6] = "Saturday";
- weeks[7] = "Sun";
- weeks[8] = "Mon";
- weeks[9] = "Tue";
- weeks[10] = "Wed";
- weeks[11] = "Thu";
- weeks[12] = "Fri";
- weeks[13] = "Sat";
- return weeks;
-}
-
-static
-wstring*
-init_wweeks()
-{
- static wstring weeks[14];
- weeks[0] = L"Sunday";
- weeks[1] = L"Monday";
- weeks[2] = L"Tuesday";
- weeks[3] = L"Wednesday";
- weeks[4] = L"Thursday";
- weeks[5] = L"Friday";
- weeks[6] = L"Saturday";
- weeks[7] = L"Sun";
- weeks[8] = L"Mon";
- weeks[9] = L"Tue";
- weeks[10] = L"Wed";
- weeks[11] = L"Thu";
- weeks[12] = L"Fri";
- weeks[13] = L"Sat";
- return weeks;
+static string* init_weeks() {
+ static string weeks[14];
+ weeks[0] = "Sunday";
+ weeks[1] = "Monday";
+ weeks[2] = "Tuesday";
+ weeks[3] = "Wednesday";
+ weeks[4] = "Thursday";
+ weeks[5] = "Friday";
+ weeks[6] = "Saturday";
+ weeks[7] = "Sun";
+ weeks[8] = "Mon";
+ weeks[9] = "Tue";
+ weeks[10] = "Wed";
+ weeks[11] = "Thu";
+ weeks[12] = "Fri";
+ weeks[13] = "Sat";
+ return weeks;
+}
+
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+static wstring* init_wweeks() {
+ static wstring weeks[14];
+ weeks[0] = L"Sunday";
+ weeks[1] = L"Monday";
+ weeks[2] = L"Tuesday";
+ weeks[3] = L"Wednesday";
+ weeks[4] = L"Thursday";
+ weeks[5] = L"Friday";
+ weeks[6] = L"Saturday";
+ weeks[7] = L"Sun";
+ weeks[8] = L"Mon";
+ weeks[9] = L"Tue";
+ weeks[10] = L"Wed";
+ weeks[11] = L"Thu";
+ weeks[12] = L"Fri";
+ weeks[13] = L"Sat";
+ return weeks;
}
+#endif
template <>
-const string*
-__time_get_c_storage<char>::__weeks() const
-{
- static const string* weeks = init_weeks();
- return weeks;
+const string* __time_get_c_storage<char>::__weeks() const {
+ static const string* weeks = init_weeks();
+ return weeks;
}
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
template <>
-const wstring*
-__time_get_c_storage<wchar_t>::__weeks() const
-{
- static const wstring* weeks = init_wweeks();
- return weeks;
-}
-
-static
-string*
-init_months()
-{
- static string months[24];
- months[0] = "January";
- months[1] = "February";
- months[2] = "March";
- months[3] = "April";
- months[4] = "May";
- months[5] = "June";
- months[6] = "July";
- months[7] = "August";
- months[8] = "September";
- months[9] = "October";
- months[10] = "November";
- months[11] = "December";
- months[12] = "Jan";
- months[13] = "Feb";
- months[14] = "Mar";
- months[15] = "Apr";
- months[16] = "May";
- months[17] = "Jun";
- months[18] = "Jul";
- months[19] = "Aug";
- months[20] = "Sep";
- months[21] = "Oct";
- months[22] = "Nov";
- months[23] = "Dec";
- return months;
-}
-
-static
-wstring*
-init_wmonths()
-{
- static wstring months[24];
- months[0] = L"January";
- months[1] = L"February";
- months[2] = L"March";
- months[3] = L"April";
- months[4] = L"May";
- months[5] = L"June";
- months[6] = L"July";
- months[7] = L"August";
- months[8] = L"September";
- months[9] = L"October";
- months[10] = L"November";
- months[11] = L"December";
- months[12] = L"Jan";
- months[13] = L"Feb";
- months[14] = L"Mar";
- months[15] = L"Apr";
- months[16] = L"May";
- months[17] = L"Jun";
- months[18] = L"Jul";
- months[19] = L"Aug";
- months[20] = L"Sep";
- months[21] = L"Oct";
- months[22] = L"Nov";
- months[23] = L"Dec";
- return months;
+const wstring* __time_get_c_storage<wchar_t>::__weeks() const {
+ static const wstring* weeks = init_wweeks();
+ return weeks;
+}
+#endif
+
+static string* init_months() {
+ static string months[24];
+ months[0] = "January";
+ months[1] = "February";
+ months[2] = "March";
+ months[3] = "April";
+ months[4] = "May";
+ months[5] = "June";
+ months[6] = "July";
+ months[7] = "August";
+ months[8] = "September";
+ months[9] = "October";
+ months[10] = "November";
+ months[11] = "December";
+ months[12] = "Jan";
+ months[13] = "Feb";
+ months[14] = "Mar";
+ months[15] = "Apr";
+ months[16] = "May";
+ months[17] = "Jun";
+ months[18] = "Jul";
+ months[19] = "Aug";
+ months[20] = "Sep";
+ months[21] = "Oct";
+ months[22] = "Nov";
+ months[23] = "Dec";
+ return months;
+}
+
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+static wstring* init_wmonths() {
+ static wstring months[24];
+ months[0] = L"January";
+ months[1] = L"February";
+ months[2] = L"March";
+ months[3] = L"April";
+ months[4] = L"May";
+ months[5] = L"June";
+ months[6] = L"July";
+ months[7] = L"August";
+ months[8] = L"September";
+ months[9] = L"October";
+ months[10] = L"November";
+ months[11] = L"December";
+ months[12] = L"Jan";
+ months[13] = L"Feb";
+ months[14] = L"Mar";
+ months[15] = L"Apr";
+ months[16] = L"May";
+ months[17] = L"Jun";
+ months[18] = L"Jul";
+ months[19] = L"Aug";
+ months[20] = L"Sep";
+ months[21] = L"Oct";
+ months[22] = L"Nov";
+ months[23] = L"Dec";
+ return months;
}
+#endif
template <>
-const string*
-__time_get_c_storage<char>::__months() const
-{
- static const string* months = init_months();
- return months;
+const string* __time_get_c_storage<char>::__months() const {
+ static const string* months = init_months();
+ return months;
}
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
template <>
-const wstring*
-__time_get_c_storage<wchar_t>::__months() const
-{
- static const wstring* months = init_wmonths();
- return months;
+const wstring* __time_get_c_storage<wchar_t>::__months() const {
+ static const wstring* months = init_wmonths();
+ return months;
}
+#endif
-static
-string*
-init_am_pm()
-{
- static string am_pm[2];
- am_pm[0] = "AM";
- am_pm[1] = "PM";
- return am_pm;
+static string* init_am_pm() {
+ static string am_pm[2];
+ am_pm[0] = "AM";
+ am_pm[1] = "PM";
+ return am_pm;
}
-static
-wstring*
-init_wam_pm()
-{
- static wstring am_pm[2];
- am_pm[0] = L"AM";
- am_pm[1] = L"PM";
- return am_pm;
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+static wstring* init_wam_pm() {
+ static wstring am_pm[2];
+ am_pm[0] = L"AM";
+ am_pm[1] = L"PM";
+ return am_pm;
}
+#endif
template <>
-const string*
-__time_get_c_storage<char>::__am_pm() const
-{
- static const string* am_pm = init_am_pm();
- return am_pm;
+const string* __time_get_c_storage<char>::__am_pm() const {
+ static const string* am_pm = init_am_pm();
+ return am_pm;
}
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
template <>
-const wstring*
-__time_get_c_storage<wchar_t>::__am_pm() const
-{
- static const wstring* am_pm = init_wam_pm();
- return am_pm;
+const wstring* __time_get_c_storage<wchar_t>::__am_pm() const {
+ static const wstring* am_pm = init_wam_pm();
+ return am_pm;
}
+#endif
template <>
-const string&
-__time_get_c_storage<char>::__x() const
-{
- static string s("%m/%d/%y");
- return s;
+const string& __time_get_c_storage<char>::__x() const {
+ static string s("%m/%d/%y");
+ return s;
}
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
template <>
-const wstring&
-__time_get_c_storage<wchar_t>::__x() const
-{
- static wstring s(L"%m/%d/%y");
- return s;
+const wstring& __time_get_c_storage<wchar_t>::__x() const {
+ static wstring s(L"%m/%d/%y");
+ return s;
}
+#endif
template <>
-const string&
-__time_get_c_storage<char>::__X() const
-{
- static string s("%H:%M:%S");
- return s;
+const string& __time_get_c_storage<char>::__X() const {
+ static string s("%H:%M:%S");
+ return s;
}
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
template <>
-const wstring&
-__time_get_c_storage<wchar_t>::__X() const
-{
- static wstring s(L"%H:%M:%S");
- return s;
+const wstring& __time_get_c_storage<wchar_t>::__X() const {
+ static wstring s(L"%H:%M:%S");
+ return s;
}
+#endif
template <>
-const string&
-__time_get_c_storage<char>::__c() const
-{
- static string s("%a %b %d %H:%M:%S %Y");
- return s;
+const string& __time_get_c_storage<char>::__c() const {
+ static string s("%a %b %d %H:%M:%S %Y");
+ return s;
}
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
template <>
-const wstring&
-__time_get_c_storage<wchar_t>::__c() const
-{
- static wstring s(L"%a %b %d %H:%M:%S %Y");
- return s;
+const wstring& __time_get_c_storage<wchar_t>::__c() const {
+ static wstring s(L"%a %b %d %H:%M:%S %Y");
+ return s;
}
+#endif
template <>
-const string&
-__time_get_c_storage<char>::__r() const
-{
- static string s("%I:%M:%S %p");
- return s;
+const string& __time_get_c_storage<char>::__r() const {
+ static string s("%I:%M:%S %p");
+ return s;
}
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
template <>
-const wstring&
-__time_get_c_storage<wchar_t>::__r() const
-{
- static wstring s(L"%I:%M:%S %p");
- return s;
+const wstring& __time_get_c_storage<wchar_t>::__r() const {
+ static wstring s(L"%I:%M:%S %p");
+ return s;
}
+#endif
// time_get_byname
-__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));
+__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)).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);
+__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).c_str());
}
-__time_get::~__time_get()
-{
- freelocale(__loc_);
-}
-#if defined(__clang__)
-#pragma clang diagnostic ignored "-Wmissing-field-initializers"
-#endif
-#if defined(__GNUG__)
-#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
-#endif
+__time_get::~__time_get() { freelocale(__loc_); }
+
+_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wmissing-field-initializers")
template <>
-string
-__time_get_storage<char>::__analyze(char fmt, const ctype<char>& ct)
-{
- tm t = {0};
- t.tm_sec = 59;
- t.tm_min = 55;
- t.tm_hour = 23;
- t.tm_mday = 31;
- t.tm_mon = 11;
- t.tm_year = 161;
- t.tm_wday = 6;
- t.tm_yday = 364;
- t.tm_isdst = -1;
- char buf[100];
- char f[3] = {0};
- f[0] = '%';
- f[1] = fmt;
- size_t n = strftime_l(buf, countof(buf), f, &t, __loc_);
- char* bb = buf;
- char* be = buf + n;
- string result;
- while (bb != be)
- {
- if (ct.is(ctype_base::space, *bb))
- {
- result.push_back(' ');
- for (++bb; bb != be && ct.is(ctype_base::space, *bb); ++bb)
- ;
- continue;
- }
- char* w = bb;
- ios_base::iostate err = ios_base::goodbit;
- ptrdiff_t i = __scan_keyword(w, be, this->__weeks_, this->__weeks_+14,
- ct, err, false)
- - this->__weeks_;
- if (i < 14)
- {
- result.push_back('%');
- if (i < 7)
- result.push_back('A');
- else
- result.push_back('a');
- bb = w;
- continue;
- }
- w = bb;
- i = __scan_keyword(w, be, this->__months_, this->__months_+24,
- ct, err, false)
- - this->__months_;
- if (i < 24)
- {
- result.push_back('%');
- if (i < 12)
- result.push_back('B');
- else
- result.push_back('b');
- if (fmt == 'x' && ct.is(ctype_base::digit, this->__months_[i][0]))
- result.back() = 'm';
- bb = w;
- continue;
- }
- if (this->__am_pm_[0].size() + this->__am_pm_[1].size() > 0)
- {
- w = bb;
- i = __scan_keyword(w, be, this->__am_pm_, this->__am_pm_+2,
- ct, err, false) - this->__am_pm_;
- if (i < 2)
- {
- result.push_back('%');
- result.push_back('p');
- bb = w;
- continue;
- }
- }
- w = bb;
- if (ct.is(ctype_base::digit, *bb))
- {
- switch(__get_up_to_n_digits(bb, be, err, ct, 4))
- {
- case 6:
- result.push_back('%');
- result.push_back('w');
- break;
- case 7:
- result.push_back('%');
- result.push_back('u');
- break;
- case 11:
- result.push_back('%');
- result.push_back('I');
- break;
- case 12:
- result.push_back('%');
- result.push_back('m');
- break;
- case 23:
- result.push_back('%');
- result.push_back('H');
- break;
- case 31:
- result.push_back('%');
- result.push_back('d');
- break;
- case 55:
- result.push_back('%');
- result.push_back('M');
- break;
- case 59:
- result.push_back('%');
- result.push_back('S');
- break;
- case 61:
- result.push_back('%');
- result.push_back('y');
- break;
- case 364:
- result.push_back('%');
- result.push_back('j');
- break;
- case 2061:
- result.push_back('%');
- result.push_back('Y');
- break;
- default:
- for (; w != bb; ++w)
- result.push_back(*w);
- break;
- }
- continue;
- }
- if (*bb == '%')
- {
- result.push_back('%');
- result.push_back('%');
- ++bb;
- continue;
- }
- result.push_back(*bb);
- ++bb;
+string __time_get_storage<char>::__analyze(char fmt, const ctype<char>& ct) {
+ tm t = {0};
+ t.tm_sec = 59;
+ t.tm_min = 55;
+ t.tm_hour = 23;
+ t.tm_mday = 31;
+ t.tm_mon = 11;
+ t.tm_year = 161;
+ t.tm_wday = 6;
+ t.tm_yday = 364;
+ t.tm_isdst = -1;
+ char buf[100];
+ char f[3] = {0};
+ f[0] = '%';
+ f[1] = fmt;
+ size_t n = strftime_l(buf, countof(buf), f, &t, __loc_);
+ char* bb = buf;
+ char* be = buf + n;
+ string result;
+ while (bb != be) {
+ if (ct.is(ctype_base::space, *bb)) {
+ result.push_back(' ');
+ for (++bb; bb != be && ct.is(ctype_base::space, *bb); ++bb)
+ ;
+ continue;
+ }
+ char* w = bb;
+ ios_base::iostate err = ios_base::goodbit;
+ ptrdiff_t i = __scan_keyword(w, be, this->__weeks_, this->__weeks_ + 14, ct, err, false) - this->__weeks_;
+ if (i < 14) {
+ result.push_back('%');
+ if (i < 7)
+ result.push_back('A');
+ else
+ result.push_back('a');
+ bb = w;
+ continue;
+ }
+ w = bb;
+ i = __scan_keyword(w, be, this->__months_, this->__months_ + 24, ct, err, false) - this->__months_;
+ if (i < 24) {
+ result.push_back('%');
+ if (i < 12)
+ result.push_back('B');
+ else
+ result.push_back('b');
+ if (fmt == 'x' && ct.is(ctype_base::digit, this->__months_[i][0]))
+ result.back() = 'm';
+ bb = w;
+ continue;
+ }
+ if (this->__am_pm_[0].size() + this->__am_pm_[1].size() > 0) {
+ w = bb;
+ i = __scan_keyword(w, be, this->__am_pm_, this->__am_pm_ + 2, ct, err, false) - this->__am_pm_;
+ if (i < 2) {
+ result.push_back('%');
+ result.push_back('p');
+ bb = w;
+ continue;
+ }
+ }
+ w = bb;
+ if (ct.is(ctype_base::digit, *bb)) {
+ switch (__get_up_to_n_digits(bb, be, err, ct, 4)) {
+ case 6:
+ result.push_back('%');
+ result.push_back('w');
+ break;
+ case 7:
+ result.push_back('%');
+ result.push_back('u');
+ break;
+ case 11:
+ result.push_back('%');
+ result.push_back('I');
+ break;
+ case 12:
+ result.push_back('%');
+ result.push_back('m');
+ break;
+ case 23:
+ result.push_back('%');
+ result.push_back('H');
+ break;
+ case 31:
+ result.push_back('%');
+ result.push_back('d');
+ break;
+ case 55:
+ result.push_back('%');
+ result.push_back('M');
+ break;
+ case 59:
+ result.push_back('%');
+ result.push_back('S');
+ break;
+ case 61:
+ result.push_back('%');
+ result.push_back('y');
+ break;
+ case 364:
+ result.push_back('%');
+ result.push_back('j');
+ break;
+ case 2061:
+ result.push_back('%');
+ result.push_back('Y');
+ break;
+ default:
+ for (; w != bb; ++w)
+ result.push_back(*w);
+ break;
+ }
+ continue;
}
- return result;
+ if (*bb == '%') {
+ result.push_back('%');
+ result.push_back('%');
+ ++bb;
+ continue;
+ }
+ result.push_back(*bb);
+ ++bb;
+ }
+ return result;
}
-#if defined(__clang__)
-#pragma clang diagnostic ignored "-Wmissing-braces"
-#endif
+_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wmissing-braces")
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
template <>
-wstring
-__time_get_storage<wchar_t>::__analyze(char fmt, const ctype<wchar_t>& ct)
-{
- tm t = {0};
- t.tm_sec = 59;
- t.tm_min = 55;
- t.tm_hour = 23;
- t.tm_mday = 31;
- t.tm_mon = 11;
- t.tm_year = 161;
- t.tm_wday = 6;
- t.tm_yday = 364;
- t.tm_isdst = -1;
- char buf[100];
- char f[3] = {0};
- f[0] = '%';
- f[1] = fmt;
- strftime_l(buf, countof(buf), f, &t, __loc_);
- wchar_t wbuf[100];
- wchar_t* wbb = wbuf;
- mbstate_t mb = {0};
- const char* bb = buf;
- size_t j = __libcpp_mbsrtowcs_l( wbb, &bb, countof(wbuf), &mb, __loc_);
- if (j == size_t(-1))
- __throw_runtime_error("locale not supported");
- wchar_t* wbe = wbb + j;
- wstring result;
- while (wbb != wbe)
- {
- if (ct.is(ctype_base::space, *wbb))
- {
- result.push_back(L' ');
- for (++wbb; wbb != wbe && ct.is(ctype_base::space, *wbb); ++wbb)
- ;
- continue;
- }
- wchar_t* w = wbb;
- ios_base::iostate err = ios_base::goodbit;
- ptrdiff_t i = __scan_keyword(w, wbe, this->__weeks_, this->__weeks_+14,
- ct, err, false)
- - this->__weeks_;
- if (i < 14)
- {
- result.push_back(L'%');
- if (i < 7)
- result.push_back(L'A');
- else
- result.push_back(L'a');
- wbb = w;
- continue;
- }
- w = wbb;
- i = __scan_keyword(w, wbe, this->__months_, this->__months_+24,
- ct, err, false)
- - this->__months_;
- if (i < 24)
- {
- result.push_back(L'%');
- if (i < 12)
- result.push_back(L'B');
- else
- result.push_back(L'b');
- if (fmt == 'x' && ct.is(ctype_base::digit, this->__months_[i][0]))
- result.back() = L'm';
- wbb = w;
- continue;
- }
- if (this->__am_pm_[0].size() + this->__am_pm_[1].size() > 0)
- {
- w = wbb;
- i = __scan_keyword(w, wbe, this->__am_pm_, this->__am_pm_+2,
- ct, err, false) - this->__am_pm_;
- if (i < 2)
- {
- result.push_back(L'%');
- result.push_back(L'p');
- wbb = w;
- continue;
- }
- }
- w = wbb;
- if (ct.is(ctype_base::digit, *wbb))
- {
- switch(__get_up_to_n_digits(wbb, wbe, err, ct, 4))
- {
- case 6:
- result.push_back(L'%');
- result.push_back(L'w');
- break;
- case 7:
- result.push_back(L'%');
- result.push_back(L'u');
- break;
- case 11:
- result.push_back(L'%');
- result.push_back(L'I');
- break;
- case 12:
- result.push_back(L'%');
- result.push_back(L'm');
- break;
- case 23:
- result.push_back(L'%');
- result.push_back(L'H');
- break;
- case 31:
- result.push_back(L'%');
- result.push_back(L'd');
- break;
- case 55:
- result.push_back(L'%');
- result.push_back(L'M');
- break;
- case 59:
- result.push_back(L'%');
- result.push_back(L'S');
- break;
- case 61:
- result.push_back(L'%');
- result.push_back(L'y');
- break;
- case 364:
- result.push_back(L'%');
- result.push_back(L'j');
- break;
- case 2061:
- result.push_back(L'%');
- result.push_back(L'Y');
- break;
- default:
- for (; w != wbb; ++w)
- result.push_back(*w);
- break;
- }
- continue;
- }
- if (ct.narrow(*wbb, 0) == '%')
- {
- result.push_back(L'%');
- result.push_back(L'%');
- ++wbb;
- continue;
- }
- result.push_back(*wbb);
- ++wbb;
+wstring __time_get_storage<wchar_t>::__analyze(char fmt, const ctype<wchar_t>& ct) {
+ tm t = {0};
+ t.tm_sec = 59;
+ t.tm_min = 55;
+ t.tm_hour = 23;
+ t.tm_mday = 31;
+ t.tm_mon = 11;
+ t.tm_year = 161;
+ t.tm_wday = 6;
+ t.tm_yday = 364;
+ t.tm_isdst = -1;
+ char buf[100];
+ char f[3] = {0};
+ f[0] = '%';
+ f[1] = fmt;
+ strftime_l(buf, countof(buf), f, &t, __loc_);
+ wchar_t wbuf[100];
+ wchar_t* wbb = wbuf;
+ mbstate_t mb = {0};
+ const char* bb = buf;
+ size_t j = __libcpp_mbsrtowcs_l(wbb, &bb, countof(wbuf), &mb, __loc_);
+ if (j == size_t(-1))
+ __throw_runtime_error("locale not supported");
+ wchar_t* wbe = wbb + j;
+ wstring result;
+ while (wbb != wbe) {
+ if (ct.is(ctype_base::space, *wbb)) {
+ result.push_back(L' ');
+ for (++wbb; wbb != wbe && ct.is(ctype_base::space, *wbb); ++wbb)
+ ;
+ continue;
}
- return result;
-}
-
-template <>
-void
-__time_get_storage<char>::init(const ctype<char>& ct)
-{
- tm t = {0};
- char buf[100];
- // __weeks_
- for (int i = 0; i < 7; ++i)
- {
- t.tm_wday = i;
- strftime_l(buf, countof(buf), "%A", &t, __loc_);
- __weeks_[i] = buf;
- strftime_l(buf, countof(buf), "%a", &t, __loc_);
- __weeks_[i+7] = buf;
+ wchar_t* w = wbb;
+ ios_base::iostate err = ios_base::goodbit;
+ ptrdiff_t i = __scan_keyword(w, wbe, this->__weeks_, this->__weeks_ + 14, ct, err, false) - this->__weeks_;
+ if (i < 14) {
+ result.push_back(L'%');
+ if (i < 7)
+ result.push_back(L'A');
+ else
+ result.push_back(L'a');
+ wbb = w;
+ continue;
}
- // __months_
- for (int i = 0; i < 12; ++i)
- {
- t.tm_mon = i;
- strftime_l(buf, countof(buf), "%B", &t, __loc_);
- __months_[i] = buf;
- strftime_l(buf, countof(buf), "%b", &t, __loc_);
- __months_[i+12] = buf;
+ w = wbb;
+ i = __scan_keyword(w, wbe, this->__months_, this->__months_ + 24, ct, err, false) - this->__months_;
+ if (i < 24) {
+ result.push_back(L'%');
+ if (i < 12)
+ result.push_back(L'B');
+ else
+ result.push_back(L'b');
+ if (fmt == 'x' && ct.is(ctype_base::digit, this->__months_[i][0]))
+ result.back() = L'm';
+ wbb = w;
+ continue;
+ }
+ if (this->__am_pm_[0].size() + this->__am_pm_[1].size() > 0) {
+ w = wbb;
+ i = __scan_keyword(w, wbe, this->__am_pm_, this->__am_pm_ + 2, ct, err, false) - this->__am_pm_;
+ if (i < 2) {
+ result.push_back(L'%');
+ result.push_back(L'p');
+ wbb = w;
+ continue;
+ }
+ }
+ w = wbb;
+ if (ct.is(ctype_base::digit, *wbb)) {
+ switch (__get_up_to_n_digits(wbb, wbe, err, ct, 4)) {
+ case 6:
+ result.push_back(L'%');
+ result.push_back(L'w');
+ break;
+ case 7:
+ result.push_back(L'%');
+ result.push_back(L'u');
+ break;
+ case 11:
+ result.push_back(L'%');
+ result.push_back(L'I');
+ break;
+ case 12:
+ result.push_back(L'%');
+ result.push_back(L'm');
+ break;
+ case 23:
+ result.push_back(L'%');
+ result.push_back(L'H');
+ break;
+ case 31:
+ result.push_back(L'%');
+ result.push_back(L'd');
+ break;
+ case 55:
+ result.push_back(L'%');
+ result.push_back(L'M');
+ break;
+ case 59:
+ result.push_back(L'%');
+ result.push_back(L'S');
+ break;
+ case 61:
+ result.push_back(L'%');
+ result.push_back(L'y');
+ break;
+ case 364:
+ result.push_back(L'%');
+ result.push_back(L'j');
+ break;
+ case 2061:
+ result.push_back(L'%');
+ result.push_back(L'Y');
+ break;
+ default:
+ for (; w != wbb; ++w)
+ result.push_back(*w);
+ break;
+ }
+ continue;
+ }
+ if (ct.narrow(*wbb, 0) == '%') {
+ result.push_back(L'%');
+ result.push_back(L'%');
+ ++wbb;
+ continue;
}
- // __am_pm_
- t.tm_hour = 1;
- strftime_l(buf, countof(buf), "%p", &t, __loc_);
- __am_pm_[0] = buf;
- t.tm_hour = 13;
- strftime_l(buf, countof(buf), "%p", &t, __loc_);
- __am_pm_[1] = buf;
- __c_ = __analyze('c', ct);
- __r_ = __analyze('r', ct);
- __x_ = __analyze('x', ct);
- __X_ = __analyze('X', ct);
+ result.push_back(*wbb);
+ ++wbb;
+ }
+ return result;
}
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
template <>
-void
-__time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct)
-{
- tm t = {0};
- char buf[100];
- wchar_t wbuf[100];
- wchar_t* wbe;
- mbstate_t mb = {0};
- // __weeks_
- for (int i = 0; i < 7; ++i)
- {
- t.tm_wday = i;
- strftime_l(buf, countof(buf), "%A", &t, __loc_);
- mb = mbstate_t();
- const char* bb = buf;
- size_t j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
- if (j == size_t(-1) || j == 0)
- __throw_runtime_error("locale not supported");
- wbe = wbuf + j;
- __weeks_[i].assign(wbuf, wbe);
- strftime_l(buf, countof(buf), "%a", &t, __loc_);
- mb = mbstate_t();
- bb = buf;
- j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
- if (j == size_t(-1) || j == 0)
- __throw_runtime_error("locale not supported");
- wbe = wbuf + j;
- __weeks_[i+7].assign(wbuf, wbe);
- }
- // __months_
- for (int i = 0; i < 12; ++i)
- {
- t.tm_mon = i;
- strftime_l(buf, countof(buf), "%B", &t, __loc_);
- mb = mbstate_t();
- const char* bb = buf;
- size_t j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
- if (j == size_t(-1) || j == 0)
- __throw_runtime_error("locale not supported");
- wbe = wbuf + j;
- __months_[i].assign(wbuf, wbe);
- strftime_l(buf, countof(buf), "%b", &t, __loc_);
- mb = mbstate_t();
- bb = buf;
- j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
- if (j == size_t(-1) || j == 0)
- __throw_runtime_error("locale not supported");
- wbe = wbuf + j;
- __months_[i+12].assign(wbuf, wbe);
- }
- // __am_pm_
- t.tm_hour = 1;
- strftime_l(buf, countof(buf), "%p", &t, __loc_);
+void __time_get_storage<char>::init(const ctype<char>& ct) {
+ tm t = {0};
+ char buf[100];
+ // __weeks_
+ for (int i = 0; i < 7; ++i) {
+ t.tm_wday = i;
+ strftime_l(buf, countof(buf), "%A", &t, __loc_);
+ __weeks_[i] = buf;
+ strftime_l(buf, countof(buf), "%a", &t, __loc_);
+ __weeks_[i + 7] = buf;
+ }
+ // __months_
+ for (int i = 0; i < 12; ++i) {
+ t.tm_mon = i;
+ strftime_l(buf, countof(buf), "%B", &t, __loc_);
+ __months_[i] = buf;
+ strftime_l(buf, countof(buf), "%b", &t, __loc_);
+ __months_[i + 12] = buf;
+ }
+ // __am_pm_
+ t.tm_hour = 1;
+ strftime_l(buf, countof(buf), "%p", &t, __loc_);
+ __am_pm_[0] = buf;
+ t.tm_hour = 13;
+ strftime_l(buf, countof(buf), "%p", &t, __loc_);
+ __am_pm_[1] = buf;
+ __c_ = __analyze('c', ct);
+ __r_ = __analyze('r', ct);
+ __x_ = __analyze('x', ct);
+ __X_ = __analyze('X', ct);
+}
+
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+template <>
+void __time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct) {
+ tm t = {0};
+ char buf[100];
+ wchar_t wbuf[100];
+ wchar_t* wbe;
+ mbstate_t mb = {0};
+ // __weeks_
+ for (int i = 0; i < 7; ++i) {
+ t.tm_wday = i;
+ strftime_l(buf, countof(buf), "%A", &t, __loc_);
+ mb = mbstate_t();
+ const char* bb = buf;
+ size_t j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
+ if (j == size_t(-1) || j == 0)
+ __throw_runtime_error("locale not supported");
+ wbe = wbuf + j;
+ __weeks_[i].assign(wbuf, wbe);
+ strftime_l(buf, countof(buf), "%a", &t, __loc_);
mb = mbstate_t();
+ bb = buf;
+ j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
+ if (j == size_t(-1) || j == 0)
+ __throw_runtime_error("locale not supported");
+ wbe = wbuf + j;
+ __weeks_[i + 7].assign(wbuf, wbe);
+ }
+ // __months_
+ for (int i = 0; i < 12; ++i) {
+ t.tm_mon = i;
+ strftime_l(buf, countof(buf), "%B", &t, __loc_);
+ mb = mbstate_t();
const char* bb = buf;
- size_t j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
- if (j == size_t(-1))
- __throw_runtime_error("locale not supported");
+ size_t j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
+ if (j == size_t(-1) || j == 0)
+ __throw_runtime_error("locale not supported");
wbe = wbuf + j;
- __am_pm_[0].assign(wbuf, wbe);
- t.tm_hour = 13;
- strftime_l(buf, countof(buf), "%p", &t, __loc_);
+ __months_[i].assign(wbuf, wbe);
+ strftime_l(buf, countof(buf), "%b", &t, __loc_);
mb = mbstate_t();
bb = buf;
- j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
- if (j == size_t(-1))
- __throw_runtime_error("locale not supported");
+ j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
+ if (j == size_t(-1) || j == 0)
+ __throw_runtime_error("locale not supported");
wbe = wbuf + j;
- __am_pm_[1].assign(wbuf, wbe);
- __c_ = __analyze('c', ct);
- __r_ = __analyze('r', ct);
- __x_ = __analyze('x', ct);
- __X_ = __analyze('X', ct);
-}
+ __months_[i + 12].assign(wbuf, wbe);
+ }
+ // __am_pm_
+ t.tm_hour = 1;
+ strftime_l(buf, countof(buf), "%p", &t, __loc_);
+ mb = mbstate_t();
+ const char* bb = buf;
+ size_t j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
+ if (j == size_t(-1))
+ __throw_runtime_error("locale not supported");
+ wbe = wbuf + j;
+ __am_pm_[0].assign(wbuf, wbe);
+ t.tm_hour = 13;
+ strftime_l(buf, countof(buf), "%p", &t, __loc_);
+ mb = mbstate_t();
+ bb = buf;
+ j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
+ if (j == size_t(-1))
+ __throw_runtime_error("locale not supported");
+ wbe = wbuf + j;
+ __am_pm_[1].assign(wbuf, wbe);
+ __c_ = __analyze('c', ct);
+ __r_ = __analyze('r', ct);
+ __x_ = __analyze('x', ct);
+ __X_ = __analyze('X', ct);
+}
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
template <class CharT>
-struct _LIBCPP_HIDDEN __time_get_temp
- : public ctype_byname<CharT>
-{
- explicit __time_get_temp(const char* nm)
- : ctype_byname<CharT>(nm, 1) {}
- explicit __time_get_temp(const string& nm)
- : ctype_byname<CharT>(nm, 1) {}
+struct _LIBCPP_HIDDEN __time_get_temp : public ctype_byname<CharT> {
+ explicit __time_get_temp(const char* nm) : ctype_byname<CharT>(nm, 1) {}
+ explicit __time_get_temp(const string& nm) : ctype_byname<CharT>(nm, 1) {}
};
template <>
-__time_get_storage<char>::__time_get_storage(const char* __nm)
- : __time_get(__nm)
-{
- const __time_get_temp<char> ct(__nm);
- init(ct);
+__time_get_storage<char>::__time_get_storage(const char* __nm) : __time_get(__nm) {
+ const __time_get_temp<char> ct(__nm);
+ init(ct);
}
template <>
-__time_get_storage<char>::__time_get_storage(const string& __nm)
- : __time_get(__nm)
-{
- const __time_get_temp<char> ct(__nm);
- init(ct);
+__time_get_storage<char>::__time_get_storage(const string& __nm) : __time_get(__nm) {
+ const __time_get_temp<char> ct(__nm);
+ init(ct);
}
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
template <>
-__time_get_storage<wchar_t>::__time_get_storage(const char* __nm)
- : __time_get(__nm)
-{
- const __time_get_temp<wchar_t> ct(__nm);
- init(ct);
+__time_get_storage<wchar_t>::__time_get_storage(const char* __nm) : __time_get(__nm) {
+ const __time_get_temp<wchar_t> ct(__nm);
+ init(ct);
}
template <>
-__time_get_storage<wchar_t>::__time_get_storage(const string& __nm)
- : __time_get(__nm)
-{
- const __time_get_temp<wchar_t> ct(__nm);
- init(ct);
+__time_get_storage<wchar_t>::__time_get_storage(const string& __nm) : __time_get(__nm) {
+ const __time_get_temp<wchar_t> ct(__nm);
+ init(ct);
}
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
template <>
-time_base::dateorder
-__time_get_storage<char>::__do_date_order() const
-{
- unsigned i;
- for (i = 0; i < __x_.size(); ++i)
- if (__x_[i] == '%')
- break;
- ++i;
- switch (__x_[i])
- {
- case 'y':
- case 'Y':
- for (++i; i < __x_.size(); ++i)
- if (__x_[i] == '%')
- break;
- if (i == __x_.size())
- break;
- ++i;
- switch (__x_[i])
- {
- case 'm':
- for (++i; i < __x_.size(); ++i)
- if (__x_[i] == '%')
- break;
- if (i == __x_.size())
- break;
- ++i;
- if (__x_[i] == 'd')
- return time_base::ymd;
- break;
- case 'd':
- for (++i; i < __x_.size(); ++i)
- if (__x_[i] == '%')
- break;
- if (i == __x_.size())
- break;
- ++i;
- if (__x_[i] == 'm')
- return time_base::ydm;
- break;
- }
+time_base::dateorder __time_get_storage<char>::__do_date_order() const {
+ unsigned i;
+ for (i = 0; i < __x_.size(); ++i)
+ if (__x_[i] == '%')
+ break;
+ ++i;
+ switch (__x_[i]) {
+ case 'y':
+ case 'Y':
+ for (++i; i < __x_.size(); ++i)
+ if (__x_[i] == '%')
break;
+ if (i == __x_.size())
+ break;
+ ++i;
+ switch (__x_[i]) {
case 'm':
- for (++i; i < __x_.size(); ++i)
- if (__x_[i] == '%')
- break;
- if (i == __x_.size())
- break;
- ++i;
- if (__x_[i] == 'd')
- {
- for (++i; i < __x_.size(); ++i)
- if (__x_[i] == '%')
- break;
- if (i == __x_.size())
- break;
- ++i;
- if (__x_[i] == 'y' || __x_[i] == 'Y')
- return time_base::mdy;
- break;
- }
+ for (++i; i < __x_.size(); ++i)
+ if (__x_[i] == '%')
+ break;
+ if (i == __x_.size())
break;
+ ++i;
+ if (__x_[i] == 'd')
+ return time_base::ymd;
+ break;
case 'd':
- for (++i; i < __x_.size(); ++i)
- if (__x_[i] == '%')
- break;
- if (i == __x_.size())
- break;
- ++i;
- if (__x_[i] == 'm')
- {
- for (++i; i < __x_.size(); ++i)
- if (__x_[i] == '%')
- break;
- if (i == __x_.size())
- break;
- ++i;
- if (__x_[i] == 'y' || __x_[i] == 'Y')
- return time_base::dmy;
- break;
- }
+ for (++i; i < __x_.size(); ++i)
+ if (__x_[i] == '%')
+ break;
+ if (i == __x_.size())
+ break;
+ ++i;
+ if (__x_[i] == 'm')
+ return time_base::ydm;
+ break;
+ }
+ break;
+ case 'm':
+ for (++i; i < __x_.size(); ++i)
+ if (__x_[i] == '%')
+ break;
+ if (i == __x_.size())
+ break;
+ ++i;
+ if (__x_[i] == 'd') {
+ for (++i; i < __x_.size(); ++i)
+ if (__x_[i] == '%')
+ break;
+ if (i == __x_.size())
break;
+ ++i;
+ if (__x_[i] == 'y' || __x_[i] == 'Y')
+ return time_base::mdy;
+ break;
}
- return time_base::no_order;
+ break;
+ case 'd':
+ for (++i; i < __x_.size(); ++i)
+ if (__x_[i] == '%')
+ break;
+ if (i == __x_.size())
+ break;
+ ++i;
+ if (__x_[i] == 'm') {
+ for (++i; i < __x_.size(); ++i)
+ if (__x_[i] == '%')
+ break;
+ if (i == __x_.size())
+ break;
+ ++i;
+ if (__x_[i] == 'y' || __x_[i] == 'Y')
+ return time_base::dmy;
+ break;
+ }
+ break;
+ }
+ return time_base::no_order;
}
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
template <>
-time_base::dateorder
-__time_get_storage<wchar_t>::__do_date_order() const
-{
- unsigned i;
- for (i = 0; i < __x_.size(); ++i)
- if (__x_[i] == L'%')
- break;
- ++i;
- switch (__x_[i])
- {
- case L'y':
- case L'Y':
- for (++i; i < __x_.size(); ++i)
- if (__x_[i] == L'%')
- break;
- if (i == __x_.size())
- break;
- ++i;
- switch (__x_[i])
- {
- case L'm':
- for (++i; i < __x_.size(); ++i)
- if (__x_[i] == L'%')
- break;
- if (i == __x_.size())
- break;
- ++i;
- if (__x_[i] == L'd')
- return time_base::ymd;
- break;
- case L'd':
- for (++i; i < __x_.size(); ++i)
- if (__x_[i] == L'%')
- break;
- if (i == __x_.size())
- break;
- ++i;
- if (__x_[i] == L'm')
- return time_base::ydm;
- break;
- }
+time_base::dateorder __time_get_storage<wchar_t>::__do_date_order() const {
+ unsigned i;
+ for (i = 0; i < __x_.size(); ++i)
+ if (__x_[i] == L'%')
+ break;
+ ++i;
+ switch (__x_[i]) {
+ case L'y':
+ case L'Y':
+ for (++i; i < __x_.size(); ++i)
+ if (__x_[i] == L'%')
break;
+ if (i == __x_.size())
+ break;
+ ++i;
+ switch (__x_[i]) {
case L'm':
- for (++i; i < __x_.size(); ++i)
- if (__x_[i] == L'%')
- break;
- if (i == __x_.size())
- break;
- ++i;
- if (__x_[i] == L'd')
- {
- for (++i; i < __x_.size(); ++i)
- if (__x_[i] == L'%')
- break;
- if (i == __x_.size())
- break;
- ++i;
- if (__x_[i] == L'y' || __x_[i] == L'Y')
- return time_base::mdy;
- break;
- }
+ for (++i; i < __x_.size(); ++i)
+ if (__x_[i] == L'%')
+ break;
+ if (i == __x_.size())
break;
+ ++i;
+ if (__x_[i] == L'd')
+ return time_base::ymd;
+ break;
case L'd':
- for (++i; i < __x_.size(); ++i)
- if (__x_[i] == L'%')
- break;
- if (i == __x_.size())
- break;
- ++i;
- if (__x_[i] == L'm')
- {
- for (++i; i < __x_.size(); ++i)
- if (__x_[i] == L'%')
- break;
- if (i == __x_.size())
- break;
- ++i;
- if (__x_[i] == L'y' || __x_[i] == L'Y')
- return time_base::dmy;
- break;
- }
+ for (++i; i < __x_.size(); ++i)
+ if (__x_[i] == L'%')
+ break;
+ if (i == __x_.size())
+ break;
+ ++i;
+ if (__x_[i] == L'm')
+ return time_base::ydm;
+ break;
+ }
+ break;
+ case L'm':
+ for (++i; i < __x_.size(); ++i)
+ if (__x_[i] == L'%')
+ break;
+ if (i == __x_.size())
+ break;
+ ++i;
+ if (__x_[i] == L'd') {
+ for (++i; i < __x_.size(); ++i)
+ if (__x_[i] == L'%')
+ break;
+ if (i == __x_.size())
+ break;
+ ++i;
+ if (__x_[i] == L'y' || __x_[i] == L'Y')
+ return time_base::mdy;
+ break;
+ }
+ break;
+ case L'd':
+ for (++i; i < __x_.size(); ++i)
+ if (__x_[i] == L'%')
+ break;
+ if (i == __x_.size())
+ break;
+ ++i;
+ if (__x_[i] == L'm') {
+ for (++i; i < __x_.size(); ++i)
+ if (__x_[i] == L'%')
+ break;
+ if (i == __x_.size())
break;
+ ++i;
+ if (__x_[i] == L'y' || __x_[i] == L'Y')
+ return time_base::dmy;
+ break;
}
- return time_base::no_order;
+ break;
+ }
+ return time_base::no_order;
}
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
// time_put
-__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));
-}
-
-__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);
-}
-
-__time_put::~__time_put()
-{
- if (__loc_ != _LIBCPP_GET_C_LOCALE)
- freelocale(__loc_);
-}
-
-void
-__time_put::__do_put(char* __nb, char*& __ne, const tm* __tm,
- char __fmt, char __mod) const
-{
- char fmt[] = {'%', __fmt, __mod, 0};
- if (__mod != 0)
- swap(fmt[1], fmt[2]);
- size_t n = strftime_l(__nb, countof(__nb, __ne), fmt, __tm, __loc_);
- __ne = __nb + n;
-}
-
-void
-__time_put::__do_put(wchar_t* __wb, wchar_t*& __we, const tm* __tm,
- char __fmt, char __mod) const
-{
- char __nar[100];
- char* __ne = __nar + 100;
- __do_put(__nar, __ne, __tm, __fmt, __mod);
- mbstate_t mb = {0};
- const char* __nb = __nar;
- size_t j = __libcpp_mbsrtowcs_l(__wb, &__nb, countof(__wb, __we), &mb, __loc_);
- if (j == size_t(-1))
- __throw_runtime_error("locale not supported");
- __we = __wb + j;
+__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)).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).c_str());
}
+__time_put::~__time_put() {
+ if (__loc_ != _LIBCPP_GET_C_LOCALE)
+ freelocale(__loc_);
+}
+
+void __time_put::__do_put(char* __nb, char*& __ne, const tm* __tm, char __fmt, char __mod) const {
+ char fmt[] = {'%', __fmt, __mod, 0};
+ if (__mod != 0)
+ swap(fmt[1], fmt[2]);
+ size_t n = strftime_l(__nb, countof(__nb, __ne), fmt, __tm, __loc_);
+ __ne = __nb + n;
+}
+
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+void __time_put::__do_put(wchar_t* __wb, wchar_t*& __we, const tm* __tm, char __fmt, char __mod) const {
+ char __nar[100];
+ char* __ne = __nar + 100;
+ __do_put(__nar, __ne, __tm, __fmt, __mod);
+ mbstate_t mb = {0};
+ const char* __nb = __nar;
+ size_t j = __libcpp_mbsrtowcs_l(__wb, &__nb, countof(__wb, __we), &mb, __loc_);
+ if (j == size_t(-1))
+ __throw_runtime_error("locale not supported");
+ __we = __wb + j;
+}
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
+
// moneypunct_byname
template <class charT>
-static
-void
-__init_pat(money_base::pattern& pat, basic_string<charT>& __curr_symbol_,
- bool intl, char cs_precedes, char sep_by_space, char sign_posn,
- charT space_char)
-{
- const char sign = static_cast<char>(money_base::sign);
- const char space = static_cast<char>(money_base::space);
- const char none = static_cast<char>(money_base::none);
- const char symbol = static_cast<char>(money_base::symbol);
- const char value = static_cast<char>(money_base::value);
- const bool symbol_contains_sep = intl && __curr_symbol_.size() == 4;
-
- // Comments on case branches reflect 'C11 7.11.2.1 The localeconv
- // function'. "Space between sign and symbol or value" means that
- // if the sign is adjacent to the symbol, there's a space between
- // them, and otherwise there's a space between the sign and value.
- //
- // C11's localeconv specifies that the fourth character of an
- // international curr_symbol is used to separate the sign and
- // value when sep_by_space says to do so. C++ can't represent
- // that, so we just use a space. When sep_by_space says to
- // separate the symbol and value-or-sign with a space, we rearrange the
- // curr_symbol to put its spacing character on the correct side of
- // the symbol.
- //
- // We also need to avoid adding an extra space between the sign
- // and value when the currency symbol is suppressed (by not
- // setting showbase). We match glibc's strfmon by interpreting
- // sep_by_space==1 as "omit the space when the currency symbol is
- // absent".
- //
- // Users who want to get this right should use ICU instead.
-
- switch (cs_precedes)
- {
- case 0: // value before curr_symbol
+static void __init_pat(
+ money_base::pattern& pat,
+ basic_string<charT>& __curr_symbol_,
+ bool intl,
+ char cs_precedes,
+ char sep_by_space,
+ char sign_posn,
+ charT space_char) {
+ const char sign = static_cast<char>(money_base::sign);
+ const char space = static_cast<char>(money_base::space);
+ const char none = static_cast<char>(money_base::none);
+ const char symbol = static_cast<char>(money_base::symbol);
+ const char value = static_cast<char>(money_base::value);
+ const bool symbol_contains_sep = intl && __curr_symbol_.size() == 4;
+
+ // Comments on case branches reflect 'C11 7.11.2.1 The localeconv
+ // function'. "Space between sign and symbol or value" means that
+ // if the sign is adjacent to the symbol, there's a space between
+ // them, and otherwise there's a space between the sign and value.
+ //
+ // C11's localeconv specifies that the fourth character of an
+ // international curr_symbol is used to separate the sign and
+ // value when sep_by_space says to do so. C++ can't represent
+ // that, so we just use a space. When sep_by_space says to
+ // separate the symbol and value-or-sign with a space, we rearrange the
+ // curr_symbol to put its spacing character on the correct side of
+ // the symbol.
+ //
+ // We also need to avoid adding an extra space between the sign
+ // and value when the currency symbol is suppressed (by not
+ // setting showbase). We match glibc's strfmon by interpreting
+ // sep_by_space==1 as "omit the space when the currency symbol is
+ // absent".
+ //
+ // Users who want to get this right should use ICU instead.
+
+ switch (cs_precedes) {
+ case 0: // value before curr_symbol
+ if (symbol_contains_sep) {
+ // Move the separator to before the symbol, to place it
+ // between the value and symbol.
+ rotate(__curr_symbol_.begin(), __curr_symbol_.begin() + 3, __curr_symbol_.end());
+ }
+ switch (sign_posn) {
+ case 0: // Parentheses surround the quantity and currency symbol.
+ pat.field[0] = sign;
+ pat.field[1] = value;
+ pat.field[2] = none; // Any space appears in the symbol.
+ pat.field[3] = symbol;
+ switch (sep_by_space) {
+ case 0: // No space separates the currency symbol and value.
+ // This case may have changed between C99 and C11;
+ // assume the currency symbol matches the intention.
+ case 2: // Space between sign and currency or value.
+ // The "sign" is two parentheses, so no space here either.
+ return;
+ case 1: // Space between currency-and-sign or currency and value.
+ if (!symbol_contains_sep) {
+ // We insert the space into the symbol instead of
+ // setting pat.field[2]=space so that when
+ // showbase is not set, the space goes away too.
+ __curr_symbol_.insert(0, 1, space_char);
+ }
+ return;
+ default:
+ break;
+ }
+ break;
+ case 1: // The sign string precedes the quantity and currency symbol.
+ pat.field[0] = sign;
+ pat.field[3] = symbol;
+ switch (sep_by_space) {
+ case 0: // No space separates the currency symbol and value.
+ pat.field[1] = value;
+ pat.field[2] = none;
+ return;
+ case 1: // Space between currency-and-sign or currency and value.
+ pat.field[1] = value;
+ pat.field[2] = none;
+ if (!symbol_contains_sep) {
+ // We insert the space into the symbol instead of
+ // setting pat.field[2]=space so that when
+ // showbase is not set, the space goes away too.
+ __curr_symbol_.insert(0, 1, space_char);
+ }
+ return;
+ case 2: // Space between sign and currency or value.
+ pat.field[1] = space;
+ pat.field[2] = value;
if (symbol_contains_sep) {
- // Move the separator to before the symbol, to place it
- // between the value and symbol.
- rotate(__curr_symbol_.begin(), __curr_symbol_.begin() + 3,
- __curr_symbol_.end());
+ // Remove the separator from the symbol, since it
+ // has already appeared after the sign.
+ __curr_symbol_.erase(__curr_symbol_.begin());
}
- switch (sign_posn)
- {
- case 0: // Parentheses surround the quantity and currency symbol.
- pat.field[0] = sign;
- pat.field[1] = value;
- pat.field[2] = none; // Any space appears in the symbol.
- pat.field[3] = symbol;
- switch (sep_by_space)
- {
- case 0: // No space separates the currency symbol and value.
- // This case may have changed between C99 and C11;
- // assume the currency symbol matches the intention.
- case 2: // Space between sign and currency or value.
- // The "sign" is two parentheses, so no space here either.
- return;
- case 1: // Space between currency-and-sign or currency and value.
- if (!symbol_contains_sep) {
- // We insert the space into the symbol instead of
- // setting pat.field[2]=space so that when
- // showbase is not set, the space goes away too.
- __curr_symbol_.insert(0, 1, space_char);
- }
- return;
- default:
- break;
- }
- break;
- case 1: // The sign string precedes the quantity and currency symbol.
- pat.field[0] = sign;
- pat.field[3] = symbol;
- switch (sep_by_space)
- {
- case 0: // No space separates the currency symbol and value.
- pat.field[1] = value;
- pat.field[2] = none;
- return;
- case 1: // Space between currency-and-sign or currency and value.
- pat.field[1] = value;
- pat.field[2] = none;
- if (!symbol_contains_sep) {
- // We insert the space into the symbol instead of
- // setting pat.field[2]=space so that when
- // showbase is not set, the space goes away too.
- __curr_symbol_.insert(0, 1, space_char);
- }
- return;
- case 2: // Space between sign and currency or value.
- pat.field[1] = space;
- pat.field[2] = value;
- if (symbol_contains_sep) {
- // Remove the separator from the symbol, since it
- // has already appeared after the sign.
- __curr_symbol_.erase(__curr_symbol_.begin());
- }
- return;
- default:
- break;
- }
- break;
- case 2: // The sign string succeeds the quantity and currency symbol.
- pat.field[0] = value;
- pat.field[3] = sign;
- switch (sep_by_space)
- {
- case 0: // No space separates the currency symbol and value.
- pat.field[1] = none;
- pat.field[2] = symbol;
- return;
- case 1: // Space between currency-and-sign or currency and value.
- if (!symbol_contains_sep) {
- // We insert the space into the symbol instead of
- // setting pat.field[1]=space so that when
- // showbase is not set, the space goes away too.
- __curr_symbol_.insert(0, 1, space_char);
- }
- pat.field[1] = none;
- pat.field[2] = symbol;
- return;
- case 2: // Space between sign and currency or value.
- pat.field[1] = symbol;
- pat.field[2] = space;
- if (symbol_contains_sep) {
- // Remove the separator from the symbol, since it
- // should not be removed if showbase is absent.
- __curr_symbol_.erase(__curr_symbol_.begin());
- }
- return;
- default:
- break;
- }
- break;
- case 3: // The sign string immediately precedes the currency symbol.
- pat.field[0] = value;
- pat.field[3] = symbol;
- switch (sep_by_space)
- {
- case 0: // No space separates the currency symbol and value.
- pat.field[1] = none;
- pat.field[2] = sign;
- return;
- case 1: // Space between currency-and-sign or currency and value.
- pat.field[1] = space;
- pat.field[2] = sign;
- if (symbol_contains_sep) {
- // Remove the separator from the symbol, since it
- // has already appeared before the sign.
- __curr_symbol_.erase(__curr_symbol_.begin());
- }
- return;
- case 2: // Space between sign and currency or value.
- pat.field[1] = sign;
- pat.field[2] = none;
- if (!symbol_contains_sep) {
- // We insert the space into the symbol instead of
- // setting pat.field[2]=space so that when
- // showbase is not set, the space goes away too.
- __curr_symbol_.insert(0, 1, space_char);
- }
- return;
- default:
- break;
- }
- break;
- case 4: // The sign string immediately succeeds the currency symbol.
- pat.field[0] = value;
- pat.field[3] = sign;
- switch (sep_by_space)
- {
- case 0: // No space separates the currency symbol and value.
- pat.field[1] = none;
- pat.field[2] = symbol;
- return;
- case 1: // Space between currency-and-sign or currency and value.
- pat.field[1] = none;
- pat.field[2] = symbol;
- if (!symbol_contains_sep) {
- // We insert the space into the symbol instead of
- // setting pat.field[1]=space so that when
- // showbase is not set, the space goes away too.
- __curr_symbol_.insert(0, 1, space_char);
- }
- return;
- case 2: // Space between sign and currency or value.
- pat.field[1] = symbol;
- pat.field[2] = space;
- if (symbol_contains_sep) {
- // Remove the separator from the symbol, since it
- // should not disappear when showbase is absent.
- __curr_symbol_.erase(__curr_symbol_.begin());
- }
- return;
- default:
- break;
- }
- break;
- default:
- break;
+ return;
+ default:
+ break;
+ }
+ break;
+ case 2: // The sign string succeeds the quantity and currency symbol.
+ pat.field[0] = value;
+ pat.field[3] = sign;
+ switch (sep_by_space) {
+ case 0: // No space separates the currency symbol and value.
+ pat.field[1] = none;
+ pat.field[2] = symbol;
+ return;
+ case 1: // Space between currency-and-sign or currency and value.
+ if (!symbol_contains_sep) {
+ // We insert the space into the symbol instead of
+ // setting pat.field[1]=space so that when
+ // showbase is not set, the space goes away too.
+ __curr_symbol_.insert(0, 1, space_char);
+ }
+ pat.field[1] = none;
+ pat.field[2] = symbol;
+ return;
+ case 2: // Space between sign and currency or value.
+ pat.field[1] = symbol;
+ pat.field[2] = space;
+ if (symbol_contains_sep) {
+ // Remove the separator from the symbol, since it
+ // should not be removed if showbase is absent.
+ __curr_symbol_.erase(__curr_symbol_.begin());
}
+ return;
+ default:
break;
- case 1: // curr_symbol before value
- switch (sign_posn)
- {
- case 0: // Parentheses surround the quantity and currency symbol.
- pat.field[0] = sign;
- pat.field[1] = symbol;
- pat.field[2] = none; // Any space appears in the symbol.
- pat.field[3] = value;
- switch (sep_by_space)
- {
- case 0: // No space separates the currency symbol and value.
- // This case may have changed between C99 and C11;
- // assume the currency symbol matches the intention.
- case 2: // Space between sign and currency or value.
- // The "sign" is two parentheses, so no space here either.
- return;
- case 1: // Space between currency-and-sign or currency and value.
- if (!symbol_contains_sep) {
- // We insert the space into the symbol instead of
- // setting pat.field[2]=space so that when
- // showbase is not set, the space goes away too.
- __curr_symbol_.insert(0, 1, space_char);
- }
- return;
- default:
- break;
- }
- break;
- case 1: // The sign string precedes the quantity and currency symbol.
- pat.field[0] = sign;
- pat.field[3] = value;
- switch (sep_by_space)
- {
- case 0: // No space separates the currency symbol and value.
- pat.field[1] = symbol;
- pat.field[2] = none;
- return;
- case 1: // Space between currency-and-sign or currency and value.
- pat.field[1] = symbol;
- pat.field[2] = none;
- if (!symbol_contains_sep) {
- // We insert the space into the symbol instead of
- // setting pat.field[2]=space so that when
- // showbase is not set, the space goes away too.
- __curr_symbol_.push_back(space_char);
- }
- return;
- case 2: // Space between sign and currency or value.
- pat.field[1] = space;
- pat.field[2] = symbol;
- if (symbol_contains_sep) {
- // Remove the separator from the symbol, since it
- // has already appeared after the sign.
- __curr_symbol_.pop_back();
- }
- return;
- default:
- break;
- }
- break;
- case 2: // The sign string succeeds the quantity and currency symbol.
- pat.field[0] = symbol;
- pat.field[3] = sign;
- switch (sep_by_space)
- {
- case 0: // No space separates the currency symbol and value.
- pat.field[1] = none;
- pat.field[2] = value;
- return;
- case 1: // Space between currency-and-sign or currency and value.
- pat.field[1] = none;
- pat.field[2] = value;
- if (!symbol_contains_sep) {
- // We insert the space into the symbol instead of
- // setting pat.field[1]=space so that when
- // showbase is not set, the space goes away too.
- __curr_symbol_.push_back(space_char);
- }
- return;
- case 2: // Space between sign and currency or value.
- pat.field[1] = value;
- pat.field[2] = space;
- if (symbol_contains_sep) {
- // Remove the separator from the symbol, since it
- // will appear before the sign.
- __curr_symbol_.pop_back();
- }
- return;
- default:
- break;
- }
- break;
- case 3: // The sign string immediately precedes the currency symbol.
- pat.field[0] = sign;
- pat.field[3] = value;
- switch (sep_by_space)
- {
- case 0: // No space separates the currency symbol and value.
- pat.field[1] = symbol;
- pat.field[2] = none;
- return;
- case 1: // Space between currency-and-sign or currency and value.
- pat.field[1] = symbol;
- pat.field[2] = none;
- if (!symbol_contains_sep) {
- // We insert the space into the symbol instead of
- // setting pat.field[2]=space so that when
- // showbase is not set, the space goes away too.
- __curr_symbol_.push_back(space_char);
- }
- return;
- case 2: // Space between sign and currency or value.
- pat.field[1] = space;
- pat.field[2] = symbol;
- if (symbol_contains_sep) {
- // Remove the separator from the symbol, since it
- // has already appeared after the sign.
- __curr_symbol_.pop_back();
- }
- return;
- default:
- break;
- }
- break;
- case 4: // The sign string immediately succeeds the currency symbol.
- pat.field[0] = symbol;
- pat.field[3] = value;
- switch (sep_by_space)
- {
- case 0: // No space separates the currency symbol and value.
- pat.field[1] = sign;
- pat.field[2] = none;
- return;
- case 1: // Space between currency-and-sign or currency and value.
- pat.field[1] = sign;
- pat.field[2] = space;
- if (symbol_contains_sep) {
- // Remove the separator from the symbol, since it
- // should not disappear when showbase is absent.
- __curr_symbol_.pop_back();
- }
- return;
- case 2: // Space between sign and currency or value.
- pat.field[1] = none;
- pat.field[2] = sign;
- if (!symbol_contains_sep) {
- // We insert the space into the symbol instead of
- // setting pat.field[1]=space so that when
- // showbase is not set, the space goes away too.
- __curr_symbol_.push_back(space_char);
- }
- return;
- default:
- break;
- }
- break;
- default:
- break;
+ }
+ break;
+ case 3: // The sign string immediately precedes the currency symbol.
+ pat.field[0] = value;
+ pat.field[3] = symbol;
+ switch (sep_by_space) {
+ case 0: // No space separates the currency symbol and value.
+ pat.field[1] = none;
+ pat.field[2] = sign;
+ return;
+ case 1: // Space between currency-and-sign or currency and value.
+ pat.field[1] = space;
+ pat.field[2] = sign;
+ if (symbol_contains_sep) {
+ // Remove the separator from the symbol, since it
+ // has already appeared before the sign.
+ __curr_symbol_.erase(__curr_symbol_.begin());
+ }
+ return;
+ case 2: // Space between sign and currency or value.
+ pat.field[1] = sign;
+ pat.field[2] = none;
+ if (!symbol_contains_sep) {
+ // We insert the space into the symbol instead of
+ // setting pat.field[2]=space so that when
+ // showbase is not set, the space goes away too.
+ __curr_symbol_.insert(0, 1, space_char);
+ }
+ return;
+ default:
+ break;
+ }
+ break;
+ case 4: // The sign string immediately succeeds the currency symbol.
+ pat.field[0] = value;
+ pat.field[3] = sign;
+ switch (sep_by_space) {
+ case 0: // No space separates the currency symbol and value.
+ pat.field[1] = none;
+ pat.field[2] = symbol;
+ return;
+ case 1: // Space between currency-and-sign or currency and value.
+ pat.field[1] = none;
+ pat.field[2] = symbol;
+ if (!symbol_contains_sep) {
+ // We insert the space into the symbol instead of
+ // setting pat.field[1]=space so that when
+ // showbase is not set, the space goes away too.
+ __curr_symbol_.insert(0, 1, space_char);
+ }
+ return;
+ case 2: // Space between sign and currency or value.
+ pat.field[1] = symbol;
+ pat.field[2] = space;
+ if (symbol_contains_sep) {
+ // Remove the separator from the symbol, since it
+ // should not disappear when showbase is absent.
+ __curr_symbol_.erase(__curr_symbol_.begin());
}
+ return;
+ default:
break;
+ }
+ break;
default:
+ break;
+ }
+ break;
+ case 1: // curr_symbol before value
+ switch (sign_posn) {
+ case 0: // Parentheses surround the quantity and currency symbol.
+ pat.field[0] = sign;
+ pat.field[1] = symbol;
+ pat.field[2] = none; // Any space appears in the symbol.
+ pat.field[3] = value;
+ switch (sep_by_space) {
+ case 0: // No space separates the currency symbol and value.
+ // This case may have changed between C99 and C11;
+ // assume the currency symbol matches the intention.
+ case 2: // Space between sign and currency or value.
+ // The "sign" is two parentheses, so no space here either.
+ return;
+ case 1: // Space between currency-and-sign or currency and value.
+ if (!symbol_contains_sep) {
+ // We insert the space into the symbol instead of
+ // setting pat.field[2]=space so that when
+ // showbase is not set, the space goes away too.
+ __curr_symbol_.insert(0, 1, space_char);
+ }
+ return;
+ default:
+ break;
+ }
+ break;
+ case 1: // The sign string precedes the quantity and currency symbol.
+ pat.field[0] = sign;
+ pat.field[3] = value;
+ switch (sep_by_space) {
+ case 0: // No space separates the currency symbol and value.
+ pat.field[1] = symbol;
+ pat.field[2] = none;
+ return;
+ case 1: // Space between currency-and-sign or currency and value.
+ pat.field[1] = symbol;
+ pat.field[2] = none;
+ if (!symbol_contains_sep) {
+ // We insert the space into the symbol instead of
+ // setting pat.field[2]=space so that when
+ // showbase is not set, the space goes away too.
+ __curr_symbol_.push_back(space_char);
+ }
+ return;
+ case 2: // Space between sign and currency or value.
+ pat.field[1] = space;
+ pat.field[2] = symbol;
+ if (symbol_contains_sep) {
+ // Remove the separator from the symbol, since it
+ // has already appeared after the sign.
+ __curr_symbol_.pop_back();
+ }
+ return;
+ default:
+ break;
+ }
+ break;
+ case 2: // The sign string succeeds the quantity and currency symbol.
+ pat.field[0] = symbol;
+ pat.field[3] = sign;
+ switch (sep_by_space) {
+ case 0: // No space separates the currency symbol and value.
+ pat.field[1] = none;
+ pat.field[2] = value;
+ return;
+ case 1: // Space between currency-and-sign or currency and value.
+ pat.field[1] = none;
+ pat.field[2] = value;
+ if (!symbol_contains_sep) {
+ // We insert the space into the symbol instead of
+ // setting pat.field[1]=space so that when
+ // showbase is not set, the space goes away too.
+ __curr_symbol_.push_back(space_char);
+ }
+ return;
+ case 2: // Space between sign and currency or value.
+ pat.field[1] = value;
+ pat.field[2] = space;
+ if (symbol_contains_sep) {
+ // Remove the separator from the symbol, since it
+ // will appear before the sign.
+ __curr_symbol_.pop_back();
+ }
+ return;
+ default:
+ break;
+ }
+ break;
+ case 3: // The sign string immediately precedes the currency symbol.
+ pat.field[0] = sign;
+ pat.field[3] = value;
+ switch (sep_by_space) {
+ case 0: // No space separates the currency symbol and value.
+ pat.field[1] = symbol;
+ pat.field[2] = none;
+ return;
+ case 1: // Space between currency-and-sign or currency and value.
+ pat.field[1] = symbol;
+ pat.field[2] = none;
+ if (!symbol_contains_sep) {
+ // We insert the space into the symbol instead of
+ // setting pat.field[2]=space so that when
+ // showbase is not set, the space goes away too.
+ __curr_symbol_.push_back(space_char);
+ }
+ return;
+ case 2: // Space between sign and currency or value.
+ pat.field[1] = space;
+ pat.field[2] = symbol;
+ if (symbol_contains_sep) {
+ // Remove the separator from the symbol, since it
+ // has already appeared after the sign.
+ __curr_symbol_.pop_back();
+ }
+ return;
+ default:
break;
+ }
+ break;
+ case 4: // The sign string immediately succeeds the currency symbol.
+ pat.field[0] = symbol;
+ pat.field[3] = value;
+ switch (sep_by_space) {
+ case 0: // No space separates the currency symbol and value.
+ pat.field[1] = sign;
+ pat.field[2] = none;
+ return;
+ case 1: // Space between currency-and-sign or currency and value.
+ pat.field[1] = sign;
+ pat.field[2] = space;
+ if (symbol_contains_sep) {
+ // Remove the separator from the symbol, since it
+ // should not disappear when showbase is absent.
+ __curr_symbol_.pop_back();
+ }
+ return;
+ case 2: // Space between sign and currency or value.
+ pat.field[1] = none;
+ pat.field[2] = sign;
+ if (!symbol_contains_sep) {
+ // We insert the space into the symbol instead of
+ // setting pat.field[1]=space so that when
+ // showbase is not set, the space goes away too.
+ __curr_symbol_.push_back(space_char);
+ }
+ return;
+ default:
+ break;
+ }
+ break;
+ default:
+ break;
}
- pat.field[0] = symbol;
- pat.field[1] = sign;
- pat.field[2] = none;
- pat.field[3] = value;
+ break;
+ default:
+ break;
+ }
+ pat.field[0] = symbol;
+ pat.field[1] = sign;
+ pat.field[2] = none;
+ pat.field[3] = value;
}
-template<>
-void
-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));
-
- lconv* lc = __libcpp_localeconv_l(loc.get());
- if (!checked_string_to_char_convert(__decimal_point_,
- lc->mon_decimal_point,
- loc.get()))
- __decimal_point_ = base::do_decimal_point();
- if (!checked_string_to_char_convert(__thousands_sep_,
- lc->mon_thousands_sep,
- loc.get()))
- __thousands_sep_ = base::do_thousands_sep();
-
- __grouping_ = lc->mon_grouping;
- __curr_symbol_ = lc->currency_symbol;
- if (lc->frac_digits != CHAR_MAX)
- __frac_digits_ = lc->frac_digits;
- else
- __frac_digits_ = base::do_frac_digits();
- if (lc->p_sign_posn == 0)
- __positive_sign_ = "()";
- else
- __positive_sign_ = lc->positive_sign;
- if (lc->n_sign_posn == 0)
- __negative_sign_ = "()";
- else
- __negative_sign_ = lc->negative_sign;
- // Assume the positive and negative formats will want spaces in
- // the same places in curr_symbol since there's no way to
- // represent anything else.
- string_type __dummy_curr_symbol = __curr_symbol_;
- __init_pat(__pos_format_, __dummy_curr_symbol, false,
- lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn, ' ');
- __init_pat(__neg_format_, __curr_symbol_, false,
- lc->n_cs_precedes, lc->n_sep_by_space, lc->n_sign_posn, ' ');
-}
-
-template<>
-void
-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));
+template <>
+void 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)).c_str());
+
+ lconv* lc = __libcpp_localeconv_l(loc.get());
+ if (!checked_string_to_char_convert(__decimal_point_, lc->mon_decimal_point, loc.get()))
+ __decimal_point_ = base::do_decimal_point();
+ if (!checked_string_to_char_convert(__thousands_sep_, lc->mon_thousands_sep, loc.get()))
+ __thousands_sep_ = base::do_thousands_sep();
+
+ __grouping_ = lc->mon_grouping;
+ __curr_symbol_ = lc->currency_symbol;
+ if (lc->frac_digits != CHAR_MAX)
+ __frac_digits_ = lc->frac_digits;
+ else
+ __frac_digits_ = base::do_frac_digits();
+ if (lc->p_sign_posn == 0)
+ __positive_sign_ = "()";
+ else
+ __positive_sign_ = lc->positive_sign;
+ if (lc->n_sign_posn == 0)
+ __negative_sign_ = "()";
+ else
+ __negative_sign_ = lc->negative_sign;
+ // Assume the positive and negative formats will want spaces in
+ // the same places in curr_symbol since there's no way to
+ // represent anything else.
+ string_type __dummy_curr_symbol = __curr_symbol_;
+ __init_pat(__pos_format_, __dummy_curr_symbol, false, lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn, ' ');
+ __init_pat(__neg_format_, __curr_symbol_, false, lc->n_cs_precedes, lc->n_sep_by_space, lc->n_sign_posn, ' ');
+}
- lconv* lc = __libcpp_localeconv_l(loc.get());
- if (!checked_string_to_char_convert(__decimal_point_,
- lc->mon_decimal_point,
- loc.get()))
- __decimal_point_ = base::do_decimal_point();
- if (!checked_string_to_char_convert(__thousands_sep_,
- lc->mon_thousands_sep,
- loc.get()))
- __thousands_sep_ = base::do_thousands_sep();
- __grouping_ = lc->mon_grouping;
- __curr_symbol_ = lc->int_curr_symbol;
- if (lc->int_frac_digits != CHAR_MAX)
- __frac_digits_ = lc->int_frac_digits;
- else
- __frac_digits_ = base::do_frac_digits();
+template <>
+void 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)).c_str());
+
+ lconv* lc = __libcpp_localeconv_l(loc.get());
+ if (!checked_string_to_char_convert(__decimal_point_, lc->mon_decimal_point, loc.get()))
+ __decimal_point_ = base::do_decimal_point();
+ if (!checked_string_to_char_convert(__thousands_sep_, lc->mon_thousands_sep, loc.get()))
+ __thousands_sep_ = base::do_thousands_sep();
+ __grouping_ = lc->mon_grouping;
+ __curr_symbol_ = lc->int_curr_symbol;
+ if (lc->int_frac_digits != CHAR_MAX)
+ __frac_digits_ = lc->int_frac_digits;
+ else
+ __frac_digits_ = base::do_frac_digits();
#if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
- if (lc->p_sign_posn == 0)
-#else // _LIBCPP_MSVCRT
- if (lc->int_p_sign_posn == 0)
+ if (lc->p_sign_posn == 0)
+#else // _LIBCPP_MSVCRT
+ if (lc->int_p_sign_posn == 0)
#endif // !_LIBCPP_MSVCRT
- __positive_sign_ = "()";
- else
- __positive_sign_ = lc->positive_sign;
+ __positive_sign_ = "()";
+ else
+ __positive_sign_ = lc->positive_sign;
#if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
- if(lc->n_sign_posn == 0)
-#else // _LIBCPP_MSVCRT
- if (lc->int_n_sign_posn == 0)
+ if (lc->n_sign_posn == 0)
+#else // _LIBCPP_MSVCRT
+ if (lc->int_n_sign_posn == 0)
#endif // !_LIBCPP_MSVCRT
- __negative_sign_ = "()";
- else
- __negative_sign_ = lc->negative_sign;
- // Assume the positive and negative formats will want spaces in
- // the same places in curr_symbol since there's no way to
- // represent anything else.
- string_type __dummy_curr_symbol = __curr_symbol_;
+ __negative_sign_ = "()";
+ else
+ __negative_sign_ = lc->negative_sign;
+ // Assume the positive and negative formats will want spaces in
+ // the same places in curr_symbol since there's no way to
+ // represent anything else.
+ string_type __dummy_curr_symbol = __curr_symbol_;
#if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
- __init_pat(__pos_format_, __dummy_curr_symbol, true,
- lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn, ' ');
- __init_pat(__neg_format_, __curr_symbol_, true,
- lc->n_cs_precedes, lc->n_sep_by_space, lc->n_sign_posn, ' ');
-#else // _LIBCPP_MSVCRT
- __init_pat(__pos_format_, __dummy_curr_symbol, true,
- lc->int_p_cs_precedes, lc->int_p_sep_by_space,
- lc->int_p_sign_posn, ' ');
- __init_pat(__neg_format_, __curr_symbol_, true,
- lc->int_n_cs_precedes, lc->int_n_sep_by_space,
- lc->int_n_sign_posn, ' ');
+ __init_pat(__pos_format_, __dummy_curr_symbol, true, lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn, ' ');
+ __init_pat(__neg_format_, __curr_symbol_, true, lc->n_cs_precedes, lc->n_sep_by_space, lc->n_sign_posn, ' ');
+#else // _LIBCPP_MSVCRT
+ __init_pat(
+ __pos_format_,
+ __dummy_curr_symbol,
+ true,
+ lc->int_p_cs_precedes,
+ lc->int_p_sep_by_space,
+ lc->int_p_sign_posn,
+ ' ');
+ __init_pat(
+ __neg_format_, __curr_symbol_, true, lc->int_n_cs_precedes, lc->int_n_sep_by_space, lc->int_n_sign_posn, ' ');
#endif // !_LIBCPP_MSVCRT
}
-template<>
-void
-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));
- lconv* lc = __libcpp_localeconv_l(loc.get());
- if (!checked_string_to_wchar_convert(__decimal_point_,
- lc->mon_decimal_point,
- loc.get()))
- __decimal_point_ = base::do_decimal_point();
- if (!checked_string_to_wchar_convert(__thousands_sep_,
- lc->mon_thousands_sep,
- loc.get()))
- __thousands_sep_ = base::do_thousands_sep();
- __grouping_ = lc->mon_grouping;
- wchar_t wbuf[100];
- mbstate_t mb = {0};
- const char* bb = lc->currency_symbol;
- size_t j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+template <>
+void 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)).c_str());
+ lconv* lc = __libcpp_localeconv_l(loc.get());
+ if (!checked_string_to_wchar_convert(__decimal_point_, lc->mon_decimal_point, loc.get()))
+ __decimal_point_ = base::do_decimal_point();
+ if (!checked_string_to_wchar_convert(__thousands_sep_, lc->mon_thousands_sep, loc.get()))
+ __thousands_sep_ = base::do_thousands_sep();
+ __grouping_ = lc->mon_grouping;
+ wchar_t wbuf[100];
+ mbstate_t mb = {0};
+ const char* bb = lc->currency_symbol;
+ size_t j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
+ if (j == size_t(-1))
+ __throw_runtime_error("locale not supported");
+ wchar_t* wbe = wbuf + j;
+ __curr_symbol_.assign(wbuf, wbe);
+ if (lc->frac_digits != CHAR_MAX)
+ __frac_digits_ = lc->frac_digits;
+ else
+ __frac_digits_ = base::do_frac_digits();
+ if (lc->p_sign_posn == 0)
+ __positive_sign_ = L"()";
+ else {
+ mb = mbstate_t();
+ bb = lc->positive_sign;
+ j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
if (j == size_t(-1))
- __throw_runtime_error("locale not supported");
- wchar_t* wbe = wbuf + j;
- __curr_symbol_.assign(wbuf, wbe);
- if (lc->frac_digits != CHAR_MAX)
- __frac_digits_ = lc->frac_digits;
- else
- __frac_digits_ = base::do_frac_digits();
- if (lc->p_sign_posn == 0)
- __positive_sign_ = L"()";
- else
- {
- mb = mbstate_t();
- bb = lc->positive_sign;
- j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
- if (j == size_t(-1))
- __throw_runtime_error("locale not supported");
- wbe = wbuf + j;
- __positive_sign_.assign(wbuf, wbe);
- }
- if (lc->n_sign_posn == 0)
- __negative_sign_ = L"()";
- else
- {
- mb = mbstate_t();
- bb = lc->negative_sign;
- j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
- if (j == size_t(-1))
- __throw_runtime_error("locale not supported");
- wbe = wbuf + j;
- __negative_sign_.assign(wbuf, wbe);
- }
- // Assume the positive and negative formats will want spaces in
- // the same places in curr_symbol since there's no way to
- // represent anything else.
- string_type __dummy_curr_symbol = __curr_symbol_;
- __init_pat(__pos_format_, __dummy_curr_symbol, false,
- lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn, L' ');
- __init_pat(__neg_format_, __curr_symbol_, false,
- lc->n_cs_precedes, lc->n_sep_by_space, lc->n_sign_posn, L' ');
-}
-
-template<>
-void
-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));
-
- lconv* lc = __libcpp_localeconv_l(loc.get());
- if (!checked_string_to_wchar_convert(__decimal_point_,
- lc->mon_decimal_point,
- loc.get()))
- __decimal_point_ = base::do_decimal_point();
- if (!checked_string_to_wchar_convert(__thousands_sep_,
- lc->mon_thousands_sep,
- loc.get()))
- __thousands_sep_ = base::do_thousands_sep();
- __grouping_ = lc->mon_grouping;
- wchar_t wbuf[100];
- mbstate_t mb = {0};
- const char* bb = lc->int_curr_symbol;
- size_t j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
+ __throw_runtime_error("locale not supported");
+ wbe = wbuf + j;
+ __positive_sign_.assign(wbuf, wbe);
+ }
+ if (lc->n_sign_posn == 0)
+ __negative_sign_ = L"()";
+ else {
+ mb = mbstate_t();
+ bb = lc->negative_sign;
+ j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
if (j == size_t(-1))
- __throw_runtime_error("locale not supported");
- wchar_t* wbe = wbuf + j;
- __curr_symbol_.assign(wbuf, wbe);
- if (lc->int_frac_digits != CHAR_MAX)
- __frac_digits_ = lc->int_frac_digits;
- else
- __frac_digits_ = base::do_frac_digits();
-#if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
- if (lc->p_sign_posn == 0)
-#else // _LIBCPP_MSVCRT
- if (lc->int_p_sign_posn == 0)
-#endif // !_LIBCPP_MSVCRT
- __positive_sign_ = L"()";
- else
- {
- mb = mbstate_t();
- bb = lc->positive_sign;
- j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
- if (j == size_t(-1))
- __throw_runtime_error("locale not supported");
- wbe = wbuf + j;
- __positive_sign_.assign(wbuf, wbe);
- }
-#if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
- if (lc->n_sign_posn == 0)
-#else // _LIBCPP_MSVCRT
- if (lc->int_n_sign_posn == 0)
-#endif // !_LIBCPP_MSVCRT
- __negative_sign_ = L"()";
- else
- {
- mb = mbstate_t();
- bb = lc->negative_sign;
- j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
- if (j == size_t(-1))
- __throw_runtime_error("locale not supported");
- wbe = wbuf + j;
- __negative_sign_.assign(wbuf, wbe);
- }
- // Assume the positive and negative formats will want spaces in
- // the same places in curr_symbol since there's no way to
- // represent anything else.
- string_type __dummy_curr_symbol = __curr_symbol_;
-#if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
- __init_pat(__pos_format_, __dummy_curr_symbol, true,
- lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn, L' ');
- __init_pat(__neg_format_, __curr_symbol_, true,
- lc->n_cs_precedes, lc->n_sep_by_space, lc->n_sign_posn, L' ');
-#else // _LIBCPP_MSVCRT
- __init_pat(__pos_format_, __dummy_curr_symbol, true,
- lc->int_p_cs_precedes, lc->int_p_sep_by_space,
- lc->int_p_sign_posn, L' ');
- __init_pat(__neg_format_, __curr_symbol_, true,
- lc->int_n_cs_precedes, lc->int_n_sep_by_space,
- lc->int_n_sign_posn, L' ');
-#endif // !_LIBCPP_MSVCRT
+ __throw_runtime_error("locale not supported");
+ wbe = wbuf + j;
+ __negative_sign_.assign(wbuf, wbe);
+ }
+ // Assume the positive and negative formats will want spaces in
+ // the same places in curr_symbol since there's no way to
+ // represent anything else.
+ string_type __dummy_curr_symbol = __curr_symbol_;
+ __init_pat(__pos_format_, __dummy_curr_symbol, false, lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn, L' ');
+ __init_pat(__neg_format_, __curr_symbol_, false, lc->n_cs_precedes, lc->n_sep_by_space, lc->n_sign_posn, L' ');
}
-void __do_nothing(void*) {}
+template <>
+void 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)).c_str());
+
+ lconv* lc = __libcpp_localeconv_l(loc.get());
+ if (!checked_string_to_wchar_convert(__decimal_point_, lc->mon_decimal_point, loc.get()))
+ __decimal_point_ = base::do_decimal_point();
+ if (!checked_string_to_wchar_convert(__thousands_sep_, lc->mon_thousands_sep, loc.get()))
+ __thousands_sep_ = base::do_thousands_sep();
+ __grouping_ = lc->mon_grouping;
+ wchar_t wbuf[100];
+ mbstate_t mb = {0};
+ const char* bb = lc->int_curr_symbol;
+ size_t j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
+ if (j == size_t(-1))
+ __throw_runtime_error("locale not supported");
+ wchar_t* wbe = wbuf + j;
+ __curr_symbol_.assign(wbuf, wbe);
+ if (lc->int_frac_digits != CHAR_MAX)
+ __frac_digits_ = lc->int_frac_digits;
+ else
+ __frac_digits_ = base::do_frac_digits();
+# if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
+ if (lc->p_sign_posn == 0)
+# else // _LIBCPP_MSVCRT
+ if (lc->int_p_sign_posn == 0)
+# endif // !_LIBCPP_MSVCRT
+ __positive_sign_ = L"()";
+ else {
+ mb = mbstate_t();
+ bb = lc->positive_sign;
+ j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
+ if (j == size_t(-1))
+ __throw_runtime_error("locale not supported");
+ wbe = wbuf + j;
+ __positive_sign_.assign(wbuf, wbe);
+ }
+# if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
+ if (lc->n_sign_posn == 0)
+# else // _LIBCPP_MSVCRT
+ if (lc->int_n_sign_posn == 0)
+# endif // !_LIBCPP_MSVCRT
+ __negative_sign_ = L"()";
+ else {
+ mb = mbstate_t();
+ bb = lc->negative_sign;
+ j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
+ if (j == size_t(-1))
+ __throw_runtime_error("locale not supported");
+ wbe = wbuf + j;
+ __negative_sign_.assign(wbuf, wbe);
+ }
+ // Assume the positive and negative formats will want spaces in
+ // the same places in curr_symbol since there's no way to
+ // represent anything else.
+ string_type __dummy_curr_symbol = __curr_symbol_;
+# if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
+ __init_pat(__pos_format_, __dummy_curr_symbol, true, lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn, L' ');
+ __init_pat(__neg_format_, __curr_symbol_, true, lc->n_cs_precedes, lc->n_sep_by_space, lc->n_sign_posn, L' ');
+# else // _LIBCPP_MSVCRT
+ __init_pat(
+ __pos_format_,
+ __dummy_curr_symbol,
+ true,
+ lc->int_p_cs_precedes,
+ lc->int_p_sep_by_space,
+ lc->int_p_sign_posn,
+ L' ');
+ __init_pat(
+ __neg_format_, __curr_symbol_, true, lc->int_n_cs_precedes, lc->int_n_sep_by_space, lc->int_n_sign_posn, L' ');
+# endif // !_LIBCPP_MSVCRT
+}
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
-void __throw_runtime_error(const char* msg)
-{
-#ifndef _LIBCPP_NO_EXCEPTIONS
- throw runtime_error(msg);
-#else
- (void)msg;
- _VSTD::abort();
-#endif
-}
+void __do_nothing(void*) {}
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS collate<char>;
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS collate<wchar_t>;
+_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS collate<wchar_t>;)
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS num_get<char>;
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS num_get<wchar_t>;
+_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS num_get<wchar_t>;)
template struct _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __num_get<char>;
-template struct _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __num_get<wchar_t>;
+_LIBCPP_IF_WIDE_CHARACTERS(template struct _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __num_get<wchar_t>;)
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS num_put<char>;
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS num_put<wchar_t>;
+_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS num_put<wchar_t>;)
template struct _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __num_put<char>;
-template struct _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __num_put<wchar_t>;
+_LIBCPP_IF_WIDE_CHARACTERS(template struct _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __num_put<wchar_t>;)
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_get<char>;
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_get<wchar_t>;
+_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_get<wchar_t>;)
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_get_byname<char>;
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_get_byname<wchar_t>;
+_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_get_byname<wchar_t>;)
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_put<char>;
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_put<wchar_t>;
+_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_put<wchar_t>;)
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_put_byname<char>;
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_put_byname<wchar_t>;
+_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_put_byname<wchar_t>;)
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct<char, false>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct<char, true>;
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct<wchar_t, false>;
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct<wchar_t, true>;
+_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct<wchar_t, false>;)
+_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct<wchar_t, true>;)
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct_byname<char, false>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct_byname<char, true>;
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct_byname<wchar_t, false>;
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct_byname<wchar_t, true>;
+_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct_byname<wchar_t, false>;)
+_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct_byname<wchar_t, true>;)
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS money_get<char>;
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS money_get<wchar_t>;
+_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS money_get<wchar_t>;)
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __money_get<char>;
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __money_get<wchar_t>;
+_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __money_get<wchar_t>;)
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS money_put<char>;
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS money_put<wchar_t>;
+_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS money_put<wchar_t>;)
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __money_put<char>;
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __money_put<wchar_t>;
+_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __money_put<wchar_t>;)
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS messages<char>;
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS messages<wchar_t>;
+_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS messages<wchar_t>;)
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS messages_byname<char>;
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS messages_byname<wchar_t>;
+_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS messages_byname<wchar_t>;)
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS codecvt_byname<char, char, mbstate_t>;
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS codecvt_byname<wchar_t, char, mbstate_t>;
-template class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS codecvt_byname<char16_t, char, mbstate_t>;
-template class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS codecvt_byname<char32_t, char, mbstate_t>;
-#ifndef _LIBCPP_NO_HAS_CHAR8_T
+_LIBCPP_IF_WIDE_CHARACTERS(
+ template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS codecvt_byname<wchar_t, char, mbstate_t>;)
+template class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
+ codecvt_byname<char16_t, char, mbstate_t>;
+template class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
+ codecvt_byname<char32_t, char, mbstate_t>;
+#ifndef _LIBCPP_HAS_NO_CHAR8_T
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS codecvt_byname<char16_t, char8_t, mbstate_t>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS codecvt_byname<char32_t, char8_t, mbstate_t>;
#endif
_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
diff --git a/contrib/llvm-project/libcxx/src/memory.cpp b/contrib/llvm-project/libcxx/src/memory.cpp
index 5a5894fd94e4..7a1c283d885e 100644
--- a/contrib/llvm-project/libcxx/src/memory.cpp
+++ b/contrib/llvm-project/libcxx/src/memory.cpp
@@ -1,4 +1,4 @@
-//===------------------------ memory.cpp ----------------------------------===//
+//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -6,228 +6,143 @@
//
//===----------------------------------------------------------------------===//
-#include "memory"
-#ifndef _LIBCPP_HAS_NO_THREADS
-#include "mutex"
-#include "thread"
-#if defined(__ELF__) && defined(_LIBCPP_LINK_PTHREAD_LIB)
-#pragma comment(lib, "pthread")
+#include <__config>
+#ifdef _LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS
+# define _LIBCPP_SHARED_PTR_DEFINE_LEGACY_INLINE_FUNCTIONS
#endif
-#endif
-#include "include/atomic_support.h"
-
-_LIBCPP_BEGIN_NAMESPACE_STD
-
-const allocator_arg_t allocator_arg = allocator_arg_t();
-
-bad_weak_ptr::~bad_weak_ptr() _NOEXCEPT {}
-
-const char*
-bad_weak_ptr::what() const _NOEXCEPT
-{
- return "bad_weak_ptr";
-}
-
-__shared_count::~__shared_count()
-{
-}
-
-__shared_weak_count::~__shared_weak_count()
-{
-}
-
-#if defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS)
-void
-__shared_count::__add_shared() _NOEXCEPT
-{
- __libcpp_atomic_refcount_increment(__shared_owners_);
-}
-bool
-__shared_count::__release_shared() _NOEXCEPT
-{
- if (__libcpp_atomic_refcount_decrement(__shared_owners_) == -1)
- {
- __on_zero_shared();
- return true;
- }
- return false;
-}
-
-void
-__shared_weak_count::__add_shared() _NOEXCEPT
-{
- __shared_count::__add_shared();
-}
-
-void
-__shared_weak_count::__add_weak() _NOEXCEPT
-{
- __libcpp_atomic_refcount_increment(__shared_weak_owners_);
-}
-
-void
-__shared_weak_count::__release_shared() _NOEXCEPT
-{
- if (__shared_count::__release_shared())
- __release_weak();
-}
-
-#endif // _LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS
-
-void
-__shared_weak_count::__release_weak() _NOEXCEPT
-{
- // NOTE: The acquire load here is an optimization of the very
- // common case where a shared pointer is being destructed while
- // having no other contended references.
- //
- // BENEFIT: We avoid expensive atomic stores like XADD and STREX
- // in a common case. Those instructions are slow and do nasty
- // things to caches.
- //
- // IS THIS SAFE? Yes. During weak destruction, if we see that we
- // are the last reference, we know that no-one else is accessing
- // us. If someone were accessing us, then they would be doing so
- // while the last shared / weak_ptr was being destructed, and
- // that's undefined anyway.
- //
- // If we see anything other than a 0, then we have possible
- // contention, and need to use an atomicrmw primitive.
- // The same arguments don't apply for increment, where it is legal
- // (though inadvisable) to share shared_ptr references between
- // threads, and have them all get copied at once. The argument
- // also doesn't apply for __release_shared, because an outstanding
- // weak_ptr::lock() could read / modify the shared count.
- if (__libcpp_atomic_load(&__shared_weak_owners_, _AO_Acquire) == 0)
- {
- // no need to do this store, because we are about
- // to destroy everything.
- //__libcpp_atomic_store(&__shared_weak_owners_, -1, _AO_Release);
- __on_zero_shared_weak();
- }
- else if (__libcpp_atomic_refcount_decrement(__shared_weak_owners_) == -1)
- __on_zero_shared_weak();
-}
+#include <memory>
-__shared_weak_count*
-__shared_weak_count::lock() _NOEXCEPT
-{
- long object_owners = __libcpp_atomic_load(&__shared_owners_);
- while (object_owners != -1)
- {
- if (__libcpp_atomic_compare_exchange(&__shared_owners_,
- &object_owners,
- object_owners+1))
- return this;
- }
- return nullptr;
-}
+#ifndef _LIBCPP_HAS_NO_THREADS
+# include <mutex>
+# include <thread>
+# if defined(__ELF__) && defined(_LIBCPP_LINK_PTHREAD_LIB)
+# pragma comment(lib, "pthread")
+# endif
+#endif
-const void*
-__shared_weak_count::__get_deleter(const type_info&) const _NOEXCEPT
-{
- return nullptr;
-}
+#include "include/atomic_support.h"
-#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
+_LIBCPP_BEGIN_NAMESPACE_STD
-_LIBCPP_SAFE_STATIC static const std::size_t __sp_mut_count = 16;
-_LIBCPP_SAFE_STATIC static __libcpp_mutex_t mut_back[__sp_mut_count] =
-{
+bad_weak_ptr::~bad_weak_ptr() noexcept {}
+
+const char* bad_weak_ptr::what() const noexcept { return "bad_weak_ptr"; }
+
+__shared_count::~__shared_count() {}
+
+__shared_weak_count::~__shared_weak_count() {}
+
+#if defined(_LIBCPP_SHARED_PTR_DEFINE_LEGACY_INLINE_FUNCTIONS)
+void __shared_count::__add_shared() noexcept { __libcpp_atomic_refcount_increment(__shared_owners_); }
+
+bool __shared_count::__release_shared() noexcept {
+ if (__libcpp_atomic_refcount_decrement(__shared_owners_) == -1) {
+ __on_zero_shared();
+ return true;
+ }
+ return false;
+}
+
+void __shared_weak_count::__add_shared() noexcept { __shared_count::__add_shared(); }
+
+void __shared_weak_count::__add_weak() noexcept { __libcpp_atomic_refcount_increment(__shared_weak_owners_); }
+
+void __shared_weak_count::__release_shared() noexcept {
+ if (__shared_count::__release_shared())
+ __release_weak();
+}
+#endif // _LIBCPP_SHARED_PTR_DEFINE_LEGACY_INLINE_FUNCTIONS
+
+void __shared_weak_count::__release_weak() noexcept {
+ // NOTE: The acquire load here is an optimization of the very
+ // common case where a shared pointer is being destructed while
+ // having no other contended references.
+ //
+ // BENEFIT: We avoid expensive atomic stores like XADD and STREX
+ // in a common case. Those instructions are slow and do nasty
+ // things to caches.
+ //
+ // IS THIS SAFE? Yes. During weak destruction, if we see that we
+ // are the last reference, we know that no-one else is accessing
+ // us. If someone were accessing us, then they would be doing so
+ // while the last shared / weak_ptr was being destructed, and
+ // that's undefined anyway.
+ //
+ // If we see anything other than a 0, then we have possible
+ // contention, and need to use an atomicrmw primitive.
+ // The same arguments don't apply for increment, where it is legal
+ // (though inadvisable) to share shared_ptr references between
+ // threads, and have them all get copied at once. The argument
+ // also doesn't apply for __release_shared, because an outstanding
+ // weak_ptr::lock() could read / modify the shared count.
+ if (__libcpp_atomic_load(&__shared_weak_owners_, _AO_Acquire) == 0) {
+ // no need to do this store, because we are about
+ // to destroy everything.
+ //__libcpp_atomic_store(&__shared_weak_owners_, -1, _AO_Release);
+ __on_zero_shared_weak();
+ } else if (__libcpp_atomic_refcount_decrement(__shared_weak_owners_) == -1)
+ __on_zero_shared_weak();
+}
+
+__shared_weak_count* __shared_weak_count::lock() noexcept {
+ long object_owners = __libcpp_atomic_load(&__shared_owners_);
+ while (object_owners != -1) {
+ if (__libcpp_atomic_compare_exchange(&__shared_owners_, &object_owners, object_owners + 1))
+ return this;
+ }
+ return nullptr;
+}
+
+const void* __shared_weak_count::__get_deleter(const type_info&) const noexcept { return nullptr; }
+
+#if !defined(_LIBCPP_HAS_NO_THREADS)
+
+static constexpr std::size_t __sp_mut_count = 32;
+static constinit __libcpp_mutex_t mut_back[__sp_mut_count] = {
_LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER,
_LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER,
_LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER,
- _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER
-};
-
-_LIBCPP_CONSTEXPR __sp_mut::__sp_mut(void* p) _NOEXCEPT
- : __lx(p)
-{
-}
-
-void
-__sp_mut::lock() _NOEXCEPT
-{
- auto m = static_cast<__libcpp_mutex_t*>(__lx);
- unsigned count = 0;
- while (!__libcpp_mutex_trylock(m))
- {
- if (++count > 16)
- {
- __libcpp_mutex_lock(m);
- break;
- }
- this_thread::yield();
- }
-}
-
-void
-__sp_mut::unlock() _NOEXCEPT
-{
- __libcpp_mutex_unlock(static_cast<__libcpp_mutex_t*>(__lx));
-}
-
-__sp_mut&
-__get_sp_mut(const void* p)
-{
- static __sp_mut muts[__sp_mut_count]
- {
- &mut_back[ 0], &mut_back[ 1], &mut_back[ 2], &mut_back[ 3],
- &mut_back[ 4], &mut_back[ 5], &mut_back[ 6], &mut_back[ 7],
- &mut_back[ 8], &mut_back[ 9], &mut_back[10], &mut_back[11],
- &mut_back[12], &mut_back[13], &mut_back[14], &mut_back[15]
- };
- return muts[hash<const void*>()(p) & (__sp_mut_count-1)];
-}
-
-#endif // !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
+ _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER,
+ _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER,
+ _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER,
+ _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER,
+ _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER};
-void
-declare_reachable(void*)
-{
-}
+constexpr __sp_mut::__sp_mut(void* p) noexcept : __lx_(p) {}
-void
-declare_no_pointers(char*, size_t)
-{
+void __sp_mut::lock() noexcept {
+ auto m = static_cast<__libcpp_mutex_t*>(__lx_);
+ __libcpp_mutex_lock(m);
}
-void
-undeclare_no_pointers(char*, size_t)
-{
-}
+void __sp_mut::unlock() noexcept { __libcpp_mutex_unlock(static_cast<__libcpp_mutex_t*>(__lx_)); }
-#if !defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE)
-pointer_safety get_pointer_safety() _NOEXCEPT
-{
- return pointer_safety::relaxed;
+__sp_mut& __get_sp_mut(const void* p) {
+ static constinit __sp_mut muts[__sp_mut_count] = {
+ &mut_back[0], &mut_back[1], &mut_back[2], &mut_back[3], &mut_back[4], &mut_back[5], &mut_back[6],
+ &mut_back[7], &mut_back[8], &mut_back[9], &mut_back[10], &mut_back[11], &mut_back[12], &mut_back[13],
+ &mut_back[14], &mut_back[15], &mut_back[16], &mut_back[17], &mut_back[18], &mut_back[19], &mut_back[20],
+ &mut_back[21], &mut_back[22], &mut_back[23], &mut_back[24], &mut_back[25], &mut_back[26], &mut_back[27],
+ &mut_back[28], &mut_back[29], &mut_back[30], &mut_back[31]};
+ return muts[hash<const void*>()(p) & (__sp_mut_count - 1)];
}
-#endif
-void*
-__undeclare_reachable(void* p)
-{
- return p;
-}
+#endif // !defined(_LIBCPP_HAS_NO_THREADS)
-void*
-align(size_t alignment, size_t size, void*& ptr, size_t& space)
-{
- void* r = nullptr;
- if (size <= space)
- {
- char* p1 = static_cast<char*>(ptr);
- char* p2 = reinterpret_cast<char*>(reinterpret_cast<size_t>(p1 + (alignment - 1)) & -alignment);
- size_t d = static_cast<size_t>(p2 - p1);
- if (d <= space - size)
- {
- r = p2;
- ptr = r;
- space -= d;
- }
+void* align(size_t alignment, size_t size, void*& ptr, size_t& space) {
+ void* r = nullptr;
+ if (size <= space) {
+ char* p1 = static_cast<char*>(ptr);
+ char* p2 = reinterpret_cast<char*>(reinterpret_cast<uintptr_t>(p1 + (alignment - 1)) & -alignment);
+ size_t d = static_cast<size_t>(p2 - p1);
+ if (d <= space - size) {
+ r = p2;
+ ptr = r;
+ space -= d;
}
- return r;
+ }
+ return r;
}
_LIBCPP_END_NAMESPACE_STD
diff --git a/contrib/llvm-project/libcxx/src/memory_resource.cpp b/contrib/llvm-project/libcxx/src/memory_resource.cpp
new file mode 100644
index 000000000000..2117238e6348
--- /dev/null
+++ b/contrib/llvm-project/libcxx/src/memory_resource.cpp
@@ -0,0 +1,498 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 <memory>
+#include <memory_resource>
+
+#ifndef _LIBCPP_HAS_NO_ATOMIC_HEADER
+# include <atomic>
+#elif !defined(_LIBCPP_HAS_NO_THREADS)
+# include <mutex>
+# if defined(__ELF__) && defined(_LIBCPP_LINK_PTHREAD_LIB)
+# pragma comment(lib, "pthread")
+# endif
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+namespace pmr {
+
+// memory_resource
+
+memory_resource::~memory_resource() = default;
+
+// new_delete_resource()
+
+#ifdef _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
+static bool is_aligned_to(void* ptr, size_t align) {
+ void* p2 = ptr;
+ size_t space = 1;
+ void* result = std::align(align, 1, p2, space);
+ return (result == ptr);
+}
+#endif
+
+class _LIBCPP_EXPORTED_FROM_ABI __new_delete_memory_resource_imp : public memory_resource {
+ void* do_allocate(size_t bytes, size_t align) override {
+#ifndef _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
+ return std::__libcpp_allocate(bytes, align);
+#else
+ if (bytes == 0)
+ bytes = 1;
+ void* result = std::__libcpp_allocate(bytes, align);
+ if (!is_aligned_to(result, align)) {
+ std::__libcpp_deallocate(result, bytes, align);
+ __throw_bad_alloc();
+ }
+ return result;
+#endif
+ }
+
+ void do_deallocate(void* p, size_t bytes, size_t align) override { std::__libcpp_deallocate(p, bytes, align); }
+
+ bool do_is_equal(const memory_resource& other) const noexcept override { return &other == this; }
+};
+
+// null_memory_resource()
+
+class _LIBCPP_EXPORTED_FROM_ABI __null_memory_resource_imp : public memory_resource {
+ void* do_allocate(size_t, size_t) override { __throw_bad_alloc(); }
+ void do_deallocate(void*, size_t, size_t) override {}
+ bool do_is_equal(const memory_resource& other) const noexcept override { return &other == this; }
+};
+
+namespace {
+
+union ResourceInitHelper {
+ struct {
+ __new_delete_memory_resource_imp new_delete_res;
+ __null_memory_resource_imp null_res;
+ } resources;
+ char dummy;
+ constexpr ResourceInitHelper() : resources() {}
+ ~ResourceInitHelper() {}
+};
+
+// Pretend we're inside a system header so the compiler doesn't flag the use of the init_priority
+// attribute with a value that's reserved for the implementation (we're the implementation).
+#include "memory_resource_init_helper.h"
+
+} // end namespace
+
+memory_resource* new_delete_resource() noexcept { return &res_init.resources.new_delete_res; }
+
+memory_resource* null_memory_resource() noexcept { return &res_init.resources.null_res; }
+
+// default_memory_resource()
+
+static memory_resource* __default_memory_resource(bool set = false, memory_resource* new_res = nullptr) noexcept {
+#ifndef _LIBCPP_HAS_NO_ATOMIC_HEADER
+ static constinit atomic<memory_resource*> __res{&res_init.resources.new_delete_res};
+ if (set) {
+ new_res = new_res ? new_res : new_delete_resource();
+ // TODO: Can a weaker ordering be used?
+ return std::atomic_exchange_explicit(&__res, new_res, memory_order_acq_rel);
+ } else {
+ return std::atomic_load_explicit(&__res, memory_order_acquire);
+ }
+#elif !defined(_LIBCPP_HAS_NO_THREADS)
+ static constinit memory_resource* res = &res_init.resources.new_delete_res;
+ static mutex res_lock;
+ if (set) {
+ new_res = new_res ? new_res : new_delete_resource();
+ lock_guard<mutex> guard(res_lock);
+ memory_resource* old_res = res;
+ res = new_res;
+ return old_res;
+ } else {
+ lock_guard<mutex> guard(res_lock);
+ return res;
+ }
+#else
+ static constinit memory_resource* res = &res_init.resources.new_delete_res;
+ if (set) {
+ new_res = new_res ? new_res : new_delete_resource();
+ memory_resource* old_res = res;
+ res = new_res;
+ return old_res;
+ } else {
+ return res;
+ }
+#endif
+}
+
+memory_resource* get_default_resource() noexcept { return __default_memory_resource(); }
+
+memory_resource* set_default_resource(memory_resource* __new_res) noexcept {
+ return __default_memory_resource(true, __new_res);
+}
+
+// 23.12.5, mem.res.pool
+
+static size_t roundup(size_t count, size_t alignment) {
+ size_t mask = alignment - 1;
+ return (count + mask) & ~mask;
+}
+
+struct unsynchronized_pool_resource::__adhoc_pool::__chunk_footer {
+ __chunk_footer* __next_;
+ char* __start_;
+ size_t __align_;
+ size_t __allocation_size() { return (reinterpret_cast<char*>(this) - __start_) + sizeof(*this); }
+};
+
+void unsynchronized_pool_resource::__adhoc_pool::__release_ptr(memory_resource* upstream) {
+ while (__first_ != nullptr) {
+ __chunk_footer* next = __first_->__next_;
+ upstream->deallocate(__first_->__start_, __first_->__allocation_size(), __first_->__align_);
+ __first_ = next;
+ }
+}
+
+void* unsynchronized_pool_resource::__adhoc_pool::__do_allocate(memory_resource* upstream, size_t bytes, size_t align) {
+ const size_t footer_size = sizeof(__chunk_footer);
+ const size_t footer_align = alignof(__chunk_footer);
+
+ if (align < footer_align)
+ align = footer_align;
+
+ size_t aligned_capacity = roundup(bytes, footer_align) + footer_size;
+
+ void* result = upstream->allocate(aligned_capacity, align);
+
+ __chunk_footer* h = (__chunk_footer*)((char*)result + aligned_capacity - footer_size);
+ h->__next_ = __first_;
+ h->__start_ = (char*)result;
+ h->__align_ = align;
+ __first_ = h;
+ return result;
+}
+
+void unsynchronized_pool_resource::__adhoc_pool::__do_deallocate(
+ memory_resource* upstream, void* p, size_t bytes, size_t align) {
+ _LIBCPP_ASSERT_NON_NULL(__first_ != nullptr, "deallocating a block that was not allocated with this allocator");
+ if (__first_->__start_ == p) {
+ __chunk_footer* next = __first_->__next_;
+ upstream->deallocate(p, __first_->__allocation_size(), __first_->__align_);
+ __first_ = next;
+ } else {
+ for (__chunk_footer* h = __first_; h->__next_ != nullptr; h = h->__next_) {
+ if (h->__next_->__start_ == p) {
+ __chunk_footer* next = h->__next_->__next_;
+ upstream->deallocate(p, h->__next_->__allocation_size(), h->__next_->__align_);
+ h->__next_ = next;
+ return;
+ }
+ }
+ // The request to deallocate memory ends up being a no-op, likely resulting in a memory leak.
+ _LIBCPP_ASSERT_VALID_DEALLOCATION(false, "deallocating a block that was not allocated with this allocator");
+ }
+}
+
+class unsynchronized_pool_resource::__fixed_pool {
+ struct __chunk_footer {
+ __chunk_footer* __next_;
+ char* __start_;
+ size_t __align_;
+ size_t __allocation_size() { return (reinterpret_cast<char*>(this) - __start_) + sizeof(*this); }
+ };
+
+ struct __vacancy_header {
+ __vacancy_header* __next_vacancy_;
+ };
+
+ __chunk_footer* __first_chunk_ = nullptr;
+ __vacancy_header* __first_vacancy_ = nullptr;
+
+public:
+ explicit __fixed_pool() = default;
+
+ void __release_ptr(memory_resource* upstream) {
+ __first_vacancy_ = nullptr;
+ while (__first_chunk_ != nullptr) {
+ __chunk_footer* next = __first_chunk_->__next_;
+ upstream->deallocate(__first_chunk_->__start_, __first_chunk_->__allocation_size(), __first_chunk_->__align_);
+ __first_chunk_ = next;
+ }
+ }
+
+ void* __try_allocate_from_vacancies() {
+ if (__first_vacancy_ != nullptr) {
+ void* result = __first_vacancy_;
+ __first_vacancy_ = __first_vacancy_->__next_vacancy_;
+ return result;
+ }
+ return nullptr;
+ }
+
+ void* __allocate_in_new_chunk(memory_resource* upstream, size_t block_size, size_t chunk_size) {
+ _LIBCPP_ASSERT_INTERNAL(chunk_size % block_size == 0, "");
+ static_assert(__default_alignment >= alignof(std::max_align_t), "");
+ static_assert(__default_alignment >= alignof(__chunk_footer), "");
+ static_assert(__default_alignment >= alignof(__vacancy_header), "");
+
+ const size_t footer_size = sizeof(__chunk_footer);
+ const size_t footer_align = alignof(__chunk_footer);
+
+ size_t aligned_capacity = roundup(chunk_size, footer_align) + footer_size;
+
+ void* result = upstream->allocate(aligned_capacity, __default_alignment);
+
+ __chunk_footer* h = (__chunk_footer*)((char*)result + aligned_capacity - footer_size);
+ h->__next_ = __first_chunk_;
+ h->__start_ = (char*)result;
+ h->__align_ = __default_alignment;
+ __first_chunk_ = h;
+
+ if (chunk_size > block_size) {
+ __vacancy_header* last_vh = this->__first_vacancy_;
+ for (size_t i = block_size; i != chunk_size; i += block_size) {
+ __vacancy_header* vh = (__vacancy_header*)((char*)result + i);
+ vh->__next_vacancy_ = last_vh;
+ last_vh = vh;
+ }
+ this->__first_vacancy_ = last_vh;
+ }
+ return result;
+ }
+
+ void __evacuate(void* p) {
+ __vacancy_header* vh = (__vacancy_header*)(p);
+ vh->__next_vacancy_ = __first_vacancy_;
+ __first_vacancy_ = vh;
+ }
+
+ size_t __previous_chunk_size_in_bytes() const { return __first_chunk_ ? __first_chunk_->__allocation_size() : 0; }
+
+ static const size_t __default_alignment = alignof(max_align_t);
+};
+
+size_t unsynchronized_pool_resource::__pool_block_size(int i) const { return size_t(1) << __log2_pool_block_size(i); }
+
+int unsynchronized_pool_resource::__log2_pool_block_size(int i) const { return (i + __log2_smallest_block_size); }
+
+int unsynchronized_pool_resource::__pool_index(size_t bytes, size_t align) const {
+ if (align > alignof(std::max_align_t) || bytes > (size_t(1) << __num_fixed_pools_))
+ return __num_fixed_pools_;
+ else {
+ int i = 0;
+ bytes = (bytes > align) ? bytes : align;
+ bytes -= 1;
+ bytes >>= __log2_smallest_block_size;
+ while (bytes != 0) {
+ bytes >>= 1;
+ i += 1;
+ }
+ return i;
+ }
+}
+
+unsynchronized_pool_resource::unsynchronized_pool_resource(const pool_options& opts, memory_resource* upstream)
+ : __res_(upstream), __fixed_pools_(nullptr) {
+ size_t largest_block_size;
+ if (opts.largest_required_pool_block == 0)
+ largest_block_size = __default_largest_block_size;
+ else if (opts.largest_required_pool_block < __smallest_block_size)
+ largest_block_size = __smallest_block_size;
+ else if (opts.largest_required_pool_block > __max_largest_block_size)
+ largest_block_size = __max_largest_block_size;
+ else
+ largest_block_size = opts.largest_required_pool_block;
+
+ if (opts.max_blocks_per_chunk == 0)
+ __options_max_blocks_per_chunk_ = __max_blocks_per_chunk;
+ else if (opts.max_blocks_per_chunk < __min_blocks_per_chunk)
+ __options_max_blocks_per_chunk_ = __min_blocks_per_chunk;
+ else if (opts.max_blocks_per_chunk > __max_blocks_per_chunk)
+ __options_max_blocks_per_chunk_ = __max_blocks_per_chunk;
+ else
+ __options_max_blocks_per_chunk_ = opts.max_blocks_per_chunk;
+
+ __num_fixed_pools_ = 1;
+ size_t capacity = __smallest_block_size;
+ while (capacity < largest_block_size) {
+ capacity <<= 1;
+ __num_fixed_pools_ += 1;
+ }
+}
+
+pool_options unsynchronized_pool_resource::options() const {
+ pool_options p;
+ p.max_blocks_per_chunk = __options_max_blocks_per_chunk_;
+ p.largest_required_pool_block = __pool_block_size(__num_fixed_pools_ - 1);
+ return p;
+}
+
+void unsynchronized_pool_resource::release() {
+ __adhoc_pool_.__release_ptr(__res_);
+ if (__fixed_pools_ != nullptr) {
+ const int n = __num_fixed_pools_;
+ for (int i = 0; i < n; ++i)
+ __fixed_pools_[i].__release_ptr(__res_);
+ __res_->deallocate(__fixed_pools_, __num_fixed_pools_ * sizeof(__fixed_pool), alignof(__fixed_pool));
+ __fixed_pools_ = nullptr;
+ }
+}
+
+void* unsynchronized_pool_resource::do_allocate(size_t bytes, size_t align) {
+ // A pointer to allocated storage (6.6.4.4.1) with a size of at least bytes.
+ // The size and alignment of the allocated memory shall meet the requirements for
+ // a class derived from memory_resource (23.12).
+ // If the pool selected for a block of size bytes is unable to satisfy the memory request
+ // from its own internal data structures, it will call upstream_resource()->allocate()
+ // to obtain more memory. If bytes is larger than that which the largest pool can handle,
+ // then memory will be allocated using upstream_resource()->allocate().
+
+ int i = __pool_index(bytes, align);
+ if (i == __num_fixed_pools_)
+ return __adhoc_pool_.__do_allocate(__res_, bytes, align);
+ else {
+ if (__fixed_pools_ == nullptr) {
+ __fixed_pools_ =
+ (__fixed_pool*)__res_->allocate(__num_fixed_pools_ * sizeof(__fixed_pool), alignof(__fixed_pool));
+ __fixed_pool* first = __fixed_pools_;
+ __fixed_pool* last = __fixed_pools_ + __num_fixed_pools_;
+ for (__fixed_pool* pool = first; pool != last; ++pool)
+ ::new ((void*)pool) __fixed_pool;
+ }
+ void* result = __fixed_pools_[i].__try_allocate_from_vacancies();
+ if (result == nullptr) {
+ auto min = [](size_t a, size_t b) { return a < b ? a : b; };
+ auto max = [](size_t a, size_t b) { return a < b ? b : a; };
+
+ size_t prev_chunk_size_in_bytes = __fixed_pools_[i].__previous_chunk_size_in_bytes();
+ size_t prev_chunk_size_in_blocks = prev_chunk_size_in_bytes >> __log2_pool_block_size(i);
+
+ size_t chunk_size_in_blocks;
+
+ if (prev_chunk_size_in_blocks == 0) {
+ size_t min_blocks_per_chunk = max(__min_bytes_per_chunk >> __log2_pool_block_size(i), __min_blocks_per_chunk);
+ chunk_size_in_blocks = min_blocks_per_chunk;
+ } else {
+ static_assert(__max_bytes_per_chunk <= SIZE_MAX - (__max_bytes_per_chunk / 4), "unsigned overflow is possible");
+ chunk_size_in_blocks = prev_chunk_size_in_blocks + (prev_chunk_size_in_blocks / 4);
+ }
+
+ size_t max_blocks_per_chunk =
+ min((__max_bytes_per_chunk >> __log2_pool_block_size(i)),
+ min(__max_blocks_per_chunk, __options_max_blocks_per_chunk_));
+ if (chunk_size_in_blocks > max_blocks_per_chunk)
+ chunk_size_in_blocks = max_blocks_per_chunk;
+
+ size_t block_size = __pool_block_size(i);
+
+ size_t chunk_size_in_bytes = (chunk_size_in_blocks << __log2_pool_block_size(i));
+ result = __fixed_pools_[i].__allocate_in_new_chunk(__res_, block_size, chunk_size_in_bytes);
+ }
+ return result;
+ }
+}
+
+void unsynchronized_pool_resource::do_deallocate(void* p, size_t bytes, size_t align) {
+ // Returns the memory at p to the pool. It is unspecified if,
+ // or under what circumstances, this operation will result in
+ // a call to upstream_resource()->deallocate().
+
+ int i = __pool_index(bytes, align);
+ if (i == __num_fixed_pools_)
+ return __adhoc_pool_.__do_deallocate(__res_, p, bytes, align);
+ else {
+ _LIBCPP_ASSERT_NON_NULL(
+ __fixed_pools_ != nullptr, "deallocating a block that was not allocated with this allocator");
+ __fixed_pools_[i].__evacuate(p);
+ }
+}
+
+bool synchronized_pool_resource::do_is_equal(const memory_resource& other) const noexcept { return &other == this; }
+
+// 23.12.6, mem.res.monotonic.buffer
+
+static void* align_down(size_t align, size_t size, void*& ptr, size_t& space) {
+ if (size > space)
+ return nullptr;
+
+ char* p1 = static_cast<char*>(ptr);
+ char* new_ptr = reinterpret_cast<char*>(reinterpret_cast<uintptr_t>(p1 - size) & ~(align - 1));
+
+ if (new_ptr < (p1 - space))
+ return nullptr;
+
+ ptr = new_ptr;
+ space -= p1 - new_ptr;
+
+ return ptr;
+}
+
+void* monotonic_buffer_resource::__initial_descriptor::__try_allocate_from_chunk(size_t bytes, size_t align) {
+ if (!__cur_)
+ return nullptr;
+ void* new_ptr = static_cast<void*>(__cur_);
+ size_t new_capacity = (__cur_ - __start_);
+ void* aligned_ptr = align_down(align, bytes, new_ptr, new_capacity);
+ if (aligned_ptr != nullptr)
+ __cur_ = static_cast<char*>(new_ptr);
+ return aligned_ptr;
+}
+
+void* monotonic_buffer_resource::__chunk_footer::__try_allocate_from_chunk(size_t bytes, size_t align) {
+ void* new_ptr = static_cast<void*>(__cur_);
+ size_t new_capacity = (__cur_ - __start_);
+ void* aligned_ptr = align_down(align, bytes, new_ptr, new_capacity);
+ if (aligned_ptr != nullptr)
+ __cur_ = static_cast<char*>(new_ptr);
+ return aligned_ptr;
+}
+
+void* monotonic_buffer_resource::do_allocate(size_t bytes, size_t align) {
+ const size_t footer_size = sizeof(__chunk_footer);
+ const size_t footer_align = alignof(__chunk_footer);
+
+ auto previous_allocation_size = [&]() {
+ if (__chunks_ != nullptr)
+ return __chunks_->__allocation_size();
+
+ size_t newsize = (__initial_.__start_ != nullptr) ? (__initial_.__end_ - __initial_.__start_) : __initial_.__size_;
+
+ return roundup(newsize, footer_align) + footer_size;
+ };
+
+ if (void* result = __initial_.__try_allocate_from_chunk(bytes, align))
+ return result;
+ if (__chunks_ != nullptr) {
+ if (void* result = __chunks_->__try_allocate_from_chunk(bytes, align))
+ return result;
+ }
+
+ // Allocate a brand-new chunk.
+
+ if (align < footer_align)
+ align = footer_align;
+
+ size_t aligned_capacity = roundup(bytes, footer_align) + footer_size;
+ size_t previous_capacity = previous_allocation_size();
+
+ if (aligned_capacity <= previous_capacity) {
+ size_t newsize = 2 * (previous_capacity - footer_size);
+ aligned_capacity = roundup(newsize, footer_align) + footer_size;
+ }
+
+ char* start = (char*)__res_->allocate(aligned_capacity, align);
+ auto end = start + aligned_capacity - footer_size;
+ __chunk_footer* footer = (__chunk_footer*)(end);
+ footer->__next_ = __chunks_;
+ footer->__start_ = start;
+ footer->__cur_ = end;
+ footer->__align_ = align;
+ __chunks_ = footer;
+
+ return __chunks_->__try_allocate_from_chunk(bytes, align);
+}
+
+} // namespace pmr
+
+_LIBCPP_END_NAMESPACE_STD
diff --git a/contrib/llvm-project/libcxx/src/memory_resource_init_helper.h b/contrib/llvm-project/libcxx/src/memory_resource_init_helper.h
new file mode 100644
index 000000000000..032edc12fa27
--- /dev/null
+++ b/contrib/llvm-project/libcxx/src/memory_resource_init_helper.h
@@ -0,0 +1,2 @@
+#pragma GCC system_header
+static constinit ResourceInitHelper res_init _LIBCPP_INIT_PRIORITY_MAX;
diff --git a/contrib/llvm-project/libcxx/src/mutex.cpp b/contrib/llvm-project/libcxx/src/mutex.cpp
index 27a4fd892778..2f8504d602dc 100644
--- a/contrib/llvm-project/libcxx/src/mutex.cpp
+++ b/contrib/llvm-project/libcxx/src/mutex.cpp
@@ -1,4 +1,4 @@
-//===------------------------- mutex.cpp ----------------------------------===//
+//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -6,255 +6,140 @@
//
//===----------------------------------------------------------------------===//
-#include "mutex"
-#include "limits"
-#include "system_error"
+#include <__assert>
+#include <__thread/id.h>
+#include <__utility/exception_guard.h>
+#include <limits>
+#include <mutex>
+
#include "include/atomic_support.h"
-#include "__undef_macros"
-#ifndef _LIBCPP_HAS_NO_THREADS
#if defined(__ELF__) && defined(_LIBCPP_LINK_PTHREAD_LIB)
-#pragma comment(lib, "pthread")
-#endif
+# pragma comment(lib, "pthread")
#endif
-_LIBCPP_BEGIN_NAMESPACE_STD
-#ifndef _LIBCPP_HAS_NO_THREADS
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
-const defer_lock_t defer_lock{};
-const try_to_lock_t try_to_lock{};
-const adopt_lock_t adopt_lock{};
+_LIBCPP_BEGIN_NAMESPACE_STD
// ~mutex is defined elsewhere
-void
-mutex::lock()
-{
- int ec = __libcpp_mutex_lock(&__m_);
- if (ec)
- __throw_system_error(ec, "mutex lock failed");
+void mutex::lock() {
+ int ec = __libcpp_mutex_lock(&__m_);
+ if (ec)
+ __throw_system_error(ec, "mutex lock failed");
}
-bool
-mutex::try_lock() _NOEXCEPT
-{
- return __libcpp_mutex_trylock(&__m_);
-}
+bool mutex::try_lock() noexcept { return __libcpp_mutex_trylock(&__m_); }
-void
-mutex::unlock() _NOEXCEPT
-{
- int ec = __libcpp_mutex_unlock(&__m_);
- (void)ec;
- _LIBCPP_ASSERT(ec == 0, "call to mutex::unlock failed");
+void mutex::unlock() noexcept {
+ int ec = __libcpp_mutex_unlock(&__m_);
+ (void)ec;
+ _LIBCPP_ASSERT_VALID_EXTERNAL_API_CALL(
+ ec == 0, "call to mutex::unlock failed. A possible reason is that the mutex wasn't locked");
}
// recursive_mutex
-recursive_mutex::recursive_mutex()
-{
- int ec = __libcpp_recursive_mutex_init(&__m_);
- if (ec)
- __throw_system_error(ec, "recursive_mutex constructor failed");
+recursive_mutex::recursive_mutex() {
+ int ec = __libcpp_recursive_mutex_init(&__m_);
+ if (ec)
+ __throw_system_error(ec, "recursive_mutex constructor failed");
}
-recursive_mutex::~recursive_mutex()
-{
- int e = __libcpp_recursive_mutex_destroy(&__m_);
- (void)e;
- _LIBCPP_ASSERT(e == 0, "call to ~recursive_mutex() failed");
+recursive_mutex::~recursive_mutex() {
+ int e = __libcpp_recursive_mutex_destroy(&__m_);
+ (void)e;
+ _LIBCPP_ASSERT_VALID_EXTERNAL_API_CALL(e == 0, "call to ~recursive_mutex() failed");
}
-void
-recursive_mutex::lock()
-{
- int ec = __libcpp_recursive_mutex_lock(&__m_);
- if (ec)
- __throw_system_error(ec, "recursive_mutex lock failed");
+void recursive_mutex::lock() {
+ int ec = __libcpp_recursive_mutex_lock(&__m_);
+ if (ec)
+ __throw_system_error(ec, "recursive_mutex lock failed");
}
-void
-recursive_mutex::unlock() _NOEXCEPT
-{
- int e = __libcpp_recursive_mutex_unlock(&__m_);
- (void)e;
- _LIBCPP_ASSERT(e == 0, "call to recursive_mutex::unlock() failed");
+void recursive_mutex::unlock() noexcept {
+ int e = __libcpp_recursive_mutex_unlock(&__m_);
+ (void)e;
+ _LIBCPP_ASSERT_VALID_EXTERNAL_API_CALL(
+ e == 0, "call to recursive_mutex::unlock() failed. A possible reason is that the mutex wasn't locked");
}
-bool
-recursive_mutex::try_lock() _NOEXCEPT
-{
- return __libcpp_recursive_mutex_trylock(&__m_);
-}
+bool recursive_mutex::try_lock() noexcept { return __libcpp_recursive_mutex_trylock(&__m_); }
// timed_mutex
-timed_mutex::timed_mutex()
- : __locked_(false)
-{
-}
+timed_mutex::timed_mutex() : __locked_(false) {}
-timed_mutex::~timed_mutex()
-{
- lock_guard<mutex> _(__m_);
-}
+timed_mutex::~timed_mutex() { lock_guard<mutex> _(__m_); }
-void
-timed_mutex::lock()
-{
- unique_lock<mutex> lk(__m_);
- while (__locked_)
- __cv_.wait(lk);
- __locked_ = true;
+void timed_mutex::lock() {
+ unique_lock<mutex> lk(__m_);
+ while (__locked_)
+ __cv_.wait(lk);
+ __locked_ = true;
}
-bool
-timed_mutex::try_lock() _NOEXCEPT
-{
- unique_lock<mutex> lk(__m_, try_to_lock);
- if (lk.owns_lock() && !__locked_)
- {
- __locked_ = true;
- return true;
- }
- return false;
+bool timed_mutex::try_lock() noexcept {
+ unique_lock<mutex> lk(__m_, try_to_lock);
+ if (lk.owns_lock() && !__locked_) {
+ __locked_ = true;
+ return true;
+ }
+ return false;
}
-void
-timed_mutex::unlock() _NOEXCEPT
-{
- lock_guard<mutex> _(__m_);
- __locked_ = false;
- __cv_.notify_one();
+void timed_mutex::unlock() noexcept {
+ lock_guard<mutex> _(__m_);
+ __locked_ = false;
+ __cv_.notify_one();
}
// recursive_timed_mutex
-recursive_timed_mutex::recursive_timed_mutex()
- : __count_(0),
- __id_{}
-{
-}
-
-recursive_timed_mutex::~recursive_timed_mutex()
-{
- lock_guard<mutex> _(__m_);
-}
-
-void
-recursive_timed_mutex::lock()
-{
- __thread_id id = this_thread::get_id();
- unique_lock<mutex> lk(__m_);
- if (id ==__id_)
- {
- if (__count_ == numeric_limits<size_t>::max())
- __throw_system_error(EAGAIN, "recursive_timed_mutex lock limit reached");
- ++__count_;
- return;
- }
- while (__count_ != 0)
- __cv_.wait(lk);
- __count_ = 1;
+recursive_timed_mutex::recursive_timed_mutex() : __count_(0), __id_{} {}
+
+recursive_timed_mutex::~recursive_timed_mutex() { lock_guard<mutex> _(__m_); }
+
+void recursive_timed_mutex::lock() {
+ __thread_id id = this_thread::get_id();
+ unique_lock<mutex> lk(__m_);
+ if (id == __id_) {
+ if (__count_ == numeric_limits<size_t>::max())
+ __throw_system_error(EAGAIN, "recursive_timed_mutex lock limit reached");
+ ++__count_;
+ return;
+ }
+ while (__count_ != 0)
+ __cv_.wait(lk);
+ __count_ = 1;
+ __id_ = id;
+}
+
+bool recursive_timed_mutex::try_lock() noexcept {
+ __thread_id id = this_thread::get_id();
+ unique_lock<mutex> lk(__m_, try_to_lock);
+ if (lk.owns_lock() && (__count_ == 0 || id == __id_)) {
+ if (__count_ == numeric_limits<size_t>::max())
+ return false;
+ ++__count_;
__id_ = id;
+ return true;
+ }
+ return false;
}
-bool
-recursive_timed_mutex::try_lock() _NOEXCEPT
-{
- __thread_id id = this_thread::get_id();
- unique_lock<mutex> lk(__m_, try_to_lock);
- if (lk.owns_lock() && (__count_ == 0 || id == __id_))
- {
- if (__count_ == numeric_limits<size_t>::max())
- return false;
- ++__count_;
- __id_ = id;
- return true;
- }
- return false;
-}
-
-void
-recursive_timed_mutex::unlock() _NOEXCEPT
-{
- unique_lock<mutex> lk(__m_);
- if (--__count_ == 0)
- {
- __id_.__reset();
- lk.unlock();
- __cv_.notify_one();
- }
-}
-
-#endif // !_LIBCPP_HAS_NO_THREADS
-
-// If dispatch_once_f ever handles C++ exceptions, and if one can get to it
-// without illegal macros (unexpected macros not beginning with _UpperCase or
-// __lowercase), and if it stops spinning waiting threads, then call_once should
-// call into dispatch_once_f instead of here. Relevant radar this code needs to
-// keep in sync with: 7741191.
-
-#ifndef _LIBCPP_HAS_NO_THREADS
-_LIBCPP_SAFE_STATIC static __libcpp_mutex_t mut = _LIBCPP_MUTEX_INITIALIZER;
-_LIBCPP_SAFE_STATIC static __libcpp_condvar_t cv = _LIBCPP_CONDVAR_INITIALIZER;
-#endif
-
-void __call_once(volatile once_flag::_State_type& flag, void* arg,
- void (*func)(void*))
-{
-#if defined(_LIBCPP_HAS_NO_THREADS)
- if (flag == 0)
- {
-#ifndef _LIBCPP_NO_EXCEPTIONS
- try
- {
-#endif // _LIBCPP_NO_EXCEPTIONS
- flag = 1;
- func(arg);
- flag = ~once_flag::_State_type(0);
-#ifndef _LIBCPP_NO_EXCEPTIONS
- }
- catch (...)
- {
- flag = 0;
- throw;
- }
-#endif // _LIBCPP_NO_EXCEPTIONS
- }
-#else // !_LIBCPP_HAS_NO_THREADS
- __libcpp_mutex_lock(&mut);
- while (flag == 1)
- __libcpp_condvar_wait(&cv, &mut);
- if (flag == 0)
- {
-#ifndef _LIBCPP_NO_EXCEPTIONS
- try
- {
-#endif // _LIBCPP_NO_EXCEPTIONS
- __libcpp_relaxed_store(&flag, once_flag::_State_type(1));
- __libcpp_mutex_unlock(&mut);
- func(arg);
- __libcpp_mutex_lock(&mut);
- __libcpp_atomic_store(&flag, ~once_flag::_State_type(0),
- _AO_Release);
- __libcpp_mutex_unlock(&mut);
- __libcpp_condvar_broadcast(&cv);
-#ifndef _LIBCPP_NO_EXCEPTIONS
- }
- catch (...)
- {
- __libcpp_mutex_lock(&mut);
- __libcpp_relaxed_store(&flag, once_flag::_State_type(0));
- __libcpp_mutex_unlock(&mut);
- __libcpp_condvar_broadcast(&cv);
- throw;
- }
-#endif // _LIBCPP_NO_EXCEPTIONS
- }
- else
- __libcpp_mutex_unlock(&mut);
-#endif // !_LIBCPP_HAS_NO_THREADS
+void recursive_timed_mutex::unlock() noexcept {
+ unique_lock<mutex> lk(__m_);
+ if (--__count_ == 0) {
+ __id_.__reset();
+ lk.unlock();
+ __cv_.notify_one();
+ }
}
_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
diff --git a/contrib/llvm-project/libcxx/src/mutex_destructor.cpp b/contrib/llvm-project/libcxx/src/mutex_destructor.cpp
index 2038d2bbe21a..d5ac257f94d5 100644
--- a/contrib/llvm-project/libcxx/src/mutex_destructor.cpp
+++ b/contrib/llvm-project/libcxx/src/mutex_destructor.cpp
@@ -1,4 +1,4 @@
-//===--------------------- mutex_destructor.cpp ---------------------------===//
+//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -16,35 +16,27 @@
// we re-declare the entire class in this file instead of using
// _LIBCPP_BUILDING_LIBRARY to change the definition in the headers.
-#include "__config"
-#include "__threading_support"
+#include <__config>
+#include <__threading_support>
-#if !defined(_LIBCPP_HAS_NO_THREADS)
#if _LIBCPP_ABI_VERSION == 1 || !defined(_LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION)
-#define NEEDS_MUTEX_DESTRUCTOR
-#endif
+# define NEEDS_MUTEX_DESTRUCTOR
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
#ifdef NEEDS_MUTEX_DESTRUCTOR
-class _LIBCPP_TYPE_VIS mutex
-{
- __libcpp_mutex_t __m_ = _LIBCPP_MUTEX_INITIALIZER;
+class _LIBCPP_EXPORTED_FROM_ABI mutex {
+ __libcpp_mutex_t __m_ = _LIBCPP_MUTEX_INITIALIZER;
public:
- _LIBCPP_ALWAYS_INLINE _LIBCPP_INLINE_VISIBILITY
- constexpr mutex() = default;
- mutex(const mutex&) = delete;
- mutex& operator=(const mutex&) = delete;
- ~mutex() noexcept;
+ _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI constexpr mutex() = default;
+ mutex(const mutex&) = delete;
+ mutex& operator=(const mutex&) = delete;
+ ~mutex() noexcept;
};
+mutex::~mutex() noexcept { __libcpp_mutex_destroy(&__m_); }
+#endif // !NEEDS_MUTEX_DESTRUCTOR
-mutex::~mutex() _NOEXCEPT
-{
- __libcpp_mutex_destroy(&__m_);
-}
-
-#endif // !_LIBCPP_HAS_NO_THREADS
_LIBCPP_END_NAMESPACE_STD
diff --git a/contrib/llvm-project/libcxx/src/new.cpp b/contrib/llvm-project/libcxx/src/new.cpp
index 9d01330ba7d5..0869d90661dd 100644
--- a/contrib/llvm-project/libcxx/src/new.cpp
+++ b/contrib/llvm-project/libcxx/src/new.cpp
@@ -1,4 +1,4 @@
-//===--------------------------- new.cpp ----------------------------------===//
+//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -6,288 +6,220 @@
//
//===----------------------------------------------------------------------===//
-#include <stdlib.h>
-
-#include "new"
-#include "include/atomic_support.h"
-
-#if defined(_LIBCPP_ABI_MICROSOFT)
-# if !defined(_LIBCPP_ABI_VCRUNTIME)
-# include "support/runtime/new_handler_fallback.ipp"
-# endif
-#elif defined(LIBCXX_BUILDING_LIBCXXABI)
-# include <cxxabi.h>
-#elif defined(LIBCXXRT)
-# include <cxxabi.h>
-# include "support/runtime/new_handler_fallback.ipp"
-#elif defined(__GLIBCXX__)
- // nothing to do
-#else
-# include "support/runtime/new_handler_fallback.ipp"
-#endif
-
-namespace std
-{
-
-#ifndef __GLIBCXX__
-const nothrow_t nothrow{};
-#endif
-
-#ifndef LIBSTDCXX
-
-void
-__throw_bad_alloc()
-{
-#ifndef _LIBCPP_NO_EXCEPTIONS
- throw bad_alloc();
-#else
- _VSTD::abort();
-#endif
-}
+#include "include/overridable_function.h"
+#include <__memory/aligned_alloc.h>
+#include <cstddef>
+#include <cstdlib>
+#include <new>
-#endif // !LIBSTDCXX
+#if !defined(__GLIBCXX__) && !defined(_LIBCPP_ABI_VCRUNTIME)
-} // std
+// The code below is copied as-is into libc++abi's libcxxabi/src/stdlib_new_delete.cpp
+// file. The version in this file is the canonical one.
-#if !defined(__GLIBCXX__) && \
- !defined(_LIBCPP_ABI_VCRUNTIME) && \
- !defined(_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS)
+inline void __throw_bad_alloc_shim() { std::__throw_bad_alloc(); }
+# define _LIBCPP_ASSERT_SHIM(expr, str) _LIBCPP_ASSERT(expr, str)
+
+// ------------------ BEGIN COPY ------------------
// Implement all new and delete operators as weak definitions
// in this shared library, so that they can be overridden by programs
// that define non-weak copies of the functions.
-_LIBCPP_WEAK
-void *
-operator new(std::size_t size) _THROW_BAD_ALLOC
-{
- if (size == 0)
- size = 1;
- void* p;
- while ((p = ::malloc(size)) == nullptr)
- {
- // If malloc fails and there is a new_handler,
- // call it to try free up memory.
- std::new_handler nh = std::get_new_handler();
- if (nh)
- nh();
- else
-#ifndef _LIBCPP_NO_EXCEPTIONS
- throw std::bad_alloc();
-#else
- break;
-#endif
- }
- return p;
-}
-
-_LIBCPP_WEAK
-void*
-operator new(size_t size, const std::nothrow_t&) _NOEXCEPT
-{
- void* p = nullptr;
-#ifndef _LIBCPP_NO_EXCEPTIONS
- try
- {
-#endif // _LIBCPP_NO_EXCEPTIONS
- p = ::operator new(size);
-#ifndef _LIBCPP_NO_EXCEPTIONS
- }
- catch (...)
- {
- }
-#endif // _LIBCPP_NO_EXCEPTIONS
- return p;
-}
-
-_LIBCPP_WEAK
-void*
-operator new[](size_t size) _THROW_BAD_ALLOC
-{
- return ::operator new(size);
+static void* operator_new_impl(std::size_t size) {
+ if (size == 0)
+ size = 1;
+ void* p;
+ while ((p = std::malloc(size)) == nullptr) {
+ // If malloc fails and there is a new_handler,
+ // call it to try free up memory.
+ std::new_handler nh = std::get_new_handler();
+ if (nh)
+ nh();
+ else
+ break;
+ }
+ return p;
+}
+
+_LIBCPP_MAKE_OVERRIDABLE_FUNCTION_DETECTABLE _LIBCPP_WEAK void* operator new(std::size_t size) _THROW_BAD_ALLOC {
+ void* p = operator_new_impl(size);
+ if (p == nullptr)
+ __throw_bad_alloc_shim();
+ return p;
+}
+
+_LIBCPP_WEAK void* operator new(size_t size, const std::nothrow_t&) noexcept {
+# ifdef _LIBCPP_HAS_NO_EXCEPTIONS
+# if _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION
+ _LIBCPP_ASSERT_SHIM(
+ !std::__is_function_overridden(static_cast<void* (*)(std::size_t)>(&operator new)),
+ "libc++ was configured with exceptions disabled and `operator new(size_t)` has been overridden, "
+ "but `operator new(size_t, nothrow_t)` has not been overridden. This is problematic because "
+ "`operator new(size_t, nothrow_t)` must call `operator new(size_t)`, which will terminate in case "
+ "it fails to allocate, making it impossible for `operator new(size_t, nothrow_t)` to fulfill its "
+ "contract (since it should return nullptr upon failure). Please make sure you override "
+ "`operator new(size_t, nothrow_t)` as well.");
+# endif
+
+ return operator_new_impl(size);
+# else
+ void* p = nullptr;
+ try {
+ p = ::operator new(size);
+ } catch (...) {
+ }
+ return p;
+# endif
+}
+
+_LIBCPP_MAKE_OVERRIDABLE_FUNCTION_DETECTABLE _LIBCPP_WEAK void* operator new[](size_t size) _THROW_BAD_ALLOC {
+ return ::operator new(size);
+}
+
+_LIBCPP_WEAK void* operator new[](size_t size, const std::nothrow_t&) noexcept {
+# ifdef _LIBCPP_HAS_NO_EXCEPTIONS
+# if _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION
+ _LIBCPP_ASSERT_SHIM(
+ !std::__is_function_overridden(static_cast<void* (*)(std::size_t)>(&operator new[])),
+ "libc++ was configured with exceptions disabled and `operator new[](size_t)` has been overridden, "
+ "but `operator new[](size_t, nothrow_t)` has not been overridden. This is problematic because "
+ "`operator new[](size_t, nothrow_t)` must call `operator new[](size_t)`, which will terminate in case "
+ "it fails to allocate, making it impossible for `operator new[](size_t, nothrow_t)` to fulfill its "
+ "contract (since it should return nullptr upon failure). Please make sure you override "
+ "`operator new[](size_t, nothrow_t)` as well.");
+# endif
+
+ return operator_new_impl(size);
+# else
+ void* p = nullptr;
+ try {
+ p = ::operator new[](size);
+ } catch (...) {
+ }
+ return p;
+# endif
+}
+
+_LIBCPP_WEAK void operator delete(void* ptr) noexcept { std::free(ptr); }
+
+_LIBCPP_WEAK void operator delete(void* ptr, const std::nothrow_t&) noexcept { ::operator delete(ptr); }
+
+_LIBCPP_WEAK void operator delete(void* ptr, size_t) noexcept { ::operator delete(ptr); }
+
+_LIBCPP_WEAK void operator delete[](void* ptr) noexcept { ::operator delete(ptr); }
+
+_LIBCPP_WEAK void operator delete[](void* ptr, const std::nothrow_t&) noexcept { ::operator delete[](ptr); }
+
+_LIBCPP_WEAK void operator delete[](void* ptr, size_t) noexcept { ::operator delete[](ptr); }
+
+# if !defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION)
+
+static void* operator_new_aligned_impl(std::size_t size, std::align_val_t alignment) {
+ if (size == 0)
+ size = 1;
+ if (static_cast<size_t>(alignment) < sizeof(void*))
+ alignment = std::align_val_t(sizeof(void*));
+
+ // Try allocating memory. If allocation fails and there is a new_handler,
+ // call it to try free up memory, and try again until it succeeds, or until
+ // the new_handler decides to terminate.
+ void* p;
+ while ((p = std::__libcpp_aligned_alloc(static_cast<std::size_t>(alignment), size)) == nullptr) {
+ std::new_handler nh = std::get_new_handler();
+ if (nh)
+ nh();
+ else
+ break;
+ }
+ return p;
+}
+
+_LIBCPP_MAKE_OVERRIDABLE_FUNCTION_DETECTABLE _LIBCPP_WEAK void*
+operator new(std::size_t size, std::align_val_t alignment) _THROW_BAD_ALLOC {
+ void* p = operator_new_aligned_impl(size, alignment);
+ if (p == nullptr)
+ __throw_bad_alloc_shim();
+ return p;
+}
+
+_LIBCPP_WEAK void* operator new(size_t size, std::align_val_t alignment, const std::nothrow_t&) noexcept {
+# ifdef _LIBCPP_HAS_NO_EXCEPTIONS
+# if _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION
+ _LIBCPP_ASSERT_SHIM(
+ !std::__is_function_overridden(static_cast<void* (*)(std::size_t, std::align_val_t)>(&operator new)),
+ "libc++ was configured with exceptions disabled and `operator new(size_t, align_val_t)` has been overridden, "
+ "but `operator new(size_t, align_val_t, nothrow_t)` has not been overridden. This is problematic because "
+ "`operator new(size_t, align_val_t, nothrow_t)` must call `operator new(size_t, align_val_t)`, which will "
+ "terminate in case it fails to allocate, making it impossible for `operator new(size_t, align_val_t, nothrow_t)` "
+ "to fulfill its contract (since it should return nullptr upon failure). Please make sure you override "
+ "`operator new(size_t, align_val_t, nothrow_t)` as well.");
+# endif
+
+ return operator_new_aligned_impl(size, alignment);
+# else
+ void* p = nullptr;
+ try {
+ p = ::operator new(size, alignment);
+ } catch (...) {
+ }
+ return p;
+# endif
}
-_LIBCPP_WEAK
-void*
-operator new[](size_t size, const std::nothrow_t&) _NOEXCEPT
-{
- void* p = nullptr;
-#ifndef _LIBCPP_NO_EXCEPTIONS
- try
- {
-#endif // _LIBCPP_NO_EXCEPTIONS
- p = ::operator new[](size);
-#ifndef _LIBCPP_NO_EXCEPTIONS
- }
- catch (...)
- {
- }
-#endif // _LIBCPP_NO_EXCEPTIONS
- return p;
+_LIBCPP_MAKE_OVERRIDABLE_FUNCTION_DETECTABLE _LIBCPP_WEAK void*
+operator new[](size_t size, std::align_val_t alignment) _THROW_BAD_ALLOC {
+ return ::operator new(size, alignment);
}
-_LIBCPP_WEAK
-void
-operator delete(void* ptr) _NOEXCEPT
-{
- ::free(ptr);
-}
+_LIBCPP_WEAK void* operator new[](size_t size, std::align_val_t alignment, const std::nothrow_t&) noexcept {
+# ifdef _LIBCPP_HAS_NO_EXCEPTIONS
+# if _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION
+ _LIBCPP_ASSERT_SHIM(
+ !std::__is_function_overridden(static_cast<void* (*)(std::size_t, std::align_val_t)>(&operator new[])),
+ "libc++ was configured with exceptions disabled and `operator new[](size_t, align_val_t)` has been overridden, "
+ "but `operator new[](size_t, align_val_t, nothrow_t)` has not been overridden. This is problematic because "
+ "`operator new[](size_t, align_val_t, nothrow_t)` must call `operator new[](size_t, align_val_t)`, which will "
+ "terminate in case it fails to allocate, making it impossible for `operator new[](size_t, align_val_t, "
+ "nothrow_t)` to fulfill its contract (since it should return nullptr upon failure). Please make sure you "
+ "override "
+ "`operator new[](size_t, align_val_t, nothrow_t)` as well.");
+# endif
-_LIBCPP_WEAK
-void
-operator delete(void* ptr, const std::nothrow_t&) _NOEXCEPT
-{
- ::operator delete(ptr);
+ return operator_new_aligned_impl(size, alignment);
+# else
+ void* p = nullptr;
+ try {
+ p = ::operator new[](size, alignment);
+ } catch (...) {
+ }
+ return p;
+# endif
}
-_LIBCPP_WEAK
-void
-operator delete(void* ptr, size_t) _NOEXCEPT
-{
- ::operator delete(ptr);
-}
-
-_LIBCPP_WEAK
-void
-operator delete[] (void* ptr) _NOEXCEPT
-{
- ::operator delete(ptr);
-}
-
-_LIBCPP_WEAK
-void
-operator delete[] (void* ptr, const std::nothrow_t&) _NOEXCEPT
-{
- ::operator delete[](ptr);
-}
-
-_LIBCPP_WEAK
-void
-operator delete[] (void* ptr, size_t) _NOEXCEPT
-{
- ::operator delete[](ptr);
-}
-
-#if !defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION)
-
-_LIBCPP_WEAK
-void *
-operator new(std::size_t size, std::align_val_t alignment) _THROW_BAD_ALLOC
-{
- if (size == 0)
- size = 1;
- if (static_cast<size_t>(alignment) < sizeof(void*))
- alignment = std::align_val_t(sizeof(void*));
-
- // Try allocating memory. If allocation fails and there is a new_handler,
- // call it to try free up memory, and try again until it succeeds, or until
- // the new_handler decides to terminate.
- //
- // If allocation fails and there is no new_handler, we throw bad_alloc
- // (or return nullptr if exceptions are disabled).
- void* p;
- while ((p = std::__libcpp_aligned_alloc(static_cast<std::size_t>(alignment), size)) == nullptr)
- {
- std::new_handler nh = std::get_new_handler();
- if (nh)
- nh();
- else {
-#ifndef _LIBCPP_NO_EXCEPTIONS
- throw std::bad_alloc();
-#else
- break;
-#endif
- }
- }
- return p;
-}
-
-_LIBCPP_WEAK
-void*
-operator new(size_t size, std::align_val_t alignment, const std::nothrow_t&) _NOEXCEPT
-{
- void* p = nullptr;
-#ifndef _LIBCPP_NO_EXCEPTIONS
- try
- {
-#endif // _LIBCPP_NO_EXCEPTIONS
- p = ::operator new(size, alignment);
-#ifndef _LIBCPP_NO_EXCEPTIONS
- }
- catch (...)
- {
- }
-#endif // _LIBCPP_NO_EXCEPTIONS
- return p;
-}
-
-_LIBCPP_WEAK
-void*
-operator new[](size_t size, std::align_val_t alignment) _THROW_BAD_ALLOC
-{
- return ::operator new(size, alignment);
-}
-
-_LIBCPP_WEAK
-void*
-operator new[](size_t size, std::align_val_t alignment, const std::nothrow_t&) _NOEXCEPT
-{
- void* p = nullptr;
-#ifndef _LIBCPP_NO_EXCEPTIONS
- try
- {
-#endif // _LIBCPP_NO_EXCEPTIONS
- p = ::operator new[](size, alignment);
-#ifndef _LIBCPP_NO_EXCEPTIONS
- }
- catch (...)
- {
- }
-#endif // _LIBCPP_NO_EXCEPTIONS
- return p;
-}
-
-_LIBCPP_WEAK
-void
-operator delete(void* ptr, std::align_val_t) _NOEXCEPT
-{
- std::__libcpp_aligned_free(ptr);
-}
-
-_LIBCPP_WEAK
-void
-operator delete(void* ptr, std::align_val_t alignment, const std::nothrow_t&) _NOEXCEPT
-{
- ::operator delete(ptr, alignment);
-}
-
-_LIBCPP_WEAK
-void
-operator delete(void* ptr, size_t, std::align_val_t alignment) _NOEXCEPT
-{
- ::operator delete(ptr, alignment);
-}
+_LIBCPP_WEAK void operator delete(void* ptr, std::align_val_t) noexcept { std::__libcpp_aligned_free(ptr); }
-_LIBCPP_WEAK
-void
-operator delete[] (void* ptr, std::align_val_t alignment) _NOEXCEPT
-{
- ::operator delete(ptr, alignment);
+_LIBCPP_WEAK void operator delete(void* ptr, std::align_val_t alignment, const std::nothrow_t&) noexcept {
+ ::operator delete(ptr, alignment);
}
-_LIBCPP_WEAK
-void
-operator delete[] (void* ptr, std::align_val_t alignment, const std::nothrow_t&) _NOEXCEPT
-{
- ::operator delete[](ptr, alignment);
+_LIBCPP_WEAK void operator delete(void* ptr, size_t, std::align_val_t alignment) noexcept {
+ ::operator delete(ptr, alignment);
}
-_LIBCPP_WEAK
-void
-operator delete[] (void* ptr, size_t, std::align_val_t alignment) _NOEXCEPT
-{
- ::operator delete[](ptr, alignment);
+_LIBCPP_WEAK void operator delete[](void* ptr, std::align_val_t alignment) noexcept {
+ ::operator delete(ptr, alignment);
}
-#endif // !_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
-#endif // !__GLIBCXX__ && !_LIBCPP_ABI_VCRUNTIME && !_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS
+_LIBCPP_WEAK void operator delete[](void* ptr, std::align_val_t alignment, const std::nothrow_t&) noexcept {
+ ::operator delete[](ptr, alignment);
+}
+
+_LIBCPP_WEAK void operator delete[](void* ptr, size_t, std::align_val_t alignment) noexcept {
+ ::operator delete[](ptr, alignment);
+}
+
+# endif // !_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
+// ------------------ END COPY ------------------
+
+#endif // !__GLIBCXX__ && !_LIBCPP_ABI_VCRUNTIME
diff --git a/contrib/llvm-project/libcxx/src/new_handler.cpp b/contrib/llvm-project/libcxx/src/new_handler.cpp
new file mode 100644
index 000000000000..49c21d85f590
--- /dev/null
+++ b/contrib/llvm-project/libcxx/src/new_handler.cpp
@@ -0,0 +1,39 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 <new>
+
+#include "include/atomic_support.h"
+
+#if defined(_LIBCPP_ABI_MICROSOFT)
+# if !defined(_LIBCPP_ABI_VCRUNTIME)
+# define _LIBPCPP_DEFINE_NEW_HANDLER
+# endif
+#elif defined(LIBCXX_BUILDING_LIBCXXABI)
+// nothing to do, we use the one from libc++abi
+#elif defined(LIBCXXRT)
+# define _LIBPCPP_DEFINE_NEW_HANDLER
+#elif defined(__GLIBCXX__)
+// nothing to do, we use the one from libstdc++/libsupc++
+#else
+# define _LIBPCPP_DEFINE_NEW_HANDLER
+#endif
+
+#if defined(_LIBPCPP_DEFINE_NEW_HANDLER)
+
+namespace std { // purposefully not versioned
+
+static constinit std::new_handler __new_handler = nullptr;
+
+new_handler set_new_handler(new_handler handler) noexcept { return __libcpp_atomic_exchange(&__new_handler, handler); }
+
+new_handler get_new_handler() noexcept { return __libcpp_atomic_load(&__new_handler); }
+
+} // namespace std
+
+#endif // _LIBPCPP_DEFINE_NEW_HANDLER
diff --git a/contrib/llvm-project/libcxx/src/support/runtime/new_handler_fallback.ipp b/contrib/llvm-project/libcxx/src/new_helpers.cpp
index 720509394297..6560d0188ee3 100644
--- a/contrib/llvm-project/libcxx/src/support/runtime/new_handler_fallback.ipp
+++ b/contrib/llvm-project/libcxx/src/new_helpers.cpp
@@ -1,4 +1,3 @@
-// -*- C++ -*-
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
@@ -7,20 +6,25 @@
//
//===----------------------------------------------------------------------===//
-namespace std {
+#include <__verbose_abort>
+#include <new>
-_LIBCPP_SAFE_STATIC static std::new_handler __new_handler;
+namespace std { // purposefully not versioned
-new_handler
-set_new_handler(new_handler handler) _NOEXCEPT
-{
- return __libcpp_atomic_exchange(&__new_handler, handler);
-}
+#ifndef __GLIBCXX__
+const nothrow_t nothrow{};
+#endif
+
+#ifndef LIBSTDCXX
-new_handler
-get_new_handler() _NOEXCEPT
-{
- return __libcpp_atomic_load(&__new_handler);
+void __throw_bad_alloc() {
+# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
+ throw bad_alloc();
+# else
+ _LIBCPP_VERBOSE_ABORT("bad_alloc was thrown in -fno-exceptions mode");
+# endif
}
+#endif // !LIBSTDCXX
+
} // namespace std
diff --git a/contrib/llvm-project/libcxx/src/optional.cpp b/contrib/llvm-project/libcxx/src/optional.cpp
index 86d013b3504f..6ba63f2d89f5 100644
--- a/contrib/llvm-project/libcxx/src/optional.cpp
+++ b/contrib/llvm-project/libcxx/src/optional.cpp
@@ -1,4 +1,4 @@
-//===------------------------ optional.cpp --------------------------------===//
+//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -6,20 +6,17 @@
//
//===----------------------------------------------------------------------===//
-#include "optional"
-#include "__availability"
-
-namespace std
-{
+#include <__availability>
+#include <optional>
+#include <stdexcept>
-bad_optional_access::~bad_optional_access() _NOEXCEPT = default;
+namespace std {
-const char* bad_optional_access::what() const _NOEXCEPT {
- return "bad_optional_access";
- }
+bad_optional_access::~bad_optional_access() noexcept = default;
-} // std
+const char* bad_optional_access::what() const noexcept { return "bad_optional_access"; }
+} // namespace std
#include <experimental/__config>
@@ -27,16 +24,14 @@ const char* bad_optional_access::what() const _NOEXCEPT {
// Even though it no longer exists in a header file
_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL
-class _LIBCPP_EXCEPTION_ABI _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS bad_optional_access
- : public std::logic_error
-{
+class _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS bad_optional_access : public std::logic_error {
public:
- bad_optional_access() : std::logic_error("Bad optional Access") {}
+ bad_optional_access() : std::logic_error("Bad optional Access") {}
-// Get the key function ~bad_optional_access() into the dylib
- virtual ~bad_optional_access() _NOEXCEPT;
+ // Get the key function ~bad_optional_access() into the dylib
+ virtual ~bad_optional_access() noexcept;
};
-bad_optional_access::~bad_optional_access() _NOEXCEPT = default;
+bad_optional_access::~bad_optional_access() noexcept = default;
_LIBCPP_END_NAMESPACE_EXPERIMENTAL
diff --git a/contrib/llvm-project/libcxx/src/ostream.cpp b/contrib/llvm-project/libcxx/src/ostream.cpp
new file mode 100644
index 000000000000..443dce9a390b
--- /dev/null
+++ b/contrib/llvm-project/libcxx/src/ostream.cpp
@@ -0,0 +1,42 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 <__availability>
+#include <__config>
+#ifndef _LIBCPP_HAS_NO_FILESYSTEM
+# include <fstream>
+#endif
+#include <ostream>
+
+#include "std_stream.h"
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+_LIBCPP_EXPORTED_FROM_ABI FILE* __get_ostream_file(ostream& __os) {
+ // dynamic_cast requires RTTI, this only affects users whose vendor builds
+ // the dylib with RTTI disabled. It does not affect users who build with RTTI
+ // disabled but use a dylib where the RTTI is enabled.
+ //
+ // Returning a nullptr means the stream is not considered a terminal and the
+ // special terminal handling is not done. The terminal handling is mainly of
+ // importance on Windows.
+#ifndef _LIBCPP_HAS_NO_RTTI
+ auto* __rdbuf = __os.rdbuf();
+# ifndef _LIBCPP_HAS_NO_FILESYSTEM
+ if (auto* __buffer = dynamic_cast<filebuf*>(__rdbuf))
+ return __buffer->__file_;
+# endif
+
+ if (auto* __buffer = dynamic_cast<__stdoutbuf<char>*>(__rdbuf))
+ return __buffer->__file_;
+#endif // _LIBCPP_HAS_NO_RTTI
+
+ return nullptr;
+}
+
+_LIBCPP_END_NAMESPACE_STD
diff --git a/contrib/llvm-project/libcxx/src/print.cpp b/contrib/llvm-project/libcxx/src/print.cpp
new file mode 100644
index 000000000000..8fa59fdd097b
--- /dev/null
+++ b/contrib/llvm-project/libcxx/src/print.cpp
@@ -0,0 +1,64 @@
+//===----------------------------------------------------------------------===//
+//
+// 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>
+
+#include <cstdlib>
+#include <print>
+
+#include <__system_error/system_error.h>
+
+#include "filesystem/error.h"
+
+#if defined(_LIBCPP_WIN32API)
+# define WIN32_LEAN_AND_MEAN
+# define NOMINMAX
+# include <io.h>
+# include <windows.h>
+#elif __has_include(<unistd.h>)
+# include <unistd.h>
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if defined(_LIBCPP_WIN32API)
+
+_LIBCPP_EXPORTED_FROM_ABI bool __is_windows_terminal(FILE* __stream) {
+ // Note the Standard does this in one call, but it's unclear whether
+ // an invalid handle is allowed when calling GetConsoleMode.
+ //
+ // https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/get-osfhandle?view=msvc-170
+ // https://learn.microsoft.com/en-us/windows/console/getconsolemode
+ intptr_t __handle = _get_osfhandle(fileno(__stream));
+ if (__handle == -1)
+ return false;
+
+ unsigned long __mode;
+ return GetConsoleMode(reinterpret_cast<void*>(__handle), &__mode);
+}
+
+# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+_LIBCPP_EXPORTED_FROM_ABI void
+__write_to_windows_console([[maybe_unused]] FILE* __stream, [[maybe_unused]] wstring_view __view) {
+ // https://learn.microsoft.com/en-us/windows/console/writeconsole
+ if (WriteConsoleW(reinterpret_cast<void*>(_get_osfhandle(fileno(__stream))), // clang-format aid
+ __view.data(),
+ __view.size(),
+ nullptr,
+ nullptr) == 0) {
+ __throw_system_error(filesystem::detail::make_windows_error(GetLastError()), "failed to write formatted output");
+ }
+}
+# endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
+
+#elif __has_include(<unistd.h>) // !_LIBCPP_WIN32API
+
+_LIBCPP_EXPORTED_FROM_ABI bool __is_posix_terminal(FILE* __stream) { return isatty(fileno(__stream)); }
+#endif
+
+_LIBCPP_END_NAMESPACE_STD
diff --git a/contrib/llvm-project/libcxx/src/pstl/libdispatch.cpp b/contrib/llvm-project/libcxx/src/pstl/libdispatch.cpp
new file mode 100644
index 000000000000..52d4afbcce6e
--- /dev/null
+++ b/contrib/llvm-project/libcxx/src/pstl/libdispatch.cpp
@@ -0,0 +1,35 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 <__algorithm/min.h>
+#include <__algorithm/pstl_backends/cpu_backends/libdispatch.h>
+#include <__config>
+#include <dispatch/dispatch.h>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+namespace __par_backend::inline __libdispatch {
+
+void __dispatch_apply(size_t chunk_count, void* context, void (*func)(void* context, size_t chunk)) noexcept {
+ ::dispatch_apply_f(chunk_count, DISPATCH_APPLY_AUTO, context, func);
+}
+
+__chunk_partitions __partition_chunks(ptrdiff_t element_count) noexcept {
+ __chunk_partitions partitions;
+ partitions.__chunk_count_ = std::max<ptrdiff_t>(1, element_count / 256);
+ partitions.__chunk_size_ = element_count / partitions.__chunk_count_;
+ partitions.__first_chunk_size_ = element_count - (partitions.__chunk_count_ - 1) * partitions.__chunk_size_;
+ if (partitions.__chunk_count_ == 0 && element_count > 0)
+ partitions.__chunk_count_ = 1;
+ return partitions;
+}
+
+// NOLINTNEXTLINE(llvm-namespace-comment) // This is https://llvm.org/PR56804
+} // namespace __par_backend::inline __libdispatch
+
+_LIBCPP_END_NAMESPACE_STD
diff --git a/contrib/llvm-project/libcxx/src/random.cpp b/contrib/llvm-project/libcxx/src/random.cpp
index 29aa43b1e1e1..c7073c54da6b 100644
--- a/contrib/llvm-project/libcxx/src/random.cpp
+++ b/contrib/llvm-project/libcxx/src/random.cpp
@@ -1,4 +1,4 @@
-//===-------------------------- random.cpp --------------------------------===//
+//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -10,173 +10,155 @@
#if defined(_LIBCPP_USING_WIN32_RANDOM)
// Must be defined before including stdlib.h to enable rand_s().
-#define _CRT_RAND_S
+# define _CRT_RAND_S
#endif // defined(_LIBCPP_USING_WIN32_RANDOM)
-#include "limits"
-#include "random"
-#include "system_error"
-
-#if defined(__sun__)
-#define rename solaris_headers_are_broken
-#endif // defined(__sun__)
+#include <__system_error/system_error.h>
+#include <limits>
+#include <random>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#if defined(_LIBCPP_USING_GETENTROPY)
-#include <sys/random.h>
+# include <sys/random.h>
#elif defined(_LIBCPP_USING_DEV_RANDOM)
-#include <fcntl.h>
-#include <unistd.h>
-#if __has_include(<sys/ioctl.h>) && __has_include(<linux/random.h>)
-#include <sys/ioctl.h>
-#include <linux/random.h>
-#endif
+# include <fcntl.h>
+# include <unistd.h>
+# if __has_include(<sys/ioctl.h>) && __has_include(<linux/random.h>)
+# include <linux/random.h>
+# include <sys/ioctl.h>
+# endif
#elif defined(_LIBCPP_USING_NACL_RANDOM)
-#include <nacl/nacl_random.h>
+# include <nacl/nacl_random.h>
+#elif defined(_LIBCPP_USING_FUCHSIA_CPRNG)
+# include <zircon/syscalls.h>
#endif
-
_LIBCPP_BEGIN_NAMESPACE_STD
#if defined(_LIBCPP_USING_GETENTROPY)
-random_device::random_device(const string& __token)
-{
- if (__token != "/dev/urandom")
- __throw_system_error(ENOENT, ("random device not supported " + __token).c_str());
+random_device::random_device(const string& __token) {
+ if (__token != "/dev/urandom")
+ __throw_system_error(ENOENT, ("random device not supported " + __token).c_str());
}
-random_device::~random_device()
-{
-}
+random_device::~random_device() {}
-unsigned
-random_device::operator()()
-{
- unsigned r;
- size_t n = sizeof(r);
- int err = getentropy(&r, n);
- if (err)
- __throw_system_error(errno, "random_device getentropy failed");
- return r;
+unsigned random_device::operator()() {
+ unsigned r;
+ size_t n = sizeof(r);
+ int err = getentropy(&r, n);
+ if (err)
+ __throw_system_error(errno, "random_device getentropy failed");
+ return r;
}
#elif defined(_LIBCPP_USING_ARC4_RANDOM)
-random_device::random_device(const string& __token)
-{
- if (__token != "/dev/urandom")
- __throw_system_error(ENOENT, ("random device not supported " + __token).c_str());
-}
+random_device::random_device(const string&) {}
-random_device::~random_device()
-{
-}
+random_device::~random_device() {}
-unsigned
-random_device::operator()()
-{
- return arc4random();
-}
+unsigned random_device::operator()() { return arc4random(); }
#elif defined(_LIBCPP_USING_DEV_RANDOM)
-random_device::random_device(const string& __token)
- : __f_(open(__token.c_str(), O_RDONLY))
-{
- if (__f_ < 0)
- __throw_system_error(errno, ("random_device failed to open " + __token).c_str());
-}
-
-random_device::~random_device()
-{
- close(__f_);
-}
-
-unsigned
-random_device::operator()()
-{
- unsigned r;
- size_t n = sizeof(r);
- char* p = reinterpret_cast<char*>(&r);
- while (n > 0)
- {
- ssize_t s = read(__f_, p, n);
- if (s == 0)
- __throw_system_error(ENODATA, "random_device got EOF");
- if (s == -1)
- {
- if (errno != EINTR)
- __throw_system_error(errno, "random_device got an unexpected error");
- continue;
- }
- n -= static_cast<size_t>(s);
- p += static_cast<size_t>(s);
+random_device::random_device(const string& __token) : __f_(open(__token.c_str(), O_RDONLY)) {
+ if (__f_ < 0)
+ __throw_system_error(errno, ("random_device failed to open " + __token).c_str());
+}
+
+random_device::~random_device() { close(__f_); }
+
+unsigned random_device::operator()() {
+ unsigned r;
+ size_t n = sizeof(r);
+ char* p = reinterpret_cast<char*>(&r);
+ while (n > 0) {
+ ssize_t s = read(__f_, p, n);
+ if (s == 0)
+ __throw_system_error(ENODATA, "random_device got EOF");
+ if (s == -1) {
+ if (errno != EINTR)
+ __throw_system_error(errno, "random_device got an unexpected error");
+ continue;
}
- return r;
+ n -= static_cast<size_t>(s);
+ p += static_cast<size_t>(s);
+ }
+ return r;
}
#elif defined(_LIBCPP_USING_NACL_RANDOM)
-random_device::random_device(const string& __token)
-{
- if (__token != "/dev/urandom")
- __throw_system_error(ENOENT, ("random device not supported " + __token).c_str());
- int error = nacl_secure_random_init();
- if (error)
- __throw_system_error(error, ("random device failed to open " + __token).c_str());
+random_device::random_device(const string& __token) {
+ if (__token != "/dev/urandom")
+ __throw_system_error(ENOENT, ("random device not supported " + __token).c_str());
+ int error = nacl_secure_random_init();
+ if (error)
+ __throw_system_error(error, ("random device failed to open " + __token).c_str());
}
-random_device::~random_device()
-{
-}
+random_device::~random_device() {}
-unsigned
-random_device::operator()()
-{
- unsigned r;
- size_t n = sizeof(r);
- size_t bytes_written;
- int error = nacl_secure_random(&r, n, &bytes_written);
- if (error != 0)
- __throw_system_error(error, "random_device failed getting bytes");
- else if (bytes_written != n)
- __throw_runtime_error("random_device failed to obtain enough bytes");
- return r;
+unsigned random_device::operator()() {
+ unsigned r;
+ size_t n = sizeof(r);
+ size_t bytes_written;
+ int error = nacl_secure_random(&r, n, &bytes_written);
+ if (error != 0)
+ __throw_system_error(error, "random_device failed getting bytes");
+ else if (bytes_written != n)
+ __throw_runtime_error("random_device failed to obtain enough bytes");
+ return r;
}
#elif defined(_LIBCPP_USING_WIN32_RANDOM)
-random_device::random_device(const string& __token)
-{
- if (__token != "/dev/urandom")
- __throw_system_error(ENOENT, ("random device not supported " + __token).c_str());
+random_device::random_device(const string& __token) {
+ if (__token != "/dev/urandom")
+ __throw_system_error(ENOENT, ("random device not supported " + __token).c_str());
}
-random_device::~random_device()
-{
+random_device::~random_device() {}
+
+unsigned random_device::operator()() {
+ unsigned r;
+ errno_t err = rand_s(&r);
+ if (err)
+ __throw_system_error(err, "random_device rand_s failed.");
+ return r;
}
-unsigned
-random_device::operator()()
-{
- unsigned r;
- errno_t err = rand_s(&r);
- if (err)
- __throw_system_error(err, "random_device rand_s failed.");
- return r;
+#elif defined(_LIBCPP_USING_FUCHSIA_CPRNG)
+
+random_device::random_device(const string& __token) {
+ if (__token != "/dev/urandom")
+ __throw_system_error(ENOENT, ("random device not supported " + __token).c_str());
+}
+
+random_device::~random_device() {}
+
+unsigned random_device::operator()() {
+ // Implicitly link against the vDSO system call ABI without
+ // requiring the final link to specify -lzircon explicitly when
+ // statically linking libc++.
+# pragma comment(lib, "zircon")
+
+ // The system call cannot fail. It returns only when the bits are ready.
+ unsigned r;
+ _zx_cprng_draw(&r, sizeof(r));
+ return r;
}
#else
-#error "Random device not implemented for this architecture"
+# error "Random device not implemented for this architecture"
#endif
-double
-random_device::entropy() const _NOEXCEPT
-{
+double random_device::entropy() const noexcept {
#if defined(_LIBCPP_USING_DEV_RANDOM) && defined(RNDGETENTCNT)
int ent;
if (::ioctl(__f_, RNDGETENTCNT, &ent) < 0)
@@ -189,7 +171,7 @@ random_device::entropy() const _NOEXCEPT
return std::numeric_limits<result_type>::digits;
return ent;
-#elif defined(__OpenBSD__)
+#elif defined(_LIBCPP_USING_ARC4_RANDOM) || defined(_LIBCPP_USING_FUCHSIA_CPRNG)
return std::numeric_limits<result_type>::digits;
#else
return 0;
diff --git a/contrib/llvm-project/libcxx/src/random_shuffle.cpp b/contrib/llvm-project/libcxx/src/random_shuffle.cpp
index be2c47fa0def..3aaf71d84643 100644
--- a/contrib/llvm-project/libcxx/src/random_shuffle.cpp
+++ b/contrib/llvm-project/libcxx/src/random_shuffle.cpp
@@ -1,4 +1,4 @@
-//===----------------------- random_shuffle.cpp ---------------------------===//
+//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -6,56 +6,46 @@
//
//===----------------------------------------------------------------------===//
-#include "algorithm"
-#include "random"
+#include <algorithm>
+#include <random>
+
#ifndef _LIBCPP_HAS_NO_THREADS
-# include "mutex"
-# if defined(__ELF__) && defined(_LIBCPP_LINK_PTHREAD_LIB)
-# pragma comment(lib, "pthread")
-# endif
+# include <mutex>
+# if defined(__ELF__) && defined(_LIBCPP_LINK_PTHREAD_LIB)
+# pragma comment(lib, "pthread")
+# endif
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
#ifndef _LIBCPP_HAS_NO_THREADS
-_LIBCPP_SAFE_STATIC static __libcpp_mutex_t __rs_mut = _LIBCPP_MUTEX_INITIALIZER;
+static constinit __libcpp_mutex_t __rs_mut = _LIBCPP_MUTEX_INITIALIZER;
#endif
unsigned __rs_default::__c_ = 0;
-__rs_default::__rs_default()
-{
+__rs_default::__rs_default() {
#ifndef _LIBCPP_HAS_NO_THREADS
- __libcpp_mutex_lock(&__rs_mut);
+ __libcpp_mutex_lock(&__rs_mut);
#endif
- __c_ = 1;
+ __c_ = 1;
}
-__rs_default::__rs_default(const __rs_default&)
-{
- ++__c_;
-}
+__rs_default::__rs_default(const __rs_default&) { ++__c_; }
-__rs_default::~__rs_default()
-{
+__rs_default::~__rs_default() {
#ifndef _LIBCPP_HAS_NO_THREADS
- if (--__c_ == 0)
- __libcpp_mutex_unlock(&__rs_mut);
+ if (--__c_ == 0)
+ __libcpp_mutex_unlock(&__rs_mut);
#else
- --__c_;
+ --__c_;
#endif
}
-__rs_default::result_type
-__rs_default::operator()()
-{
- static mt19937 __rs_g;
- return __rs_g();
+__rs_default::result_type __rs_default::operator()() {
+ static mt19937 __rs_g;
+ return __rs_g();
}
-__rs_default
-__rs_get()
-{
- return __rs_default();
-}
+__rs_default __rs_get() { return __rs_default(); }
_LIBCPP_END_NAMESPACE_STD
diff --git a/contrib/llvm-project/libcxx/src/regex.cpp b/contrib/llvm-project/libcxx/src/regex.cpp
index d31e49487432..9dc0c698541c 100644
--- a/contrib/llvm-project/libcxx/src/regex.cpp
+++ b/contrib/llvm-project/libcxx/src/regex.cpp
@@ -1,4 +1,4 @@
-//===-------------------------- regex.cpp ---------------------------------===//
+//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -6,78 +6,187 @@
//
//===----------------------------------------------------------------------===//
-#include "regex"
-#include "algorithm"
-#include "iterator"
+#include <algorithm>
+#include <iterator>
+#include <regex>
_LIBCPP_BEGIN_NAMESPACE_STD
-static
-const char*
-make_error_type_string(regex_constants::error_type ecode)
-{
- switch (ecode)
- {
- case regex_constants::error_collate:
- return "The expression contained an invalid collating element name.";
- case regex_constants::error_ctype:
- return "The expression contained an invalid character class name.";
- case regex_constants::error_escape:
- return "The expression contained an invalid escaped character, or a "
- "trailing escape.";
- case regex_constants::error_backref:
- return "The expression contained an invalid back reference.";
- case regex_constants::error_brack:
- return "The expression contained mismatched [ and ].";
- case regex_constants::error_paren:
- return "The expression contained mismatched ( and ).";
- case regex_constants::error_brace:
- return "The expression contained mismatched { and }.";
- case regex_constants::error_badbrace:
- return "The expression contained an invalid range in a {} expression.";
- case regex_constants::error_range:
- return "The expression contained an invalid character range, "
- "such as [b-a] in most encodings.";
- case regex_constants::error_space:
- return "There was insufficient memory to convert the expression into "
- "a finite state machine.";
- case regex_constants::error_badrepeat:
- return "One of *?+{ was not preceded by a valid regular expression.";
- case regex_constants::error_complexity:
- return "The complexity of an attempted match against a regular "
- "expression exceeded a pre-set level.";
- case regex_constants::error_stack:
- return "There was insufficient memory to determine whether the regular "
- "expression could match the specified character sequence.";
- case regex_constants::__re_err_grammar:
- return "An invalid regex grammar has been requested.";
- case regex_constants::__re_err_empty:
- return "An empty regex is not allowed in the POSIX grammar.";
- case regex_constants::__re_err_parse:
- return "The parser did not consume the entire regular expression.";
- default:
- break;
- }
- return "Unknown error type";
+static const char* make_error_type_string(regex_constants::error_type ecode) {
+ switch (ecode) {
+ case regex_constants::error_collate:
+ return "The expression contained an invalid collating element name.";
+ case regex_constants::error_ctype:
+ return "The expression contained an invalid character class name.";
+ case regex_constants::error_escape:
+ return "The expression contained an invalid escaped character, or a "
+ "trailing escape.";
+ case regex_constants::error_backref:
+ return "The expression contained an invalid back reference.";
+ case regex_constants::error_brack:
+ return "The expression contained mismatched [ and ].";
+ case regex_constants::error_paren:
+ return "The expression contained mismatched ( and ).";
+ case regex_constants::error_brace:
+ return "The expression contained mismatched { and }.";
+ case regex_constants::error_badbrace:
+ return "The expression contained an invalid range in a {} expression.";
+ case regex_constants::error_range:
+ return "The expression contained an invalid character range, "
+ "such as [b-a] in most encodings.";
+ case regex_constants::error_space:
+ return "There was insufficient memory to convert the expression into "
+ "a finite state machine.";
+ case regex_constants::error_badrepeat:
+ return "One of *?+{ was not preceded by a valid regular expression.";
+ case regex_constants::error_complexity:
+ return "The complexity of an attempted match against a regular "
+ "expression exceeded a pre-set level.";
+ case regex_constants::error_stack:
+ return "There was insufficient memory to determine whether the regular "
+ "expression could match the specified character sequence.";
+ case regex_constants::__re_err_grammar:
+ return "An invalid regex grammar has been requested.";
+ case regex_constants::__re_err_empty:
+ return "An empty regex is not allowed in the POSIX grammar.";
+ case regex_constants::__re_err_parse:
+ return "The parser did not consume the entire regular expression.";
+ default:
+ break;
+ }
+ return "Unknown error type";
}
regex_error::regex_error(regex_constants::error_type ecode)
- : runtime_error(make_error_type_string(ecode)),
- __code_(ecode)
-{}
+ : runtime_error(make_error_type_string(ecode)), __code_(ecode) {}
regex_error::~regex_error() throw() {}
namespace {
-struct collationnames
-{
- const char* elem_;
- char char_;
+struct collationnames {
+ const char* elem_;
+ char char_;
};
-const collationnames collatenames[] =
-{
+#if defined(__MVS__) && !defined(__NATIVE_ASCII_F)
+// EBCDIC IBM-1047
+// Sorted via the EBCDIC collating sequence
+const collationnames collatenames[] = {
+ {"a", 0x81},
+ {"alert", 0x2f},
+ {"ampersand", 0x50},
+ {"apostrophe", 0x7d},
+ {"asterisk", 0x5c},
+ {"b", 0x82},
+ {"backslash", 0xe0},
+ {"backspace", 0x16},
+ {"c", 0x83},
+ {"carriage-return", 0xd},
+ {"circumflex", 0x5f},
+ {"circumflex-accent", 0x5f},
+ {"colon", 0x7a},
+ {"comma", 0x6b},
+ {"commercial-at", 0x7c},
+ {"d", 0x84},
+ {"dollar-sign", 0x5b},
+ {"e", 0x85},
+ {"eight", 0xf8},
+ {"equals-sign", 0x7e},
+ {"exclamation-mark", 0x5a},
+ {"f", 0x86},
+ {"five", 0xf5},
+ {"form-feed", 0xc},
+ {"four", 0xf4},
+ {"full-stop", 0x4b},
+ {"g", 0x87},
+ {"grave-accent", 0x79},
+ {"greater-than-sign", 0x6e},
+ {"h", 0x88},
+ {"hyphen", 0x60},
+ {"hyphen-minus", 0x60},
+ {"i", 0x89},
+ {"j", 0x91},
+ {"k", 0x92},
+ {"l", 0x93},
+ {"left-brace", 0xc0},
+ {"left-curly-bracket", 0xc0},
+ {"left-parenthesis", 0x4d},
+ {"left-square-bracket", 0xad},
+ {"less-than-sign", 0x4c},
+ {"low-line", 0x6d},
+ {"m", 0x94},
+ {"n", 0x95},
+ {"newline", 0x15},
+ {"nine", 0xf9},
+ {"number-sign", 0x7b},
+ {"o", 0x96},
+ {"one", 0xf1},
+ {"p", 0x97},
+ {"percent-sign", 0x6c},
+ {"period", 0x4b},
+ {"plus-sign", 0x4e},
+ {"q", 0x98},
+ {"question-mark", 0x6f},
+ {"quotation-mark", 0x7f},
+ {"r", 0x99},
+ {"reverse-solidus", 0xe0},
+ {"right-brace", 0xd0},
+ {"right-curly-bracket", 0xd0},
+ {"right-parenthesis", 0x5d},
+ {"right-square-bracket", 0xbd},
+ {"s", 0xa2},
+ {"semicolon", 0x5e},
+ {"seven", 0xf7},
+ {"six", 0xf6},
+ {"slash", 0x61},
+ {"solidus", 0x61},
+ {"space", 0x40},
+ {"t", 0xa3},
+ {"tab", 0x5},
+ {"three", 0xf3},
+ {"tilde", 0xa1},
+ {"two", 0xf2},
+ {"u", 0xa4},
+ {"underscore", 0x6d},
+ {"v", 0xa5},
+ {"vertical-line", 0x4f},
+ {"vertical-tab", 0xb},
+ {"w", 0xa6},
+ {"x", 0xa7},
+ {"y", 0xa8},
+ {"z", 0xa9},
+ {"zero", 0xf0},
+ {"A", 0xc1},
+ {"B", 0xc2},
+ {"C", 0xc3},
+ {"D", 0xc4},
+ {"E", 0xc5},
+ {"F", 0xc6},
+ {"G", 0xc7},
+ {"H", 0xc8},
+ {"I", 0xc9},
+ {"J", 0xd1},
+ {"K", 0xd2},
+ {"L", 0xd3},
+ {"M", 0xd4},
+ {"N", 0xd5},
+ {"NUL", 0},
+ {"O", 0xd6},
+ {"P", 0xd7},
+ {"Q", 0xd8},
+ {"R", 0xd9},
+ {"S", 0xe2},
+ {"T", 0xe3},
+ {"U", 0xe4},
+ {"V", 0xe5},
+ {"W", 0xe6},
+ {"X", 0xe7},
+ {"Y", 0xe8},
+ {"Z", 0xe9}};
+#else
+// ASCII
+const collationnames collatenames[] = {
{"A", 0x41},
{"B", 0x42},
{"C", 0x43},
@@ -188,129 +297,103 @@ const collationnames collatenames[] =
{"x", 0x78},
{"y", 0x79},
{"z", 0x7a},
- {"zero", 0x30}
-};
+ {"zero", 0x30}};
+#endif
-struct classnames
-{
- const char* elem_;
- regex_traits<char>::char_class_type mask_;
+struct classnames {
+ const char* elem_;
+ regex_traits<char>::char_class_type mask_;
};
-const classnames ClassNames[] =
-{
- {"alnum", ctype_base::alnum},
- {"alpha", ctype_base::alpha},
- {"blank", ctype_base::blank},
- {"cntrl", ctype_base::cntrl},
- {"d", ctype_base::digit},
- {"digit", ctype_base::digit},
- {"graph", ctype_base::graph},
- {"lower", ctype_base::lower},
- {"print", ctype_base::print},
- {"punct", ctype_base::punct},
- {"s", ctype_base::space},
- {"space", ctype_base::space},
- {"upper", ctype_base::upper},
- {"w", regex_traits<char>::__regex_word},
- {"xdigit", ctype_base::xdigit}
-};
+const classnames ClassNames[] = {
+ {"alnum", ctype_base::alnum},
+ {"alpha", ctype_base::alpha},
+ {"blank", ctype_base::blank},
+ {"cntrl", ctype_base::cntrl},
+ {"d", ctype_base::digit},
+ {"digit", ctype_base::digit},
+ {"graph", ctype_base::graph},
+ {"lower", ctype_base::lower},
+ {"print", ctype_base::print},
+ {"punct", ctype_base::punct},
+ {"s", ctype_base::space},
+ {"space", ctype_base::space},
+ {"upper", ctype_base::upper},
+ {"w", regex_traits<char>::__regex_word},
+ {"xdigit", ctype_base::xdigit}};
-struct use_strcmp
-{
- bool operator()(const collationnames& x, const char* y)
- {return strcmp(x.elem_, y) < 0;}
- bool operator()(const classnames& x, const char* y)
- {return strcmp(x.elem_, y) < 0;}
+struct use_strcmp {
+ bool operator()(const collationnames& x, const char* y) { return strcmp(x.elem_, y) < 0; }
+ bool operator()(const classnames& x, const char* y) { return strcmp(x.elem_, y) < 0; }
};
-}
+} // namespace
-string
-__get_collation_name(const char* s)
-{
- const collationnames* i =
- _VSTD::lower_bound(begin(collatenames), end(collatenames), s, use_strcmp());
- string r;
- if (i != end(collatenames) && strcmp(s, i->elem_) == 0)
- r = char(i->char_);
- return r;
+string __get_collation_name(const char* s) {
+ const collationnames* i = std::lower_bound(begin(collatenames), end(collatenames), s, use_strcmp());
+ string r;
+ if (i != end(collatenames) && strcmp(s, i->elem_) == 0)
+ r = char(i->char_);
+ return r;
}
-regex_traits<char>::char_class_type
-__get_classname(const char* s, bool __icase)
-{
- const classnames* i =
- _VSTD::lower_bound(begin(ClassNames), end(ClassNames), s, use_strcmp());
- regex_traits<char>::char_class_type r = 0;
- if (i != end(ClassNames) && strcmp(s, i->elem_) == 0)
- {
- r = i->mask_;
- if (r == regex_traits<char>::__regex_word)
- r |= ctype_base::alnum | ctype_base::upper | ctype_base::lower;
- else if (__icase)
- {
- if (r & (ctype_base::lower | ctype_base::upper))
- r |= ctype_base::alpha;
- }
+regex_traits<char>::char_class_type __get_classname(const char* s, bool __icase) {
+ const classnames* i = std::lower_bound(begin(ClassNames), end(ClassNames), s, use_strcmp());
+ regex_traits<char>::char_class_type r = 0;
+ if (i != end(ClassNames) && strcmp(s, i->elem_) == 0) {
+ r = i->mask_;
+ if (r == regex_traits<char>::__regex_word)
+ r |= ctype_base::alnum | ctype_base::upper | ctype_base::lower;
+ else if (__icase) {
+ if (r & (ctype_base::lower | ctype_base::upper))
+ r |= ctype_base::alpha;
}
- return r;
+ }
+ return r;
}
template <>
-void
-__match_any_but_newline<char>::__exec(__state& __s) const
-{
- if (__s.__current_ != __s.__last_)
- {
- switch (*__s.__current_)
- {
- case '\r':
- case '\n':
- __s.__do_ = __state::__reject;
- __s.__node_ = nullptr;
- break;
- default:
- __s.__do_ = __state::__accept_and_consume;
- ++__s.__current_;
- __s.__node_ = this->first();
- break;
- }
- }
- else
- {
- __s.__do_ = __state::__reject;
- __s.__node_ = nullptr;
+void __match_any_but_newline<char>::__exec(__state& __s) const {
+ if (__s.__current_ != __s.__last_) {
+ switch (*__s.__current_) {
+ case '\r':
+ case '\n':
+ __s.__do_ = __state::__reject;
+ __s.__node_ = nullptr;
+ break;
+ default:
+ __s.__do_ = __state::__accept_and_consume;
+ ++__s.__current_;
+ __s.__node_ = this->first();
+ break;
}
+ } else {
+ __s.__do_ = __state::__reject;
+ __s.__node_ = nullptr;
+ }
}
template <>
-void
-__match_any_but_newline<wchar_t>::__exec(__state& __s) const
-{
- if (__s.__current_ != __s.__last_)
- {
- switch (*__s.__current_)
- {
- case '\r':
- case '\n':
- case 0x2028:
- case 0x2029:
- __s.__do_ = __state::__reject;
- __s.__node_ = nullptr;
- break;
- default:
- __s.__do_ = __state::__accept_and_consume;
- ++__s.__current_;
- __s.__node_ = this->first();
- break;
- }
- }
- else
- {
- __s.__do_ = __state::__reject;
- __s.__node_ = nullptr;
+void __match_any_but_newline<wchar_t>::__exec(__state& __s) const {
+ if (__s.__current_ != __s.__last_) {
+ switch (*__s.__current_) {
+ case '\r':
+ case '\n':
+ case 0x2028:
+ case 0x2029:
+ __s.__do_ = __state::__reject;
+ __s.__node_ = nullptr;
+ break;
+ default:
+ __s.__do_ = __state::__accept_and_consume;
+ ++__s.__current_;
+ __s.__node_ = this->first();
+ break;
}
+ } else {
+ __s.__do_ = __state::__reject;
+ __s.__node_ = nullptr;
+ }
}
_LIBCPP_END_NAMESPACE_STD
diff --git a/contrib/llvm-project/libcxx/src/ryu/README.txt b/contrib/llvm-project/libcxx/src/ryu/README.txt
new file mode 100644
index 000000000000..e3d17469d476
--- /dev/null
+++ b/contrib/llvm-project/libcxx/src/ryu/README.txt
@@ -0,0 +1,11 @@
+The code in this directory is based on Ulf Adams's work. The upstream for the
+code is:
+
+https://github.com/ulfjack/ryu/tree/59661c3/ryu
+
+The code has been adapted by Stephan T. Lavavej of Microsoft for usage in
+std::to_chars. This code has been contributed by Microsoft for inclusion in
+libc++.
+
+The code in this directory has a different coding style than other parts to
+minimize the number of changes by both upstream sources.
diff --git a/contrib/llvm-project/libcxx/src/ryu/d2fixed.cpp b/contrib/llvm-project/libcxx/src/ryu/d2fixed.cpp
new file mode 100644
index 000000000000..4cfc39535988
--- /dev/null
+++ b/contrib/llvm-project/libcxx/src/ryu/d2fixed.cpp
@@ -0,0 +1,669 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// Copyright (c) Microsoft Corporation.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+// Copyright 2018 Ulf Adams
+// Copyright (c) Microsoft Corporation. All rights reserved.
+
+// Boost Software License - Version 1.0 - August 17th, 2003
+
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+
+// Avoid formatting to keep the changes with the original code minimal.
+// clang-format off
+
+#include <__assert>
+#include <__config>
+#include <charconv>
+#include <cstring>
+
+#include "include/ryu/common.h"
+#include "include/ryu/d2fixed.h"
+#include "include/ryu/d2fixed_full_table.h"
+#include "include/ryu/d2s.h"
+#include "include/ryu/d2s_intrinsics.h"
+#include "include/ryu/digit_table.h"
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+inline constexpr int __POW10_ADDITIONAL_BITS = 120;
+
+#ifdef _LIBCPP_INTRINSIC128
+// Returns the low 64 bits of the high 128 bits of the 256-bit product of a and b.
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __umul256_hi128_lo64(
+ const uint64_t __aHi, const uint64_t __aLo, const uint64_t __bHi, const uint64_t __bLo) {
+ uint64_t __b00Hi;
+ const uint64_t __b00Lo = __ryu_umul128(__aLo, __bLo, &__b00Hi);
+ uint64_t __b01Hi;
+ const uint64_t __b01Lo = __ryu_umul128(__aLo, __bHi, &__b01Hi);
+ uint64_t __b10Hi;
+ const uint64_t __b10Lo = __ryu_umul128(__aHi, __bLo, &__b10Hi);
+ uint64_t __b11Hi;
+ const uint64_t __b11Lo = __ryu_umul128(__aHi, __bHi, &__b11Hi);
+ (void) __b00Lo; // unused
+ (void) __b11Hi; // unused
+ const uint64_t __temp1Lo = __b10Lo + __b00Hi;
+ const uint64_t __temp1Hi = __b10Hi + (__temp1Lo < __b10Lo);
+ const uint64_t __temp2Lo = __b01Lo + __temp1Lo;
+ const uint64_t __temp2Hi = __b01Hi + (__temp2Lo < __b01Lo);
+ return __b11Lo + __temp1Hi + __temp2Hi;
+}
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint32_t __uint128_mod1e9(const uint64_t __vHi, const uint64_t __vLo) {
+ // After multiplying, we're going to shift right by 29, then truncate to uint32_t.
+ // This means that we need only 29 + 32 = 61 bits, so we can truncate to uint64_t before shifting.
+ const uint64_t __multiplied = __umul256_hi128_lo64(__vHi, __vLo, 0x89705F4136B4A597u, 0x31680A88F8953031u);
+
+ // For uint32_t truncation, see the __mod1e9() comment in d2s_intrinsics.h.
+ const uint32_t __shifted = static_cast<uint32_t>(__multiplied >> 29);
+
+ return static_cast<uint32_t>(__vLo) - 1000000000 * __shifted;
+}
+#endif // ^^^ intrinsics available ^^^
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint32_t __mulShift_mod1e9(const uint64_t __m, const uint64_t* const __mul, const int32_t __j) {
+ uint64_t __high0; // 64
+ const uint64_t __low0 = __ryu_umul128(__m, __mul[0], &__high0); // 0
+ uint64_t __high1; // 128
+ const uint64_t __low1 = __ryu_umul128(__m, __mul[1], &__high1); // 64
+ uint64_t __high2; // 192
+ const uint64_t __low2 = __ryu_umul128(__m, __mul[2], &__high2); // 128
+ const uint64_t __s0low = __low0; // 0
+ (void) __s0low; // unused
+ const uint64_t __s0high = __low1 + __high0; // 64
+ const uint32_t __c1 = __s0high < __low1;
+ const uint64_t __s1low = __low2 + __high1 + __c1; // 128
+ const uint32_t __c2 = __s1low < __low2; // __high1 + __c1 can't overflow, so compare against __low2
+ const uint64_t __s1high = __high2 + __c2; // 192
+ _LIBCPP_ASSERT_INTERNAL(__j >= 128, "");
+ _LIBCPP_ASSERT_INTERNAL(__j <= 180, "");
+#ifdef _LIBCPP_INTRINSIC128
+ const uint32_t __dist = static_cast<uint32_t>(__j - 128); // __dist: [0, 52]
+ const uint64_t __shiftedhigh = __s1high >> __dist;
+ const uint64_t __shiftedlow = __ryu_shiftright128(__s1low, __s1high, __dist);
+ return __uint128_mod1e9(__shiftedhigh, __shiftedlow);
+#else // ^^^ intrinsics available ^^^ / vvv intrinsics unavailable vvv
+ if (__j < 160) { // __j: [128, 160)
+ const uint64_t __r0 = __mod1e9(__s1high);
+ const uint64_t __r1 = __mod1e9((__r0 << 32) | (__s1low >> 32));
+ const uint64_t __r2 = ((__r1 << 32) | (__s1low & 0xffffffff));
+ return __mod1e9(__r2 >> (__j - 128));
+ } else { // __j: [160, 192)
+ const uint64_t __r0 = __mod1e9(__s1high);
+ const uint64_t __r1 = ((__r0 << 32) | (__s1low >> 32));
+ return __mod1e9(__r1 >> (__j - 160));
+ }
+#endif // ^^^ intrinsics unavailable ^^^
+}
+
+void __append_n_digits(const uint32_t __olength, uint32_t __digits, char* const __result) {
+ uint32_t __i = 0;
+ while (__digits >= 10000) {
+#ifdef __clang__ // TRANSITION, LLVM-38217
+ const uint32_t __c = __digits - 10000 * (__digits / 10000);
+#else
+ const uint32_t __c = __digits % 10000;
+#endif
+ __digits /= 10000;
+ const uint32_t __c0 = (__c % 100) << 1;
+ const uint32_t __c1 = (__c / 100) << 1;
+ std::memcpy(__result + __olength - __i - 2, __DIGIT_TABLE + __c0, 2);
+ std::memcpy(__result + __olength - __i - 4, __DIGIT_TABLE + __c1, 2);
+ __i += 4;
+ }
+ if (__digits >= 100) {
+ const uint32_t __c = (__digits % 100) << 1;
+ __digits /= 100;
+ std::memcpy(__result + __olength - __i - 2, __DIGIT_TABLE + __c, 2);
+ __i += 2;
+ }
+ if (__digits >= 10) {
+ const uint32_t __c = __digits << 1;
+ std::memcpy(__result + __olength - __i - 2, __DIGIT_TABLE + __c, 2);
+ } else {
+ __result[0] = static_cast<char>('0' + __digits);
+ }
+}
+
+_LIBCPP_HIDE_FROM_ABI inline void __append_d_digits(const uint32_t __olength, uint32_t __digits, char* const __result) {
+ uint32_t __i = 0;
+ while (__digits >= 10000) {
+#ifdef __clang__ // TRANSITION, LLVM-38217
+ const uint32_t __c = __digits - 10000 * (__digits / 10000);
+#else
+ const uint32_t __c = __digits % 10000;
+#endif
+ __digits /= 10000;
+ const uint32_t __c0 = (__c % 100) << 1;
+ const uint32_t __c1 = (__c / 100) << 1;
+ std::memcpy(__result + __olength + 1 - __i - 2, __DIGIT_TABLE + __c0, 2);
+ std::memcpy(__result + __olength + 1 - __i - 4, __DIGIT_TABLE + __c1, 2);
+ __i += 4;
+ }
+ if (__digits >= 100) {
+ const uint32_t __c = (__digits % 100) << 1;
+ __digits /= 100;
+ std::memcpy(__result + __olength + 1 - __i - 2, __DIGIT_TABLE + __c, 2);
+ __i += 2;
+ }
+ if (__digits >= 10) {
+ const uint32_t __c = __digits << 1;
+ __result[2] = __DIGIT_TABLE[__c + 1];
+ __result[1] = '.';
+ __result[0] = __DIGIT_TABLE[__c];
+ } else {
+ __result[1] = '.';
+ __result[0] = static_cast<char>('0' + __digits);
+ }
+}
+
+_LIBCPP_HIDE_FROM_ABI inline void __append_c_digits(const uint32_t __count, uint32_t __digits, char* const __result) {
+ uint32_t __i = 0;
+ for (; __i < __count - 1; __i += 2) {
+ const uint32_t __c = (__digits % 100) << 1;
+ __digits /= 100;
+ std::memcpy(__result + __count - __i - 2, __DIGIT_TABLE + __c, 2);
+ }
+ if (__i < __count) {
+ const char __c = static_cast<char>('0' + (__digits % 10));
+ __result[__count - __i - 1] = __c;
+ }
+}
+
+void __append_nine_digits(uint32_t __digits, char* const __result) {
+ if (__digits == 0) {
+ std::memset(__result, '0', 9);
+ return;
+ }
+
+ for (uint32_t __i = 0; __i < 5; __i += 4) {
+#ifdef __clang__ // TRANSITION, LLVM-38217
+ const uint32_t __c = __digits - 10000 * (__digits / 10000);
+#else
+ const uint32_t __c = __digits % 10000;
+#endif
+ __digits /= 10000;
+ const uint32_t __c0 = (__c % 100) << 1;
+ const uint32_t __c1 = (__c / 100) << 1;
+ std::memcpy(__result + 7 - __i, __DIGIT_TABLE + __c0, 2);
+ std::memcpy(__result + 5 - __i, __DIGIT_TABLE + __c1, 2);
+ }
+ __result[0] = static_cast<char>('0' + __digits);
+}
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint32_t __indexForExponent(const uint32_t __e) {
+ return (__e + 15) / 16;
+}
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint32_t __pow10BitsForIndex(const uint32_t __idx) {
+ return 16 * __idx + __POW10_ADDITIONAL_BITS;
+}
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint32_t __lengthForIndex(const uint32_t __idx) {
+ // +1 for ceil, +16 for mantissa, +8 to round up when dividing by 9
+ return (__log10Pow2(16 * static_cast<int32_t>(__idx)) + 1 + 16 + 8) / 9;
+}
+
+[[nodiscard]] to_chars_result __d2fixed_buffered_n(char* _First, char* const _Last, const double __d,
+ const uint32_t __precision) {
+ char* const _Original_first = _First;
+
+ const uint64_t __bits = __double_to_bits(__d);
+
+ // Case distinction; exit early for the easy cases.
+ if (__bits == 0) {
+ const int32_t _Total_zero_length = 1 // leading zero
+ + static_cast<int32_t>(__precision != 0) // possible decimal point
+ + static_cast<int32_t>(__precision); // zeroes after decimal point
+
+ if (_Last - _First < _Total_zero_length) {
+ return { _Last, errc::value_too_large };
+ }
+
+ *_First++ = '0';
+ if (__precision > 0) {
+ *_First++ = '.';
+ std::memset(_First, '0', __precision);
+ _First += __precision;
+ }
+ return { _First, errc{} };
+ }
+
+ // Decode __bits into mantissa and exponent.
+ const uint64_t __ieeeMantissa = __bits & ((1ull << __DOUBLE_MANTISSA_BITS) - 1);
+ const uint32_t __ieeeExponent = static_cast<uint32_t>(__bits >> __DOUBLE_MANTISSA_BITS);
+
+ int32_t __e2;
+ uint64_t __m2;
+ if (__ieeeExponent == 0) {
+ __e2 = 1 - __DOUBLE_BIAS - __DOUBLE_MANTISSA_BITS;
+ __m2 = __ieeeMantissa;
+ } else {
+ __e2 = static_cast<int32_t>(__ieeeExponent) - __DOUBLE_BIAS - __DOUBLE_MANTISSA_BITS;
+ __m2 = (1ull << __DOUBLE_MANTISSA_BITS) | __ieeeMantissa;
+ }
+
+ bool __nonzero = false;
+ if (__e2 >= -52) {
+ const uint32_t __idx = __e2 < 0 ? 0 : __indexForExponent(static_cast<uint32_t>(__e2));
+ const uint32_t __p10bits = __pow10BitsForIndex(__idx);
+ const int32_t __len = static_cast<int32_t>(__lengthForIndex(__idx));
+ for (int32_t __i = __len - 1; __i >= 0; --__i) {
+ const uint32_t __j = __p10bits - __e2;
+ // Temporary: __j is usually around 128, and by shifting a bit, we push it to 128 or above, which is
+ // a slightly faster code path in __mulShift_mod1e9. Instead, we can just increase the multipliers.
+ const uint32_t __digits = __mulShift_mod1e9(__m2 << 8, __POW10_SPLIT[__POW10_OFFSET[__idx] + __i],
+ static_cast<int32_t>(__j + 8));
+ if (__nonzero) {
+ if (_Last - _First < 9) {
+ return { _Last, errc::value_too_large };
+ }
+ __append_nine_digits(__digits, _First);
+ _First += 9;
+ } else if (__digits != 0) {
+ const uint32_t __olength = __decimalLength9(__digits);
+ if (_Last - _First < static_cast<ptrdiff_t>(__olength)) {
+ return { _Last, errc::value_too_large };
+ }
+ __append_n_digits(__olength, __digits, _First);
+ _First += __olength;
+ __nonzero = true;
+ }
+ }
+ }
+ if (!__nonzero) {
+ if (_First == _Last) {
+ return { _Last, errc::value_too_large };
+ }
+ *_First++ = '0';
+ }
+ if (__precision > 0) {
+ if (_First == _Last) {
+ return { _Last, errc::value_too_large };
+ }
+ *_First++ = '.';
+ }
+ if (__e2 < 0) {
+ const int32_t __idx = -__e2 / 16;
+ const uint32_t __blocks = __precision / 9 + 1;
+ // 0 = don't round up; 1 = round up unconditionally; 2 = round up if odd.
+ int __roundUp = 0;
+ uint32_t __i = 0;
+ if (__blocks <= __MIN_BLOCK_2[__idx]) {
+ __i = __blocks;
+ if (_Last - _First < static_cast<ptrdiff_t>(__precision)) {
+ return { _Last, errc::value_too_large };
+ }
+ std::memset(_First, '0', __precision);
+ _First += __precision;
+ } else if (__i < __MIN_BLOCK_2[__idx]) {
+ __i = __MIN_BLOCK_2[__idx];
+ if (_Last - _First < static_cast<ptrdiff_t>(9 * __i)) {
+ return { _Last, errc::value_too_large };
+ }
+ std::memset(_First, '0', 9 * __i);
+ _First += 9 * __i;
+ }
+ for (; __i < __blocks; ++__i) {
+ const int32_t __j = __ADDITIONAL_BITS_2 + (-__e2 - 16 * __idx);
+ const uint32_t __p = __POW10_OFFSET_2[__idx] + __i - __MIN_BLOCK_2[__idx];
+ if (__p >= __POW10_OFFSET_2[__idx + 1]) {
+ // If the remaining digits are all 0, then we might as well use memset.
+ // No rounding required in this case.
+ const uint32_t __fill = __precision - 9 * __i;
+ if (_Last - _First < static_cast<ptrdiff_t>(__fill)) {
+ return { _Last, errc::value_too_large };
+ }
+ std::memset(_First, '0', __fill);
+ _First += __fill;
+ break;
+ }
+ // Temporary: __j is usually around 128, and by shifting a bit, we push it to 128 or above, which is
+ // a slightly faster code path in __mulShift_mod1e9. Instead, we can just increase the multipliers.
+ uint32_t __digits = __mulShift_mod1e9(__m2 << 8, __POW10_SPLIT_2[__p], __j + 8);
+ if (__i < __blocks - 1) {
+ if (_Last - _First < 9) {
+ return { _Last, errc::value_too_large };
+ }
+ __append_nine_digits(__digits, _First);
+ _First += 9;
+ } else {
+ const uint32_t __maximum = __precision - 9 * __i;
+ uint32_t __lastDigit = 0;
+ for (uint32_t __k = 0; __k < 9 - __maximum; ++__k) {
+ __lastDigit = __digits % 10;
+ __digits /= 10;
+ }
+ if (__lastDigit != 5) {
+ __roundUp = __lastDigit > 5;
+ } else {
+ // Is m * 10^(additionalDigits + 1) / 2^(-__e2) integer?
+ const int32_t __requiredTwos = -__e2 - static_cast<int32_t>(__precision) - 1;
+ const bool __trailingZeros = __requiredTwos <= 0
+ || (__requiredTwos < 60 && __multipleOfPowerOf2(__m2, static_cast<uint32_t>(__requiredTwos)));
+ __roundUp = __trailingZeros ? 2 : 1;
+ }
+ if (__maximum > 0) {
+ if (_Last - _First < static_cast<ptrdiff_t>(__maximum)) {
+ return { _Last, errc::value_too_large };
+ }
+ __append_c_digits(__maximum, __digits, _First);
+ _First += __maximum;
+ }
+ break;
+ }
+ }
+ if (__roundUp != 0) {
+ char* _Round = _First;
+ char* _Dot = _Last;
+ while (true) {
+ if (_Round == _Original_first) {
+ _Round[0] = '1';
+ if (_Dot != _Last) {
+ _Dot[0] = '0';
+ _Dot[1] = '.';
+ }
+ if (_First == _Last) {
+ return { _Last, errc::value_too_large };
+ }
+ *_First++ = '0';
+ break;
+ }
+ --_Round;
+ const char __c = _Round[0];
+ if (__c == '.') {
+ _Dot = _Round;
+ } else if (__c == '9') {
+ _Round[0] = '0';
+ __roundUp = 1;
+ } else {
+ if (__roundUp == 1 || __c % 2 != 0) {
+ _Round[0] = __c + 1;
+ }
+ break;
+ }
+ }
+ }
+ } else {
+ if (_Last - _First < static_cast<ptrdiff_t>(__precision)) {
+ return { _Last, errc::value_too_large };
+ }
+ std::memset(_First, '0', __precision);
+ _First += __precision;
+ }
+ return { _First, errc{} };
+}
+
+[[nodiscard]] to_chars_result __d2exp_buffered_n(char* _First, char* const _Last, const double __d,
+ uint32_t __precision) {
+ char* const _Original_first = _First;
+
+ const uint64_t __bits = __double_to_bits(__d);
+
+ // Case distinction; exit early for the easy cases.
+ if (__bits == 0) {
+ const int32_t _Total_zero_length = 1 // leading zero
+ + static_cast<int32_t>(__precision != 0) // possible decimal point
+ + static_cast<int32_t>(__precision) // zeroes after decimal point
+ + 4; // "e+00"
+ if (_Last - _First < _Total_zero_length) {
+ return { _Last, errc::value_too_large };
+ }
+ *_First++ = '0';
+ if (__precision > 0) {
+ *_First++ = '.';
+ std::memset(_First, '0', __precision);
+ _First += __precision;
+ }
+ std::memcpy(_First, "e+00", 4);
+ _First += 4;
+ return { _First, errc{} };
+ }
+
+ // Decode __bits into mantissa and exponent.
+ const uint64_t __ieeeMantissa = __bits & ((1ull << __DOUBLE_MANTISSA_BITS) - 1);
+ const uint32_t __ieeeExponent = static_cast<uint32_t>(__bits >> __DOUBLE_MANTISSA_BITS);
+
+ int32_t __e2;
+ uint64_t __m2;
+ if (__ieeeExponent == 0) {
+ __e2 = 1 - __DOUBLE_BIAS - __DOUBLE_MANTISSA_BITS;
+ __m2 = __ieeeMantissa;
+ } else {
+ __e2 = static_cast<int32_t>(__ieeeExponent) - __DOUBLE_BIAS - __DOUBLE_MANTISSA_BITS;
+ __m2 = (1ull << __DOUBLE_MANTISSA_BITS) | __ieeeMantissa;
+ }
+
+ const bool __printDecimalPoint = __precision > 0;
+ ++__precision;
+ uint32_t __digits = 0;
+ uint32_t __printedDigits = 0;
+ uint32_t __availableDigits = 0;
+ int32_t __exp = 0;
+ if (__e2 >= -52) {
+ const uint32_t __idx = __e2 < 0 ? 0 : __indexForExponent(static_cast<uint32_t>(__e2));
+ const uint32_t __p10bits = __pow10BitsForIndex(__idx);
+ const int32_t __len = static_cast<int32_t>(__lengthForIndex(__idx));
+ for (int32_t __i = __len - 1; __i >= 0; --__i) {
+ const uint32_t __j = __p10bits - __e2;
+ // Temporary: __j is usually around 128, and by shifting a bit, we push it to 128 or above, which is
+ // a slightly faster code path in __mulShift_mod1e9. Instead, we can just increase the multipliers.
+ __digits = __mulShift_mod1e9(__m2 << 8, __POW10_SPLIT[__POW10_OFFSET[__idx] + __i],
+ static_cast<int32_t>(__j + 8));
+ if (__printedDigits != 0) {
+ if (__printedDigits + 9 > __precision) {
+ __availableDigits = 9;
+ break;
+ }
+ if (_Last - _First < 9) {
+ return { _Last, errc::value_too_large };
+ }
+ __append_nine_digits(__digits, _First);
+ _First += 9;
+ __printedDigits += 9;
+ } else if (__digits != 0) {
+ __availableDigits = __decimalLength9(__digits);
+ __exp = __i * 9 + static_cast<int32_t>(__availableDigits) - 1;
+ if (__availableDigits > __precision) {
+ break;
+ }
+ if (__printDecimalPoint) {
+ if (_Last - _First < static_cast<ptrdiff_t>(__availableDigits + 1)) {
+ return { _Last, errc::value_too_large };
+ }
+ __append_d_digits(__availableDigits, __digits, _First);
+ _First += __availableDigits + 1; // +1 for decimal point
+ } else {
+ if (_First == _Last) {
+ return { _Last, errc::value_too_large };
+ }
+ *_First++ = static_cast<char>('0' + __digits);
+ }
+ __printedDigits = __availableDigits;
+ __availableDigits = 0;
+ }
+ }
+ }
+
+ if (__e2 < 0 && __availableDigits == 0) {
+ const int32_t __idx = -__e2 / 16;
+ for (int32_t __i = __MIN_BLOCK_2[__idx]; __i < 200; ++__i) {
+ const int32_t __j = __ADDITIONAL_BITS_2 + (-__e2 - 16 * __idx);
+ const uint32_t __p = __POW10_OFFSET_2[__idx] + static_cast<uint32_t>(__i) - __MIN_BLOCK_2[__idx];
+ // Temporary: __j is usually around 128, and by shifting a bit, we push it to 128 or above, which is
+ // a slightly faster code path in __mulShift_mod1e9. Instead, we can just increase the multipliers.
+ __digits = (__p >= __POW10_OFFSET_2[__idx + 1]) ? 0 : __mulShift_mod1e9(__m2 << 8, __POW10_SPLIT_2[__p], __j + 8);
+ if (__printedDigits != 0) {
+ if (__printedDigits + 9 > __precision) {
+ __availableDigits = 9;
+ break;
+ }
+ if (_Last - _First < 9) {
+ return { _Last, errc::value_too_large };
+ }
+ __append_nine_digits(__digits, _First);
+ _First += 9;
+ __printedDigits += 9;
+ } else if (__digits != 0) {
+ __availableDigits = __decimalLength9(__digits);
+ __exp = -(__i + 1) * 9 + static_cast<int32_t>(__availableDigits) - 1;
+ if (__availableDigits > __precision) {
+ break;
+ }
+ if (__printDecimalPoint) {
+ if (_Last - _First < static_cast<ptrdiff_t>(__availableDigits + 1)) {
+ return { _Last, errc::value_too_large };
+ }
+ __append_d_digits(__availableDigits, __digits, _First);
+ _First += __availableDigits + 1; // +1 for decimal point
+ } else {
+ if (_First == _Last) {
+ return { _Last, errc::value_too_large };
+ }
+ *_First++ = static_cast<char>('0' + __digits);
+ }
+ __printedDigits = __availableDigits;
+ __availableDigits = 0;
+ }
+ }
+ }
+
+ const uint32_t __maximum = __precision - __printedDigits;
+ if (__availableDigits == 0) {
+ __digits = 0;
+ }
+ uint32_t __lastDigit = 0;
+ if (__availableDigits > __maximum) {
+ for (uint32_t __k = 0; __k < __availableDigits - __maximum; ++__k) {
+ __lastDigit = __digits % 10;
+ __digits /= 10;
+ }
+ }
+ // 0 = don't round up; 1 = round up unconditionally; 2 = round up if odd.
+ int __roundUp = 0;
+ if (__lastDigit != 5) {
+ __roundUp = __lastDigit > 5;
+ } else {
+ // Is m * 2^__e2 * 10^(__precision + 1 - __exp) integer?
+ // __precision was already increased by 1, so we don't need to write + 1 here.
+ const int32_t __rexp = static_cast<int32_t>(__precision) - __exp;
+ const int32_t __requiredTwos = -__e2 - __rexp;
+ bool __trailingZeros = __requiredTwos <= 0
+ || (__requiredTwos < 60 && __multipleOfPowerOf2(__m2, static_cast<uint32_t>(__requiredTwos)));
+ if (__rexp < 0) {
+ const int32_t __requiredFives = -__rexp;
+ __trailingZeros = __trailingZeros && __multipleOfPowerOf5(__m2, static_cast<uint32_t>(__requiredFives));
+ }
+ __roundUp = __trailingZeros ? 2 : 1;
+ }
+ if (__printedDigits != 0) {
+ if (_Last - _First < static_cast<ptrdiff_t>(__maximum)) {
+ return { _Last, errc::value_too_large };
+ }
+ if (__digits == 0) {
+ std::memset(_First, '0', __maximum);
+ } else {
+ __append_c_digits(__maximum, __digits, _First);
+ }
+ _First += __maximum;
+ } else {
+ if (__printDecimalPoint) {
+ if (_Last - _First < static_cast<ptrdiff_t>(__maximum + 1)) {
+ return { _Last, errc::value_too_large };
+ }
+ __append_d_digits(__maximum, __digits, _First);
+ _First += __maximum + 1; // +1 for decimal point
+ } else {
+ if (_First == _Last) {
+ return { _Last, errc::value_too_large };
+ }
+ *_First++ = static_cast<char>('0' + __digits);
+ }
+ }
+ if (__roundUp != 0) {
+ char* _Round = _First;
+ while (true) {
+ if (_Round == _Original_first) {
+ _Round[0] = '1';
+ ++__exp;
+ break;
+ }
+ --_Round;
+ const char __c = _Round[0];
+ if (__c == '.') {
+ // Keep going.
+ } else if (__c == '9') {
+ _Round[0] = '0';
+ __roundUp = 1;
+ } else {
+ if (__roundUp == 1 || __c % 2 != 0) {
+ _Round[0] = __c + 1;
+ }
+ break;
+ }
+ }
+ }
+
+ char _Sign_character;
+
+ if (__exp < 0) {
+ _Sign_character = '-';
+ __exp = -__exp;
+ } else {
+ _Sign_character = '+';
+ }
+
+ const int _Exponent_part_length = __exp >= 100
+ ? 5 // "e+NNN"
+ : 4; // "e+NN"
+
+ if (_Last - _First < _Exponent_part_length) {
+ return { _Last, errc::value_too_large };
+ }
+
+ *_First++ = 'e';
+ *_First++ = _Sign_character;
+
+ if (__exp >= 100) {
+ const int32_t __c = __exp % 10;
+ std::memcpy(_First, __DIGIT_TABLE + 2 * (__exp / 10), 2);
+ _First[2] = static_cast<char>('0' + __c);
+ _First += 3;
+ } else {
+ std::memcpy(_First, __DIGIT_TABLE + 2 * __exp, 2);
+ _First += 2;
+ }
+
+ return { _First, errc{} };
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+// clang-format on
diff --git a/contrib/llvm-project/libcxx/src/ryu/d2s.cpp b/contrib/llvm-project/libcxx/src/ryu/d2s.cpp
new file mode 100644
index 000000000000..32d617cb5532
--- /dev/null
+++ b/contrib/llvm-project/libcxx/src/ryu/d2s.cpp
@@ -0,0 +1,783 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// Copyright (c) Microsoft Corporation.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+// Copyright 2018 Ulf Adams
+// Copyright (c) Microsoft Corporation. All rights reserved.
+
+// Boost Software License - Version 1.0 - August 17th, 2003
+
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+
+// Avoid formatting to keep the changes with the original code minimal.
+// clang-format off
+
+#include <__assert>
+#include <__config>
+#include <charconv>
+
+#include "include/ryu/common.h"
+#include "include/ryu/d2fixed.h"
+#include "include/ryu/d2s.h"
+#include "include/ryu/d2s_full_table.h"
+#include "include/ryu/d2s_intrinsics.h"
+#include "include/ryu/digit_table.h"
+#include "include/ryu/ryu.h"
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+// We need a 64x128-bit multiplication and a subsequent 128-bit shift.
+// Multiplication:
+// The 64-bit factor is variable and passed in, the 128-bit factor comes
+// from a lookup table. We know that the 64-bit factor only has 55
+// significant bits (i.e., the 9 topmost bits are zeros). The 128-bit
+// factor only has 124 significant bits (i.e., the 4 topmost bits are
+// zeros).
+// Shift:
+// In principle, the multiplication result requires 55 + 124 = 179 bits to
+// represent. However, we then shift this value to the right by __j, which is
+// at least __j >= 115, so the result is guaranteed to fit into 179 - 115 = 64
+// bits. This means that we only need the topmost 64 significant bits of
+// the 64x128-bit multiplication.
+//
+// There are several ways to do this:
+// 1. Best case: the compiler exposes a 128-bit type.
+// We perform two 64x64-bit multiplications, add the higher 64 bits of the
+// lower result to the higher result, and shift by __j - 64 bits.
+//
+// We explicitly cast from 64-bit to 128-bit, so the compiler can tell
+// that these are only 64-bit inputs, and can map these to the best
+// possible sequence of assembly instructions.
+// x64 machines happen to have matching assembly instructions for
+// 64x64-bit multiplications and 128-bit shifts.
+//
+// 2. Second best case: the compiler exposes intrinsics for the x64 assembly
+// instructions mentioned in 1.
+//
+// 3. We only have 64x64 bit instructions that return the lower 64 bits of
+// the result, i.e., we have to use plain C.
+// Our inputs are less than the full width, so we have three options:
+// a. Ignore this fact and just implement the intrinsics manually.
+// b. Split both into 31-bit pieces, which guarantees no internal overflow,
+// but requires extra work upfront (unless we change the lookup table).
+// c. Split only the first factor into 31-bit pieces, which also guarantees
+// no internal overflow, but requires extra work since the intermediate
+// results are not perfectly aligned.
+#ifdef _LIBCPP_INTRINSIC128
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __mulShift(const uint64_t __m, const uint64_t* const __mul, const int32_t __j) {
+ // __m is maximum 55 bits
+ uint64_t __high1; // 128
+ const uint64_t __low1 = __ryu_umul128(__m, __mul[1], &__high1); // 64
+ uint64_t __high0; // 64
+ (void) __ryu_umul128(__m, __mul[0], &__high0); // 0
+ const uint64_t __sum = __high0 + __low1;
+ if (__sum < __high0) {
+ ++__high1; // overflow into __high1
+ }
+ return __ryu_shiftright128(__sum, __high1, static_cast<uint32_t>(__j - 64));
+}
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint64_t __mulShiftAll(const uint64_t __m, const uint64_t* const __mul, const int32_t __j,
+ uint64_t* const __vp, uint64_t* const __vm, const uint32_t __mmShift) {
+ *__vp = __mulShift(4 * __m + 2, __mul, __j);
+ *__vm = __mulShift(4 * __m - 1 - __mmShift, __mul, __j);
+ return __mulShift(4 * __m, __mul, __j);
+}
+
+#else // ^^^ intrinsics available ^^^ / vvv intrinsics unavailable vvv
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline _LIBCPP_ALWAYS_INLINE uint64_t __mulShiftAll(uint64_t __m, const uint64_t* const __mul, const int32_t __j,
+ uint64_t* const __vp, uint64_t* const __vm, const uint32_t __mmShift) { // TRANSITION, VSO-634761
+ __m <<= 1;
+ // __m is maximum 55 bits
+ uint64_t __tmp;
+ const uint64_t __lo = __ryu_umul128(__m, __mul[0], &__tmp);
+ uint64_t __hi;
+ const uint64_t __mid = __tmp + __ryu_umul128(__m, __mul[1], &__hi);
+ __hi += __mid < __tmp; // overflow into __hi
+
+ const uint64_t __lo2 = __lo + __mul[0];
+ const uint64_t __mid2 = __mid + __mul[1] + (__lo2 < __lo);
+ const uint64_t __hi2 = __hi + (__mid2 < __mid);
+ *__vp = __ryu_shiftright128(__mid2, __hi2, static_cast<uint32_t>(__j - 64 - 1));
+
+ if (__mmShift == 1) {
+ const uint64_t __lo3 = __lo - __mul[0];
+ const uint64_t __mid3 = __mid - __mul[1] - (__lo3 > __lo);
+ const uint64_t __hi3 = __hi - (__mid3 > __mid);
+ *__vm = __ryu_shiftright128(__mid3, __hi3, static_cast<uint32_t>(__j - 64 - 1));
+ } else {
+ const uint64_t __lo3 = __lo + __lo;
+ const uint64_t __mid3 = __mid + __mid + (__lo3 < __lo);
+ const uint64_t __hi3 = __hi + __hi + (__mid3 < __mid);
+ const uint64_t __lo4 = __lo3 - __mul[0];
+ const uint64_t __mid4 = __mid3 - __mul[1] - (__lo4 > __lo3);
+ const uint64_t __hi4 = __hi3 - (__mid4 > __mid3);
+ *__vm = __ryu_shiftright128(__mid4, __hi4, static_cast<uint32_t>(__j - 64));
+ }
+
+ return __ryu_shiftright128(__mid, __hi, static_cast<uint32_t>(__j - 64 - 1));
+}
+
+#endif // ^^^ intrinsics unavailable ^^^
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint32_t __decimalLength17(const uint64_t __v) {
+ // This is slightly faster than a loop.
+ // The average output length is 16.38 digits, so we check high-to-low.
+ // Function precondition: __v is not an 18, 19, or 20-digit number.
+ // (17 digits are sufficient for round-tripping.)
+ _LIBCPP_ASSERT_INTERNAL(__v < 100000000000000000u, "");
+ if (__v >= 10000000000000000u) { return 17; }
+ if (__v >= 1000000000000000u) { return 16; }
+ if (__v >= 100000000000000u) { return 15; }
+ if (__v >= 10000000000000u) { return 14; }
+ if (__v >= 1000000000000u) { return 13; }
+ if (__v >= 100000000000u) { return 12; }
+ if (__v >= 10000000000u) { return 11; }
+ if (__v >= 1000000000u) { return 10; }
+ if (__v >= 100000000u) { return 9; }
+ if (__v >= 10000000u) { return 8; }
+ if (__v >= 1000000u) { return 7; }
+ if (__v >= 100000u) { return 6; }
+ if (__v >= 10000u) { return 5; }
+ if (__v >= 1000u) { return 4; }
+ if (__v >= 100u) { return 3; }
+ if (__v >= 10u) { return 2; }
+ return 1;
+}
+
+// A floating decimal representing m * 10^e.
+struct __floating_decimal_64 {
+ uint64_t __mantissa;
+ int32_t __exponent;
+};
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline __floating_decimal_64 __d2d(const uint64_t __ieeeMantissa, const uint32_t __ieeeExponent) {
+ int32_t __e2;
+ uint64_t __m2;
+ if (__ieeeExponent == 0) {
+ // We subtract 2 so that the bounds computation has 2 additional bits.
+ __e2 = 1 - __DOUBLE_BIAS - __DOUBLE_MANTISSA_BITS - 2;
+ __m2 = __ieeeMantissa;
+ } else {
+ __e2 = static_cast<int32_t>(__ieeeExponent) - __DOUBLE_BIAS - __DOUBLE_MANTISSA_BITS - 2;
+ __m2 = (1ull << __DOUBLE_MANTISSA_BITS) | __ieeeMantissa;
+ }
+ const bool __even = (__m2 & 1) == 0;
+ const bool __acceptBounds = __even;
+
+ // Step 2: Determine the interval of valid decimal representations.
+ const uint64_t __mv = 4 * __m2;
+ // Implicit bool -> int conversion. True is 1, false is 0.
+ const uint32_t __mmShift = __ieeeMantissa != 0 || __ieeeExponent <= 1;
+ // We would compute __mp and __mm like this:
+ // uint64_t __mp = 4 * __m2 + 2;
+ // uint64_t __mm = __mv - 1 - __mmShift;
+
+ // Step 3: Convert to a decimal power base using 128-bit arithmetic.
+ uint64_t __vr, __vp, __vm;
+ int32_t __e10;
+ bool __vmIsTrailingZeros = false;
+ bool __vrIsTrailingZeros = false;
+ if (__e2 >= 0) {
+ // I tried special-casing __q == 0, but there was no effect on performance.
+ // This expression is slightly faster than max(0, __log10Pow2(__e2) - 1).
+ const uint32_t __q = __log10Pow2(__e2) - (__e2 > 3);
+ __e10 = static_cast<int32_t>(__q);
+ const int32_t __k = __DOUBLE_POW5_INV_BITCOUNT + __pow5bits(static_cast<int32_t>(__q)) - 1;
+ const int32_t __i = -__e2 + static_cast<int32_t>(__q) + __k;
+ __vr = __mulShiftAll(__m2, __DOUBLE_POW5_INV_SPLIT[__q], __i, &__vp, &__vm, __mmShift);
+ if (__q <= 21) {
+ // This should use __q <= 22, but I think 21 is also safe. Smaller values
+ // may still be safe, but it's more difficult to reason about them.
+ // Only one of __mp, __mv, and __mm can be a multiple of 5, if any.
+ const uint32_t __mvMod5 = static_cast<uint32_t>(__mv) - 5 * static_cast<uint32_t>(__div5(__mv));
+ if (__mvMod5 == 0) {
+ __vrIsTrailingZeros = __multipleOfPowerOf5(__mv, __q);
+ } else if (__acceptBounds) {
+ // Same as min(__e2 + (~__mm & 1), __pow5Factor(__mm)) >= __q
+ // <=> __e2 + (~__mm & 1) >= __q && __pow5Factor(__mm) >= __q
+ // <=> true && __pow5Factor(__mm) >= __q, since __e2 >= __q.
+ __vmIsTrailingZeros = __multipleOfPowerOf5(__mv - 1 - __mmShift, __q);
+ } else {
+ // Same as min(__e2 + 1, __pow5Factor(__mp)) >= __q.
+ __vp -= __multipleOfPowerOf5(__mv + 2, __q);
+ }
+ }
+ } else {
+ // This expression is slightly faster than max(0, __log10Pow5(-__e2) - 1).
+ const uint32_t __q = __log10Pow5(-__e2) - (-__e2 > 1);
+ __e10 = static_cast<int32_t>(__q) + __e2;
+ const int32_t __i = -__e2 - static_cast<int32_t>(__q);
+ const int32_t __k = __pow5bits(__i) - __DOUBLE_POW5_BITCOUNT;
+ const int32_t __j = static_cast<int32_t>(__q) - __k;
+ __vr = __mulShiftAll(__m2, __DOUBLE_POW5_SPLIT[__i], __j, &__vp, &__vm, __mmShift);
+ if (__q <= 1) {
+ // {__vr,__vp,__vm} is trailing zeros if {__mv,__mp,__mm} has at least __q trailing 0 bits.
+ // __mv = 4 * __m2, so it always has at least two trailing 0 bits.
+ __vrIsTrailingZeros = true;
+ if (__acceptBounds) {
+ // __mm = __mv - 1 - __mmShift, so it has 1 trailing 0 bit iff __mmShift == 1.
+ __vmIsTrailingZeros = __mmShift == 1;
+ } else {
+ // __mp = __mv + 2, so it always has at least one trailing 0 bit.
+ --__vp;
+ }
+ } else if (__q < 63) { // TRANSITION(ulfjack): Use a tighter bound here.
+ // We need to compute min(ntz(__mv), __pow5Factor(__mv) - __e2) >= __q - 1
+ // <=> ntz(__mv) >= __q - 1 && __pow5Factor(__mv) - __e2 >= __q - 1
+ // <=> ntz(__mv) >= __q - 1 (__e2 is negative and -__e2 >= __q)
+ // <=> (__mv & ((1 << (__q - 1)) - 1)) == 0
+ // We also need to make sure that the left shift does not overflow.
+ __vrIsTrailingZeros = __multipleOfPowerOf2(__mv, __q - 1);
+ }
+ }
+
+ // Step 4: Find the shortest decimal representation in the interval of valid representations.
+ int32_t __removed = 0;
+ uint8_t __lastRemovedDigit = 0;
+ uint64_t _Output;
+ // On average, we remove ~2 digits.
+ if (__vmIsTrailingZeros || __vrIsTrailingZeros) {
+ // General case, which happens rarely (~0.7%).
+ for (;;) {
+ const uint64_t __vpDiv10 = __div10(__vp);
+ const uint64_t __vmDiv10 = __div10(__vm);
+ if (__vpDiv10 <= __vmDiv10) {
+ break;
+ }
+ const uint32_t __vmMod10 = static_cast<uint32_t>(__vm) - 10 * static_cast<uint32_t>(__vmDiv10);
+ const uint64_t __vrDiv10 = __div10(__vr);
+ const uint32_t __vrMod10 = static_cast<uint32_t>(__vr) - 10 * static_cast<uint32_t>(__vrDiv10);
+ __vmIsTrailingZeros &= __vmMod10 == 0;
+ __vrIsTrailingZeros &= __lastRemovedDigit == 0;
+ __lastRemovedDigit = static_cast<uint8_t>(__vrMod10);
+ __vr = __vrDiv10;
+ __vp = __vpDiv10;
+ __vm = __vmDiv10;
+ ++__removed;
+ }
+ if (__vmIsTrailingZeros) {
+ for (;;) {
+ const uint64_t __vmDiv10 = __div10(__vm);
+ const uint32_t __vmMod10 = static_cast<uint32_t>(__vm) - 10 * static_cast<uint32_t>(__vmDiv10);
+ if (__vmMod10 != 0) {
+ break;
+ }
+ const uint64_t __vpDiv10 = __div10(__vp);
+ const uint64_t __vrDiv10 = __div10(__vr);
+ const uint32_t __vrMod10 = static_cast<uint32_t>(__vr) - 10 * static_cast<uint32_t>(__vrDiv10);
+ __vrIsTrailingZeros &= __lastRemovedDigit == 0;
+ __lastRemovedDigit = static_cast<uint8_t>(__vrMod10);
+ __vr = __vrDiv10;
+ __vp = __vpDiv10;
+ __vm = __vmDiv10;
+ ++__removed;
+ }
+ }
+ if (__vrIsTrailingZeros && __lastRemovedDigit == 5 && __vr % 2 == 0) {
+ // Round even if the exact number is .....50..0.
+ __lastRemovedDigit = 4;
+ }
+ // We need to take __vr + 1 if __vr is outside bounds or we need to round up.
+ _Output = __vr + ((__vr == __vm && (!__acceptBounds || !__vmIsTrailingZeros)) || __lastRemovedDigit >= 5);
+ } else {
+ // Specialized for the common case (~99.3%). Percentages below are relative to this.
+ bool __roundUp = false;
+ const uint64_t __vpDiv100 = __div100(__vp);
+ const uint64_t __vmDiv100 = __div100(__vm);
+ if (__vpDiv100 > __vmDiv100) { // Optimization: remove two digits at a time (~86.2%).
+ const uint64_t __vrDiv100 = __div100(__vr);
+ const uint32_t __vrMod100 = static_cast<uint32_t>(__vr) - 100 * static_cast<uint32_t>(__vrDiv100);
+ __roundUp = __vrMod100 >= 50;
+ __vr = __vrDiv100;
+ __vp = __vpDiv100;
+ __vm = __vmDiv100;
+ __removed += 2;
+ }
+ // Loop iterations below (approximately), without optimization above:
+ // 0: 0.03%, 1: 13.8%, 2: 70.6%, 3: 14.0%, 4: 1.40%, 5: 0.14%, 6+: 0.02%
+ // Loop iterations below (approximately), with optimization above:
+ // 0: 70.6%, 1: 27.8%, 2: 1.40%, 3: 0.14%, 4+: 0.02%
+ for (;;) {
+ const uint64_t __vpDiv10 = __div10(__vp);
+ const uint64_t __vmDiv10 = __div10(__vm);
+ if (__vpDiv10 <= __vmDiv10) {
+ break;
+ }
+ const uint64_t __vrDiv10 = __div10(__vr);
+ const uint32_t __vrMod10 = static_cast<uint32_t>(__vr) - 10 * static_cast<uint32_t>(__vrDiv10);
+ __roundUp = __vrMod10 >= 5;
+ __vr = __vrDiv10;
+ __vp = __vpDiv10;
+ __vm = __vmDiv10;
+ ++__removed;
+ }
+ // We need to take __vr + 1 if __vr is outside bounds or we need to round up.
+ _Output = __vr + (__vr == __vm || __roundUp);
+ }
+ const int32_t __exp = __e10 + __removed;
+
+ __floating_decimal_64 __fd;
+ __fd.__exponent = __exp;
+ __fd.__mantissa = _Output;
+ return __fd;
+}
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline to_chars_result __to_chars(char* const _First, char* const _Last, const __floating_decimal_64 __v,
+ chars_format _Fmt, const double __f) {
+ // Step 5: Print the decimal representation.
+ uint64_t _Output = __v.__mantissa;
+ int32_t _Ryu_exponent = __v.__exponent;
+ const uint32_t __olength = __decimalLength17(_Output);
+ int32_t _Scientific_exponent = _Ryu_exponent + static_cast<int32_t>(__olength) - 1;
+
+ if (_Fmt == chars_format{}) {
+ int32_t _Lower;
+ int32_t _Upper;
+
+ if (__olength == 1) {
+ // Value | Fixed | Scientific
+ // 1e-3 | "0.001" | "1e-03"
+ // 1e4 | "10000" | "1e+04"
+ _Lower = -3;
+ _Upper = 4;
+ } else {
+ // Value | Fixed | Scientific
+ // 1234e-7 | "0.0001234" | "1.234e-04"
+ // 1234e5 | "123400000" | "1.234e+08"
+ _Lower = -static_cast<int32_t>(__olength + 3);
+ _Upper = 5;
+ }
+
+ if (_Lower <= _Ryu_exponent && _Ryu_exponent <= _Upper) {
+ _Fmt = chars_format::fixed;
+ } else {
+ _Fmt = chars_format::scientific;
+ }
+ } else if (_Fmt == chars_format::general) {
+ // C11 7.21.6.1 "The fprintf function"/8:
+ // "Let P equal [...] 6 if the precision is omitted [...].
+ // Then, if a conversion with style E would have an exponent of X:
+ // - if P > X >= -4, the conversion is with style f [...].
+ // - otherwise, the conversion is with style e [...]."
+ if (-4 <= _Scientific_exponent && _Scientific_exponent < 6) {
+ _Fmt = chars_format::fixed;
+ } else {
+ _Fmt = chars_format::scientific;
+ }
+ }
+
+ if (_Fmt == chars_format::fixed) {
+ // Example: _Output == 1729, __olength == 4
+
+ // _Ryu_exponent | Printed | _Whole_digits | _Total_fixed_length | Notes
+ // --------------|----------|---------------|----------------------|---------------------------------------
+ // 2 | 172900 | 6 | _Whole_digits | Ryu can't be used for printing
+ // 1 | 17290 | 5 | (sometimes adjusted) | when the trimmed digits are nonzero.
+ // --------------|----------|---------------|----------------------|---------------------------------------
+ // 0 | 1729 | 4 | _Whole_digits | Unified length cases.
+ // --------------|----------|---------------|----------------------|---------------------------------------
+ // -1 | 172.9 | 3 | __olength + 1 | This case can't happen for
+ // -2 | 17.29 | 2 | | __olength == 1, but no additional
+ // -3 | 1.729 | 1 | | code is needed to avoid it.
+ // --------------|----------|---------------|----------------------|---------------------------------------
+ // -4 | 0.1729 | 0 | 2 - _Ryu_exponent | C11 7.21.6.1 "The fprintf function"/8:
+ // -5 | 0.01729 | -1 | | "If a decimal-point character appears,
+ // -6 | 0.001729 | -2 | | at least one digit appears before it."
+
+ const int32_t _Whole_digits = static_cast<int32_t>(__olength) + _Ryu_exponent;
+
+ uint32_t _Total_fixed_length;
+ if (_Ryu_exponent >= 0) { // cases "172900" and "1729"
+ _Total_fixed_length = static_cast<uint32_t>(_Whole_digits);
+ if (_Output == 1) {
+ // Rounding can affect the number of digits.
+ // For example, 1e23 is exactly "99999999999999991611392" which is 23 digits instead of 24.
+ // We can use a lookup table to detect this and adjust the total length.
+ static constexpr uint8_t _Adjustment[309] = {
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,1,1,0,1,0,1,1,1,0,1,1,1,0,0,0,0,0,
+ 1,1,0,0,1,0,1,1,1,0,0,0,0,1,1,1,1,0,0,0,1,1,1,1,0,0,0,1,1,1,1,0,1,0,1,0,1,1,0,0,0,0,1,1,1,
+ 1,0,0,0,0,0,0,0,1,1,0,1,1,0,0,1,0,1,0,1,0,1,1,0,0,0,0,0,1,1,1,0,0,1,1,1,1,1,0,1,0,1,1,0,1,
+ 1,0,0,0,0,0,0,0,0,0,1,1,1,0,0,1,0,0,1,0,0,1,1,1,1,0,0,1,1,0,1,1,0,1,1,0,1,0,0,0,1,0,0,0,1,
+ 0,1,0,1,0,1,1,1,0,0,0,0,0,0,1,1,1,1,0,0,1,0,1,1,1,0,0,0,1,0,1,1,1,1,1,1,0,1,0,1,1,0,0,0,1,
+ 1,1,0,1,1,0,0,0,1,0,0,0,1,0,1,0,0,0,0,0,0,0,1,0,1,1,0,0,1,1,1,0,0,0,1,0,1,0,0,0,0,0,1,1,0,
+ 0,1,0,1,1,1,0,0,1,0,0,0,0,1,0,1,0,0,0,0,0,1,0,1,0,1,1,0,1,0,0,0,0,0,1,1,0,1,0 };
+ _Total_fixed_length -= _Adjustment[_Ryu_exponent];
+ // _Whole_digits doesn't need to be adjusted because these cases won't refer to it later.
+ }
+ } else if (_Whole_digits > 0) { // case "17.29"
+ _Total_fixed_length = __olength + 1;
+ } else { // case "0.001729"
+ _Total_fixed_length = static_cast<uint32_t>(2 - _Ryu_exponent);
+ }
+
+ if (_Last - _First < static_cast<ptrdiff_t>(_Total_fixed_length)) {
+ return { _Last, errc::value_too_large };
+ }
+
+ char* _Mid;
+ if (_Ryu_exponent > 0) { // case "172900"
+ bool _Can_use_ryu;
+
+ if (_Ryu_exponent > 22) { // 10^22 is the largest power of 10 that's exactly representable as a double.
+ _Can_use_ryu = false;
+ } else {
+ // Ryu generated X: __v.__mantissa * 10^_Ryu_exponent
+ // __v.__mantissa == 2^_Trailing_zero_bits * (__v.__mantissa >> _Trailing_zero_bits)
+ // 10^_Ryu_exponent == 2^_Ryu_exponent * 5^_Ryu_exponent
+
+ // _Trailing_zero_bits is [0, 56] (aside: because 2^56 is the largest power of 2
+ // with 17 decimal digits, which is double's round-trip limit.)
+ // _Ryu_exponent is [1, 22].
+ // Normalization adds [2, 52] (aside: at least 2 because the pre-normalized mantissa is at least 5).
+ // This adds up to [3, 130], which is well below double's maximum binary exponent 1023.
+
+ // Therefore, we just need to consider (__v.__mantissa >> _Trailing_zero_bits) * 5^_Ryu_exponent.
+
+ // If that product would exceed 53 bits, then X can't be exactly represented as a double.
+ // (That's not a problem for round-tripping, because X is close enough to the original double,
+ // but X isn't mathematically equal to the original double.) This requires a high-precision fallback.
+
+ // If the product is 53 bits or smaller, then X can be exactly represented as a double (and we don't
+ // need to re-synthesize it; the original double must have been X, because Ryu wouldn't produce the
+ // same output for two different doubles X and Y). This allows Ryu's output to be used (zero-filled).
+
+ // (2^53 - 1) / 5^0 (for indexing), (2^53 - 1) / 5^1, ..., (2^53 - 1) / 5^22
+ static constexpr uint64_t _Max_shifted_mantissa[23] = {
+ 9007199254740991u, 1801439850948198u, 360287970189639u, 72057594037927u, 14411518807585u,
+ 2882303761517u, 576460752303u, 115292150460u, 23058430092u, 4611686018u, 922337203u, 184467440u,
+ 36893488u, 7378697u, 1475739u, 295147u, 59029u, 11805u, 2361u, 472u, 94u, 18u, 3u };
+
+ unsigned long _Trailing_zero_bits;
+#ifdef _LIBCPP_HAS_BITSCAN64
+ (void) _BitScanForward64(&_Trailing_zero_bits, __v.__mantissa); // __v.__mantissa is guaranteed nonzero
+#else // ^^^ 64-bit ^^^ / vvv 32-bit vvv
+ const uint32_t _Low_mantissa = static_cast<uint32_t>(__v.__mantissa);
+ if (_Low_mantissa != 0) {
+ (void) _BitScanForward(&_Trailing_zero_bits, _Low_mantissa);
+ } else {
+ const uint32_t _High_mantissa = static_cast<uint32_t>(__v.__mantissa >> 32); // nonzero here
+ (void) _BitScanForward(&_Trailing_zero_bits, _High_mantissa);
+ _Trailing_zero_bits += 32;
+ }
+#endif // ^^^ 32-bit ^^^
+ const uint64_t _Shifted_mantissa = __v.__mantissa >> _Trailing_zero_bits;
+ _Can_use_ryu = _Shifted_mantissa <= _Max_shifted_mantissa[_Ryu_exponent];
+ }
+
+ if (!_Can_use_ryu) {
+ // Print the integer exactly.
+ // Performance note: This will redundantly perform bounds checking.
+ // Performance note: This will redundantly decompose the IEEE representation.
+ return __d2fixed_buffered_n(_First, _Last, __f, 0);
+ }
+
+ // _Can_use_ryu
+ // Print the decimal digits, left-aligned within [_First, _First + _Total_fixed_length).
+ _Mid = _First + __olength;
+ } else { // cases "1729", "17.29", and "0.001729"
+ // Print the decimal digits, right-aligned within [_First, _First + _Total_fixed_length).
+ _Mid = _First + _Total_fixed_length;
+ }
+
+ // We prefer 32-bit operations, even on 64-bit platforms.
+ // We have at most 17 digits, and uint32_t can store 9 digits.
+ // If _Output doesn't fit into uint32_t, we cut off 8 digits,
+ // so the rest will fit into uint32_t.
+ if ((_Output >> 32) != 0) {
+ // Expensive 64-bit division.
+ const uint64_t __q = __div1e8(_Output);
+ uint32_t __output2 = static_cast<uint32_t>(_Output - 100000000 * __q);
+ _Output = __q;
+
+ const uint32_t __c = __output2 % 10000;
+ __output2 /= 10000;
+ const uint32_t __d = __output2 % 10000;
+ const uint32_t __c0 = (__c % 100) << 1;
+ const uint32_t __c1 = (__c / 100) << 1;
+ const uint32_t __d0 = (__d % 100) << 1;
+ const uint32_t __d1 = (__d / 100) << 1;
+
+ std::memcpy(_Mid -= 2, __DIGIT_TABLE + __c0, 2);
+ std::memcpy(_Mid -= 2, __DIGIT_TABLE + __c1, 2);
+ std::memcpy(_Mid -= 2, __DIGIT_TABLE + __d0, 2);
+ std::memcpy(_Mid -= 2, __DIGIT_TABLE + __d1, 2);
+ }
+ uint32_t __output2 = static_cast<uint32_t>(_Output);
+ while (__output2 >= 10000) {
+#ifdef __clang__ // TRANSITION, LLVM-38217
+ const uint32_t __c = __output2 - 10000 * (__output2 / 10000);
+#else
+ const uint32_t __c = __output2 % 10000;
+#endif
+ __output2 /= 10000;
+ const uint32_t __c0 = (__c % 100) << 1;
+ const uint32_t __c1 = (__c / 100) << 1;
+ std::memcpy(_Mid -= 2, __DIGIT_TABLE + __c0, 2);
+ std::memcpy(_Mid -= 2, __DIGIT_TABLE + __c1, 2);
+ }
+ if (__output2 >= 100) {
+ const uint32_t __c = (__output2 % 100) << 1;
+ __output2 /= 100;
+ std::memcpy(_Mid -= 2, __DIGIT_TABLE + __c, 2);
+ }
+ if (__output2 >= 10) {
+ const uint32_t __c = __output2 << 1;
+ std::memcpy(_Mid -= 2, __DIGIT_TABLE + __c, 2);
+ } else {
+ *--_Mid = static_cast<char>('0' + __output2);
+ }
+
+ if (_Ryu_exponent > 0) { // case "172900" with _Can_use_ryu
+ // Performance note: it might be more efficient to do this immediately after setting _Mid.
+ std::memset(_First + __olength, '0', static_cast<size_t>(_Ryu_exponent));
+ } else if (_Ryu_exponent == 0) { // case "1729"
+ // Done!
+ } else if (_Whole_digits > 0) { // case "17.29"
+ // Performance note: moving digits might not be optimal.
+ std::memmove(_First, _First + 1, static_cast<size_t>(_Whole_digits));
+ _First[_Whole_digits] = '.';
+ } else { // case "0.001729"
+ // Performance note: a larger memset() followed by overwriting '.' might be more efficient.
+ _First[0] = '0';
+ _First[1] = '.';
+ std::memset(_First + 2, '0', static_cast<size_t>(-_Whole_digits));
+ }
+
+ return { _First + _Total_fixed_length, errc{} };
+ }
+
+ const uint32_t _Total_scientific_length = __olength + (__olength > 1) // digits + possible decimal point
+ + (-100 < _Scientific_exponent && _Scientific_exponent < 100 ? 4 : 5); // + scientific exponent
+ if (_Last - _First < static_cast<ptrdiff_t>(_Total_scientific_length)) {
+ return { _Last, errc::value_too_large };
+ }
+ char* const __result = _First;
+
+ // Print the decimal digits.
+ uint32_t __i = 0;
+ // We prefer 32-bit operations, even on 64-bit platforms.
+ // We have at most 17 digits, and uint32_t can store 9 digits.
+ // If _Output doesn't fit into uint32_t, we cut off 8 digits,
+ // so the rest will fit into uint32_t.
+ if ((_Output >> 32) != 0) {
+ // Expensive 64-bit division.
+ const uint64_t __q = __div1e8(_Output);
+ uint32_t __output2 = static_cast<uint32_t>(_Output) - 100000000 * static_cast<uint32_t>(__q);
+ _Output = __q;
+
+ const uint32_t __c = __output2 % 10000;
+ __output2 /= 10000;
+ const uint32_t __d = __output2 % 10000;
+ const uint32_t __c0 = (__c % 100) << 1;
+ const uint32_t __c1 = (__c / 100) << 1;
+ const uint32_t __d0 = (__d % 100) << 1;
+ const uint32_t __d1 = (__d / 100) << 1;
+ std::memcpy(__result + __olength - __i - 1, __DIGIT_TABLE + __c0, 2);
+ std::memcpy(__result + __olength - __i - 3, __DIGIT_TABLE + __c1, 2);
+ std::memcpy(__result + __olength - __i - 5, __DIGIT_TABLE + __d0, 2);
+ std::memcpy(__result + __olength - __i - 7, __DIGIT_TABLE + __d1, 2);
+ __i += 8;
+ }
+ uint32_t __output2 = static_cast<uint32_t>(_Output);
+ while (__output2 >= 10000) {
+#ifdef __clang__ // TRANSITION, LLVM-38217
+ const uint32_t __c = __output2 - 10000 * (__output2 / 10000);
+#else
+ const uint32_t __c = __output2 % 10000;
+#endif
+ __output2 /= 10000;
+ const uint32_t __c0 = (__c % 100) << 1;
+ const uint32_t __c1 = (__c / 100) << 1;
+ std::memcpy(__result + __olength - __i - 1, __DIGIT_TABLE + __c0, 2);
+ std::memcpy(__result + __olength - __i - 3, __DIGIT_TABLE + __c1, 2);
+ __i += 4;
+ }
+ if (__output2 >= 100) {
+ const uint32_t __c = (__output2 % 100) << 1;
+ __output2 /= 100;
+ std::memcpy(__result + __olength - __i - 1, __DIGIT_TABLE + __c, 2);
+ __i += 2;
+ }
+ if (__output2 >= 10) {
+ const uint32_t __c = __output2 << 1;
+ // We can't use memcpy here: the decimal dot goes between these two digits.
+ __result[2] = __DIGIT_TABLE[__c + 1];
+ __result[0] = __DIGIT_TABLE[__c];
+ } else {
+ __result[0] = static_cast<char>('0' + __output2);
+ }
+
+ // Print decimal point if needed.
+ uint32_t __index;
+ if (__olength > 1) {
+ __result[1] = '.';
+ __index = __olength + 1;
+ } else {
+ __index = 1;
+ }
+
+ // Print the exponent.
+ __result[__index++] = 'e';
+ if (_Scientific_exponent < 0) {
+ __result[__index++] = '-';
+ _Scientific_exponent = -_Scientific_exponent;
+ } else {
+ __result[__index++] = '+';
+ }
+
+ if (_Scientific_exponent >= 100) {
+ const int32_t __c = _Scientific_exponent % 10;
+ std::memcpy(__result + __index, __DIGIT_TABLE + 2 * (_Scientific_exponent / 10), 2);
+ __result[__index + 2] = static_cast<char>('0' + __c);
+ __index += 3;
+ } else {
+ std::memcpy(__result + __index, __DIGIT_TABLE + 2 * _Scientific_exponent, 2);
+ __index += 2;
+ }
+
+ return { _First + _Total_scientific_length, errc{} };
+}
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline bool __d2d_small_int(const uint64_t __ieeeMantissa, const uint32_t __ieeeExponent,
+ __floating_decimal_64* const __v) {
+ const uint64_t __m2 = (1ull << __DOUBLE_MANTISSA_BITS) | __ieeeMantissa;
+ const int32_t __e2 = static_cast<int32_t>(__ieeeExponent) - __DOUBLE_BIAS - __DOUBLE_MANTISSA_BITS;
+
+ if (__e2 > 0) {
+ // f = __m2 * 2^__e2 >= 2^53 is an integer.
+ // Ignore this case for now.
+ return false;
+ }
+
+ if (__e2 < -52) {
+ // f < 1.
+ return false;
+ }
+
+ // Since 2^52 <= __m2 < 2^53 and 0 <= -__e2 <= 52: 1 <= f = __m2 / 2^-__e2 < 2^53.
+ // Test if the lower -__e2 bits of the significand are 0, i.e. whether the fraction is 0.
+ const uint64_t __mask = (1ull << -__e2) - 1;
+ const uint64_t __fraction = __m2 & __mask;
+ if (__fraction != 0) {
+ return false;
+ }
+
+ // f is an integer in the range [1, 2^53).
+ // Note: __mantissa might contain trailing (decimal) 0's.
+ // Note: since 2^53 < 10^16, there is no need to adjust __decimalLength17().
+ __v->__mantissa = __m2 >> -__e2;
+ __v->__exponent = 0;
+ return true;
+}
+
+[[nodiscard]] to_chars_result __d2s_buffered_n(char* const _First, char* const _Last, const double __f,
+ const chars_format _Fmt) {
+
+ // Step 1: Decode the floating-point number, and unify normalized and subnormal cases.
+ const uint64_t __bits = __double_to_bits(__f);
+
+ // Case distinction; exit early for the easy cases.
+ if (__bits == 0) {
+ if (_Fmt == chars_format::scientific) {
+ if (_Last - _First < 5) {
+ return { _Last, errc::value_too_large };
+ }
+
+ std::memcpy(_First, "0e+00", 5);
+
+ return { _First + 5, errc{} };
+ }
+
+ // Print "0" for chars_format::fixed, chars_format::general, and chars_format{}.
+ if (_First == _Last) {
+ return { _Last, errc::value_too_large };
+ }
+
+ *_First = '0';
+
+ return { _First + 1, errc{} };
+ }
+
+ // Decode __bits into mantissa and exponent.
+ const uint64_t __ieeeMantissa = __bits & ((1ull << __DOUBLE_MANTISSA_BITS) - 1);
+ const uint32_t __ieeeExponent = static_cast<uint32_t>(__bits >> __DOUBLE_MANTISSA_BITS);
+
+ if (_Fmt == chars_format::fixed) {
+ // const uint64_t _Mantissa2 = __ieeeMantissa | (1ull << __DOUBLE_MANTISSA_BITS); // restore implicit bit
+ const int32_t _Exponent2 = static_cast<int32_t>(__ieeeExponent)
+ - __DOUBLE_BIAS - __DOUBLE_MANTISSA_BITS; // bias and normalization
+
+ // Normal values are equal to _Mantissa2 * 2^_Exponent2.
+ // (Subnormals are different, but they'll be rejected by the _Exponent2 test here, so they can be ignored.)
+
+ // For nonzero integers, _Exponent2 >= -52. (The minimum value occurs when _Mantissa2 * 2^_Exponent2 is 1.
+ // In that case, _Mantissa2 is the implicit 1 bit followed by 52 zeros, so _Exponent2 is -52 to shift away
+ // the zeros.) The dense range of exactly representable integers has negative or zero exponents
+ // (as positive exponents make the range non-dense). For that dense range, Ryu will always be used:
+ // every digit is necessary to uniquely identify the value, so Ryu must print them all.
+
+ // Positive exponents are the non-dense range of exactly representable integers. This contains all of the values
+ // for which Ryu can't be used (and a few Ryu-friendly values). We can save time by detecting positive
+ // exponents here and skipping Ryu. Calling __d2fixed_buffered_n() with precision 0 is valid for all integers
+ // (so it's okay if we call it with a Ryu-friendly value).
+ if (_Exponent2 > 0) {
+ return __d2fixed_buffered_n(_First, _Last, __f, 0);
+ }
+ }
+
+ __floating_decimal_64 __v;
+ const bool __isSmallInt = __d2d_small_int(__ieeeMantissa, __ieeeExponent, &__v);
+ if (__isSmallInt) {
+ // For small integers in the range [1, 2^53), __v.__mantissa might contain trailing (decimal) zeros.
+ // For scientific notation we need to move these zeros into the exponent.
+ // (This is not needed for fixed-point notation, so it might be beneficial to trim
+ // trailing zeros in __to_chars only if needed - once fixed-point notation output is implemented.)
+ for (;;) {
+ const uint64_t __q = __div10(__v.__mantissa);
+ const uint32_t __r = static_cast<uint32_t>(__v.__mantissa) - 10 * static_cast<uint32_t>(__q);
+ if (__r != 0) {
+ break;
+ }
+ __v.__mantissa = __q;
+ ++__v.__exponent;
+ }
+ } else {
+ __v = __d2d(__ieeeMantissa, __ieeeExponent);
+ }
+
+ return __to_chars(_First, _Last, __v, _Fmt, __f);
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+// clang-format on
diff --git a/contrib/llvm-project/libcxx/src/ryu/f2s.cpp b/contrib/llvm-project/libcxx/src/ryu/f2s.cpp
new file mode 100644
index 000000000000..f42fbd68c91d
--- /dev/null
+++ b/contrib/llvm-project/libcxx/src/ryu/f2s.cpp
@@ -0,0 +1,716 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// Copyright (c) Microsoft Corporation.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+// Copyright 2018 Ulf Adams
+// Copyright (c) Microsoft Corporation. All rights reserved.
+
+// Boost Software License - Version 1.0 - August 17th, 2003
+
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+
+// Avoid formatting to keep the changes with the original code minimal.
+// clang-format off
+
+#include <__assert>
+#include <__config>
+#include <charconv>
+
+#include "include/ryu/common.h"
+#include "include/ryu/d2fixed.h"
+#include "include/ryu/d2s_intrinsics.h"
+#include "include/ryu/digit_table.h"
+#include "include/ryu/f2s.h"
+#include "include/ryu/ryu.h"
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+inline constexpr int __FLOAT_MANTISSA_BITS = 23;
+inline constexpr int __FLOAT_EXPONENT_BITS = 8;
+inline constexpr int __FLOAT_BIAS = 127;
+
+inline constexpr int __FLOAT_POW5_INV_BITCOUNT = 59;
+inline constexpr uint64_t __FLOAT_POW5_INV_SPLIT[31] = {
+ 576460752303423489u, 461168601842738791u, 368934881474191033u, 295147905179352826u,
+ 472236648286964522u, 377789318629571618u, 302231454903657294u, 483570327845851670u,
+ 386856262276681336u, 309485009821345069u, 495176015714152110u, 396140812571321688u,
+ 316912650057057351u, 507060240091291761u, 405648192073033409u, 324518553658426727u,
+ 519229685853482763u, 415383748682786211u, 332306998946228969u, 531691198313966350u,
+ 425352958651173080u, 340282366920938464u, 544451787073501542u, 435561429658801234u,
+ 348449143727040987u, 557518629963265579u, 446014903970612463u, 356811923176489971u,
+ 570899077082383953u, 456719261665907162u, 365375409332725730u
+};
+inline constexpr int __FLOAT_POW5_BITCOUNT = 61;
+inline constexpr uint64_t __FLOAT_POW5_SPLIT[47] = {
+ 1152921504606846976u, 1441151880758558720u, 1801439850948198400u, 2251799813685248000u,
+ 1407374883553280000u, 1759218604441600000u, 2199023255552000000u, 1374389534720000000u,
+ 1717986918400000000u, 2147483648000000000u, 1342177280000000000u, 1677721600000000000u,
+ 2097152000000000000u, 1310720000000000000u, 1638400000000000000u, 2048000000000000000u,
+ 1280000000000000000u, 1600000000000000000u, 2000000000000000000u, 1250000000000000000u,
+ 1562500000000000000u, 1953125000000000000u, 1220703125000000000u, 1525878906250000000u,
+ 1907348632812500000u, 1192092895507812500u, 1490116119384765625u, 1862645149230957031u,
+ 1164153218269348144u, 1455191522836685180u, 1818989403545856475u, 2273736754432320594u,
+ 1421085471520200371u, 1776356839400250464u, 2220446049250313080u, 1387778780781445675u,
+ 1734723475976807094u, 2168404344971008868u, 1355252715606880542u, 1694065894508600678u,
+ 2117582368135750847u, 1323488980084844279u, 1654361225106055349u, 2067951531382569187u,
+ 1292469707114105741u, 1615587133892632177u, 2019483917365790221u
+};
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint32_t __pow5Factor(uint32_t __value) {
+ uint32_t __count = 0;
+ for (;;) {
+ _LIBCPP_ASSERT_INTERNAL(__value != 0, "");
+ const uint32_t __q = __value / 5;
+ const uint32_t __r = __value % 5;
+ if (__r != 0) {
+ break;
+ }
+ __value = __q;
+ ++__count;
+ }
+ return __count;
+}
+
+// Returns true if __value is divisible by 5^__p.
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline bool __multipleOfPowerOf5(const uint32_t __value, const uint32_t __p) {
+ return __pow5Factor(__value) >= __p;
+}
+
+// Returns true if __value is divisible by 2^__p.
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline bool __multipleOfPowerOf2(const uint32_t __value, const uint32_t __p) {
+ _LIBCPP_ASSERT_INTERNAL(__value != 0, "");
+ _LIBCPP_ASSERT_INTERNAL(__p < 32, "");
+ // __builtin_ctz doesn't appear to be faster here.
+ return (__value & ((1u << __p) - 1)) == 0;
+}
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint32_t __mulShift(const uint32_t __m, const uint64_t __factor, const int32_t __shift) {
+ _LIBCPP_ASSERT_INTERNAL(__shift > 32, "");
+
+ // The casts here help MSVC to avoid calls to the __allmul library
+ // function.
+ const uint32_t __factorLo = static_cast<uint32_t>(__factor);
+ const uint32_t __factorHi = static_cast<uint32_t>(__factor >> 32);
+ const uint64_t __bits0 = static_cast<uint64_t>(__m) * __factorLo;
+ const uint64_t __bits1 = static_cast<uint64_t>(__m) * __factorHi;
+
+#ifndef _LIBCPP_64_BIT
+ // On 32-bit platforms we can avoid a 64-bit shift-right since we only
+ // need the upper 32 bits of the result and the shift value is > 32.
+ const uint32_t __bits0Hi = static_cast<uint32_t>(__bits0 >> 32);
+ uint32_t __bits1Lo = static_cast<uint32_t>(__bits1);
+ uint32_t __bits1Hi = static_cast<uint32_t>(__bits1 >> 32);
+ __bits1Lo += __bits0Hi;
+ __bits1Hi += (__bits1Lo < __bits0Hi);
+ const int32_t __s = __shift - 32;
+ return (__bits1Hi << (32 - __s)) | (__bits1Lo >> __s);
+#else // ^^^ 32-bit ^^^ / vvv 64-bit vvv
+ const uint64_t __sum = (__bits0 >> 32) + __bits1;
+ const uint64_t __shiftedSum = __sum >> (__shift - 32);
+ _LIBCPP_ASSERT_INTERNAL(__shiftedSum <= UINT32_MAX, "");
+ return static_cast<uint32_t>(__shiftedSum);
+#endif // ^^^ 64-bit ^^^
+}
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint32_t __mulPow5InvDivPow2(const uint32_t __m, const uint32_t __q, const int32_t __j) {
+ return __mulShift(__m, __FLOAT_POW5_INV_SPLIT[__q], __j);
+}
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline uint32_t __mulPow5divPow2(const uint32_t __m, const uint32_t __i, const int32_t __j) {
+ return __mulShift(__m, __FLOAT_POW5_SPLIT[__i], __j);
+}
+
+// A floating decimal representing m * 10^e.
+struct __floating_decimal_32 {
+ uint32_t __mantissa;
+ int32_t __exponent;
+};
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline __floating_decimal_32 __f2d(const uint32_t __ieeeMantissa, const uint32_t __ieeeExponent) {
+ int32_t __e2;
+ uint32_t __m2;
+ if (__ieeeExponent == 0) {
+ // We subtract 2 so that the bounds computation has 2 additional bits.
+ __e2 = 1 - __FLOAT_BIAS - __FLOAT_MANTISSA_BITS - 2;
+ __m2 = __ieeeMantissa;
+ } else {
+ __e2 = static_cast<int32_t>(__ieeeExponent) - __FLOAT_BIAS - __FLOAT_MANTISSA_BITS - 2;
+ __m2 = (1u << __FLOAT_MANTISSA_BITS) | __ieeeMantissa;
+ }
+ const bool __even = (__m2 & 1) == 0;
+ const bool __acceptBounds = __even;
+
+ // Step 2: Determine the interval of valid decimal representations.
+ const uint32_t __mv = 4 * __m2;
+ const uint32_t __mp = 4 * __m2 + 2;
+ // Implicit bool -> int conversion. True is 1, false is 0.
+ const uint32_t __mmShift = __ieeeMantissa != 0 || __ieeeExponent <= 1;
+ const uint32_t __mm = 4 * __m2 - 1 - __mmShift;
+
+ // Step 3: Convert to a decimal power base using 64-bit arithmetic.
+ uint32_t __vr, __vp, __vm;
+ int32_t __e10;
+ bool __vmIsTrailingZeros = false;
+ bool __vrIsTrailingZeros = false;
+ uint8_t __lastRemovedDigit = 0;
+ if (__e2 >= 0) {
+ const uint32_t __q = __log10Pow2(__e2);
+ __e10 = static_cast<int32_t>(__q);
+ const int32_t __k = __FLOAT_POW5_INV_BITCOUNT + __pow5bits(static_cast<int32_t>(__q)) - 1;
+ const int32_t __i = -__e2 + static_cast<int32_t>(__q) + __k;
+ __vr = __mulPow5InvDivPow2(__mv, __q, __i);
+ __vp = __mulPow5InvDivPow2(__mp, __q, __i);
+ __vm = __mulPow5InvDivPow2(__mm, __q, __i);
+ if (__q != 0 && (__vp - 1) / 10 <= __vm / 10) {
+ // We need to know one removed digit even if we are not going to loop below. We could use
+ // __q = X - 1 above, except that would require 33 bits for the result, and we've found that
+ // 32-bit arithmetic is faster even on 64-bit machines.
+ const int32_t __l = __FLOAT_POW5_INV_BITCOUNT + __pow5bits(static_cast<int32_t>(__q - 1)) - 1;
+ __lastRemovedDigit = static_cast<uint8_t>(__mulPow5InvDivPow2(__mv, __q - 1,
+ -__e2 + static_cast<int32_t>(__q) - 1 + __l) % 10);
+ }
+ if (__q <= 9) {
+ // The largest power of 5 that fits in 24 bits is 5^10, but __q <= 9 seems to be safe as well.
+ // Only one of __mp, __mv, and __mm can be a multiple of 5, if any.
+ if (__mv % 5 == 0) {
+ __vrIsTrailingZeros = __multipleOfPowerOf5(__mv, __q);
+ } else if (__acceptBounds) {
+ __vmIsTrailingZeros = __multipleOfPowerOf5(__mm, __q);
+ } else {
+ __vp -= __multipleOfPowerOf5(__mp, __q);
+ }
+ }
+ } else {
+ const uint32_t __q = __log10Pow5(-__e2);
+ __e10 = static_cast<int32_t>(__q) + __e2;
+ const int32_t __i = -__e2 - static_cast<int32_t>(__q);
+ const int32_t __k = __pow5bits(__i) - __FLOAT_POW5_BITCOUNT;
+ int32_t __j = static_cast<int32_t>(__q) - __k;
+ __vr = __mulPow5divPow2(__mv, static_cast<uint32_t>(__i), __j);
+ __vp = __mulPow5divPow2(__mp, static_cast<uint32_t>(__i), __j);
+ __vm = __mulPow5divPow2(__mm, static_cast<uint32_t>(__i), __j);
+ if (__q != 0 && (__vp - 1) / 10 <= __vm / 10) {
+ __j = static_cast<int32_t>(__q) - 1 - (__pow5bits(__i + 1) - __FLOAT_POW5_BITCOUNT);
+ __lastRemovedDigit = static_cast<uint8_t>(__mulPow5divPow2(__mv, static_cast<uint32_t>(__i + 1), __j) % 10);
+ }
+ if (__q <= 1) {
+ // {__vr,__vp,__vm} is trailing zeros if {__mv,__mp,__mm} has at least __q trailing 0 bits.
+ // __mv = 4 * __m2, so it always has at least two trailing 0 bits.
+ __vrIsTrailingZeros = true;
+ if (__acceptBounds) {
+ // __mm = __mv - 1 - __mmShift, so it has 1 trailing 0 bit iff __mmShift == 1.
+ __vmIsTrailingZeros = __mmShift == 1;
+ } else {
+ // __mp = __mv + 2, so it always has at least one trailing 0 bit.
+ --__vp;
+ }
+ } else if (__q < 31) { // TRANSITION(ulfjack): Use a tighter bound here.
+ __vrIsTrailingZeros = __multipleOfPowerOf2(__mv, __q - 1);
+ }
+ }
+
+ // Step 4: Find the shortest decimal representation in the interval of valid representations.
+ int32_t __removed = 0;
+ uint32_t _Output;
+ if (__vmIsTrailingZeros || __vrIsTrailingZeros) {
+ // General case, which happens rarely (~4.0%).
+ while (__vp / 10 > __vm / 10) {
+#ifdef __clang__ // TRANSITION, LLVM-23106
+ __vmIsTrailingZeros &= __vm - (__vm / 10) * 10 == 0;
+#else
+ __vmIsTrailingZeros &= __vm % 10 == 0;
+#endif
+ __vrIsTrailingZeros &= __lastRemovedDigit == 0;
+ __lastRemovedDigit = static_cast<uint8_t>(__vr % 10);
+ __vr /= 10;
+ __vp /= 10;
+ __vm /= 10;
+ ++__removed;
+ }
+ if (__vmIsTrailingZeros) {
+ while (__vm % 10 == 0) {
+ __vrIsTrailingZeros &= __lastRemovedDigit == 0;
+ __lastRemovedDigit = static_cast<uint8_t>(__vr % 10);
+ __vr /= 10;
+ __vp /= 10;
+ __vm /= 10;
+ ++__removed;
+ }
+ }
+ if (__vrIsTrailingZeros && __lastRemovedDigit == 5 && __vr % 2 == 0) {
+ // Round even if the exact number is .....50..0.
+ __lastRemovedDigit = 4;
+ }
+ // We need to take __vr + 1 if __vr is outside bounds or we need to round up.
+ _Output = __vr + ((__vr == __vm && (!__acceptBounds || !__vmIsTrailingZeros)) || __lastRemovedDigit >= 5);
+ } else {
+ // Specialized for the common case (~96.0%). Percentages below are relative to this.
+ // Loop iterations below (approximately):
+ // 0: 13.6%, 1: 70.7%, 2: 14.1%, 3: 1.39%, 4: 0.14%, 5+: 0.01%
+ while (__vp / 10 > __vm / 10) {
+ __lastRemovedDigit = static_cast<uint8_t>(__vr % 10);
+ __vr /= 10;
+ __vp /= 10;
+ __vm /= 10;
+ ++__removed;
+ }
+ // We need to take __vr + 1 if __vr is outside bounds or we need to round up.
+ _Output = __vr + (__vr == __vm || __lastRemovedDigit >= 5);
+ }
+ const int32_t __exp = __e10 + __removed;
+
+ __floating_decimal_32 __fd;
+ __fd.__exponent = __exp;
+ __fd.__mantissa = _Output;
+ return __fd;
+}
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline to_chars_result _Large_integer_to_chars(char* const _First, char* const _Last,
+ const uint32_t _Mantissa2, const int32_t _Exponent2) {
+
+ // Print the integer _Mantissa2 * 2^_Exponent2 exactly.
+
+ // For nonzero integers, _Exponent2 >= -23. (The minimum value occurs when _Mantissa2 * 2^_Exponent2 is 1.
+ // In that case, _Mantissa2 is the implicit 1 bit followed by 23 zeros, so _Exponent2 is -23 to shift away
+ // the zeros.) The dense range of exactly representable integers has negative or zero exponents
+ // (as positive exponents make the range non-dense). For that dense range, Ryu will always be used:
+ // every digit is necessary to uniquely identify the value, so Ryu must print them all.
+
+ // Positive exponents are the non-dense range of exactly representable integers.
+ // This contains all of the values for which Ryu can't be used (and a few Ryu-friendly values).
+
+ // Performance note: Long division appears to be faster than losslessly widening float to double and calling
+ // __d2fixed_buffered_n(). If __f2fixed_buffered_n() is implemented, it might be faster than long division.
+
+ _LIBCPP_ASSERT_INTERNAL(_Exponent2 > 0, "");
+ _LIBCPP_ASSERT_INTERNAL(_Exponent2 <= 104, ""); // because __ieeeExponent <= 254
+
+ // Manually represent _Mantissa2 * 2^_Exponent2 as a large integer. _Mantissa2 is always 24 bits
+ // (due to the implicit bit), while _Exponent2 indicates a shift of at most 104 bits.
+ // 24 + 104 equals 128 equals 4 * 32, so we need exactly 4 32-bit elements.
+ // We use a little-endian representation, visualized like this:
+
+ // << left shift <<
+ // most significant
+ // _Data[3] _Data[2] _Data[1] _Data[0]
+ // least significant
+ // >> right shift >>
+
+ constexpr uint32_t _Data_size = 4;
+ uint32_t _Data[_Data_size]{};
+
+ // _Maxidx is the index of the most significant nonzero element.
+ uint32_t _Maxidx = ((24 + static_cast<uint32_t>(_Exponent2) + 31) / 32) - 1;
+ _LIBCPP_ASSERT_INTERNAL(_Maxidx < _Data_size, "");
+
+ const uint32_t _Bit_shift = static_cast<uint32_t>(_Exponent2) % 32;
+ if (_Bit_shift <= 8) { // _Mantissa2's 24 bits don't cross an element boundary
+ _Data[_Maxidx] = _Mantissa2 << _Bit_shift;
+ } else { // _Mantissa2's 24 bits cross an element boundary
+ _Data[_Maxidx - 1] = _Mantissa2 << _Bit_shift;
+ _Data[_Maxidx] = _Mantissa2 >> (32 - _Bit_shift);
+ }
+
+ // If Ryu hasn't determined the total output length, we need to buffer the digits generated from right to left
+ // by long division. The largest possible float is: 340'282346638'528859811'704183484'516925440
+ uint32_t _Blocks[4];
+ int32_t _Filled_blocks = 0;
+ // From left to right, we're going to print:
+ // _Data[0] will be [1, 10] digits.
+ // Then if _Filled_blocks > 0:
+ // _Blocks[_Filled_blocks - 1], ..., _Blocks[0] will be 0-filled 9-digit blocks.
+
+ if (_Maxidx != 0) { // If the integer is actually large, perform long division.
+ // Otherwise, skip to printing _Data[0].
+ for (;;) {
+ // Loop invariant: _Maxidx != 0 (i.e. the integer is actually large)
+
+ const uint32_t _Most_significant_elem = _Data[_Maxidx];
+ const uint32_t _Initial_remainder = _Most_significant_elem % 1000000000;
+ const uint32_t _Initial_quotient = _Most_significant_elem / 1000000000;
+ _Data[_Maxidx] = _Initial_quotient;
+ uint64_t _Remainder = _Initial_remainder;
+
+ // Process less significant elements.
+ uint32_t _Idx = _Maxidx;
+ do {
+ --_Idx; // Initially, _Remainder is at most 10^9 - 1.
+
+ // Now, _Remainder is at most (10^9 - 1) * 2^32 + 2^32 - 1, simplified to 10^9 * 2^32 - 1.
+ _Remainder = (_Remainder << 32) | _Data[_Idx];
+
+ // floor((10^9 * 2^32 - 1) / 10^9) == 2^32 - 1, so uint32_t _Quotient is lossless.
+ const uint32_t _Quotient = static_cast<uint32_t>(__div1e9(_Remainder));
+
+ // _Remainder is at most 10^9 - 1 again.
+ // For uint32_t truncation, see the __mod1e9() comment in d2s_intrinsics.h.
+ _Remainder = static_cast<uint32_t>(_Remainder) - 1000000000u * _Quotient;
+
+ _Data[_Idx] = _Quotient;
+ } while (_Idx != 0);
+
+ // Store a 0-filled 9-digit block.
+ _Blocks[_Filled_blocks++] = static_cast<uint32_t>(_Remainder);
+
+ if (_Initial_quotient == 0) { // Is the large integer shrinking?
+ --_Maxidx; // log2(10^9) is 29.9, so we can't shrink by more than one element.
+ if (_Maxidx == 0) {
+ break; // We've finished long division. Now we need to print _Data[0].
+ }
+ }
+ }
+ }
+
+ _LIBCPP_ASSERT_INTERNAL(_Data[0] != 0, "");
+ for (uint32_t _Idx = 1; _Idx < _Data_size; ++_Idx) {
+ _LIBCPP_ASSERT_INTERNAL(_Data[_Idx] == 0, "");
+ }
+
+ const uint32_t _Data_olength = _Data[0] >= 1000000000 ? 10 : __decimalLength9(_Data[0]);
+ const uint32_t _Total_fixed_length = _Data_olength + 9 * _Filled_blocks;
+
+ if (_Last - _First < static_cast<ptrdiff_t>(_Total_fixed_length)) {
+ return { _Last, errc::value_too_large };
+ }
+
+ char* _Result = _First;
+
+ // Print _Data[0]. While it's up to 10 digits,
+ // which is more than Ryu generates, the code below can handle this.
+ __append_n_digits(_Data_olength, _Data[0], _Result);
+ _Result += _Data_olength;
+
+ // Print 0-filled 9-digit blocks.
+ for (int32_t _Idx = _Filled_blocks - 1; _Idx >= 0; --_Idx) {
+ __append_nine_digits(_Blocks[_Idx], _Result);
+ _Result += 9;
+ }
+
+ return { _Result, errc{} };
+}
+
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline to_chars_result __to_chars(char* const _First, char* const _Last, const __floating_decimal_32 __v,
+ chars_format _Fmt, const uint32_t __ieeeMantissa, const uint32_t __ieeeExponent) {
+ // Step 5: Print the decimal representation.
+ uint32_t _Output = __v.__mantissa;
+ int32_t _Ryu_exponent = __v.__exponent;
+ const uint32_t __olength = __decimalLength9(_Output);
+ int32_t _Scientific_exponent = _Ryu_exponent + static_cast<int32_t>(__olength) - 1;
+
+ if (_Fmt == chars_format{}) {
+ int32_t _Lower;
+ int32_t _Upper;
+
+ if (__olength == 1) {
+ // Value | Fixed | Scientific
+ // 1e-3 | "0.001" | "1e-03"
+ // 1e4 | "10000" | "1e+04"
+ _Lower = -3;
+ _Upper = 4;
+ } else {
+ // Value | Fixed | Scientific
+ // 1234e-7 | "0.0001234" | "1.234e-04"
+ // 1234e5 | "123400000" | "1.234e+08"
+ _Lower = -static_cast<int32_t>(__olength + 3);
+ _Upper = 5;
+ }
+
+ if (_Lower <= _Ryu_exponent && _Ryu_exponent <= _Upper) {
+ _Fmt = chars_format::fixed;
+ } else {
+ _Fmt = chars_format::scientific;
+ }
+ } else if (_Fmt == chars_format::general) {
+ // C11 7.21.6.1 "The fprintf function"/8:
+ // "Let P equal [...] 6 if the precision is omitted [...].
+ // Then, if a conversion with style E would have an exponent of X:
+ // - if P > X >= -4, the conversion is with style f [...].
+ // - otherwise, the conversion is with style e [...]."
+ if (-4 <= _Scientific_exponent && _Scientific_exponent < 6) {
+ _Fmt = chars_format::fixed;
+ } else {
+ _Fmt = chars_format::scientific;
+ }
+ }
+
+ if (_Fmt == chars_format::fixed) {
+ // Example: _Output == 1729, __olength == 4
+
+ // _Ryu_exponent | Printed | _Whole_digits | _Total_fixed_length | Notes
+ // --------------|----------|---------------|----------------------|---------------------------------------
+ // 2 | 172900 | 6 | _Whole_digits | Ryu can't be used for printing
+ // 1 | 17290 | 5 | (sometimes adjusted) | when the trimmed digits are nonzero.
+ // --------------|----------|---------------|----------------------|---------------------------------------
+ // 0 | 1729 | 4 | _Whole_digits | Unified length cases.
+ // --------------|----------|---------------|----------------------|---------------------------------------
+ // -1 | 172.9 | 3 | __olength + 1 | This case can't happen for
+ // -2 | 17.29 | 2 | | __olength == 1, but no additional
+ // -3 | 1.729 | 1 | | code is needed to avoid it.
+ // --------------|----------|---------------|----------------------|---------------------------------------
+ // -4 | 0.1729 | 0 | 2 - _Ryu_exponent | C11 7.21.6.1 "The fprintf function"/8:
+ // -5 | 0.01729 | -1 | | "If a decimal-point character appears,
+ // -6 | 0.001729 | -2 | | at least one digit appears before it."
+
+ const int32_t _Whole_digits = static_cast<int32_t>(__olength) + _Ryu_exponent;
+
+ uint32_t _Total_fixed_length;
+ if (_Ryu_exponent >= 0) { // cases "172900" and "1729"
+ _Total_fixed_length = static_cast<uint32_t>(_Whole_digits);
+ if (_Output == 1) {
+ // Rounding can affect the number of digits.
+ // For example, 1e11f is exactly "99999997952" which is 11 digits instead of 12.
+ // We can use a lookup table to detect this and adjust the total length.
+ static constexpr uint8_t _Adjustment[39] = {
+ 0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,1,0,1,1,1,0,0,1,1,0,1,0,1,1,0,0,1,0,1,1,0,1,1,1 };
+ _Total_fixed_length -= _Adjustment[_Ryu_exponent];
+ // _Whole_digits doesn't need to be adjusted because these cases won't refer to it later.
+ }
+ } else if (_Whole_digits > 0) { // case "17.29"
+ _Total_fixed_length = __olength + 1;
+ } else { // case "0.001729"
+ _Total_fixed_length = static_cast<uint32_t>(2 - _Ryu_exponent);
+ }
+
+ if (_Last - _First < static_cast<ptrdiff_t>(_Total_fixed_length)) {
+ return { _Last, errc::value_too_large };
+ }
+
+ char* _Mid;
+ if (_Ryu_exponent > 0) { // case "172900"
+ bool _Can_use_ryu;
+
+ if (_Ryu_exponent > 10) { // 10^10 is the largest power of 10 that's exactly representable as a float.
+ _Can_use_ryu = false;
+ } else {
+ // Ryu generated X: __v.__mantissa * 10^_Ryu_exponent
+ // __v.__mantissa == 2^_Trailing_zero_bits * (__v.__mantissa >> _Trailing_zero_bits)
+ // 10^_Ryu_exponent == 2^_Ryu_exponent * 5^_Ryu_exponent
+
+ // _Trailing_zero_bits is [0, 29] (aside: because 2^29 is the largest power of 2
+ // with 9 decimal digits, which is float's round-trip limit.)
+ // _Ryu_exponent is [1, 10].
+ // Normalization adds [2, 23] (aside: at least 2 because the pre-normalized mantissa is at least 5).
+ // This adds up to [3, 62], which is well below float's maximum binary exponent 127.
+
+ // Therefore, we just need to consider (__v.__mantissa >> _Trailing_zero_bits) * 5^_Ryu_exponent.
+
+ // If that product would exceed 24 bits, then X can't be exactly represented as a float.
+ // (That's not a problem for round-tripping, because X is close enough to the original float,
+ // but X isn't mathematically equal to the original float.) This requires a high-precision fallback.
+
+ // If the product is 24 bits or smaller, then X can be exactly represented as a float (and we don't
+ // need to re-synthesize it; the original float must have been X, because Ryu wouldn't produce the
+ // same output for two different floats X and Y). This allows Ryu's output to be used (zero-filled).
+
+ // (2^24 - 1) / 5^0 (for indexing), (2^24 - 1) / 5^1, ..., (2^24 - 1) / 5^10
+ static constexpr uint32_t _Max_shifted_mantissa[11] = {
+ 16777215, 3355443, 671088, 134217, 26843, 5368, 1073, 214, 42, 8, 1 };
+
+ unsigned long _Trailing_zero_bits;
+ (void) _BitScanForward(&_Trailing_zero_bits, __v.__mantissa); // __v.__mantissa is guaranteed nonzero
+ const uint32_t _Shifted_mantissa = __v.__mantissa >> _Trailing_zero_bits;
+ _Can_use_ryu = _Shifted_mantissa <= _Max_shifted_mantissa[_Ryu_exponent];
+ }
+
+ if (!_Can_use_ryu) {
+ const uint32_t _Mantissa2 = __ieeeMantissa | (1u << __FLOAT_MANTISSA_BITS); // restore implicit bit
+ const int32_t _Exponent2 = static_cast<int32_t>(__ieeeExponent)
+ - __FLOAT_BIAS - __FLOAT_MANTISSA_BITS; // bias and normalization
+
+ // Performance note: We've already called Ryu, so this will redundantly perform buffering and bounds checking.
+ return _Large_integer_to_chars(_First, _Last, _Mantissa2, _Exponent2);
+ }
+
+ // _Can_use_ryu
+ // Print the decimal digits, left-aligned within [_First, _First + _Total_fixed_length).
+ _Mid = _First + __olength;
+ } else { // cases "1729", "17.29", and "0.001729"
+ // Print the decimal digits, right-aligned within [_First, _First + _Total_fixed_length).
+ _Mid = _First + _Total_fixed_length;
+ }
+
+ while (_Output >= 10000) {
+#ifdef __clang__ // TRANSITION, LLVM-38217
+ const uint32_t __c = _Output - 10000 * (_Output / 10000);
+#else
+ const uint32_t __c = _Output % 10000;
+#endif
+ _Output /= 10000;
+ const uint32_t __c0 = (__c % 100) << 1;
+ const uint32_t __c1 = (__c / 100) << 1;
+ std::memcpy(_Mid -= 2, __DIGIT_TABLE + __c0, 2);
+ std::memcpy(_Mid -= 2, __DIGIT_TABLE + __c1, 2);
+ }
+ if (_Output >= 100) {
+ const uint32_t __c = (_Output % 100) << 1;
+ _Output /= 100;
+ std::memcpy(_Mid -= 2, __DIGIT_TABLE + __c, 2);
+ }
+ if (_Output >= 10) {
+ const uint32_t __c = _Output << 1;
+ std::memcpy(_Mid -= 2, __DIGIT_TABLE + __c, 2);
+ } else {
+ *--_Mid = static_cast<char>('0' + _Output);
+ }
+
+ if (_Ryu_exponent > 0) { // case "172900" with _Can_use_ryu
+ // Performance note: it might be more efficient to do this immediately after setting _Mid.
+ std::memset(_First + __olength, '0', static_cast<size_t>(_Ryu_exponent));
+ } else if (_Ryu_exponent == 0) { // case "1729"
+ // Done!
+ } else if (_Whole_digits > 0) { // case "17.29"
+ // Performance note: moving digits might not be optimal.
+ std::memmove(_First, _First + 1, static_cast<size_t>(_Whole_digits));
+ _First[_Whole_digits] = '.';
+ } else { // case "0.001729"
+ // Performance note: a larger memset() followed by overwriting '.' might be more efficient.
+ _First[0] = '0';
+ _First[1] = '.';
+ std::memset(_First + 2, '0', static_cast<size_t>(-_Whole_digits));
+ }
+
+ return { _First + _Total_fixed_length, errc{} };
+ }
+
+ const uint32_t _Total_scientific_length =
+ __olength + (__olength > 1) + 4; // digits + possible decimal point + scientific exponent
+ if (_Last - _First < static_cast<ptrdiff_t>(_Total_scientific_length)) {
+ return { _Last, errc::value_too_large };
+ }
+ char* const __result = _First;
+
+ // Print the decimal digits.
+ uint32_t __i = 0;
+ while (_Output >= 10000) {
+#ifdef __clang__ // TRANSITION, LLVM-38217
+ const uint32_t __c = _Output - 10000 * (_Output / 10000);
+#else
+ const uint32_t __c = _Output % 10000;
+#endif
+ _Output /= 10000;
+ const uint32_t __c0 = (__c % 100) << 1;
+ const uint32_t __c1 = (__c / 100) << 1;
+ std::memcpy(__result + __olength - __i - 1, __DIGIT_TABLE + __c0, 2);
+ std::memcpy(__result + __olength - __i - 3, __DIGIT_TABLE + __c1, 2);
+ __i += 4;
+ }
+ if (_Output >= 100) {
+ const uint32_t __c = (_Output % 100) << 1;
+ _Output /= 100;
+ std::memcpy(__result + __olength - __i - 1, __DIGIT_TABLE + __c, 2);
+ __i += 2;
+ }
+ if (_Output >= 10) {
+ const uint32_t __c = _Output << 1;
+ // We can't use memcpy here: the decimal dot goes between these two digits.
+ __result[2] = __DIGIT_TABLE[__c + 1];
+ __result[0] = __DIGIT_TABLE[__c];
+ } else {
+ __result[0] = static_cast<char>('0' + _Output);
+ }
+
+ // Print decimal point if needed.
+ uint32_t __index;
+ if (__olength > 1) {
+ __result[1] = '.';
+ __index = __olength + 1;
+ } else {
+ __index = 1;
+ }
+
+ // Print the exponent.
+ __result[__index++] = 'e';
+ if (_Scientific_exponent < 0) {
+ __result[__index++] = '-';
+ _Scientific_exponent = -_Scientific_exponent;
+ } else {
+ __result[__index++] = '+';
+ }
+
+ std::memcpy(__result + __index, __DIGIT_TABLE + 2 * _Scientific_exponent, 2);
+ __index += 2;
+
+ return { _First + _Total_scientific_length, errc{} };
+}
+
+[[nodiscard]] to_chars_result __f2s_buffered_n(char* const _First, char* const _Last, const float __f,
+ const chars_format _Fmt) {
+
+ // Step 1: Decode the floating-point number, and unify normalized and subnormal cases.
+ const uint32_t __bits = __float_to_bits(__f);
+
+ // Case distinction; exit early for the easy cases.
+ if (__bits == 0) {
+ if (_Fmt == chars_format::scientific) {
+ if (_Last - _First < 5) {
+ return { _Last, errc::value_too_large };
+ }
+
+ std::memcpy(_First, "0e+00", 5);
+
+ return { _First + 5, errc{} };
+ }
+
+ // Print "0" for chars_format::fixed, chars_format::general, and chars_format{}.
+ if (_First == _Last) {
+ return { _Last, errc::value_too_large };
+ }
+
+ *_First = '0';
+
+ return { _First + 1, errc{} };
+ }
+
+ // Decode __bits into mantissa and exponent.
+ const uint32_t __ieeeMantissa = __bits & ((1u << __FLOAT_MANTISSA_BITS) - 1);
+ const uint32_t __ieeeExponent = __bits >> __FLOAT_MANTISSA_BITS;
+
+ // When _Fmt == chars_format::fixed and the floating-point number is a large integer,
+ // it's faster to skip Ryu and immediately print the integer exactly.
+ if (_Fmt == chars_format::fixed) {
+ const uint32_t _Mantissa2 = __ieeeMantissa | (1u << __FLOAT_MANTISSA_BITS); // restore implicit bit
+ const int32_t _Exponent2 = static_cast<int32_t>(__ieeeExponent)
+ - __FLOAT_BIAS - __FLOAT_MANTISSA_BITS; // bias and normalization
+
+ // Normal values are equal to _Mantissa2 * 2^_Exponent2.
+ // (Subnormals are different, but they'll be rejected by the _Exponent2 test here, so they can be ignored.)
+
+ if (_Exponent2 > 0) {
+ return _Large_integer_to_chars(_First, _Last, _Mantissa2, _Exponent2);
+ }
+ }
+
+ const __floating_decimal_32 __v = __f2d(__ieeeMantissa, __ieeeExponent);
+ return __to_chars(_First, _Last, __v, _Fmt, __ieeeMantissa, __ieeeExponent);
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+// clang-format on
diff --git a/contrib/llvm-project/libcxx/src/shared_mutex.cpp b/contrib/llvm-project/libcxx/src/shared_mutex.cpp
index 5feef9f4889f..1a346dda027f 100644
--- a/contrib/llvm-project/libcxx/src/shared_mutex.cpp
+++ b/contrib/llvm-project/libcxx/src/shared_mutex.cpp
@@ -1,4 +1,4 @@
-//===---------------------- shared_mutex.cpp ------------------------------===//
+//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -6,113 +6,88 @@
//
//===----------------------------------------------------------------------===//
-#include "__config"
-#ifndef _LIBCPP_HAS_NO_THREADS
-
-#include "shared_mutex"
+#include <mutex>
+#include <shared_mutex>
#if defined(__ELF__) && defined(_LIBCPP_LINK_PTHREAD_LIB)
-#pragma comment(lib, "pthread")
+# pragma comment(lib, "pthread")
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
// Shared Mutex Base
-__shared_mutex_base::__shared_mutex_base()
- : __state_(0)
-{
-}
+__shared_mutex_base::__shared_mutex_base() : __state_(0) {}
// Exclusive ownership
-void
-__shared_mutex_base::lock()
-{
- unique_lock<mutex> lk(__mut_);
- while (__state_ & __write_entered_)
- __gate1_.wait(lk);
- __state_ |= __write_entered_;
- while (__state_ & __n_readers_)
- __gate2_.wait(lk);
+void __shared_mutex_base::lock() {
+ unique_lock<mutex> lk(__mut_);
+ while (__state_ & __write_entered_)
+ __gate1_.wait(lk);
+ __state_ |= __write_entered_;
+ while (__state_ & __n_readers_)
+ __gate2_.wait(lk);
}
-bool
-__shared_mutex_base::try_lock()
-{
- unique_lock<mutex> lk(__mut_);
- if (__state_ == 0)
- {
- __state_ = __write_entered_;
- return true;
- }
- return false;
+bool __shared_mutex_base::try_lock() {
+ unique_lock<mutex> lk(__mut_);
+ if (__state_ == 0) {
+ __state_ = __write_entered_;
+ return true;
+ }
+ return false;
}
-void
-__shared_mutex_base::unlock()
-{
- lock_guard<mutex> _(__mut_);
- __state_ = 0;
- __gate1_.notify_all();
+void __shared_mutex_base::unlock() {
+ lock_guard<mutex> _(__mut_);
+ __state_ = 0;
+ __gate1_.notify_all();
}
// Shared ownership
-void
-__shared_mutex_base::lock_shared()
-{
- unique_lock<mutex> lk(__mut_);
- while ((__state_ & __write_entered_) || (__state_ & __n_readers_) == __n_readers_)
- __gate1_.wait(lk);
- unsigned num_readers = (__state_ & __n_readers_) + 1;
- __state_ &= ~__n_readers_;
- __state_ |= num_readers;
+void __shared_mutex_base::lock_shared() {
+ unique_lock<mutex> lk(__mut_);
+ while ((__state_ & __write_entered_) || (__state_ & __n_readers_) == __n_readers_)
+ __gate1_.wait(lk);
+ unsigned num_readers = (__state_ & __n_readers_) + 1;
+ __state_ &= ~__n_readers_;
+ __state_ |= num_readers;
}
-bool
-__shared_mutex_base::try_lock_shared()
-{
- unique_lock<mutex> lk(__mut_);
- unsigned num_readers = __state_ & __n_readers_;
- if (!(__state_ & __write_entered_) && num_readers != __n_readers_)
- {
- ++num_readers;
- __state_ &= ~__n_readers_;
- __state_ |= num_readers;
- return true;
- }
- return false;
-}
-
-void
-__shared_mutex_base::unlock_shared()
-{
- lock_guard<mutex> _(__mut_);
- unsigned num_readers = (__state_ & __n_readers_) - 1;
+bool __shared_mutex_base::try_lock_shared() {
+ unique_lock<mutex> lk(__mut_);
+ unsigned num_readers = __state_ & __n_readers_;
+ if (!(__state_ & __write_entered_) && num_readers != __n_readers_) {
+ ++num_readers;
__state_ &= ~__n_readers_;
__state_ |= num_readers;
- if (__state_ & __write_entered_)
- {
- if (num_readers == 0)
- __gate2_.notify_one();
- }
- else
- {
- if (num_readers == __n_readers_ - 1)
- __gate1_.notify_one();
- }
+ return true;
+ }
+ return false;
}
+void __shared_mutex_base::unlock_shared() {
+ lock_guard<mutex> _(__mut_);
+ unsigned num_readers = (__state_ & __n_readers_) - 1;
+ __state_ &= ~__n_readers_;
+ __state_ |= num_readers;
+ if (__state_ & __write_entered_) {
+ if (num_readers == 0)
+ __gate2_.notify_one();
+ } else {
+ if (num_readers == __n_readers_ - 1)
+ __gate1_.notify_one();
+ }
+}
// Shared Timed Mutex
// These routines are here for ABI stability
-shared_timed_mutex::shared_timed_mutex() : __base() {}
-void shared_timed_mutex::lock() { return __base.lock(); }
-bool shared_timed_mutex::try_lock() { return __base.try_lock(); }
-void shared_timed_mutex::unlock() { return __base.unlock(); }
-void shared_timed_mutex::lock_shared() { return __base.lock_shared(); }
-bool shared_timed_mutex::try_lock_shared() { return __base.try_lock_shared(); }
-void shared_timed_mutex::unlock_shared() { return __base.unlock_shared(); }
+shared_timed_mutex::shared_timed_mutex() : __base_() {}
+void shared_timed_mutex::lock() { return __base_.lock(); }
+bool shared_timed_mutex::try_lock() { return __base_.try_lock(); }
+void shared_timed_mutex::unlock() { return __base_.unlock(); }
+void shared_timed_mutex::lock_shared() { return __base_.lock_shared(); }
+bool shared_timed_mutex::try_lock_shared() { return __base_.try_lock_shared(); }
+void shared_timed_mutex::unlock_shared() { return __base_.unlock_shared(); }
_LIBCPP_END_NAMESPACE_STD
-
-#endif // !_LIBCPP_HAS_NO_THREADS
diff --git a/contrib/llvm-project/libcxx/src/std_stream.h b/contrib/llvm-project/libcxx/src/std_stream.h
new file mode 100644
index 000000000000..e55cd0b6b77a
--- /dev/null
+++ b/contrib/llvm-project/libcxx/src/std_stream.h
@@ -0,0 +1,387 @@
+// -*- 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_STD_STREAM_H
+#define _LIBCPP_STD_STREAM_H
+
+#include <__config>
+#include <__locale>
+#include <cstdio>
+#include <istream>
+#include <ostream>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+# pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+static const int __limit = 8;
+
+// __stdinbuf
+
+template <class _CharT>
+class _LIBCPP_HIDDEN __stdinbuf : public basic_streambuf<_CharT, char_traits<_CharT> > {
+public:
+ typedef _CharT char_type;
+ typedef char_traits<char_type> traits_type;
+ typedef typename traits_type::int_type int_type;
+ typedef typename traits_type::pos_type pos_type;
+ typedef typename traits_type::off_type off_type;
+ typedef typename traits_type::state_type state_type;
+
+ __stdinbuf(FILE* __fp, state_type* __st);
+
+protected:
+ virtual int_type underflow();
+ virtual int_type uflow();
+ virtual int_type pbackfail(int_type __c = traits_type::eof());
+ virtual void imbue(const locale& __loc);
+
+private:
+ FILE* __file_;
+ const codecvt<char_type, char, state_type>* __cv_;
+ state_type* __st_;
+ int __encoding_;
+ int_type __last_consumed_;
+ bool __last_consumed_is_next_;
+ bool __always_noconv_;
+
+#if defined(_LIBCPP_WIN32API)
+ static constexpr bool __is_win32api_wide_char = !is_same_v<_CharT, char>;
+#else
+ static constexpr bool __is_win32api_wide_char = false;
+#endif
+
+ __stdinbuf(const __stdinbuf&);
+ __stdinbuf& operator=(const __stdinbuf&);
+
+ int_type __getchar(bool __consume);
+};
+
+template <class _CharT>
+__stdinbuf<_CharT>::__stdinbuf(FILE* __fp, state_type* __st)
+ : __file_(__fp), __st_(__st), __last_consumed_(traits_type::eof()), __last_consumed_is_next_(false) {
+ imbue(this->getloc());
+ // On Windows, in wchar_t mode, ignore the codecvt from the locale by
+ // default and assume noconv; this passes wchar_t through unmodified from
+ // getwc. If the user sets a custom locale with imbue(), that gets honored,
+ // the IO is done with getc() and converted with the provided codecvt.
+ if constexpr (__is_win32api_wide_char)
+ __always_noconv_ = true;
+}
+
+template <class _CharT>
+void __stdinbuf<_CharT>::imbue(const locale& __loc) {
+ __cv_ = &use_facet<codecvt<char_type, char, state_type> >(__loc);
+ __encoding_ = __cv_->encoding();
+ __always_noconv_ = __cv_->always_noconv();
+ if (__encoding_ > __limit)
+ __throw_runtime_error("unsupported locale for standard input");
+}
+
+template <class _CharT>
+typename __stdinbuf<_CharT>::int_type __stdinbuf<_CharT>::underflow() {
+ return __getchar(false);
+}
+
+template <class _CharT>
+typename __stdinbuf<_CharT>::int_type __stdinbuf<_CharT>::uflow() {
+ return __getchar(true);
+}
+
+inline bool __do_getc(FILE* __fp, char* __pbuf) {
+ int __c = getc(__fp);
+ if (__c == EOF)
+ return false;
+ *__pbuf = static_cast<char>(__c);
+ return true;
+}
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+inline bool __do_getc(FILE* __fp, wchar_t* __pbuf) {
+ wint_t __c = getwc(__fp);
+ if (__c == WEOF)
+ return false;
+ *__pbuf = static_cast<wchar_t>(__c);
+ return true;
+}
+#endif
+
+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
+inline bool __do_ungetc(std::wint_t __c, FILE* __fp, wchar_t __dummy) {
+ if (ungetwc(__c, __fp) == WEOF)
+ return false;
+ return true;
+}
+#endif
+
+template <class _CharT>
+typename __stdinbuf<_CharT>::int_type __stdinbuf<_CharT>::__getchar(bool __consume) {
+ if (__last_consumed_is_next_) {
+ int_type __result = __last_consumed_;
+ if (__consume) {
+ __last_consumed_ = traits_type::eof();
+ __last_consumed_is_next_ = false;
+ }
+ return __result;
+ }
+ if (__always_noconv_) {
+ char_type __1buf;
+ if (!__do_getc(__file_, &__1buf))
+ return traits_type::eof();
+ if (!__consume) {
+ if (!__do_ungetc(traits_type::to_int_type(__1buf), __file_, __1buf))
+ return traits_type::eof();
+ } else
+ __last_consumed_ = traits_type::to_int_type(__1buf);
+ return traits_type::to_int_type(__1buf);
+ }
+
+ char __extbuf[__limit];
+ int __nread = std::max(1, __encoding_);
+ for (int __i = 0; __i < __nread; ++__i) {
+ int __c = getc(__file_);
+ if (__c == EOF)
+ return traits_type::eof();
+ __extbuf[__i] = static_cast<char>(__c);
+ }
+ char_type __1buf;
+ const char* __enxt;
+ char_type* __inxt;
+ codecvt_base::result __r;
+ do {
+ state_type __sv_st = *__st_;
+ __r = __cv_->in(*__st_, __extbuf, __extbuf + __nread, __enxt, &__1buf, &__1buf + 1, __inxt);
+ switch (__r) {
+ case std::codecvt_base::ok:
+ break;
+ case codecvt_base::partial:
+ *__st_ = __sv_st;
+ if (__nread == sizeof(__extbuf))
+ return traits_type::eof();
+ {
+ int __c = getc(__file_);
+ if (__c == EOF)
+ return traits_type::eof();
+ __extbuf[__nread] = static_cast<char>(__c);
+ }
+ ++__nread;
+ break;
+ case codecvt_base::error:
+ return traits_type::eof();
+ case std::codecvt_base::noconv:
+ __1buf = static_cast<char_type>(__extbuf[0]);
+ break;
+ }
+ } while (__r == std::codecvt_base::partial);
+ if (!__consume) {
+ for (int __i = __nread; __i > 0;) {
+ if (ungetc(traits_type::to_int_type(__extbuf[--__i]), __file_) == EOF)
+ return traits_type::eof();
+ }
+ } else
+ __last_consumed_ = traits_type::to_int_type(__1buf);
+ return traits_type::to_int_type(__1buf);
+}
+
+template <class _CharT>
+typename __stdinbuf<_CharT>::int_type __stdinbuf<_CharT>::pbackfail(int_type __c) {
+ if (traits_type::eq_int_type(__c, traits_type::eof())) {
+ if (!__last_consumed_is_next_) {
+ __c = __last_consumed_;
+ __last_consumed_is_next_ = !traits_type::eq_int_type(__last_consumed_, traits_type::eof());
+ }
+ return __c;
+ }
+ if (__always_noconv_ && __last_consumed_is_next_) {
+ if (!__do_ungetc(__last_consumed_, __file_, traits_type::to_char_type(__last_consumed_)))
+ return traits_type::eof();
+ } else if (__last_consumed_is_next_) {
+ char __extbuf[__limit];
+ char* __enxt;
+ const char_type __ci = traits_type::to_char_type(__last_consumed_);
+ const char_type* __inxt;
+ switch (__cv_->out(*__st_, &__ci, &__ci + 1, __inxt, __extbuf, __extbuf + sizeof(__extbuf), __enxt)) {
+ case std::codecvt_base::ok:
+ break;
+ case std::codecvt_base::noconv:
+ __extbuf[0] = static_cast<char>(__last_consumed_);
+ __enxt = __extbuf + 1;
+ break;
+ case codecvt_base::partial:
+ case codecvt_base::error:
+ return traits_type::eof();
+ }
+ while (__enxt > __extbuf)
+ if (ungetc(*--__enxt, __file_) == EOF)
+ return traits_type::eof();
+ }
+ __last_consumed_ = __c;
+ __last_consumed_is_next_ = true;
+ return __c;
+}
+
+// __stdoutbuf
+
+template <class _CharT>
+class _LIBCPP_HIDDEN __stdoutbuf : public basic_streambuf<_CharT, char_traits<_CharT> > {
+public:
+ typedef _CharT char_type;
+ typedef char_traits<char_type> traits_type;
+ typedef typename traits_type::int_type int_type;
+ typedef typename traits_type::pos_type pos_type;
+ typedef typename traits_type::off_type off_type;
+ typedef typename traits_type::state_type state_type;
+
+ __stdoutbuf(FILE* __fp, state_type* __st);
+
+protected:
+ virtual int_type overflow(int_type __c = traits_type::eof());
+ virtual streamsize xsputn(const char_type* __s, streamsize __n);
+ virtual int sync();
+ virtual void imbue(const locale& __loc);
+
+private:
+ FILE* __file_;
+ const codecvt<char_type, char, state_type>* __cv_;
+ state_type* __st_;
+ bool __always_noconv_;
+
+#if defined(_LIBCPP_WIN32API)
+ static constexpr bool __is_win32api_wide_char = !is_same_v<_CharT, char>;
+#else
+ static constexpr bool __is_win32api_wide_char = false;
+#endif
+
+ __stdoutbuf(const __stdoutbuf&);
+ __stdoutbuf& operator=(const __stdoutbuf&);
+
+ _LIBCPP_EXPORTED_FROM_ABI friend FILE* __get_ostream_file(ostream&);
+};
+
+template <class _CharT>
+__stdoutbuf<_CharT>::__stdoutbuf(FILE* __fp, state_type* __st)
+ : __file_(__fp),
+ __cv_(&use_facet<codecvt<char_type, char, state_type> >(this->getloc())),
+ __st_(__st),
+ __always_noconv_(__cv_->always_noconv()) {
+ // On Windows, in wchar_t mode, ignore the codecvt from the locale by
+ // default and assume noconv; this passes wchar_t through unmodified to
+ // fputwc, which handles it correctly depending on the actual mode of the
+ // output stream. If the user sets a custom locale with imbue(), that
+ // gets honored.
+ if constexpr (__is_win32api_wide_char)
+ __always_noconv_ = true;
+}
+
+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
+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.
+ if (fputwc(__c, __fp) == WEOF)
+ return false;
+ return true;
+}
+#endif
+
+template <class _CharT>
+typename __stdoutbuf<_CharT>::int_type __stdoutbuf<_CharT>::overflow(int_type __c) {
+ char __extbuf[__limit];
+ char_type __1buf;
+ if (!traits_type::eq_int_type(__c, traits_type::eof())) {
+ __1buf = traits_type::to_char_type(__c);
+ if (__always_noconv_) {
+ if (!__do_fputc(__1buf, __file_))
+ return traits_type::eof();
+ } else {
+ char* __extbe = __extbuf;
+ codecvt_base::result __r;
+ char_type* pbase = &__1buf;
+ char_type* pptr = pbase + 1;
+ do {
+ const char_type* __e;
+ __r = __cv_->out(*__st_, pbase, pptr, __e, __extbuf, __extbuf + sizeof(__extbuf), __extbe);
+ if (__e == pbase)
+ return traits_type::eof();
+ if (__r == codecvt_base::noconv) {
+ if (fwrite(pbase, 1, 1, __file_) != 1)
+ return traits_type::eof();
+ } else if (__r == codecvt_base::ok || __r == codecvt_base::partial) {
+ size_t __nmemb = static_cast<size_t>(__extbe - __extbuf);
+ if (fwrite(__extbuf, 1, __nmemb, __file_) != __nmemb)
+ return traits_type::eof();
+ if (__r == codecvt_base::partial) {
+ pbase = const_cast<char_type*>(__e);
+ }
+ } else
+ return traits_type::eof();
+ } while (__r == codecvt_base::partial);
+ }
+ }
+ return traits_type::not_eof(__c);
+}
+
+template <class _CharT>
+streamsize __stdoutbuf<_CharT>::xsputn(const char_type* __s, streamsize __n) {
+ // For wchar_t on Windows, don't call fwrite(), but write characters one
+ // at a time with fputwc(); that works both when stdout is in the default
+ // mode and when it is set to Unicode mode.
+ if (__always_noconv_ && !__is_win32api_wide_char)
+ return fwrite(__s, sizeof(char_type), __n, __file_);
+ streamsize __i = 0;
+ for (; __i < __n; ++__i, ++__s)
+ if (overflow(traits_type::to_int_type(*__s)) == traits_type::eof())
+ break;
+ return __i;
+}
+
+template <class _CharT>
+int __stdoutbuf<_CharT>::sync() {
+ char __extbuf[__limit];
+ codecvt_base::result __r;
+ do {
+ char* __extbe;
+ __r = __cv_->unshift(*__st_, __extbuf, __extbuf + sizeof(__extbuf), __extbe);
+ size_t __nmemb = static_cast<size_t>(__extbe - __extbuf);
+ if (fwrite(__extbuf, 1, __nmemb, __file_) != __nmemb)
+ return -1;
+ } while (__r == codecvt_base::partial);
+ if (__r == codecvt_base::error)
+ return -1;
+ if (fflush(__file_))
+ return -1;
+ return 0;
+}
+
+template <class _CharT>
+void __stdoutbuf<_CharT>::imbue(const locale& __loc) {
+ sync();
+ __cv_ = &use_facet<codecvt<char_type, char, state_type> >(__loc);
+ __always_noconv_ = __cv_->always_noconv();
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP_STD_STREAM_H
diff --git a/contrib/llvm-project/libcxx/src/stdexcept.cpp b/contrib/llvm-project/libcxx/src/stdexcept.cpp
index f8f335f34ae1..bc25c0f9e6ef 100644
--- a/contrib/llvm-project/libcxx/src/stdexcept.cpp
+++ b/contrib/llvm-project/libcxx/src/stdexcept.cpp
@@ -1,4 +1,4 @@
-//===------------------------ stdexcept.cpp -------------------------------===//
+//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -6,14 +6,25 @@
//
//===----------------------------------------------------------------------===//
-#include "stdexcept"
-#include "new"
-#include "string"
-#include "system_error"
-
+#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/llvm-project/libcxx/src/string.cpp b/contrib/llvm-project/libcxx/src/string.cpp
index 5105594cf38b..cf07b3ef1ef2 100644
--- a/contrib/llvm-project/libcxx/src/string.cpp
+++ b/contrib/llvm-project/libcxx/src/string.cpp
@@ -1,4 +1,4 @@
-//===------------------------- string.cpp ---------------------------------===//
+//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -6,458 +6,342 @@
//
//===----------------------------------------------------------------------===//
-#include "string"
-#include "charconv"
-#include "cstdlib"
-#include "cwchar"
-#include "cerrno"
-#include "limits"
-#include "stdexcept"
-#include <stdio.h>
-#include "__debug"
+#include <__assert>
+#include <cerrno>
+#include <charconv>
+#include <cstdlib>
+#include <limits>
+#include <stdexcept>
+#include <string>
+
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+# include <cwchar>
+#endif
_LIBCPP_BEGIN_NAMESPACE_STD
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __basic_string_common<true>;
+#ifndef _LIBCPP_ABI_DO_NOT_EXPORT_BASIC_STRING_COMMON
+
+template <bool>
+struct __basic_string_common;
+
+// The struct isn't declared anymore in the headers. It's only here for ABI compatibility.
+template <>
+struct __basic_string_common<true> {
+ _LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void __throw_length_error() const;
+ _LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void __throw_out_of_range() const;
+};
+
+void __basic_string_common<true>::__throw_length_error() const { std::__throw_length_error("basic_string"); }
+void __basic_string_common<true>::__throw_out_of_range() const { std::__throw_out_of_range("basic_string"); }
+#endif // _LIBCPP_ABI_DO_NOT_EXPORT_BASIC_STRING_COMMON
+
+#define _LIBCPP_EXTERN_TEMPLATE_DEFINE(...) template __VA_ARGS__;
#ifdef _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION
_LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE_DEFINE, char)
+# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
_LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE_DEFINE, wchar_t)
+# endif
#else
_LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE_DEFINE, char)
+# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
_LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE_DEFINE, wchar_t)
+# endif
#endif
+#undef _LIBCPP_EXTERN_TEMPLATE_DEFINE
-template
- string
- operator+<char, char_traits<char>, allocator<char> >(char const*, string const&);
+template string operator+ <char, char_traits<char>, allocator<char>>(char const*, string const&);
-namespace
-{
+namespace {
-template<typename T>
-inline
-void throw_helper( const string& msg )
-{
-#ifndef _LIBCPP_NO_EXCEPTIONS
- throw T( msg );
-#else
- fprintf(stderr, "%s\n", msg.c_str());
- _VSTD::abort();
-#endif
+inline void throw_from_string_out_of_range(const string& func) {
+ std::__throw_out_of_range((func + ": out of range").c_str());
}
-inline
-void throw_from_string_out_of_range( const string& func )
-{
- throw_helper<out_of_range>(func + ": out of range");
-}
-
-inline
-void throw_from_string_invalid_arg( const string& func )
-{
- throw_helper<invalid_argument>(func + ": no conversion");
+inline void throw_from_string_invalid_arg(const string& func) {
+ std::__throw_invalid_argument((func + ": no conversion").c_str());
}
// as_integer
-template<typename V, typename S, typename F>
-inline
-V
-as_integer_helper(const string& func, const S& str, size_t* idx, int base, F f)
-{
- typename S::value_type* ptr = nullptr;
- const typename S::value_type* const p = str.c_str();
- typename remove_reference<decltype(errno)>::type errno_save = errno;
- errno = 0;
- V r = f(p, &ptr, base);
- swap(errno, errno_save);
- if (errno_save == ERANGE)
- throw_from_string_out_of_range(func);
- if (ptr == p)
- throw_from_string_invalid_arg(func);
- if (idx)
- *idx = static_cast<size_t>(ptr - p);
- return r;
-}
-
-template<typename V, typename S>
-inline
-V
-as_integer(const string& func, const S& s, size_t* idx, int base);
+template <typename V, typename S, typename F>
+inline V as_integer_helper(const string& func, const S& str, size_t* idx, int base, F f) {
+ typename S::value_type* ptr = nullptr;
+ const typename S::value_type* const p = str.c_str();
+ __libcpp_remove_reference_t<decltype(errno)> errno_save = errno;
+ errno = 0;
+ V r = f(p, &ptr, base);
+ swap(errno, errno_save);
+ if (errno_save == ERANGE)
+ throw_from_string_out_of_range(func);
+ if (ptr == p)
+ throw_from_string_invalid_arg(func);
+ if (idx)
+ *idx = static_cast<size_t>(ptr - p);
+ return r;
+}
+
+template <typename V, typename S>
+inline V as_integer(const string& func, const S& s, size_t* idx, int base);
// string
-template<>
-inline
-int
-as_integer(const string& func, const string& s, size_t* idx, int base )
-{
- // Use long as no Standard string to integer exists.
- long r = as_integer_helper<long>( func, s, idx, base, strtol );
- if (r < numeric_limits<int>::min() || numeric_limits<int>::max() < r)
- throw_from_string_out_of_range(func);
- return static_cast<int>(r);
+template <>
+inline int as_integer(const string& func, const string& s, size_t* idx, int base) {
+ // Use long as no Standard string to integer exists.
+ long r = as_integer_helper<long>(func, s, idx, base, strtol);
+ if (r < numeric_limits<int>::min() || numeric_limits<int>::max() < r)
+ throw_from_string_out_of_range(func);
+ return static_cast<int>(r);
}
-template<>
-inline
-long
-as_integer(const string& func, const string& s, size_t* idx, int base )
-{
- return as_integer_helper<long>( func, s, idx, base, strtol );
+template <>
+inline long as_integer(const string& func, const string& s, size_t* idx, int base) {
+ return as_integer_helper<long>(func, s, idx, base, strtol);
}
-template<>
-inline
-unsigned long
-as_integer( const string& func, const string& s, size_t* idx, int base )
-{
- return as_integer_helper<unsigned long>( func, s, idx, base, strtoul );
+template <>
+inline unsigned long as_integer(const string& func, const string& s, size_t* idx, int base) {
+ return as_integer_helper<unsigned long>(func, s, idx, base, strtoul);
}
-template<>
-inline
-long long
-as_integer( const string& func, const string& s, size_t* idx, int base )
-{
- return as_integer_helper<long long>( func, s, idx, base, strtoll );
+template <>
+inline long long as_integer(const string& func, const string& s, size_t* idx, int base) {
+ return as_integer_helper<long long>(func, s, idx, base, strtoll);
}
-template<>
-inline
-unsigned long long
-as_integer( const string& func, const string& s, size_t* idx, int base )
-{
- return as_integer_helper<unsigned long long>( func, s, idx, base, strtoull );
+template <>
+inline unsigned long long as_integer(const string& func, const string& s, size_t* idx, int base) {
+ return as_integer_helper<unsigned long long>(func, s, idx, base, strtoull);
}
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
// wstring
-template<>
-inline
-int
-as_integer( const string& func, const wstring& s, size_t* idx, int base )
-{
- // Use long as no Stantard string to integer exists.
- long r = as_integer_helper<long>( func, s, idx, base, wcstol );
- if (r < numeric_limits<int>::min() || numeric_limits<int>::max() < r)
- throw_from_string_out_of_range(func);
- return static_cast<int>(r);
+template <>
+inline int as_integer(const string& func, const wstring& s, size_t* idx, int base) {
+ // Use long as no Stantard string to integer exists.
+ long r = as_integer_helper<long>(func, s, idx, base, wcstol);
+ if (r < numeric_limits<int>::min() || numeric_limits<int>::max() < r)
+ throw_from_string_out_of_range(func);
+ return static_cast<int>(r);
}
-template<>
-inline
-long
-as_integer( const string& func, const wstring& s, size_t* idx, int base )
-{
- return as_integer_helper<long>( func, s, idx, base, wcstol );
+template <>
+inline long as_integer(const string& func, const wstring& s, size_t* idx, int base) {
+ return as_integer_helper<long>(func, s, idx, base, wcstol);
}
-template<>
-inline
-unsigned long
-as_integer( const string& func, const wstring& s, size_t* idx, int base )
-{
- return as_integer_helper<unsigned long>( func, s, idx, base, wcstoul );
+template <>
+inline unsigned long as_integer(const string& func, const wstring& s, size_t* idx, int base) {
+ return as_integer_helper<unsigned long>(func, s, idx, base, wcstoul);
}
-template<>
-inline
-long long
-as_integer( const string& func, const wstring& s, size_t* idx, int base )
-{
- return as_integer_helper<long long>( func, s, idx, base, wcstoll );
+template <>
+inline long long as_integer(const string& func, const wstring& s, size_t* idx, int base) {
+ return as_integer_helper<long long>(func, s, idx, base, wcstoll);
}
-template<>
-inline
-unsigned long long
-as_integer( const string& func, const wstring& s, size_t* idx, int base )
-{
- return as_integer_helper<unsigned long long>( func, s, idx, base, wcstoull );
+template <>
+inline unsigned long long as_integer(const string& func, const wstring& s, size_t* idx, int base) {
+ return as_integer_helper<unsigned long long>(func, s, idx, base, wcstoull);
}
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
// as_float
-template<typename V, typename S, typename F>
-inline
-V
-as_float_helper(const string& func, const S& str, size_t* idx, F f )
-{
- typename S::value_type* ptr = nullptr;
- const typename S::value_type* const p = str.c_str();
- typename remove_reference<decltype(errno)>::type errno_save = errno;
- errno = 0;
- V r = f(p, &ptr);
- swap(errno, errno_save);
- if (errno_save == ERANGE)
- throw_from_string_out_of_range(func);
- if (ptr == p)
- throw_from_string_invalid_arg(func);
- if (idx)
- *idx = static_cast<size_t>(ptr - p);
- return r;
-}
+template <typename V, typename S, typename F>
+inline V as_float_helper(const string& func, const S& str, size_t* idx, F f) {
+ typename S::value_type* ptr = nullptr;
+ const typename S::value_type* const p = str.c_str();
+ __libcpp_remove_reference_t<decltype(errno)> errno_save = errno;
+ errno = 0;
+ V r = f(p, &ptr);
+ swap(errno, errno_save);
+ if (errno_save == ERANGE)
+ throw_from_string_out_of_range(func);
+ if (ptr == p)
+ throw_from_string_invalid_arg(func);
+ if (idx)
+ *idx = static_cast<size_t>(ptr - p);
+ return r;
+}
+
+template <typename V, typename S>
+inline V as_float(const string& func, const S& s, size_t* idx = nullptr);
-template<typename V, typename S>
-inline
-V as_float( const string& func, const S& s, size_t* idx = nullptr );
-
-template<>
-inline
-float
-as_float( const string& func, const string& s, size_t* idx )
-{
- return as_float_helper<float>( func, s, idx, strtof );
+template <>
+inline float as_float(const string& func, const string& s, size_t* idx) {
+ return as_float_helper<float>(func, s, idx, strtof);
}
-template<>
-inline
-double
-as_float(const string& func, const string& s, size_t* idx )
-{
- return as_float_helper<double>( func, s, idx, strtod );
+template <>
+inline double as_float(const string& func, const string& s, size_t* idx) {
+ return as_float_helper<double>(func, s, idx, strtod);
}
-template<>
-inline
-long double
-as_float( const string& func, const string& s, size_t* idx )
-{
- return as_float_helper<long double>( func, s, idx, strtold );
+template <>
+inline long double as_float(const string& func, const string& s, size_t* idx) {
+ return as_float_helper<long double>(func, s, idx, strtold);
}
-template<>
-inline
-float
-as_float( const string& func, const wstring& s, size_t* idx )
-{
- return as_float_helper<float>( func, s, idx, wcstof );
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+template <>
+inline float as_float(const string& func, const wstring& s, size_t* idx) {
+ return as_float_helper<float>(func, s, idx, wcstof);
}
-template<>
-inline
-double
-as_float( const string& func, const wstring& s, size_t* idx )
-{
- return as_float_helper<double>( func, s, idx, wcstod );
+template <>
+inline double as_float(const string& func, const wstring& s, size_t* idx) {
+ return as_float_helper<double>(func, s, idx, wcstod);
}
-template<>
-inline
-long double
-as_float( const string& func, const wstring& s, size_t* idx )
-{
- return as_float_helper<long double>( func, s, idx, wcstold );
+template <>
+inline long double as_float(const string& func, const wstring& s, size_t* idx) {
+ return as_float_helper<long double>(func, s, idx, wcstold);
}
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
-} // unnamed namespace
+} // unnamed namespace
-int
-stoi(const string& str, size_t* idx, int base)
-{
- return as_integer<int>( "stoi", str, idx, base );
-}
+int stoi(const string& str, size_t* idx, int base) { return as_integer<int>("stoi", str, idx, base); }
-int
-stoi(const wstring& str, size_t* idx, int base)
-{
- return as_integer<int>( "stoi", str, idx, base );
-}
+long stol(const string& str, size_t* idx, int base) { return as_integer<long>("stol", str, idx, base); }
-long
-stol(const string& str, size_t* idx, int base)
-{
- return as_integer<long>( "stol", str, idx, base );
+unsigned long stoul(const string& str, size_t* idx, int base) {
+ return as_integer<unsigned long>("stoul", str, idx, base);
}
-long
-stol(const wstring& str, size_t* idx, int base)
-{
- return as_integer<long>( "stol", str, idx, base );
-}
+long long stoll(const string& str, size_t* idx, int base) { return as_integer<long long>("stoll", str, idx, base); }
-unsigned long
-stoul(const string& str, size_t* idx, int base)
-{
- return as_integer<unsigned long>( "stoul", str, idx, base );
+unsigned long long stoull(const string& str, size_t* idx, int base) {
+ return as_integer<unsigned long long>("stoull", str, idx, base);
}
-unsigned long
-stoul(const wstring& str, size_t* idx, int base)
-{
- return as_integer<unsigned long>( "stoul", str, idx, base );
-}
+float stof(const string& str, size_t* idx) { return as_float<float>("stof", str, idx); }
-long long
-stoll(const string& str, size_t* idx, int base)
-{
- return as_integer<long long>( "stoll", str, idx, base );
-}
+double stod(const string& str, size_t* idx) { return as_float<double>("stod", str, idx); }
-long long
-stoll(const wstring& str, size_t* idx, int base)
-{
- return as_integer<long long>( "stoll", str, idx, base );
-}
+long double stold(const string& str, size_t* idx) { return as_float<long double>("stold", str, idx); }
-unsigned long long
-stoull(const string& str, size_t* idx, int base)
-{
- return as_integer<unsigned long long>( "stoull", str, idx, base );
-}
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+int stoi(const wstring& str, size_t* idx, int base) { return as_integer<int>("stoi", str, idx, base); }
-unsigned long long
-stoull(const wstring& str, size_t* idx, int base)
-{
- return as_integer<unsigned long long>( "stoull", str, idx, base );
-}
+long stol(const wstring& str, size_t* idx, int base) { return as_integer<long>("stol", str, idx, base); }
-float
-stof(const string& str, size_t* idx)
-{
- return as_float<float>( "stof", str, idx );
+unsigned long stoul(const wstring& str, size_t* idx, int base) {
+ return as_integer<unsigned long>("stoul", str, idx, base);
}
-float
-stof(const wstring& str, size_t* idx)
-{
- return as_float<float>( "stof", str, idx );
-}
+long long stoll(const wstring& str, size_t* idx, int base) { return as_integer<long long>("stoll", str, idx, base); }
-double
-stod(const string& str, size_t* idx)
-{
- return as_float<double>( "stod", str, idx );
+unsigned long long stoull(const wstring& str, size_t* idx, int base) {
+ return as_integer<unsigned long long>("stoull", str, idx, base);
}
-double
-stod(const wstring& str, size_t* idx)
-{
- return as_float<double>( "stod", str, idx );
-}
+float stof(const wstring& str, size_t* idx) { return as_float<float>("stof", str, idx); }
-long double
-stold(const string& str, size_t* idx)
-{
- return as_float<long double>( "stold", str, idx );
-}
+double stod(const wstring& str, size_t* idx) { return as_float<double>("stod", str, idx); }
-long double
-stold(const wstring& str, size_t* idx)
-{
- return as_float<long double>( "stold", str, idx );
-}
+long double stold(const wstring& str, size_t* idx) { return as_float<long double>("stold", str, idx); }
+#endif // !_LIBCPP_HAS_NO_WIDE_CHARACTERS
// to_string
-namespace
-{
+namespace {
// as_string
-template<typename S, typename P, typename V >
-inline
-S
-as_string(P sprintf_like, S s, const typename S::value_type* fmt, V a)
-{
- typedef typename S::size_type size_type;
- size_type available = s.size();
- while (true)
- {
- int status = sprintf_like(&s[0], available + 1, fmt, a);
- if ( status >= 0 )
- {
- size_type used = static_cast<size_type>(status);
- if ( used <= available )
- {
- s.resize( used );
- break;
- }
- available = used; // Assume this is advice of how much space we need.
- }
- else
- available = available * 2 + 1;
- s.resize(available);
- }
- return s;
+template <typename S, typename P, typename V >
+inline S as_string(P sprintf_like, S s, const typename S::value_type* fmt, V a) {
+ typedef typename S::size_type size_type;
+ size_type available = s.size();
+ while (true) {
+ int status = sprintf_like(&s[0], available + 1, fmt, a);
+ if (status >= 0) {
+ size_type used = static_cast<size_type>(status);
+ if (used <= available) {
+ s.resize(used);
+ break;
+ }
+ available = used; // Assume this is advice of how much space we need.
+ } else
+ available = available * 2 + 1;
+ s.resize(available);
+ }
+ return s;
}
template <class S>
struct initial_string;
template <>
-struct initial_string<string>
-{
- string
- operator()() const
- {
- string s;
- s.resize(s.capacity());
- return s;
- }
+struct initial_string<string> {
+ string operator()() const {
+ string s;
+ s.resize(s.capacity());
+ return s;
+ }
};
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
template <>
-struct initial_string<wstring>
-{
- wstring
- operator()() const
- {
- wstring s(20, wchar_t());
- s.resize(s.capacity());
- return s;
- }
+struct initial_string<wstring> {
+ wstring operator()() const {
+ wstring s(20, wchar_t());
+ s.resize(s.capacity());
+ return s;
+ }
};
-typedef int (*wide_printf)(wchar_t* __restrict, size_t, const wchar_t*__restrict, ...);
+typedef int (*wide_printf)(wchar_t* __restrict, size_t, const wchar_t* __restrict, ...);
-inline
-wide_printf
-get_swprintf()
-{
-#ifndef _LIBCPP_MSVCRT
- return swprintf;
-#else
- return static_cast<int (__cdecl*)(wchar_t* __restrict, size_t, const wchar_t*__restrict, ...)>(_snwprintf);
-#endif
+inline wide_printf get_swprintf() {
+# ifndef _LIBCPP_MSVCRT
+ return swprintf;
+# else
+ return static_cast<int(__cdecl*)(wchar_t* __restrict, size_t, const wchar_t* __restrict, ...)>(_snwprintf);
+# endif
}
+#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
template <typename S, typename V>
-S i_to_string(const V v)
-{
-// numeric_limits::digits10 returns value less on 1 than desired for unsigned numbers.
-// For example, for 1-byte unsigned value digits10 is 2 (999 can not be represented),
-// so we need +1 here.
- constexpr size_t bufsize = numeric_limits<V>::digits10 + 2; // +1 for minus, +1 for digits10
- char buf[bufsize];
- const auto res = to_chars(buf, buf + bufsize, v);
- _LIBCPP_ASSERT(res.ec == errc(), "bufsize must be large enough to accomodate the value");
- return S(buf, res.ptr);
-}
-
-} // unnamed namespace
-
-string to_string (int val) { return i_to_string< string>(val); }
-string to_string (long val) { return i_to_string< string>(val); }
-string to_string (long long val) { return i_to_string< string>(val); }
-string to_string (unsigned val) { return i_to_string< string>(val); }
-string to_string (unsigned long val) { return i_to_string< string>(val); }
-string to_string (unsigned long long val) { return i_to_string< string>(val); }
-
-wstring to_wstring(int val) { return i_to_string<wstring>(val); }
-wstring to_wstring(long val) { return i_to_string<wstring>(val); }
-wstring to_wstring(long long val) { return i_to_string<wstring>(val); }
-wstring to_wstring(unsigned val) { return i_to_string<wstring>(val); }
-wstring to_wstring(unsigned long val) { return i_to_string<wstring>(val); }
+S i_to_string(V v) {
+ // numeric_limits::digits10 returns value less on 1 than desired for unsigned numbers.
+ // For example, for 1-byte unsigned value digits10 is 2 (999 can not be represented),
+ // so we need +1 here.
+ constexpr size_t bufsize = numeric_limits<V>::digits10 + 2; // +1 for minus, +1 for digits10
+ char buf[bufsize];
+ const auto res = to_chars(buf, buf + bufsize, v);
+ _LIBCPP_ASSERT_INTERNAL(res.ec == errc(), "bufsize must be large enough to accomodate the value");
+ return S(buf, res.ptr);
+}
+
+} // unnamed namespace
+
+string to_string(int val) { return i_to_string< string>(val); }
+string to_string(long val) { return i_to_string< string>(val); }
+string to_string(long long val) { return i_to_string< string>(val); }
+string to_string(unsigned val) { return i_to_string< string>(val); }
+string to_string(unsigned long val) { return i_to_string< string>(val); }
+string to_string(unsigned long long val) { return i_to_string< string>(val); }
+
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+wstring to_wstring(int val) { return i_to_string<wstring>(val); }
+wstring to_wstring(long val) { return i_to_string<wstring>(val); }
+wstring to_wstring(long long val) { return i_to_string<wstring>(val); }
+wstring to_wstring(unsigned val) { return i_to_string<wstring>(val); }
+wstring to_wstring(unsigned long val) { return i_to_string<wstring>(val); }
wstring to_wstring(unsigned long long val) { return i_to_string<wstring>(val); }
+#endif
+string to_string(float val) { return as_string(snprintf, initial_string< string>()(), "%f", val); }
+string to_string(double val) { return as_string(snprintf, initial_string< string>()(), "%f", val); }
+string to_string(long double val) { return as_string(snprintf, initial_string< string>()(), "%Lf", val); }
-string to_string (float val) { return as_string(snprintf, initial_string< string>()(), "%f", val); }
-string to_string (double val) { return as_string(snprintf, initial_string< string>()(), "%f", val); }
-string to_string (long double val) { return as_string(snprintf, initial_string< string>()(), "%Lf", val); }
-
-wstring to_wstring(float val) { return as_string(get_swprintf(), initial_string<wstring>()(), L"%f", val); }
-wstring to_wstring(double val) { return as_string(get_swprintf(), initial_string<wstring>()(), L"%f", val); }
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+wstring to_wstring(float val) { return as_string(get_swprintf(), initial_string<wstring>()(), L"%f", val); }
+wstring to_wstring(double val) { return as_string(get_swprintf(), initial_string<wstring>()(), L"%f", val); }
wstring to_wstring(long double val) { return as_string(get_swprintf(), initial_string<wstring>()(), L"%Lf", val); }
+#endif
_LIBCPP_END_NAMESPACE_STD
diff --git a/contrib/llvm-project/libcxx/src/strstream.cpp b/contrib/llvm-project/libcxx/src/strstream.cpp
index ae66806833aa..70374191c6ab 100644
--- a/contrib/llvm-project/libcxx/src/strstream.cpp
+++ b/contrib/llvm-project/libcxx/src/strstream.cpp
@@ -1,4 +1,4 @@
-//===------------------------ strstream.cpp -------------------------------===//
+//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -6,330 +6,253 @@
//
//===----------------------------------------------------------------------===//
-#include "strstream"
-#include "algorithm"
-#include "climits"
-#include "cstring"
-#include "cstdlib"
-#include "__debug"
-#include "__undef_macros"
+#include <__assert>
+#include <__utility/unreachable.h>
+#include <algorithm>
+#include <climits>
+#include <cstdlib>
+#include <cstring>
+#include <strstream>
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_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);
+ : __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();
- }
-}
-
-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);
+ std::swap(__strmode_, __rhs.__strmode_);
+ std::swap(__alsize_, __rhs.__alsize_);
+ std::swap(__palloc_, __rhs.__palloc_);
+ std::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(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_INTERNAL(eback(), "strstreambuf::overflow reallocating but the get area is a null pointer");
+ 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, std::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, std::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/llvm-project/libcxx/src/support/ibm/mbsnrtowcs.cpp b/contrib/llvm-project/libcxx/src/support/ibm/mbsnrtowcs.cpp
new file mode 100644
index 000000000000..122dc5ed892f
--- /dev/null
+++ b/contrib/llvm-project/libcxx/src/support/ibm/mbsnrtowcs.cpp
@@ -0,0 +1,97 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 <cstddef> // size_t
+#include <cwchar> // mbstate_t
+#include <limits.h> // MB_LEN_MAX
+#include <string.h> // wmemcpy
+
+// Returns 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 null terminator.
+// When `dst` is NULL, no characters are copied to `dst`.
+// Returns (size_t) -1 when an invalid sequence is encountered.
+// Leaves *`src` pointing to the next character to convert or NULL
+// if a null character was converted from *`src`.
+_LIBCPP_EXPORTED_FROM_ABI size_t mbsnrtowcs(
+ wchar_t* __restrict dst,
+ const char** __restrict src,
+ size_t src_size_bytes,
+ size_t max_dest_chars,
+ mbstate_t* __restrict ps) {
+ const size_t terminated_sequence = static_cast<size_t>(0);
+ const size_t invalid_sequence = static_cast<size_t>(-1);
+ const size_t incomplete_sequence = static_cast<size_t>(-2);
+
+ size_t source_converted;
+ size_t dest_converted;
+ size_t result = 0;
+
+ // If `dst` is null then `max_dest_chars` should be ignored according to the
+ // standard. Setting `max_dest_chars` to a large value has this effect.
+ if (dst == nullptr)
+ max_dest_chars = static_cast<size_t>(-1);
+
+ for (dest_converted = source_converted = 0;
+ source_converted < src_size_bytes && (!dst || dest_converted < max_dest_chars);
+ ++dest_converted, source_converted += result) {
+ // Converts one multi byte character.
+ // If result (char_size) is greater than 0, it's the size in bytes of that character.
+ // If result (char_size) is zero, it indicates that the null character has been found.
+ // Otherwise, it's an error and errno may be set.
+ size_t source_remaining = src_size_bytes - source_converted;
+ size_t dest_remaining = max_dest_chars - dest_converted;
+
+ if (dst == nullptr) {
+ result = mbrtowc(NULL, *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);
+ } else {
+ /*
+ * dst may not have enough space, so use a temporary buffer.
+ *
+ * We need to save a copy of the conversion state
+ * here so we can restore it if the multibyte
+ * character is too long for the buffer.
+ */
+ wchar_t buff[MB_LEN_MAX];
+ mbstate_t mbstate_tmp;
+
+ if (ps != nullptr)
+ mbstate_tmp = *ps;
+ result = mbrtowc(buff, *src + source_converted, source_remaining, ps);
+
+ if (result > dest_remaining) {
+ // Multi-byte sequence for character won't fit.
+ if (ps != nullptr)
+ *ps = mbstate_tmp;
+ break;
+ } else {
+ // The buffer was used, so we need copy the translation to dst.
+ wmemcpy(dst, buff, result);
+ }
+ }
+
+ // Don't do anything to change errno from here on.
+ if (result == invalid_sequence || result == terminated_sequence || result == incomplete_sequence) {
+ break;
+ }
+ }
+
+ if (dst) {
+ if (result == terminated_sequence)
+ *src = NULL;
+ else
+ *src += source_converted;
+ }
+ if (result == invalid_sequence)
+ return invalid_sequence;
+
+ return dest_converted;
+}
diff --git a/contrib/llvm-project/libcxx/src/support/ibm/wcsnrtombs.cpp b/contrib/llvm-project/libcxx/src/support/ibm/wcsnrtombs.cpp
new file mode 100644
index 000000000000..f0372152339f
--- /dev/null
+++ b/contrib/llvm-project/libcxx/src/support/ibm/wcsnrtombs.cpp
@@ -0,0 +1,94 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 <cwchar> // mbstate_t
+#include <limits.h> // MB_LEN_MAX
+#include <stdlib.h> // MB_CUR_MAX, size_t
+#include <string.h> // memcpy
+
+// Converts `max_source_chars` from the wide character buffer pointer to by *`src`,
+// into the multi byte character sequence buffer stored at `dst`, which must be
+// `dst_size_bytes` bytes in size. Returns the number of bytes in the sequence
+// converted from *src, excluding the null terminator.
+// Returns (size_t) -1 if an error occurs and sets errno.
+// If `dst` is NULL, `dst_size_bytes` is ignored and no bytes are copied to `dst`.
+_LIBCPP_EXPORTED_FROM_ABI size_t wcsnrtombs(
+ char* __restrict dst,
+ const wchar_t** __restrict src,
+ size_t max_source_chars,
+ size_t dst_size_bytes,
+ mbstate_t* __restrict ps) {
+ const size_t invalid_wchar = static_cast<size_t>(-1);
+
+ size_t source_converted;
+ size_t dest_converted;
+ size_t result = 0;
+
+ // If `dst` is null then `dst_size_bytes` should be ignored according to the
+ // standard. Setting dst_size_bytes to a large value has this effect.
+ if (dst == nullptr)
+ dst_size_bytes = static_cast<size_t>(-1);
+
+ for (dest_converted = source_converted = 0;
+ source_converted < max_source_chars && (!dst || dest_converted < dst_size_bytes);
+ ++source_converted, dest_converted += result) {
+ wchar_t c = (*src)[source_converted];
+ size_t dest_remaining = dst_size_bytes - dest_converted;
+
+ if (dst == nullptr) {
+ result = wcrtomb(NULL, 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);
+ } else {
+ /*
+ * dst may not have enough space, so use a temporary buffer.
+ *
+ * We need to save a copy of the conversion state
+ * here so we can restore it if the multibyte
+ * character is too long for the buffer.
+ */
+ char buff[MB_LEN_MAX];
+ mbstate_t mbstate_tmp;
+
+ if (ps != nullptr)
+ mbstate_tmp = *ps;
+ result = wcrtomb(buff, c, ps);
+
+ if (result > dest_remaining) {
+ // Multi-byte sequence for character won't fit.
+ if (ps != nullptr)
+ *ps = mbstate_tmp;
+ if (result != invalid_wchar)
+ break;
+ } else {
+ // The buffer was used, so we need copy the translation to dst.
+ memcpy(dst, buff, result);
+ }
+ }
+
+ // result (char_size) contains the size of the multi-byte-sequence converted.
+ // Otherwise, result (char_size) is (size_t) -1 and wcrtomb() sets the errno.
+ if (result == invalid_wchar) {
+ if (dst)
+ *src = *src + source_converted;
+ return invalid_wchar;
+ }
+
+ if (c == L'\0') {
+ if (dst)
+ *src = NULL;
+ return dest_converted;
+ }
+ }
+
+ if (dst)
+ *src = *src + source_converted;
+
+ return dest_converted;
+}
diff --git a/contrib/llvm-project/libcxx/src/support/ibm/xlocale_zos.cpp b/contrib/llvm-project/libcxx/src/support/ibm/xlocale_zos.cpp
new file mode 100644
index 000000000000..9a90e08e11cf
--- /dev/null
+++ b/contrib/llvm-project/libcxx/src/support/ibm/xlocale_zos.cpp
@@ -0,0 +1,130 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 <__assert>
+#include <__support/ibm/xlocale.h>
+#include <sstream>
+#include <vector>
+
+#ifdef __cplusplus
+extern "C" {
+#endif // __cplusplus
+
+locale_t newlocale(int category_mask, const char* locale, locale_t base) {
+ // Maintain current locale name(s) to restore later.
+ std::string current_loc_name(setlocale(LC_ALL, 0));
+
+ // Check for errors.
+ if (category_mask == LC_ALL_MASK && setlocale(LC_ALL, locale) == NULL) {
+ 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) {
+ setlocale(LC_ALL, current_loc_name.c_str());
+ errno = EINVAL;
+ return (locale_t)0;
+ }
+ }
+ }
+
+ // Create new locale.
+ locale_t newloc = new locale_struct();
+
+ if (base) {
+ if (category_mask != LC_ALL_MASK) {
+ // Copy base when it will not be overwritten.
+ memcpy(newloc, base, sizeof(locale_struct));
+ newloc->category_mask = category_mask | base->category_mask;
+ }
+ delete base;
+ } else {
+ newloc->category_mask = category_mask;
+ }
+
+ if (category_mask & LC_COLLATE_MASK)
+ newloc->lc_collate = locale;
+ if (category_mask & LC_CTYPE_MASK)
+ newloc->lc_ctype = locale;
+ if (category_mask & LC_MONETARY_MASK)
+ newloc->lc_monetary = locale;
+ if (category_mask & LC_NUMERIC_MASK)
+ newloc->lc_numeric = locale;
+ if (category_mask & LC_TIME_MASK)
+ newloc->lc_time = locale;
+ if (category_mask & LC_MESSAGES_MASK)
+ newloc->lc_messages = locale;
+
+ // Restore current locale.
+ setlocale(LC_ALL, current_loc_name.c_str());
+ return (locale_t)newloc;
+}
+
+void freelocale(locale_t locobj) { delete locobj; }
+
+locale_t uselocale(locale_t newloc) {
+ // Maintain current locale name(s).
+ std::string current_loc_name(setlocale(LC_ALL, 0));
+
+ 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);
+
+ if (is_error) {
+ setlocale(LC_ALL, current_loc_name.c_str());
+ errno = EINVAL;
+ return (locale_t)0;
+ }
+ }
+
+ // Construct and return previous locale.
+ locale_t previous_loc = new locale_struct();
+
+ // current_loc_name might be a comma-separated locale name list.
+ if (current_loc_name.find(',') != std::string::npos) {
+ // Tokenize locale name list.
+ const char delimiter = ',';
+ std::vector<std::string> tokenized;
+ std::stringstream ss(current_loc_name);
+ std::string s;
+
+ while (std::getline(ss, s, delimiter)) {
+ tokenized.push_back(s);
+ }
+
+ _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(tokenized.size() >= _NCAT, "locale-name list is too short");
+
+ previous_loc->lc_collate = tokenized[LC_COLLATE];
+ previous_loc->lc_ctype = tokenized[LC_CTYPE];
+ previous_loc->lc_monetary = tokenized[LC_MONETARY];
+ previous_loc->lc_numeric = tokenized[LC_NUMERIC];
+ previous_loc->lc_time = tokenized[LC_TIME];
+ // Skip LC_TOD.
+ previous_loc->lc_messages = tokenized[LC_MESSAGES];
+ } else {
+ previous_loc->lc_collate = current_loc_name;
+ previous_loc->lc_ctype = current_loc_name;
+ previous_loc->lc_monetary = current_loc_name;
+ previous_loc->lc_numeric = current_loc_name;
+ previous_loc->lc_time = current_loc_name;
+ previous_loc->lc_messages = current_loc_name;
+ }
+
+ previous_loc->category_mask = LC_ALL_MASK;
+ return previous_loc;
+}
+
+#ifdef __cplusplus
+}
+#endif // __cplusplus
diff --git a/contrib/llvm-project/libcxx/src/support/runtime/exception_fallback.ipp b/contrib/llvm-project/libcxx/src/support/runtime/exception_fallback.ipp
index faa112f7f3a4..18ff4b83d876 100644
--- a/contrib/llvm-project/libcxx/src/support/runtime/exception_fallback.ipp
+++ b/contrib/llvm-project/libcxx/src/support/runtime/exception_fallback.ipp
@@ -11,150 +11,83 @@
namespace std {
-_LIBCPP_SAFE_STATIC static std::terminate_handler __terminate_handler;
-_LIBCPP_SAFE_STATIC static std::unexpected_handler __unexpected_handler;
-
+static constinit std::terminate_handler __terminate_handler = nullptr;
+static constinit std::unexpected_handler __unexpected_handler = nullptr;
// libcxxrt provides implementations of these functions itself.
-unexpected_handler
-set_unexpected(unexpected_handler func) _NOEXCEPT
-{
+unexpected_handler set_unexpected(unexpected_handler func) noexcept {
return __libcpp_atomic_exchange(&__unexpected_handler, func);
}
-unexpected_handler
-get_unexpected() _NOEXCEPT
-{
- return __libcpp_atomic_load(&__unexpected_handler);
-
-}
+unexpected_handler get_unexpected() noexcept { return __libcpp_atomic_load(&__unexpected_handler); }
-_LIBCPP_NORETURN
-void unexpected()
-{
- (*get_unexpected())();
- // unexpected handler should not return
- terminate();
+_LIBCPP_NORETURN void unexpected() {
+ (*get_unexpected())();
+ // unexpected handler should not return
+ terminate();
}
-terminate_handler
-set_terminate(terminate_handler func) _NOEXCEPT
-{
+terminate_handler set_terminate(terminate_handler func) noexcept {
return __libcpp_atomic_exchange(&__terminate_handler, func);
}
-terminate_handler
-get_terminate() _NOEXCEPT
-{
- return __libcpp_atomic_load(&__terminate_handler);
-}
+terminate_handler get_terminate() noexcept { return __libcpp_atomic_load(&__terminate_handler); }
-_LIBCPP_NORETURN
-void
-terminate() _NOEXCEPT
-{
-#ifndef _LIBCPP_NO_EXCEPTIONS
- try
- {
-#endif // _LIBCPP_NO_EXCEPTIONS
- (*get_terminate())();
- // handler should not return
- fprintf(stderr, "terminate_handler unexpectedly returned\n");
- ::abort();
-#ifndef _LIBCPP_NO_EXCEPTIONS
- }
- catch (...)
- {
- // handler should not throw exception
- fprintf(stderr, "terminate_handler unexpectedly threw an exception\n");
- ::abort();
- }
-#endif // _LIBCPP_NO_EXCEPTIONS
+_LIBCPP_NORETURN void terminate() noexcept {
+#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
+ try {
+#endif // _LIBCPP_HAS_NO_EXCEPTIONS
+ (*get_terminate())();
+ // handler should not return
+ fprintf(stderr, "terminate_handler unexpectedly returned\n");
+ ::abort();
+#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
+ } catch (...) {
+ // handler should not throw exception
+ fprintf(stderr, "terminate_handler unexpectedly threw an exception\n");
+ ::abort();
+ }
+#endif // _LIBCPP_HAS_NO_EXCEPTIONS
}
-bool uncaught_exception() _NOEXCEPT { return uncaught_exceptions() > 0; }
+bool uncaught_exception() noexcept { return uncaught_exceptions() > 0; }
-int uncaught_exceptions() _NOEXCEPT
-{
+int uncaught_exceptions() noexcept {
#warning uncaught_exception not yet implemented
fprintf(stderr, "uncaught_exceptions not yet implemented\n");
::abort();
}
+exception::~exception() noexcept {}
-exception::~exception() _NOEXCEPT
-{
-}
+const char* exception::what() const noexcept { return "std::exception"; }
-const char* exception::what() const _NOEXCEPT
-{
- return "std::exception";
-}
+bad_exception::~bad_exception() noexcept {}
-bad_exception::~bad_exception() _NOEXCEPT
-{
-}
-
-const char* bad_exception::what() const _NOEXCEPT
-{
- return "std::bad_exception";
-}
+const char* bad_exception::what() const noexcept { return "std::bad_exception"; }
+bad_alloc::bad_alloc() noexcept {}
-bad_alloc::bad_alloc() _NOEXCEPT
-{
-}
-
-bad_alloc::~bad_alloc() _NOEXCEPT
-{
-}
+bad_alloc::~bad_alloc() noexcept {}
-const char*
-bad_alloc::what() const _NOEXCEPT
-{
- return "std::bad_alloc";
-}
+const char* bad_alloc::what() const noexcept { return "std::bad_alloc"; }
-bad_array_new_length::bad_array_new_length() _NOEXCEPT
-{
-}
+bad_array_new_length::bad_array_new_length() noexcept {}
-bad_array_new_length::~bad_array_new_length() _NOEXCEPT
-{
-}
+bad_array_new_length::~bad_array_new_length() noexcept {}
-const char*
-bad_array_new_length::what() const _NOEXCEPT
-{
- return "bad_array_new_length";
-}
+const char* bad_array_new_length::what() const noexcept { return "bad_array_new_length"; }
-bad_cast::bad_cast() _NOEXCEPT
-{
-}
+bad_cast::bad_cast() noexcept {}
-bad_typeid::bad_typeid() _NOEXCEPT
-{
-}
+bad_typeid::bad_typeid() noexcept {}
-bad_cast::~bad_cast() _NOEXCEPT
-{
-}
+bad_cast::~bad_cast() noexcept {}
-const char*
-bad_cast::what() const _NOEXCEPT
-{
- return "std::bad_cast";
-}
+const char* bad_cast::what() const noexcept { return "std::bad_cast"; }
-bad_typeid::~bad_typeid() _NOEXCEPT
-{
-}
+bad_typeid::~bad_typeid() noexcept {}
-const char*
-bad_typeid::what() const _NOEXCEPT
-{
- return "std::bad_typeid";
-}
+const char* bad_typeid::what() const noexcept { return "std::bad_typeid"; }
} // namespace std
diff --git a/contrib/llvm-project/libcxx/src/support/runtime/exception_glibcxx.ipp b/contrib/llvm-project/libcxx/src/support/runtime/exception_glibcxx.ipp
index 4bf3c4d87759..aa67cab6bc23 100644
--- a/contrib/llvm-project/libcxx/src/support/runtime/exception_glibcxx.ipp
+++ b/contrib/llvm-project/libcxx/src/support/runtime/exception_glibcxx.ipp
@@ -8,25 +8,17 @@
//===----------------------------------------------------------------------===//
#ifndef __GLIBCXX__
-#error header can only be used when targeting libstdc++ or libsupc++
+# error header can only be used when targeting libstdc++ or libsupc++
#endif
namespace std {
-bad_alloc::bad_alloc() _NOEXCEPT
-{
-}
+bad_alloc::bad_alloc() noexcept {}
-bad_array_new_length::bad_array_new_length() _NOEXCEPT
-{
-}
+bad_array_new_length::bad_array_new_length() noexcept {}
-bad_cast::bad_cast() _NOEXCEPT
-{
-}
+bad_cast::bad_cast() noexcept {}
-bad_typeid::bad_typeid() _NOEXCEPT
-{
-}
+bad_typeid::bad_typeid() noexcept {}
} // namespace std
diff --git a/contrib/llvm-project/libcxx/src/support/runtime/exception_libcxxabi.ipp b/contrib/llvm-project/libcxx/src/support/runtime/exception_libcxxabi.ipp
index 6bc049bf382d..df6bd6574bde 100644
--- a/contrib/llvm-project/libcxx/src/support/runtime/exception_libcxxabi.ipp
+++ b/contrib/llvm-project/libcxx/src/support/runtime/exception_libcxxabi.ipp
@@ -8,20 +8,19 @@
//===----------------------------------------------------------------------===//
#ifndef _LIBCPPABI_VERSION
-#error this header can only be used with libc++abi
+# error this header can only be used with libc++abi
#endif
namespace std {
-bool uncaught_exception() _NOEXCEPT { return uncaught_exceptions() > 0; }
+bool uncaught_exception() noexcept { return uncaught_exceptions() > 0; }
-int uncaught_exceptions() _NOEXCEPT
-{
-# if _LIBCPPABI_VERSION > 1001
- return __cxa_uncaught_exceptions();
-# else
- return __cxa_uncaught_exception() ? 1 : 0;
-# endif
+int uncaught_exceptions() noexcept {
+#if _LIBCPPABI_VERSION > 1001
+ return __cxa_uncaught_exceptions();
+#else
+ return __cxa_uncaught_exception() ? 1 : 0;
+#endif
}
} // namespace std
diff --git a/contrib/llvm-project/libcxx/src/support/runtime/exception_libcxxrt.ipp b/contrib/llvm-project/libcxx/src/support/runtime/exception_libcxxrt.ipp
index 0ebffdedba94..f17fecc71e34 100644
--- a/contrib/llvm-project/libcxx/src/support/runtime/exception_libcxxrt.ipp
+++ b/contrib/llvm-project/libcxx/src/support/runtime/exception_libcxxrt.ipp
@@ -8,18 +8,13 @@
//===----------------------------------------------------------------------===//
#ifndef LIBCXXRT
-#error this header may only be used when targeting libcxxrt
+# error this header may only be used when targeting libcxxrt
#endif
namespace std {
-bad_exception::~bad_exception() _NOEXCEPT
-{
-}
+bad_exception::~bad_exception() noexcept {}
-const char* bad_exception::what() const _NOEXCEPT
-{
- return "std::bad_exception";
-}
+const char* bad_exception::what() const noexcept { return "std::bad_exception"; }
} // namespace std
diff --git a/contrib/llvm-project/libcxx/src/support/runtime/exception_msvc.ipp b/contrib/llvm-project/libcxx/src/support/runtime/exception_msvc.ipp
index 7315b8261b76..323cd9d18005 100644
--- a/contrib/llvm-project/libcxx/src/support/runtime/exception_msvc.ipp
+++ b/contrib/llvm-project/libcxx/src/support/runtime/exception_msvc.ipp
@@ -8,21 +8,19 @@
//===----------------------------------------------------------------------===//
#ifndef _LIBCPP_ABI_MICROSOFT
-#error this header can only be used when targeting the MSVC ABI
+# error this header can only be used when targeting the MSVC ABI
#endif
#include <stdio.h>
#include <stdlib.h>
extern "C" {
-typedef void (__cdecl* terminate_handler)();
-_LIBCPP_CRT_FUNC terminate_handler __cdecl set_terminate(
- terminate_handler _NewTerminateHandler) throw();
+typedef void(__cdecl* terminate_handler)();
+_LIBCPP_CRT_FUNC terminate_handler __cdecl set_terminate(terminate_handler _NewTerminateHandler) throw();
_LIBCPP_CRT_FUNC terminate_handler __cdecl _get_terminate();
-typedef void (__cdecl* unexpected_handler)();
-unexpected_handler __cdecl set_unexpected(
- unexpected_handler _NewUnexpectedHandler) throw();
+typedef void(__cdecl* unexpected_handler)();
+unexpected_handler __cdecl set_unexpected(unexpected_handler _NewUnexpectedHandler) throw();
unexpected_handler __cdecl _get_unexpected();
int __cdecl __uncaught_exceptions();
@@ -30,134 +28,73 @@ int __cdecl __uncaught_exceptions();
namespace std {
-unexpected_handler
-set_unexpected(unexpected_handler func) _NOEXCEPT {
- return ::set_unexpected(func);
-}
+unexpected_handler set_unexpected(unexpected_handler func) noexcept { return ::set_unexpected(func); }
-unexpected_handler get_unexpected() _NOEXCEPT {
- return ::_get_unexpected();
-}
+unexpected_handler get_unexpected() noexcept { return ::_get_unexpected(); }
-_LIBCPP_NORETURN
-void unexpected() {
- (*get_unexpected())();
- // unexpected handler should not return
- terminate();
+_LIBCPP_NORETURN void unexpected() {
+ (*get_unexpected())();
+ // unexpected handler should not return
+ terminate();
}
-terminate_handler set_terminate(terminate_handler func) _NOEXCEPT {
- return ::set_terminate(func);
-}
+terminate_handler set_terminate(terminate_handler func) noexcept { return ::set_terminate(func); }
-terminate_handler get_terminate() _NOEXCEPT {
- return ::_get_terminate();
-}
+terminate_handler get_terminate() noexcept { return ::_get_terminate(); }
-_LIBCPP_NORETURN
-void terminate() _NOEXCEPT
-{
-#ifndef _LIBCPP_NO_EXCEPTIONS
- try
- {
-#endif // _LIBCPP_NO_EXCEPTIONS
- (*get_terminate())();
- // handler should not return
- fprintf(stderr, "terminate_handler unexpectedly returned\n");
- ::abort();
-#ifndef _LIBCPP_NO_EXCEPTIONS
- }
- catch (...)
- {
- // handler should not throw exception
- fprintf(stderr, "terminate_handler unexpectedly threw an exception\n");
- ::abort();
- }
-#endif // _LIBCPP_NO_EXCEPTIONS
+_LIBCPP_NORETURN void terminate() noexcept {
+#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
+ try {
+#endif // _LIBCPP_HAS_NO_EXCEPTIONS
+ (*get_terminate())();
+ // handler should not return
+ fprintf(stderr, "terminate_handler unexpectedly returned\n");
+ ::abort();
+#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
+ } catch (...) {
+ // handler should not throw exception
+ fprintf(stderr, "terminate_handler unexpectedly threw an exception\n");
+ ::abort();
+ }
+#endif // _LIBCPP_HAS_NO_EXCEPTIONS
}
-bool uncaught_exception() _NOEXCEPT { return uncaught_exceptions() > 0; }
+bool uncaught_exception() noexcept { return uncaught_exceptions() > 0; }
-int uncaught_exceptions() _NOEXCEPT {
- return __uncaught_exceptions();
-}
+int uncaught_exceptions() noexcept { return __uncaught_exceptions(); }
#if !defined(_LIBCPP_ABI_VCRUNTIME)
-bad_cast::bad_cast() _NOEXCEPT
-{
-}
+bad_cast::bad_cast() noexcept {}
-bad_cast::~bad_cast() _NOEXCEPT
-{
-}
+bad_cast::~bad_cast() noexcept {}
-const char *
-bad_cast::what() const _NOEXCEPT
-{
- return "std::bad_cast";
-}
+const char* bad_cast::what() const noexcept { return "std::bad_cast"; }
-bad_typeid::bad_typeid() _NOEXCEPT
-{
-}
+bad_typeid::bad_typeid() noexcept {}
-bad_typeid::~bad_typeid() _NOEXCEPT
-{
-}
+bad_typeid::~bad_typeid() noexcept {}
-const char *
-bad_typeid::what() const _NOEXCEPT
-{
- return "std::bad_typeid";
-}
+const char* bad_typeid::what() const noexcept { return "std::bad_typeid"; }
-exception::~exception() _NOEXCEPT
-{
-}
+exception::~exception() noexcept {}
-const char* exception::what() const _NOEXCEPT
-{
- return "std::exception";
-}
+const char* exception::what() const noexcept { return "std::exception"; }
+bad_exception::~bad_exception() noexcept {}
-bad_exception::~bad_exception() _NOEXCEPT
-{
-}
+const char* bad_exception::what() const noexcept { return "std::bad_exception"; }
-const char* bad_exception::what() const _NOEXCEPT
-{
- return "std::bad_exception";
-}
+bad_alloc::bad_alloc() noexcept {}
+bad_alloc::~bad_alloc() noexcept {}
-bad_alloc::bad_alloc() _NOEXCEPT
-{
-}
+const char* bad_alloc::what() const noexcept { return "std::bad_alloc"; }
-bad_alloc::~bad_alloc() _NOEXCEPT
-{
-}
+bad_array_new_length::bad_array_new_length() noexcept {}
-const char*
-bad_alloc::what() const _NOEXCEPT
-{
- return "std::bad_alloc";
-}
+bad_array_new_length::~bad_array_new_length() noexcept {}
-bad_array_new_length::bad_array_new_length() _NOEXCEPT
-{
-}
-
-bad_array_new_length::~bad_array_new_length() _NOEXCEPT
-{
-}
-
-const char*
-bad_array_new_length::what() const _NOEXCEPT
-{
- return "bad_array_new_length";
-}
+const char* bad_array_new_length::what() const noexcept { return "bad_array_new_length"; }
#endif // !_LIBCPP_ABI_VCRUNTIME
} // namespace std
diff --git a/contrib/llvm-project/libcxx/src/support/runtime/exception_pointer_cxxabi.ipp b/contrib/llvm-project/libcxx/src/support/runtime/exception_pointer_cxxabi.ipp
index 82a8e6972fa3..bdb17b9996b7 100644
--- a/contrib/llvm-project/libcxx/src/support/runtime/exception_pointer_cxxabi.ipp
+++ b/contrib/llvm-project/libcxx/src/support/runtime/exception_pointer_cxxabi.ipp
@@ -8,66 +8,57 @@
//===----------------------------------------------------------------------===//
#ifndef HAVE_DEPENDENT_EH_ABI
-#error this header may only be used with libc++abi or libcxxrt
+# error this header may only be used with libc++abi or libcxxrt
#endif
namespace std {
-exception_ptr::~exception_ptr() _NOEXCEPT {
- __cxa_decrement_exception_refcount(__ptr_);
-}
+exception_ptr::~exception_ptr() noexcept { __cxa_decrement_exception_refcount(__ptr_); }
-exception_ptr::exception_ptr(const exception_ptr& other) _NOEXCEPT
- : __ptr_(other.__ptr_)
-{
- __cxa_increment_exception_refcount(__ptr_);
+exception_ptr::exception_ptr(const exception_ptr& other) noexcept : __ptr_(other.__ptr_) {
+ __cxa_increment_exception_refcount(__ptr_);
}
-exception_ptr& exception_ptr::operator=(const exception_ptr& other) _NOEXCEPT
-{
- if (__ptr_ != other.__ptr_)
- {
- __cxa_increment_exception_refcount(other.__ptr_);
- __cxa_decrement_exception_refcount(__ptr_);
- __ptr_ = other.__ptr_;
- }
- return *this;
+exception_ptr& exception_ptr::operator=(const exception_ptr& other) noexcept {
+ if (__ptr_ != other.__ptr_) {
+ __cxa_increment_exception_refcount(other.__ptr_);
+ __cxa_decrement_exception_refcount(__ptr_);
+ __ptr_ = other.__ptr_;
+ }
+ return *this;
}
-nested_exception::nested_exception() _NOEXCEPT
- : __ptr_(current_exception())
-{
-}
+exception_ptr exception_ptr::__from_native_exception_pointer(void* __e) noexcept {
+ exception_ptr ptr;
+ ptr.__ptr_ = __e;
+ __cxa_increment_exception_refcount(ptr.__ptr_);
-nested_exception::~nested_exception() _NOEXCEPT
-{
+ return ptr;
}
-_LIBCPP_NORETURN
-void
-nested_exception::rethrow_nested() const
-{
- if (__ptr_ == nullptr)
- terminate();
- rethrow_exception(__ptr_);
+nested_exception::nested_exception() noexcept : __ptr_(current_exception()) {}
+
+nested_exception::~nested_exception() noexcept {}
+
+_LIBCPP_NORETURN void nested_exception::rethrow_nested() const {
+ if (__ptr_ == nullptr)
+ terminate();
+ rethrow_exception(__ptr_);
}
-exception_ptr current_exception() _NOEXCEPT
-{
- // be nicer if there was a constructor that took a ptr, then
- // this whole function would be just:
- // return exception_ptr(__cxa_current_primary_exception());
- exception_ptr ptr;
- ptr.__ptr_ = __cxa_current_primary_exception();
- return ptr;
+exception_ptr current_exception() noexcept {
+ // be nicer if there was a constructor that took a ptr, then
+ // this whole function would be just:
+ // return exception_ptr(__cxa_current_primary_exception());
+ exception_ptr ptr;
+ ptr.__ptr_ = __cxa_current_primary_exception();
+ return ptr;
}
-_LIBCPP_NORETURN
-void rethrow_exception(exception_ptr p)
-{
- __cxa_rethrow_primary_exception(p.__ptr_);
- // if p.__ptr_ is NULL, above returns so we terminate
- terminate();
+_LIBCPP_NORETURN void rethrow_exception(exception_ptr p) {
+ __cxa_rethrow_primary_exception(p.__ptr_);
+ // if p.__ptr_ is NULL, above returns so we terminate
+ terminate();
}
} // namespace std
diff --git a/contrib/llvm-project/libcxx/src/support/runtime/exception_pointer_glibcxx.ipp b/contrib/llvm-project/libcxx/src/support/runtime/exception_pointer_glibcxx.ipp
index 3abc137c67ba..6dad248f9e1f 100644
--- a/contrib/llvm-project/libcxx/src/support/runtime/exception_pointer_glibcxx.ipp
+++ b/contrib/llvm-project/libcxx/src/support/runtime/exception_pointer_glibcxx.ipp
@@ -18,60 +18,51 @@
namespace std {
-namespace __exception_ptr
-{
+namespace __exception_ptr {
-struct exception_ptr
-{
- void* __ptr_;
+struct exception_ptr {
+ void* __ptr_;
- exception_ptr(const exception_ptr&) _NOEXCEPT;
- exception_ptr& operator=(const exception_ptr&) _NOEXCEPT;
- ~exception_ptr() _NOEXCEPT;
+ explicit exception_ptr(void*) noexcept;
+ exception_ptr(const exception_ptr&) noexcept;
+ exception_ptr& operator=(const exception_ptr&) noexcept;
+ ~exception_ptr() noexcept;
};
-}
+} // namespace __exception_ptr
_LIBCPP_NORETURN void rethrow_exception(__exception_ptr::exception_ptr);
-exception_ptr::~exception_ptr() _NOEXCEPT
-{
- reinterpret_cast<__exception_ptr::exception_ptr*>(this)->~exception_ptr();
-}
+exception_ptr::~exception_ptr() noexcept { reinterpret_cast<__exception_ptr::exception_ptr*>(this)->~exception_ptr(); }
-exception_ptr::exception_ptr(const exception_ptr& other) _NOEXCEPT
- : __ptr_(other.__ptr_)
-{
- new (reinterpret_cast<void*>(this)) __exception_ptr::exception_ptr(
- reinterpret_cast<const __exception_ptr::exception_ptr&>(other));
+exception_ptr::exception_ptr(const exception_ptr& other) noexcept : __ptr_(other.__ptr_) {
+ new (reinterpret_cast<void*>(this))
+ __exception_ptr::exception_ptr(reinterpret_cast<const __exception_ptr::exception_ptr&>(other));
}
-exception_ptr& exception_ptr::operator=(const exception_ptr& other) _NOEXCEPT
-{
- *reinterpret_cast<__exception_ptr::exception_ptr*>(this) =
- reinterpret_cast<const __exception_ptr::exception_ptr&>(other);
- return *this;
+exception_ptr& exception_ptr::operator=(const exception_ptr& other) noexcept {
+ *reinterpret_cast<__exception_ptr::exception_ptr*>(this) =
+ reinterpret_cast<const __exception_ptr::exception_ptr&>(other);
+ return *this;
}
-nested_exception::nested_exception() _NOEXCEPT
- : __ptr_(current_exception())
-{
+exception_ptr exception_ptr::__from_native_exception_pointer(void* __e) noexcept {
+ exception_ptr ptr{};
+ new (reinterpret_cast<void*>(&ptr)) __exception_ptr::exception_ptr(__e);
+
+ return ptr;
}
+nested_exception::nested_exception() noexcept : __ptr_(current_exception()) {}
-_LIBCPP_NORETURN
-void
-nested_exception::rethrow_nested() const
-{
- if (__ptr_ == nullptr)
- terminate();
- rethrow_exception(__ptr_);
+_LIBCPP_NORETURN void nested_exception::rethrow_nested() const {
+ if (__ptr_ == nullptr)
+ terminate();
+ rethrow_exception(__ptr_);
}
-_LIBCPP_NORETURN
-void rethrow_exception(exception_ptr p)
-{
- rethrow_exception(reinterpret_cast<__exception_ptr::exception_ptr&>(p));
+_LIBCPP_NORETURN void rethrow_exception(exception_ptr p) {
+ rethrow_exception(reinterpret_cast<__exception_ptr::exception_ptr&>(p));
}
} // namespace std
diff --git a/contrib/llvm-project/libcxx/src/support/runtime/exception_pointer_msvc.ipp b/contrib/llvm-project/libcxx/src/support/runtime/exception_pointer_msvc.ipp
index b1a36952232c..b87742b32ded 100644
--- a/contrib/llvm-project/libcxx/src/support/runtime/exception_pointer_msvc.ipp
+++ b/contrib/llvm-project/libcxx/src/support/runtime/exception_pointer_msvc.ipp
@@ -19,42 +19,34 @@ _LIBCPP_CRT_FUNC bool __cdecl __ExceptionPtrToBool(const void*);
_LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrSwap(void*, void*);
_LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrCurrentException(void*);
[[noreturn]] _LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrRethrow(const void*);
-_LIBCPP_CRT_FUNC void __cdecl
-__ExceptionPtrCopyException(void*, const void*, const void*);
+_LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrCopyException(void*, const void*, const void*);
namespace std {
-exception_ptr::exception_ptr() _NOEXCEPT { __ExceptionPtrCreate(this); }
-exception_ptr::exception_ptr(nullptr_t) _NOEXCEPT { __ExceptionPtrCreate(this); }
+exception_ptr::exception_ptr() noexcept { __ExceptionPtrCreate(this); }
+exception_ptr::exception_ptr(nullptr_t) noexcept { __ExceptionPtrCreate(this); }
-exception_ptr::exception_ptr(const exception_ptr& __other) _NOEXCEPT {
- __ExceptionPtrCopy(this, &__other);
-}
-exception_ptr& exception_ptr::operator=(const exception_ptr& __other) _NOEXCEPT {
+exception_ptr::exception_ptr(const exception_ptr& __other) noexcept { __ExceptionPtrCopy(this, &__other); }
+exception_ptr& exception_ptr::operator=(const exception_ptr& __other) noexcept {
__ExceptionPtrAssign(this, &__other);
return *this;
}
-exception_ptr& exception_ptr::operator=(nullptr_t) _NOEXCEPT {
+exception_ptr& exception_ptr::operator=(nullptr_t) noexcept {
exception_ptr dummy;
__ExceptionPtrAssign(this, &dummy);
return *this;
}
-exception_ptr::~exception_ptr() _NOEXCEPT { __ExceptionPtrDestroy(this); }
+exception_ptr::~exception_ptr() noexcept { __ExceptionPtrDestroy(this); }
-exception_ptr::operator bool() const _NOEXCEPT {
- return __ExceptionPtrToBool(this);
-}
+exception_ptr::operator bool() const noexcept { return __ExceptionPtrToBool(this); }
-bool operator==(const exception_ptr& __x, const exception_ptr& __y) _NOEXCEPT {
+bool operator==(const exception_ptr& __x, const exception_ptr& __y) noexcept {
return __ExceptionPtrCompare(&__x, &__y);
}
-
-void swap(exception_ptr& lhs, exception_ptr& rhs) _NOEXCEPT {
- __ExceptionPtrSwap(&rhs, &lhs);
-}
+void swap(exception_ptr& lhs, exception_ptr& rhs) noexcept { __ExceptionPtrSwap(&rhs, &lhs); }
exception_ptr __copy_exception_ptr(void* __except, const void* __ptr) {
exception_ptr __ret = nullptr;
@@ -63,21 +55,19 @@ exception_ptr __copy_exception_ptr(void* __except, const void* __ptr) {
return __ret;
}
-exception_ptr current_exception() _NOEXCEPT {
+exception_ptr current_exception() noexcept {
exception_ptr __ret;
__ExceptionPtrCurrentException(&__ret);
return __ret;
}
-_LIBCPP_NORETURN
-void rethrow_exception(exception_ptr p) { __ExceptionPtrRethrow(&p); }
+_LIBCPP_NORETURN void rethrow_exception(exception_ptr p) { __ExceptionPtrRethrow(&p); }
-nested_exception::nested_exception() _NOEXCEPT : __ptr_(current_exception()) {}
+nested_exception::nested_exception() noexcept : __ptr_(current_exception()) {}
-nested_exception::~nested_exception() _NOEXCEPT {}
+nested_exception::~nested_exception() noexcept {}
-_LIBCPP_NORETURN
-void nested_exception::rethrow_nested() const {
+_LIBCPP_NORETURN void nested_exception::rethrow_nested() const {
if (__ptr_ == nullptr)
terminate();
rethrow_exception(__ptr_);
diff --git a/contrib/llvm-project/libcxx/src/support/runtime/exception_pointer_unimplemented.ipp b/contrib/llvm-project/libcxx/src/support/runtime/exception_pointer_unimplemented.ipp
index 991bca9ecfe3..e12b0caf419d 100644
--- a/contrib/llvm-project/libcxx/src/support/runtime/exception_pointer_unimplemented.ipp
+++ b/contrib/llvm-project/libcxx/src/support/runtime/exception_pointer_unimplemented.ipp
@@ -12,46 +12,40 @@
namespace std {
-exception_ptr::~exception_ptr() _NOEXCEPT
-{
-# warning exception_ptr not yet implemented
+exception_ptr::~exception_ptr() noexcept {
+#warning exception_ptr not yet implemented
fprintf(stderr, "exception_ptr not yet implemented\n");
::abort();
}
-exception_ptr::exception_ptr(const exception_ptr& other) _NOEXCEPT
- : __ptr_(other.__ptr_)
-{
-# warning exception_ptr not yet implemented
+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();
}
-exception_ptr& exception_ptr::operator=(const exception_ptr& other) _NOEXCEPT
-{
-# warning exception_ptr not yet implemented
+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();
}
-nested_exception::nested_exception() _NOEXCEPT
- : __ptr_(current_exception())
-{
+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();
}
+nested_exception::nested_exception() noexcept : __ptr_(current_exception()) {}
+
#if !defined(__GLIBCXX__)
-nested_exception::~nested_exception() _NOEXCEPT
-{
-}
+nested_exception::~nested_exception() noexcept {}
#endif
-_LIBCPP_NORETURN
-void
-nested_exception::rethrow_nested() const
-{
-# warning exception_ptr not yet implemented
+_LIBCPP_NORETURN void nested_exception::rethrow_nested() const {
+#warning exception_ptr not yet implemented
fprintf(stderr, "exception_ptr not yet implemented\n");
::abort();
#if 0
@@ -61,17 +55,14 @@ nested_exception::rethrow_nested() const
#endif // FIXME
}
-exception_ptr current_exception() _NOEXCEPT
-{
-# warning exception_ptr not yet implemented
+exception_ptr current_exception() noexcept {
+#warning exception_ptr not yet implemented
fprintf(stderr, "exception_ptr not yet implemented\n");
::abort();
}
-_LIBCPP_NORETURN
-void rethrow_exception(exception_ptr p)
-{
-# warning exception_ptr not yet implemented
+_LIBCPP_NORETURN void rethrow_exception(exception_ptr p) {
+#warning exception_ptr not yet implemented
fprintf(stderr, "exception_ptr not yet implemented\n");
::abort();
}
diff --git a/contrib/llvm-project/libcxx/src/support/runtime/stdexcept_default.ipp b/contrib/llvm-project/libcxx/src/support/runtime/stdexcept_default.ipp
index c827ca4c5130..1f47a0325d76 100644
--- a/contrib/llvm-project/libcxx/src/support/runtime/stdexcept_default.ipp
+++ b/contrib/llvm-project/libcxx/src/support/runtime/stdexcept_default.ipp
@@ -1,4 +1,4 @@
-//===--------------------- stdexcept_default.ipp --------------------------===//
+//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -9,9 +9,8 @@
#include "../../include/refstring.h"
/* For _LIBCPPABI_VERSION */
-#if !defined(_LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY) && \
- (defined(LIBCXX_BUILDING_LIBCXXABI) || defined(LIBCXXRT))
-#include <cxxabi.h>
+#if !defined(_LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY) && (defined(LIBCXX_BUILDING_LIBCXXABI) || defined(LIBCXXRT))
+# include <cxxabi.h>
#endif
static_assert(sizeof(std::__libcpp_refstring) == sizeof(const char*), "");
@@ -23,9 +22,9 @@ logic_error::logic_error(const string& msg) : __imp_(msg.c_str()) {}
logic_error::logic_error(const char* msg) : __imp_(msg) {}
-logic_error::logic_error(const logic_error& le) _NOEXCEPT : __imp_(le.__imp_) {}
+logic_error::logic_error(const logic_error& le) noexcept : __imp_(le.__imp_) {}
-logic_error& logic_error::operator=(const logic_error& le) _NOEXCEPT {
+logic_error& logic_error::operator=(const logic_error& le) noexcept {
__imp_ = le.__imp_;
return *this;
}
@@ -34,30 +33,29 @@ runtime_error::runtime_error(const string& msg) : __imp_(msg.c_str()) {}
runtime_error::runtime_error(const char* msg) : __imp_(msg) {}
-runtime_error::runtime_error(const runtime_error& re) _NOEXCEPT
- : __imp_(re.__imp_) {}
+runtime_error::runtime_error(const runtime_error& re) noexcept : __imp_(re.__imp_) {}
-runtime_error& runtime_error::operator=(const runtime_error& re) _NOEXCEPT {
+runtime_error& runtime_error::operator=(const runtime_error& re) noexcept {
__imp_ = re.__imp_;
return *this;
}
#if !defined(_LIBCPPABI_VERSION) && !defined(LIBSTDCXX)
-const char* logic_error::what() const _NOEXCEPT { return __imp_.c_str(); }
+const char* logic_error::what() const noexcept { return __imp_.c_str(); }
-const char* runtime_error::what() const _NOEXCEPT { return __imp_.c_str(); }
+const char* runtime_error::what() const noexcept { return __imp_.c_str(); }
-logic_error::~logic_error() _NOEXCEPT {}
-domain_error::~domain_error() _NOEXCEPT {}
-invalid_argument::~invalid_argument() _NOEXCEPT {}
-length_error::~length_error() _NOEXCEPT {}
-out_of_range::~out_of_range() _NOEXCEPT {}
+logic_error::~logic_error() noexcept {}
+domain_error::~domain_error() noexcept {}
+invalid_argument::~invalid_argument() noexcept {}
+length_error::~length_error() noexcept {}
+out_of_range::~out_of_range() noexcept {}
-runtime_error::~runtime_error() _NOEXCEPT {}
-range_error::~range_error() _NOEXCEPT {}
-overflow_error::~overflow_error() _NOEXCEPT {}
-underflow_error::~underflow_error() _NOEXCEPT {}
+runtime_error::~runtime_error() noexcept {}
+range_error::~range_error() noexcept {}
+overflow_error::~overflow_error() noexcept {}
+underflow_error::~underflow_error() noexcept {}
#endif
diff --git a/contrib/llvm-project/libcxx/src/support/runtime/stdexcept_vcruntime.ipp b/contrib/llvm-project/libcxx/src/support/runtime/stdexcept_vcruntime.ipp
index 94eed465ae97..e6ecbf782f2a 100644
--- a/contrib/llvm-project/libcxx/src/support/runtime/stdexcept_vcruntime.ipp
+++ b/contrib/llvm-project/libcxx/src/support/runtime/stdexcept_vcruntime.ipp
@@ -1,4 +1,4 @@
-//===------------------- stdexcept_vcruntime.ipp --------------------------===//
+//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
#ifndef _LIBCPP_ABI_VCRUNTIME
-#error This file may only be used when defering to vcruntime
+# error This file may only be used when deferring to vcruntime
#endif
namespace std {
diff --git a/contrib/llvm-project/libcxx/src/system_error.cpp b/contrib/llvm-project/libcxx/src/system_error.cpp
index 9ddf7bcbe030..f518b480a278 100644
--- a/contrib/llvm-project/libcxx/src/system_error.cpp
+++ b/contrib/llvm-project/libcxx/src/system_error.cpp
@@ -1,4 +1,4 @@
-//===---------------------- system_error.cpp ------------------------------===//
+//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -6,64 +6,34 @@
//
//===----------------------------------------------------------------------===//
-#include "__config"
-
-#include "system_error"
+#include <__assert>
+#include <__config>
+#include <__verbose_abort>
+#include <cerrno>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+#include <string.h>
+#include <string>
+#include <system_error>
#include "include/config_elast.h"
-#include "cerrno"
-#include "cstring"
-#include "cstdio"
-#include "cstdlib"
-#include "string"
-#include "string.h"
-#include "__debug"
#if defined(__ANDROID__)
-#include <android/api-level.h>
+# include <android/api-level.h>
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
-// class error_category
-
-#if defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_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;
string do_strerror_r(int ev);
-#if defined(_LIBCPP_MSVCRT_LIKE)
+# if defined(_LIBCPP_MSVCRT_LIKE)
string do_strerror_r(int ev) {
char buffer[strerror_buff_size];
if (::strerror_s(buffer, strerror_buff_size, ev) == 0)
@@ -71,14 +41,13 @@ string do_strerror_r(int ev) {
std::snprintf(buffer, strerror_buff_size, "unknown error %d", ev);
return string(buffer);
}
-#else
+# else
// Only one of the two following functions will be used, depending on
// the return type of strerror_r:
// For the GNU variant, a char* return value:
-__attribute__((unused)) const char *
-handle_strerror_r_return(char *strerror_return, char *buffer) {
+__attribute__((unused)) const char* handle_strerror_r_return(char* strerror_return, char* buffer) {
// GNU always returns a string pointer in its return value. The
// string might point to either the input buffer, or a static
// buffer, but we don't care which.
@@ -86,8 +55,7 @@ handle_strerror_r_return(char *strerror_return, char *buffer) {
}
// For the POSIX variant: an int return value.
-__attribute__((unused)) const char *
-handle_strerror_r_return(int strerror_return, char *buffer) {
+__attribute__((unused)) const char* handle_strerror_r_return(int strerror_return, char* buffer) {
// The POSIX variant either:
// - fills in the provided buffer and returns 0
// - returns a positive error value, or
@@ -100,7 +68,7 @@ handle_strerror_r_return(int strerror_return, char *buffer) {
if (new_errno == EINVAL)
return "";
- _LIBCPP_ASSERT(new_errno == ERANGE, "unexpected error from ::strerror_r");
+ _LIBCPP_ASSERT_INTERNAL(new_errno == ERANGE, "unexpected error from ::strerror_r");
// FIXME maybe? 'strerror_buff_size' is likely to exceed the
// maximum error size so ERANGE shouldn't be returned.
std::abort();
@@ -109,186 +77,146 @@ handle_strerror_r_return(int strerror_return, char *buffer) {
// This function handles both GNU and POSIX variants, dispatching to
// one of the two above functions.
string do_strerror_r(int ev) {
- char buffer[strerror_buff_size];
- // Preserve errno around the call. (The C++ standard requires that
- // system_error functions not modify errno).
- const int old_errno = errno;
- const char *error_message = handle_strerror_r_return(
- ::strerror_r(ev, buffer, strerror_buff_size), buffer);
- // If we didn't get any message, print one now.
- if (!error_message[0]) {
- std::snprintf(buffer, strerror_buff_size, "Unknown error %d", ev);
- error_message = buffer;
+ char buffer[strerror_buff_size];
+ // Preserve errno around the call. (The C++ standard requires that
+ // system_error functions not modify errno).
+ const int old_errno = errno;
+ const char* error_message = handle_strerror_r_return(::strerror_r(ev, buffer, strerror_buff_size), buffer);
+ // If we didn't get any message, print one now.
+ if (!error_message[0]) {
+ std::snprintf(buffer, strerror_buff_size, "Unknown error %d", ev);
+ error_message = buffer;
+ }
+ errno = old_errno;
+ 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 += ": ";
}
- errno = old_errno;
- return string(error_message);
+ what_arg += ec.message();
+ }
+ return what_arg;
+}
+
+string make_error_str(const error_code& ec) {
+ if (ec) {
+ return ec.message();
+ }
+ return string();
}
-#endif
} // end namespace
-#endif
-string
-__do_message::message(int ev) const
-{
+string __do_message::message(int ev) const {
#if defined(_LIBCPP_HAS_NO_THREADS)
- return string(::strerror(ev));
+ return string(::strerror(ev));
#else
- return do_strerror_r(ev);
+ return do_strerror_r(ev);
#endif
}
-class _LIBCPP_HIDDEN __generic_error_category
- : public __do_message
-{
+class _LIBCPP_HIDDEN __generic_error_category : public __do_message {
public:
- virtual const char* name() const _NOEXCEPT;
- virtual string message(int ev) const;
+ virtual const char* name() const noexcept;
+ virtual string message(int ev) const;
};
-const char*
-__generic_error_category::name() const _NOEXCEPT
-{
- return "generic";
-}
+const char* __generic_error_category::name() const noexcept { return "generic"; }
-string
-__generic_error_category::message(int ev) const
-{
+string __generic_error_category::message(int ev) const {
#ifdef _LIBCPP_ELAST
- if (ev > _LIBCPP_ELAST)
- return string("unspecified generic_category error");
-#endif // _LIBCPP_ELAST
- return __do_message::message(ev);
+ if (ev > _LIBCPP_ELAST)
+ return string("unspecified generic_category error");
+#endif // _LIBCPP_ELAST
+ return __do_message::message(ev);
}
-const error_category&
-generic_category() _NOEXCEPT
-{
- static __generic_error_category s;
- return s;
+const error_category& generic_category() noexcept {
+ 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
- : public __do_message
-{
+class _LIBCPP_HIDDEN __system_error_category : public __do_message {
public:
- virtual const char* name() const _NOEXCEPT;
- virtual string message(int ev) const;
- virtual error_condition default_error_condition(int ev) const _NOEXCEPT;
+ virtual const char* name() const noexcept;
+ virtual string message(int ev) const;
+ virtual error_condition default_error_condition(int ev) const noexcept;
};
-const char*
-__system_error_category::name() const _NOEXCEPT
-{
- return "system";
-}
+const char* __system_error_category::name() const noexcept { return "system"; }
-string
-__system_error_category::message(int ev) const
-{
+string __system_error_category::message(int ev) const {
#ifdef _LIBCPP_ELAST
- if (ev > _LIBCPP_ELAST)
- return string("unspecified system_category error");
-#endif // _LIBCPP_ELAST
- return __do_message::message(ev);
+ if (ev > _LIBCPP_ELAST)
+ return string("unspecified system_category error");
+#endif // _LIBCPP_ELAST
+ return __do_message::message(ev);
}
-error_condition
-__system_error_category::default_error_condition(int ev) const _NOEXCEPT
-{
+error_condition __system_error_category::default_error_condition(int ev) const noexcept {
#ifdef _LIBCPP_ELAST
- if (ev > _LIBCPP_ELAST)
- return error_condition(ev, system_category());
-#endif // _LIBCPP_ELAST
- return error_condition(ev, generic_category());
+ if (ev > _LIBCPP_ELAST)
+ return error_condition(ev, system_category());
+#endif // _LIBCPP_ELAST
+ return error_condition(ev, generic_category());
}
-const error_category&
-system_category() _NOEXCEPT
-{
- static __system_error_category s;
- return s;
+const error_category& system_category() noexcept {
+ 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
-string
-error_condition::message() const
-{
- return __cat_->message(__val_);
-}
+string error_condition::message() const { return __cat_->message(__val_); }
// error_code
-string
-error_code::message() const
-{
- return __cat_->message(__val_);
-}
+string error_code::message() const { return __cat_->message(__val_); }
// 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)),
- __ec_(ec)
-{
-}
+ : 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)),
- __ec_(ec)
-{
-}
+ : runtime_error(make_error_str(ec, what_arg)), __ec_(ec) {}
-system_error::system_error(error_code ec)
- : runtime_error(__init(ec, "")),
- __ec_(ec)
-{
-}
+system_error::system_error(error_code 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)),
- __ec_(error_code(ev, ecat))
-{
-}
+ : 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)),
- __ec_(error_code(ev, ecat))
-{
-}
+ : 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), "")),
- __ec_(error_code(ev, ecat))
-{
-}
+ : runtime_error(make_error_str(error_code(ev, ecat))), __ec_(error_code(ev, ecat)) {}
-system_error::~system_error() _NOEXCEPT
-{
-}
+system_error::~system_error() noexcept {}
-void
-__throw_system_error(int ev, const char* what_arg)
-{
-#ifndef _LIBCPP_NO_EXCEPTIONS
- throw system_error(error_code(ev, system_category()), what_arg);
+void __throw_system_error(int ev, const char* what_arg) {
+#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
+ std::__throw_system_error(error_code(ev, system_category()), what_arg);
#else
- (void)ev;
- (void)what_arg;
- _VSTD::abort();
+ // 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/llvm-project/libcxx/src/thread.cpp b/contrib/llvm-project/libcxx/src/thread.cpp
index 5959d8b71103..73f22f12d8cc 100644
--- a/contrib/llvm-project/libcxx/src/thread.cpp
+++ b/contrib/llvm-project/libcxx/src/thread.cpp
@@ -6,206 +6,168 @@
//
//===----------------------------------------------------------------------===//
-#include "__config"
-#ifndef _LIBCPP_HAS_NO_THREADS
-
-#include "thread"
-#include "exception"
-#include "vector"
-#include "future"
-#include "limits"
+#include <__thread/poll_with_backoff.h>
+#include <__thread/timed_backoff_policy.h>
+#include <exception>
+#include <future>
+#include <limits>
+#include <thread>
+#include <vector>
#if __has_include(<unistd.h>)
-# include <unistd.h> // for sysconf
+# include <unistd.h> // for sysconf
#endif
#if defined(__NetBSD__)
-#pragma weak pthread_create // Do not create libpthread dependency
+# pragma weak pthread_create // Do not create libpthread dependency
#endif
#if defined(_LIBCPP_WIN32API)
-#include <windows.h>
+# include <windows.h>
#endif
#if defined(__ELF__) && defined(_LIBCPP_LINK_PTHREAD_LIB)
-#pragma comment(lib, "pthread")
+# pragma comment(lib, "pthread")
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
-thread::~thread()
-{
- if (!__libcpp_thread_isnull(&__t_))
- terminate();
+thread::~thread() {
+ if (!__libcpp_thread_isnull(&__t_))
+ terminate();
}
-void
-thread::join()
-{
- int ec = EINVAL;
- if (!__libcpp_thread_isnull(&__t_))
- {
- ec = __libcpp_thread_join(&__t_);
- if (ec == 0)
- __t_ = _LIBCPP_NULL_THREAD;
- }
-
- if (ec)
- __throw_system_error(ec, "thread::join failed");
+void thread::join() {
+ int ec = EINVAL;
+ if (!__libcpp_thread_isnull(&__t_)) {
+ ec = __libcpp_thread_join(&__t_);
+ if (ec == 0)
+ __t_ = _LIBCPP_NULL_THREAD;
+ }
+
+ if (ec)
+ __throw_system_error(ec, "thread::join failed");
}
-void
-thread::detach()
-{
- int ec = EINVAL;
- if (!__libcpp_thread_isnull(&__t_))
- {
- ec = __libcpp_thread_detach(&__t_);
- if (ec == 0)
- __t_ = _LIBCPP_NULL_THREAD;
- }
-
- if (ec)
- __throw_system_error(ec, "thread::detach failed");
+void thread::detach() {
+ int ec = EINVAL;
+ if (!__libcpp_thread_isnull(&__t_)) {
+ ec = __libcpp_thread_detach(&__t_);
+ if (ec == 0)
+ __t_ = _LIBCPP_NULL_THREAD;
+ }
+
+ if (ec)
+ __throw_system_error(ec, "thread::detach failed");
}
-unsigned
-thread::hardware_concurrency() _NOEXCEPT
-{
+unsigned thread::hardware_concurrency() noexcept {
#if defined(_SC_NPROCESSORS_ONLN)
- long result = sysconf(_SC_NPROCESSORS_ONLN);
- // sysconf returns -1 if the name is invalid, the option does not exist or
- // does not have a definite limit.
- // if sysconf returns some other negative number, we have no idea
- // what is going on. Default to something safe.
- if (result < 0)
- return 0;
- return static_cast<unsigned>(result);
+ long result = sysconf(_SC_NPROCESSORS_ONLN);
+ // sysconf returns -1 if the name is invalid, the option does not exist or
+ // does not have a definite limit.
+ // if sysconf returns some other negative number, we have no idea
+ // what is going on. Default to something safe.
+ if (result < 0)
+ return 0;
+ return static_cast<unsigned>(result);
#elif defined(_LIBCPP_WIN32API)
- SYSTEM_INFO info;
- GetSystemInfo(&info);
- return info.dwNumberOfProcessors;
-#else // defined(CTL_HW) && defined(HW_NCPU)
- // TODO: grovel through /proc or check cpuid on x86 and similar
- // instructions on other architectures.
-# if defined(_LIBCPP_WARNING)
- _LIBCPP_WARNING("hardware_concurrency not yet implemented")
-# else
-# warning hardware_concurrency not yet implemented
-# endif
- return 0; // Means not computable [thread.thread.static]
-#endif // defined(CTL_HW) && defined(HW_NCPU)
+ SYSTEM_INFO info;
+ GetSystemInfo(&info);
+ return info.dwNumberOfProcessors;
+#else // defined(CTL_HW) && defined(HW_NCPU)
+ // TODO: grovel through /proc or check cpuid on x86 and similar
+ // instructions on other architectures.
+# if defined(_LIBCPP_WARNING)
+ _LIBCPP_WARNING("hardware_concurrency not yet implemented")
+# else
+# warning hardware_concurrency not yet implemented
+# endif
+ return 0; // Means not computable [thread.thread.static]
+#endif // defined(CTL_HW) && defined(HW_NCPU)
}
-namespace this_thread
-{
+namespace this_thread {
-void
-sleep_for(const chrono::nanoseconds& ns)
-{
- if (ns > chrono::nanoseconds::zero())
- {
- __libcpp_thread_sleep_for(ns);
- }
+void sleep_for(const chrono::nanoseconds& ns) {
+ if (ns > chrono::nanoseconds::zero()) {
+ __libcpp_thread_sleep_for(ns);
+ }
}
-} // this_thread
+} // namespace this_thread
-__thread_specific_ptr<__thread_struct>&
-__thread_local_data()
-{
- static __thread_specific_ptr<__thread_struct> __p;
- return __p;
+__thread_specific_ptr<__thread_struct>& __thread_local_data() {
+ // Even though __thread_specific_ptr's destructor doesn't actually destroy
+ // anything (see comments there), we can't call it at all because threads may
+ // outlive the static variable and calling its destructor means accessing an
+ // object outside of its lifetime, which is UB.
+ alignas(__thread_specific_ptr<__thread_struct>) static char __b[sizeof(__thread_specific_ptr<__thread_struct>)];
+ static __thread_specific_ptr<__thread_struct>* __p = new (__b) __thread_specific_ptr<__thread_struct>();
+ return *__p;
}
// __thread_struct_imp
template <class T>
-class _LIBCPP_HIDDEN __hidden_allocator
-{
+class _LIBCPP_HIDDEN __hidden_allocator {
public:
- typedef T value_type;
+ typedef T value_type;
- T* allocate(size_t __n)
- {return static_cast<T*>(::operator new(__n * sizeof(T)));}
- void deallocate(T* __p, size_t) {::operator delete(static_cast<void*>(__p));}
+ T* allocate(size_t __n) { return static_cast<T*>(::operator new(__n * sizeof(T))); }
+ void deallocate(T* __p, size_t) { ::operator delete(static_cast<void*>(__p)); }
- size_t max_size() const {return size_t(~0) / sizeof(T);}
+ size_t max_size() const { return size_t(~0) / sizeof(T); }
};
-class _LIBCPP_HIDDEN __thread_struct_imp
-{
- typedef vector<__assoc_sub_state*,
- __hidden_allocator<__assoc_sub_state*> > _AsyncStates;
- typedef vector<pair<condition_variable*, mutex*>,
- __hidden_allocator<pair<condition_variable*, mutex*> > > _Notify;
+class _LIBCPP_HIDDEN __thread_struct_imp {
+ typedef vector<__assoc_sub_state*, __hidden_allocator<__assoc_sub_state*> > _AsyncStates;
+ typedef vector<pair<condition_variable*, mutex*>, __hidden_allocator<pair<condition_variable*, mutex*> > > _Notify;
+
+ _AsyncStates async_states_;
+ _Notify notify_;
- _AsyncStates async_states_;
- _Notify notify_;
+ __thread_struct_imp(const __thread_struct_imp&);
+ __thread_struct_imp& operator=(const __thread_struct_imp&);
- __thread_struct_imp(const __thread_struct_imp&);
- __thread_struct_imp& operator=(const __thread_struct_imp&);
public:
- __thread_struct_imp() {}
- ~__thread_struct_imp();
+ __thread_struct_imp() {}
+ ~__thread_struct_imp();
- void notify_all_at_thread_exit(condition_variable* cv, mutex* m);
- void __make_ready_at_thread_exit(__assoc_sub_state* __s);
+ void notify_all_at_thread_exit(condition_variable* cv, mutex* m);
+ void __make_ready_at_thread_exit(__assoc_sub_state* __s);
};
-__thread_struct_imp::~__thread_struct_imp()
-{
- for (_Notify::iterator i = notify_.begin(), e = notify_.end();
- i != e; ++i)
- {
- i->second->unlock();
- i->first->notify_all();
- }
- for (_AsyncStates::iterator i = async_states_.begin(), e = async_states_.end();
- i != e; ++i)
- {
- (*i)->__make_ready();
- (*i)->__release_shared();
- }
+__thread_struct_imp::~__thread_struct_imp() {
+ for (_Notify::iterator i = notify_.begin(), e = notify_.end(); i != e; ++i) {
+ i->first->notify_all();
+ i->second->unlock();
+ }
+ for (_AsyncStates::iterator i = async_states_.begin(), e = async_states_.end(); i != e; ++i) {
+ (*i)->__make_ready();
+ (*i)->__release_shared();
+ }
}
-void
-__thread_struct_imp::notify_all_at_thread_exit(condition_variable* cv, mutex* m)
-{
- notify_.push_back(pair<condition_variable*, mutex*>(cv, m));
+void __thread_struct_imp::notify_all_at_thread_exit(condition_variable* cv, mutex* m) {
+ notify_.push_back(pair<condition_variable*, mutex*>(cv, m));
}
-void
-__thread_struct_imp::__make_ready_at_thread_exit(__assoc_sub_state* __s)
-{
- async_states_.push_back(__s);
- __s->__add_shared();
+void __thread_struct_imp::__make_ready_at_thread_exit(__assoc_sub_state* __s) {
+ async_states_.push_back(__s);
+ __s->__add_shared();
}
// __thread_struct
-__thread_struct::__thread_struct()
- : __p_(new __thread_struct_imp)
-{
-}
+__thread_struct::__thread_struct() : __p_(new __thread_struct_imp) {}
-__thread_struct::~__thread_struct()
-{
- delete __p_;
-}
+__thread_struct::~__thread_struct() { delete __p_; }
-void
-__thread_struct::notify_all_at_thread_exit(condition_variable* cv, mutex* m)
-{
- __p_->notify_all_at_thread_exit(cv, m);
+void __thread_struct::notify_all_at_thread_exit(condition_variable* cv, mutex* m) {
+ __p_->notify_all_at_thread_exit(cv, m);
}
-void
-__thread_struct::__make_ready_at_thread_exit(__assoc_sub_state* __s)
-{
- __p_->__make_ready_at_thread_exit(__s);
-}
+void __thread_struct::__make_ready_at_thread_exit(__assoc_sub_state* __s) { __p_->__make_ready_at_thread_exit(__s); }
_LIBCPP_END_NAMESPACE_STD
-
-#endif // !_LIBCPP_HAS_NO_THREADS
diff --git a/contrib/llvm-project/libcxx/src/typeinfo.cpp b/contrib/llvm-project/libcxx/src/typeinfo.cpp
index 49a07ef7dabe..e5f59da31cff 100644
--- a/contrib/llvm-project/libcxx/src/typeinfo.cpp
+++ b/contrib/llvm-project/libcxx/src/typeinfo.cpp
@@ -1,4 +1,4 @@
-//===------------------------- typeinfo.cpp -------------------------------===//
+//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -6,30 +6,31 @@
//
//===----------------------------------------------------------------------===//
-#include "typeinfo"
+#include <typeinfo>
#if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_ABI_VCRUNTIME)
-#include <string.h>
-int std::type_info::__compare(const type_info &__rhs) const _NOEXCEPT {
+# include <string.h>
+
+int std::type_info::__compare(const type_info& __rhs) const noexcept {
if (&__data == &__rhs.__data)
return 0;
return strcmp(&__data.__decorated_name[1], &__rhs.__data.__decorated_name[1]);
}
-const char *std::type_info::name() const _NOEXCEPT {
+const char* std::type_info::name() const noexcept {
// TODO(compnerd) cache demangled &__data.__decorated_name[1]
return &__data.__decorated_name[1];
}
-size_t std::type_info::hash_code() const _NOEXCEPT {
-#if defined(_WIN64)
+size_t std::type_info::hash_code() const noexcept {
+# if defined(_WIN64)
constexpr size_t fnv_offset_basis = 14695981039346656037ull;
- constexpr size_t fnv_prime = 10995116282110ull;
-#else
+ constexpr size_t fnv_prime = 10995116282110ull;
+# else
constexpr size_t fnv_offset_basis = 2166136261ull;
- constexpr size_t fnv_prime = 16777619ull;
-#endif
+ constexpr size_t fnv_prime = 16777619ull;
+# endif
size_t value = fnv_offset_basis;
for (const char* c = &__data.__decorated_name[1]; *c; ++c) {
@@ -37,21 +38,17 @@ size_t std::type_info::hash_code() const _NOEXCEPT {
value *= fnv_prime;
}
-#if defined(_WIN64)
+# if defined(_WIN64)
value ^= value >> 32;
-#endif
+# endif
return value;
}
#endif // _LIBCPP_ABI_MICROSOFT
// FIXME: Remove the _LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY configuration.
-#if (!defined(LIBCXX_BUILDING_LIBCXXABI) && \
- !defined(LIBCXXRT) && \
- !defined(__GLIBCXX__) && \
- !defined(_LIBCPP_ABI_VCRUNTIME)) || \
+#if (!defined(LIBCXX_BUILDING_LIBCXXABI) && !defined(LIBCXXRT) && !defined(__GLIBCXX__) && \
+ !defined(_LIBCPP_ABI_VCRUNTIME)) || \
defined(_LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY)
-std::type_info::~type_info()
-{
-}
+std::type_info::~type_info() {}
#endif
diff --git a/contrib/llvm-project/libcxx/src/tz.cpp b/contrib/llvm-project/libcxx/src/tz.cpp
new file mode 100644
index 000000000000..4425f0e6b91b
--- /dev/null
+++ b/contrib/llvm-project/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/llvm-project/libcxx/src/tzdb_list.cpp b/contrib/llvm-project/libcxx/src/tzdb_list.cpp
new file mode 100644
index 000000000000..7eaaedc6eda7
--- /dev/null
+++ b/contrib/llvm-project/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
diff --git a/contrib/llvm-project/libcxx/src/valarray.cpp b/contrib/llvm-project/libcxx/src/valarray.cpp
index 64d26583c74b..6ef1f1cafc0e 100644
--- a/contrib/llvm-project/libcxx/src/valarray.cpp
+++ b/contrib/llvm-project/libcxx/src/valarray.cpp
@@ -1,4 +1,4 @@
-//===------------------------ valarray.cpp --------------------------------===//
+//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -6,52 +6,44 @@
//
//===----------------------------------------------------------------------===//
-#include "valarray"
+#include <valarray>
_LIBCPP_BEGIN_NAMESPACE_STD
// These two symbols are part of the v1 ABI but not part of the >=v2 ABI.
#if _LIBCPP_ABI_VERSION == 1
-template _LIBCPP_FUNC_VIS valarray<size_t>::valarray(size_t);
-template _LIBCPP_FUNC_VIS valarray<size_t>::~valarray();
+template _LIBCPP_EXPORTED_FROM_ABI valarray<size_t>::valarray(size_t);
+template _LIBCPP_EXPORTED_FROM_ABI valarray<size_t>::~valarray();
#endif
template void valarray<size_t>::resize(size_t, size_t);
-void
-gslice::__init(size_t __start)
-{
- valarray<size_t> __indices(__size_.size());
- size_t __k = __size_.size() != 0;
- for (size_t __i = 0; __i < __size_.size(); ++__i)
- __k *= __size_[__i];
- __1d_.resize(__k);
- if (__1d_.size())
- {
- __k = 0;
- __1d_[__k] = __start;
- while (true)
- {
- size_t __i = __indices.size() - 1;
- while (true)
- {
- if (++__indices[__i] < __size_[__i])
- {
- ++__k;
- __1d_[__k] = __1d_[__k-1] + __stride_[__i];
- for (size_t __j = __i + 1; __j != __indices.size(); ++__j)
- __1d_[__k] -= __stride_[__j] * (__size_[__j] - 1);
- break;
- }
- else
- {
- if (__i == 0)
- return;
- __indices[__i--] = 0;
- }
- }
+void gslice::__init(size_t __start) {
+ valarray<size_t> __indices(__size_.size());
+ size_t __k = __size_.size() != 0;
+ for (size_t __i = 0; __i < __size_.size(); ++__i)
+ __k *= __size_[__i];
+ __1d_.resize(__k);
+ if (__1d_.size()) {
+ __k = 0;
+ __1d_[__k] = __start;
+ while (true) {
+ size_t __i = __indices.size() - 1;
+ while (true) {
+ if (++__indices[__i] < __size_[__i]) {
+ ++__k;
+ __1d_[__k] = __1d_[__k - 1] + __stride_[__i];
+ for (size_t __j = __i + 1; __j != __indices.size(); ++__j)
+ __1d_[__k] -= __stride_[__j] * (__size_[__j] - 1);
+ break;
+ } else {
+ if (__i == 0)
+ return;
+ __indices[__i--] = 0;
}
+ }
}
+ }
}
_LIBCPP_END_NAMESPACE_STD
diff --git a/contrib/llvm-project/libcxx/src/variant.cpp b/contrib/llvm-project/libcxx/src/variant.cpp
index 1fe70a1809c9..b5462d64fe95 100644
--- a/contrib/llvm-project/libcxx/src/variant.cpp
+++ b/contrib/llvm-project/libcxx/src/variant.cpp
@@ -1,4 +1,4 @@
-//===------------------------ variant.cpp ---------------------------------===//
+//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -6,12 +6,10 @@
//
//===----------------------------------------------------------------------===//
-#include "variant"
+#include <variant>
namespace std {
-const char* bad_variant_access::what() const noexcept {
- return "bad_variant_access";
-}
+const char* bad_variant_access::what() const noexcept { return "bad_variant_access"; }
-} // namespace std
+} // namespace std
diff --git a/contrib/llvm-project/libcxx/src/vector.cpp b/contrib/llvm-project/libcxx/src/vector.cpp
index 3b65e558fd0a..b6153b0e9bf9 100644
--- a/contrib/llvm-project/libcxx/src/vector.cpp
+++ b/contrib/llvm-project/libcxx/src/vector.cpp
@@ -1,4 +1,4 @@
-//===------------------------- vector.cpp ---------------------------------===//
+//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -6,10 +6,25 @@
//
//===----------------------------------------------------------------------===//
-#include "vector"
+#include <vector>
_LIBCPP_BEGIN_NAMESPACE_STD
-template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __vector_base_common<true>;
+#ifndef _LIBCPP_ABI_DO_NOT_EXPORT_VECTOR_BASE_COMMON
+
+template <bool>
+struct __vector_base_common;
+
+template <>
+struct __vector_base_common<true> {
+ _LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void __throw_length_error() const;
+ _LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void __throw_out_of_range() const;
+};
+
+void __vector_base_common<true>::__throw_length_error() const { std::__throw_length_error("vector"); }
+
+void __vector_base_common<true>::__throw_out_of_range() const { std::__throw_out_of_range("vector"); }
+
+#endif // _LIBCPP_ABI_DO_NOT_EXPORT_VECTOR_BASE_COMMON
_LIBCPP_END_NAMESPACE_STD
diff --git a/contrib/llvm-project/libcxx/src/verbose_abort.cpp b/contrib/llvm-project/libcxx/src/verbose_abort.cpp
new file mode 100644
index 000000000000..719134e2ae55
--- /dev/null
+++ b/contrib/llvm-project/libcxx/src/verbose_abort.cpp
@@ -0,0 +1,77 @@
+//===----------------------------------------------------------------------===//
+//
+// 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>
+#include <__verbose_abort>
+#include <cstdarg>
+#include <cstdio>
+#include <cstdlib>
+
+#ifdef __BIONIC__
+# include <android/api-level.h>
+# if __ANDROID_API__ >= 21
+# include <syslog.h>
+extern "C" void android_set_abort_message(const char* msg);
+# else
+# include <assert.h>
+# endif // __ANDROID_API__ >= 21
+#endif // __BIONIC__
+
+#if defined(__APPLE__) && __has_include(<CrashReporterClient.h>)
+# include <CrashReporterClient.h>
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+_LIBCPP_WEAK void __libcpp_verbose_abort(char const* format, ...) {
+ // Write message to stderr. We do this before formatting into a
+ // buffer so that we still get some information out if that fails.
+ {
+ va_list list;
+ va_start(list, format);
+ std::vfprintf(stderr, format, list);
+ va_end(list);
+ }
+
+ // Format the arguments into an allocated buffer for CrashReport & friends.
+ // We leak the buffer on purpose, since we're about to abort() anyway.
+ char* buffer;
+ (void)buffer;
+ va_list list;
+ va_start(list, format);
+
+#if defined(__APPLE__) && __has_include(<CrashReporterClient.h>)
+ // Note that we should technically synchronize accesses here (by e.g. taking a lock),
+ // however concretely we're only setting a pointer, so the likelihood of a race here
+ // is low.
+ vasprintf(&buffer, format, list);
+ CRSetCrashLogMessage(buffer);
+#elif defined(__BIONIC__)
+ vasprintf(&buffer, format, list);
+
+# if __ANDROID_API__ >= 21
+ // Show error in tombstone.
+ android_set_abort_message(buffer);
+
+ // Show error in logcat.
+ openlog("libc++", 0, 0);
+ syslog(LOG_CRIT, "%s", buffer);
+ closelog();
+# else
+ // The good error reporting wasn't available in Android until L. Since we're
+ // about to abort anyway, just call __assert2, which will log _somewhere_
+ // (tombstone and/or logcat) in older releases.
+ __assert2(__FILE__, __LINE__, __func__, buffer);
+# endif // __ANDROID_API__ >= 21
+#endif
+ va_end(list);
+
+ std::abort();
+}
+
+_LIBCPP_END_NAMESPACE_STD