|
14 | 14 |
|
15 | 15 | #include <array>
|
16 | 16 | #include <cstdint>
|
17 |
| -#include <exception> |
| 17 | +#include <memory_resource> |
18 | 18 |
|
19 | 19 | #include <libhal-exceptions/control.hpp>
|
20 |
| -#include <memory_resource> |
21 | 20 |
|
22 | 21 | namespace __cxxabiv1 { // NOLINT
|
23 | 22 | std::terminate_handler __terminate_handler = +[]() { // NOLINT
|
@@ -46,19 +45,12 @@ std::terminate_handler get_terminate() noexcept
|
46 | 45 | *
|
47 | 46 | * This allocator can only allocates space for a single exception object at a
|
48 | 47 | * time.
|
49 |
| - * |
50 |
| - * @tparam size - size of the exception object memory buffer. If this is set too |
51 |
| - * small (less than 128 bytes), then it is likely that the memory will not be |
52 |
| - * enough for any exception runtime and will result in terminate being called. |
53 | 48 | */
|
54 |
| -template<size_t size> |
55 | 49 | class single_exception_allocator : public std::pmr::memory_resource
|
56 | 50 | {
|
57 | 51 | public:
|
58 | 52 | single_exception_allocator() = default;
|
59 |
| - virtual ~single_exception_allocator() override |
60 |
| - { |
61 |
| - } |
| 53 | + ~single_exception_allocator() override = default; |
62 | 54 |
|
63 | 55 | private:
|
64 | 56 | void* do_allocate(std::size_t p_size,
|
@@ -87,19 +79,18 @@ class single_exception_allocator : public std::pmr::memory_resource
|
87 | 79 | return this == &other;
|
88 | 80 | }
|
89 | 81 |
|
90 |
| - std::array<std::uint8_t, size> m_buffer{}; |
| 82 | + std::array<std::uint8_t, 256> m_buffer{}; |
91 | 83 | bool m_allocated = false;
|
92 | 84 | };
|
93 | 85 |
|
94 | 86 | // TODO(#11): Add macro to IFDEF this out if the user want to save 256 bytes.
|
95 |
| -using default_exception_allocator = single_exception_allocator<256>; |
96 |
| -default_exception_allocator _default_allocator{}; // NOLINT |
| 87 | +single_exception_allocator _default_allocator{}; // NOLINT |
97 | 88 | std::pmr::memory_resource* _exception_allocator =
|
98 | 89 | &_default_allocator; // NOLINT
|
99 | 90 |
|
100 |
| -void set_exception_allocator(std::pmr::memory_resource* p_allocator) noexcept |
| 91 | +void set_exception_allocator(std::pmr::memory_resource& p_allocator) noexcept |
101 | 92 | {
|
102 |
| - _exception_allocator = p_allocator; |
| 93 | + _exception_allocator = &p_allocator; |
103 | 94 | }
|
104 | 95 |
|
105 | 96 | std::pmr::memory_resource& get_exception_allocator() noexcept
|
|
0 commit comments