Impl basic ws binary proto with data and execution state manipulation
This commit is contained in:
42
inc/panic.h
Normal file
42
inc/panic.h
Normal file
@@ -0,0 +1,42 @@
|
||||
#ifndef __PANIC_H__
|
||||
#define __PANIC_H__
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <execinfo.h>
|
||||
|
||||
#ifndef PANIC_FD
|
||||
#define PANIC_FD stderr
|
||||
#endif //ifndef PANIC_FD
|
||||
|
||||
#ifndef PANIC_STRACE_LEN
|
||||
#define PANIC_STRACE_LEN 32
|
||||
#endif //ifndef PANIC_STRACE_LEN
|
||||
|
||||
void print_stacktrace(FILE* fd);
|
||||
|
||||
#define panic(...) \
|
||||
do { \
|
||||
fprintf(PANIC_FD, "Panic at %s:%d\n", __FILE__, __LINE__); \
|
||||
fprintf(PANIC_FD, "Panic message:\n\t" __VA_ARGS__); \
|
||||
print_stacktrace(PANIC_FD); \
|
||||
abort(); \
|
||||
} while(0)
|
||||
|
||||
#define NULL_GUARD(ptr, ...) \
|
||||
do { \
|
||||
if((ptr) == NULL) \
|
||||
{ \
|
||||
if(sizeof(#__VA_ARGS__) > 1) \
|
||||
{ \
|
||||
panic(__VA_ARGS__); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
panic("NULL detected in %s", #ptr); \
|
||||
} \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
|
||||
#endif //ifndef __PANIC_H__
|
||||
Reference in New Issue
Block a user