summaryrefslogtreecommitdiffhomepage
path: root/dev/kernel/NeKit
diff options
context:
space:
mode:
Diffstat (limited to 'dev/kernel/NeKit')
-rw-r--r--dev/kernel/NeKit/ErrorOr.h8
-rw-r--r--dev/kernel/NeKit/Ref.h37
2 files changed, 19 insertions, 26 deletions
diff --git a/dev/kernel/NeKit/ErrorOr.h b/dev/kernel/NeKit/ErrorOr.h
index d7751b7e..5e983d09 100644
--- a/dev/kernel/NeKit/ErrorOr.h
+++ b/dev/kernel/NeKit/ErrorOr.h
@@ -18,13 +18,13 @@ using ErrorT = UInt;
template <typename T>
class ErrorOr final {
public:
- ErrorOr() = default;
+ explicit ErrorOr() = default;
~ErrorOr() = default;
public:
- explicit ErrorOr(Int32 err) : mId(err) {}
+ explicit ErrorOr(Int32 err) : mRef((T*)RTL_ALLOCA(sizeof(T))), mId(err) {}
- explicit ErrorOr(nullPtr Null) {}
+ explicit ErrorOr(nullPtr) {}
explicit ErrorOr(T* Class) : mRef(Class) {}
@@ -48,7 +48,7 @@ class ErrorOr final {
private:
Ref<T> mRef;
- UInt32 mId{0};
+ Int32 mId{0};
};
using ErrorOrAny = ErrorOr<voidPtr>;
diff --git a/dev/kernel/NeKit/Ref.h b/dev/kernel/NeKit/Ref.h
index 9920aa6f..9380bab4 100644
--- a/dev/kernel/NeKit/Ref.h
+++ b/dev/kernel/NeKit/Ref.h
@@ -11,46 +11,39 @@
#include <KernelKit/HeapMgr.h>
#include <NeKit/Defines.h>
#include <NeKit/KernelPanic.h>
+#include <CompilerKit/CompilerKit.h>
namespace Kernel {
template <typename T>
class Ref final {
public:
- Ref() = default;
-
- ~Ref() {
- if (mm_is_valid_ptr(fClass)) delete fClass;
- }
+ explicit Ref() = default;
+ ~Ref() = default;
public:
- Ref(T* cls) : fClass(cls) {}
-
- Ref(T cls) : fClass(nullptr) { fClass = &cls; }
+ Ref(T* cls) : fClass(*cls) {}
+ Ref(T cls) : fClass(cls) {}
Ref& operator=(T ref) {
- fClass = &ref;
+ fClass = ref;
return *this;
}
+ NE_COPY_DEFAULT(Ref);
+
public:
- T operator->() const {
- MUST_PASS(*fClass);
- return *fClass;
- }
+ T operator->() const { return fClass; }
- T& Leak() noexcept { return *fClass; }
+ T& Leak() noexcept { return fClass; }
- T& TryLeak() const noexcept {
- MUST_PASS(*fClass);
- return *fClass;
- }
+ T& TryLeak() const noexcept { return fClass; }
- T operator*() { return *fClass; }
+ T operator*() { return fClass; }
- operator bool() noexcept { return fClass; }
+ operator bool() noexcept { return true; }
private:
- T* fClass{nullptr};
+ T fClass;
};
template <typename T>
@@ -70,7 +63,7 @@ class NonNullRef final {
NonNullRef(const NonNullRef<T>& ref) = default;
private:
- Ref<T> fRef{nullptr};
+ Ref<T> fRef{};
};
} // namespace Kernel