mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 03:27:45 +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
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>
|
#include <AK/RefCounted.h>
|
||||||
#ifdef KERNEL
|
#ifdef KERNEL
|
||||||
# include <Kernel/API/KResult.h>
|
# include <Kernel/API/KResult.h>
|
||||||
|
#else
|
||||||
|
# include <AK/Error.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define OWNPTR_SCRUB_BYTE 0xf0
|
#define OWNPTR_SCRUB_BYTE 0xf0
|
||||||
|
@ -216,6 +218,15 @@ inline Kernel::KResultOr<NonnullOwnPtr<T>> adopt_nonnull_own_or_enomem(T* object
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
return result.release_nonnull();
|
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
|
#endif
|
||||||
|
|
||||||
template<typename T, class... Args>
|
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::adopt_own_if_nonnull;
|
||||||
using AK::OwnPtr;
|
using AK::OwnPtr;
|
||||||
using AK::try_make;
|
using AK::try_make;
|
||||||
|
|
||||||
#ifdef KERNEL
|
|
||||||
using AK::adopt_nonnull_own_or_enomem;
|
|
||||||
#endif
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue