ams: revamp assertion system

This commit is contained in:
Michael Scire
2020-02-22 23:05:14 -08:00
parent 9572fb2ce3
commit 40400aee1f
168 changed files with 1014 additions and 696 deletions

View File

@@ -22,7 +22,7 @@ namespace ams::fssystem {
{
this->before_dir = nullptr;
this->after_dir = nullptr;
R_ASSERT(this->Initialize(before, after));
R_ABORT_UNLESS(this->Initialize(before, after));
}
DirectoryRedirectionFileSystem::DirectoryRedirectionFileSystem(std::unique_ptr<fs::fsa::IFileSystem> fs, const char *before, const char *after, bool unc)
@@ -30,7 +30,7 @@ namespace ams::fssystem {
{
this->before_dir = nullptr;
this->after_dir = nullptr;
R_ASSERT(this->Initialize(before, after));
R_ABORT_UNLESS(this->Initialize(before, after));
}
DirectoryRedirectionFileSystem::~DirectoryRedirectionFileSystem() {
@@ -57,7 +57,7 @@ namespace ams::fssystem {
/* Ensure terminating '/' */
if (!PathTool::IsSeparator(normalized_path[normalized_path_len - 1])) {
AMS_ASSERT(normalized_path_len + 2 <= sizeof(normalized_path));
AMS_ABORT_UNLESS(normalized_path_len + 2 <= sizeof(normalized_path));
normalized_path[normalized_path_len] = StringTraits::DirectorySeparator;
normalized_path[normalized_path_len + 1] = StringTraits::NullTerminator;
@@ -67,7 +67,7 @@ namespace ams::fssystem {
/* Allocate new path. */
const size_t size = normalized_path_len + 1;
char *new_dir = static_cast<char *>(std::malloc(size));
AMS_ASSERT(new_dir != nullptr);
AMS_ABORT_UNLESS(new_dir != nullptr);
/* TODO: custom ResultAllocationFailure? */
/* Copy path in. */

View File

@@ -134,7 +134,7 @@ namespace ams::fssystem {
/* TODO: Return a result here? Nintendo does not, but they have other allocation failed results. */
/* Consider returning ResultFsAllocationFailureInDirectorySaveDataFileSystem? */
AMS_ASSERT(false);
AMS_ABORT_UNLESS(false);
}
Result DirectorySaveDataFileSystem::SynchronizeDirectory(const char *dst, const char *src) {
@@ -173,7 +173,7 @@ namespace ams::fssystem {
this->open_writable_files--;
/* Nintendo does not check this, but I think it's sensible to do so. */
AMS_ASSERT(this->open_writable_files >= 0);
AMS_ABORT_UNLESS(this->open_writable_files >= 0);
}
Result DirectorySaveDataFileSystem::CopySaveFromFileSystem(fs::fsa::IFileSystem *save_fs) {

View File

@@ -21,14 +21,14 @@ namespace ams::fssystem {
: PathResolutionFileSystem(fs, unc)
{
this->base_path = nullptr;
R_ASSERT(this->Initialize(bp));
R_ABORT_UNLESS(this->Initialize(bp));
}
SubDirectoryFileSystem::SubDirectoryFileSystem(std::unique_ptr<fs::fsa::IFileSystem> fs, const char *bp, bool unc)
: PathResolutionFileSystem(std::move(fs), unc)
{
this->base_path = nullptr;
R_ASSERT(this->Initialize(bp));
R_ABORT_UNLESS(this->Initialize(bp));
}
SubDirectoryFileSystem::~SubDirectoryFileSystem() {
@@ -48,7 +48,7 @@ namespace ams::fssystem {
/* Ensure terminating '/' */
if (!PathTool::IsSeparator(normalized_path[normalized_path_len - 1])) {
AMS_ASSERT(normalized_path_len + 2 <= sizeof(normalized_path));
AMS_ABORT_UNLESS(normalized_path_len + 2 <= sizeof(normalized_path));
normalized_path[normalized_path_len] = StringTraits::DirectorySeparator;
normalized_path[normalized_path_len + 1] = StringTraits::NullTerminator;

View File

@@ -40,7 +40,7 @@ namespace ams::fssystem {
char dst_path[fs::EntryNameLengthMax + 1];
const size_t original_size = static_cast<size_t>(std::snprintf(dst_path, sizeof(dst_path), "%s%s", dst_parent_path, entry->name));
/* TODO: Error code? N aborts here. */
AMS_ASSERT(original_size < sizeof(dst_path));
AMS_ABORT_UNLESS(original_size < sizeof(dst_path));
R_TRY(dst_fs->CreateFile(dst_path, entry->file_size));
R_TRY(dst_fs->OpenFile(&dst_file, dst_path, fs::OpenMode_Write));
@@ -64,7 +64,7 @@ namespace ams::fssystem {
Result CopyDirectoryRecursively(fs::fsa::IFileSystem *dst_fs, fs::fsa::IFileSystem *src_fs, const char *dst_path, const char *src_path, void *work_buf, size_t work_buf_size) {
char dst_path_buf[fs::EntryNameLengthMax + 1];
const size_t original_size = static_cast<size_t>(std::snprintf(dst_path_buf, sizeof(dst_path_buf), "%s", dst_path));
AMS_ASSERT(original_size < sizeof(dst_path_buf));
AMS_ABORT_UNLESS(original_size < sizeof(dst_path_buf));
return IterateDirectoryRecursively(src_fs, src_path,
[&](const char *path, const fs::DirectoryEntry &entry) -> Result { /* On Enter Directory */