| 115 | # if _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION |
| 116 | |
| 117 | static void* operator_new_aligned_impl(std::size_t size, std::align_val_t alignment) { |
| 118 | if (size == 0) |
| 119 | size = 1; |
| 120 | if (static_cast<size_t>(alignment) < sizeof(void*)) |
| 121 | alignment = std::align_val_t(sizeof(void*)); |
| 122 | |
| 123 | // Try allocating memory. If allocation fails and there is a new_handler, |
| 124 | // call it to try free up memory, and try again until it succeeds, or until |
| 125 | // the new_handler decides to terminate. |
| 126 | void* p; |
| 127 | while ((p = std::__libcpp_aligned_alloc(static_cast<std::size_t>(alignment), size)) == nullptr) { |
| 128 | std::new_handler nh = std::get_new_handler(); |
| 129 | if (nh) |
| 130 | nh(); |
| 131 | else |
| 132 | break; |
| 133 | } |
| 134 | return p; |
| 135 | } |
| 136 | |
| 137 | _LIBCPP_OVERRIDABLE_FUNCTION(void*, operator new, (std::size_t size, std::align_val_t alignment)) _THROW_BAD_ALLOC { |
| 138 | void* p = operator_new_aligned_impl(size, alignment); |
no test coverage detected