ams: replace most remaining operator & with std::addressof

This commit is contained in:
Michael Scire
2021-10-09 14:49:53 -07:00
parent ce8aacef21
commit 1ab0bd1765
109 changed files with 587 additions and 586 deletions

View File

@@ -63,7 +63,7 @@ namespace ams::cfg {
static_assert(util::is_pod<OverrideStatus>::value, "util::is_pod<OverrideStatus>::value");
constexpr inline bool operator==(const OverrideStatus &lhs, const OverrideStatus &rhs) {
return std::memcmp(&lhs, &rhs, sizeof(lhs)) == 0;
return std::memcmp(std::addressof(lhs), std::addressof(rhs), sizeof(lhs)) == 0;
}
constexpr inline bool operator!=(const OverrideStatus &lhs, const OverrideStatus &rhs) {

View File

@@ -169,7 +169,7 @@ namespace ams::fs {
R_TRY(GetPathForServiceObject(std::addressof(sf_path), path));
FsFile f;
R_TRY(fsFsOpenFile(std::addressof(this->base_fs), sf_path.str, mode, &f));
R_TRY(fsFsOpenFile(std::addressof(this->base_fs), sf_path.str, mode, std::addressof(f)));
auto file = std::make_unique<RemoteFile>(f);
R_UNLESS(file != nullptr, fs::ResultAllocationFailureInNew());
@@ -183,7 +183,7 @@ namespace ams::fs {
R_TRY(GetPathForServiceObject(std::addressof(sf_path), path));
FsDir d;
R_TRY(fsFsOpenDirectory(std::addressof(this->base_fs), sf_path.str, mode, &d));
R_TRY(fsFsOpenDirectory(std::addressof(this->base_fs), sf_path.str, mode, std::addressof(d)));
auto dir = std::make_unique<RemoteDirectory>(d);
R_UNLESS(dir != nullptr, fs::ResultAllocationFailureInNew());

View File

@@ -29,7 +29,7 @@ namespace ams::fssystem {
Result IterateDirectoryRecursivelyImpl(fs::fsa::IFileSystem *fs, char *work_path, size_t work_path_size, fs::DirectoryEntry *dir_ent, OnEnterDir on_enter_dir, OnExitDir on_exit_dir, OnFile on_file) {
/* Open the directory. */
std::unique_ptr<fs::fsa::IDirectory> dir;
R_TRY(fs->OpenDirectory(&dir, work_path, fs::OpenDirectoryMode_All));
R_TRY(fs->OpenDirectory(std::addressof(dir), work_path, fs::OpenDirectoryMode_All));
const size_t parent_len = strnlen(work_path, work_path_size - 1);
@@ -37,7 +37,7 @@ namespace ams::fssystem {
while (true) {
/* Read a single entry. */
s64 read_count = 0;
R_TRY(dir->Read(&read_count, dir_ent, 1));
R_TRY(dir->Read(std::addressof(read_count), dir_ent, 1));
/* If we're out of entries, we're done. */
if (read_count == 0) {
@@ -106,7 +106,7 @@ namespace ams::fssystem {
Result IterateDirectoryRecursively(fs::fsa::IFileSystem *fs, const char *root_path, OnEnterDir on_enter_dir, OnExitDir on_exit_dir, OnFile on_file) {
fs::DirectoryEntry dir_entry = {};
char work_path[fs::EntryNameLengthMax + 1] = {};
return IterateDirectoryRecursively(fs, root_path, work_path, sizeof(work_path), &dir_entry, on_enter_dir, on_exit_dir, on_file);
return IterateDirectoryRecursively(fs, root_path, work_path, sizeof(work_path), std::addressof(dir_entry), on_enter_dir, on_exit_dir, on_file);
}
template<typename OnEnterDir, typename OnExitDir, typename OnFile>

View File

@@ -245,8 +245,8 @@ namespace ams::kvdb {
static Result ValidateExistingCache(const char *dir) {
/* Check for existence. */
bool has_lru = false, has_kvs = false;
R_TRY(FileExists(&has_lru, GetLeastRecentlyUsedListPath(dir)));
R_TRY(DirectoryExists(&has_kvs, GetFileKeyValueStorePath(dir)));
R_TRY(FileExists(std::addressof(has_lru), GetLeastRecentlyUsedListPath(dir)));
R_TRY(DirectoryExists(std::addressof(has_kvs), GetFileKeyValueStorePath(dir)));
/* If neither exists, CreateNewCache was never called. */
R_UNLESS(has_lru || has_kvs, kvdb::ResultNotCreated());

View File

@@ -84,38 +84,38 @@ namespace ams::kvdb {
template<typename Key>
Result Get(size_t *out_size, void *out_value, size_t max_out_size, const Key &key) {
static_assert(util::is_pod<Key>::value && sizeof(Key) <= MaxKeySize, "Invalid FileKeyValueStore Key!");
return this->Get(out_size, out_value, max_out_size, &key, sizeof(Key));
return this->Get(out_size, out_value, max_out_size, std::addressof(key), sizeof(Key));
}
template<typename Key, typename Value>
Result Get(Value *out_value, const Key &key) {
static_assert(util::is_pod<Value>::value && !std::is_pointer<Value>::value, "Invalid FileKeyValueStore Value!");
size_t size = 0;
R_TRY(this->Get(&size, out_value, sizeof(Value), key));
R_TRY(this->Get(std::addressof(size), out_value, sizeof(Value), key));
AMS_ABORT_UNLESS(size >= sizeof(Value));
return ResultSuccess();
}
template<typename Key>
Result GetSize(size_t *out_size, const Key &key) {
return this->GetSize(out_size, &key, sizeof(Key));
return this->GetSize(out_size, std::addressof(key), sizeof(Key));
}
template<typename Key>
Result Set(const Key &key, const void *value, size_t value_size) {
static_assert(util::is_pod<Key>::value && sizeof(Key) <= MaxKeySize, "Invalid FileKeyValueStore Key!");
return this->Set(&key, sizeof(Key), value, value_size);
return this->Set(std::addressof(key), sizeof(Key), value, value_size);
}
template<typename Key, typename Value>
Result Set(const Key &key, const Value &value) {
static_assert(util::is_pod<Value>::value && !std::is_pointer<Value>::value, "Invalid FileKeyValueStore Value!");
return this->Set(key, &value, sizeof(Value));
return this->Set(key, std::addressof(value), sizeof(Value));
}
template<typename Key>
Result Remove(const Key &key) {
return this->Remove(&key, sizeof(Key));
return this->Remove(std::addressof(key), sizeof(Key));
}
};

View File

@@ -306,7 +306,7 @@ namespace ams::kvdb {
/* Try to read the archive -- note, path not found is a success condition. */
/* This is because no archive file = no entries, so we're in the right state. */
AutoBuffer buffer;
R_TRY_CATCH(this->ReadArchiveFile(&buffer)) {
R_TRY_CATCH(this->ReadArchiveFile(std::addressof(buffer))) {
R_CONVERT(fs::ResultPathNotFound, ResultSuccess());
} R_END_TRY_CATCH;
@@ -315,12 +315,12 @@ namespace ams::kvdb {
ArchiveReader reader(buffer);
size_t entry_count = 0;
R_TRY(reader.ReadEntryCount(&entry_count));
R_TRY(reader.ReadEntryCount(std::addressof(entry_count)));
for (size_t i = 0; i < entry_count; i++) {
/* Get size of key/value. */
size_t key_size = 0, value_size = 0;
R_TRY(reader.GetEntrySize(&key_size, &value_size));
R_TRY(reader.GetEntrySize(std::addressof(key_size), std::addressof(value_size)));
/* Allocate memory for value. */
void *new_value = this->memory_resource->Allocate(value_size);
@@ -329,7 +329,7 @@ namespace ams::kvdb {
/* Read key and value. */
Key key;
R_TRY(reader.ReadEntry(&key, sizeof(key), new_value, value_size));
R_TRY(reader.ReadEntry(std::addressof(key), sizeof(key), new_value, value_size));
R_TRY(this->index.AddUnsafe(key, new_value, value_size));
/* We succeeded, so cancel the value guard to prevent deallocation. */
@@ -351,7 +351,7 @@ namespace ams::kvdb {
writer.WriteHeader(this->GetCount());
for (const auto &it : this->index) {
const auto &key = it.GetKey();
writer.WriteEntry(&key, sizeof(Key), it.GetValuePointer(), it.GetValueSize());
writer.WriteEntry(std::addressof(key), sizeof(Key), it.GetValuePointer(), it.GetValueSize());
}
}
@@ -367,7 +367,7 @@ namespace ams::kvdb {
Result Set(const Key &key, const Value &value) {
/* Only allow setting pod. */
static_assert(util::is_pod<Value>::value, "KeyValueStore Values must be pod");
return this->Set(key, &value, sizeof(Value));
return this->Set(key, std::addressof(value), sizeof(Value));
}
template<typename Value>

View File

@@ -50,11 +50,11 @@ namespace ams::ncm {
void Store(ContentId content_id, ncm::RightsId rights_id) {
std::scoped_lock lk(this->mutex);
Entry *eviction_candidate = &this->entries[0];
Entry *eviction_candidate = std::addressof(this->entries[0]);
/* Find a suitable existing entry to store our new one at. */
for (size_t i = 1; i < MaxEntries; i++) {
Entry *entry = &this->entries[i];
Entry *entry = std::addressof(this->entries[i]);
/* Change eviction candidates if the uuid already matches ours, or if the uuid doesn't already match and the last_accessed count is lower */
if (content_id == entry->uuid || (content_id != eviction_candidate->uuid && entry->last_accessed < eviction_candidate->last_accessed)) {
@@ -73,7 +73,7 @@ namespace ams::ncm {
/* Attempt to locate the content id in the cache. */
for (size_t i = 0; i < MaxEntries; i++) {
Entry *entry = &this->entries[i];
Entry *entry = std::addressof(this->entries[i]);
if (entry->last_accessed != 1 && content_id == entry->uuid) {
entry->last_accessed = this->counter;

View File

@@ -26,4 +26,4 @@
#include <stratosphere/rapidjson/rapidjson.h>
#include <stratosphere/rapidjson/encodings.h>
#include <stratosphere/rapidjson/reader.h>
#include <stratosphere/rapidjson/reader.h>

View File

@@ -190,7 +190,7 @@ namespace ams::ro {
}
const ModuleId *GetModuleId() const {
return &this->module_id;
return std::addressof(this->module_id);
}
};
static_assert(sizeof(NroHeader) == 0x80, "NroHeader definition!");

View File

@@ -116,7 +116,7 @@ namespace ams::sf::cmif {
using DispatchTableType = DomainServiceObjectDispatchTable;
static constexpr ProcessHandlerType ProcessHandlerImpl = &impl::ServiceDispatchTableBase::ProcessMessage<DispatchTableType>;
static constexpr inline ServiceDispatchMeta Meta{&DomainServiceObject::s_CmifServiceDispatchTable, ProcessHandlerImpl};
static constexpr inline ServiceDispatchMeta Meta{std::addressof(DomainServiceObject::s_CmifServiceDispatchTable), ProcessHandlerImpl};
};
template<>
@@ -127,7 +127,7 @@ namespace ams::sf::cmif {
using DispatchTableType = DomainServiceObjectDispatchTable;
static constexpr ProcessHandlerType ProcessHandlerImpl = &impl::ServiceDispatchTableBase::ProcessMessageForMitm<DispatchTableType>;
static constexpr inline ServiceDispatchMeta Meta{&DomainServiceObject::s_CmifServiceDispatchTable, ProcessHandlerImpl};
static constexpr inline ServiceDispatchMeta Meta{std::addressof(DomainServiceObject::s_CmifServiceDispatchTable), ProcessHandlerImpl};
};

View File

@@ -136,7 +136,7 @@ namespace ams::sf::cmif {
static constexpr ProcessHandlerType ProcessHandlerImpl = sf::IsMitmServiceObject<T> ? (&impl::ServiceDispatchTableBase::ProcessMessageForMitm<DispatchTableType>)
: (&impl::ServiceDispatchTableBase::ProcessMessage<DispatchTableType>);
static constexpr inline ServiceDispatchMeta Meta{&DispatchTable, ProcessHandlerImpl};
static constexpr inline ServiceDispatchMeta Meta{std::addressof(DispatchTable), ProcessHandlerImpl};
};
template<>
@@ -151,7 +151,7 @@ namespace ams::sf::cmif {
template<typename T>
constexpr ALWAYS_INLINE const ServiceDispatchMeta *GetServiceDispatchMeta() {
return &ServiceDispatchTraits<T>::Meta;
return std::addressof(ServiceDispatchTraits<T>::Meta);
}
}

View File

@@ -760,7 +760,7 @@ namespace ams::sf::impl {
template<size_t Index, typename Interface>
Out<SharedPointer<Interface>> GetOutObject() {
auto sp = std::construct_at(GetOutObjectSharedPointer<Index, Interface>());
return Out<SharedPointer<Interface>>(sp, this->out_object_ids + Index);
return Out<SharedPointer<Interface>>(sp, std::addressof(this->out_object_ids[Index]));
}
template<size_t Index, typename Interface>
@@ -869,7 +869,7 @@ namespace ams::sf::impl {
return;
}
os::NativeHandle server_handle, client_handle;
R_ABORT_UNLESS(sf::hipc::CreateSession(&server_handle, &client_handle));
R_ABORT_UNLESS(sf::hipc::CreateSession(std::addressof(server_handle), std::addressof(client_handle)));
R_ABORT_UNLESS(manager->RegisterSession(server_handle, std::move(object)));
response.move_handles[Index] = client_handle;
}
@@ -1137,10 +1137,10 @@ namespace ams::sf::impl {
ImplProcessorType impl_processor;
if (ctx.processor == nullptr) {
/* In the non-domain case, this is our only processor. */
ctx.processor = &impl_processor;
ctx.processor = std::addressof(impl_processor);
} else {
/* In the domain case, we already have a processor, so we should give it a pointer to our template implementation. */
ctx.processor->SetImplementationProcessor(&impl_processor);
ctx.processor->SetImplementationProcessor(std::addressof(impl_processor));
}
/* Validate the metadata has the expected counts. */

View File

@@ -50,7 +50,7 @@ namespace ams::sm {
static_assert(alignof(ServiceName) == 1, "ServiceName definition!");
inline bool operator==(const ServiceName &lhs, const ServiceName &rhs) {
return std::memcmp(&lhs, &rhs, sizeof(ServiceName)) == 0;
return std::memcmp(std::addressof(lhs), std::addressof(rhs), sizeof(ServiceName)) == 0;
}
inline bool operator!=(const ServiceName &lhs, const ServiceName &rhs) {