Move UC_ASSERT/NOTREACHED to backtrace.h
This commit is contained in:
@@ -1,12 +1,14 @@
|
|||||||
#ifndef UC_BACKTRACE_H_
|
#ifndef UC_BACKTRACE_H_
|
||||||
#define UC_BACKTRACE_H_
|
#define UC_BACKTRACE_H_
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define UC_BACTRACE_STDERR uc_backtrace_fd(2)
|
#define UC_BACKTRACE_STDERR uc_backtrace_fd(2)
|
||||||
/**
|
/**
|
||||||
* Print a stacktrace to the given file descriptor.
|
* Print a stacktrace to the given file descriptor.
|
||||||
*
|
*
|
||||||
@@ -24,6 +26,30 @@ void uc_backtrace_fd(int fd);
|
|||||||
*/
|
*/
|
||||||
void uc_backtrace_buf(char *buf, size_t len);
|
void uc_backtrace_buf(char *buf, size_t len);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* assert() that is not affected by NDEBUG define
|
||||||
|
*/
|
||||||
|
#define UC_ASSERT(expr)\
|
||||||
|
do {\
|
||||||
|
if (!(expr) ) {\
|
||||||
|
fprintf(stderr,\
|
||||||
|
"UC_ASSERT failed '%s' %s\n", UC_STRINGIFY(expr), UC_SRC_LOCATION);\
|
||||||
|
UC_BACKTRACE_STDERR;\
|
||||||
|
abort();\
|
||||||
|
}\
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Macro for asserting code that should not be reached,
|
||||||
|
* terminates the program if executed
|
||||||
|
*/
|
||||||
|
#define UC_NOT_REACED()\
|
||||||
|
do {\
|
||||||
|
fprintf(stderr, "UC_NOT_REACHED at %s\n", UC_SRC_LOCATION);\
|
||||||
|
UC_BACKTRACE_STDERR;\
|
||||||
|
abort();\
|
||||||
|
while (0)
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+3
-25
@@ -3,8 +3,6 @@
|
|||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
|
||||||
#include "backtrace.h"
|
|
||||||
|
|
||||||
//Gnerate a compiler error if the compile time
|
//Gnerate a compiler error if the compile time
|
||||||
//constant expression fails
|
//constant expression fails
|
||||||
@@ -75,18 +73,6 @@ const typeof( ((const type *)0)->member ) *__mptr = (ptr); \
|
|||||||
*/
|
*/
|
||||||
#define UC_SRC_LOCATION __FILE__ ":" UC_STRINGIFY(__LINE__)
|
#define UC_SRC_LOCATION __FILE__ ":" UC_STRINGIFY(__LINE__)
|
||||||
|
|
||||||
/**
|
|
||||||
* assert() that is not affected by NDEBUG define
|
|
||||||
*/
|
|
||||||
#define UC_ASSERT(expr)\
|
|
||||||
do {\
|
|
||||||
if (!(expr) ) {\
|
|
||||||
fprintf(stderr,\
|
|
||||||
"UC_ASSERT failed '%s' %s\n", UC_STRINGIFY(expr), UC_SRC_LOCATION);\
|
|
||||||
uc_backtrace_fd(2);\
|
|
||||||
abort();\
|
|
||||||
}\
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
#define TRACEF(fmt, ...)\
|
#define TRACEF(fmt, ...)\
|
||||||
@@ -98,17 +84,6 @@ const typeof( ((const type *)0)->member ) *__mptr = (ptr); \
|
|||||||
#define TRACEF(fmt, ...) do {} while(0)
|
#define TRACEF(fmt, ...) do {} while(0)
|
||||||
#endif
|
#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\n", UC_SRC_LOCATION);\
|
|
||||||
uc_backtrace_fd(2);\
|
|
||||||
abort();\
|
|
||||||
while (0)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Round up x / y
|
* Round up x / y
|
||||||
* (e.g 100/9 == 12, 3/2 == 2)
|
* (e.g 100/9 == 12, 3/2 == 2)
|
||||||
@@ -138,6 +113,9 @@ while (0)
|
|||||||
*/
|
*/
|
||||||
#define UC_ROUND_DOWN(x, y) ((x) / (y) * (y))
|
#define UC_ROUND_DOWN(x, y) ((x) / (y) * (y))
|
||||||
|
|
||||||
|
/** Indicate the variable is unused.
|
||||||
|
*/
|
||||||
|
#define UC_UNUSED(x) x __attribute__((unused))
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include <check.h>
|
#include <check.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <ucore/dstr.h>
|
#include <ucore/dstr.h>
|
||||||
#include <ucore/utils.h>
|
#include <ucore/utils.h>
|
||||||
|
|||||||
Reference in New Issue
Block a user