GenSVM
Macros
dbg.h File Reference

Debug macros for the minunit framework. More...

#include <stdio.h>
#include <errno.h>
#include <string.h>
Include dependency graph for dbg.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define debug(M, ...)
 
#define clean_errno()   (errno == 0 ? "None" : strerror(errno))
 
#define log_err(M, ...)
 
#define log_warn(M, ...)
 
#define log_info(M, ...)
 
#define check(A, M, ...)
 
#define sentinel(M, ...)   { log_err(M, ##__VA_ARGS__); errno=0; goto error; }
 
#define check_mem(A)   check((A), "Out of memory.");
 
#define check_debug(A, M, ...)
 

Detailed Description

Debug macros for the minunit framework.

Author
Zed Shaw

These debug macros come from Zed Shaw's book Learn C The Hard Way, and are used for the testing framework of GenSVM.

See also
minunit.h

Definition in file dbg.h.

Macro Definition Documentation

◆ check

#define check (   A,
  M,
  ... 
)
Value:
if(!(A)) { log_err(M, ##__VA_ARGS__); errno=0; \
goto error; }
#define log_err(M,...)
Definition: dbg.h:41

Check a condition an log an error with the given message if it fails

Definition at line 59 of file dbg.h.

◆ check_debug

#define check_debug (   A,
  M,
  ... 
)
Value:
if (!(A)) { debug(M, ##__VA_ARGS__); errno=0; \
goto error; }
#define debug(M,...)
Definition: dbg.h:29

Check a condition and log to debug if it fails, and reset errno

Definition at line 75 of file dbg.h.

◆ check_mem

#define check_mem (   A)    check((A), "Out of memory.");

Check a memory allocation

Definition at line 70 of file dbg.h.

◆ clean_errno

#define clean_errno ( )    (errno == 0 ? "None" : strerror(errno))

Return a clean string of the current errno

Definition at line 36 of file dbg.h.

◆ debug

#define debug (   M,
  ... 
)
Value:
fprintf(stderr, "DEBUG %s:%d: " M "\n", __FILE__, \
__LINE__, ##__VA_ARGS__)

Print debug info to stderr

Definition at line 29 of file dbg.h.

◆ log_err

#define log_err (   M,
  ... 
)
Value:
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " M "\n", \
__FILE__, __LINE__, clean_errno(), ##__VA_ARGS__)
#define clean_errno()
Definition: dbg.h:36

Log an error to stderr

Definition at line 41 of file dbg.h.

◆ log_info

#define log_info (   M,
  ... 
)
Value:
fprintf(stderr, "[INFO] (%s:%d) " M "\n", \
__FILE__, __LINE__, ##__VA_ARGS__)

Log info to stderr

Definition at line 53 of file dbg.h.

◆ log_warn

#define log_warn (   M,
  ... 
)
Value:
fprintf(stderr, "[WARN] (%s:%d: errno: %s) " M "\n", \
__FILE__, __LINE__, clean_errno(), ##__VA_ARGS__)
#define clean_errno()
Definition: dbg.h:36

Log a warning to stderr

Definition at line 47 of file dbg.h.

◆ sentinel

#define sentinel (   M,
  ... 
)    { log_err(M, ##__VA_ARGS__); errno=0; goto error; }

Log an error with the given message and reset errno

Definition at line 65 of file dbg.h.