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 | 86c674e | 2014-11-01 00:41:42 +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) |
Peter Collingbourne | dc00995 | 2013-10-06 22:13:16 +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; |
| 73 | while (::posix_memalign(&p, static_cast<size_t>(alignment), size) != 0) |
| 74 | { |
| 75 | // If posix_memalign fails and there is a new_handler, |
| 76 | // call it to try free up memory. |
| 77 | std::new_handler nh = std::get_new_handler(); |
| 78 | if (nh) |
| 79 | nh(); |
| 80 | else { |
| 81 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 82 | throw std::bad_alloc(); |
| 83 | #else |
| 84 | p = nullptr; // posix_memalign doesn't initialize 'p' on failure |
| 85 | break; |
| 86 | #endif |
| 87 | } |
| 88 | } |
| 89 | return p; |
| 90 | } |
| 91 | |
Shoaib Meenai | 2d71db4 | 2016-11-16 22:18:10 +0000 | [diff] [blame] | 92 | _LIBCPP_WEAK |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 93 | void* |
Howard Hinnant | 1bc52cf | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 94 | operator new(size_t size, const std::nothrow_t&) _NOEXCEPT |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 95 | { |
| 96 | void* p = 0; |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 97 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 98 | try |
| 99 | { |
Howard Hinnant | ffb308e | 2010-08-22 00:03:27 +0000 | [diff] [blame] | 100 | #endif // _LIBCPP_NO_EXCEPTIONS |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 101 | p = ::operator new(size); |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 102 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 103 | } |
| 104 | catch (...) |
| 105 | { |
| 106 | } |
Howard Hinnant | ffb308e | 2010-08-22 00:03:27 +0000 | [diff] [blame] | 107 | #endif // _LIBCPP_NO_EXCEPTIONS |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 108 | return p; |
| 109 | } |
| 110 | |
Shoaib Meenai | 2d71db4 | 2016-11-16 22:18:10 +0000 | [diff] [blame] | 111 | _LIBCPP_WEAK |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 112 | void* |
Eric Fiselier | 162922f | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 113 | operator new(size_t size, std::align_val_t alignment, const std::nothrow_t&) _NOEXCEPT |
| 114 | { |
| 115 | void* p = 0; |
| 116 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 117 | try |
| 118 | { |
| 119 | #endif // _LIBCPP_NO_EXCEPTIONS |
| 120 | p = ::operator new(size, alignment); |
| 121 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 122 | } |
| 123 | catch (...) |
| 124 | { |
| 125 | } |
| 126 | #endif // _LIBCPP_NO_EXCEPTIONS |
| 127 | return p; |
| 128 | } |
| 129 | |
Shoaib Meenai | 2d71db4 | 2016-11-16 22:18:10 +0000 | [diff] [blame] | 130 | _LIBCPP_WEAK |
Eric Fiselier | 162922f | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 131 | void* |
| 132 | operator new[](size_t size) _THROW_BAD_ALLOC |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 133 | { |
| 134 | return ::operator new(size); |
| 135 | } |
| 136 | |
Shoaib Meenai | 2d71db4 | 2016-11-16 22:18:10 +0000 | [diff] [blame] | 137 | _LIBCPP_WEAK |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 138 | void* |
Eric Fiselier | 162922f | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 139 | operator new[](size_t size, std::align_val_t alignment) _THROW_BAD_ALLOC |
| 140 | { |
| 141 | return ::operator new(size, alignment); |
| 142 | } |
| 143 | |
Shoaib Meenai | 2d71db4 | 2016-11-16 22:18:10 +0000 | [diff] [blame] | 144 | _LIBCPP_WEAK |
Eric Fiselier | 162922f | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 145 | void* |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 146 | operator new[](size_t size, const std::nothrow_t&) _NOEXCEPT |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 147 | { |
| 148 | void* p = 0; |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 149 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 150 | try |
| 151 | { |
Howard Hinnant | ffb308e | 2010-08-22 00:03:27 +0000 | [diff] [blame] | 152 | #endif // _LIBCPP_NO_EXCEPTIONS |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 153 | p = ::operator new[](size); |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 154 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 155 | } |
| 156 | catch (...) |
| 157 | { |
| 158 | } |
Howard Hinnant | ffb308e | 2010-08-22 00:03:27 +0000 | [diff] [blame] | 159 | #endif // _LIBCPP_NO_EXCEPTIONS |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 160 | return p; |
| 161 | } |
| 162 | |
Shoaib Meenai | 2d71db4 | 2016-11-16 22:18:10 +0000 | [diff] [blame] | 163 | _LIBCPP_WEAK |
Eric Fiselier | 162922f | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 164 | void* |
| 165 | operator new[](size_t size, std::align_val_t alignment, const std::nothrow_t&) _NOEXCEPT |
| 166 | { |
| 167 | void* p = 0; |
| 168 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 169 | try |
| 170 | { |
| 171 | #endif // _LIBCPP_NO_EXCEPTIONS |
| 172 | p = ::operator new[](size, alignment); |
| 173 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 174 | } |
| 175 | catch (...) |
| 176 | { |
| 177 | } |
| 178 | #endif // _LIBCPP_NO_EXCEPTIONS |
| 179 | return p; |
| 180 | } |
| 181 | |
Shoaib Meenai | 2d71db4 | 2016-11-16 22:18:10 +0000 | [diff] [blame] | 182 | _LIBCPP_WEAK |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 183 | void |
Howard Hinnant | 1bc52cf | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 184 | operator delete(void* ptr) _NOEXCEPT |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 185 | { |
| 186 | if (ptr) |
| 187 | ::free(ptr); |
| 188 | } |
| 189 | |
Shoaib Meenai | 2d71db4 | 2016-11-16 22:18:10 +0000 | [diff] [blame] | 190 | _LIBCPP_WEAK |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 191 | void |
Eric Fiselier | 162922f | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 192 | operator delete(void* ptr, std::align_val_t) _NOEXCEPT |
| 193 | { |
| 194 | if (ptr) |
| 195 | ::free(ptr); |
| 196 | } |
| 197 | |
Shoaib Meenai | 2d71db4 | 2016-11-16 22:18:10 +0000 | [diff] [blame] | 198 | _LIBCPP_WEAK |
Eric Fiselier | 162922f | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 199 | void |
Howard Hinnant | 1bc52cf | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 200 | operator delete(void* ptr, const std::nothrow_t&) _NOEXCEPT |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 201 | { |
| 202 | ::operator delete(ptr); |
| 203 | } |
| 204 | |
Shoaib Meenai | 2d71db4 | 2016-11-16 22:18:10 +0000 | [diff] [blame] | 205 | _LIBCPP_WEAK |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 206 | void |
Eric Fiselier | 162922f | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 207 | operator delete(void* ptr, std::align_val_t alignment, const std::nothrow_t&) _NOEXCEPT |
| 208 | { |
| 209 | ::operator delete(ptr, alignment); |
| 210 | } |
| 211 | |
Shoaib Meenai | 2d71db4 | 2016-11-16 22:18:10 +0000 | [diff] [blame] | 212 | _LIBCPP_WEAK |
Eric Fiselier | 162922f | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 213 | void |
Larisse Voufo | a744a7e | 2015-02-20 06:13:05 +0000 | [diff] [blame] | 214 | operator delete(void* ptr, size_t) _NOEXCEPT |
Larisse Voufo | 574190d | 2015-02-15 05:18:55 +0000 | [diff] [blame] | 215 | { |
| 216 | ::operator delete(ptr); |
| 217 | } |
| 218 | |
Shoaib Meenai | 2d71db4 | 2016-11-16 22:18:10 +0000 | [diff] [blame] | 219 | _LIBCPP_WEAK |
Larisse Voufo | 574190d | 2015-02-15 05:18:55 +0000 | [diff] [blame] | 220 | void |
Eric Fiselier | 162922f | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 221 | operator delete(void* ptr, size_t, std::align_val_t alignment) _NOEXCEPT |
| 222 | { |
| 223 | ::operator delete(ptr, alignment); |
| 224 | } |
| 225 | |
Shoaib Meenai | 2d71db4 | 2016-11-16 22:18:10 +0000 | [diff] [blame] | 226 | _LIBCPP_WEAK |
Eric Fiselier | 162922f | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 227 | void |
Howard Hinnant | 1bc52cf | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 228 | operator delete[] (void* ptr) _NOEXCEPT |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 229 | { |
Larisse Voufo | 574190d | 2015-02-15 05:18:55 +0000 | [diff] [blame] | 230 | ::operator delete(ptr); |
| 231 | } |
| 232 | |
Shoaib Meenai | 2d71db4 | 2016-11-16 22:18:10 +0000 | [diff] [blame] | 233 | _LIBCPP_WEAK |
Larisse Voufo | 574190d | 2015-02-15 05:18:55 +0000 | [diff] [blame] | 234 | void |
Eric Fiselier | 162922f | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 235 | operator delete[] (void* ptr, std::align_val_t alignment) _NOEXCEPT |
| 236 | { |
| 237 | ::operator delete(ptr, alignment); |
| 238 | } |
| 239 | |
Shoaib Meenai | 2d71db4 | 2016-11-16 22:18:10 +0000 | [diff] [blame] | 240 | _LIBCPP_WEAK |
Eric Fiselier | 162922f | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 241 | void |
Howard Hinnant | 1bc52cf | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 242 | operator delete[] (void* ptr, const std::nothrow_t&) _NOEXCEPT |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 243 | { |
| 244 | ::operator delete[](ptr); |
| 245 | } |
| 246 | |
Shoaib Meenai | 2d71db4 | 2016-11-16 22:18:10 +0000 | [diff] [blame] | 247 | _LIBCPP_WEAK |
Larisse Voufo | 574190d | 2015-02-15 05:18:55 +0000 | [diff] [blame] | 248 | void |
Eric Fiselier | 162922f | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 249 | operator delete[] (void* ptr, std::align_val_t alignment, const std::nothrow_t&) _NOEXCEPT |
| 250 | { |
| 251 | ::operator delete[](ptr, alignment); |
| 252 | } |
| 253 | |
Shoaib Meenai | 2d71db4 | 2016-11-16 22:18:10 +0000 | [diff] [blame] | 254 | _LIBCPP_WEAK |
Eric Fiselier | 162922f | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 255 | void |
Larisse Voufo | a744a7e | 2015-02-20 06:13:05 +0000 | [diff] [blame] | 256 | operator delete[] (void* ptr, size_t) _NOEXCEPT |
Larisse Voufo | 574190d | 2015-02-15 05:18:55 +0000 | [diff] [blame] | 257 | { |
| 258 | ::operator delete[](ptr); |
| 259 | } |
| 260 | |
Shoaib Meenai | 2d71db4 | 2016-11-16 22:18:10 +0000 | [diff] [blame] | 261 | _LIBCPP_WEAK |
Eric Fiselier | 162922f | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 262 | void |
| 263 | operator delete[] (void* ptr, size_t, std::align_val_t alignment) _NOEXCEPT |
| 264 | { |
| 265 | ::operator delete[](ptr, alignment); |
| 266 | } |
| 267 | |
Peter Collingbourne | dc00995 | 2013-10-06 22:13:16 +0000 | [diff] [blame] | 268 | #endif // !__GLIBCXX__ |
| 269 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 270 | namespace std |
| 271 | { |
| 272 | |
Peter Collingbourne | dc00995 | 2013-10-06 22:13:16 +0000 | [diff] [blame] | 273 | #ifndef __GLIBCXX__ |
Nick Kledzik | 09163cc | 2010-05-18 22:17:13 +0000 | [diff] [blame] | 274 | const nothrow_t nothrow = {}; |
Peter Collingbourne | dc00995 | 2013-10-06 22:13:16 +0000 | [diff] [blame] | 275 | #endif |
Nick Kledzik | 09163cc | 2010-05-18 22:17:13 +0000 | [diff] [blame] | 276 | |
Howard Hinnant | 4ad4eee | 2012-02-02 20:48:35 +0000 | [diff] [blame] | 277 | #ifndef _LIBCPPABI_VERSION |
| 278 | |
Peter Collingbourne | dc00995 | 2013-10-06 22:13:16 +0000 | [diff] [blame] | 279 | #ifndef __GLIBCXX__ |
| 280 | |
Nick Kledzik | 09163cc | 2010-05-18 22:17:13 +0000 | [diff] [blame] | 281 | new_handler |
Howard Hinnant | 1bc52cf | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 282 | set_new_handler(new_handler handler) _NOEXCEPT |
Nick Kledzik | 09163cc | 2010-05-18 22:17:13 +0000 | [diff] [blame] | 283 | { |
Howard Hinnant | e65e8e3 | 2010-12-02 16:45:21 +0000 | [diff] [blame] | 284 | return __sync_lock_test_and_set(&__new_handler, handler); |
| 285 | } |
| 286 | |
| 287 | new_handler |
Howard Hinnant | 1bc52cf | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 288 | get_new_handler() _NOEXCEPT |
Howard Hinnant | e65e8e3 | 2010-12-02 16:45:21 +0000 | [diff] [blame] | 289 | { |
Joerg Sonnenberger | c7655a2 | 2014-01-04 17:43:00 +0000 | [diff] [blame] | 290 | return __sync_fetch_and_add(&__new_handler, nullptr); |
Nick Kledzik | 09163cc | 2010-05-18 22:17:13 +0000 | [diff] [blame] | 291 | } |
| 292 | |
Peter Collingbourne | dc00995 | 2013-10-06 22:13:16 +0000 | [diff] [blame] | 293 | #endif // !__GLIBCXX__ |
| 294 | |
David Chisnall | 3954f44 | 2012-02-29 12:59:17 +0000 | [diff] [blame] | 295 | #ifndef LIBCXXRT |
| 296 | |
Howard Hinnant | 1bc52cf | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 297 | bad_alloc::bad_alloc() _NOEXCEPT |
Howard Hinnant | ffb308e | 2010-08-22 00:03:27 +0000 | [diff] [blame] | 298 | { |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 299 | } |
| 300 | |
Peter Collingbourne | dc00995 | 2013-10-06 22:13:16 +0000 | [diff] [blame] | 301 | #ifndef __GLIBCXX__ |
| 302 | |
Howard Hinnant | 1bc52cf | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 303 | bad_alloc::~bad_alloc() _NOEXCEPT |
Howard Hinnant | ffb308e | 2010-08-22 00:03:27 +0000 | [diff] [blame] | 304 | { |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 305 | } |
| 306 | |
Howard Hinnant | ffb308e | 2010-08-22 00:03:27 +0000 | [diff] [blame] | 307 | const char* |
Howard Hinnant | 1bc52cf | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 308 | bad_alloc::what() const _NOEXCEPT |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 309 | { |
| 310 | return "std::bad_alloc"; |
| 311 | } |
| 312 | |
Peter Collingbourne | dc00995 | 2013-10-06 22:13:16 +0000 | [diff] [blame] | 313 | #endif // !__GLIBCXX__ |
| 314 | |
Howard Hinnant | 1bc52cf | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 315 | bad_array_new_length::bad_array_new_length() _NOEXCEPT |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 316 | { |
| 317 | } |
| 318 | |
Howard Hinnant | 1bc52cf | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 319 | bad_array_new_length::~bad_array_new_length() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 320 | { |
| 321 | } |
| 322 | |
Eric Fiselier | 11ec441 | 2014-11-01 00:11:25 +0000 | [diff] [blame] | 323 | const char* |
| 324 | bad_array_new_length::what() const _NOEXCEPT |
| 325 | { |
| 326 | return "bad_array_new_length"; |
| 327 | } |
| 328 | |
Eric Fiselier | 7cca7da | 2014-10-29 23:14:53 +0000 | [diff] [blame] | 329 | #endif //LIBCXXRT |
| 330 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 331 | const char* |
Marshall Clow | 3bf7713 | 2013-09-11 01:38:42 +0000 | [diff] [blame] | 332 | bad_array_length::what() const _NOEXCEPT |
| 333 | { |
| 334 | return "bad_array_length"; |
| 335 | } |
| 336 | |
| 337 | bad_array_length::bad_array_length() _NOEXCEPT |
| 338 | { |
| 339 | } |
| 340 | |
| 341 | bad_array_length::~bad_array_length() _NOEXCEPT |
| 342 | { |
| 343 | } |
| 344 | |
Marshall Clow | 3bf7713 | 2013-09-11 01:38:42 +0000 | [diff] [blame] | 345 | #endif // _LIBCPPABI_VERSION |
Howard Hinnant | 4ad4eee | 2012-02-02 20:48:35 +0000 | [diff] [blame] | 346 | |
Peter Collingbourne | 22dc63b | 2013-10-06 22:13:19 +0000 | [diff] [blame] | 347 | #ifndef LIBSTDCXX |
| 348 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 349 | void |
| 350 | __throw_bad_alloc() |
| 351 | { |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 352 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 353 | throw bad_alloc(); |
Marshall Clow | 8fea161 | 2016-08-25 15:09:01 +0000 | [diff] [blame] | 354 | #else |
| 355 | _VSTD::abort(); |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 356 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 357 | } |
| 358 | |
Peter Collingbourne | 22dc63b | 2013-10-06 22:13:19 +0000 | [diff] [blame] | 359 | #endif // !LIBSTDCXX |
| 360 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 361 | } // std |