Prepare exception aware integration
This commit is contained in:
1 parent
3c4943015b
commit
c539eb57b7
1 file changed
+15
-9
@@ -3821,11 +3821,19 @@ M_INLINE size_t m_core_cstr_hash(const char str[])
|
|||||||
/* Check if both variables are of the same type.
|
/* Check if both variables are of the same type.
|
||||||
The test compare their size.
|
The test compare their size.
|
||||||
NOTE: Not perfect but catch some errors */
|
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) \
|
#define M_CHECK_SAME(a, b) \
|
||||||
M_STATIC_ASSERT(sizeof(a) == sizeof(b), \
|
M_STATIC_ASSERT(sizeof(a) == sizeof(b), \
|
||||||
M_LIB_NOT_SAME_TYPE, \
|
M_LIB_NOT_SAME_TYPE, \
|
||||||
"The variable " M_AS_STR(a) " and " M_AS_STR(b) \
|
"The variable " M_AS_STR(a) " and " M_AS_STR(b) \
|
||||||
" are not of same type.")
|
" are not of same type.")
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Check if the oplist is compatible with the type.
|
/* Check if the oplist is compatible with the type.
|
||||||
The oplist should define a TYPE method, in which case it is tested.
|
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
|
/* If exceptions are activated, M_ON_EXCEPTION enables support for fixing
|
||||||
the data structure when an exception is throw,
|
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.
|
The fix code is *only* executed on exception.
|
||||||
USAGE:
|
USAGE:
|
||||||
void init_function(struct_t s) {
|
void init_function(struct_t s) {
|
||||||
M_ON_EXCEPTION(name, OPLIST, s->size = i ) {
|
M_ON_EXCEPTION(s->size = i ) {
|
||||||
// Rest of initialization code
|
// Rest of initialization code
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
#define M_ON_EXCEPTION(name, oplist, fix) \
|
#define M_ON_EXCEPTION(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) \
|
|
||||||
for(bool cont = true; cont; cont = false) \
|
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) \
|
for( ; cont ; cont = false) \
|
||||||
M_DEFER_TRY_INJECT_POST(cont, clear) \
|
M_DEFER_TRY_INJECT_POST(cont, fix) \
|
||||||
for( ; cont; cont = false)
|
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,
|
/* Declare a variable, initialize it, continue if the initialization succeeds,
|
||||||
and clears the variable afterwards.
|
and clears the variable afterwards.
|
||||||
|
|||||||
Reference in new issue
Block a user