1
//===------------------------ cxa_new_delete.cpp --------------------------===//
3
// The LLVM Compiler Infrastructure
5
// This file is dual licensed under the MIT and the University of Illinois Open
6
// Source Licenses. See LICENSE.TXT for details.
9
// This file implements the new and delete operators.
10
//===----------------------------------------------------------------------===//
18
* Executes a loop: Within the loop, the function first attempts to allocate
19
the requested storage. Whether the attempt involves a call to the Standard C
20
library function malloc is unspecified.
22
* Returns a pointer to the allocated storage if the attempt is successful.
23
Otherwise, if the current new_handler (18.6.2.5) is a null pointer value,
26
* Otherwise, the function calls the current new_handler function (18.6.2.3).
27
If the called function returns, the loop repeats.
29
* The loop terminates when an attempt to allocate the requested storage is
30
successful or when a called new_handler function does not return.
32
__attribute__((__weak__, __visibility__("default")))
34
operator new(std::size_t size)
35
#if !__has_feature(cxx_noexcept)
42
while ((p = std::malloc(size)) == 0)
44
std::new_handler nh = std::get_new_handler();
48
throw std::bad_alloc();
54
Note: The relationships among these operators is both carefully considered
55
and standard in C++11. Please do not change them without fully understanding
56
the consequences of doing so. Reference:
57
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2158.html
62
Calls operator new(size). If the call returns normally, returns the result of
63
that call. Otherwise, returns a null pointer.
65
__attribute__((__weak__, __visibility__("default")))
67
operator new(size_t size, const std::nothrow_t&)
68
#if __has_feature(cxx_noexcept)
77
p = ::operator new(size);
88
Returns operator new(size).
90
__attribute__((__weak__, __visibility__("default")))
92
operator new[](size_t size)
93
#if !__has_feature(cxx_noexcept)
97
return ::operator new(size);
103
Calls operator new[](size). If the call returns normally, returns the result
104
of that call. Otherwise, returns a null pointer.
106
__attribute__((__weak__, __visibility__("default")))
108
operator new[](size_t size, const std::nothrow_t&)
109
#if __has_feature(cxx_noexcept)
118
p = ::operator new[](size);
129
If ptr is null, does nothing. Otherwise, reclaims the storage allocated by the
130
earlier call to operator new.
132
__attribute__((__weak__, __visibility__("default")))
134
operator delete(void* ptr)
135
#if __has_feature(cxx_noexcept)
148
calls operator delete(ptr)
150
__attribute__((__weak__, __visibility__("default")))
152
operator delete(void* ptr, const std::nothrow_t&)
153
#if __has_feature(cxx_noexcept)
159
::operator delete(ptr);
165
Calls operator delete(ptr)
167
__attribute__((__weak__, __visibility__("default")))
169
operator delete[] (void* ptr)
170
#if __has_feature(cxx_noexcept)
176
::operator delete(ptr);
182
calls operator delete[](ptr)
184
__attribute__((__weak__, __visibility__("default")))
186
operator delete[] (void* ptr, const std::nothrow_t&)
187
#if __has_feature(cxx_noexcept)
193
::operator delete[](ptr);
201
bad_alloc::bad_alloc() _NOEXCEPT
205
bad_alloc::~bad_alloc() _NOEXCEPT
210
bad_alloc::what() const _NOEXCEPT
212
return "std::bad_alloc";
215
// bad_array_new_length
217
bad_array_new_length::bad_array_new_length() _NOEXCEPT
221
bad_array_new_length::~bad_array_new_length() _NOEXCEPT
226
bad_array_new_length::what() const _NOEXCEPT
228
return "bad_array_new_length";
232
// We don't build the new.cpp from libcxx, so we need to define this.
236
#ifndef _LIBCPP_NO_EXCEPTIONS