mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 01:20:25 +00:00
AK: Add a variant of adopt_nonnull_own_or_enomem() for userspace
This variant returns ErrorOr<NonnullOwnPtr<T>> instead of KResultOr. Eventually the KResultOr variant should go away once the kernel adopts Error and ErrorOr<T>.
This commit is contained in:
parent
2c70c479ab
commit
e841f3c283
Notes:
sideshowbarker
2024-07-18 01:23:19 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/e841f3c283a
1 changed files with 12 additions and 4 deletions
16
AK/OwnPtr.h
16
AK/OwnPtr.h
|
@ -10,6 +10,8 @@
|
|||
#include <AK/RefCounted.h>
|
||||
#ifdef KERNEL
|
||||
# include <Kernel/API/KResult.h>
|
||||
#else
|
||||
# include <AK/Error.h>
|
||||
#endif
|
||||
|
||||
#define OWNPTR_SCRUB_BYTE 0xf0
|
||||
|
@ -216,6 +218,15 @@ inline Kernel::KResultOr<NonnullOwnPtr<T>> adopt_nonnull_own_or_enomem(T* object
|
|||
return ENOMEM;
|
||||
return result.release_nonnull();
|
||||
}
|
||||
#else
|
||||
template<typename T>
|
||||
inline ErrorOr<NonnullOwnPtr<T>> adopt_nonnull_own_or_enomem(T* object)
|
||||
{
|
||||
auto result = adopt_own_if_nonnull(object);
|
||||
if (!result)
|
||||
return ENOMEM;
|
||||
return result.release_nonnull();
|
||||
}
|
||||
#endif
|
||||
|
||||
template<typename T, class... Args>
|
||||
|
@ -242,10 +253,7 @@ struct Traits<OwnPtr<T>> : public GenericTraits<OwnPtr<T>> {
|
|||
|
||||
}
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue