From a63a8b32b58c3ca744336683933a185207ba0309 Mon Sep 17 00:00:00 2001 From: apio Date: Mon, 5 Dec 2022 13:45:32 +0100 Subject: [PATCH] Make new and delete noexcept and return nullptr on failure --- kernel/src/memory/Heap.cpp | 36 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/kernel/src/memory/Heap.cpp b/kernel/src/memory/Heap.cpp index edc689f8..a95244be 100644 --- a/kernel/src/memory/Heap.cpp +++ b/kernel/src/memory/Heap.cpp @@ -368,44 +368,32 @@ void dump_heap_usage() kdbgln("-- Heap memory in use by the kernel: %zu bytes", alloc_used); } -void* operator new(usize size) +void* operator new(usize size) noexcept { - auto rc = kmalloc(size); - if (rc.has_error()) { expect(false, rc.error_string()); } - return rc.release_value(); + return kmalloc(size).value_or(nullptr); } -void* operator new[](usize size) +void* operator new[](usize size) noexcept { - auto rc = kmalloc(size); - if (rc.has_error()) { expect(false, rc.error_string()); } - return rc.release_value(); + return kmalloc(size).value_or(nullptr); } -void operator delete(void* p) +void operator delete(void* p) noexcept { - auto rc = kfree(p); - if (rc.has_error()) { expect(false, rc.error_string()); } - return rc.release_value(); + kfree(p); } -void operator delete[](void* p) +void operator delete[](void* p) noexcept { - auto rc = kfree(p); - if (rc.has_error()) { expect(false, rc.error_string()); } - return rc.release_value(); + kfree(p); } -void operator delete(void* p, usize) +void operator delete(void* p, usize) noexcept { - auto rc = kfree(p); - if (rc.has_error()) { expect(false, rc.error_string()); } - return rc.release_value(); + kfree(p); } -void operator delete[](void* p, usize) +void operator delete[](void* p, usize) noexcept { - auto rc = kfree(p); - if (rc.has_error()) { expect(false, rc.error_string()); } - return rc.release_value(); + kfree(p); } \ No newline at end of file