diff --git a/include/stratosphere/results/utilities.h b/include/stratosphere/results/utilities.h index 1b45d1c7..2e1c9b92 100644 --- a/include/stratosphere/results/utilities.h +++ b/include/stratosphere/results/utilities.h @@ -20,6 +20,21 @@ extern "C" { } \ }) +/// Evaluates an expression that returns a result, and fatals the result if it would fail. +#ifdef RESULT_ABORT_ON_ASSERT +#define R_ASSERT_IMPL(res) std::abort() +#else +#define R_ASSERT_IMPL(res) fatalSimple(res) +#endif + +#define R_ASSERT(res_expr) \ + ({ \ + const Result _tmp_r_assert_rc = res_expr; \ + if (R_FAILED(_tmp_r_assert_rc)) { \ + R_ASSERT_IMPL(_tmp_r_assert_rc); \ + } \ + }) + /// Helpers for pattern-matching on a result expression, if the result would fail. #define R_TRY_CATCH(res_expr) \ ({ \ @@ -47,6 +62,11 @@ extern "C" { if (false) { } \ else +#define R_CATCH_ALL() \ + } else if (R_FAILED(_tmp_r_try_catch_rc)) { \ + if (false) { } \ + else + #define R_END_TRY_CATCH \ else if (R_FAILED(_tmp_r_try_catch_rc)) { \ return _tmp_r_try_catch_rc; \