mirror of
https://github.com/Atmosphere-NX/Atmosphere-libs.git
synced 2025-06-27 21:42:49 +02:00
Add R_TRY_CLEANUP utility.
This commit is contained in:
parent
afcd075354
commit
b5f1ec02b3
@ -13,16 +13,17 @@ extern "C" {
|
||||
|
||||
/// Evaluates an expression that returns a result, and returns the result if it would fail.
|
||||
#define R_TRY(res_expr) \
|
||||
do { \
|
||||
{ \
|
||||
const Result _tmp_r_try_rc = res_expr; \
|
||||
if (R_FAILED(_tmp_r_try_rc)) { \
|
||||
return _tmp_r_try_rc; \
|
||||
} \
|
||||
} while (0)
|
||||
} \
|
||||
do {} while (0)
|
||||
|
||||
/// Helpers for pattern-matching on a result expression, if the result would fail.
|
||||
#define R_TRY_CATCH(res_expr) \
|
||||
do { \
|
||||
{ \
|
||||
const Result _tmp_r_try_catch_rc = res_expr; \
|
||||
if (R_FAILED(_tmp_r_try_catch_rc)) { \
|
||||
if (false)
|
||||
@ -51,7 +52,21 @@ extern "C" {
|
||||
} else if (R_FAILED(_tmp_r_try_catch_rc)) { \
|
||||
return _tmp_r_try_catch_rc; \
|
||||
} \
|
||||
} while (0)
|
||||
} \
|
||||
do {} while (0)
|
||||
|
||||
/// Evaluates an expression that returns a result, and returns the result (after evaluating a cleanup expression) if it would fail.
|
||||
#define R_TRY_CLEANUP(res_expr, cleanup_expr) \
|
||||
{ \
|
||||
const Result _tmp_r_try_cleanup_rc = res_expr; \
|
||||
if (R_FAILED(_tmp_r_try_cleanup_rc)) { \
|
||||
do { \
|
||||
cleanup_expr \
|
||||
} while (0); \
|
||||
return _tmp_r_try_cleanup_rc; \
|
||||
} \
|
||||
} \
|
||||
do {} while (0)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user