From 4a99026cc94ee74963b63e1bd950115ddcfd8cd3 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Tue, 19 Nov 2024 18:01:54 +0100 Subject: [PATCH] Revert "Replace boost::aligned_storage with alignas std::array" This reverts commit 32ff87f7f6da97830ab002cc64565bafd0b65dc6. This causes issues on macOS/clang ``` ../libs/pbd/pbd/stack_allocator.h:152:53: note: destructor of 'StackAllocator, PBD::StackAllocator, 16>>>, void *>, 2>' is implicitly deleted because field '_buf' has a deleted destructor 152 | alignas(16) std::array _buf; ``` --- libs/pbd/pbd/stack_allocator.h | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/libs/pbd/pbd/stack_allocator.h b/libs/pbd/pbd/stack_allocator.h index 742cf39b6d..9eed081ec0 100644 --- a/libs/pbd/pbd/stack_allocator.h +++ b/libs/pbd/pbd/stack_allocator.h @@ -19,6 +19,7 @@ #ifndef PBD_STACK_ALLOCATOR_H #define PBD_STACK_ALLOCATOR_H +#include #include #include "pbd/libpbd_visibility.h" @@ -60,22 +61,22 @@ public: }; StackAllocator () - : _ptr (_buf.data()) + : _ptr ((pointer)&_buf) { } StackAllocator (const StackAllocator&) - : StackAllocator () + : _ptr ((pointer)&_buf) { } template StackAllocator (const StackAllocator&) - : StackAllocator () + : _ptr ((pointer)&_buf) { } /* inspired by http://howardhinnant.github.io/stack_alloc.h */ pointer allocate (size_type n, void* hint = 0) { - if (_buf.data() + stack_capacity >= _ptr + n) { + if ((pointer)&_buf + stack_capacity >= _ptr + n) { DEBUG_STACK_ALLOC ("Allocate %ld item(s) of size %zu on the stack\n", n, sizeof (T)); pointer rv = _ptr; _ptr += n; @@ -107,12 +108,12 @@ public: bool operator== (StackAllocator const& a) const { - return _buf.data() == a._buf.data(); + return &_buf == &a._buf; } bool operator!= (StackAllocator const& a) const { - return _buf.data() != a._buf.data(); + return &_buf != &a._buf; } template @@ -146,10 +147,12 @@ private: bool pointer_in_buffer (pointer const p) { - return (_buf.data() <= p && p < _buf.data() + stack_capacity); + return ((pointer const)&_buf <= p && p < (pointer const)&_buf + stack_capacity); } - alignas(16) std::array _buf; + typedef typename boost::aligned_storage::type align_t; + + align_t _buf; pointer _ptr; };