From 5a002913166aa09899d2a5cf5bdabc45a0b09ee8 Mon Sep 17 00:00:00 2001 From: DH Date: Thu, 25 Dec 2025 22:07:36 +0300 Subject: [PATCH] orbis: add kunique_ptr, KDelete, fix kdelete(ptr) --- .../orbis/include/orbis/KernelAllocator.hpp | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/kernel/orbis/include/orbis/KernelAllocator.hpp b/kernel/orbis/include/orbis/KernelAllocator.hpp index 0d21459c6..726fabb89 100644 --- a/kernel/orbis/include/orbis/KernelAllocator.hpp +++ b/kernel/orbis/include/orbis/KernelAllocator.hpp @@ -3,6 +3,7 @@ #include "rx/Rc.hpp" #include #include +#include #include #include #include @@ -78,12 +79,28 @@ T *knew(Args &&...args) { // clang-format off template void kdelete(T *ptr) { - static_assert(std::is_final_v, "Uncertain type size"); - ptr->~T(); - kfree(ptr, sizeof(T)); + static_assert(!std::is_void_v); + static_assert(sizeof(T) > 0); + + if constexpr (std::is_base_of_v) { + delete ptr; + } else { + static_assert(!std::is_polymorphic_v, + "Polymorphic type should be derived from rx::RcBase"); + ptr->~T(); + kfree(ptr, sizeof(T)); + } } // clang-format on +template struct KDelete { + void operator()(T *ptr) const { + kdelete(ptr); + } +}; + +template using kunique_ptr = std::unique_ptr>; + void initializeAllocator(); void deinitializeAllocator(); } // namespace orbis