aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Chisnall <dchisnall@pathscale.com>2014-05-09 01:35:33 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2014-05-09 01:35:33 +0000
commit364082c2469aae2a932463a7fc591339083817cd (patch)
treeb27c72a8c0f2f89011c2293b6d1bf5e6fa20f8e4
parent101709a2940cbd9e1e42808e68ff9f8b417801a8 (diff)
parent5d697c8a703aa509aa40ae9cd886d74db1838c91 (diff)
downloadlibcxxrt-364082c2469aae2a932463a7fc591339083817cd.tar.gz
am 5d697c8a: Ensure that the no-throw variants of new and new[] have the same behaviour as the throw variants in case of overrides.
* commit '5d697c8a703aa509aa40ae9cd886d74db1838c91': Ensure that the no-throw variants of new and new[] have the same behaviour as the throw variants in case of overrides.
-rw-r--r--src/memory.cc47
1 files changed, 19 insertions, 28 deletions
diff --git a/src/memory.cc b/src/memory.cc
index cc879e0..c86fc85 100644
--- a/src/memory.cc
+++ b/src/memory.cc
@@ -99,35 +99,13 @@ void* operator new(size_t size)
__attribute__((weak))
void* operator new(size_t size, const std::nothrow_t &) throw()
{
- if (0 == size)
- {
- size = 1;
- }
- void *mem = malloc(size);
- while (0 == mem)
- {
- new_handler h = std::get_new_handler();
- if (0 != h)
- {
- try
- {
- h();
- }
- catch (...)
- {
- // nothrow operator new should return NULL in case of
- // std::bad_alloc exception in new handler
- return NULL;
- }
- }
- else
- {
- return NULL;
- }
- mem = malloc(size);
+ try {
+ return :: operator new(size);
+ } catch (...) {
+ // nothrow operator new should return NULL in case of
+ // std::bad_alloc exception in new handler
+ return NULL;
}
-
- return mem;
}
@@ -146,6 +124,19 @@ void * operator new[](size_t size)
__attribute__((weak))
+void * operator new[](size_t size, const std::nothrow_t &) throw()
+{
+ try {
+ return ::operator new[](size);
+ } catch (...) {
+ // nothrow operator new should return NULL in case of
+ // std::bad_alloc exception in new handler
+ return NULL;
+ }
+}
+
+
+__attribute__((weak))
void operator delete[](void * ptr) throw()
{
::operator delete(ptr);