diff --git a/include/ucore/utils.h b/include/ucore/utils.h index cc1b0cf..cc23bef 100644 --- a/include/ucore/utils.h +++ b/include/ucore/utils.h @@ -11,15 +11,6 @@ #define UC_STATIC_ASSERT(expr) \ enum { assert_static__ = 1/(expr) }; -#ifdef DEBUG - #define TRACEF(fmt, ...)\ - do { \ - fprintf(stdout, "%s:%d (%s)\t" fmt, __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__);\ - fflush(stdout);\ - } while(0) -#else - #define TRACEF(fmt, ...) -#endif //MAX of a and b #define UC_MAX(a,b) \ @@ -80,6 +71,9 @@ const typeof( ((const type *)0)->member ) *__mptr = (ptr); \ #define UC_STRINGIFY(x) UC_STRINGIFY_HLP(x) #define UC_STRINGIFY_HLP(x) #x +/** Macro that expands to a string for the current file:line + */ +#define UC_SRC_LOCATION __FILE__ ":" UC_STRINGIFY(__LINE__) /** * assert() that is not affected by NDEBUG define */ @@ -87,19 +81,29 @@ const typeof( ((const type *)0)->member ) *__mptr = (ptr); \ do {\ if (!(expr) ) {\ fprintf(stderr,\ - "UC_ASSERT failed '%s' %s:%d\n", UC_STRINGIFY(expr), __FILE__, __LINE__);\ + "UC_ASSERT failed '%s' %s\n", UC_STRINGIFY(expr), UC_SRC_LOCATION);\ uc_backtrace_fd(2);\ abort();\ }\ } while (0) +#ifdef DEBUG + #define TRACEF(fmt, ...)\ + do { \ + fprintf(stdout, "%s (%s)\t" fmt, UC_SRC_LOCATION, __FUNCTION__, ##__VA_ARGS__);\ + fflush(stdout);\ + } while(0) +#else + #define TRACEF(fmt, ...) +#endif + /** * Macro for asserting code that should not be reached, * terminates the program if executed */ #define UC_NOT_REACED()\ do {\ - fprintf(stderr, "UC_NOT_REACED at %s:%d\n", __FILE__, __LINE__);\ + fprintf(stderr, "UC_NOT_REACED at %s\n", UC_SRC_LOCATION);\ uc_backtrace_fd(2);\ abort();\ while (0)