Add macro for stringifying __FILE__:__LINE__

This commit is contained in:
Nils O. Selåsdal
2013-10-16 01:37:20 +02:00
parent 934088ca4a
commit 13567e3cd9
+15 -11
View File
@@ -11,15 +11,6 @@
#define UC_STATIC_ASSERT(expr) \ #define UC_STATIC_ASSERT(expr) \
enum { assert_static__ = 1/(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 //MAX of a and b
#define UC_MAX(a,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(x) UC_STRINGIFY_HLP(x)
#define UC_STRINGIFY_HLP(x) #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 * assert() that is not affected by NDEBUG define
*/ */
@@ -87,19 +81,29 @@ const typeof( ((const type *)0)->member ) *__mptr = (ptr); \
do {\ do {\
if (!(expr) ) {\ if (!(expr) ) {\
fprintf(stderr,\ 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);\ uc_backtrace_fd(2);\
abort();\ abort();\
}\ }\
} while (0) } 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, * Macro for asserting code that should not be reached,
* terminates the program if executed * terminates the program if executed
*/ */
#define UC_NOT_REACED()\ #define UC_NOT_REACED()\
do {\ 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);\ uc_backtrace_fd(2);\
abort();\ abort();\
while (0) while (0)