From c618d0447bfe7535c4f3ef6c6cbb8cdcaf5fb85f Mon Sep 17 00:00:00 2001 From: dingxintong Date: Wed, 13 Jan 2021 20:10:25 +0800 Subject: [PATCH] Add placement new and new[] function. Signed-off-by: dingxintong --- libs/libxx/libxx_new.cxx | 15 +++++++++++++++ libs/libxx/libxx_newa.cxx | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/libs/libxx/libxx_new.cxx b/libs/libxx/libxx_new.cxx index 652eb342fd3..e0f8894b45e 100644 --- a/libs/libxx/libxx_new.cxx +++ b/libs/libxx/libxx_new.cxx @@ -88,3 +88,18 @@ FAR void *operator new(std::size_t nbytes) return alloc; } + +FAR void *operator new(std::size_t nbytes, FAR void *ptr) +{ + +#ifdef CONFIG_DEBUG_ERROR + if (ptr == nullptr) + { + _err("ERROR: Failed to placement new\n"); + } +#endif + + // Return the ptr pointer + + return ptr; +} diff --git a/libs/libxx/libxx_newa.cxx b/libs/libxx/libxx_newa.cxx index 8cab9f55e6d..8c3b8a464cc 100644 --- a/libs/libxx/libxx_newa.cxx +++ b/libs/libxx/libxx_newa.cxx @@ -96,3 +96,18 @@ FAR void *operator new[](std::size_t nbytes) return alloc; } + +FAR void *operator new[](std::size_t nbytes, FAR void *ptr) +{ + +#ifdef CONFIG_DEBUG_ERROR + if (ptr == nullptr) + { + _err("ERROR: Failed to placement new[]\n"); + } +#endif + + // Return the ptr pointer + + return ptr; +}