Fix recursion in aligned_allocation. Rename aligned_alloc.hpp to aligned_allocation.hpp to be consistent:

- "aligned_allocation" will be the internal name for the utility in the Container library.
- "aligned_alloc" is the C11 function name
This commit is contained in:
Ion Gaztañaga
2025-12-26 16:14:33 +01:00
parent e19e121cf4
commit c99257c1dc
2 changed files with 19 additions and 10 deletions

View File

@@ -7,8 +7,8 @@
// See http://www.boost.org/libs/container for documentation.
//
//////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_CONTAINER_DETAIL_ALIGNED_ALLOC_HPP
#define BOOST_CONTAINER_DETAIL_ALIGNED_ALLOC_HPP
#ifndef BOOST_CONTAINER_DETAIL_ALIGNED_ALLOCATION_HPP
#define BOOST_CONTAINER_DETAIL_ALIGNED_ALLOCATION_HPP
#ifndef BOOST_CONFIG_HPP
# include <boost/config.hpp>
@@ -25,8 +25,6 @@
#include <unistd.h> //Include it to detect POSIX features
#if defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L)
#define BOOST_CONTAINER_HAS_POSIX_MEMALIGN
#elif defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE >= 600)
#define BOOST_CONTAINER_HAS_POSIX_MEMALIGN
#elif defined(__APPLE__)
#include <Availability.h>
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500
@@ -86,7 +84,7 @@ inline void* aligned_allocate(std::size_t al, std::size_t sz)
std::size_t rounded_size = std::size_t(sz + al - 1u) & ~std::size_t(al - 1);
//Check for rounded size overflow
return rounded_size ? aligned_allocate(al, rounded_size) : 0;
return rounded_size ? ::aligned_alloc(al, rounded_size) : 0;
}
#elif defined(BOOST_CONTAINER_HAS_ALIGNED_MALLOC)
@@ -106,12 +104,12 @@ inline void* aligned_allocate(std::size_t al, std::size_t sz)
return 0;
//Now align the returned pointer (which will be aligned at least to sizeof(void*)
std::size_t raw_addr = reinterpret_cast<std::size_t>(mptr);
std::size_t offset = sizeof(void*);
const std::size_t raw_addr = reinterpret_cast<std::size_t>(mptr);
const std::size_t offset = sizeof(void*);
void *const ptr = reinterpret_cast<void*>((raw_addr + offset + al - 1u) & ~(al - 1u));
// Store the original pointer just before the aligned address
void** backpointer = reinterpret_cast<void**>(ptr) - 1;
void** const backpointer = reinterpret_cast<void**>(ptr) - 1;
*backpointer = mptr;
return ptr;
}
@@ -149,4 +147,4 @@ inline void aligned_deallocate(void* ptr)
} //namespace container {
} //namespace boost {
#endif //#ifndef BOOST_CONTAINER_DETAIL_ALIGNED_ALLOC_HPP
#endif //#ifndef BOOST_CONTAINER_DETAIL_ALIGNED_ALLOCATION_HPP

View File

@@ -23,13 +23,24 @@
#include <boost/container/detail/type_traits.hpp>
#if !defined(__cpp_aligned_new)
#include <boost/container/detail/aligned_alloc.hpp>
#include <boost/container/detail/aligned_allocation.hpp>
#endif
namespace boost {
namespace container {
namespace dtl {
//For GCC and clang there are several cases where __STDCPP_DEFAULT_NEW_ALIGNMENT__
//is not properly synchronized with the default alignment of malloc. Examples:
//
// - On Unix platforms, a programmer uses jemalloc, mimalloc that have historically a lower
// default alignment (to waste less memory)
//
// - On Windows platforms, the allocator is provided by MSVCRT o UCRT that uses HeapAlloc
// (e.g. 8 byte alignment for x86 and 16 bytes for x64)
//
// - On Apple platforms the default malloc implementation has a reduced defaykt alignment
// even on ARM64 platforms.
BOOST_CONTAINER_FORCEINLINE bool operator_new_raw_overaligned(std::size_t alignment)
{
//In MacOs, the default allocator can return data aligned to 8 bytes