From cb09ea0f0174162a85f47fdb8446b397c3c57e20 Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Tue, 2 Nov 2021 17:23:19 -0400 Subject: [PATCH] general: Remove MakeResult helpers This is made obsolete by the presence of implicit constructors. --- src/core/file_sys/romfs_factory.cpp | 10 +++---- src/core/file_sys/savedata_factory.cpp | 4 +-- src/core/file_sys/sdmc_factory.cpp | 2 +- src/core/hle/kernel/k_page_table.cpp | 4 +-- src/core/hle/result.h | 20 +------------- .../hle/service/filesystem/filesystem.cpp | 21 +++++++-------- src/core/hle/service/glue/glue_manager.cpp | 4 +-- src/core/hle/service/ldr/ldr.cpp | 4 +-- src/core/hle/service/mii/mii_manager.cpp | 4 +-- src/core/hle/service/ns/ns.cpp | 4 +-- src/core/hle/service/sm/sm.cpp | 4 +-- src/core/hle/service/spl/spl_module.cpp | 26 +++++++++---------- src/core/hle/service/vi/vi.cpp | 10 +++---- 13 files changed, 48 insertions(+), 69 deletions(-) diff --git a/src/core/file_sys/romfs_factory.cpp b/src/core/file_sys/romfs_factory.cpp index 638c6cea83..3d9ce863b9 100644 --- a/src/core/file_sys/romfs_factory.cpp +++ b/src/core/file_sys/romfs_factory.cpp @@ -39,13 +39,12 @@ void RomFSFactory::SetPackedUpdate(VirtualFile update_raw_file) { ResultVal RomFSFactory::OpenCurrentProcess(u64 current_process_title_id) const { if (!updatable) { - return MakeResult(file); + return file; } const PatchManager patch_manager{current_process_title_id, filesystem_controller, content_provider}; - return MakeResult( - patch_manager.PatchRomFS(file, ivfc_offset, ContentRecordType::Program, update_raw)); + return patch_manager.PatchRomFS(file, ivfc_offset, ContentRecordType::Program, update_raw); } ResultVal RomFSFactory::OpenPatchedRomFS(u64 title_id, ContentRecordType type) const { @@ -58,8 +57,7 @@ ResultVal RomFSFactory::OpenPatchedRomFS(u64 title_id, ContentRecor const PatchManager patch_manager{title_id, filesystem_controller, content_provider}; - return MakeResult( - patch_manager.PatchRomFS(nca->GetRomFS(), nca->GetBaseIVFCOffset(), type)); + return patch_manager.PatchRomFS(nca->GetRomFS(), nca->GetBaseIVFCOffset(), type); } ResultVal RomFSFactory::OpenPatchedRomFSWithProgramIndex( @@ -83,7 +81,7 @@ ResultVal RomFSFactory::Open(u64 title_id, StorageId storage, return ResultUnknown; } - return MakeResult(romfs); + return romfs; } std::shared_ptr RomFSFactory::GetEntry(u64 title_id, StorageId storage, diff --git a/src/core/file_sys/savedata_factory.cpp b/src/core/file_sys/savedata_factory.cpp index b5254dd75f..0c8ec4ba29 100644 --- a/src/core/file_sys/savedata_factory.cpp +++ b/src/core/file_sys/savedata_factory.cpp @@ -94,7 +94,7 @@ ResultVal SaveDataFactory::Create(SaveDataSpaceId space, return ResultUnknown; } - return MakeResult(std::move(out)); + return out; } ResultVal SaveDataFactory::Open(SaveDataSpaceId space, @@ -115,7 +115,7 @@ ResultVal SaveDataFactory::Open(SaveDataSpaceId space, return ResultUnknown; } - return MakeResult(std::move(out)); + return out; } VirtualDir SaveDataFactory::GetSaveDataSpaceDirectory(SaveDataSpaceId space) const { diff --git a/src/core/file_sys/sdmc_factory.cpp b/src/core/file_sys/sdmc_factory.cpp index e5c72cd4d8..c0e13e56fd 100644 --- a/src/core/file_sys/sdmc_factory.cpp +++ b/src/core/file_sys/sdmc_factory.cpp @@ -25,7 +25,7 @@ SDMCFactory::SDMCFactory(VirtualDir sd_dir_, VirtualDir sd_mod_dir_) SDMCFactory::~SDMCFactory() = default; ResultVal SDMCFactory::Open() const { - return MakeResult(sd_dir); + return sd_dir; } VirtualDir SDMCFactory::GetSDMCModificationLoadRoot(u64 title_id) const { diff --git a/src/core/hle/kernel/k_page_table.cpp b/src/core/hle/kernel/k_page_table.cpp index 5e0b620c27..526b872413 100644 --- a/src/core/hle/kernel/k_page_table.cpp +++ b/src/core/hle/kernel/k_page_table.cpp @@ -859,7 +859,7 @@ ResultVal KPageTable::SetHeapSize(std::size_t size) { current_heap_addr = heap_region_start + size; } - return MakeResult(heap_region_start); + return heap_region_start; } ResultVal KPageTable::AllocateAndMapMemory(std::size_t needed_num_pages, std::size_t align, @@ -893,7 +893,7 @@ ResultVal KPageTable::AllocateAndMapMemory(std::size_t needed_num_pages, block_manager->Update(addr, needed_num_pages, state, perm); - return MakeResult(addr); + return addr; } ResultCode KPageTable::LockForDeviceAddressSpace(VAddr addr, std::size_t size) { diff --git a/src/core/hle/result.h b/src/core/hle/result.h index a1917d32bc..3807b9aa82 100644 --- a/src/core/hle/result.h +++ b/src/core/hle/result.h @@ -168,7 +168,7 @@ constexpr ResultCode ResultUnknown(UINT32_MAX); * return ResultCode{ErrorModule::Common, 1}; * } else { * // Frobnicated! Give caller a cookie - * return MakeResult(42); + * return 42; * } * } * \endcode @@ -279,24 +279,6 @@ private: Common::Expected expected; }; -/** - * This function is a helper used to construct `ResultVal`s. It receives the arguments to construct - * `T` with and creates a `ResultVal` that contains the constructed value. - */ -template -[[nodiscard]] ResultVal MakeResult(Args&&... args) { - return ResultVal{std::forward(args)...}; -} - -/** - * Deducible overload of MakeResult, allowing the template parameter to be ommited if you're just - * copy or move constructing. - */ -template -[[nodiscard]] ResultVal> MakeResult(T&& val) { - return ResultVal>{std::forward(val)}; -} - /** * Check for the success of `source` (which must evaluate to a ResultVal). If it succeeds, unwraps * the contained value and assigns it to `target`, which can be either an l-value expression or a diff --git a/src/core/hle/service/filesystem/filesystem.cpp b/src/core/hle/service/filesystem/filesystem.cpp index f8f9e32f7d..42e468ce27 100644 --- a/src/core/hle/service/filesystem/filesystem.cpp +++ b/src/core/hle/service/filesystem/filesystem.cpp @@ -226,11 +226,10 @@ ResultVal VfsDirectoryServiceWrapper::OpenFile(const std:: } if (mode == FileSys::Mode::Append) { - return MakeResult( - std::make_shared(file, 0, file->GetSize())); + return std::make_shared(file, 0, file->GetSize()); } - return MakeResult(file); + return file; } ResultVal VfsDirectoryServiceWrapper::OpenDirectory(const std::string& path_) { @@ -240,7 +239,7 @@ ResultVal VfsDirectoryServiceWrapper::OpenDirectory(const s // TODO(DarkLordZach): Find a better error code for this return FileSys::ERROR_PATH_NOT_FOUND; } - return MakeResult(dir); + return dir; } ResultVal VfsDirectoryServiceWrapper::GetEntryType( @@ -252,12 +251,12 @@ ResultVal VfsDirectoryServiceWrapper::GetEntryType( auto filename = Common::FS::GetFilename(path); // TODO(Subv): Some games use the '/' path, find out what this means. if (filename.empty()) - return MakeResult(FileSys::EntryType::Directory); + return FileSys::EntryType::Directory; if (dir->GetFile(filename) != nullptr) - return MakeResult(FileSys::EntryType::File); + return FileSys::EntryType::File; if (dir->GetSubdirectory(filename) != nullptr) - return MakeResult(FileSys::EntryType::Directory); + return FileSys::EntryType::Directory; return FileSys::ERROR_PATH_NOT_FOUND; } @@ -270,7 +269,7 @@ ResultVal VfsDirectoryServiceWrapper::GetFileTimeStam if (GetEntryType(path).Failed()) { return FileSys::ERROR_PATH_NOT_FOUND; } - return MakeResult(dir->GetFileTimeStamp(Common::FS::GetFilename(path))); + return dir->GetFileTimeStamp(Common::FS::GetFilename(path)); } FileSystemController::FileSystemController(Core::System& system_) : system{system_} {} @@ -395,7 +394,7 @@ ResultVal FileSystemController::OpenSaveDataSpace( return FileSys::ERROR_ENTITY_NOT_FOUND; } - return MakeResult(save_data_factory->GetSaveDataSpaceDirectory(space)); + return save_data_factory->GetSaveDataSpaceDirectory(space); } ResultVal FileSystemController::OpenSDMC() const { @@ -421,7 +420,7 @@ ResultVal FileSystemController::OpenBISPartition( return FileSys::ERROR_INVALID_ARGUMENT; } - return MakeResult(std::move(part)); + return part; } ResultVal FileSystemController::OpenBISPartitionStorage( @@ -437,7 +436,7 @@ ResultVal FileSystemController::OpenBISPartitionStorage( return FileSys::ERROR_INVALID_ARGUMENT; } - return MakeResult(std::move(part)); + return part; } u64 FileSystemController::GetFreeSpaceSize(FileSys::StorageId id) const { diff --git a/src/core/hle/service/glue/glue_manager.cpp b/src/core/hle/service/glue/glue_manager.cpp index aa9d48c0ce..48e133b488 100644 --- a/src/core/hle/service/glue/glue_manager.cpp +++ b/src/core/hle/service/glue/glue_manager.cpp @@ -26,7 +26,7 @@ ResultVal ARPManager::GetLaunchProperty(u64 title_id) return ERR_NOT_REGISTERED; } - return MakeResult(iter->second.launch); + return iter->second.launch; } ResultVal> ARPManager::GetControlProperty(u64 title_id) const { @@ -39,7 +39,7 @@ ResultVal> ARPManager::GetControlProperty(u64 title_id) const { return ERR_NOT_REGISTERED; } - return MakeResult>(iter->second.control); + return iter->second.control; } ResultCode ARPManager::Register(u64 title_id, ApplicationLaunchProperty launch, diff --git a/src/core/hle/service/ldr/ldr.cpp b/src/core/hle/service/ldr/ldr.cpp index 24b7e4435d..e4b97c1f6a 100644 --- a/src/core/hle/service/ldr/ldr.cpp +++ b/src/core/hle/service/ldr/ldr.cpp @@ -335,7 +335,7 @@ public: CASCADE_CODE(result); if (ValidateRegionForMap(page_table, addr, size)) { - return MakeResult(addr); + return addr; } } @@ -371,7 +371,7 @@ public: } if (ValidateRegionForMap(page_table, addr, size)) { - return MakeResult(addr); + return addr; } } diff --git a/src/core/hle/service/mii/mii_manager.cpp b/src/core/hle/service/mii/mii_manager.cpp index 4fef2aea48..ca4ed35bb1 100644 --- a/src/core/hle/service/mii/mii_manager.cpp +++ b/src/core/hle/service/mii/mii_manager.cpp @@ -443,14 +443,14 @@ ResultVal> MiiManager::GetDefault(SourceFlag source_ std::vector result; if ((source_flag & SourceFlag::Default) == SourceFlag::None) { - return MakeResult(std::move(result)); + return result; } for (std::size_t index = BaseMiiCount; index < DefaultMiiCount; index++) { result.emplace_back(BuildDefault(index), Source::Default); } - return MakeResult(std::move(result)); + return result; } ResultCode MiiManager::GetIndex([[maybe_unused]] const MiiInfo& info, u32& index) { diff --git a/src/core/hle/service/ns/ns.cpp b/src/core/hle/service/ns/ns.cpp index 931b48f728..64ffc8572e 100644 --- a/src/core/hle/service/ns/ns.cpp +++ b/src/core/hle/service/ns/ns.cpp @@ -414,7 +414,7 @@ ResultVal IApplicationManagerInterface::GetApplicationDesiredLanguage( for (const auto lang : *priority_list) { const auto supported_flag = GetSupportedLanguageFlag(lang); if (supported_languages == 0 || (supported_languages & supported_flag) == supported_flag) { - return MakeResult(static_cast(lang)); + return static_cast(lang); } } @@ -448,7 +448,7 @@ ResultVal IApplicationManagerInterface::ConvertApplicationLanguageToLanguag return ERR_APPLICATION_LANGUAGE_NOT_FOUND; } - return MakeResult(static_cast(*language_code)); + return static_cast(*language_code); } IApplicationVersionInterface::IApplicationVersionInterface(Core::System& system_) diff --git a/src/core/hle/service/sm/sm.cpp b/src/core/hle/service/sm/sm.cpp index ae4dc4a752..41abb146cf 100644 --- a/src/core/hle/service/sm/sm.cpp +++ b/src/core/hle/service/sm/sm.cpp @@ -87,7 +87,7 @@ ResultVal ServiceManager::GetServicePort(const std::string& name auto handler = it->second; port->GetServerPort().SetSessionHandler(std::move(handler)); - return MakeResult(port); + return port; } /** @@ -165,7 +165,7 @@ ResultVal SM::GetServiceImpl(Kernel::HLERequestContext& LOG_DEBUG(Service_SM, "called service={} -> session={}", name, session->GetId()); - return MakeResult(session); + return session; } void SM::RegisterService(Kernel::HLERequestContext& ctx) { diff --git a/src/core/hle/service/spl/spl_module.cpp b/src/core/hle/service/spl/spl_module.cpp index ed4c06260d..10f7d14616 100644 --- a/src/core/hle/service/spl/spl_module.cpp +++ b/src/core/hle/service/spl/spl_module.cpp @@ -120,40 +120,40 @@ ResultVal Module::Interface::GetConfigImpl(ConfigItem config_item) const { return ResultSecureMonitorNotImplemented; case ConfigItem::ExosphereApiVersion: // Get information about the current exosphere version. - return MakeResult((u64{HLE::ApiVersion::ATMOSPHERE_RELEASE_VERSION_MAJOR} << 56) | - (u64{HLE::ApiVersion::ATMOSPHERE_RELEASE_VERSION_MINOR} << 48) | - (u64{HLE::ApiVersion::ATMOSPHERE_RELEASE_VERSION_MICRO} << 40) | - (static_cast(HLE::ApiVersion::GetTargetFirmware()))); + return (u64{HLE::ApiVersion::ATMOSPHERE_RELEASE_VERSION_MAJOR} << 56) | + (u64{HLE::ApiVersion::ATMOSPHERE_RELEASE_VERSION_MINOR} << 48) | + (u64{HLE::ApiVersion::ATMOSPHERE_RELEASE_VERSION_MICRO} << 40) | + (static_cast(HLE::ApiVersion::GetTargetFirmware())); case ConfigItem::ExosphereNeedsReboot: // We are executing, so we aren't in the process of rebooting. - return MakeResult(u64{0}); + return u64{0}; case ConfigItem::ExosphereNeedsShutdown: // We are executing, so we aren't in the process of shutting down. - return MakeResult(u64{0}); + return u64{0}; case ConfigItem::ExosphereGitCommitHash: // Get information about the current exosphere git commit hash. - return MakeResult(u64{0}); + return u64{0}; case ConfigItem::ExosphereHasRcmBugPatch: // Get information about whether this unit has the RCM bug patched. - return MakeResult(u64{0}); + return u64{0}; case ConfigItem::ExosphereBlankProdInfo: // Get whether this unit should simulate a "blanked" PRODINFO. - return MakeResult(u64{0}); + return u64{0}; case ConfigItem::ExosphereAllowCalWrites: // Get whether this unit should allow writing to the calibration partition. - return MakeResult(u64{0}); + return u64{0}; case ConfigItem::ExosphereEmummcType: // Get what kind of emummc this unit has active. - return MakeResult(u64{0}); + return u64{0}; case ConfigItem::ExospherePayloadAddress: // Gets the physical address of the reboot payload buffer, if one exists. return ResultSecureMonitorNotInitialized; case ConfigItem::ExosphereLogConfiguration: // Get the log configuration. - return MakeResult(u64{0}); + return u64{0}; case ConfigItem::ExosphereForceEnableUsb30: // Get whether usb 3.0 should be force-enabled. - return MakeResult(u64{0}); + return u64{0}; default: return ResultSecureMonitorInvalidArgument; } diff --git a/src/core/hle/service/vi/vi.cpp b/src/core/hle/service/vi/vi.cpp index 439e7e4726..760b528b95 100644 --- a/src/core/hle/service/vi/vi.cpp +++ b/src/core/hle/service/vi/vi.cpp @@ -1284,15 +1284,15 @@ private: static ResultVal ConvertScalingModeImpl(NintendoScaleMode mode) { switch (mode) { case NintendoScaleMode::None: - return MakeResult(ConvertedScaleMode::None); + return ConvertedScaleMode::None; case NintendoScaleMode::Freeze: - return MakeResult(ConvertedScaleMode::Freeze); + return ConvertedScaleMode::Freeze; case NintendoScaleMode::ScaleToWindow: - return MakeResult(ConvertedScaleMode::ScaleToWindow); + return ConvertedScaleMode::ScaleToWindow; case NintendoScaleMode::ScaleAndCrop: - return MakeResult(ConvertedScaleMode::ScaleAndCrop); + return ConvertedScaleMode::ScaleAndCrop; case NintendoScaleMode::PreserveAspectRatio: - return MakeResult(ConvertedScaleMode::PreserveAspectRatio); + return ConvertedScaleMode::PreserveAspectRatio; default: LOG_ERROR(Service_VI, "Invalid scaling mode specified, mode={}", mode); return ERR_OPERATION_FAILED;