From c1de1c563ed5e47a17e7d72a7ab2abcfda08b3be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=81=E6=AC=A3=E7=AB=A5?= Date: Wed, 13 Jan 2021 15:57:32 +0800 Subject: [PATCH] Add placement new and new[] function. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit N/A Change-Id: I9f16f9c0c36f2619218a65d178100d54ced5f71b Signed-off-by: 丁欣童 --- 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..1d31af08875 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; +} \ No newline at end of file diff --git a/libs/libxx/libxx_newa.cxx b/libs/libxx/libxx_newa.cxx index 8cab9f55e6d..d464e57301e 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; +} \ No newline at end of file