From 825b4f09ca6f551551c4f3be5d72517eab504860 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Tue, 2 Dec 2025 15:57:26 -0500 Subject: chore: new Kernel API for KString, ArrayList and ErrorOr. Signed-off-by: Amlal El Mahrouss --- src/kernel/NeKit/ArrayList.h | 2 +- src/kernel/NeKit/ErrorOr.h | 7 ++---- src/kernel/NeKit/KString.h | 20 ++++++++--------- src/kernel/NeKit/KString.inl | 51 ++++++++++++++++++++++-------------------- src/kernel/NeKit/KernelPanic.h | 12 +++++----- src/kernel/NeKit/OwnPtr.h | 2 +- src/kernel/SignalKit/Signals.h | 2 +- 7 files changed, 48 insertions(+), 48 deletions(-) (limited to 'src/kernel') diff --git a/src/kernel/NeKit/ArrayList.h b/src/kernel/NeKit/ArrayList.h index d3225a50..5787fe98 100644 --- a/src/kernel/NeKit/ArrayList.h +++ b/src/kernel/NeKit/ArrayList.h @@ -28,7 +28,7 @@ class ArrayList final { return fList[index]; } - operator bool() { return fList; } + explicit operator bool() { return fList; } SizeT Count() const { return fLen; } diff --git a/src/kernel/NeKit/ErrorOr.h b/src/kernel/NeKit/ErrorOr.h index f0740488..7de7434d 100644 --- a/src/kernel/NeKit/ErrorOr.h +++ b/src/kernel/NeKit/ErrorOr.h @@ -26,12 +26,9 @@ class ErrorOr final { public: explicit ErrorOr(ErrorT err) : mRef((T*) RTL_ALLOCA(sizeof(T))), mId(err) {} - explicit ErrorOr(nullPtr) {} - - explicit ErrorOr(T* Class) : mRef(Class) {} - - explicit ErrorOr(T Class) : mRef(Class) {} + explicit ErrorOr(T* klass) : mRef(klass) {} + explicit ErrorOr(T klass) : mRef(klass) {} ErrorOr& operator=(const ErrorOr&) = default; ErrorOr(const ErrorOr&) = default; diff --git a/src/kernel/NeKit/KString.h b/src/kernel/NeKit/KString.h index fa0ebcbf..a27084cb 100644 --- a/src/kernel/NeKit/KString.h +++ b/src/kernel/NeKit/KString.h @@ -13,14 +13,14 @@ #include namespace Kernel { -inline auto kMinimumStringSize = 8196; +inline constexpr Int kMinimumStringSize = 8196; /// @brief Kernel string class, not dynamic. -template +template class KBasicString final { public: explicit KBasicString() { - fDataSz = kMinimumStringSize; + fDataSz = MinSz; fData = new CharKind[fDataSz]; MUST_PASS(fData); @@ -53,15 +53,15 @@ class KBasicString final { bool operator==(const CharKind* rhs) const; bool operator!=(const CharKind* rhs) const; - bool operator==(const KBasicString& rhs) const; - bool operator!=(const KBasicString& rhs) const; + bool operator==(const KBasicString& rhs) const; + bool operator!=(const KBasicString& rhs) const; - KBasicString& operator+=(const CharKind* rhs); - KBasicString& operator+=(const KBasicString& rhs); + KBasicString& operator+=(const CharKind* rhs); + KBasicString& operator+=(const KBasicString& rhs); operator const char*() { return fData; } - operator bool() { return fData; } + explicit operator bool() { return fData; } bool operator!() { return fData; } @@ -78,8 +78,8 @@ using KStringOr = ErrorOr; class KStringBuilder final { public: - template - static ErrorOr> Construct(const CharKind* data); + template + static ErrorOr> Construct(const CharKind* data); template static const CharKind* FromBool(const CharKind* fmt, bool n); template diff --git a/src/kernel/NeKit/KString.inl b/src/kernel/NeKit/KString.inl index 3a73e90f..70380ebe 100644 --- a/src/kernel/NeKit/KString.inl +++ b/src/kernel/NeKit/KString.inl @@ -18,23 +18,24 @@ inline void ort_string_append(CharKind* lhs, const CharKind* rhs, Int32 cur) { } } -template -inline CharKind* KBasicString::Data() { +template +inline CharKind* KBasicString::Data() { return this->fData; } -template -inline const CharKind* KBasicString::CData() const { +template +inline const CharKind* KBasicString::CData() const { return const_cast(this->fData); } -template -inline SizeT KBasicString::Length() const { +template +inline SizeT KBasicString::Length() const { return this->fDataSz; } -template -inline bool KBasicString::operator==(const KBasicString& rhs) const { +template +inline bool KBasicString::operator==( + const KBasicString& rhs) const { if (rhs.Length() != this->Length()) return false; for (Size index = 0; index < this->Length(); ++index) { @@ -44,8 +45,8 @@ inline bool KBasicString::operator==(const KBasicString& rhs return true; } -template -inline bool KBasicString::operator==(const CharKind* rhs) const { +template +inline bool KBasicString::operator==(const CharKind* rhs) const { if (oe_string_len(rhs) != this->Length()) return false; for (Size index = 0; index < oe_string_len(rhs); ++index) { @@ -55,8 +56,9 @@ inline bool KBasicString::operator==(const CharKind* rhs) const { return true; } -template -inline bool KBasicString::operator!=(const KBasicString& rhs) const { +template +inline bool KBasicString::operator!=( + const KBasicString& rhs) const { if (rhs.Length() != this->Length()) return false; for (Size index = 0; index < rhs.Length(); ++index) { @@ -66,8 +68,8 @@ inline bool KBasicString::operator!=(const KBasicString& rhs return true; } -template -inline bool KBasicString::operator!=(const CharKind* rhs) const { +template +inline bool KBasicString::operator!=(const CharKind* rhs) const { if (oe_string_len(rhs) != this->Length()) return false; for (Size index = 0; index < oe_string_len(rhs); ++index) { @@ -77,9 +79,9 @@ inline bool KBasicString::operator!=(const CharKind* rhs) const { return true; } -template -inline KBasicString& KBasicString::operator+=( - const KBasicString& rhs) { +template +inline KBasicString& KBasicString::operator+=( + const KBasicString& rhs) { if (oe_string_len(rhs.fData) > this->Length()) return *this; ort_string_append(this->fData, const_cast(rhs.fData), this->fCur); @@ -88,22 +90,23 @@ inline KBasicString& KBasicString::operator+=( return *this; } -template -inline KBasicString& KBasicString::operator+=(const CharKind* rhs) { +template +inline KBasicString& KBasicString::operator+=( + const CharKind* rhs) { ort_string_append(this->fData, const_cast(rhs), this->fCur); this->fCur += oe_string_len(const_cast(rhs)); return *this; } -template -inline ErrorOr> KStringBuilder::Construct(const CharKind* data) { - if (!data || *data == 0) return ErrorOr>(nullptr); +template +inline ErrorOr> KStringBuilder::Construct(const CharKind* data) { + if (!data || *data == 0) return ErrorOr>(-kErrorInvalidData); - KBasicString* view = new KBasicString(oe_string_len(data)); + KBasicString* view = new KBasicString(oe_string_len(data)); (*view) += data; - return ErrorOr>(*view); + return ErrorOr>(*view); } template inline const CharKind* KStringBuilder::FromBool(const CharKind* fmt, bool i) { diff --git a/src/kernel/NeKit/KernelPanic.h b/src/kernel/NeKit/KernelPanic.h index a12ff73c..27cbbb6b 100644 --- a/src/kernel/NeKit/KernelPanic.h +++ b/src/kernel/NeKit/KernelPanic.h @@ -16,12 +16,12 @@ #undef TRY #endif -#define TRY(X) \ - { \ - auto fn = X; \ - if ((fn()) == NO) { \ - MUST_PASS(NO); \ - } \ +#define TRY(X) \ + { \ + auto FN__ = X; \ + if ((FN__()) == NO) { \ + MUST_PASS(NO); \ + } \ } #ifdef __MUST_PASS diff --git a/src/kernel/NeKit/OwnPtr.h b/src/kernel/NeKit/OwnPtr.h index 18a31bd1..d67236b9 100644 --- a/src/kernel/NeKit/OwnPtr.h +++ b/src/kernel/NeKit/OwnPtr.h @@ -8,9 +8,9 @@ #pragma once #include +#include #include #include -#include namespace Kernel { template diff --git a/src/kernel/SignalKit/Signals.h b/src/kernel/SignalKit/Signals.h index 700a4f41..4369d5a0 100644 --- a/src/kernel/SignalKit/Signals.h +++ b/src/kernel/SignalKit/Signals.h @@ -9,7 +9,7 @@ #include #include -#define SIGBAD 0 /* bad signal*/ +#define SIGBAD 0 /* bad signal*/ #define SIGKILL 1 /* kill */ #define SIGPAUS 2 /* pause */ #define SIGEXEC 3 /* execute */ -- cgit v1.2.3