diff --git a/ase/cmn/macros.h b/ase/cmn/macros.h index cebb7362..6c0c2b28 100644 --- a/ase/cmn/macros.h +++ b/ase/cmn/macros.h @@ -1,5 +1,5 @@ /* - * $Id: macros.h,v 1.1 2007-03-06 14:16:52 bacon Exp $ + * $Id: macros.h,v 1.2 2007-03-06 14:29:04 bacon Exp $ * * {License} */ @@ -56,11 +56,11 @@ #define ASE_REPEAT(n,blk) \ do { \ - ase_size_t __ase_repeat_x1 = (ase_size_t)(n); \ - ase_size_t __ase_repeat_x2 = __ase_repeat_x1 >> 4; \ - __ase_repeat_x1 &= 15; \ - while (__ase_repeat_x1-- > 0) { blk; } \ - while (__ase_repeat_x2-- > 0) { \ + ase_size_t __ase_repeat_x1__ = (ase_size_t)(n); \ + ase_size_t __ase_repeat_x2__ = __ase_repeat_x1__ >> 4; \ + __ase_repeat_x1__ &= 15; \ + while (__ase_repeat_x1__-- > 0) { blk; } \ + while (__ase_repeat_x2__-- > 0) { \ blk; blk; blk; blk; blk; blk; blk; blk; \ blk; blk; blk; blk; blk; blk; blk; blk; \ } \ @@ -96,6 +96,28 @@ #define ASE_END_PACKED_STRUCT() }; #endif +#ifdef NDEBUG + #define ASE_ASSERT(awk,expr) ((void)0) + #define ASE_ASSERTX(awk,expr,desc) ((void)0) +#else + #ifdef __cplusplus + extern "C" { + #endif + void ase_assert_abort (void); + void ase_assert_printf (const ase_char_t* fmt, ...); + int ase_assert_failed ( + const ase_char_t* expr, const ase_char_t* desc, + const ase_char_t* file, ase_size_t line); + #ifdef __cplusplus + } + #endif + + #define ASE_ASSERT(awk,expr) (void)((expr) || \ + (ase_assert_failed (ASE_T(#expr), ASE_NULL, ASE_T(__FILE__), __LINE__), 0)) + #define ASE_ASSERTX(awk,expr,desc) (void)((expr) || \ + (ase_assert_failed (ASE_T(#expr), ASE_T(desc), ASE_T(__FILE__), __LINE__), 0)) +#endif + #define ASE_MALLOC(mmgr,size) (mmgr)->malloc((mmgr)->custom_data, size) #define ASE_REALLOC(mmgr,ptr,size) (mmgr)->realloc((mmgr)->custom_data, ptr, size) #define ASE_FREE(mmgr,ptr) (mmgr)->free((mmgr)->custom_data, ptr) diff --git a/ase/cmn/makefile.in b/ase/cmn/makefile.in index 3d49fb53..a5cdf411 100644 --- a/ase/cmn/makefile.in +++ b/ase/cmn/makefile.in @@ -1,6 +1,6 @@ OUT = asecmn -C_SRCS = mem.c str.c +C_SRCS = mem.c str.c misc.c C_OBJS = $(C_SRCS:.c=.o) CC = @CC@ diff --git a/ase/cmn/makefile.msw.bcc b/ase/cmn/makefile.msw.bcc index f49a17c0..8aee0bbb 100644 --- a/ase/cmn/makefile.msw.bcc +++ b/ase/cmn/makefile.msw.bcc @@ -1,6 +1,6 @@ OUT = asecmn -C_SRCS = mem.c str.c +C_SRCS = mem.c str.c misc.c C_OBJS = $(C_SRCS:.c=.obj) CC = bcc32 diff --git a/ase/cmn/makefile.msw.cl b/ase/cmn/makefile.msw.cl index 0d01bdf3..d0b24a94 100644 --- a/ase/cmn/makefile.msw.cl +++ b/ase/cmn/makefile.msw.cl @@ -1,6 +1,6 @@ OUT = asecmn -C_SRCS = mem.c str.c +C_SRCS = mem.c str.c misc.c C_OBJS = $(C_SRCS:.c=.obj) CC = cl diff --git a/ase/cmn/misc.c b/ase/cmn/misc.c new file mode 100644 index 00000000..8196a909 --- /dev/null +++ b/ase/cmn/misc.c @@ -0,0 +1,31 @@ +/* + * $Id: misc.c,v 1.1 2007-03-06 14:29:27 bacon Exp $ + * + * {License} + */ + +#include +#include + +int ase_assert_failed ( + const ase_char_t* expr, const ase_char_t* desc, + const ase_char_t* file, ase_size_t line) +{ + if (desc == ASE_NULL) + { + ase_assert_printf ( + ASE_T("ASSERTION FAILURE AT FILE %s LINE %lu\n%s\n"), + file, (unsigned long)line, expr); + } + else + { + ase_assert_printf ( + ASE_T("ASSERTION FAILURE AT FILE %s LINE %lu\n%s\n\nDESCRIPTION:\n%s\n"), + file, (unsigned long)line, expr, desc); + + } + + ase_assert_abort (); + return 0; +} +