hermespy-rt

Minimalistic signal processing ray-tracer in C
git clone https://git.ea.contact/hermespy-rt
Log | Files | Refs

common.h (690B)


      1 #ifndef COMMON_H
      2 #define COMMON_H
      3 
      4 #define IN
      5 #define OUT
      6 
      7 #include <stdlib.h> /* for exit */
      8 
      9 #define FREE_POINTERS(...) \
     10   do {                            \
     11     if (sizeof((int[]){__VA_ARGS__}) > 0) { \
     12     void *ptrs[] = {__VA_ARGS__};\
     13     size_t cnt = sizeof(ptrs) / sizeof(ptrs[0]); \
     14     for (size_t i = 0; i < cnt; i++) \
     15       free(ptrs[i]);          \
     16     }                          \
     17   } while (0)
     18 
     19 /* Variadic arguments after rc are the pointers to free */
     20 #define PERROR_CLEANUP_EXIT(msg, rc, ...) \
     21   do {                            \
     22     perror(msg);                \
     23     FREE_POINTERS(__VA_ARGS__); \
     24     exit(rc);                    \
     25   } while (0)
     26 
     27 #endif /* COMMON_H */