Merge "new.cpp: add sized operator delete." into main am: 3e8dd2b88c
Original change: https://android-review.googlesource.com/c/platform/bionic/+/3115108 Change-Id: Iccd1fbfb0b80dcc4babfa8b47c799f387a42b2d6 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
commit
e6c408d79f
1 changed files with 12 additions and 17 deletions
|
@ -16,13 +16,14 @@
|
||||||
|
|
||||||
#include <new>
|
#include <new>
|
||||||
|
|
||||||
#include <errno.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <async_safe/log.h>
|
#include <async_safe/log.h>
|
||||||
|
|
||||||
__attribute__((weak)) const std::nothrow_t std::nothrow = {};
|
__attribute__((weak)) const std::nothrow_t std::nothrow = {};
|
||||||
|
|
||||||
|
// We can't throw in bionic, so we go straight to the equivalent of
|
||||||
|
// std::terminate for these two instead.
|
||||||
void* operator new(std::size_t size) {
|
void* operator new(std::size_t size) {
|
||||||
void* p = malloc(size);
|
void* p = malloc(size);
|
||||||
if (p == nullptr) {
|
if (p == nullptr) {
|
||||||
|
@ -30,7 +31,6 @@ void* operator new(std::size_t size) {
|
||||||
}
|
}
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* operator new[](std::size_t size) {
|
void* operator new[](std::size_t size) {
|
||||||
void* p = malloc(size);
|
void* p = malloc(size);
|
||||||
if (p == nullptr) {
|
if (p == nullptr) {
|
||||||
|
@ -39,26 +39,21 @@ void* operator new[](std::size_t size) {
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
void operator delete(void* ptr) throw() {
|
// These two are the "nothrow" variants, so we just return nullptr on failure.
|
||||||
free(ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void operator delete[](void* ptr) throw() {
|
|
||||||
free(ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void* operator new(std::size_t size, const std::nothrow_t&) {
|
void* operator new(std::size_t size, const std::nothrow_t&) {
|
||||||
return malloc(size);
|
return malloc(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void* operator new[](std::size_t size, const std::nothrow_t&) {
|
void* operator new[](std::size_t size, const std::nothrow_t&) {
|
||||||
return malloc(size);
|
return malloc(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void operator delete(void* ptr, const std::nothrow_t&) throw() {
|
// free() can't throw anyway (except on heap corruption, which is always fatal),
|
||||||
free(ptr);
|
// so there's no difference between the regular and "nothrow" variants here.
|
||||||
}
|
void operator delete(void* p) noexcept { free(p); }
|
||||||
|
void operator delete[](void* p) noexcept { free(p); }
|
||||||
|
void operator delete(void* p, const std::nothrow_t&) noexcept { free(p); }
|
||||||
|
void operator delete[](void* p, const std::nothrow_t&) noexcept { free(p); }
|
||||||
|
|
||||||
void operator delete[](void* ptr, const std::nothrow_t&) throw() {
|
// TODO: these can use free_sized() once we have it (http://b/284321795).
|
||||||
free(ptr);
|
void operator delete(void* p, std::size_t) noexcept { free(p); }
|
||||||
}
|
void operator delete[](void* p, std::size_t) noexcept { free(p); }
|
||||||
|
|
Loading…
Reference in a new issue