1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:48:11 +00:00

Everywhere: Use nothrow new with adopt_{ref,own}_if_nonnull

This commit converts naked `new`s to `AK::try_make` and `AK::try_create`
wherever possible. If the called constructor is private, this can not be
done, so we instead now use the standard-defined and compiler-agnostic
`new (nothrow)`.
This commit is contained in:
Daniel Bertalan 2021-06-20 10:21:16 +02:00 committed by Ali Mohammad Pur
parent 00915e8948
commit f820917a76
45 changed files with 64 additions and 68 deletions

View file

@ -210,7 +210,7 @@ size_t Region::amount_shared() const
NonnullOwnPtr<Region> Region::create_user_accessible(Process* owner, const Range& range, NonnullRefPtr<VMObject> vmobject, size_t offset_in_vmobject, OwnPtr<KString> name, Region::Access access, Cacheable cacheable, bool shared)
{
auto region = adopt_own_if_nonnull(new Region(range, move(vmobject), offset_in_vmobject, move(name), access, cacheable, shared));
auto region = adopt_own_if_nonnull(new (nothrow) Region(range, move(vmobject), offset_in_vmobject, move(name), access, cacheable, shared));
if (region && owner)
region->m_owner = owner->make_weak_ptr();
// FIXME: Return OwnPtr and propagate failure, currently there are too many assumptions made by down stream callers.
@ -219,7 +219,7 @@ NonnullOwnPtr<Region> Region::create_user_accessible(Process* owner, const Range
OwnPtr<Region> Region::create_kernel_only(const Range& range, NonnullRefPtr<VMObject> vmobject, size_t offset_in_vmobject, OwnPtr<KString> name, Region::Access access, Cacheable cacheable)
{
return adopt_own_if_nonnull(new Region(range, move(vmobject), offset_in_vmobject, move(name), access, cacheable, false));
return adopt_own_if_nonnull(new (nothrow) Region(range, move(vmobject), offset_in_vmobject, move(name), access, cacheable, false));
}
bool Region::should_cow(size_t page_index) const