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