From e841f3c283a113b07b70ac77cf31862dd7d0bcf4 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 7 Nov 2021 12:10:16 +0100 Subject: [PATCH] AK: Add a variant of adopt_nonnull_own_or_enomem() for userspace This variant returns ErrorOr> instead of KResultOr. Eventually the KResultOr variant should go away once the kernel adopts Error and ErrorOr. --- AK/OwnPtr.h | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/AK/OwnPtr.h b/AK/OwnPtr.h index 30e567aae1..582693d9e4 100644 --- a/AK/OwnPtr.h +++ b/AK/OwnPtr.h @@ -10,6 +10,8 @@ #include #ifdef KERNEL # include +#else +# include #endif #define OWNPTR_SCRUB_BYTE 0xf0 @@ -216,6 +218,15 @@ inline Kernel::KResultOr> adopt_nonnull_own_or_enomem(T* object return ENOMEM; return result.release_nonnull(); } +#else +template +inline ErrorOr> adopt_nonnull_own_or_enomem(T* object) +{ + auto result = adopt_own_if_nonnull(object); + if (!result) + return ENOMEM; + return result.release_nonnull(); +} #endif template @@ -242,10 +253,7 @@ struct Traits> : public GenericTraits> { } +using AK::adopt_nonnull_own_or_enomem; using AK::adopt_own_if_nonnull; using AK::OwnPtr; using AK::try_make; - -#ifdef KERNEL -using AK::adopt_nonnull_own_or_enomem; -#endif