mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:37:35 +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:
parent
00915e8948
commit
f820917a76
45 changed files with 64 additions and 68 deletions
|
@ -14,7 +14,7 @@ class AnonymousFile final : public File {
|
|||
public:
|
||||
static RefPtr<AnonymousFile> create(NonnullRefPtr<AnonymousVMObject> vmobject)
|
||||
{
|
||||
return adopt_ref_if_nonnull(new AnonymousFile(move(vmobject)));
|
||||
return adopt_ref_if_nonnull(new (nothrow) AnonymousFile(move(vmobject)));
|
||||
}
|
||||
|
||||
virtual ~AnonymousFile() override;
|
||||
|
|
|
@ -17,7 +17,7 @@ KResultOr<NonnullRefPtr<Custody>> Custody::try_create(Custody* parent, StringVie
|
|||
auto name_kstring = KString::try_create(name);
|
||||
if (!name_kstring)
|
||||
return ENOMEM;
|
||||
auto custody = adopt_ref_if_nonnull(new Custody(parent, name_kstring.release_nonnull(), inode, mount_flags));
|
||||
auto custody = adopt_ref_if_nonnull(new (nothrow) Custody(parent, name_kstring.release_nonnull(), inode, mount_flags));
|
||||
if (!custody)
|
||||
return ENOMEM;
|
||||
return custody.release_nonnull();
|
||||
|
|
|
@ -275,7 +275,7 @@ KResultOr<NonnullRefPtr<Inode>> DevFSRootDirectoryInode::create_child(const Stri
|
|||
}
|
||||
if (name != "pts")
|
||||
return EROFS;
|
||||
auto new_directory_inode = adopt_ref_if_nonnull(new DevFSPtsDirectoryInode(m_parent_fs));
|
||||
auto new_directory_inode = adopt_ref_if_nonnull(new (nothrow) DevFSPtsDirectoryInode(m_parent_fs));
|
||||
if (!new_directory_inode)
|
||||
return ENOMEM;
|
||||
if (!m_subfolders.try_ensure_capacity(m_subfolders.size() + 1))
|
||||
|
@ -291,7 +291,7 @@ KResultOr<NonnullRefPtr<Inode>> DevFSRootDirectoryInode::create_child(const Stri
|
|||
if (link.name() == name)
|
||||
return EEXIST;
|
||||
}
|
||||
auto new_link_inode = adopt_ref_if_nonnull(new DevFSLinkInode(m_parent_fs, name));
|
||||
auto new_link_inode = adopt_ref_if_nonnull(new (nothrow) DevFSLinkInode(m_parent_fs, name));
|
||||
if (!new_link_inode)
|
||||
return ENOMEM;
|
||||
if (!m_links.try_ensure_capacity(m_links.size() + 1))
|
||||
|
|
|
@ -1500,7 +1500,7 @@ KResultOr<Ext2FS::CachedBitmap*> Ext2FS::get_bitmap_block(BlockIndex bitmap_bloc
|
|||
dbgln("Ext2FS: Failed to load bitmap block {}", bitmap_block_index);
|
||||
return result;
|
||||
}
|
||||
auto new_bitmap = adopt_own_if_nonnull(new CachedBitmap(bitmap_block_index, move(block)));
|
||||
auto new_bitmap = adopt_own_if_nonnull(new (nothrow) CachedBitmap(bitmap_block_index, move(block)));
|
||||
if (!new_bitmap)
|
||||
return ENOMEM;
|
||||
if (!m_cached_bitmaps.try_append(move(new_bitmap)))
|
||||
|
|
|
@ -30,7 +30,7 @@ KResultOr<NonnullRefPtr<FileDescription>> FileDescription::create(Custody& custo
|
|||
if (inode_file.is_error())
|
||||
return inode_file.error();
|
||||
|
||||
auto description = adopt_ref_if_nonnull(new FileDescription(*inode_file.release_value()));
|
||||
auto description = adopt_ref_if_nonnull(new (nothrow) FileDescription(*inode_file.release_value()));
|
||||
if (!description)
|
||||
return ENOMEM;
|
||||
|
||||
|
@ -45,7 +45,7 @@ KResultOr<NonnullRefPtr<FileDescription>> FileDescription::create(Custody& custo
|
|||
|
||||
KResultOr<NonnullRefPtr<FileDescription>> FileDescription::create(File& file)
|
||||
{
|
||||
auto description = adopt_ref_if_nonnull(new FileDescription(file));
|
||||
auto description = adopt_ref_if_nonnull(new (nothrow) FileDescription(file));
|
||||
if (!description)
|
||||
return ENOMEM;
|
||||
auto result = description->attach();
|
||||
|
|
|
@ -16,7 +16,7 @@ class InodeFile final : public File {
|
|||
public:
|
||||
static KResultOr<NonnullRefPtr<InodeFile>> create(NonnullRefPtr<Inode>&& inode)
|
||||
{
|
||||
auto file = adopt_ref_if_nonnull(new InodeFile(move(inode)));
|
||||
auto file = adopt_ref_if_nonnull(new (nothrow) InodeFile(move(inode)));
|
||||
if (!file)
|
||||
return ENOMEM;
|
||||
return file.release_nonnull();
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace Kernel {
|
|||
|
||||
KResultOr<NonnullRefPtr<InodeWatcher>> InodeWatcher::create()
|
||||
{
|
||||
auto watcher = adopt_ref_if_nonnull(new InodeWatcher);
|
||||
auto watcher = adopt_ref_if_nonnull(new (nothrow) InodeWatcher);
|
||||
if (watcher)
|
||||
return watcher.release_nonnull();
|
||||
return ENOMEM;
|
||||
|
|
|
@ -27,7 +27,7 @@ struct WatchDescription {
|
|||
|
||||
static KResultOr<NonnullOwnPtr<WatchDescription>> create(int wd, Inode& inode, unsigned event_mask)
|
||||
{
|
||||
auto description = adopt_own_if_nonnull(new WatchDescription(wd, inode, event_mask));
|
||||
auto description = adopt_own_if_nonnull(new (nothrow) WatchDescription(wd, inode, event_mask));
|
||||
if (description)
|
||||
return description.release_nonnull();
|
||||
return ENOMEM;
|
||||
|
|
|
@ -576,7 +576,7 @@ KResult Plan9FS::read_and_dispatch_one_message()
|
|||
auto completion = optional_completion.value();
|
||||
ScopedSpinLock lock(completion->lock);
|
||||
completion->result = KSuccess;
|
||||
completion->message = adopt_own_if_nonnull(new Message { buffer.release_nonnull() });
|
||||
completion->message = adopt_own_if_nonnull(new (nothrow) Message { buffer.release_nonnull() });
|
||||
completion->completed = true;
|
||||
|
||||
m_completions.remove(header.tag);
|
||||
|
|
|
@ -264,7 +264,7 @@ struct ProcFSInodeData : public FileDescriptionData {
|
|||
|
||||
RefPtr<ProcFS> ProcFS::create()
|
||||
{
|
||||
return adopt_ref_if_nonnull(new ProcFS);
|
||||
return adopt_ref_if_nonnull(new (nothrow) ProcFS);
|
||||
}
|
||||
|
||||
ProcFS::~ProcFS()
|
||||
|
@ -1073,7 +1073,7 @@ RefPtr<Inode> ProcFS::get_inode(InodeIdentifier inode_id) const
|
|||
return adopt_ref_if_nonnull(it->value);
|
||||
// We couldn't ref it, so just create a new one and replace the entry
|
||||
}
|
||||
auto inode = adopt_ref_if_nonnull(new ProcFSInode(const_cast<ProcFS&>(*this), inode_id.index()));
|
||||
auto inode = adopt_ref_if_nonnull(new (nothrow) ProcFSInode(const_cast<ProcFS&>(*this), inode_id.index()));
|
||||
if (!inode)
|
||||
return {};
|
||||
auto result = m_inodes.set(inode_id.index().value(), inode.ptr());
|
||||
|
@ -1163,7 +1163,7 @@ KResult ProcFSInode::refresh_data(FileDescription& description) const
|
|||
}
|
||||
|
||||
if (!cached_data)
|
||||
cached_data = adopt_own_if_nonnull(new ProcFSInodeData);
|
||||
cached_data = adopt_own_if_nonnull(new (nothrow) ProcFSInodeData);
|
||||
auto& buffer = static_cast<ProcFSInodeData&>(*cached_data).buffer;
|
||||
if (buffer) {
|
||||
// If we're reusing the buffer, reset the size to 0 first. This
|
||||
|
|
|
@ -13,7 +13,7 @@ namespace Kernel {
|
|||
|
||||
RefPtr<TmpFS> TmpFS::create()
|
||||
{
|
||||
return adopt_ref_if_nonnull(new TmpFS);
|
||||
return adopt_ref_if_nonnull(new (nothrow) TmpFS);
|
||||
}
|
||||
|
||||
TmpFS::TmpFS()
|
||||
|
@ -86,7 +86,7 @@ TmpFSInode::~TmpFSInode()
|
|||
|
||||
RefPtr<TmpFSInode> TmpFSInode::create(TmpFS& fs, InodeMetadata metadata, InodeIdentifier parent)
|
||||
{
|
||||
auto inode = adopt_ref_if_nonnull(new TmpFSInode(fs, metadata, parent));
|
||||
auto inode = adopt_ref_if_nonnull(new (nothrow) TmpFSInode(fs, metadata, parent));
|
||||
if (inode)
|
||||
fs.register_inode(*inode);
|
||||
return inode;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue