|
18 | 18 | #define SWIFT_RUNTIME_HEAP_H
|
19 | 19 |
|
20 | 20 | #include <cstddef>
|
21 |
| -#include <cstdint> |
22 |
| -#include <cstdlib> |
23 | 21 | #include <new>
|
24 |
| -#include <type_traits> |
25 | 22 | #include <utility>
|
26 | 23 |
|
27 | 24 | #include "swift/Runtime/Config.h"
|
28 | 25 |
|
29 |
| -#if defined(_WIN32) |
30 |
| -#include <malloc.h> |
31 |
| -#endif |
32 |
| - |
33 | 26 | namespace swift {
|
34 | 27 | // Allocate plain old memory. This is the generalized entry point
|
35 | 28 | // Never returns nil. The returned memory is uninitialized.
|
@@ -85,77 +78,6 @@ static inline void swift_cxx_deleteObject(T *ptr) {
|
85 | 78 | swift_slowDealloc(ptr, sizeof(T), alignof(T) - 1);
|
86 | 79 | }
|
87 | 80 | }
|
88 |
| - |
89 |
| -namespace { |
90 |
| -// This is C++17 and newer, so we simply re-define it. Since the codebase is |
91 |
| -// C++14, assume that DR1558 is accounted for and that unused parameters in alias |
92 |
| -// templates are guaranteed to ensure SFINAE and are not ignored. |
93 |
| -template <typename ...> |
94 |
| -using void_t = void; |
95 |
| - |
96 |
| -template <typename T, typename = void> |
97 |
| -struct is_aligned_alloc_aware : std::false_type {}; |
98 |
| - |
99 |
| -template <typename T> |
100 |
| -struct is_aligned_alloc_aware<T, void_t<decltype(T::operator new(0))>> |
101 |
| - : std::true_type {}; |
102 |
| -} |
103 |
| - |
104 |
| -template <std::size_t Alignment_> |
105 |
| -struct requires_aligned_alloc { |
106 |
| -#if defined(__cpp_aligned_new) |
107 |
| - // If we have C++17 or newer we can use the alignment aware allocation |
108 |
| - // implicitly. |
109 |
| - static constexpr const bool value = false; |
110 |
| -#else |
111 |
| -#if defined(__STDCPP_DEFAULT_NEW_ALIGNMENT__) |
112 |
| - static constexpr const bool value = |
113 |
| - Alignment_ > std::alignment_of<std::max_align_t>::value && |
114 |
| - Alignment_ > __STDCPP_DEFAULT_NEW_ALIGNMENT__; |
115 |
| -#else |
116 |
| - static constexpr const bool value = |
117 |
| - Alignment_ > std::alignment_of<std::max_align_t>::value; |
118 |
| -#endif |
119 |
| -#endif |
120 |
| -}; |
121 |
| - |
122 |
| -template <std::size_t Alignment_, |
123 |
| - bool = requires_aligned_alloc<Alignment_>::value> |
124 |
| -struct aligned_alloc; |
125 |
| - |
126 |
| -template <std::size_t Alignment_> |
127 |
| -struct aligned_alloc<Alignment_, false> {}; |
128 |
| - |
129 |
| -template <std::size_t Alignment_> |
130 |
| -struct aligned_alloc<Alignment_, true> { |
131 |
| - [[nodiscard]] void *operator new(std::size_t size) noexcept { |
132 |
| -#if defined(_WIN32) |
133 |
| - return _aligned_malloc(size, Alignment_); |
134 |
| -#else |
135 |
| - static_assert(Alignment_ >= sizeof(void *), |
136 |
| - "posix_memalign requires minimal alignment of pointer"); |
137 |
| - void *ptr = nullptr; |
138 |
| - (void)posix_memalign(&ptr, Alignment_, size); |
139 |
| - return ptr; |
140 |
| -#endif |
141 |
| - } |
142 |
| - |
143 |
| - void operator delete(void *ptr) noexcept { |
144 |
| -#if defined(_WIN32) |
145 |
| - _aligned_free(ptr); |
146 |
| -#else |
147 |
| - free(ptr); |
148 |
| -#endif |
149 |
| - } |
150 |
| - |
151 |
| -#if defined(_WIN32) |
152 |
| - // FIXME: why is this even needed? This is not permitted as per the C++ |
153 |
| - // standard new.delete.placement (§17.6.3.4). |
154 |
| - [[nodiscard]] void *operator new(std::size_t size, void *where) noexcept { |
155 |
| - return ::operator new(size, where); |
156 |
| - } |
157 |
| -#endif |
158 |
| -}; |
159 | 81 | }
|
160 | 82 |
|
161 | 83 | #endif // SWIFT_RUNTIME_HEAP_H
|
0 commit comments