Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===--------------------------- new.cpp ----------------------------------===// |
| 2 | // |
Howard Hinnant | c566dc3 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
Howard Hinnant | ee11c31 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Marshall Clow | 3bf7713 | 2013-09-11 01:38:42 +0000 | [diff] [blame] | 10 | #define _LIBCPP_BUILDING_NEW |
| 11 | |
Howard Hinnant | 155c2af | 2010-05-24 17:49:41 +0000 | [diff] [blame] | 12 | #include <stdlib.h> |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 13 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 14 | #include "new" |
| 15 | |
Eric Fiselier | 224f960 | 2017-01-02 22:27:45 +0000 | [diff] [blame] | 16 | #if defined(__APPLE__) && !defined(LIBCXXRT) |
Howard Hinnant | ffb308e | 2010-08-22 00:03:27 +0000 | [diff] [blame] | 17 | #include <cxxabi.h> |
Howard Hinnant | 4ad4eee | 2012-02-02 20:48:35 +0000 | [diff] [blame] | 18 | |
| 19 | #ifndef _LIBCPPABI_VERSION |
| 20 | // On Darwin, there are two STL shared libraries and a lower level ABI |
Marshall Clow | f98383c | 2013-11-11 23:27:19 +0000 | [diff] [blame] | 21 | // shared library. The global holding the current new handler is |
Howard Hinnant | 4ad4eee | 2012-02-02 20:48:35 +0000 | [diff] [blame] | 22 | // in the ABI library and named __cxa_new_handler. |
| 23 | #define __new_handler __cxxabiapple::__cxa_new_handler |
| 24 | #endif |
Howard Hinnant | ffb308e | 2010-08-22 00:03:27 +0000 | [diff] [blame] | 25 | #else // __APPLE__ |
Benjamin Kramer | af9fc2c | 2015-10-16 11:14:30 +0000 | [diff] [blame] | 26 | #if defined(LIBCXXRT) || defined(LIBCXX_BUILDING_LIBCXXABI) |
Howard Hinnant | a4cabeb | 2012-07-26 17:42:39 +0000 | [diff] [blame] | 27 | #include <cxxabi.h> |
Benjamin Kramer | af9fc2c | 2015-10-16 11:14:30 +0000 | [diff] [blame] | 28 | #endif // defined(LIBCXX_BUILDING_LIBCXXABI) |
Eric Fiselier | 224f960 | 2017-01-02 22:27:45 +0000 | [diff] [blame] | 29 | #if !defined(_LIBCPPABI_VERSION) && !defined(__GLIBCXX__) |
Howard Hinnant | a4cabeb | 2012-07-26 17:42:39 +0000 | [diff] [blame] | 30 | static std::new_handler __new_handler; |
| 31 | #endif // _LIBCPPABI_VERSION |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 32 | #endif |
| 33 | |
Peter Collingbourne | dc00995 | 2013-10-06 22:13:16 +0000 | [diff] [blame] | 34 | #ifndef __GLIBCXX__ |
| 35 | |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 36 | // Implement all new and delete operators as weak definitions |
Eric Fiselier | cd4496b | 2015-08-20 05:23:16 +0000 | [diff] [blame] | 37 | // in this shared library, so that they can be overridden by programs |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 38 | // that define non-weak copies of the functions. |
| 39 | |
Shoaib Meenai | 2d71db4 | 2016-11-16 22:18:10 +0000 | [diff] [blame] | 40 | _LIBCPP_WEAK |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 41 | void * |
Eric Fiselier | 162922f | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 42 | operator new(std::size_t size) _THROW_BAD_ALLOC |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 43 | { |
| 44 | if (size == 0) |
| 45 | size = 1; |
| 46 | void* p; |
| 47 | while ((p = ::malloc(size)) == 0) |
| 48 | { |
Howard Hinnant | 34468d4 | 2010-08-22 13:53:14 +0000 | [diff] [blame] | 49 | // If malloc fails and there is a new_handler, |
| 50 | // call it to try free up memory. |
Howard Hinnant | 8c65b45 | 2010-12-04 19:56:43 +0000 | [diff] [blame] | 51 | std::new_handler nh = std::get_new_handler(); |
Howard Hinnant | f64dfce | 2010-12-04 19:54:11 +0000 | [diff] [blame] | 52 | if (nh) |
| 53 | nh(); |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 54 | else |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 55 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 56 | throw std::bad_alloc(); |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 57 | #else |
| 58 | break; |
| 59 | #endif |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 60 | } |
| 61 | return p; |
| 62 | } |
| 63 | |
Shoaib Meenai | 2d71db4 | 2016-11-16 22:18:10 +0000 | [diff] [blame] | 64 | _LIBCPP_WEAK |
Eric Fiselier | 162922f | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 65 | void * |
| 66 | operator new(std::size_t size, std::align_val_t alignment) _THROW_BAD_ALLOC |
| 67 | { |
| 68 | if (size == 0) |
| 69 | size = 1; |
| 70 | if (static_cast<size_t>(alignment) < sizeof(void*)) |
| 71 | alignment = std::align_val_t(sizeof(void*)); |
| 72 | void* p; |
Eric Fiselier | 29aaae1 | 2016-12-23 20:17:23 +0000 | [diff] [blame] | 73 | #if defined(_WIN32) |
| 74 | while ((p = _aligned_malloc(size, static_cast<size_t>(alignment))) == nullptr) |
| 75 | #else |
Eric Fiselier | 162922f | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 76 | while (::posix_memalign(&p, static_cast<size_t>(alignment), size) != 0) |
Eric Fiselier | 29aaae1 | 2016-12-23 20:17:23 +0000 | [diff] [blame] | 77 | #endif |
Eric Fiselier | 162922f | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 78 | { |
| 79 | // If posix_memalign fails and there is a new_handler, |
| 80 | // call it to try free up memory. |
| 81 | std::new_handler nh = std::get_new_handler(); |
| 82 | if (nh) |
| 83 | nh(); |
| 84 | else { |
| 85 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 86 | throw std::bad_alloc(); |
| 87 | #else |
| 88 | p = nullptr; // posix_memalign doesn't initialize 'p' on failure |
| 89 | break; |
| 90 | #endif |
| 91 | } |
| 92 | } |
| 93 | return p; |
| 94 | } |
| 95 | |
Shoaib Meenai | 2d71db4 | 2016-11-16 22:18:10 +0000 | [diff] [blame] | 96 | _LIBCPP_WEAK |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 97 | void* |
Howard Hinnant | 1bc52cf | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 98 | operator new(size_t size, const std::nothrow_t&) _NOEXCEPT |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 99 | { |
| 100 | void* p = 0; |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 101 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 102 | try |
| 103 | { |
Howard Hinnant | ffb308e | 2010-08-22 00:03:27 +0000 | [diff] [blame] | 104 | #endif // _LIBCPP_NO_EXCEPTIONS |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 105 | p = ::operator new(size); |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 106 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 107 | } |
| 108 | catch (...) |
| 109 | { |
| 110 | } |
Howard Hinnant | ffb308e | 2010-08-22 00:03:27 +0000 | [diff] [blame] | 111 | #endif // _LIBCPP_NO_EXCEPTIONS |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 112 | return p; |
| 113 | } |
| 114 | |
Shoaib Meenai | 2d71db4 | 2016-11-16 22:18:10 +0000 | [diff] [blame] | 115 | _LIBCPP_WEAK |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 116 | void* |
Eric Fiselier | 162922f | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 117 | operator new(size_t size, std::align_val_t alignment, const std::nothrow_t&) _NOEXCEPT |
| 118 | { |
| 119 | void* p = 0; |
| 120 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 121 | try |
| 122 | { |
| 123 | #endif // _LIBCPP_NO_EXCEPTIONS |
| 124 | p = ::operator new(size, alignment); |
| 125 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 126 | } |
| 127 | catch (...) |
| 128 | { |
| 129 | } |
| 130 | #endif // _LIBCPP_NO_EXCEPTIONS |
| 131 | return p; |
| 132 | } |
| 133 | |
Shoaib Meenai | 2d71db4 | 2016-11-16 22:18:10 +0000 | [diff] [blame] | 134 | _LIBCPP_WEAK |
Eric Fiselier | 162922f | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 135 | void* |
| 136 | operator new[](size_t size) _THROW_BAD_ALLOC |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 137 | { |
| 138 | return ::operator new(size); |
| 139 | } |
| 140 | |
Shoaib Meenai | 2d71db4 | 2016-11-16 22:18:10 +0000 | [diff] [blame] | 141 | _LIBCPP_WEAK |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 142 | void* |
Eric Fiselier | 162922f | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 143 | operator new[](size_t size, std::align_val_t alignment) _THROW_BAD_ALLOC |
| 144 | { |
| 145 | return ::operator new(size, alignment); |
| 146 | } |
| 147 | |
Shoaib Meenai | 2d71db4 | 2016-11-16 22:18:10 +0000 | [diff] [blame] | 148 | _LIBCPP_WEAK |
Eric Fiselier | 162922f | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 149 | void* |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 150 | operator new[](size_t size, const std::nothrow_t&) _NOEXCEPT |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 151 | { |
| 152 | void* p = 0; |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 153 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 154 | try |
| 155 | { |
Howard Hinnant | ffb308e | 2010-08-22 00:03:27 +0000 | [diff] [blame] | 156 | #endif // _LIBCPP_NO_EXCEPTIONS |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 157 | p = ::operator new[](size); |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 158 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 159 | } |
| 160 | catch (...) |
| 161 | { |
| 162 | } |
Howard Hinnant | ffb308e | 2010-08-22 00:03:27 +0000 | [diff] [blame] | 163 | #endif // _LIBCPP_NO_EXCEPTIONS |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 164 | return p; |
| 165 | } |
| 166 | |
Shoaib Meenai | 2d71db4 | 2016-11-16 22:18:10 +0000 | [diff] [blame] | 167 | _LIBCPP_WEAK |
Eric Fiselier | 162922f | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 168 | void* |
| 169 | operator new[](size_t size, std::align_val_t alignment, const std::nothrow_t&) _NOEXCEPT |
| 170 | { |
| 171 | void* p = 0; |
| 172 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 173 | try |
| 174 | { |
| 175 | #endif // _LIBCPP_NO_EXCEPTIONS |
| 176 | p = ::operator new[](size, alignment); |
| 177 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 178 | } |
| 179 | catch (...) |
| 180 | { |
| 181 | } |
| 182 | #endif // _LIBCPP_NO_EXCEPTIONS |
| 183 | return p; |
| 184 | } |
| 185 | |
Shoaib Meenai | 2d71db4 | 2016-11-16 22:18:10 +0000 | [diff] [blame] | 186 | _LIBCPP_WEAK |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 187 | void |
Howard Hinnant | 1bc52cf | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 188 | operator delete(void* ptr) _NOEXCEPT |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 189 | { |
| 190 | if (ptr) |
| 191 | ::free(ptr); |
| 192 | } |
| 193 | |
Shoaib Meenai | 2d71db4 | 2016-11-16 22:18:10 +0000 | [diff] [blame] | 194 | _LIBCPP_WEAK |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 195 | void |
Eric Fiselier | 162922f | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 196 | operator delete(void* ptr, std::align_val_t) _NOEXCEPT |
| 197 | { |
| 198 | if (ptr) |
| 199 | ::free(ptr); |
| 200 | } |
| 201 | |
Shoaib Meenai | 2d71db4 | 2016-11-16 22:18:10 +0000 | [diff] [blame] | 202 | _LIBCPP_WEAK |
Eric Fiselier | 162922f | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 203 | void |
Howard Hinnant | 1bc52cf | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 204 | operator delete(void* ptr, const std::nothrow_t&) _NOEXCEPT |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 205 | { |
| 206 | ::operator delete(ptr); |
| 207 | } |
| 208 | |
Shoaib Meenai | 2d71db4 | 2016-11-16 22:18:10 +0000 | [diff] [blame] | 209 | _LIBCPP_WEAK |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 210 | void |
Eric Fiselier | 162922f | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 211 | operator delete(void* ptr, std::align_val_t alignment, const std::nothrow_t&) _NOEXCEPT |
| 212 | { |
| 213 | ::operator delete(ptr, alignment); |
| 214 | } |
| 215 | |
Shoaib Meenai | 2d71db4 | 2016-11-16 22:18:10 +0000 | [diff] [blame] | 216 | _LIBCPP_WEAK |
Eric Fiselier | 162922f | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 217 | void |
Larisse Voufo | a744a7e | 2015-02-20 06:13:05 +0000 | [diff] [blame] | 218 | operator delete(void* ptr, size_t) _NOEXCEPT |
Larisse Voufo | 574190d | 2015-02-15 05:18:55 +0000 | [diff] [blame] | 219 | { |
| 220 | ::operator delete(ptr); |
| 221 | } |
| 222 | |
Shoaib Meenai | 2d71db4 | 2016-11-16 22:18:10 +0000 | [diff] [blame] | 223 | _LIBCPP_WEAK |
Larisse Voufo | 574190d | 2015-02-15 05:18:55 +0000 | [diff] [blame] | 224 | void |
Eric Fiselier | 162922f | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 225 | operator delete(void* ptr, size_t, std::align_val_t alignment) _NOEXCEPT |
| 226 | { |
| 227 | ::operator delete(ptr, alignment); |
| 228 | } |
| 229 | |
Shoaib Meenai | 2d71db4 | 2016-11-16 22:18:10 +0000 | [diff] [blame] | 230 | _LIBCPP_WEAK |
Eric Fiselier | 162922f | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 231 | void |
Howard Hinnant | 1bc52cf | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 232 | operator delete[] (void* ptr) _NOEXCEPT |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 233 | { |
Larisse Voufo | 574190d | 2015-02-15 05:18:55 +0000 | [diff] [blame] | 234 | ::operator delete(ptr); |
| 235 | } |
| 236 | |
Shoaib Meenai | 2d71db4 | 2016-11-16 22:18:10 +0000 | [diff] [blame] | 237 | _LIBCPP_WEAK |
Larisse Voufo | 574190d | 2015-02-15 05:18:55 +0000 | [diff] [blame] | 238 | void |
Eric Fiselier | 162922f | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 239 | operator delete[] (void* ptr, std::align_val_t alignment) _NOEXCEPT |
| 240 | { |
| 241 | ::operator delete(ptr, alignment); |
| 242 | } |
| 243 | |
Shoaib Meenai | 2d71db4 | 2016-11-16 22:18:10 +0000 | [diff] [blame] | 244 | _LIBCPP_WEAK |
Eric Fiselier | 162922f | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 245 | void |
Howard Hinnant | 1bc52cf | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 246 | operator delete[] (void* ptr, const std::nothrow_t&) _NOEXCEPT |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 247 | { |
| 248 | ::operator delete[](ptr); |
| 249 | } |
| 250 | |
Shoaib Meenai | 2d71db4 | 2016-11-16 22:18:10 +0000 | [diff] [blame] | 251 | _LIBCPP_WEAK |
Larisse Voufo | 574190d | 2015-02-15 05:18:55 +0000 | [diff] [blame] | 252 | void |
Eric Fiselier | 162922f | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 253 | operator delete[] (void* ptr, std::align_val_t alignment, const std::nothrow_t&) _NOEXCEPT |
| 254 | { |
| 255 | ::operator delete[](ptr, alignment); |
| 256 | } |
| 257 | |
Shoaib Meenai | 2d71db4 | 2016-11-16 22:18:10 +0000 | [diff] [blame] | 258 | _LIBCPP_WEAK |
Eric Fiselier | 162922f | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 259 | void |
Larisse Voufo | a744a7e | 2015-02-20 06:13:05 +0000 | [diff] [blame] | 260 | operator delete[] (void* ptr, size_t) _NOEXCEPT |
Larisse Voufo | 574190d | 2015-02-15 05:18:55 +0000 | [diff] [blame] | 261 | { |
| 262 | ::operator delete[](ptr); |
| 263 | } |
| 264 | |
Shoaib Meenai | 2d71db4 | 2016-11-16 22:18:10 +0000 | [diff] [blame] | 265 | _LIBCPP_WEAK |
Eric Fiselier | 162922f | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 266 | void |
| 267 | operator delete[] (void* ptr, size_t, std::align_val_t alignment) _NOEXCEPT |
| 268 | { |
| 269 | ::operator delete[](ptr, alignment); |
| 270 | } |
| 271 | |
Peter Collingbourne | dc00995 | 2013-10-06 22:13:16 +0000 | [diff] [blame] | 272 | #endif // !__GLIBCXX__ |
| 273 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 274 | namespace std |
| 275 | { |
| 276 | |
Peter Collingbourne | dc00995 | 2013-10-06 22:13:16 +0000 | [diff] [blame] | 277 | #ifndef __GLIBCXX__ |
Nick Kledzik | 09163cc | 2010-05-18 22:17:13 +0000 | [diff] [blame] | 278 | const nothrow_t nothrow = {}; |
Peter Collingbourne | dc00995 | 2013-10-06 22:13:16 +0000 | [diff] [blame] | 279 | #endif |
Nick Kledzik | 09163cc | 2010-05-18 22:17:13 +0000 | [diff] [blame] | 280 | |
Howard Hinnant | 4ad4eee | 2012-02-02 20:48:35 +0000 | [diff] [blame] | 281 | #ifndef _LIBCPPABI_VERSION |
| 282 | |
Peter Collingbourne | dc00995 | 2013-10-06 22:13:16 +0000 | [diff] [blame] | 283 | #ifndef __GLIBCXX__ |
| 284 | |
Nick Kledzik | 09163cc | 2010-05-18 22:17:13 +0000 | [diff] [blame] | 285 | new_handler |
Howard Hinnant | 1bc52cf | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 286 | set_new_handler(new_handler handler) _NOEXCEPT |
Nick Kledzik | 09163cc | 2010-05-18 22:17:13 +0000 | [diff] [blame] | 287 | { |
Howard Hinnant | e65e8e3 | 2010-12-02 16:45:21 +0000 | [diff] [blame] | 288 | return __sync_lock_test_and_set(&__new_handler, handler); |
| 289 | } |
| 290 | |
| 291 | new_handler |
Howard Hinnant | 1bc52cf | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 292 | get_new_handler() _NOEXCEPT |
Howard Hinnant | e65e8e3 | 2010-12-02 16:45:21 +0000 | [diff] [blame] | 293 | { |
Joerg Sonnenberger | c7655a2 | 2014-01-04 17:43:00 +0000 | [diff] [blame] | 294 | return __sync_fetch_and_add(&__new_handler, nullptr); |
Nick Kledzik | 09163cc | 2010-05-18 22:17:13 +0000 | [diff] [blame] | 295 | } |
| 296 | |
Peter Collingbourne | dc00995 | 2013-10-06 22:13:16 +0000 | [diff] [blame] | 297 | #endif // !__GLIBCXX__ |
| 298 | |
David Chisnall | 3954f44 | 2012-02-29 12:59:17 +0000 | [diff] [blame] | 299 | #ifndef LIBCXXRT |
| 300 | |
Howard Hinnant | 1bc52cf | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 301 | bad_alloc::bad_alloc() _NOEXCEPT |
Howard Hinnant | ffb308e | 2010-08-22 00:03:27 +0000 | [diff] [blame] | 302 | { |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 303 | } |
| 304 | |
Peter Collingbourne | dc00995 | 2013-10-06 22:13:16 +0000 | [diff] [blame] | 305 | #ifndef __GLIBCXX__ |
| 306 | |
Howard Hinnant | 1bc52cf | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 307 | bad_alloc::~bad_alloc() _NOEXCEPT |
Howard Hinnant | ffb308e | 2010-08-22 00:03:27 +0000 | [diff] [blame] | 308 | { |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 309 | } |
| 310 | |
Howard Hinnant | ffb308e | 2010-08-22 00:03:27 +0000 | [diff] [blame] | 311 | const char* |
Howard Hinnant | 1bc52cf | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 312 | bad_alloc::what() const _NOEXCEPT |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 313 | { |
| 314 | return "std::bad_alloc"; |
| 315 | } |
| 316 | |
Peter Collingbourne | dc00995 | 2013-10-06 22:13:16 +0000 | [diff] [blame] | 317 | #endif // !__GLIBCXX__ |
| 318 | |
Howard Hinnant | 1bc52cf | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 319 | bad_array_new_length::bad_array_new_length() _NOEXCEPT |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 320 | { |
| 321 | } |
| 322 | |
Eric Fiselier | 740a49d | 2016-11-18 22:25:41 +0000 | [diff] [blame] | 323 | #ifndef __GLIBCXX__ |
| 324 | |
Howard Hinnant | 1bc52cf | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 325 | bad_array_new_length::~bad_array_new_length() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 326 | { |
| 327 | } |
| 328 | |
Eric Fiselier | 11ec441 | 2014-11-01 00:11:25 +0000 | [diff] [blame] | 329 | const char* |
| 330 | bad_array_new_length::what() const _NOEXCEPT |
| 331 | { |
| 332 | return "bad_array_new_length"; |
| 333 | } |
| 334 | |
Eric Fiselier | 740a49d | 2016-11-18 22:25:41 +0000 | [diff] [blame] | 335 | #endif // !__GLIBCXX__ |
| 336 | |
Eric Fiselier | 7cca7da | 2014-10-29 23:14:53 +0000 | [diff] [blame] | 337 | #endif //LIBCXXRT |
| 338 | |
Eric Fiselier | 740a49d | 2016-11-18 22:25:41 +0000 | [diff] [blame] | 339 | bad_array_length::bad_array_length() _NOEXCEPT |
| 340 | { |
| 341 | } |
| 342 | |
| 343 | #ifndef __GLIBCXX__ |
| 344 | |
| 345 | bad_array_length::~bad_array_length() _NOEXCEPT |
| 346 | { |
| 347 | } |
| 348 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 349 | const char* |
Marshall Clow | 3bf7713 | 2013-09-11 01:38:42 +0000 | [diff] [blame] | 350 | bad_array_length::what() const _NOEXCEPT |
| 351 | { |
| 352 | return "bad_array_length"; |
| 353 | } |
| 354 | |
Eric Fiselier | 740a49d | 2016-11-18 22:25:41 +0000 | [diff] [blame] | 355 | #endif // !__GLIBCXX__ |
Marshall Clow | 3bf7713 | 2013-09-11 01:38:42 +0000 | [diff] [blame] | 356 | |
Marshall Clow | 3bf7713 | 2013-09-11 01:38:42 +0000 | [diff] [blame] | 357 | #endif // _LIBCPPABI_VERSION |
Howard Hinnant | 4ad4eee | 2012-02-02 20:48:35 +0000 | [diff] [blame] | 358 | |
Peter Collingbourne | 22dc63b | 2013-10-06 22:13:19 +0000 | [diff] [blame] | 359 | #ifndef LIBSTDCXX |
| 360 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 361 | void |
| 362 | __throw_bad_alloc() |
| 363 | { |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 364 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 365 | throw bad_alloc(); |
Marshall Clow | 8fea161 | 2016-08-25 15:09:01 +0000 | [diff] [blame] | 366 | #else |
| 367 | _VSTD::abort(); |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 368 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 369 | } |
| 370 | |
Peter Collingbourne | 22dc63b | 2013-10-06 22:13:19 +0000 | [diff] [blame] | 371 | #endif // !LIBSTDCXX |
| 372 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 373 | } // std |