mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 01:57:45 +00:00
AK: Simplify constructors and conversions from nullptr_t
Problem: - Many constructors are defined as `{}` rather than using the ` = default` compiler-provided constructor. - Some types provide an implicit conversion operator from `nullptr_t` instead of requiring the caller to default construct. This violates the C++ Core Guidelines suggestion to declare single-argument constructors explicit (https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c46-by-default-declare-single-argument-constructors-explicit). Solution: - Change default constructors to use the compiler-provided default constructor. - Remove implicit conversion operators from `nullptr_t` and change usage to enforce type consistency without conversion.
This commit is contained in:
parent
9dc44bf8c4
commit
e6f907a155
105 changed files with 300 additions and 244 deletions
|
@ -41,7 +41,7 @@ OwnPtr<MultiProcessorParser> MultiProcessorParser::autodetect()
|
|||
{
|
||||
auto floating_pointer = find_floating_pointer();
|
||||
if (!floating_pointer.has_value())
|
||||
return nullptr;
|
||||
return {};
|
||||
return adopt_own(*new MultiProcessorParser(floating_pointer.value()));
|
||||
}
|
||||
|
||||
|
|
|
@ -45,12 +45,12 @@ OwnPtr<CoreDump> CoreDump::create(NonnullRefPtr<Process> process, const String&
|
|||
{
|
||||
if (!process->is_dumpable()) {
|
||||
dbgln("Refusing to generate CoreDump for non-dumpable process {}", process->pid().value());
|
||||
return nullptr;
|
||||
return {};
|
||||
}
|
||||
|
||||
auto fd = create_target_file(process, output_path);
|
||||
if (!fd)
|
||||
return nullptr;
|
||||
return {};
|
||||
return adopt_own(*new CoreDump(move(process), fd.release_nonnull()));
|
||||
}
|
||||
|
||||
|
|
|
@ -227,7 +227,7 @@ void SB16::handle_irq(const RegisterState&)
|
|||
|
||||
void SB16::wait_for_irq()
|
||||
{
|
||||
m_irq_queue.wait_on(nullptr, "SB16");
|
||||
m_irq_queue.wait_on({}, "SB16");
|
||||
disable_irq();
|
||||
}
|
||||
|
||||
|
|
|
@ -75,7 +75,7 @@ KResultOr<NonnullRefPtr<FileDescription>> FIFO::open_direction_blocking(FIFO::Di
|
|||
|
||||
if (m_writers == 0) {
|
||||
locker.unlock();
|
||||
m_write_open_queue.wait_on(nullptr, "FIFO");
|
||||
m_write_open_queue.wait_on({}, "FIFO");
|
||||
locker.lock();
|
||||
}
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ KResultOr<NonnullRefPtr<FileDescription>> FIFO::open_direction_blocking(FIFO::Di
|
|||
|
||||
if (m_readers == 0) {
|
||||
locker.unlock();
|
||||
m_read_open_queue.wait_on(nullptr, "FIFO");
|
||||
m_read_open_queue.wait_on({}, "FIFO");
|
||||
locker.lock();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -531,7 +531,7 @@ KResult Plan9FS::post_message(Message& message, RefPtr<ReceiveCompletion> comple
|
|||
while (size > 0) {
|
||||
if (!description.can_write()) {
|
||||
auto unblock_flags = Thread::FileBlocker::BlockFlags::None;
|
||||
if (Thread::current()->block<Thread::WriteBlocker>(nullptr, description, unblock_flags).was_interrupted())
|
||||
if (Thread::current()->block<Thread::WriteBlocker>({}, description, unblock_flags).was_interrupted())
|
||||
return KResult(-EINTR);
|
||||
}
|
||||
auto data_buffer = UserOrKernelBuffer::for_kernel_buffer(const_cast<u8*>(data));
|
||||
|
@ -552,7 +552,7 @@ KResult Plan9FS::do_read(u8* data, size_t size)
|
|||
while (size > 0) {
|
||||
if (!description.can_read()) {
|
||||
auto unblock_flags = Thread::FileBlocker::BlockFlags::None;
|
||||
if (Thread::current()->block<Thread::ReadBlocker>(nullptr, description, unblock_flags).was_interrupted())
|
||||
if (Thread::current()->block<Thread::ReadBlocker>({}, description, unblock_flags).was_interrupted())
|
||||
return KResult(-EINTR);
|
||||
}
|
||||
auto data_buffer = UserOrKernelBuffer::for_kernel_buffer(data);
|
||||
|
@ -621,7 +621,7 @@ KResult Plan9FS::post_message_and_wait_for_a_reply(Message& message)
|
|||
auto result = post_message(message, completion);
|
||||
if (result.is_error())
|
||||
return result;
|
||||
if (Thread::current()->block<Plan9FS::Blocker>(nullptr, *this, message, completion).was_interrupted())
|
||||
if (Thread::current()->block<Plan9FS::Blocker>({}, *this, message, completion).was_interrupted())
|
||||
return KResult(-EINTR);
|
||||
|
||||
if (completion->result.is_error()) {
|
||||
|
|
|
@ -128,7 +128,7 @@ public:
|
|||
{
|
||||
auto impl = KBufferImpl::try_create_with_size(size, access, name, strategy);
|
||||
if (!impl)
|
||||
return nullptr;
|
||||
return {};
|
||||
return adopt_own(*new KBuffer(impl.release_nonnull()));
|
||||
}
|
||||
|
||||
|
@ -136,7 +136,7 @@ public:
|
|||
{
|
||||
auto impl = KBufferImpl::try_create_with_bytes(bytes, access, name, strategy);
|
||||
if (!impl)
|
||||
return nullptr;
|
||||
return {};
|
||||
return adopt_own(*new KBuffer(impl.release_nonnull()));
|
||||
}
|
||||
|
||||
|
|
|
@ -123,7 +123,7 @@ void Lock::lock(Mode mode)
|
|||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
m_lock.store(false, AK::memory_order_release);
|
||||
} while (m_queue.wait_on(nullptr, m_name) == Thread::BlockResult::NotBlocked);
|
||||
} while (m_queue.wait_on({}, m_name) == Thread::BlockResult::NotBlocked);
|
||||
} else {
|
||||
// I don't know *who* is using "m_lock", so just yield.
|
||||
Scheduler::yield_from_critical();
|
||||
|
|
|
@ -457,7 +457,7 @@ void E1000NetworkAdapter::send_raw(ReadonlyBytes payload)
|
|||
sti();
|
||||
break;
|
||||
}
|
||||
m_wait_queue.wait_on(nullptr, "E1000NetworkAdapter");
|
||||
m_wait_queue.wait_on({}, "E1000NetworkAdapter");
|
||||
}
|
||||
#ifdef E1000_DEBUG
|
||||
dbgln("E1000: Sent packet, status is now {:#02x}!", (u8)descriptor.status);
|
||||
|
|
|
@ -255,7 +255,7 @@ KResultOr<size_t> IPv4Socket::receive_byte_buffered(FileDescription& description
|
|||
|
||||
locker.unlock();
|
||||
auto unblocked_flags = Thread::FileDescriptionBlocker::BlockFlags::None;
|
||||
auto res = Thread::current()->block<Thread::ReadBlocker>(nullptr, description, unblocked_flags);
|
||||
auto res = Thread::current()->block<Thread::ReadBlocker>({}, description, unblocked_flags);
|
||||
locker.lock();
|
||||
|
||||
if (!((u32)unblocked_flags & (u32)Thread::FileDescriptionBlocker::BlockFlags::Read)) {
|
||||
|
@ -306,7 +306,7 @@ KResultOr<size_t> IPv4Socket::receive_packet_buffered(FileDescription& descripti
|
|||
|
||||
locker.unlock();
|
||||
auto unblocked_flags = Thread::FileDescriptionBlocker::BlockFlags::None;
|
||||
auto res = Thread::current()->block<Thread::ReadBlocker>(nullptr, description, unblocked_flags);
|
||||
auto res = Thread::current()->block<Thread::ReadBlocker>({}, description, unblocked_flags);
|
||||
locker.lock();
|
||||
|
||||
if (!((u32)unblocked_flags & (u32)Thread::FileDescriptionBlocker::BlockFlags::Read)) {
|
||||
|
|
|
@ -192,7 +192,7 @@ KResult LocalSocket::connect(FileDescription& description, Userspace<const socka
|
|||
}
|
||||
|
||||
auto unblock_flags = Thread::FileDescriptionBlocker::BlockFlags::None;
|
||||
if (Thread::current()->block<Thread::ConnectBlocker>(nullptr, description, unblock_flags).was_interrupted()) {
|
||||
if (Thread::current()->block<Thread::ConnectBlocker>({}, description, unblock_flags).was_interrupted()) {
|
||||
set_connect_side_role(Role::None);
|
||||
return KResult(-EINTR);
|
||||
}
|
||||
|
@ -329,7 +329,7 @@ KResultOr<size_t> LocalSocket::recvfrom(FileDescription& description, UserOrKern
|
|||
}
|
||||
} else if (!can_read(description, 0)) {
|
||||
auto unblock_flags = Thread::FileDescriptionBlocker::BlockFlags::None;
|
||||
if (Thread::current()->block<Thread::ReadBlocker>(nullptr, description, unblock_flags).was_interrupted())
|
||||
if (Thread::current()->block<Thread::ReadBlocker>({}, description, unblock_flags).was_interrupted())
|
||||
return KResult(-EINTR);
|
||||
}
|
||||
if (!has_attached_peer(description) && socket_buffer->is_empty())
|
||||
|
|
|
@ -114,7 +114,7 @@ void NetworkTask_main(void*)
|
|||
for (;;) {
|
||||
size_t packet_size = dequeue_packet(buffer, buffer_size, packet_timestamp);
|
||||
if (!packet_size) {
|
||||
packet_wait_queue.wait_on(nullptr, "NetworkTask");
|
||||
packet_wait_queue.wait_on({}, "NetworkTask");
|
||||
continue;
|
||||
}
|
||||
if (packet_size < sizeof(EthernetFrameHeader)) {
|
||||
|
|
|
@ -230,7 +230,7 @@ RoutingDecision route_to(const IPv4Address& target, const IPv4Address& source, c
|
|||
adapter->send({ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, request);
|
||||
|
||||
Optional<MACAddress> addr;
|
||||
if (!Thread::current()->block<ARPTableBlocker>(nullptr, next_hop_ip, addr).was_interrupted()) {
|
||||
if (!Thread::current()->block<ARPTableBlocker>({}, next_hop_ip, addr).was_interrupted()) {
|
||||
if (addr.has_value()) {
|
||||
#ifdef ROUTING_DEBUG
|
||||
klog() << "Routing: Got ARP response using adapter " << adapter->name().characters() << " for " << next_hop_ip.to_string().characters() << " (" << addr.value().to_string().characters() << ")";
|
||||
|
|
|
@ -400,7 +400,7 @@ KResult TCPSocket::protocol_connect(FileDescription& description, ShouldBlock sh
|
|||
if (should_block == ShouldBlock::Yes) {
|
||||
locker.unlock();
|
||||
auto unblock_flags = Thread::FileBlocker::BlockFlags::None;
|
||||
if (Thread::current()->block<Thread::ConnectBlocker>(nullptr, description, unblock_flags).was_interrupted())
|
||||
if (Thread::current()->block<Thread::ConnectBlocker>({}, description, unblock_flags).was_interrupted())
|
||||
return KResult(-EINTR);
|
||||
locker.lock();
|
||||
ASSERT(setup_state() == SetupState::Completed);
|
||||
|
|
|
@ -89,7 +89,7 @@ OwnPtr<KBuffer> PerformanceEventBuffer::to_json(ProcessID pid, const String& exe
|
|||
{
|
||||
KBufferBuilder builder;
|
||||
if (!to_json(builder, pid, executable_path))
|
||||
return nullptr;
|
||||
return {};
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ KernelRng::KernelRng()
|
|||
void KernelRng::wait_for_entropy()
|
||||
{
|
||||
if (!resource().is_ready()) {
|
||||
m_seed_queue.wait_on(nullptr, "KernelRng");
|
||||
m_seed_queue.wait_on({}, "KernelRng");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ OwnPtr<MBRPartitionTable> MBRPartitionTable::try_to_initialize(const StorageDevi
|
|||
{
|
||||
auto table = make<MBRPartitionTable>(device, start_lba);
|
||||
if (!table->is_valid())
|
||||
return nullptr;
|
||||
return {};
|
||||
return table;
|
||||
}
|
||||
|
||||
|
|
|
@ -90,16 +90,16 @@ OwnPtr<PartitionTable> StorageManagement::try_to_initialize_partition_table(cons
|
|||
if (mbr_table_or_result.error() == PartitionTable::Error::MBRProtective) {
|
||||
auto gpt_table_or_result = GUIDPartitionTable::try_to_initialize(device);
|
||||
if (gpt_table_or_result.is_error())
|
||||
return nullptr;
|
||||
return {};
|
||||
return move(gpt_table_or_result.value());
|
||||
}
|
||||
if (mbr_table_or_result.error() == PartitionTable::Error::ConatinsEBR) {
|
||||
auto ebr_table_or_result = EBRPartitionTable::try_to_initialize(device);
|
||||
if (ebr_table_or_result.is_error())
|
||||
return nullptr;
|
||||
return {};
|
||||
return move(ebr_table_or_result.value());
|
||||
}
|
||||
return nullptr;
|
||||
return {};
|
||||
}
|
||||
|
||||
NonnullRefPtrVector<DiskPartition> StorageManagement::enumerate_disk_partitions() const
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include <AK/LexicalPath.h>
|
||||
#include <AK/ScopeGuard.h>
|
||||
#include <AK/TemporaryChange.h>
|
||||
#include <AK/WeakPtr.h>
|
||||
#include <Kernel/FileSystem/Custody.h>
|
||||
#include <Kernel/FileSystem/FileDescription.h>
|
||||
#include <Kernel/PerformanceEventBuffer.h>
|
||||
|
@ -269,7 +270,7 @@ KResultOr<Process::LoadResult> Process::load_elf_object(FileDescription& object_
|
|||
executable_size,
|
||||
VirtualAddress(elf_image.program_header_table_offset()).offset(load_offset).get(),
|
||||
elf_image.program_header_count(),
|
||||
master_tls_region ? master_tls_region->make_weak_ptr() : nullptr,
|
||||
AK::try_make_weak_ptr(master_tls_region),
|
||||
master_tls_size,
|
||||
master_tls_alignment,
|
||||
stack_region->make_weak_ptr()
|
||||
|
|
|
@ -51,7 +51,7 @@ ssize_t Process::sys$read(int fd, Userspace<u8*> buffer, ssize_t size)
|
|||
if (description->is_blocking()) {
|
||||
if (!description->can_read()) {
|
||||
auto unblock_flags = Thread::FileBlocker::BlockFlags::None;
|
||||
if (Thread::current()->block<Thread::ReadBlocker>(nullptr, *description, unblock_flags).was_interrupted())
|
||||
if (Thread::current()->block<Thread::ReadBlocker>({}, *description, unblock_flags).was_interrupted())
|
||||
return -EINTR;
|
||||
if (!((u32)unblock_flags & (u32)Thread::FileBlocker::BlockFlags::Read))
|
||||
return -EAGAIN;
|
||||
|
|
|
@ -115,7 +115,7 @@ int Process::sys$accept(int accepting_socket_fd, Userspace<sockaddr*> user_addre
|
|||
if (!socket.can_accept()) {
|
||||
if (accepting_socket_description->is_blocking()) {
|
||||
auto unblock_flags = Thread::FileBlocker::BlockFlags::None;
|
||||
if (Thread::current()->block<Thread::AcceptBlocker>(nullptr, *accepting_socket_description, unblock_flags).was_interrupted())
|
||||
if (Thread::current()->block<Thread::AcceptBlocker>({}, *accepting_socket_description, unblock_flags).was_interrupted())
|
||||
return -EINTR;
|
||||
} else {
|
||||
return -EAGAIN;
|
||||
|
|
|
@ -132,7 +132,7 @@ int Process::sys$join_thread(pid_t tid, Userspace<void**> exit_value)
|
|||
// NOTE: pthread_join() cannot be interrupted by signals. Only by death.
|
||||
for (;;) {
|
||||
KResult try_join_result(KSuccess);
|
||||
auto result = current_thread->block<Thread::JoinBlocker>(nullptr, *thread, try_join_result, joinee_exit_value);
|
||||
auto result = current_thread->block<Thread::JoinBlocker>({}, *thread, try_join_result, joinee_exit_value);
|
||||
if (result == Thread::BlockResult::NotBlocked) {
|
||||
if (try_join_result.is_error())
|
||||
return try_join_result.error();
|
||||
|
|
|
@ -42,7 +42,7 @@ KResultOr<siginfo_t> Process::do_waitid(idtype_t idtype, int id, int options)
|
|||
}
|
||||
|
||||
KResultOr<siginfo_t> result = KResult(KSuccess);
|
||||
if (Thread::current()->block<Thread::WaitBlocker>(nullptr, options, idtype, id, result).was_interrupted())
|
||||
if (Thread::current()->block<Thread::WaitBlocker>({}, options, idtype, id, result).was_interrupted())
|
||||
return KResult(-EINTR);
|
||||
ASSERT(!result.is_error() || (options & WNOHANG) || result.error() != KSuccess);
|
||||
return result;
|
||||
|
|
|
@ -97,7 +97,7 @@ ssize_t Process::do_write(FileDescription& description, const UserOrKernelBuffer
|
|||
return total_nwritten;
|
||||
}
|
||||
auto unblock_flags = Thread::FileBlocker::BlockFlags::None;
|
||||
if (Thread::current()->block<Thread::WriteBlocker>(nullptr, description, unblock_flags).was_interrupted()) {
|
||||
if (Thread::current()->block<Thread::WriteBlocker>({}, description, unblock_flags).was_interrupted()) {
|
||||
if (total_nwritten == 0)
|
||||
return -EINTR;
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ void FinalizerTask::spawn()
|
|||
finalizer_thread, "FinalizerTask", [](void*) {
|
||||
Thread::current()->set_priority(THREAD_PRIORITY_LOW);
|
||||
for (;;) {
|
||||
g_finalizer_wait_queue->wait_on(nullptr, "FinalizerTask");
|
||||
g_finalizer_wait_queue->wait_on({}, "FinalizerTask");
|
||||
|
||||
if (g_finalizer_has_work.exchange(false, AK::MemoryOrder::memory_order_acq_rel) == true)
|
||||
Thread::finalize_dying_threads();
|
||||
|
|
|
@ -316,13 +316,13 @@ void Thread::relock_process(LockMode previous_locked, u32 lock_count_to_restore)
|
|||
auto Thread::sleep(clockid_t clock_id, const timespec& duration, timespec* remaining_time) -> BlockResult
|
||||
{
|
||||
ASSERT(state() == Thread::Running);
|
||||
return Thread::current()->block<Thread::SleepBlocker>(nullptr, Thread::BlockTimeout(false, &duration, nullptr, clock_id), remaining_time);
|
||||
return Thread::current()->block<Thread::SleepBlocker>({}, Thread::BlockTimeout(false, &duration, nullptr, clock_id), remaining_time);
|
||||
}
|
||||
|
||||
auto Thread::sleep_until(clockid_t clock_id, const timespec& deadline) -> BlockResult
|
||||
{
|
||||
ASSERT(state() == Thread::Running);
|
||||
return Thread::current()->block<Thread::SleepBlocker>(nullptr, Thread::BlockTimeout(true, &deadline, nullptr, clock_id));
|
||||
return Thread::current()->block<Thread::SleepBlocker>({}, Thread::BlockTimeout(true, &deadline, nullptr, clock_id));
|
||||
}
|
||||
|
||||
const char* Thread::state_string() const
|
||||
|
|
|
@ -207,10 +207,6 @@ public:
|
|||
: m_infinite(true)
|
||||
{
|
||||
}
|
||||
BlockTimeout(std::nullptr_t)
|
||||
: m_infinite(true)
|
||||
{
|
||||
}
|
||||
explicit BlockTimeout(bool is_absolute, const timeval* time, const timespec* start_time = nullptr, clockid_t clock_id = CLOCK_MONOTONIC_COARSE)
|
||||
: m_clock_id(clock_id)
|
||||
, m_infinite(!time)
|
||||
|
|
|
@ -385,7 +385,7 @@ OwnPtr<Region> MemoryManager::allocate_contiguous_kernel_region(size_t size, con
|
|||
ScopedSpinLock lock(s_mm_lock);
|
||||
auto range = kernel_page_directory().range_allocator().allocate_anywhere(size);
|
||||
if (!range.is_valid())
|
||||
return nullptr;
|
||||
return {};
|
||||
auto vmobject = ContiguousVMObject::create_with_size(size);
|
||||
return allocate_kernel_region_with_vmobject(range, vmobject, name, access, user_accessible, cacheable);
|
||||
}
|
||||
|
@ -396,10 +396,10 @@ OwnPtr<Region> MemoryManager::allocate_kernel_region(size_t size, const StringVi
|
|||
ScopedSpinLock lock(s_mm_lock);
|
||||
auto range = kernel_page_directory().range_allocator().allocate_anywhere(size);
|
||||
if (!range.is_valid())
|
||||
return nullptr;
|
||||
return {};
|
||||
auto vmobject = AnonymousVMObject::create_with_size(size, strategy);
|
||||
if (!vmobject)
|
||||
return nullptr;
|
||||
return {};
|
||||
return allocate_kernel_region_with_vmobject(range, vmobject.release_nonnull(), name, access, user_accessible, cacheable);
|
||||
}
|
||||
|
||||
|
@ -409,10 +409,10 @@ OwnPtr<Region> MemoryManager::allocate_kernel_region(PhysicalAddress paddr, size
|
|||
ScopedSpinLock lock(s_mm_lock);
|
||||
auto range = kernel_page_directory().range_allocator().allocate_anywhere(size);
|
||||
if (!range.is_valid())
|
||||
return nullptr;
|
||||
return {};
|
||||
auto vmobject = AnonymousVMObject::create_for_physical_range(paddr, size);
|
||||
if (!vmobject)
|
||||
return nullptr;
|
||||
return {};
|
||||
return allocate_kernel_region_with_vmobject(range, *vmobject, name, access, user_accessible, cacheable);
|
||||
}
|
||||
|
||||
|
@ -422,10 +422,10 @@ OwnPtr<Region> MemoryManager::allocate_kernel_region_identity(PhysicalAddress pa
|
|||
ScopedSpinLock lock(s_mm_lock);
|
||||
auto range = kernel_page_directory().identity_range_allocator().allocate_specific(VirtualAddress(paddr.get()), size);
|
||||
if (!range.is_valid())
|
||||
return nullptr;
|
||||
return {};
|
||||
auto vmobject = AnonymousVMObject::create_for_physical_range(paddr, size);
|
||||
if (!vmobject)
|
||||
return nullptr;
|
||||
return {};
|
||||
return allocate_kernel_region_with_vmobject(range, *vmobject, name, access, user_accessible, cacheable);
|
||||
}
|
||||
|
||||
|
@ -453,7 +453,7 @@ OwnPtr<Region> MemoryManager::allocate_kernel_region_with_vmobject(VMObject& vmo
|
|||
ScopedSpinLock lock(s_mm_lock);
|
||||
auto range = kernel_page_directory().range_allocator().allocate_anywhere(size);
|
||||
if (!range.is_valid())
|
||||
return nullptr;
|
||||
return {};
|
||||
return allocate_kernel_region_with_vmobject(range, vmobject, name, access, user_accessible, cacheable);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue