From 2fb77adb9f3fca7c4243ffe20df14c45d928fa96 Mon Sep 17 00:00:00 2001 From: bunnei Date: Fri, 15 Jan 2021 21:52:18 -0800 Subject: common: common_funcs: Add a few more useful macros for kernel code. --- src/common/common_funcs.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/common/common_funcs.h') diff --git a/src/common/common_funcs.h b/src/common/common_funcs.h index 75f3027fb..49c36765d 100644 --- a/src/common/common_funcs.h +++ b/src/common/common_funcs.h @@ -101,6 +101,17 @@ __declspec(dllimport) void __stdcall DebugBreak(void); } \ } +#define R_SUCCEEDED(res) (res.IsSuccess()) + +/// Evaluates an expression that returns a result, and returns the result if it would fail. +#define R_TRY(res_expr) \ + { \ + const auto _tmp_r_try_rc = (res_expr); \ + if (_tmp_r_try_rc.IsError()) { \ + return _tmp_r_try_rc; \ + } \ + } + namespace Common { [[nodiscard]] constexpr u32 MakeMagic(char a, char b, char c, char d) { -- cgit v1.2.3 From bb966d3e336ce1eee86daca5db00b29a63708d4c Mon Sep 17 00:00:00 2001 From: bunnei Date: Tue, 19 Jan 2021 20:53:11 -0800 Subject: common: common_funcs: Add useful kernel macro R_SUCCEED_IF. --- src/common/common_funcs.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/common/common_funcs.h') diff --git a/src/common/common_funcs.h b/src/common/common_funcs.h index 49c36765d..842d62ca7 100644 --- a/src/common/common_funcs.h +++ b/src/common/common_funcs.h @@ -112,6 +112,9 @@ __declspec(dllimport) void __stdcall DebugBreak(void); } \ } +/// Evaluates a boolean expression, and succeeds if that expression is true. +#define R_SUCCEED_IF(expr) R_UNLESS(!(expr), RESULT_SUCCESS) + namespace Common { [[nodiscard]] constexpr u32 MakeMagic(char a, char b, char c, char d) { -- cgit v1.2.3 From 091e9e8c4100308c3c8d367f7fd32290cd053f40 Mon Sep 17 00:00:00 2001 From: bunnei Date: Sun, 24 Jan 2021 22:50:36 -0800 Subject: common: common_funcs: Log error on R_UNLESS. --- src/common/common_funcs.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/common/common_funcs.h') diff --git a/src/common/common_funcs.h b/src/common/common_funcs.h index 842d62ca7..71d136d4a 100644 --- a/src/common/common_funcs.h +++ b/src/common/common_funcs.h @@ -97,6 +97,9 @@ __declspec(dllimport) void __stdcall DebugBreak(void); #define R_UNLESS(expr, res) \ { \ if (!(expr)) { \ + if (res.IsError()) { \ + LOG_CRITICAL(Kernel, "Failed with error {}", res.raw); \ + } \ return res; \ } \ } -- cgit v1.2.3 From 8d1afcb90f59e000467466cd03e42f1488f5e44a Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 28 Jan 2021 21:51:16 -0800 Subject: common: common_funcs: Change R_UNLESS to LOG_ERROR. --- src/common/common_funcs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/common/common_funcs.h') diff --git a/src/common/common_funcs.h b/src/common/common_funcs.h index 71d136d4a..71b64e32a 100644 --- a/src/common/common_funcs.h +++ b/src/common/common_funcs.h @@ -98,7 +98,7 @@ __declspec(dllimport) void __stdcall DebugBreak(void); { \ if (!(expr)) { \ if (res.IsError()) { \ - LOG_CRITICAL(Kernel, "Failed with error {}", res.raw); \ + LOG_ERROR(Kernel, "Failed with result: {}", res.raw); \ } \ return res; \ } \ -- cgit v1.2.3