Skip to content

Commit ff95378

Browse files
committed
Add __libcpp_allocate and __libcpp_deallocate in the absense of align allocation and sized deallocation
1 parent a83b5ca commit ff95378

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

libcxx/include/__utility/small_buffer.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,26 +61,30 @@ class __small_buffer {
6161
return *std::launder(reinterpret_cast<_Stored**>(__buffer_));
6262
}
6363

64-
# ifdef _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION
6564
template <class _Stored>
6665
_LIBCPP_HIDE_FROM_ABI _Stored* __alloc() {
6766
if constexpr (__fits_in_buffer<_Stored>) {
6867
return std::launder(reinterpret_cast<_Stored*>(__buffer_));
6968
} else {
69+
# ifdef _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION
7070
byte* __allocation = static_cast<byte*>(::operator new[](sizeof(_Stored), align_val_t{alignof(_Stored)}));
7171
std::construct_at(reinterpret_cast<byte**>(__buffer_), __allocation);
7272
return std::launder(reinterpret_cast<_Stored*>(__allocation));
73+
# else
74+
return static_cast<_Stored*>(std::__libcpp_allocate(_BufferSize* sizeof(byte), _LIBCPP_ALIGNOF(byte)));
75+
# endif // _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION
7376
}
7477
}
7578

76-
# endif // _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION
77-
# ifdef _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION
7879
template <class _Stored>
7980
_LIBCPP_HIDE_FROM_ABI void __dealloc() noexcept {
8081
if constexpr (!__fits_in_buffer<_Stored>)
82+
# ifdef _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION
8183
::operator delete[](*reinterpret_cast<void**>(__buffer_), sizeof(_Stored), align_val_t{alignof(_Stored)});
82-
}
84+
# else
85+
std::__libcpp_deallocate((void*)__buffer_, _BufferSize * sizeof(byte), _LIBCPP_ALIGNOF(_Stored));
8386
# endif // _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION
87+
}
8488

8589
template <class _Stored, class... _Args>
8690
_LIBCPP_HIDE_FROM_ABI void __construct(_Args&&... __args) {

0 commit comments

Comments
 (0)