mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-03 19:22:27 +00:00
Release Cosmopolitan v3.6.0
This release is an atomic upgrade to GCC 14.1.0 with C23 and C++23
This commit is contained in:
parent
62ace3623a
commit
5660ec4741
1585 changed files with 117353 additions and 271644 deletions
81
third_party/libcxx/__memory/allocation_guard.h
vendored
81
third_party/libcxx/__memory/allocation_guard.h
vendored
|
@ -11,6 +11,7 @@
|
|||
#define _LIBCPP___MEMORY_ALLOCATION_GUARD_H
|
||||
|
||||
#include <__config>
|
||||
#include <__memory/addressof.h>
|
||||
#include <__memory/allocator_traits.h>
|
||||
#include <__utility/move.h>
|
||||
#include <cstddef>
|
||||
|
@ -19,6 +20,9 @@
|
|||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
_LIBCPP_PUSH_MACROS
|
||||
#include <__undef_macros>
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
// Helper class to allocate memory using an Allocator in an exception safe
|
||||
|
@ -40,44 +44,65 @@ _LIBCPP_BEGIN_NAMESPACE_STD
|
|||
//
|
||||
// This is similar to a unique_ptr, except it's easier to use with a
|
||||
// custom allocator.
|
||||
template<class _Alloc>
|
||||
template <class _Alloc>
|
||||
struct __allocation_guard {
|
||||
using _Pointer = typename allocator_traits<_Alloc>::pointer;
|
||||
using _Size = typename allocator_traits<_Alloc>::size_type;
|
||||
using _Pointer = typename allocator_traits<_Alloc>::pointer;
|
||||
using _Size = typename allocator_traits<_Alloc>::size_type;
|
||||
|
||||
template<class _AllocT> // we perform the allocator conversion inside the constructor
|
||||
_LIBCPP_HIDE_FROM_ABI
|
||||
explicit __allocation_guard(_AllocT __alloc, _Size __n)
|
||||
: __alloc_(_VSTD::move(__alloc))
|
||||
, __n_(__n)
|
||||
, __ptr_(allocator_traits<_Alloc>::allocate(__alloc_, __n_)) // initialization order is important
|
||||
{ }
|
||||
template <class _AllocT> // we perform the allocator conversion inside the constructor
|
||||
_LIBCPP_HIDE_FROM_ABI explicit __allocation_guard(_AllocT __alloc, _Size __n)
|
||||
: __alloc_(std::move(__alloc)),
|
||||
__n_(__n),
|
||||
__ptr_(allocator_traits<_Alloc>::allocate(__alloc_, __n_)) // initialization order is important
|
||||
{}
|
||||
|
||||
_LIBCPP_HIDE_FROM_ABI
|
||||
~__allocation_guard() _NOEXCEPT {
|
||||
if (__ptr_ != nullptr) {
|
||||
allocator_traits<_Alloc>::deallocate(__alloc_, __ptr_, __n_);
|
||||
}
|
||||
_LIBCPP_HIDE_FROM_ABI ~__allocation_guard() _NOEXCEPT { __destroy(); }
|
||||
|
||||
_LIBCPP_HIDE_FROM_ABI __allocation_guard(const __allocation_guard&) = delete;
|
||||
_LIBCPP_HIDE_FROM_ABI __allocation_guard(__allocation_guard&& __other) _NOEXCEPT
|
||||
: __alloc_(std::move(__other.__alloc_)),
|
||||
__n_(__other.__n_),
|
||||
__ptr_(__other.__ptr_) {
|
||||
__other.__ptr_ = nullptr;
|
||||
}
|
||||
|
||||
_LIBCPP_HIDE_FROM_ABI __allocation_guard& operator=(const __allocation_guard& __other) = delete;
|
||||
_LIBCPP_HIDE_FROM_ABI __allocation_guard& operator=(__allocation_guard&& __other) _NOEXCEPT {
|
||||
if (std::addressof(__other) != this) {
|
||||
__destroy();
|
||||
|
||||
__alloc_ = std::move(__other.__alloc_);
|
||||
__n_ = __other.__n_;
|
||||
__ptr_ = __other.__ptr_;
|
||||
__other.__ptr_ = nullptr;
|
||||
}
|
||||
|
||||
_LIBCPP_HIDE_FROM_ABI
|
||||
_Pointer __release_ptr() _NOEXCEPT { // not called __release() because it's a keyword in objective-c++
|
||||
_Pointer __tmp = __ptr_;
|
||||
__ptr_ = nullptr;
|
||||
return __tmp;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
_LIBCPP_HIDE_FROM_ABI
|
||||
_Pointer __get() const _NOEXCEPT {
|
||||
return __ptr_;
|
||||
}
|
||||
_LIBCPP_HIDE_FROM_ABI _Pointer
|
||||
__release_ptr() _NOEXCEPT { // not called __release() because it's a keyword in objective-c++
|
||||
_Pointer __tmp = __ptr_;
|
||||
__ptr_ = nullptr;
|
||||
return __tmp;
|
||||
}
|
||||
|
||||
_LIBCPP_HIDE_FROM_ABI _Pointer __get() const _NOEXCEPT { return __ptr_; }
|
||||
|
||||
private:
|
||||
_Alloc __alloc_;
|
||||
_Size __n_;
|
||||
_Pointer __ptr_;
|
||||
_LIBCPP_HIDE_FROM_ABI void __destroy() _NOEXCEPT {
|
||||
if (__ptr_ != nullptr) {
|
||||
allocator_traits<_Alloc>::deallocate(__alloc_, __ptr_, __n_);
|
||||
}
|
||||
}
|
||||
|
||||
_Alloc __alloc_;
|
||||
_Size __n_;
|
||||
_Pointer __ptr_;
|
||||
};
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
_LIBCPP_POP_MACROS
|
||||
|
||||
#endif // _LIBCPP___MEMORY_ALLOCATION_GUARD_H
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue