Results: Implement namespaced, type-safe results.
Because I was working on multiple things at once, this commit also:
- Adds wrappers for/linker flags to wrap CXX exceptions to make them
abort. This saves ~0x8000 of memory in every system module.
- Broadly replaces lines of the pattern if (cond) { return ResultX; }
with R_UNLESS(!cond, ResultX());.
- Reworks the R_TRY_CATCH macros (and the result macros in general).
This commit is contained in:
@@ -90,9 +90,7 @@ namespace sts::fatal::srv {
|
||||
ViDisplay temp_display;
|
||||
/* Try to open the display. */
|
||||
R_TRY_CATCH(viOpenDisplay("Internal", &temp_display)) {
|
||||
R_CATCH(ResultViNotFound) {
|
||||
return ResultSuccess;
|
||||
}
|
||||
R_CONVERT(vi::ResultNotFound, ResultSuccess());
|
||||
} R_END_TRY_CATCH;
|
||||
|
||||
/* Guarantee we close the display. */
|
||||
@@ -109,16 +107,14 @@ namespace sts::fatal::srv {
|
||||
/* Set alpha to 1.0f. */
|
||||
R_TRY(viSetDisplayAlpha(&temp_display, 1.0f));
|
||||
|
||||
return ResultSuccess;
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result ShowFatalTask::SetupDisplayExternal() {
|
||||
ViDisplay temp_display;
|
||||
/* Try to open the display. */
|
||||
R_TRY_CATCH(viOpenDisplay("External", &temp_display)) {
|
||||
R_CATCH(ResultViNotFound) {
|
||||
return ResultSuccess;
|
||||
}
|
||||
R_CONVERT(vi::ResultNotFound, ResultSuccess());
|
||||
} R_END_TRY_CATCH;
|
||||
|
||||
/* Guarantee we close the display. */
|
||||
@@ -127,7 +123,7 @@ namespace sts::fatal::srv {
|
||||
/* Set alpha to 1.0f. */
|
||||
R_TRY(viSetDisplayAlpha(&temp_display, 1.0f));
|
||||
|
||||
return ResultSuccess;
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result ShowFatalTask::PrepareScreenForDrawing() {
|
||||
@@ -182,7 +178,7 @@ namespace sts::fatal::srv {
|
||||
R_TRY(framebufferCreate(&this->fb, &this->win, raw_width, raw_height, PIXEL_FORMAT_RGB_565, 1));
|
||||
}
|
||||
|
||||
return ResultSuccess;
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result ShowFatalTask::ShowFatal() {
|
||||
@@ -195,9 +191,7 @@ namespace sts::fatal::srv {
|
||||
|
||||
/* Dequeue a buffer. */
|
||||
u16 *tiled_buf = reinterpret_cast<u16 *>(framebufferBegin(&this->fb, NULL));
|
||||
if (tiled_buf == nullptr) {
|
||||
return ResultFatalNullGraphicsBuffer;
|
||||
}
|
||||
R_UNLESS(tiled_buf != nullptr, ResultNullGraphicsBuffer());
|
||||
|
||||
/* Let the font manager know about our framebuffer. */
|
||||
font::ConfigureFontFramebuffer(tiled_buf, GetPixelOffset);
|
||||
@@ -218,13 +212,13 @@ namespace sts::fatal::srv {
|
||||
/* TODO: Actually draw meaningful shit here. */
|
||||
font::SetPosition(32, 64);
|
||||
font::SetFontSize(16.0f);
|
||||
font::PrintFormat(config.GetErrorMessage(), R_MODULE(this->context->error_code), R_DESCRIPTION(this->context->error_code), this->context->error_code);
|
||||
font::PrintFormat(config.GetErrorMessage(), this->context->result.GetModule(), this->context->result.GetDescription(), this->context->result.GetValue());
|
||||
font::AddSpacingLines(0.5f);
|
||||
font::PrintFormatLine("Title: %016lX", static_cast<u64>(this->context->title_id));
|
||||
font::AddSpacingLines(0.5f);
|
||||
font::PrintFormatLine(u8"Firmware: %s (Atmosphère %u.%u.%u-%s)", config.GetFirmwareVersion().display_version, ATMOSPHERE_RELEASE_VERSION, ams::GetGitRevision());
|
||||
font::AddSpacingLines(1.5f);
|
||||
if (this->context->error_code != ResultAtmosphereVersionMismatch) {
|
||||
if (!ams::ResultVersionMismatch::Includes(this->context->result)) {
|
||||
font::Print(config.GetErrorDescription());
|
||||
} else {
|
||||
/* Print a special message for atmosphere version mismatch. */
|
||||
@@ -415,7 +409,7 @@ namespace sts::fatal::srv {
|
||||
/* Enqueue the buffer. */
|
||||
framebufferEnd(&fb);
|
||||
|
||||
return ResultSuccess;
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result ShowFatalTask::Run() {
|
||||
@@ -431,7 +425,7 @@ namespace sts::fatal::srv {
|
||||
|
||||
Result BacklightControlTask::Run() {
|
||||
TurnOnBacklight();
|
||||
return ResultSuccess;
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user