diff options
author | Andreas Kling <kling@serenityos.org> | 2021-11-16 01:15:21 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-11-17 00:21:13 +0100 |
commit | 216e21a1fa95ffc87c371cdd6262467df8cdb5cd (patch) | |
tree | d58f31c31215cce39557cfcc3f35b7795334aa06 /Kernel | |
parent | 008355c222980bd3520caeea9848e04dc2230df1 (diff) | |
download | serenity-216e21a1fa95ffc87c371cdd6262467df8cdb5cd.zip |
AK: Convert AK::Format formatting helpers to returning ErrorOr<void>
This isn't a complete conversion to ErrorOr<void>, but a good chunk.
The end goal here is to propagate buffer allocation failures to the
caller, and allow the use of TRY() with formatting functions.
Diffstat (limited to 'Kernel')
-rw-r--r-- | Kernel/Arch/x86/IO.h | 2 | ||||
-rw-r--r-- | Kernel/Bus/PCI/Definitions.h | 4 | ||||
-rw-r--r-- | Kernel/FileSystem/InodeIdentifier.h | 2 | ||||
-rw-r--r-- | Kernel/KBufferBuilder.h | 2 | ||||
-rw-r--r-- | Kernel/KString.h | 15 | ||||
-rw-r--r-- | Kernel/Library/ThreadSafeNonnullRefPtr.h | 4 | ||||
-rw-r--r-- | Kernel/Library/ThreadSafeRefPtr.h | 4 | ||||
-rw-r--r-- | Kernel/Library/ThreadSafeWeakPtr.h | 6 | ||||
-rw-r--r-- | Kernel/Memory/VirtualRange.h | 2 | ||||
-rw-r--r-- | Kernel/PhysicalAddress.h | 2 | ||||
-rw-r--r-- | Kernel/Process.h | 2 | ||||
-rw-r--r-- | Kernel/Thread.cpp | 2 | ||||
-rw-r--r-- | Kernel/Thread.h | 2 | ||||
-rw-r--r-- | Kernel/VirtualAddress.h | 2 |
14 files changed, 25 insertions, 26 deletions
diff --git a/Kernel/Arch/x86/IO.h b/Kernel/Arch/x86/IO.h index b42bdce0f7..d53264c22e 100644 --- a/Kernel/Arch/x86/IO.h +++ b/Kernel/Arch/x86/IO.h @@ -143,7 +143,7 @@ private: template<> struct AK::Formatter<IOAddress> : AK::Formatter<FormatString> { - void format(FormatBuilder& builder, IOAddress value) + ErrorOr<void> format(FormatBuilder& builder, IOAddress value) { return Formatter<FormatString>::format(builder, "IO {:x}", value.get()); } diff --git a/Kernel/Bus/PCI/Definitions.h b/Kernel/Bus/PCI/Definitions.h index 1118987f4a..f563064257 100644 --- a/Kernel/Bus/PCI/Definitions.h +++ b/Kernel/Bus/PCI/Definitions.h @@ -298,7 +298,7 @@ class Device; template<> struct AK::Formatter<Kernel::PCI::Address> : Formatter<FormatString> { - void format(FormatBuilder& builder, Kernel::PCI::Address value) + ErrorOr<void> format(FormatBuilder& builder, Kernel::PCI::Address value) { return Formatter<FormatString>::format( builder, @@ -308,7 +308,7 @@ struct AK::Formatter<Kernel::PCI::Address> : Formatter<FormatString> { template<> struct AK::Formatter<Kernel::PCI::HardwareID> : Formatter<FormatString> { - void format(FormatBuilder& builder, Kernel::PCI::HardwareID value) + ErrorOr<void> format(FormatBuilder& builder, Kernel::PCI::HardwareID value) { return Formatter<FormatString>::format( builder, diff --git a/Kernel/FileSystem/InodeIdentifier.h b/Kernel/FileSystem/InodeIdentifier.h index 8cee21a3fb..bd07c7d1cd 100644 --- a/Kernel/FileSystem/InodeIdentifier.h +++ b/Kernel/FileSystem/InodeIdentifier.h @@ -53,7 +53,7 @@ private: template<> struct AK::Formatter<Kernel::InodeIdentifier> : AK::Formatter<FormatString> { - void format(FormatBuilder& builder, Kernel::InodeIdentifier value) + ErrorOr<void> format(FormatBuilder& builder, Kernel::InodeIdentifier value) { return AK::Formatter<FormatString>::format(builder, "{}:{}", value.fsid(), value.index()); } diff --git a/Kernel/KBufferBuilder.h b/Kernel/KBufferBuilder.h index e6cded298e..335096a1d4 100644 --- a/Kernel/KBufferBuilder.h +++ b/Kernel/KBufferBuilder.h @@ -37,7 +37,7 @@ public: // FIXME: This really not ideal, but vformat expects StringBuilder. StringBuilder builder; AK::VariadicFormatParams variadic_format_params { parameters... }; - vformat(builder, fmtstr.view(), variadic_format_params); + TRY(vformat(builder, fmtstr.view(), variadic_format_params)); return append_bytes(builder.string_view().bytes()); } diff --git a/Kernel/KString.h b/Kernel/KString.h index d92f400df2..e5ec4d0f79 100644 --- a/Kernel/KString.h +++ b/Kernel/KString.h @@ -46,28 +46,27 @@ namespace AK { template<> struct Formatter<Kernel::KString> : Formatter<StringView> { - void format(FormatBuilder& builder, Kernel::KString const& value) + ErrorOr<void> format(FormatBuilder& builder, Kernel::KString const& value) { - Formatter<StringView>::format(builder, value.view()); + return Formatter<StringView>::format(builder, value.view()); } }; template<> struct Formatter<OwnPtr<Kernel::KString>> : Formatter<StringView> { - void format(FormatBuilder& builder, OwnPtr<Kernel::KString> const& value) + ErrorOr<void> format(FormatBuilder& builder, OwnPtr<Kernel::KString> const& value) { if (value) - Formatter<StringView>::format(builder, value->view()); - else - Formatter<StringView>::format(builder, "[out of memory]"sv); + return Formatter<StringView>::format(builder, value->view()); + return Formatter<StringView>::format(builder, "[out of memory]"sv); } }; template<> struct Formatter<NonnullOwnPtr<Kernel::KString>> : Formatter<StringView> { - void format(FormatBuilder& builder, NonnullOwnPtr<Kernel::KString> const& value) + ErrorOr<void> format(FormatBuilder& builder, NonnullOwnPtr<Kernel::KString> const& value) { - Formatter<StringView>::format(builder, value->view()); + return Formatter<StringView>::format(builder, value->view()); } }; diff --git a/Kernel/Library/ThreadSafeNonnullRefPtr.h b/Kernel/Library/ThreadSafeNonnullRefPtr.h index e12bb05a7f..0f0a0b0eea 100644 --- a/Kernel/Library/ThreadSafeNonnullRefPtr.h +++ b/Kernel/Library/ThreadSafeNonnullRefPtr.h @@ -322,9 +322,9 @@ inline NonnullRefPtr<T> adopt_ref(T& object) template<typename T> struct Formatter<NonnullRefPtr<T>> : Formatter<const T*> { - void format(FormatBuilder& builder, const NonnullRefPtr<T>& value) + ErrorOr<void> format(FormatBuilder& builder, const NonnullRefPtr<T>& value) { - Formatter<const T*>::format(builder, value.ptr()); + return Formatter<const T*>::format(builder, value.ptr()); } }; diff --git a/Kernel/Library/ThreadSafeRefPtr.h b/Kernel/Library/ThreadSafeRefPtr.h index 0bc3f0eeae..31f4824780 100644 --- a/Kernel/Library/ThreadSafeRefPtr.h +++ b/Kernel/Library/ThreadSafeRefPtr.h @@ -445,9 +445,9 @@ private: template<typename T> struct Formatter<RefPtr<T>> : Formatter<const T*> { - void format(FormatBuilder& builder, const RefPtr<T>& value) + ErrorOr<void> format(FormatBuilder& builder, RefPtr<T> const& value) { - Formatter<const T*>::format(builder, value.ptr()); + return Formatter<const T*>::format(builder, value.ptr()); } }; diff --git a/Kernel/Library/ThreadSafeWeakPtr.h b/Kernel/Library/ThreadSafeWeakPtr.h index b89dc480f2..c5675c57a0 100644 --- a/Kernel/Library/ThreadSafeWeakPtr.h +++ b/Kernel/Library/ThreadSafeWeakPtr.h @@ -217,13 +217,13 @@ inline WeakPtr<U> Weakable<T>::make_weak_ptr() const template<typename T> struct Formatter<WeakPtr<T>> : Formatter<const T*> { - void format(FormatBuilder& builder, const WeakPtr<T>& value) + ErrorOr<void> format(FormatBuilder& builder, WeakPtr<T> const& value) { #ifdef KERNEL auto ref = value.strong_ref(); - Formatter<const T*>::format(builder, ref.ptr()); + return Formatter<const T*>::format(builder, ref.ptr()); #else - Formatter<const T*>::format(builder, value.ptr()); + return Formatter<const T*>::format(builder, value.ptr()); #endif } }; diff --git a/Kernel/Memory/VirtualRange.h b/Kernel/Memory/VirtualRange.h index 93c8f80df3..fb959f3e52 100644 --- a/Kernel/Memory/VirtualRange.h +++ b/Kernel/Memory/VirtualRange.h @@ -62,7 +62,7 @@ private: template<> struct AK::Formatter<Kernel::Memory::VirtualRange> : Formatter<FormatString> { - void format(FormatBuilder& builder, Kernel::Memory::VirtualRange value) + ErrorOr<void> format(FormatBuilder& builder, Kernel::Memory::VirtualRange value) { return Formatter<FormatString>::format(builder, "{} - {} (size {:p})", value.base().as_ptr(), value.base().offset(value.size() - 1).as_ptr(), value.size()); } diff --git a/Kernel/PhysicalAddress.h b/Kernel/PhysicalAddress.h index 195e4c2cc0..e1f66d6a6a 100644 --- a/Kernel/PhysicalAddress.h +++ b/Kernel/PhysicalAddress.h @@ -58,7 +58,7 @@ private: template<> struct AK::Formatter<PhysicalAddress> : AK::Formatter<FormatString> { - void format(FormatBuilder& builder, PhysicalAddress value) + ErrorOr<void> format(FormatBuilder& builder, PhysicalAddress value) { if constexpr (sizeof(PhysicalPtr) == sizeof(u64)) return AK::Formatter<FormatString>::format(builder, "P{:016x}", value.get()); diff --git a/Kernel/Process.h b/Kernel/Process.h index e37475a399..3fe8fe2f55 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -980,7 +980,7 @@ inline static ErrorOr<NonnullOwnPtr<KString>> try_copy_kstring_from_user(const K template<> struct AK::Formatter<Kernel::Process> : AK::Formatter<FormatString> { - void format(FormatBuilder& builder, const Kernel::Process& value) + ErrorOr<void> format(FormatBuilder& builder, Kernel::Process const& value) { return AK::Formatter<FormatString>::format(builder, "{}({})", value.name(), value.pid().value()); } diff --git a/Kernel/Thread.cpp b/Kernel/Thread.cpp index d24f98b6e6..45cd0fb34c 100644 --- a/Kernel/Thread.cpp +++ b/Kernel/Thread.cpp @@ -1279,7 +1279,7 @@ void Thread::track_lock_release(LockRank rank) } -void AK::Formatter<Kernel::Thread>::format(FormatBuilder& builder, const Kernel::Thread& value) +ErrorOr<void> AK::Formatter<Kernel::Thread>::format(FormatBuilder& builder, Kernel::Thread const& value) { return AK::Formatter<FormatString>::format( builder, diff --git a/Kernel/Thread.h b/Kernel/Thread.h index d2b858134d..5378b2b9bb 100644 --- a/Kernel/Thread.h +++ b/Kernel/Thread.h @@ -1432,5 +1432,5 @@ inline IterationDecision Thread::for_each_in_state(State state, Callback callbac template<> struct AK::Formatter<Kernel::Thread> : AK::Formatter<FormatString> { - void format(FormatBuilder&, const Kernel::Thread&); + ErrorOr<void> format(FormatBuilder&, Kernel::Thread const&); }; diff --git a/Kernel/VirtualAddress.h b/Kernel/VirtualAddress.h index 6f2120389f..28febf6097 100644 --- a/Kernel/VirtualAddress.h +++ b/Kernel/VirtualAddress.h @@ -54,7 +54,7 @@ inline VirtualAddress operator-(const VirtualAddress& a, const VirtualAddress& b template<> struct AK::Formatter<VirtualAddress> : AK::Formatter<FormatString> { - void format(FormatBuilder& builder, const VirtualAddress& value) + ErrorOr<void> format(FormatBuilder& builder, const VirtualAddress& value) { return AK::Formatter<FormatString>::format(builder, "V{}", value.as_ptr()); } |