1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 06:47:34 +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:
Lenny Maiorani 2021-01-10 16:29:28 -07:00 committed by Andreas Kling
parent 9dc44bf8c4
commit e6f907a155
105 changed files with 300 additions and 244 deletions

View file

@ -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()

View file

@ -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;

View file

@ -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;

View file

@ -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();

View file

@ -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;

View file

@ -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;
}