From 12ee3213b0d3a8cbdda88ab03eaacc122b06e46e Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Sat, 6 Apr 2024 19:13:08 +0200 Subject: [PATCH] Simplify M_ON_EXCEPTION / M_IF_EXCEPTION --- m-core.h | 13 +++++-------- m-try.h | 11 +++++++++++ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/m-core.h b/m-core.h index f0a5e37c..21755fa3 100644 --- a/m-core.h +++ b/m-core.h @@ -4542,16 +4542,13 @@ m_core_parse2_enum (const char str[], const char **endptr) // Rest of initialization code } } + Do nothing if exceptions are not enabled. */ -#define M_ON_EXCEPTION(fix) \ - for(bool cont = true; cont; cont = false) \ - M_DEFER_TRY_INJECT_PRE(cont, fix) \ - for( ; cont ; cont = false) \ - M_DEFER_TRY_INJECT_POST(cont, fix) \ - for( ; cont; cont = false) +#define M_ON_EXCEPTION(...) for(bool cont = true; cont; cont = false) \ -/* If exceptions are activated, M_IF_EXCEPTION will expand the code */ -#define M_IF_EXCEPTION(fix) (void) 0 +/* If exceptions are activated, M_IF_EXCEPTION will expand the code. + Do nothing if exceptions are not enabled. */ +#define M_IF_EXCEPTION(...) (void) 0 /* Declare a variable, initialize it, continue if the initialization succeeds, and clears the variable afterwards. diff --git a/m-try.h b/m-try.h index b5d9ba33..b252e74f 100644 --- a/m-try.h +++ b/m-try.h @@ -156,6 +156,17 @@ struct m_exception_s { /********************************** INTERNAL *********************************/ /*****************************************************************************/ +#undef M_IF_EXCEPTION +#define M_IF_EXCEPTION(...) __VA_ARGS__ + +#undef M_ON_EXCEPTION +#define M_ON_EXCEPTION(...) \ + for(bool cont = true; cont; cont = false) \ + M_DEFER_TRY_INJECT_PRE(cont, __VA_ARGS__) \ + for( ; cont ; cont = false) \ + M_DEFER_TRY_INJECT_POST(cont, __VA_ARGS__) \ + for( ; cont; cont = false) + /* * Define the C++ back-end. * It is fully different from C back-end as it reuses the classic try of the C++.