diff options
author | Andrey Khalyavin <halyavin@gmail.com> | 2022-02-10 16:46:29 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:29 +0300 |
commit | f773626848a7c7456803654292e716b83d69cc12 (patch) | |
tree | db052dfcf9134f492bdbb962cb6c16cea58e1ed3 /contrib/libs/cxxsupp/libcxx/src/include | |
parent | f43ab775d197d300eb67bd4497632b909cd7c2a5 (diff) | |
download | ydb-f773626848a7c7456803654292e716b83d69cc12.tar.gz |
Restoring authorship annotation for Andrey Khalyavin <halyavin@gmail.com>. Commit 1 of 2.
Diffstat (limited to 'contrib/libs/cxxsupp/libcxx/src/include')
5 files changed, 502 insertions, 502 deletions
diff --git a/contrib/libs/cxxsupp/libcxx/src/include/apple_availability.h b/contrib/libs/cxxsupp/libcxx/src/include/apple_availability.h index 0f999d3fea..c12d346a2d 100644 --- a/contrib/libs/cxxsupp/libcxx/src/include/apple_availability.h +++ b/contrib/libs/cxxsupp/libcxx/src/include/apple_availability.h @@ -1,51 +1,51 @@ -//===------------------------ apple_availability.h ------------------------===// -// +//===------------------------ 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__ - -#endif // __APPLE__ - -#endif // _LIBCPP_SRC_INCLUDE_APPLE_AVAILABILITY_H +// +//===----------------------------------------------------------------------===// +#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__ + +#endif // __APPLE__ + +#endif // _LIBCPP_SRC_INCLUDE_APPLE_AVAILABILITY_H diff --git a/contrib/libs/cxxsupp/libcxx/src/include/atomic_support.h b/contrib/libs/cxxsupp/libcxx/src/include/atomic_support.h index 5a745a2f00..6785232fe0 100644 --- a/contrib/libs/cxxsupp/libcxx/src/include/atomic_support.h +++ b/contrib/libs/cxxsupp/libcxx/src/include/atomic_support.h @@ -1,176 +1,176 @@ -//===----------------------------------------------------------------------===//// -// +//===----------------------------------------------------------------------===//// +// // 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 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(_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 -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -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 -}; - -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); -} - -template <class _ValueType, class _FromType> -inline _LIBCPP_INLINE_VISIBILITY -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); -} - -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); -} - -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); -} - -template <class _ValueType> -inline _LIBCPP_INLINE_VISIBILITY -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); -} - -#else // _LIBCPP_HAS_NO_THREADS - -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; -} - -template <class _ValueType, class _FromType> -inline _LIBCPP_INLINE_VISIBILITY -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; -} - -template <class _ValueType, class _AddType> -inline _LIBCPP_INLINE_VISIBILITY -_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 = _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; -} - -#endif // _LIBCPP_HAS_NO_THREADS - -} // end namespace - -_LIBCPP_END_NAMESPACE_STD - -#endif // ATOMIC_SUPPORT_H +// +//===----------------------------------------------------------------------===//// + +#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(_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 +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +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 +}; + +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); +} + +template <class _ValueType, class _FromType> +inline _LIBCPP_INLINE_VISIBILITY +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); +} + +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); +} + +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); +} + +template <class _ValueType> +inline _LIBCPP_INLINE_VISIBILITY +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); +} + +#else // _LIBCPP_HAS_NO_THREADS + +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; +} + +template <class _ValueType, class _FromType> +inline _LIBCPP_INLINE_VISIBILITY +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; +} + +template <class _ValueType, class _AddType> +inline _LIBCPP_INLINE_VISIBILITY +_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 = _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; +} + +#endif // _LIBCPP_HAS_NO_THREADS + +} // end namespace + +_LIBCPP_END_NAMESPACE_STD + +#endif // ATOMIC_SUPPORT_H diff --git a/contrib/libs/cxxsupp/libcxx/src/include/config_elast.h b/contrib/libs/cxxsupp/libcxx/src/include/config_elast.h index 7880c733fb..6798ea30c0 100644 --- a/contrib/libs/cxxsupp/libcxx/src/include/config_elast.h +++ b/contrib/libs/cxxsupp/libcxx/src/include/config_elast.h @@ -1,49 +1,49 @@ -//===----------------------- config_elast.h -------------------------------===// -// +//===----------------------- 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. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP_CONFIG_ELAST -#define _LIBCPP_CONFIG_ELAST - -#include <__config> - -#if defined(_LIBCPP_MSVCRT_LIKE) -#include <stdlib.h> -#else -#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 -#elif defined(_NEWLIB_VERSION) -#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(__linux__) || defined(_LIBCPP_HAS_MUSL_LIBC) -#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) -#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 -#endif - -#endif // _LIBCPP_CONFIG_ELAST +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CONFIG_ELAST +#define _LIBCPP_CONFIG_ELAST + +#include <__config> + +#if defined(_LIBCPP_MSVCRT_LIKE) +#include <stdlib.h> +#else +#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 +#elif defined(_NEWLIB_VERSION) +#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(__linux__) || defined(_LIBCPP_HAS_MUSL_LIBC) +#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) +#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 +#endif + +#endif // _LIBCPP_CONFIG_ELAST diff --git a/contrib/libs/cxxsupp/libcxx/src/include/refstring.h b/contrib/libs/cxxsupp/libcxx/src/include/refstring.h index 3edd240a5d..d3cec926f7 100644 --- a/contrib/libs/cxxsupp/libcxx/src/include/refstring.h +++ b/contrib/libs/cxxsupp/libcxx/src/include/refstring.h @@ -1,167 +1,167 @@ -//===------------------------ __refstring ---------------------------------===// -// +//===------------------------ __refstring ---------------------------------===// +// // 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_REFSTRING_H -#define _LIBCPP_REFSTRING_H - -#include <__config> -#include <stdexcept> -#include <cstddef> -#include <cstring> - -#if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_CXX03_LANG) && !defined(_LIBCPP_USE_ATOMIC) -#define _LIBCPP_USE_ATOMIC -#include <atomic> -#else -#include "atomic_support.h" -#endif - -// MacOS and iOS used to ship with libstdc++, and still support old applications -// linking against libstdc++. The libc++ and libstdc++ exceptions are supposed -// to be ABI compatible, such that they can be thrown from one library and caught -// in the other. -// -// For that reason, we must look for libstdc++ in the same process and if found, -// check the string stored in the exception object to see if it is the GCC empty -// 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 +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_REFSTRING_H +#define _LIBCPP_REFSTRING_H + +#include <__config> +#include <stdexcept> +#include <cstddef> +#include <cstring> + +#if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_CXX03_LANG) && !defined(_LIBCPP_USE_ATOMIC) +#define _LIBCPP_USE_ATOMIC +#include <atomic> +#else +#include "atomic_support.h" +#endif + +// MacOS and iOS used to ship with libstdc++, and still support old applications +// linking against libstdc++. The libc++ and libstdc++ exceptions are supposed +// to be ABI compatible, such that they can be thrown from one library and caught +// in the other. +// +// For that reason, we must look for libstdc++ in the same process and if found, +// check the string stored in the exception object to see if it is the GCC empty +// 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> -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -namespace __refstring_imp { namespace { -typedef int count_t; - -struct _Rep_base { - std::size_t len; - std::size_t cap; -#ifdef _LIBCPP_USE_ATOMIC - std::atomic<count_t> count; -#else - count_t count; -#endif -}; - -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); -} - -#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* -get_gcc_empty_string_storage() noexcept -{ - static const char* p = compute_gcc_empty_string_storage(); - return p; -} -#endif - -}} // 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 __libcpp_refstring &s) noexcept - : __imp_(s.__imp_) -{ - if (__uses_refcount()) -#ifdef _LIBCPP_USE_ATOMIC - rep_from_data(__imp_)->count.fetch_add(1); -#else - __libcpp_atomic_add(&rep_from_data(__imp_)->count, 1); -#endif -} - -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()) -#ifdef _LIBCPP_USE_ATOMIC - rep_from_data(__imp_)->count.fetch_add(1); -#else - __libcpp_atomic_add(&rep_from_data(__imp_)->count, 1); -#endif - - if (adjust_old_count) - { -#ifdef _LIBCPP_USE_ATOMIC - if (old_rep->count.fetch_sub(1) == 0) -#else - if (__libcpp_atomic_add(&old_rep->count, count_t(-1)) < 0) -#endif - { - ::operator delete(old_rep); - } - } - return *this; -} - -inline -__libcpp_refstring::~__libcpp_refstring() { - if (__uses_refcount()) { - _Rep_base* rep = rep_from_data(__imp_); -#ifdef _LIBCPP_USE_ATOMIC - if (rep->count.fetch_sub(1) == 0) { -#else - if (__sync_add_and_fetch(&rep->count, count_t(-1)) < 0) { -#endif - ::operator delete(rep); - } - } -} - -inline -bool __libcpp_refstring::__uses_refcount() const { -#if defined(_LIBCPP_CHECK_FOR_GCC_EMPTY_STRING_STORAGE) - return __imp_ != get_gcc_empty_string_storage(); -#else - return true; -#endif -} - -_LIBCPP_END_NAMESPACE_STD - -#endif //_LIBCPP_REFSTRING_H +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +namespace __refstring_imp { namespace { +typedef int count_t; + +struct _Rep_base { + std::size_t len; + std::size_t cap; +#ifdef _LIBCPP_USE_ATOMIC + std::atomic<count_t> count; +#else + count_t count; +#endif +}; + +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); +} + +#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* +get_gcc_empty_string_storage() noexcept +{ + static const char* p = compute_gcc_empty_string_storage(); + return p; +} +#endif + +}} // 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 __libcpp_refstring &s) noexcept + : __imp_(s.__imp_) +{ + if (__uses_refcount()) +#ifdef _LIBCPP_USE_ATOMIC + rep_from_data(__imp_)->count.fetch_add(1); +#else + __libcpp_atomic_add(&rep_from_data(__imp_)->count, 1); +#endif +} + +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()) +#ifdef _LIBCPP_USE_ATOMIC + rep_from_data(__imp_)->count.fetch_add(1); +#else + __libcpp_atomic_add(&rep_from_data(__imp_)->count, 1); +#endif + + if (adjust_old_count) + { +#ifdef _LIBCPP_USE_ATOMIC + if (old_rep->count.fetch_sub(1) == 0) +#else + if (__libcpp_atomic_add(&old_rep->count, count_t(-1)) < 0) +#endif + { + ::operator delete(old_rep); + } + } + return *this; +} + +inline +__libcpp_refstring::~__libcpp_refstring() { + if (__uses_refcount()) { + _Rep_base* rep = rep_from_data(__imp_); +#ifdef _LIBCPP_USE_ATOMIC + if (rep->count.fetch_sub(1) == 0) { +#else + if (__sync_add_and_fetch(&rep->count, count_t(-1)) < 0) { +#endif + ::operator delete(rep); + } + } +} + +inline +bool __libcpp_refstring::__uses_refcount() const { +#if defined(_LIBCPP_CHECK_FOR_GCC_EMPTY_STRING_STORAGE) + return __imp_ != get_gcc_empty_string_storage(); +#else + return true; +#endif +} + +_LIBCPP_END_NAMESPACE_STD + +#endif //_LIBCPP_REFSTRING_H diff --git a/contrib/libs/cxxsupp/libcxx/src/include/sso_allocator.h b/contrib/libs/cxxsupp/libcxx/src/include/sso_allocator.h index 2baf599c5c..9590bac79c 100644 --- a/contrib/libs/cxxsupp/libcxx/src/include/sso_allocator.h +++ b/contrib/libs/cxxsupp/libcxx/src/include/sso_allocator.h @@ -1,77 +1,77 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// +// -*- 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 <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 -{ - typename aligned_storage<sizeof(_Tp) * _Np>::type buf_; - bool __allocated_; -public: - typedef size_t size_type; - typedef _Tp* pointer; - typedef _Tp value_type; - - _LIBCPP_INLINE_VISIBILITY __sso_allocator() throw() : __allocated_(false) {} - _LIBCPP_INLINE_VISIBILITY __sso_allocator(const __sso_allocator&) throw() : __allocated_(false) {} - template <class _Up> _LIBCPP_INLINE_VISIBILITY __sso_allocator(const __sso_allocator<_Up, _Np>&) throw() - : __allocated_(false) {} -private: - __sso_allocator& operator=(const __sso_allocator&); -public: - _LIBCPP_INLINE_VISIBILITY 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); - } +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_SSO_ALLOCATOR_H +#define _LIBCPP_SSO_ALLOCATOR_H + +#include <__config> +#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 +{ + typename aligned_storage<sizeof(_Tp) * _Np>::type buf_; + bool __allocated_; +public: + typedef size_t size_type; + typedef _Tp* pointer; + typedef _Tp value_type; + + _LIBCPP_INLINE_VISIBILITY __sso_allocator() throw() : __allocated_(false) {} + _LIBCPP_INLINE_VISIBILITY __sso_allocator(const __sso_allocator&) throw() : __allocated_(false) {} + template <class _Up> _LIBCPP_INLINE_VISIBILITY __sso_allocator(const __sso_allocator<_Up, _Np>&) throw() + : __allocated_(false) {} +private: + __sso_allocator& operator=(const __sso_allocator&); +public: + _LIBCPP_INLINE_VISIBILITY 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_INLINE_VISIBILITY void deallocate(pointer __p, size_type __n) - { - if (__p == (pointer)&buf_) - __allocated_ = false; - else - allocator<_Tp>().deallocate(__p, __n); - } - _LIBCPP_INLINE_VISIBILITY size_type max_size() const throw() {return size_type(~0) / sizeof(_Tp);} - - _LIBCPP_INLINE_VISIBILITY - bool operator==(const __sso_allocator& __a) const {return &buf_ == &__a.buf_;} - _LIBCPP_INLINE_VISIBILITY - bool operator!=(const __sso_allocator& __a) const {return &buf_ != &__a.buf_;} -}; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP_SSO_ALLOCATOR_H + { + if (__p == (pointer)&buf_) + __allocated_ = false; + else + allocator<_Tp>().deallocate(__p, __n); + } + _LIBCPP_INLINE_VISIBILITY size_type max_size() const throw() {return size_type(~0) / sizeof(_Tp);} + + _LIBCPP_INLINE_VISIBILITY + bool operator==(const __sso_allocator& __a) const {return &buf_ == &__a.buf_;} + _LIBCPP_INLINE_VISIBILITY + bool operator!=(const __sso_allocator& __a) const {return &buf_ != &__a.buf_;} +}; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_SSO_ALLOCATOR_H |