summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Gianforcaro <bgianf@serenityos.org>2021-05-28 05:09:00 -0700
committerAndreas Kling <kling@serenityos.org>2021-05-29 09:04:05 +0200
commit99e23a711d991eea72554ee2deae04a8a3e8c090 (patch)
tree9058a5190e0d59cdbfb12ec1a6205ce3b50acf8e
parent9b1ff3d3ac16237716fede8149f8b850c0d4d91f (diff)
downloadserenity-99e23a711d991eea72554ee2deae04a8a3e8c090.zip
AK+Kernel: Hide AK::adopt_own from usage in the Kernel
We want to discourage folks from using APIs which lull you into a sense of false safety in terms of OOM. There are cases where you want to force allocations to succeed or crash, but those should use a more explicit API than `AK::adopt_own(.)`.
-rw-r--r--AK/NonnullOwnPtr.h6
1 files changed, 6 insertions, 0 deletions
diff --git a/AK/NonnullOwnPtr.h b/AK/NonnullOwnPtr.h
index 5fa314b927..6e3f3b5963 100644
--- a/AK/NonnullOwnPtr.h
+++ b/AK/NonnullOwnPtr.h
@@ -143,12 +143,16 @@ private:
T* m_ptr = nullptr;
};
+#if !defined(KERNEL)
+
template<typename T>
inline NonnullOwnPtr<T> adopt_own(T& object)
{
return NonnullOwnPtr<T>(NonnullOwnPtr<T>::Adopt, object);
}
+#endif
+
template<class T, class... Args>
inline NonnullOwnPtr<T>
make(Args&&... args)
@@ -180,6 +184,8 @@ struct Formatter<NonnullOwnPtr<T>> : Formatter<const T*> {
}
+#if !defined(KERNEL)
using AK::adopt_own;
+#endif
using AK::make;
using AK::NonnullOwnPtr;