13
0

Revert "Replace boost::aligned_storage with alignas std::array"

This reverts commit 32ff87f7f6.

This causes issues on macOS/clang
```
../libs/pbd/pbd/stack_allocator.h:152:53: note: destructor of 'StackAllocator<std::__tree_node<std::__value_type<ARDOUR::DataType, std::map<unsigned int, unsigned int, std::less<unsigned int>, PBD::StackAllocator<std::pair<const unsigned int, unsigned int>, 16>>>, void *>, 2>' is implicitly deleted because field '_buf' has a deleted destructor
  152 |         alignas(16) std::array<value_type, stack_capacity> _buf;
```
This commit is contained in:
Robin Gareus 2024-11-19 18:01:54 +01:00
parent 2a620c64e9
commit 4a99026cc9
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04

View File

@ -19,6 +19,7 @@
#ifndef PBD_STACK_ALLOCATOR_H
#define PBD_STACK_ALLOCATOR_H
#include <boost/type_traits/aligned_storage.hpp>
#include <limits>
#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 <typename U, size_t other_capacity>
StackAllocator (const StackAllocator<U, other_capacity>&)
: 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 <class U>
@ -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<value_type, stack_capacity> _buf;
typedef typename boost::aligned_storage<sizeof (T) * stack_capacity, 16>::type align_t;
align_t _buf;
pointer _ptr;
};