diff --git a/m-core.h b/m-core.h index f178f1b8..1e0f2825 100644 --- a/m-core.h +++ b/m-core.h @@ -3821,11 +3821,19 @@ M_INLINE size_t m_core_cstr_hash(const char str[]) /* Check if both variables are of the same type. The test compare their size. NOTE: Not perfect but catch some errors */ +#ifdef __GNUC__ +#define M_CHECK_SAME(a, b) \ + M_STATIC_ASSERT(__builtin_types_compatible_p(__typeof__(a), __typeof__(b)), \ + M_LIB_NOT_SAME_TYPE, \ + "The variable " M_AS_STR(a) " and " M_AS_STR(b) \ + " are not of same type.") +#else #define M_CHECK_SAME(a, b) \ M_STATIC_ASSERT(sizeof(a) == sizeof(b), \ M_LIB_NOT_SAME_TYPE, \ "The variable " M_AS_STR(a) " and " M_AS_STR(b) \ " are not of same type.") +#endif /* Check if the oplist is compatible with the type. The oplist should define a TYPE method, in which case it is tested. @@ -4526,26 +4534,24 @@ m_core_parse2_enum (const char str[], const char **endptr) /* If exceptions are activated, M_ON_EXCEPTION enables support for fixing the data structure when an exception is throw, - so that the data structure is proper for the CLEAR method. + so that the data structure integrity is ready for the CLEAR method. The fix code is *only* executed on exception. USAGE: void init_function(struct_t s) { - M_ON_EXCEPTION(name, OPLIST, s->size = i ) { + M_ON_EXCEPTION(s->size = i ) { // Rest of initialization code } } */ -#define M_ON_EXCEPTION(name, oplist, fix) \ - M_IF(M_GET_PROPERTY(oplist, NOCLEAR))(M_EAT, M_ON_EXCEPTION_B) \ - (M_C(m_var_, name), fix) - -#define M_ON_EXCEPTION_B(cont, fix) \ +#define M_ON_EXCEPTION(fix) \ for(bool cont = true; cont; cont = false) \ - M_DEFER_TRY_INJECT_PRE(cont, clear) \ + M_DEFER_TRY_INJECT_PRE(cont, fix) \ for( ; cont ; cont = false) \ - M_DEFER_TRY_INJECT_POST(cont, clear) \ + M_DEFER_TRY_INJECT_POST(cont, fix) \ for( ; cont; cont = false) +/* If exceptions are activated, M_IF_EXCEPTION will expand the code */ +#define M_IF_EXCEPTION(fix) (void) 0 /* Declare a variable, initialize it, continue if the initialization succeeds, and clears the variable afterwards.