AK: Rename adopt() to adopt_ref()

This makes it more symmetrical with adopt_own() (which is used to
create a NonnullOwnPtr from the result of a naked new.)
This commit is contained in:
Andreas Kling 2021-04-23 16:46:57 +02:00
parent b3db01e20e
commit b91c49364d
Notes: sideshowbarker 2024-07-19 01:59:31 +09:00
228 changed files with 461 additions and 461 deletions

View file

@ -292,12 +292,12 @@ inline void ByteBufferImpl::zero_fill()
inline NonnullRefPtr<ByteBufferImpl> ByteBufferImpl::create_uninitialized(size_t size) inline NonnullRefPtr<ByteBufferImpl> ByteBufferImpl::create_uninitialized(size_t size)
{ {
return ::adopt(*new ByteBufferImpl(size)); return ::adopt_ref(*new ByteBufferImpl(size));
} }
inline NonnullRefPtr<ByteBufferImpl> ByteBufferImpl::create_zeroed(size_t size) inline NonnullRefPtr<ByteBufferImpl> ByteBufferImpl::create_zeroed(size_t size)
{ {
auto buffer = ::adopt(*new ByteBufferImpl(size)); auto buffer = ::adopt_ref(*new ByteBufferImpl(size));
if (size != 0) if (size != 0)
__builtin_memset(buffer->data(), 0, size); __builtin_memset(buffer->data(), 0, size);
return buffer; return buffer;
@ -305,7 +305,7 @@ inline NonnullRefPtr<ByteBufferImpl> ByteBufferImpl::create_zeroed(size_t size)
inline NonnullRefPtr<ByteBufferImpl> ByteBufferImpl::copy(const void* data, size_t size) inline NonnullRefPtr<ByteBufferImpl> ByteBufferImpl::copy(const void* data, size_t size)
{ {
return ::adopt(*new ByteBufferImpl(data, size)); return ::adopt_ref(*new ByteBufferImpl(data, size));
} }
} }

View file

@ -37,7 +37,7 @@ Result<NonnullRefPtr<MappedFile>, OSError> MappedFile::map(const String& path)
if (ptr == MAP_FAILED) if (ptr == MAP_FAILED)
return OSError(errno); return OSError(errno);
return adopt(*new MappedFile(ptr, size)); return adopt_ref(*new MappedFile(ptr, size));
} }
MappedFile::MappedFile(void* ptr, size_t size) MappedFile::MappedFile(void* ptr, size_t size)

View file

@ -314,7 +314,7 @@ private:
}; };
template<typename T> template<typename T>
inline NonnullRefPtr<T> adopt(T& object) inline NonnullRefPtr<T> adopt_ref(T& object)
{ {
return NonnullRefPtr<T>(NonnullRefPtr<T>::Adopt, object); return NonnullRefPtr<T>(NonnullRefPtr<T>::Adopt, object);
} }
@ -335,5 +335,5 @@ inline void swap(NonnullRefPtr<T>& a, NonnullRefPtr<U>& b)
} }
using AK::adopt; using AK::adopt_ref;
using AK::NonnullRefPtr; using AK::NonnullRefPtr;

View file

@ -71,7 +71,7 @@ NonnullRefPtr<StringImpl> StringImpl::create_uninitialized(size_t length, char*&
VERIFY(length); VERIFY(length);
void* slot = kmalloc(allocation_size_for_stringimpl(length)); void* slot = kmalloc(allocation_size_for_stringimpl(length));
VERIFY(slot); VERIFY(slot);
auto new_stringimpl = adopt(*new (slot) StringImpl(ConstructWithInlineBuffer, length)); auto new_stringimpl = adopt_ref(*new (slot) StringImpl(ConstructWithInlineBuffer, length));
buffer = const_cast<char*>(new_stringimpl->characters()); buffer = const_cast<char*>(new_stringimpl->characters());
buffer[length] = '\0'; buffer[length] = '\0';
return new_stringimpl; return new_stringimpl;

View file

@ -239,25 +239,25 @@ using AK::TestSuite;
#define __TESTCASE_FUNC(x) __test_##x #define __TESTCASE_FUNC(x) __test_##x
#define __TESTCASE_TYPE(x) __TestCase_##x #define __TESTCASE_TYPE(x) __TestCase_##x
#define TEST_CASE(x) \ #define TEST_CASE(x) \
static void __TESTCASE_FUNC(x)(); \ static void __TESTCASE_FUNC(x)(); \
struct __TESTCASE_TYPE(x) { \ struct __TESTCASE_TYPE(x) { \
__TESTCASE_TYPE(x) \ __TESTCASE_TYPE(x) \
() { TestSuite::the().add_case(adopt(*new TestCase(#x, __TESTCASE_FUNC(x), false))); } \ () { TestSuite::the().add_case(adopt_ref(*new TestCase(#x, __TESTCASE_FUNC(x), false))); } \
}; \ }; \
static struct __TESTCASE_TYPE(x) __TESTCASE_TYPE(x); \ static struct __TESTCASE_TYPE(x) __TESTCASE_TYPE(x); \
static void __TESTCASE_FUNC(x)() static void __TESTCASE_FUNC(x)()
#define __BENCHMARK_FUNC(x) __benchmark_##x #define __BENCHMARK_FUNC(x) __benchmark_##x
#define __BENCHMARK_TYPE(x) __BenchmarkCase_##x #define __BENCHMARK_TYPE(x) __BenchmarkCase_##x
#define BENCHMARK_CASE(x) \ #define BENCHMARK_CASE(x) \
static void __BENCHMARK_FUNC(x)(); \ static void __BENCHMARK_FUNC(x)(); \
struct __BENCHMARK_TYPE(x) { \ struct __BENCHMARK_TYPE(x) { \
__BENCHMARK_TYPE(x) \ __BENCHMARK_TYPE(x) \
() { TestSuite::the().add_case(adopt(*new TestCase(#x, __BENCHMARK_FUNC(x), true))); } \ () { TestSuite::the().add_case(adopt_ref(*new TestCase(#x, __BENCHMARK_FUNC(x), true))); } \
}; \ }; \
static struct __BENCHMARK_TYPE(x) __BENCHMARK_TYPE(x); \ static struct __BENCHMARK_TYPE(x) __BENCHMARK_TYPE(x); \
static void __BENCHMARK_FUNC(x)() static void __BENCHMARK_FUNC(x)()
#define TEST_MAIN(x) \ #define TEST_MAIN(x) \

View file

@ -60,7 +60,7 @@ using IntrusiveRefPtrList = IntrusiveList<IntrusiveRefPtrItem, RefPtr<IntrusiveR
TEST_CASE(intrusive_ref_ptr_no_ref_leaks) TEST_CASE(intrusive_ref_ptr_no_ref_leaks)
{ {
auto item = adopt(*new IntrusiveRefPtrItem()); auto item = adopt_ref(*new IntrusiveRefPtrItem());
EXPECT_EQ(1u, item->ref_count()); EXPECT_EQ(1u, item->ref_count());
IntrusiveRefPtrList ref_list; IntrusiveRefPtrList ref_list;
@ -73,7 +73,7 @@ TEST_CASE(intrusive_ref_ptr_no_ref_leaks)
TEST_CASE(intrusive_ref_ptr_clear) TEST_CASE(intrusive_ref_ptr_clear)
{ {
auto item = adopt(*new IntrusiveRefPtrItem()); auto item = adopt_ref(*new IntrusiveRefPtrItem());
EXPECT_EQ(1u, item->ref_count()); EXPECT_EQ(1u, item->ref_count());
IntrusiveRefPtrList ref_list; IntrusiveRefPtrList ref_list;
@ -86,7 +86,7 @@ TEST_CASE(intrusive_ref_ptr_clear)
TEST_CASE(intrusive_ref_ptr_destructor) TEST_CASE(intrusive_ref_ptr_destructor)
{ {
auto item = adopt(*new IntrusiveRefPtrItem()); auto item = adopt_ref(*new IntrusiveRefPtrItem());
EXPECT_EQ(1u, item->ref_count()); EXPECT_EQ(1u, item->ref_count());
{ {
@ -107,7 +107,7 @@ using IntrusiveNonnullRefPtrList = IntrusiveList<IntrusiveNonnullRefPtrItem, Non
TEST_CASE(intrusive_nonnull_ref_ptr_intrusive) TEST_CASE(intrusive_nonnull_ref_ptr_intrusive)
{ {
auto item = adopt(*new IntrusiveNonnullRefPtrItem()); auto item = adopt_ref(*new IntrusiveNonnullRefPtrItem());
EXPECT_EQ(1u, item->ref_count()); EXPECT_EQ(1u, item->ref_count());
IntrusiveNonnullRefPtrList nonnull_ref_list; IntrusiveNonnullRefPtrList nonnull_ref_list;

View file

@ -15,7 +15,7 @@ struct Object : public RefCounted<Object> {
TEST_CASE(basics) TEST_CASE(basics)
{ {
auto object = adopt(*new Object); auto object = adopt_ref(*new Object);
EXPECT(object.ptr() != nullptr); EXPECT(object.ptr() != nullptr);
EXPECT_EQ(object->ref_count(), 1u); EXPECT_EQ(object->ref_count(), 1u);
object->ref(); object->ref();
@ -33,7 +33,7 @@ TEST_CASE(basics)
TEST_CASE(assign_reference) TEST_CASE(assign_reference)
{ {
auto object = adopt(*new Object); auto object = adopt_ref(*new Object);
EXPECT_EQ(object->ref_count(), 1u); EXPECT_EQ(object->ref_count(), 1u);
object = *object; object = *object;
EXPECT_EQ(object->ref_count(), 1u); EXPECT_EQ(object->ref_count(), 1u);
@ -45,8 +45,8 @@ TEST_CASE(assign_owner_of_self)
RefPtr<Object> parent; RefPtr<Object> parent;
}; };
auto parent = adopt(*new Object); auto parent = adopt_ref(*new Object);
auto child = adopt(*new Object); auto child = adopt_ref(*new Object);
child->parent = move(parent); child->parent = move(parent);
child = *child->parent; child = *child->parent;
@ -55,7 +55,7 @@ TEST_CASE(assign_owner_of_self)
TEST_CASE(swap_with_self) TEST_CASE(swap_with_self)
{ {
auto object = adopt(*new Object); auto object = adopt_ref(*new Object);
swap(object, object); swap(object, object);
EXPECT_EQ(object->ref_count(), 1u); EXPECT_EQ(object->ref_count(), 1u);
} }

View file

@ -27,7 +27,7 @@ size_t SelfAwareObject::num_destroyed = 0;
TEST_CASE(basics) TEST_CASE(basics)
{ {
RefPtr<Object> object = adopt(*new Object); RefPtr<Object> object = adopt_ref(*new Object);
EXPECT(object.ptr() != nullptr); EXPECT(object.ptr() != nullptr);
EXPECT_EQ(object->ref_count(), 1u); EXPECT_EQ(object->ref_count(), 1u);
object->ref(); object->ref();
@ -45,7 +45,7 @@ TEST_CASE(basics)
TEST_CASE(assign_reference) TEST_CASE(assign_reference)
{ {
RefPtr<Object> object = adopt(*new Object); RefPtr<Object> object = adopt_ref(*new Object);
EXPECT_EQ(object->ref_count(), 1u); EXPECT_EQ(object->ref_count(), 1u);
object = *object; object = *object;
EXPECT_EQ(object->ref_count(), 1u); EXPECT_EQ(object->ref_count(), 1u);
@ -53,7 +53,7 @@ TEST_CASE(assign_reference)
TEST_CASE(assign_ptr) TEST_CASE(assign_ptr)
{ {
RefPtr<Object> object = adopt(*new Object); RefPtr<Object> object = adopt_ref(*new Object);
EXPECT_EQ(object->ref_count(), 1u); EXPECT_EQ(object->ref_count(), 1u);
object = object.ptr(); object = object.ptr();
EXPECT_EQ(object->ref_count(), 1u); EXPECT_EQ(object->ref_count(), 1u);
@ -61,7 +61,7 @@ TEST_CASE(assign_ptr)
TEST_CASE(copy_move_ref) TEST_CASE(copy_move_ref)
{ {
RefPtr<Object2> object = adopt(*new Object2); RefPtr<Object2> object = adopt_ref(*new Object2);
EXPECT_EQ(object->ref_count(), 1u); EXPECT_EQ(object->ref_count(), 1u);
{ {
auto object2 = object; auto object2 = object;
@ -84,8 +84,8 @@ TEST_CASE(copy_move_ref)
TEST_CASE(swap) TEST_CASE(swap)
{ {
RefPtr<Object> object_a = adopt(*new Object); RefPtr<Object> object_a = adopt_ref(*new Object);
RefPtr<Object> object_b = adopt(*new Object); RefPtr<Object> object_b = adopt_ref(*new Object);
auto* ptr_a = object_a.ptr(); auto* ptr_a = object_a.ptr();
auto* ptr_b = object_b.ptr(); auto* ptr_b = object_b.ptr();
swap(object_a, object_b); swap(object_a, object_b);
@ -97,7 +97,7 @@ TEST_CASE(swap)
TEST_CASE(assign_moved_self) TEST_CASE(assign_moved_self)
{ {
RefPtr<Object> object = adopt(*new Object); RefPtr<Object> object = adopt_ref(*new Object);
EXPECT_EQ(object->ref_count(), 1u); EXPECT_EQ(object->ref_count(), 1u);
#ifdef __clang__ #ifdef __clang__
# pragma clang diagnostic push # pragma clang diagnostic push
@ -112,7 +112,7 @@ TEST_CASE(assign_moved_self)
TEST_CASE(assign_copy_self) TEST_CASE(assign_copy_self)
{ {
RefPtr<Object> object = adopt(*new Object); RefPtr<Object> object = adopt_ref(*new Object);
EXPECT_EQ(object->ref_count(), 1u); EXPECT_EQ(object->ref_count(), 1u);
#ifdef __clang__ #ifdef __clang__
@ -129,7 +129,7 @@ TEST_CASE(assign_copy_self)
TEST_CASE(self_observers) TEST_CASE(self_observers)
{ {
RefPtr<SelfAwareObject> object = adopt(*new SelfAwareObject); RefPtr<SelfAwareObject> object = adopt_ref(*new SelfAwareObject);
EXPECT_EQ(object->ref_count(), 1u); EXPECT_EQ(object->ref_count(), 1u);
EXPECT_EQ(object->m_has_one_ref_left, false); EXPECT_EQ(object->m_has_one_ref_left, false);
EXPECT_EQ(SelfAwareObject::num_destroyed, 0u); EXPECT_EQ(SelfAwareObject::num_destroyed, 0u);

View file

@ -34,7 +34,7 @@ TEST_CASE(basic_weak)
WeakPtr<SimpleWeakable> weak2; WeakPtr<SimpleWeakable> weak2;
{ {
auto simple = adopt(*new SimpleWeakable); auto simple = adopt_ref(*new SimpleWeakable);
weak1 = simple; weak1 = simple;
weak2 = simple; weak2 = simple;
EXPECT_EQ(weak1.is_null(), false); EXPECT_EQ(weak1.is_null(), false);
@ -54,7 +54,7 @@ TEST_CASE(weakptr_move)
WeakPtr<SimpleWeakable> weak2; WeakPtr<SimpleWeakable> weak2;
{ {
auto simple = adopt(*new SimpleWeakable); auto simple = adopt_ref(*new SimpleWeakable);
weak1 = simple; weak1 = simple;
weak2 = move(weak1); weak2 = move(weak1);
EXPECT_EQ(weak1.is_null(), true); EXPECT_EQ(weak1.is_null(), true);

View file

@ -198,7 +198,7 @@ inline WeakPtr<U> Weakable<T>::make_weak_ptr() const
// There is a small chance that we create a new WeakLink and throw // There is a small chance that we create a new WeakLink and throw
// it away because another thread beat us to it. But the window is // it away because another thread beat us to it. But the window is
// pretty small and the overhead isn't terrible. // pretty small and the overhead isn't terrible.
m_link.assign_if_null(adopt(*new WeakLink(const_cast<T&>(static_cast<const T&>(*this))))); m_link.assign_if_null(adopt_ref(*new WeakLink(const_cast<T&>(static_cast<const T&>(*this)))));
} }
WeakPtr<U> weak_ptr(m_link); WeakPtr<U> weak_ptr(m_link);

View file

@ -43,7 +43,7 @@ public:
if (!(m_consumers.fetch_add(1u << 1, AK::MemoryOrder::memory_order_acquire) & 1u)) { if (!(m_consumers.fetch_add(1u << 1, AK::MemoryOrder::memory_order_acquire) & 1u)) {
T* ptr = (T*)m_ptr.load(AK::MemoryOrder::memory_order_acquire); T* ptr = (T*)m_ptr.load(AK::MemoryOrder::memory_order_acquire);
if (ptr && ptr->try_ref()) if (ptr && ptr->try_ref())
ref = adopt(*ptr); ref = adopt_ref(*ptr);
} }
m_consumers.fetch_sub(1u << 1, AK::MemoryOrder::memory_order_release); m_consumers.fetch_sub(1u << 1, AK::MemoryOrder::memory_order_release);
} }

View file

@ -42,14 +42,14 @@ Objects can only be held by `RefPtr` if they meet certain criteria. Specifically
To make a class `T` reference-counted, you can simply make it inherit from `RefCounted<T>`. This will add all the necessary pieces to `T`. To make a class `T` reference-counted, you can simply make it inherit from `RefCounted<T>`. This will add all the necessary pieces to `T`.
**Note:** When constructing an object that derives from `RefCounted`, the reference count starts out at 1 (since 0 would mean that the object has no owners and should be deleted.) The object must therefore be "adopted" by someone who takes responsibility of that 1. This is done through the global `adopt()` function: **Note:** When constructing an object that derives from `RefCounted`, the reference count starts out at 1 (since 0 would mean that the object has no owners and should be deleted.) The object must therefore be "adopted" by someone who takes responsibility of that 1. This is done through the global `adopt_ref()` function:
```cpp ```cpp
class Bar : public RefCounted<Bar> { class Bar : public RefCounted<Bar> {
... ...
}; };
RefPtr<Bar> our_object = adopt(*new Bar); RefPtr<Bar> our_object = adopt_ref(*new Bar);
RefPtr<Bar> another_owner = our_object; RefPtr<Bar> another_owner = our_object;
``` ```

View file

@ -51,7 +51,7 @@ public:
template<typename AsyncRequestType, typename... Args> template<typename AsyncRequestType, typename... Args>
NonnullRefPtr<AsyncRequestType> make_request(Args&&... args) NonnullRefPtr<AsyncRequestType> make_request(Args&&... args)
{ {
auto request = adopt(*new AsyncRequestType(*this, forward<Args>(args)...)); auto request = adopt_ref(*new AsyncRequestType(*this, forward<Args>(args)...));
ScopedSpinLock lock(m_requests_lock); ScopedSpinLock lock(m_requests_lock);
bool was_empty = m_requests.is_empty(); bool was_empty = m_requests.is_empty();
m_requests.append(request); m_requests.append(request);

View file

@ -14,7 +14,7 @@ namespace Kernel {
UNMAP_AFTER_INIT NonnullRefPtr<I8042Controller> I8042Controller::initialize() UNMAP_AFTER_INIT NonnullRefPtr<I8042Controller> I8042Controller::initialize()
{ {
return adopt(*new I8042Controller()); return adopt_ref(*new I8042Controller());
} }
RefPtr<MouseDevice> I8042Controller::mouse() const RefPtr<MouseDevice> I8042Controller::mouse() const

View file

@ -85,7 +85,7 @@ void PS2KeyboardDevice::handle_irq(const RegisterState&)
UNMAP_AFTER_INIT RefPtr<PS2KeyboardDevice> PS2KeyboardDevice::try_to_initialize(const I8042Controller& ps2_controller) UNMAP_AFTER_INIT RefPtr<PS2KeyboardDevice> PS2KeyboardDevice::try_to_initialize(const I8042Controller& ps2_controller)
{ {
auto device = adopt(*new PS2KeyboardDevice(ps2_controller)); auto device = adopt_ref(*new PS2KeyboardDevice(ps2_controller));
if (device->initialize()) if (device->initialize())
return device; return device;
return nullptr; return nullptr;

View file

@ -176,7 +176,7 @@ void PS2MouseDevice::set_sample_rate(u8 rate)
UNMAP_AFTER_INIT RefPtr<PS2MouseDevice> PS2MouseDevice::try_to_initialize(const I8042Controller& ps2_controller) UNMAP_AFTER_INIT RefPtr<PS2MouseDevice> PS2MouseDevice::try_to_initialize(const I8042Controller& ps2_controller)
{ {
auto device = adopt(*new PS2MouseDevice(ps2_controller)); auto device = adopt_ref(*new PS2MouseDevice(ps2_controller));
if (device->initialize()) if (device->initialize())
return device; return device;
return nullptr; return nullptr;

View file

@ -15,7 +15,7 @@ UNMAP_AFTER_INIT RefPtr<VMWareMouseDevice> VMWareMouseDevice::try_to_initialize(
return {}; return {};
if (!VMWareBackdoor::the()->vmmouse_is_absolute()) if (!VMWareBackdoor::the()->vmmouse_is_absolute())
return {}; return {};
auto device = adopt(*new VMWareMouseDevice(ps2_controller)); auto device = adopt_ref(*new VMWareMouseDevice(ps2_controller));
if (device->initialize()) if (device->initialize())
return device; return device;
return {}; return {};

View file

@ -14,7 +14,7 @@ class AnonymousFile final : public File {
public: public:
static NonnullRefPtr<AnonymousFile> create(NonnullRefPtr<AnonymousVMObject> vmobject) static NonnullRefPtr<AnonymousFile> create(NonnullRefPtr<AnonymousVMObject> vmobject)
{ {
return adopt(*new AnonymousFile(move(vmobject))); return adopt_ref(*new AnonymousFile(move(vmobject)));
} }
virtual ~AnonymousFile() override; virtual ~AnonymousFile() override;

View file

@ -21,7 +21,7 @@ class Custody : public RefCounted<Custody> {
public: public:
static NonnullRefPtr<Custody> create(Custody* parent, const StringView& name, Inode& inode, int mount_flags) static NonnullRefPtr<Custody> create(Custody* parent, const StringView& name, Inode& inode, int mount_flags)
{ {
return adopt(*new Custody(parent, name, inode, mount_flags)); return adopt_ref(*new Custody(parent, name, inode, mount_flags));
} }
~Custody(); ~Custody();

View file

@ -14,11 +14,11 @@ namespace Kernel {
NonnullRefPtr<DevFS> DevFS::create() NonnullRefPtr<DevFS> DevFS::create()
{ {
return adopt(*new DevFS); return adopt_ref(*new DevFS);
} }
DevFS::DevFS() DevFS::DevFS()
: m_root_inode(adopt(*new DevFSRootDirectoryInode(*this))) : m_root_inode(adopt_ref(*new DevFSRootDirectoryInode(*this)))
{ {
LOCKER(m_lock); LOCKER(m_lock);
Device::for_each([&](Device& device) { Device::for_each([&](Device& device) {
@ -32,7 +32,7 @@ DevFS::DevFS()
void DevFS::notify_new_device(Device& device) void DevFS::notify_new_device(Device& device)
{ {
LOCKER(m_lock); LOCKER(m_lock);
auto new_device_inode = adopt(*new DevFSDeviceInode(*this, device)); auto new_device_inode = adopt_ref(*new DevFSDeviceInode(*this, device));
m_nodes.append(new_device_inode); m_nodes.append(new_device_inode);
m_root_inode->m_devices.append(new_device_inode); m_root_inode->m_devices.append(new_device_inode);
} }
@ -274,7 +274,7 @@ KResultOr<NonnullRefPtr<Inode>> DevFSRootDirectoryInode::create_child(const Stri
} }
if (name != "pts") if (name != "pts")
return EROFS; return EROFS;
auto new_directory_inode = adopt(*new DevFSPtsDirectoryInode(m_parent_fs)); auto new_directory_inode = adopt_ref(*new DevFSPtsDirectoryInode(m_parent_fs));
m_subfolders.append(new_directory_inode); m_subfolders.append(new_directory_inode);
m_parent_fs.m_nodes.append(new_directory_inode); m_parent_fs.m_nodes.append(new_directory_inode);
return KResult(KSuccess); return KResult(KSuccess);
@ -284,7 +284,7 @@ KResultOr<NonnullRefPtr<Inode>> DevFSRootDirectoryInode::create_child(const Stri
if (link.name() == name) if (link.name() == name)
return EEXIST; return EEXIST;
} }
auto new_link_inode = adopt(*new DevFSLinkInode(m_parent_fs, name)); auto new_link_inode = adopt_ref(*new DevFSLinkInode(m_parent_fs, name));
m_links.append(new_link_inode); m_links.append(new_link_inode);
m_parent_fs.m_nodes.append(new_link_inode); m_parent_fs.m_nodes.append(new_link_inode);
return new_link_inode; return new_link_inode;

View file

@ -15,7 +15,7 @@ namespace Kernel {
NonnullRefPtr<DevPtsFS> DevPtsFS::create() NonnullRefPtr<DevPtsFS> DevPtsFS::create()
{ {
return adopt(*new DevPtsFS); return adopt_ref(*new DevPtsFS);
} }
DevPtsFS::DevPtsFS() DevPtsFS::DevPtsFS()
@ -30,7 +30,7 @@ static AK::Singleton<HashTable<unsigned>> s_ptys;
bool DevPtsFS::initialize() bool DevPtsFS::initialize()
{ {
m_root_inode = adopt(*new DevPtsFSInode(*this, 1, nullptr)); m_root_inode = adopt_ref(*new DevPtsFSInode(*this, 1, nullptr));
m_root_inode->m_metadata.inode = { fsid(), 1 }; m_root_inode->m_metadata.inode = { fsid(), 1 };
m_root_inode->m_metadata.mode = 0040555; m_root_inode->m_metadata.mode = 0040555;
m_root_inode->m_metadata.uid = 0; m_root_inode->m_metadata.uid = 0;
@ -66,7 +66,7 @@ RefPtr<Inode> DevPtsFS::get_inode(InodeIdentifier inode_id) const
auto* device = Device::get_device(201, pty_index); auto* device = Device::get_device(201, pty_index);
VERIFY(device); VERIFY(device);
auto inode = adopt(*new DevPtsFSInode(const_cast<DevPtsFS&>(*this), inode_id.index(), static_cast<SlavePTY*>(device))); auto inode = adopt_ref(*new DevPtsFSInode(const_cast<DevPtsFS&>(*this), inode_id.index(), static_cast<SlavePTY*>(device)));
inode->m_metadata.inode = inode_id; inode->m_metadata.inode = inode_id;
inode->m_metadata.size = 0; inode->m_metadata.size = 0;
inode->m_metadata.uid = device->uid(); inode->m_metadata.uid = device->uid();

View file

@ -55,7 +55,7 @@ static unsigned divide_rounded_up(unsigned a, unsigned b)
NonnullRefPtr<Ext2FS> Ext2FS::create(FileDescription& file_description) NonnullRefPtr<Ext2FS> Ext2FS::create(FileDescription& file_description)
{ {
return adopt(*new Ext2FS(file_description)); return adopt_ref(*new Ext2FS(file_description));
} }
Ext2FS::Ext2FS(FileDescription& file_description) Ext2FS::Ext2FS(FileDescription& file_description)
@ -797,7 +797,7 @@ RefPtr<Inode> Ext2FS::get_inode(InodeIdentifier inode) const
if (!find_block_containing_inode(inode.index(), block_index, offset)) if (!find_block_containing_inode(inode.index(), block_index, offset))
return {}; return {};
auto new_inode = adopt(*new Ext2FSInode(const_cast<Ext2FS&>(*this), inode.index())); auto new_inode = adopt_ref(*new Ext2FSInode(const_cast<Ext2FS&>(*this), inode.index()));
auto buffer = UserOrKernelBuffer::for_kernel_buffer(reinterpret_cast<u8*>(&new_inode->m_raw_inode)); auto buffer = UserOrKernelBuffer::for_kernel_buffer(reinterpret_cast<u8*>(&new_inode->m_raw_inode));
if (auto result = read_block(block_index, &buffer, sizeof(ext2_inode), offset); result.is_error()) { if (auto result = read_block(block_index, &buffer, sizeof(ext2_inode), offset); result.is_error()) {
// FIXME: Propagate the actual error. // FIXME: Propagate the actual error.

View file

@ -27,7 +27,7 @@ static int s_next_fifo_id = 1;
NonnullRefPtr<FIFO> FIFO::create(uid_t uid) NonnullRefPtr<FIFO> FIFO::create(uid_t uid)
{ {
return adopt(*new FIFO(uid)); return adopt_ref(*new FIFO(uid));
} }
KResultOr<NonnullRefPtr<FileDescription>> FIFO::open_direction(FIFO::Direction direction) KResultOr<NonnullRefPtr<FileDescription>> FIFO::open_direction(FIFO::Direction direction)

View file

@ -25,7 +25,7 @@ namespace Kernel {
KResultOr<NonnullRefPtr<FileDescription>> FileDescription::create(Custody& custody) KResultOr<NonnullRefPtr<FileDescription>> FileDescription::create(Custody& custody)
{ {
auto description = adopt(*new FileDescription(InodeFile::create(custody.inode()))); auto description = adopt_ref(*new FileDescription(InodeFile::create(custody.inode())));
description->m_custody = custody; description->m_custody = custody;
auto result = description->attach(); auto result = description->attach();
if (result.is_error()) { if (result.is_error()) {
@ -37,7 +37,7 @@ KResultOr<NonnullRefPtr<FileDescription>> FileDescription::create(Custody& custo
KResultOr<NonnullRefPtr<FileDescription>> FileDescription::create(File& file) KResultOr<NonnullRefPtr<FileDescription>> FileDescription::create(File& file)
{ {
auto description = adopt(*new FileDescription(file)); auto description = adopt_ref(*new FileDescription(file));
auto result = description->attach(); auto result = description->attach();
if (result.is_error()) { if (result.is_error()) {
dbgln_if(FILEDESCRIPTION_DEBUG, "Failed to create file description for file: {}", result); dbgln_if(FILEDESCRIPTION_DEBUG, "Failed to create file description for file: {}", result);

View file

@ -16,7 +16,7 @@ class InodeFile final : public File {
public: public:
static NonnullRefPtr<InodeFile> create(NonnullRefPtr<Inode>&& inode) static NonnullRefPtr<InodeFile> create(NonnullRefPtr<Inode>&& inode)
{ {
return adopt(*new InodeFile(move(inode))); return adopt_ref(*new InodeFile(move(inode)));
} }
virtual ~InodeFile() override; virtual ~InodeFile() override;

View file

@ -12,7 +12,7 @@ namespace Kernel {
NonnullRefPtr<InodeWatcher> InodeWatcher::create(Inode& inode) NonnullRefPtr<InodeWatcher> InodeWatcher::create(Inode& inode)
{ {
return adopt(*new InodeWatcher(inode)); return adopt_ref(*new InodeWatcher(inode));
} }
InodeWatcher::InodeWatcher(Inode& inode) InodeWatcher::InodeWatcher(Inode& inode)

View file

@ -11,7 +11,7 @@ namespace Kernel {
NonnullRefPtr<Plan9FS> Plan9FS::create(FileDescription& file_description) NonnullRefPtr<Plan9FS> Plan9FS::create(FileDescription& file_description)
{ {
return adopt(*new Plan9FS(file_description)); return adopt_ref(*new Plan9FS(file_description));
} }
Plan9FS::Plan9FS(FileDescription& file_description) Plan9FS::Plan9FS(FileDescription& file_description)
@ -597,7 +597,7 @@ KResult Plan9FS::post_message_and_wait_for_a_reply(Message& message)
{ {
auto request_type = message.type(); auto request_type = message.type();
auto tag = message.tag(); auto tag = message.tag();
auto completion = adopt(*new ReceiveCompletion(tag)); auto completion = adopt_ref(*new ReceiveCompletion(tag));
auto result = post_message(message, completion); auto result = post_message(message, completion);
if (result.is_error()) if (result.is_error())
return result; return result;
@ -680,7 +680,7 @@ Plan9FSInode::Plan9FSInode(Plan9FS& fs, u32 fid)
NonnullRefPtr<Plan9FSInode> Plan9FSInode::create(Plan9FS& fs, u32 fid) NonnullRefPtr<Plan9FSInode> Plan9FSInode::create(Plan9FS& fs, u32 fid)
{ {
return adopt(*new Plan9FSInode(fs, fid)); return adopt_ref(*new Plan9FSInode(fs, fid));
} }
Plan9FSInode::~Plan9FSInode() Plan9FSInode::~Plan9FSInode()

View file

@ -237,7 +237,7 @@ struct ProcFSInodeData : public FileDescriptionData {
NonnullRefPtr<ProcFS> ProcFS::create() NonnullRefPtr<ProcFS> ProcFS::create()
{ {
return adopt(*new ProcFS); return adopt_ref(*new ProcFS);
} }
ProcFS::~ProcFS() ProcFS::~ProcFS()
@ -1018,10 +1018,10 @@ RefPtr<Inode> ProcFS::get_inode(InodeIdentifier inode_id) const
// and if that fails we cannot return this instance anymore and just // and if that fails we cannot return this instance anymore and just
// create a new one. // create a new one.
if (it->value->try_ref()) if (it->value->try_ref())
return adopt(*it->value); return adopt_ref(*it->value);
// We couldn't ref it, so just create a new one and replace the entry // We couldn't ref it, so just create a new one and replace the entry
} }
auto inode = adopt(*new ProcFSInode(const_cast<ProcFS&>(*this), inode_id.index())); auto inode = adopt_ref(*new ProcFSInode(const_cast<ProcFS&>(*this), inode_id.index()));
auto result = m_inodes.set(inode_id.index().value(), inode.ptr()); auto result = m_inodes.set(inode_id.index().value(), inode.ptr());
VERIFY(result == ((it == m_inodes.end()) ? AK::HashSetResult::InsertedNewEntry : AK::HashSetResult::ReplacedExistingEntry)); VERIFY(result == ((it == m_inodes.end()) ? AK::HashSetResult::InsertedNewEntry : AK::HashSetResult::ReplacedExistingEntry));
return inode; return inode;
@ -1677,7 +1677,7 @@ KResult ProcFSInode::chmod(mode_t)
ProcFS::ProcFS() ProcFS::ProcFS()
{ {
m_root_inode = adopt(*new ProcFSInode(*this, 1)); m_root_inode = adopt_ref(*new ProcFSInode(*this, 1));
m_entries.resize(FI_MaxStaticFileIndex); m_entries.resize(FI_MaxStaticFileIndex);
m_entries[FI_Root_df] = { "df", FI_Root_df, false, procfs$df }; m_entries[FI_Root_df] = { "df", FI_Root_df, false, procfs$df };
m_entries[FI_Root_all] = { "all", FI_Root_all, false, procfs$all }; m_entries[FI_Root_all] = { "all", FI_Root_all, false, procfs$all };

View file

@ -132,7 +132,7 @@ private:
ProcFSProxyInode(ProcFS&, FileDescription&); ProcFSProxyInode(ProcFS&, FileDescription&);
static NonnullRefPtr<ProcFSProxyInode> create(ProcFS& fs, FileDescription& fd) static NonnullRefPtr<ProcFSProxyInode> create(ProcFS& fs, FileDescription& fd)
{ {
return adopt(*new ProcFSProxyInode(fs, fd)); return adopt_ref(*new ProcFSProxyInode(fs, fd));
} }
NonnullRefPtr<FileDescription> m_fd; NonnullRefPtr<FileDescription> m_fd;

View file

@ -13,7 +13,7 @@ namespace Kernel {
NonnullRefPtr<TmpFS> TmpFS::create() NonnullRefPtr<TmpFS> TmpFS::create()
{ {
return adopt(*new TmpFS); return adopt_ref(*new TmpFS);
} }
TmpFS::TmpFS() TmpFS::TmpFS()
@ -86,7 +86,7 @@ TmpFSInode::~TmpFSInode()
NonnullRefPtr<TmpFSInode> TmpFSInode::create(TmpFS& fs, InodeMetadata metadata, InodeIdentifier parent) NonnullRefPtr<TmpFSInode> TmpFSInode::create(TmpFS& fs, InodeMetadata metadata, InodeIdentifier parent)
{ {
auto inode = adopt(*new TmpFSInode(fs, metadata, parent)); auto inode = adopt_ref(*new TmpFSInode(fs, metadata, parent));
fs.register_inode(inode); fs.register_inode(inode);
return inode; return inode;
} }

View file

@ -125,7 +125,7 @@ UNMAP_AFTER_INIT void InterruptManagement::switch_to_pic_mode()
dmesgln("Interrupts: Switch to Legacy PIC mode"); dmesgln("Interrupts: Switch to Legacy PIC mode");
InterruptDisabler disabler; InterruptDisabler disabler;
m_smp_enabled = false; m_smp_enabled = false;
m_interrupt_controllers[0] = adopt(*new PIC()); m_interrupt_controllers[0] = adopt_ref(*new PIC());
SpuriousInterruptHandler::initialize(7); SpuriousInterruptHandler::initialize(7);
SpuriousInterruptHandler::initialize(15); SpuriousInterruptHandler::initialize(15);
for (auto& irq_controller : m_interrupt_controllers) { for (auto& irq_controller : m_interrupt_controllers) {
@ -183,7 +183,7 @@ UNMAP_AFTER_INIT void InterruptManagement::locate_apic_data()
int irq_controller_count = 0; int irq_controller_count = 0;
if (madt->flags & PCAT_COMPAT_FLAG) { if (madt->flags & PCAT_COMPAT_FLAG) {
m_interrupt_controllers[0] = adopt(*new PIC()); m_interrupt_controllers[0] = adopt_ref(*new PIC());
irq_controller_count++; irq_controller_count++;
} }
size_t entry_index = 0; size_t entry_index = 0;
@ -195,7 +195,7 @@ UNMAP_AFTER_INIT void InterruptManagement::locate_apic_data()
auto* ioapic_entry = (const ACPI::Structures::MADTEntries::IOAPIC*)madt_entry; auto* ioapic_entry = (const ACPI::Structures::MADTEntries::IOAPIC*)madt_entry;
dbgln("IOAPIC found @ MADT entry {}, MMIO Registers @ {}", entry_index, PhysicalAddress(ioapic_entry->ioapic_address)); dbgln("IOAPIC found @ MADT entry {}, MMIO Registers @ {}", entry_index, PhysicalAddress(ioapic_entry->ioapic_address));
m_interrupt_controllers.resize(1 + irq_controller_count); m_interrupt_controllers.resize(1 + irq_controller_count);
m_interrupt_controllers[irq_controller_count] = adopt(*new IOAPIC(PhysicalAddress(ioapic_entry->ioapic_address), ioapic_entry->gsi_base)); m_interrupt_controllers[irq_controller_count] = adopt_ref(*new IOAPIC(PhysicalAddress(ioapic_entry->ioapic_address), ioapic_entry->gsi_base));
irq_controller_count++; irq_controller_count++;
} }
if (madt_entry->type == (u8)ACPI::Structures::MADTEntryType::InterruptSourceOverride) { if (madt_entry->type == (u8)ACPI::Structures::MADTEntryType::InterruptSourceOverride) {

View file

@ -32,7 +32,7 @@ public:
auto region = MM.allocate_kernel_region(page_round_up(size), name, access, strategy); auto region = MM.allocate_kernel_region(page_round_up(size), name, access, strategy);
if (!region) if (!region)
return nullptr; return nullptr;
return adopt(*new KBufferImpl(region.release_nonnull(), size, strategy)); return adopt_ref(*new KBufferImpl(region.release_nonnull(), size, strategy));
} }
static RefPtr<KBufferImpl> try_create_with_bytes(ReadonlyBytes bytes, Region::Access access, const char* name = "KBuffer", AllocationStrategy strategy = AllocationStrategy::Reserve) static RefPtr<KBufferImpl> try_create_with_bytes(ReadonlyBytes bytes, Region::Access access, const char* name = "KBuffer", AllocationStrategy strategy = AllocationStrategy::Reserve)
@ -41,7 +41,7 @@ public:
if (!region) if (!region)
return nullptr; return nullptr;
memcpy(region->vaddr().as_ptr(), bytes.data(), bytes.size()); memcpy(region->vaddr().as_ptr(), bytes.data(), bytes.size());
return adopt(*new KBufferImpl(region.release_nonnull(), bytes.size(), strategy)); return adopt_ref(*new KBufferImpl(region.release_nonnull(), bytes.size(), strategy));
} }
static RefPtr<KBufferImpl> create_with_size(size_t size, Region::Access access, const char* name, AllocationStrategy strategy = AllocationStrategy::Reserve) static RefPtr<KBufferImpl> create_with_size(size_t size, Region::Access access, const char* name, AllocationStrategy strategy = AllocationStrategy::Reserve)

View file

@ -165,7 +165,7 @@ UNMAP_AFTER_INIT void E1000NetworkAdapter::detect()
if (!is_valid_device_id(id.device_id)) if (!is_valid_device_id(id.device_id))
return; return;
u8 irq = PCI::get_interrupt_line(address); u8 irq = PCI::get_interrupt_line(address);
[[maybe_unused]] auto& unused = adopt(*new E1000NetworkAdapter(address, irq)).leak_ref(); [[maybe_unused]] auto& unused = adopt_ref(*new E1000NetworkAdapter(address, irq)).leak_ref();
}); });
} }

View file

@ -41,7 +41,7 @@ KResultOr<NonnullRefPtr<Socket>> IPv4Socket::create(int type, int protocol)
if (type == SOCK_DGRAM) if (type == SOCK_DGRAM)
return UDPSocket::create(protocol); return UDPSocket::create(protocol);
if (type == SOCK_RAW) if (type == SOCK_RAW)
return adopt(*new IPv4Socket(type, protocol)); return adopt_ref(*new IPv4Socket(type, protocol));
return EINVAL; return EINVAL;
} }

View file

@ -33,7 +33,7 @@ void LocalSocket::for_each(Function<void(const LocalSocket&)> callback)
KResultOr<NonnullRefPtr<Socket>> LocalSocket::create(int type) KResultOr<NonnullRefPtr<Socket>> LocalSocket::create(int type)
{ {
return adopt(*new LocalSocket(type)); return adopt_ref(*new LocalSocket(type));
} }
LocalSocket::LocalSocket(int type) LocalSocket::LocalSocket(int type)

View file

@ -158,7 +158,7 @@ UNMAP_AFTER_INIT void NE2000NetworkAdapter::detect()
if (!ne2k_ids.span().contains_slow(id)) if (!ne2k_ids.span().contains_slow(id))
return; return;
u8 irq = PCI::get_interrupt_line(address); u8 irq = PCI::get_interrupt_line(address);
[[maybe_unused]] auto& unused = adopt(*new NE2000NetworkAdapter(address, irq)).leak_ref(); [[maybe_unused]] auto& unused = adopt_ref(*new NE2000NetworkAdapter(address, irq)).leak_ref();
}); });
} }

View file

@ -114,7 +114,7 @@ UNMAP_AFTER_INIT void RTL8139NetworkAdapter::detect()
if (id != rtl8139_id) if (id != rtl8139_id)
return; return;
u8 irq = PCI::get_interrupt_line(address); u8 irq = PCI::get_interrupt_line(address);
[[maybe_unused]] auto& unused = adopt(*new RTL8139NetworkAdapter(address, irq)).leak_ref(); [[maybe_unused]] auto& unused = adopt_ref(*new RTL8139NetworkAdapter(address, irq)).leak_ref();
}); });
} }

View file

@ -139,7 +139,7 @@ TCPSocket::~TCPSocket()
NonnullRefPtr<TCPSocket> TCPSocket::create(int protocol) NonnullRefPtr<TCPSocket> TCPSocket::create(int protocol)
{ {
return adopt(*new TCPSocket(protocol)); return adopt_ref(*new TCPSocket(protocol));
} }
KResultOr<size_t> TCPSocket::protocol_receive(ReadonlyBytes raw_ipv4_packet, UserOrKernelBuffer& buffer, size_t buffer_size, [[maybe_unused]] int flags) KResultOr<size_t> TCPSocket::protocol_receive(ReadonlyBytes raw_ipv4_packet, UserOrKernelBuffer& buffer, size_t buffer_size, [[maybe_unused]] int flags)

View file

@ -56,7 +56,7 @@ UDPSocket::~UDPSocket()
NonnullRefPtr<UDPSocket> UDPSocket::create(int protocol) NonnullRefPtr<UDPSocket> UDPSocket::create(int protocol)
{ {
return adopt(*new UDPSocket(protocol)); return adopt_ref(*new UDPSocket(protocol));
} }
KResultOr<size_t> UDPSocket::protocol_receive(ReadonlyBytes raw_ipv4_packet, UserOrKernelBuffer& buffer, size_t buffer_size, [[maybe_unused]] int flags) KResultOr<size_t> UDPSocket::protocol_receive(ReadonlyBytes raw_ipv4_packet, UserOrKernelBuffer& buffer, size_t buffer_size, [[maybe_unused]] int flags)

View file

@ -143,7 +143,7 @@ RefPtr<Process> Process::create_user_process(RefPtr<Thread>& first_thread, const
if (!cwd) if (!cwd)
cwd = VFS::the().root_custody(); cwd = VFS::the().root_custody();
auto process = adopt(*new Process(first_thread, parts.take_last(), uid, gid, parent_pid, false, move(cwd), nullptr, tty)); auto process = adopt_ref(*new Process(first_thread, parts.take_last(), uid, gid, parent_pid, false, move(cwd), nullptr, tty));
if (!first_thread) if (!first_thread)
return {}; return {};
process->m_fds.resize(m_max_open_file_descriptors); process->m_fds.resize(m_max_open_file_descriptors);
@ -171,7 +171,7 @@ RefPtr<Process> Process::create_user_process(RefPtr<Thread>& first_thread, const
RefPtr<Process> Process::create_kernel_process(RefPtr<Thread>& first_thread, String&& name, void (*entry)(void*), void* entry_data, u32 affinity) RefPtr<Process> Process::create_kernel_process(RefPtr<Thread>& first_thread, String&& name, void (*entry)(void*), void* entry_data, u32 affinity)
{ {
auto process = adopt(*new Process(first_thread, move(name), (uid_t)0, (gid_t)0, ProcessID(0), true)); auto process = adopt_ref(*new Process(first_thread, move(name), (uid_t)0, (gid_t)0, ProcessID(0), true));
if (!first_thread) if (!first_thread)
return {}; return {};
first_thread->tss().eip = (FlatPtr)entry; first_thread->tss().eip = (FlatPtr)entry;

View file

@ -19,7 +19,7 @@ ProcessGroup::~ProcessGroup()
NonnullRefPtr<ProcessGroup> ProcessGroup::create(ProcessGroupID pgid) NonnullRefPtr<ProcessGroup> ProcessGroup::create(ProcessGroupID pgid)
{ {
auto process_group = adopt(*new ProcessGroup(pgid)); auto process_group = adopt_ref(*new ProcessGroup(pgid));
{ {
ScopedSpinLock lock(g_process_groups_lock); ScopedSpinLock lock(g_process_groups_lock);
g_process_groups->prepend(process_group); g_process_groups->prepend(process_group);

View file

@ -17,7 +17,7 @@ namespace Kernel {
NonnullRefPtr<AHCIController> AHCIController::initialize(PCI::Address address) NonnullRefPtr<AHCIController> AHCIController::initialize(PCI::Address address)
{ {
return adopt(*new AHCIController(address)); return adopt_ref(*new AHCIController(address));
} }
bool AHCIController::reset() bool AHCIController::reset()

View file

@ -18,7 +18,7 @@ namespace Kernel {
NonnullRefPtr<AHCIPort::ScatterList> AHCIPort::ScatterList::create(AsyncBlockDeviceRequest& request, NonnullRefPtrVector<PhysicalPage> allocated_pages, size_t device_block_size) NonnullRefPtr<AHCIPort::ScatterList> AHCIPort::ScatterList::create(AsyncBlockDeviceRequest& request, NonnullRefPtrVector<PhysicalPage> allocated_pages, size_t device_block_size)
{ {
return adopt(*new ScatterList(request, allocated_pages, device_block_size)); return adopt_ref(*new ScatterList(request, allocated_pages, device_block_size));
} }
AHCIPort::ScatterList::ScatterList(AsyncBlockDeviceRequest& request, NonnullRefPtrVector<PhysicalPage> allocated_pages, size_t device_block_size) AHCIPort::ScatterList::ScatterList(AsyncBlockDeviceRequest& request, NonnullRefPtrVector<PhysicalPage> allocated_pages, size_t device_block_size)
@ -29,7 +29,7 @@ AHCIPort::ScatterList::ScatterList(AsyncBlockDeviceRequest& request, NonnullRefP
NonnullRefPtr<AHCIPort> AHCIPort::create(const AHCIPortHandler& handler, volatile AHCI::PortRegisters& registers, u32 port_index) NonnullRefPtr<AHCIPort> AHCIPort::create(const AHCIPortHandler& handler, volatile AHCI::PortRegisters& registers, u32 port_index)
{ {
return adopt(*new AHCIPort(handler, registers, port_index)); return adopt_ref(*new AHCIPort(handler, registers, port_index));
} }
AHCIPort::AHCIPort(const AHCIPortHandler& handler, volatile AHCI::PortRegisters& registers, u32 port_index) AHCIPort::AHCIPort(const AHCIPortHandler& handler, volatile AHCI::PortRegisters& registers, u32 port_index)

View file

@ -11,7 +11,7 @@ namespace Kernel {
NonnullRefPtr<AHCIPortHandler> AHCIPortHandler::create(AHCIController& controller, u8 irq, AHCI::MaskedBitField taken_ports) NonnullRefPtr<AHCIPortHandler> AHCIPortHandler::create(AHCIController& controller, u8 irq, AHCI::MaskedBitField taken_ports)
{ {
return adopt(*new AHCIPortHandler(controller, irq, taken_ports)); return adopt_ref(*new AHCIPortHandler(controller, irq, taken_ports));
} }
AHCIPortHandler::AHCIPortHandler(AHCIController& controller, u8 irq, AHCI::MaskedBitField taken_ports) AHCIPortHandler::AHCIPortHandler(AHCIController& controller, u8 irq, AHCI::MaskedBitField taken_ports)

View file

@ -13,12 +13,12 @@ namespace Kernel {
UNMAP_AFTER_INIT NonnullRefPtr<BMIDEChannel> BMIDEChannel::create(const IDEController& ide_controller, IDEChannel::IOAddressGroup io_group, IDEChannel::ChannelType type) UNMAP_AFTER_INIT NonnullRefPtr<BMIDEChannel> BMIDEChannel::create(const IDEController& ide_controller, IDEChannel::IOAddressGroup io_group, IDEChannel::ChannelType type)
{ {
return adopt(*new BMIDEChannel(ide_controller, io_group, type)); return adopt_ref(*new BMIDEChannel(ide_controller, io_group, type));
} }
UNMAP_AFTER_INIT NonnullRefPtr<BMIDEChannel> BMIDEChannel::create(const IDEController& ide_controller, u8 irq, IDEChannel::IOAddressGroup io_group, IDEChannel::ChannelType type) UNMAP_AFTER_INIT NonnullRefPtr<BMIDEChannel> BMIDEChannel::create(const IDEController& ide_controller, u8 irq, IDEChannel::IOAddressGroup io_group, IDEChannel::ChannelType type)
{ {
return adopt(*new BMIDEChannel(ide_controller, irq, io_group, type)); return adopt_ref(*new BMIDEChannel(ide_controller, irq, io_group, type));
} }
UNMAP_AFTER_INIT BMIDEChannel::BMIDEChannel(const IDEController& controller, IDEChannel::IOAddressGroup io_group, IDEChannel::ChannelType type) UNMAP_AFTER_INIT BMIDEChannel::BMIDEChannel(const IDEController& controller, IDEChannel::IOAddressGroup io_group, IDEChannel::ChannelType type)

View file

@ -26,12 +26,12 @@ namespace Kernel {
UNMAP_AFTER_INIT NonnullRefPtr<IDEChannel> IDEChannel::create(const IDEController& controller, IOAddressGroup io_group, ChannelType type) UNMAP_AFTER_INIT NonnullRefPtr<IDEChannel> IDEChannel::create(const IDEController& controller, IOAddressGroup io_group, ChannelType type)
{ {
return adopt(*new IDEChannel(controller, io_group, type)); return adopt_ref(*new IDEChannel(controller, io_group, type));
} }
UNMAP_AFTER_INIT NonnullRefPtr<IDEChannel> IDEChannel::create(const IDEController& controller, u8 irq, IOAddressGroup io_group, ChannelType type) UNMAP_AFTER_INIT NonnullRefPtr<IDEChannel> IDEChannel::create(const IDEController& controller, u8 irq, IOAddressGroup io_group, ChannelType type)
{ {
return adopt(*new IDEChannel(controller, irq, io_group, type)); return adopt_ref(*new IDEChannel(controller, irq, io_group, type));
} }
RefPtr<StorageDevice> IDEChannel::master_device() const RefPtr<StorageDevice> IDEChannel::master_device() const

View file

@ -16,7 +16,7 @@ namespace Kernel {
UNMAP_AFTER_INIT NonnullRefPtr<IDEController> IDEController::initialize(PCI::Address address, bool force_pio) UNMAP_AFTER_INIT NonnullRefPtr<IDEController> IDEController::initialize(PCI::Address address, bool force_pio)
{ {
return adopt(*new IDEController(address, force_pio)); return adopt_ref(*new IDEController(address, force_pio));
} }
bool IDEController::reset() bool IDEController::reset()

View file

@ -15,7 +15,7 @@ namespace Kernel {
UNMAP_AFTER_INIT NonnullRefPtr<PATADiskDevice> PATADiskDevice::create(const IDEController& controller, IDEChannel& channel, DriveType type, InterfaceType interface_type, u16 capabilities, u64 max_addressable_block) UNMAP_AFTER_INIT NonnullRefPtr<PATADiskDevice> PATADiskDevice::create(const IDEController& controller, IDEChannel& channel, DriveType type, InterfaceType interface_type, u16 capabilities, u64 max_addressable_block)
{ {
return adopt(*new PATADiskDevice(controller, channel, type, interface_type, capabilities, max_addressable_block)); return adopt_ref(*new PATADiskDevice(controller, channel, type, interface_type, capabilities, max_addressable_block));
} }
UNMAP_AFTER_INIT PATADiskDevice::PATADiskDevice(const IDEController& controller, IDEChannel& channel, DriveType type, InterfaceType interface_type, u16 capabilities, u64 max_addressable_block) UNMAP_AFTER_INIT PATADiskDevice::PATADiskDevice(const IDEController& controller, IDEChannel& channel, DriveType type, InterfaceType interface_type, u16 capabilities, u64 max_addressable_block)

View file

@ -12,7 +12,7 @@ namespace Kernel {
NonnullRefPtr<DiskPartition> DiskPartition::create(BlockDevice& device, unsigned minor_number, DiskPartitionMetadata metadata) NonnullRefPtr<DiskPartition> DiskPartition::create(BlockDevice& device, unsigned minor_number, DiskPartitionMetadata metadata)
{ {
return adopt(*new DiskPartition(device, minor_number, metadata)); return adopt_ref(*new DiskPartition(device, minor_number, metadata));
} }
DiskPartition::DiskPartition(BlockDevice& device, unsigned minor_number, DiskPartitionMetadata metadata) DiskPartition::DiskPartition(BlockDevice& device, unsigned minor_number, DiskPartitionMetadata metadata)

View file

@ -13,7 +13,7 @@ namespace Kernel {
NonnullRefPtr<RamdiskController> RamdiskController::initialize() NonnullRefPtr<RamdiskController> RamdiskController::initialize()
{ {
return adopt(*new RamdiskController()); return adopt_ref(*new RamdiskController());
} }
bool RamdiskController::reset() bool RamdiskController::reset()

View file

@ -14,7 +14,7 @@ namespace Kernel {
NonnullRefPtr<RamdiskDevice> RamdiskDevice::create(const RamdiskController& controller, NonnullOwnPtr<Region>&& region, int major, int minor) NonnullRefPtr<RamdiskDevice> RamdiskDevice::create(const RamdiskController& controller, NonnullOwnPtr<Region>&& region, int major, int minor)
{ {
return adopt(*new RamdiskDevice(controller, move(region), major, minor)); return adopt_ref(*new RamdiskDevice(controller, move(region), major, minor));
} }
RamdiskDevice::RamdiskDevice(const RamdiskController& controller, NonnullOwnPtr<Region>&& region, int major, int minor) RamdiskDevice::RamdiskDevice(const RamdiskController& controller, NonnullOwnPtr<Region>&& region, int major, int minor)

View file

@ -15,7 +15,7 @@ namespace Kernel {
NonnullRefPtr<SATADiskDevice> SATADiskDevice::create(const AHCIController& controller, const AHCIPort& port, size_t sector_size, u64 max_addressable_block) NonnullRefPtr<SATADiskDevice> SATADiskDevice::create(const AHCIController& controller, const AHCIPort& port, size_t sector_size, u64 max_addressable_block)
{ {
return adopt(*new SATADiskDevice(controller, port, sector_size, max_addressable_block)); return adopt_ref(*new SATADiskDevice(controller, port, sector_size, max_addressable_block));
} }
SATADiskDevice::SATADiskDevice(const AHCIController& controller, const AHCIPort& port, size_t sector_size, u64 max_addressable_block) SATADiskDevice::SATADiskDevice(const AHCIController& controller, const AHCIPort& port, size_t sector_size, u64 max_addressable_block)

View file

@ -16,7 +16,7 @@ KResultOr<pid_t> Process::sys$fork(RegisterState& regs)
{ {
REQUIRE_PROMISE(proc); REQUIRE_PROMISE(proc);
RefPtr<Thread> child_first_thread; RefPtr<Thread> child_first_thread;
auto child = adopt(*new Process(child_first_thread, m_name, uid(), gid(), pid(), m_is_kernel_process, m_cwd, m_executable, m_tty, this)); auto child = adopt_ref(*new Process(child_first_thread, m_name, uid(), gid(), pid(), m_is_kernel_process, m_cwd, m_executable, m_tty, this));
if (!child_first_thread) if (!child_first_thread)
return ENOMEM; return ENOMEM;
child->m_root_directory = m_root_directory; child->m_root_directory = m_root_directory;

View file

@ -167,7 +167,7 @@ KResultOr<int> Process::sys$futex(Userspace<const Syscall::SC_futex_params*> use
if (it != queues->end()) if (it != queues->end())
return it->value; return it->value;
if (create_if_not_found) { if (create_if_not_found) {
auto futex_queue = adopt(*new FutexQueue(user_address_or_offset, vmobject)); auto futex_queue = adopt_ref(*new FutexQueue(user_address_or_offset, vmobject));
auto result = queues->set(user_address_or_offset, futex_queue); auto result = queues->set(user_address_or_offset, futex_queue);
VERIFY(result == AK::HashSetResult::InsertedNewEntry); VERIFY(result == AK::HashSetResult::InsertedNewEntry);
return futex_queue; return futex_queue;

View file

@ -17,7 +17,7 @@ namespace Kernel {
MasterPTY::MasterPTY(unsigned index) MasterPTY::MasterPTY(unsigned index)
: CharacterDevice(200, index) : CharacterDevice(200, index)
, m_slave(adopt(*new SlavePTY(*this, index))) , m_slave(adopt_ref(*new SlavePTY(*this, index)))
, m_index(index) , m_index(index)
{ {
m_pts_name = String::formatted("/dev/pts/{}", m_index); m_pts_name = String::formatted("/dev/pts/{}", m_index);

View file

@ -40,7 +40,7 @@ KResultOr<NonnullRefPtr<FileDescription>> PTYMultiplexer::open(int options)
if (m_freelist.is_empty()) if (m_freelist.is_empty())
return EBUSY; return EBUSY;
auto master_index = m_freelist.take_last(); auto master_index = m_freelist.take_last();
auto master = adopt(*new MasterPTY(master_index)); auto master = adopt_ref(*new MasterPTY(master_index));
dbgln_if(PTMX_DEBUG, "PTYMultiplexer::open: Vending master {}", master->index()); dbgln_if(PTMX_DEBUG, "PTYMultiplexer::open: Vending master {}", master->index());
auto description = FileDescription::create(move(master)); auto description = FileDescription::create(move(master));
if (!description.is_error()) { if (!description.is_error()) {

View file

@ -41,7 +41,7 @@ KResultOr<NonnullRefPtr<Thread>> Thread::try_create(NonnullRefPtr<Process> proce
if (!kernel_stack_region) if (!kernel_stack_region)
return ENOMEM; return ENOMEM;
kernel_stack_region->set_stack(true); kernel_stack_region->set_stack(true);
return adopt(*new Thread(move(process), kernel_stack_region.release_nonnull())); return adopt_ref(*new Thread(move(process), kernel_stack_region.release_nonnull()));
} }
Thread::Thread(NonnullRefPtr<Process> process, NonnullOwnPtr<Region> kernel_stack_region) Thread::Thread(NonnullRefPtr<Process> process, NonnullOwnPtr<Region> kernel_stack_region)

View file

@ -19,7 +19,7 @@ namespace Kernel {
UNMAP_AFTER_INIT APICTimer* APICTimer::initialize(u8 interrupt_number, HardwareTimerBase& calibration_source) UNMAP_AFTER_INIT APICTimer* APICTimer::initialize(u8 interrupt_number, HardwareTimerBase& calibration_source)
{ {
auto timer = adopt(*new APICTimer(interrupt_number, nullptr)); auto timer = adopt_ref(*new APICTimer(interrupt_number, nullptr));
timer->register_interrupt_handler(); timer->register_interrupt_handler();
if (!timer->calibrate(calibration_source)) { if (!timer->calibrate(calibration_source)) {
return nullptr; return nullptr;

View file

@ -13,7 +13,7 @@ namespace Kernel {
UNMAP_AFTER_INIT NonnullRefPtr<HPETComparator> HPETComparator::create(u8 number, u8 irq, bool periodic_capable) UNMAP_AFTER_INIT NonnullRefPtr<HPETComparator> HPETComparator::create(u8 number, u8 irq, bool periodic_capable)
{ {
auto timer = adopt(*new HPETComparator(number, irq, periodic_capable)); auto timer = adopt_ref(*new HPETComparator(number, irq, periodic_capable));
timer->register_interrupt_handler(); timer->register_interrupt_handler();
return timer; return timer;
} }

View file

@ -17,7 +17,7 @@ namespace Kernel {
UNMAP_AFTER_INIT NonnullRefPtr<PIT> PIT::initialize(Function<void(const RegisterState&)> callback) UNMAP_AFTER_INIT NonnullRefPtr<PIT> PIT::initialize(Function<void(const RegisterState&)> callback)
{ {
return adopt(*new PIT(move(callback))); return adopt_ref(*new PIT(move(callback)));
} }
inline static void reset_countdown(u16 timer_reload) inline static void reset_countdown(u16 timer_reload)

View file

@ -16,7 +16,7 @@ namespace Kernel {
NonnullRefPtr<RealTimeClock> RealTimeClock::create(Function<void(const RegisterState&)> callback) NonnullRefPtr<RealTimeClock> RealTimeClock::create(Function<void(const RegisterState&)> callback)
{ {
return adopt(*new RealTimeClock(move(callback))); return adopt_ref(*new RealTimeClock(move(callback)));
} }
RealTimeClock::RealTimeClock(Function<void(const RegisterState&)> callback) RealTimeClock::RealTimeClock(Function<void(const RegisterState&)> callback)
: HardwareTimer(IRQ_TIMER, move(callback)) : HardwareTimer(IRQ_TIMER, move(callback))

View file

@ -67,7 +67,7 @@ RefPtr<Timer> TimerQueue::add_timer_without_id(clockid_t clock_id, const Time& d
// *must* be a RefPtr<Timer>. Otherwise calling cancel_timer() could // *must* be a RefPtr<Timer>. Otherwise calling cancel_timer() could
// inadvertently cancel another timer that has been created between // inadvertently cancel another timer that has been created between
// returning from the timer handler and a call to cancel_timer(). // returning from the timer handler and a call to cancel_timer().
auto timer = adopt(*new Timer(clock_id, deadline, move(callback))); auto timer = adopt_ref(*new Timer(clock_id, deadline, move(callback)));
ScopedSpinLock lock(g_timerqueue_lock); ScopedSpinLock lock(g_timerqueue_lock);
timer->m_id = 0; // Don't generate a timer id timer->m_id = 0; // Don't generate a timer id
@ -119,7 +119,7 @@ TimerId TimerQueue::add_timer(clockid_t clock_id, const Time& deadline, Function
{ {
auto expires = TimeManagement::the().current_time(clock_id).value(); auto expires = TimeManagement::the().current_time(clock_id).value();
expires = expires + deadline; expires = expires + deadline;
return add_timer(adopt(*new Timer(clock_id, expires, move(callback)))); return add_timer(adopt_ref(*new Timer(clock_id, expires, move(callback))));
} }
bool TimerQueue::cancel_timer(TimerId id) bool TimerQueue::cancel_timer(TimerId id)

View file

@ -41,13 +41,13 @@ RefPtr<VMObject> AnonymousVMObject::clone()
// one would keep the one it still has. This ensures that the original // one would keep the one it still has. This ensures that the original
// one and this one, as well as the clone have sufficient resources // one and this one, as well as the clone have sufficient resources
// to cow all pages as needed // to cow all pages as needed
m_shared_committed_cow_pages = adopt(*new CommittedCowPages(need_cow_pages)); m_shared_committed_cow_pages = adopt_ref(*new CommittedCowPages(need_cow_pages));
// Both original and clone become COW. So create a COW map for ourselves // Both original and clone become COW. So create a COW map for ourselves
// or reset all pages to be copied again if we were previously cloned // or reset all pages to be copied again if we were previously cloned
ensure_or_reset_cow_map(); ensure_or_reset_cow_map();
return adopt(*new AnonymousVMObject(*this)); return adopt_ref(*new AnonymousVMObject(*this));
} }
RefPtr<AnonymousVMObject> AnonymousVMObject::create_with_size(size_t size, AllocationStrategy commit) RefPtr<AnonymousVMObject> AnonymousVMObject::create_with_size(size_t size, AllocationStrategy commit)
@ -57,17 +57,17 @@ RefPtr<AnonymousVMObject> AnonymousVMObject::create_with_size(size_t size, Alloc
if (!MM.commit_user_physical_pages(ceil_div(size, static_cast<size_t>(PAGE_SIZE)))) if (!MM.commit_user_physical_pages(ceil_div(size, static_cast<size_t>(PAGE_SIZE))))
return {}; return {};
} }
return adopt(*new AnonymousVMObject(size, commit)); return adopt_ref(*new AnonymousVMObject(size, commit));
} }
NonnullRefPtr<AnonymousVMObject> AnonymousVMObject::create_with_physical_pages(NonnullRefPtrVector<PhysicalPage> physical_pages) NonnullRefPtr<AnonymousVMObject> AnonymousVMObject::create_with_physical_pages(NonnullRefPtrVector<PhysicalPage> physical_pages)
{ {
return adopt(*new AnonymousVMObject(physical_pages)); return adopt_ref(*new AnonymousVMObject(physical_pages));
} }
NonnullRefPtr<AnonymousVMObject> AnonymousVMObject::create_with_physical_page(PhysicalPage& page) NonnullRefPtr<AnonymousVMObject> AnonymousVMObject::create_with_physical_page(PhysicalPage& page)
{ {
return adopt(*new AnonymousVMObject(page)); return adopt_ref(*new AnonymousVMObject(page));
} }
RefPtr<AnonymousVMObject> AnonymousVMObject::create_for_physical_range(PhysicalAddress paddr, size_t size) RefPtr<AnonymousVMObject> AnonymousVMObject::create_for_physical_range(PhysicalAddress paddr, size_t size)
@ -76,7 +76,7 @@ RefPtr<AnonymousVMObject> AnonymousVMObject::create_for_physical_range(PhysicalA
dbgln("Shenanigans! create_for_physical_range({}, {}) would wrap around", paddr, size); dbgln("Shenanigans! create_for_physical_range({}, {}) would wrap around", paddr, size);
return nullptr; return nullptr;
} }
return adopt(*new AnonymousVMObject(paddr, size)); return adopt_ref(*new AnonymousVMObject(paddr, size));
} }
AnonymousVMObject::AnonymousVMObject(size_t size, AllocationStrategy strategy) AnonymousVMObject::AnonymousVMObject(size_t size, AllocationStrategy strategy)

View file

@ -12,7 +12,7 @@ namespace Kernel {
NonnullRefPtr<ContiguousVMObject> ContiguousVMObject::create_with_size(size_t size, size_t physical_alignment) NonnullRefPtr<ContiguousVMObject> ContiguousVMObject::create_with_size(size_t size, size_t physical_alignment)
{ {
return adopt(*new ContiguousVMObject(size, physical_alignment)); return adopt_ref(*new ContiguousVMObject(size, physical_alignment));
} }
ContiguousVMObject::ContiguousVMObject(size_t size, size_t physical_alignment) ContiguousVMObject::ContiguousVMObject(size_t size, size_t physical_alignment)

View file

@ -22,12 +22,12 @@ class PageDirectory : public RefCounted<PageDirectory> {
public: public:
static RefPtr<PageDirectory> create_for_userspace(const RangeAllocator* parent_range_allocator = nullptr) static RefPtr<PageDirectory> create_for_userspace(const RangeAllocator* parent_range_allocator = nullptr)
{ {
auto page_directory = adopt(*new PageDirectory(parent_range_allocator)); auto page_directory = adopt_ref(*new PageDirectory(parent_range_allocator));
if (!page_directory->is_valid()) if (!page_directory->is_valid())
return {}; return {};
return page_directory; return page_directory;
} }
static NonnullRefPtr<PageDirectory> create_kernel_page_directory() { return adopt(*new PageDirectory); } static NonnullRefPtr<PageDirectory> create_kernel_page_directory() { return adopt_ref(*new PageDirectory); }
static RefPtr<PageDirectory> find_by_cr3(u32); static RefPtr<PageDirectory> find_by_cr3(u32);
~PageDirectory(); ~PageDirectory();

View file

@ -12,7 +12,7 @@ namespace Kernel {
NonnullRefPtr<PhysicalPage> PhysicalPage::create(PhysicalAddress paddr, bool supervisor, bool may_return_to_freelist) NonnullRefPtr<PhysicalPage> PhysicalPage::create(PhysicalAddress paddr, bool supervisor, bool may_return_to_freelist)
{ {
return adopt(*new PhysicalPage(paddr, supervisor, may_return_to_freelist)); return adopt_ref(*new PhysicalPage(paddr, supervisor, may_return_to_freelist));
} }
PhysicalPage::PhysicalPage(PhysicalAddress paddr, bool supervisor, bool may_return_to_freelist) PhysicalPage::PhysicalPage(PhysicalAddress paddr, bool supervisor, bool may_return_to_freelist)

View file

@ -17,7 +17,7 @@ namespace Kernel {
NonnullRefPtr<PhysicalRegion> PhysicalRegion::create(PhysicalAddress lower, PhysicalAddress upper) NonnullRefPtr<PhysicalRegion> PhysicalRegion::create(PhysicalAddress lower, PhysicalAddress upper)
{ {
return adopt(*new PhysicalRegion(lower, upper)); return adopt_ref(*new PhysicalRegion(lower, upper));
} }
PhysicalRegion::PhysicalRegion(PhysicalAddress lower, PhysicalAddress upper) PhysicalRegion::PhysicalRegion(PhysicalAddress lower, PhysicalAddress upper)

View file

@ -11,12 +11,12 @@ namespace Kernel {
NonnullRefPtr<PrivateInodeVMObject> PrivateInodeVMObject::create_with_inode(Inode& inode) NonnullRefPtr<PrivateInodeVMObject> PrivateInodeVMObject::create_with_inode(Inode& inode)
{ {
return adopt(*new PrivateInodeVMObject(inode, inode.size())); return adopt_ref(*new PrivateInodeVMObject(inode, inode.size()));
} }
RefPtr<VMObject> PrivateInodeVMObject::clone() RefPtr<VMObject> PrivateInodeVMObject::clone()
{ {
return adopt(*new PrivateInodeVMObject(*this)); return adopt_ref(*new PrivateInodeVMObject(*this));
} }
PrivateInodeVMObject::PrivateInodeVMObject(Inode& inode, size_t size) PrivateInodeVMObject::PrivateInodeVMObject(Inode& inode, size_t size)

View file

@ -14,14 +14,14 @@ NonnullRefPtr<SharedInodeVMObject> SharedInodeVMObject::create_with_inode(Inode&
size_t size = inode.size(); size_t size = inode.size();
if (auto shared_vmobject = inode.shared_vmobject()) if (auto shared_vmobject = inode.shared_vmobject())
return shared_vmobject.release_nonnull(); return shared_vmobject.release_nonnull();
auto vmobject = adopt(*new SharedInodeVMObject(inode, size)); auto vmobject = adopt_ref(*new SharedInodeVMObject(inode, size));
vmobject->inode().set_shared_vmobject(*vmobject); vmobject->inode().set_shared_vmobject(*vmobject);
return vmobject; return vmobject;
} }
RefPtr<VMObject> SharedInodeVMObject::clone() RefPtr<VMObject> SharedInodeVMObject::clone()
{ {
return adopt(*new SharedInodeVMObject(*this)); return adopt_ref(*new SharedInodeVMObject(*this));
} }
SharedInodeVMObject::SharedInodeVMObject(Inode& inode, size_t size) SharedInodeVMObject::SharedInodeVMObject(Inode& inode, size_t size)

View file

@ -22,11 +22,11 @@ void VirtIO::detect()
return; return;
switch (id.device_id) { switch (id.device_id) {
case VIRTIO_CONSOLE_PCI_DEVICE_ID: { case VIRTIO_CONSOLE_PCI_DEVICE_ID: {
[[maybe_unused]] auto& unused = adopt(*new VirtIOConsole(address)).leak_ref(); [[maybe_unused]] auto& unused = adopt_ref(*new VirtIOConsole(address)).leak_ref();
break; break;
} }
case VIRTIO_ENTROPY_PCI_DEVICE_ID: { case VIRTIO_ENTROPY_PCI_DEVICE_ID: {
[[maybe_unused]] auto& unused = adopt(*new VirtIORNG(address)).leak_ref(); [[maybe_unused]] auto& unused = adopt_ref(*new VirtIORNG(address)).leak_ref();
break; break;
} }
default: default:

View file

@ -10,7 +10,7 @@
NonnullRefPtr<ClipboardHistoryModel> ClipboardHistoryModel::create() NonnullRefPtr<ClipboardHistoryModel> ClipboardHistoryModel::create()
{ {
return adopt(*new ClipboardHistoryModel()); return adopt_ref(*new ClipboardHistoryModel());
} }
ClipboardHistoryModel::~ClipboardHistoryModel() ClipboardHistoryModel::~ClipboardHistoryModel()

View file

@ -30,7 +30,7 @@ ConsoleWidget::ConsoleWidget()
set_fill_with_background_color(true); set_fill_with_background_color(true);
auto base_document = Web::DOM::Document::create(); auto base_document = Web::DOM::Document::create();
base_document->append_child(adopt(*new Web::DOM::DocumentType(base_document))); base_document->append_child(adopt_ref(*new Web::DOM::DocumentType(base_document)));
auto html_element = base_document->create_element("html"); auto html_element = base_document->create_element("html");
base_document->append_child(html_element); base_document->append_child(html_element);
auto head_element = base_document->create_element("head"); auto head_element = base_document->create_element("head");

View file

@ -32,7 +32,7 @@ private:
__Count, __Count,
}; };
static NonnullRefPtr<MonthListModel> create() { return adopt(*new MonthListModel); } static NonnullRefPtr<MonthListModel> create() { return adopt_ref(*new MonthListModel); }
virtual ~MonthListModel() override; virtual ~MonthListModel() override;
virtual int row_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override; virtual int row_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override;

View file

@ -118,7 +118,7 @@ NonnullRefPtrVector<LauncherHandler> DirectoryView::get_launch_handlers(const UR
{ {
NonnullRefPtrVector<LauncherHandler> handlers; NonnullRefPtrVector<LauncherHandler> handlers;
for (auto& h : Desktop::Launcher::get_handlers_with_details_for_url(url)) { for (auto& h : Desktop::Launcher::get_handlers_with_details_for_url(url)) {
handlers.append(adopt(*new LauncherHandler(h))); handlers.append(adopt_ref(*new LauncherHandler(h)));
} }
return handlers; return handlers;
} }

View file

@ -481,7 +481,7 @@ void FontEditorWidget::initialize(const String& path, RefPtr<Gfx::BitmapFont>&&
}); });
m_undo_stack = make<GUI::UndoStack>(); m_undo_stack = make<GUI::UndoStack>();
m_undo_glyph = adopt(*new UndoGlyph(m_glyph_map_widget->selected_glyph(), *m_edited_font)); m_undo_glyph = adopt_ref(*new UndoGlyph(m_glyph_map_widget->selected_glyph(), *m_edited_font));
did_change_undo_stack(); did_change_undo_stack();
if (on_initialize) if (on_initialize)

View file

@ -19,7 +19,7 @@ public:
} }
RefPtr<UndoGlyph> save_state() const RefPtr<UndoGlyph> save_state() const
{ {
auto state = adopt(*new UndoGlyph(m_code_point, *m_font)); auto state = adopt_ref(*new UndoGlyph(m_code_point, *m_font));
auto glyph = font().glyph(m_code_point).glyph_bitmap(); auto glyph = font().glyph(m_code_point).glyph_bitmap();
for (int x = 0; x < glyph.width(); x++) for (int x = 0; x < glyph.width(); x++)
for (int y = 0; y < glyph.height(); y++) for (int y = 0; y < glyph.height(); y++)

View file

@ -16,7 +16,7 @@ class ManualModel final : public GUI::Model {
public: public:
static NonnullRefPtr<ManualModel> create() static NonnullRefPtr<ManualModel> create()
{ {
return adopt(*new ManualModel); return adopt_ref(*new ManualModel);
} }
virtual ~ManualModel() override {}; virtual ~ManualModel() override {};

View file

@ -25,7 +25,7 @@ IRCChannel::~IRCChannel()
NonnullRefPtr<IRCChannel> IRCChannel::create(IRCClient& client, const String& name) NonnullRefPtr<IRCChannel> IRCChannel::create(IRCClient& client, const String& name)
{ {
return adopt(*new IRCChannel(client, name)); return adopt_ref(*new IRCChannel(client, name));
} }
void IRCChannel::add_member(const String& name, char prefix) void IRCChannel::add_member(const String& name, char prefix)

View file

@ -16,7 +16,7 @@ public:
enum Column { enum Column {
Name Name
}; };
static NonnullRefPtr<IRCChannelMemberListModel> create(IRCChannel& channel) { return adopt(*new IRCChannelMemberListModel(channel)); } static NonnullRefPtr<IRCChannelMemberListModel> create(IRCChannel& channel) { return adopt_ref(*new IRCChannelMemberListModel(channel)); }
virtual ~IRCChannelMemberListModel() override; virtual ~IRCChannelMemberListModel() override;
virtual int row_count(const GUI::ModelIndex&) const override; virtual int row_count(const GUI::ModelIndex&) const override;

View file

@ -15,19 +15,19 @@
NonnullRefPtr<IRCLogBuffer> IRCLogBuffer::create() NonnullRefPtr<IRCLogBuffer> IRCLogBuffer::create()
{ {
return adopt(*new IRCLogBuffer); return adopt_ref(*new IRCLogBuffer);
} }
IRCLogBuffer::IRCLogBuffer() IRCLogBuffer::IRCLogBuffer()
{ {
m_document = Web::DOM::Document::create(); m_document = Web::DOM::Document::create();
m_document->append_child(adopt(*new Web::DOM::DocumentType(document()))); m_document->append_child(adopt_ref(*new Web::DOM::DocumentType(document())));
auto html_element = m_document->create_element("html"); auto html_element = m_document->create_element("html");
m_document->append_child(html_element); m_document->append_child(html_element);
auto head_element = m_document->create_element("head"); auto head_element = m_document->create_element("head");
html_element->append_child(head_element); html_element->append_child(head_element);
auto style_element = m_document->create_element("style"); auto style_element = m_document->create_element("style");
style_element->append_child(adopt(*new Web::DOM::Text(document(), "div { font-family: Csilla; font-weight: lighter; }"))); style_element->append_child(adopt_ref(*new Web::DOM::Text(document(), "div { font-family: Csilla; font-weight: lighter; }")));
head_element->append_child(style_element); head_element->append_child(style_element);
auto body_element = m_document->create_element("body"); auto body_element = m_document->create_element("body");
html_element->append_child(body_element); html_element->append_child(body_element);

View file

@ -23,7 +23,7 @@ IRCQuery::~IRCQuery()
NonnullRefPtr<IRCQuery> IRCQuery::create(IRCClient& client, const String& name) NonnullRefPtr<IRCQuery> IRCQuery::create(IRCClient& client, const String& name)
{ {
return adopt(*new IRCQuery(client, name)); return adopt_ref(*new IRCQuery(client, name));
} }
void IRCQuery::add_message(char prefix, const String& name, const String& text, Color color) void IRCQuery::add_message(char prefix, const String& name, const String& text, Color color)

View file

@ -18,7 +18,7 @@ public:
Name, Name,
}; };
static NonnullRefPtr<IRCWindowListModel> create(IRCClient& client) { return adopt(*new IRCWindowListModel(client)); } static NonnullRefPtr<IRCWindowListModel> create(IRCClient& client) { return adopt_ref(*new IRCWindowListModel(client)); }
virtual ~IRCWindowListModel() override; virtual ~IRCWindowListModel() override;
virtual int row_count(const GUI::ModelIndex&) const override; virtual int row_count(const GUI::ModelIndex&) const override;

View file

@ -13,7 +13,7 @@ class CharacterMapFileListModel final : public GUI::Model {
public: public:
static NonnullRefPtr<CharacterMapFileListModel> create(Vector<String>& file_names) static NonnullRefPtr<CharacterMapFileListModel> create(Vector<String>& file_names)
{ {
return adopt(*new CharacterMapFileListModel(file_names)); return adopt_ref(*new CharacterMapFileListModel(file_names));
} }
virtual ~CharacterMapFileListModel() override { } virtual ~CharacterMapFileListModel() override { }

View file

@ -27,7 +27,7 @@ RefPtr<Image> Image::create_with_size(const Gfx::IntSize& size)
if (size.width() > 16384 || size.height() > 16384) if (size.width() > 16384 || size.height() > 16384)
return nullptr; return nullptr;
return adopt(*new Image(size)); return adopt_ref(*new Image(size));
} }
Image::Image(const Gfx::IntSize& size) Image::Image(const Gfx::IntSize& size)

View file

@ -18,7 +18,7 @@ RefPtr<Layer> Layer::create_with_size(Image& image, const Gfx::IntSize& size, co
if (size.width() > 16384 || size.height() > 16384) if (size.width() > 16384 || size.height() > 16384)
return nullptr; return nullptr;
return adopt(*new Layer(image, size, name)); return adopt_ref(*new Layer(image, size, name));
} }
RefPtr<Layer> Layer::create_with_bitmap(Image& image, const Gfx::Bitmap& bitmap, const String& name) RefPtr<Layer> Layer::create_with_bitmap(Image& image, const Gfx::Bitmap& bitmap, const String& name)
@ -29,7 +29,7 @@ RefPtr<Layer> Layer::create_with_bitmap(Image& image, const Gfx::Bitmap& bitmap,
if (bitmap.size().width() > 16384 || bitmap.size().height() > 16384) if (bitmap.size().width() > 16384 || bitmap.size().height() > 16384)
return nullptr; return nullptr;
return adopt(*new Layer(image, bitmap, name)); return adopt_ref(*new Layer(image, bitmap, name));
} }
RefPtr<Layer> Layer::create_snapshot(Image& image, const Layer& layer) RefPtr<Layer> Layer::create_snapshot(Image& image, const Layer& layer)

View file

@ -35,7 +35,7 @@ SoundPlayerWidgetAdvancedView::SoundPlayerWidgetAdvancedView(GUI::Window& window
set_layout<GUI::VerticalBoxLayout>(); set_layout<GUI::VerticalBoxLayout>();
m_splitter = add<GUI::HorizontalSplitter>(); m_splitter = add<GUI::HorizontalSplitter>();
m_player_view = m_splitter->add<GUI::Widget>(); m_player_view = m_splitter->add<GUI::Widget>();
m_playlist_model = adopt(*new PlaylistModel()); m_playlist_model = adopt_ref(*new PlaylistModel());
m_player_view->set_layout<GUI::VerticalBoxLayout>(); m_player_view->set_layout<GUI::VerticalBoxLayout>();

View file

@ -253,7 +253,7 @@ int main(int argc, char* argv[])
{ {
auto app = GUI::Application::construct(argc, argv); auto app = GUI::Application::construct(argc, argv);
RefPtr<Tree> tree = adopt(*new Tree("")); RefPtr<Tree> tree = adopt_ref(*new Tree(""));
// Configure application window. // Configure application window.
auto app_icon = GUI::Icon::default_icon("app-space-analyzer"); auto app_icon = GUI::Icon::default_icon("app-space-analyzer");

View file

@ -21,7 +21,7 @@ namespace Spreadsheet {
class HelpListModel final : public GUI::Model { class HelpListModel final : public GUI::Model {
public: public:
static NonnullRefPtr<HelpListModel> create() { return adopt(*new HelpListModel); } static NonnullRefPtr<HelpListModel> create() { return adopt_ref(*new HelpListModel); }
virtual ~HelpListModel() override { } virtual ~HelpListModel() override { }

View file

@ -23,7 +23,7 @@ public:
if (s_the) if (s_the)
return *s_the; return *s_the;
return *(s_the = adopt(*new HelpWindow(window))); return *(s_the = adopt_ref(*new HelpWindow(window)));
} }
virtual ~HelpWindow() override; virtual ~HelpWindow() override;

View file

@ -359,7 +359,7 @@ void Sheet::copy_cells(Vector<Position> from, Vector<Position> to, Optional<Posi
RefPtr<Sheet> Sheet::from_json(const JsonObject& object, Workbook& workbook) RefPtr<Sheet> Sheet::from_json(const JsonObject& object, Workbook& workbook)
{ {
auto sheet = adopt(*new Sheet(workbook)); auto sheet = adopt_ref(*new Sheet(workbook));
auto rows = object.get("rows").to_u32(default_row_count); auto rows = object.get("rows").to_u32(default_row_count);
auto columns = object.get("columns"); auto columns = object.get("columns");
auto name = object.get("name").as_string_or("Sheet"); auto name = object.get("name").as_string_or("Sheet");
@ -617,7 +617,7 @@ RefPtr<Sheet> Sheet::from_xsv(const Reader::XSV& xsv, Workbook& workbook)
auto cols = xsv.headers(); auto cols = xsv.headers();
auto rows = xsv.size(); auto rows = xsv.size();
auto sheet = adopt(*new Sheet(workbook)); auto sheet = adopt_ref(*new Sheet(workbook));
if (xsv.has_explicit_headers()) { if (xsv.has_explicit_headers()) {
sheet->m_columns = cols; sheet->m_columns = cols;
} else { } else {

View file

@ -13,7 +13,7 @@ namespace Spreadsheet {
class SheetModel final : public GUI::Model { class SheetModel final : public GUI::Model {
public: public:
static NonnullRefPtr<SheetModel> create(Sheet& sheet) { return adopt(*new SheetModel(sheet)); } static NonnullRefPtr<SheetModel> create(Sheet& sheet) { return adopt_ref(*new SheetModel(sheet)); }
virtual ~SheetModel() override; virtual ~SheetModel() override;
virtual int row_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override { return m_sheet->row_count(); } virtual int row_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override { return m_sheet->row_count(); }

View file

@ -14,7 +14,7 @@
NonnullRefPtr<DevicesModel> DevicesModel::create() NonnullRefPtr<DevicesModel> DevicesModel::create()
{ {
return adopt(*new DevicesModel); return adopt_ref(*new DevicesModel);
} }
DevicesModel::DevicesModel() DevicesModel::DevicesModel()

View file

@ -53,7 +53,7 @@ public:
static ProcessModel& the(); static ProcessModel& the();
static NonnullRefPtr<ProcessModel> create() { return adopt(*new ProcessModel); } static NonnullRefPtr<ProcessModel> create() { return adopt_ref(*new ProcessModel); }
virtual ~ProcessModel() override; virtual ~ProcessModel() override;
virtual int row_count(const GUI::ModelIndex&) const override; virtual int row_count(const GUI::ModelIndex&) const override;

View file

@ -88,7 +88,7 @@ ProcessStateWidget::ProcessStateWidget(pid_t pid)
m_table_view = add<GUI::TableView>(); m_table_view = add<GUI::TableView>();
m_table_view->column_header().set_visible(false); m_table_view->column_header().set_visible(false);
m_table_view->column_header().set_section_size(0, 90); m_table_view->column_header().set_section_size(0, 90);
m_table_view->set_model(adopt(*new ProcessStateModel(ProcessModel::the(), pid))); m_table_view->set_model(adopt_ref(*new ProcessStateModel(ProcessModel::the(), pid)));
} }
ProcessStateWidget::~ProcessStateWidget() ProcessStateWidget::~ProcessStateWidget()

View file

@ -95,7 +95,7 @@ int main(int argc, char** argv)
#undef __ENUMERATE_COLOR_ROLE #undef __ENUMERATE_COLOR_ROLE
combo_box.set_only_allow_values_from_model(true); combo_box.set_only_allow_values_from_model(true);
combo_box.set_model(adopt(*new ColorRoleModel(color_roles))); combo_box.set_model(adopt_ref(*new ColorRoleModel(color_roles)));
combo_box.on_change = [&](auto&, auto& index) { combo_box.on_change = [&](auto&, auto& index) {
auto role = static_cast<const ColorRoleModel*>(index.model())->color_role(index); auto role = static_cast<const ColorRoleModel*>(index.model())->color_role(index);
color_input.set_color(preview_palette.color(role)); color_input.set_color(preview_palette.color(role));

View file

@ -13,7 +13,7 @@
class MouseCursorModel final : public GUI::Model { class MouseCursorModel final : public GUI::Model {
public: public:
static NonnullRefPtr<MouseCursorModel> create() { return adopt(*new MouseCursorModel); } static NonnullRefPtr<MouseCursorModel> create() { return adopt_ref(*new MouseCursorModel); }
virtual ~MouseCursorModel() override { } virtual ~MouseCursorModel() override { }
enum Column { enum Column {
@ -86,7 +86,7 @@ private:
class FileIconsModel final : public GUI::Model { class FileIconsModel final : public GUI::Model {
public: public:
static NonnullRefPtr<FileIconsModel> create() { return adopt(*new FileIconsModel); } static NonnullRefPtr<FileIconsModel> create() { return adopt_ref(*new FileIconsModel); }
virtual ~FileIconsModel() override { } virtual ~FileIconsModel() override { }
enum Column { enum Column {

View file

@ -33,7 +33,7 @@ ClassViewWidget::ClassViewWidget()
RefPtr<ClassViewModel> ClassViewModel::create() RefPtr<ClassViewModel> ClassViewModel::create()
{ {
return adopt(*new ClassViewModel()); return adopt_ref(*new ClassViewModel());
} }
int ClassViewModel::row_count(const GUI::ModelIndex& index) const int ClassViewModel::row_count(const GUI::ModelIndex& index) const

View file

@ -10,12 +10,12 @@ namespace HackStudio {
NonnullRefPtr<CodeDocument> CodeDocument::create(const String& file_path, Client* client) NonnullRefPtr<CodeDocument> CodeDocument::create(const String& file_path, Client* client)
{ {
return adopt(*new CodeDocument(file_path, client)); return adopt_ref(*new CodeDocument(file_path, client));
} }
NonnullRefPtr<CodeDocument> CodeDocument::create(Client* client) NonnullRefPtr<CodeDocument> CodeDocument::create(Client* client)
{ {
return adopt(*new CodeDocument(client)); return adopt_ref(*new CodeDocument(client));
} }
CodeDocument::CodeDocument(const String& file_path, Client* client) CodeDocument::CodeDocument(const String& file_path, Client* client)

View file

@ -12,7 +12,7 @@ namespace HackStudio {
NonnullRefPtr<BacktraceModel> BacktraceModel::create(const Debug::DebugSession& debug_session, const PtraceRegisters& regs) NonnullRefPtr<BacktraceModel> BacktraceModel::create(const Debug::DebugSession& debug_session, const PtraceRegisters& regs)
{ {
return adopt(*new BacktraceModel(create_backtrace(debug_session, regs))); return adopt_ref(*new BacktraceModel(create_backtrace(debug_session, regs)));
} }
GUI::Variant BacktraceModel::data(const GUI::ModelIndex& index, GUI::ModelRole role) const GUI::Variant BacktraceModel::data(const GUI::ModelIndex& index, GUI::ModelRole role) const

View file

@ -30,7 +30,7 @@ class DisassemblyModel final : public GUI::Model {
public: public:
static NonnullRefPtr<DisassemblyModel> create(const Debug::DebugSession& debug_session, const PtraceRegisters& regs) static NonnullRefPtr<DisassemblyModel> create(const Debug::DebugSession& debug_session, const PtraceRegisters& regs)
{ {
return adopt(*new DisassemblyModel(debug_session, regs)); return adopt_ref(*new DisassemblyModel(debug_session, regs));
} }
enum Column { enum Column {

Some files were not shown because too many files have changed in this diff Show more