Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===----------------------------- new ------------------------------------===// |
| 3 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 4 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 6 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 7 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 8 | // |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | |
| 11 | #ifndef _LIBCPP_NEW |
| 12 | #define _LIBCPP_NEW |
| 13 | |
| 14 | /* |
| 15 | new synopsis |
| 16 | |
| 17 | namespace std |
| 18 | { |
| 19 | |
| 20 | class bad_alloc |
| 21 | : public exception |
| 22 | { |
| 23 | public: |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 24 | bad_alloc() noexcept; |
| 25 | bad_alloc(const bad_alloc&) noexcept; |
| 26 | bad_alloc& operator=(const bad_alloc&) noexcept; |
| 27 | virtual const char* what() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 28 | }; |
| 29 | |
Eric Fiselier | 9acbffa | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 30 | class bad_array_length : public bad_alloc // FIXME: Not part of C++ |
Marshall Clow | 7f9f52e | 2013-09-11 01:38:42 +0000 | [diff] [blame] | 31 | { |
| 32 | public: |
| 33 | bad_array_length() noexcept; |
| 34 | }; |
| 35 | |
Eric Fiselier | 9acbffa | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 36 | class bad_array_new_length : public bad_alloc // C++14 |
Marshall Clow | 7f9f52e | 2013-09-11 01:38:42 +0000 | [diff] [blame] | 37 | { |
| 38 | public: |
| 39 | bad_array_new_length() noexcept; |
| 40 | }; |
| 41 | |
Eric Fiselier | 9acbffa | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 42 | enum class align_val_t : size_t {}; // C++17 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 43 | struct nothrow_t {}; |
| 44 | extern const nothrow_t nothrow; |
| 45 | typedef void (*new_handler)(); |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 46 | new_handler set_new_handler(new_handler new_p) noexcept; |
| 47 | new_handler get_new_handler() noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 48 | |
| 49 | } // std |
| 50 | |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 51 | void* operator new(std::size_t size); // replaceable |
Eric Fiselier | 9acbffa | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 52 | void* operator new(std::size_t size, std::align_val_t alignment); // replaceable, C++17 |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 53 | void* operator new(std::size_t size, const std::nothrow_t&) noexcept; // replaceable |
Eric Fiselier | 9acbffa | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 54 | void* operator new(std::size_t size, std::align_val_t alignment, |
| 55 | const std::nothrow_t&) noexcept; // replaceable, C++17 |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 56 | void operator delete(void* ptr) noexcept; // replaceable |
Larisse Voufo | 19efe01 | 2015-02-15 05:18:55 +0000 | [diff] [blame] | 57 | void operator delete(void* ptr, std::size_t size) noexcept; // replaceable, C++14 |
Eric Fiselier | 9acbffa | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 58 | void operator delete(void* ptr, std::align_val_t alignment) noexcept; // replaceable, C++17 |
| 59 | void operator delete(void* ptr, std::size_t size, |
| 60 | std::align_val_t alignment) noexcept; // replaceable, C++17 |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 61 | void operator delete(void* ptr, const std::nothrow_t&) noexcept; // replaceable |
Eric Fiselier | 9acbffa | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 62 | void operator delete(void* ptr, std:align_val_t alignment, |
| 63 | const std::nothrow_t&) noexcept; // replaceable, C++17 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 64 | |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 65 | void* operator new[](std::size_t size); // replaceable |
Eric Fiselier | 9acbffa | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 66 | void* operator new[](std::size_t size, |
| 67 | std::align_val_t alignment) noexcept; // replaceable, C++17 |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 68 | void* operator new[](std::size_t size, const std::nothrow_t&) noexcept; // replaceable |
Eric Fiselier | 9acbffa | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 69 | void* operator new[](std::size_t size, std::align_val_t alignment, |
| 70 | const std::nothrow_t&) noexcept; // replaceable, C++17 |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 71 | void operator delete[](void* ptr) noexcept; // replaceable |
Larisse Voufo | 19efe01 | 2015-02-15 05:18:55 +0000 | [diff] [blame] | 72 | void operator delete[](void* ptr, std::size_t size) noexcept; // replaceable, C++14 |
Eric Fiselier | 9acbffa | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 73 | void operator delete[](void* ptr, |
| 74 | std::align_val_t alignment) noexcept; // replaceable, C++17 |
| 75 | void operator delete[](void* ptr, std::size_t size, |
| 76 | std::align_val_t alignment) noexcept; // replaceable, C++17 |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 77 | void operator delete[](void* ptr, const std::nothrow_t&) noexcept; // replaceable |
Eric Fiselier | 9acbffa | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 78 | void operator delete[](void* ptr, std::align_val_t alignment, |
| 79 | const std::nothrow_t&) noexcept; // replaceable, C++17 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 80 | |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 81 | void* operator new (std::size_t size, void* ptr) noexcept; |
| 82 | void* operator new[](std::size_t size, void* ptr) noexcept; |
| 83 | void operator delete (void* ptr, void*) noexcept; |
| 84 | void operator delete[](void* ptr, void*) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 85 | |
| 86 | */ |
| 87 | |
| 88 | #include <__config> |
| 89 | #include <exception> |
| 90 | #include <cstddef> |
Eric Fiselier | dbf60fa | 2016-09-06 21:25:27 +0000 | [diff] [blame] | 91 | #ifdef _LIBCPP_NO_EXCEPTIONS |
| 92 | #include <cstdlib> |
| 93 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 94 | |
Shoaib Meenai | 18dba06 | 2017-10-09 19:25:17 +0000 | [diff] [blame^] | 95 | #if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME) |
Eric Fiselier | 1edf316 | 2017-02-10 08:57:35 +0000 | [diff] [blame] | 96 | #include <new.h> |
| 97 | #endif |
| 98 | |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 99 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 100 | #pragma GCC system_header |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 101 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 102 | |
Eric Fiselier | 9acbffa | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 103 | #if !(defined(_LIBCPP_BUILDING_NEW) || _LIBCPP_STD_VER >= 14 || \ |
| 104 | (defined(__cpp_sized_deallocation) && __cpp_sized_deallocation >= 201309)) |
| 105 | # define _LIBCPP_HAS_NO_SIZED_DEALLOCATION |
| 106 | #endif |
| 107 | |
Eric Fiselier | d54d974 | 2017-01-20 01:47:26 +0000 | [diff] [blame] | 108 | #if !defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION) && \ |
| 109 | (!(defined(_LIBCPP_BUILDING_NEW) || _LIBCPP_STD_VER > 14 || \ |
| 110 | (defined(__cpp_aligned_new) && __cpp_aligned_new >= 201606))) |
Eric Fiselier | 9acbffa | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 111 | # define _LIBCPP_HAS_NO_ALIGNED_ALLOCATION |
| 112 | #endif |
| 113 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 114 | namespace std // purposefully not using versioning namespace |
| 115 | { |
| 116 | |
Shoaib Meenai | 18dba06 | 2017-10-09 19:25:17 +0000 | [diff] [blame^] | 117 | #if !defined(_LIBCPP_ABI_MICROSOFT) || defined(_LIBCPP_NO_VCRUNTIME) |
Eric Fiselier | 1edf316 | 2017-02-10 08:57:35 +0000 | [diff] [blame] | 118 | struct _LIBCPP_TYPE_VIS nothrow_t {}; |
| 119 | extern _LIBCPP_FUNC_VIS const nothrow_t nothrow; |
| 120 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 121 | class _LIBCPP_EXCEPTION_ABI bad_alloc |
| 122 | : public exception |
| 123 | { |
| 124 | public: |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 125 | bad_alloc() _NOEXCEPT; |
| 126 | virtual ~bad_alloc() _NOEXCEPT; |
| 127 | virtual const char* what() const _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 128 | }; |
| 129 | |
| 130 | class _LIBCPP_EXCEPTION_ABI bad_array_new_length |
| 131 | : public bad_alloc |
| 132 | { |
| 133 | public: |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 134 | bad_array_new_length() _NOEXCEPT; |
| 135 | virtual ~bad_array_new_length() _NOEXCEPT; |
| 136 | virtual const char* what() const _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 137 | }; |
| 138 | |
Eric Fiselier | 1edf316 | 2017-02-10 08:57:35 +0000 | [diff] [blame] | 139 | typedef void (*new_handler)(); |
| 140 | _LIBCPP_FUNC_VIS new_handler set_new_handler(new_handler) _NOEXCEPT; |
| 141 | _LIBCPP_FUNC_VIS new_handler get_new_handler() _NOEXCEPT; |
| 142 | |
Shoaib Meenai | 18dba06 | 2017-10-09 19:25:17 +0000 | [diff] [blame^] | 143 | #endif // !_LIBCPP_ABI_MICROSOFT || _LIBCPP_NO_VCRUNTIME |
Eric Fiselier | 1edf316 | 2017-02-10 08:57:35 +0000 | [diff] [blame] | 144 | |
Marshall Clow | 14c09a2 | 2016-08-25 15:09:01 +0000 | [diff] [blame] | 145 | _LIBCPP_NORETURN _LIBCPP_FUNC_VIS void __throw_bad_alloc(); // not in C++ spec |
| 146 | |
Eric Fiselier | 1edf316 | 2017-02-10 08:57:35 +0000 | [diff] [blame] | 147 | #if defined(_LIBCPP_BUILDING_LIBRARY) || (_LIBCPP_STD_VER > 11) |
Howard Hinnant | 29250b7 | 2013-11-07 17:15:51 +0000 | [diff] [blame] | 148 | |
Mehdi Amini | 907c119 | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 149 | class _LIBCPP_EXCEPTION_ABI _LIBCPP_AVAILABILITY_BAD_ARRAY_LENGTH |
| 150 | bad_array_length : public bad_alloc { |
Marshall Clow | 7f9f52e | 2013-09-11 01:38:42 +0000 | [diff] [blame] | 151 | public: |
| 152 | bad_array_length() _NOEXCEPT; |
| 153 | virtual ~bad_array_length() _NOEXCEPT; |
| 154 | virtual const char* what() const _NOEXCEPT; |
| 155 | }; |
Howard Hinnant | 29250b7 | 2013-11-07 17:15:51 +0000 | [diff] [blame] | 156 | |
| 157 | #define _LIBCPP_BAD_ARRAY_LENGTH_DEFINED |
| 158 | |
| 159 | #endif // defined(_LIBCPP_BUILDING_NEW) || (_LIBCPP_STD_VER > 11) |
Marshall Clow | 7f9f52e | 2013-09-11 01:38:42 +0000 | [diff] [blame] | 160 | |
Eric Fiselier | 85e34e4 | 2017-01-21 14:42:44 +0000 | [diff] [blame] | 161 | #if !defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION) || _LIBCPP_STD_VER > 14 |
Eric Fiselier | 9acbffa | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 162 | #ifndef _LIBCPP_CXX03_LANG |
| 163 | enum class _LIBCPP_ENUM_VIS align_val_t : size_t { }; |
| 164 | #else |
| 165 | enum align_val_t { __zero = 0, __max = (size_t)-1 }; |
| 166 | #endif |
| 167 | #endif |
| 168 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 169 | } // std |
| 170 | |
Eric Fiselier | b45121d | 2017-01-02 23:27:42 +0000 | [diff] [blame] | 171 | #if defined(_LIBCPP_CXX03_LANG) |
Eric Fiselier | 9acbffa | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 172 | #define _THROW_BAD_ALLOC throw(std::bad_alloc) |
| 173 | #else |
| 174 | #define _THROW_BAD_ALLOC |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 175 | #endif |
Eric Fiselier | 9acbffa | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 176 | |
Shoaib Meenai | 18dba06 | 2017-10-09 19:25:17 +0000 | [diff] [blame^] | 177 | #if !defined(_LIBCPP_ABI_MICROSOFT) || defined(_LIBCPP_NO_VCRUNTIME) |
Eric Fiselier | 1edf316 | 2017-02-10 08:57:35 +0000 | [diff] [blame] | 178 | |
Shoaib Meenai | e6479bc | 2016-11-16 22:18:10 +0000 | [diff] [blame] | 179 | _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz) _THROW_BAD_ALLOC; |
| 180 | _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, const std::nothrow_t&) _NOEXCEPT _NOALIAS; |
| 181 | _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p) _NOEXCEPT; |
| 182 | _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, const std::nothrow_t&) _NOEXCEPT; |
Eric Fiselier | 9acbffa | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 183 | #ifndef _LIBCPP_HAS_NO_SIZED_DEALLOCATION |
Mehdi Amini | 907c119 | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 184 | _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE void operator delete(void* __p, std::size_t __sz) _NOEXCEPT; |
Larisse Voufo | 74f95a0 | 2015-02-20 06:13:05 +0000 | [diff] [blame] | 185 | #endif |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 186 | |
Shoaib Meenai | e6479bc | 2016-11-16 22:18:10 +0000 | [diff] [blame] | 187 | _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz) _THROW_BAD_ALLOC; |
| 188 | _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, const std::nothrow_t&) _NOEXCEPT _NOALIAS; |
| 189 | _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p) _NOEXCEPT; |
| 190 | _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, const std::nothrow_t&) _NOEXCEPT; |
Shoaib Meenai | f66194b | 2016-11-18 04:31:09 +0000 | [diff] [blame] | 191 | #ifndef _LIBCPP_HAS_NO_SIZED_DEALLOCATION |
Mehdi Amini | 907c119 | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 192 | _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE void operator delete[](void* __p, std::size_t __sz) _NOEXCEPT; |
Larisse Voufo | 74f95a0 | 2015-02-20 06:13:05 +0000 | [diff] [blame] | 193 | #endif |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 194 | |
Eric Fiselier | 9acbffa | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 195 | #ifndef _LIBCPP_HAS_NO_ALIGNED_ALLOCATION |
Akira Hatanaka | c5247b4 | 2017-06-30 18:50:23 +0000 | [diff] [blame] | 196 | _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, std::align_val_t) _THROW_BAD_ALLOC; |
| 197 | _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, std::align_val_t, const std::nothrow_t&) _NOEXCEPT _NOALIAS; |
| 198 | _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::align_val_t) _NOEXCEPT; |
| 199 | _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::align_val_t, const std::nothrow_t&) _NOEXCEPT; |
Eric Fiselier | 9acbffa | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 200 | #ifndef _LIBCPP_HAS_NO_SIZED_DEALLOCATION |
Akira Hatanaka | c5247b4 | 2017-06-30 18:50:23 +0000 | [diff] [blame] | 201 | _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE void operator delete(void* __p, std::size_t __sz, std::align_val_t) _NOEXCEPT; |
Eric Fiselier | 9acbffa | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 202 | #endif |
| 203 | |
Akira Hatanaka | c5247b4 | 2017-06-30 18:50:23 +0000 | [diff] [blame] | 204 | _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, std::align_val_t) _THROW_BAD_ALLOC; |
| 205 | _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, std::align_val_t, const std::nothrow_t&) _NOEXCEPT _NOALIAS; |
| 206 | _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::align_val_t) _NOEXCEPT; |
| 207 | _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::align_val_t, const std::nothrow_t&) _NOEXCEPT; |
Eric Fiselier | 9acbffa | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 208 | #ifndef _LIBCPP_HAS_NO_SIZED_DEALLOCATION |
Akira Hatanaka | c5247b4 | 2017-06-30 18:50:23 +0000 | [diff] [blame] | 209 | _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE void operator delete[](void* __p, std::size_t __sz, std::align_val_t) _NOEXCEPT; |
Eric Fiselier | 9acbffa | 2016-10-14 06:46:30 +0000 | [diff] [blame] | 210 | #endif |
| 211 | #endif |
| 212 | |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 213 | inline _LIBCPP_INLINE_VISIBILITY void* operator new (std::size_t, void* __p) _NOEXCEPT {return __p;} |
| 214 | inline _LIBCPP_INLINE_VISIBILITY void* operator new[](std::size_t, void* __p) _NOEXCEPT {return __p;} |
| 215 | inline _LIBCPP_INLINE_VISIBILITY void operator delete (void*, void*) _NOEXCEPT {} |
| 216 | inline _LIBCPP_INLINE_VISIBILITY void operator delete[](void*, void*) _NOEXCEPT {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 217 | |
Shoaib Meenai | 18dba06 | 2017-10-09 19:25:17 +0000 | [diff] [blame^] | 218 | #endif // !_LIBCPP_ABI_MICROSOFT || _LIBCPP_NO_VCRUNTIME |
Eric Fiselier | 1edf316 | 2017-02-10 08:57:35 +0000 | [diff] [blame] | 219 | |
Richard Smith | 73c1fce | 2014-06-04 19:54:15 +0000 | [diff] [blame] | 220 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 221 | |
| 222 | inline _LIBCPP_INLINE_VISIBILITY void *__allocate(size_t __size) { |
| 223 | #ifdef _LIBCPP_HAS_NO_BUILTIN_OPERATOR_NEW_DELETE |
| 224 | return ::operator new(__size); |
| 225 | #else |
| 226 | return __builtin_operator_new(__size); |
| 227 | #endif |
| 228 | } |
| 229 | |
Eric Fiselier | 32b19c3 | 2017-01-07 03:01:24 +0000 | [diff] [blame] | 230 | inline _LIBCPP_INLINE_VISIBILITY void __libcpp_deallocate(void *__ptr) { |
Richard Smith | 73c1fce | 2014-06-04 19:54:15 +0000 | [diff] [blame] | 231 | #ifdef _LIBCPP_HAS_NO_BUILTIN_OPERATOR_NEW_DELETE |
| 232 | ::operator delete(__ptr); |
| 233 | #else |
| 234 | __builtin_operator_delete(__ptr); |
| 235 | #endif |
| 236 | } |
| 237 | |
Marshall Clow | 14c09a2 | 2016-08-25 15:09:01 +0000 | [diff] [blame] | 238 | #ifdef _LIBCPP_BAD_ARRAY_LENGTH_DEFINED |
| 239 | _LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE |
Mehdi Amini | 907c119 | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 240 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 241 | _LIBCPP_AVAILABILITY_BAD_ARRAY_LENGTH |
| 242 | #endif |
Marshall Clow | 14c09a2 | 2016-08-25 15:09:01 +0000 | [diff] [blame] | 243 | void __throw_bad_array_length() |
| 244 | { |
| 245 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 246 | throw bad_array_length(); |
| 247 | #else |
| 248 | _VSTD::abort(); |
| 249 | #endif |
| 250 | } |
| 251 | #endif |
| 252 | |
Richard Smith | 73c1fce | 2014-06-04 19:54:15 +0000 | [diff] [blame] | 253 | _LIBCPP_END_NAMESPACE_STD |
| 254 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 255 | #endif // _LIBCPP_NEW |