#ifndef APFL_INTERNAL_H #define APFL_INTERNAL_H #ifdef __cplusplus extern "C" { #endif #include #include #include "common.h" #define DEINIT_LIST(items, len, item_deinit) \ do { \ if ((items) == NULL) { \ break; \ } \ for (size_t i = 0; i < (len); i++) { \ item_deinit(&((items)[i])); \ } \ len = 0; \ free(items); \ (items) = NULL; \ } while(0) #define MOVEPTR(out, in) \ do { \ out = in; \ in = NULL; \ } while(0) // ALLOC_LIST allocates memory for a list of n values of type T. // n == 0 will always result in NULL (not guaranteed by calloc()) and the // result will be cast into a pointer to T (this way the compiler can warn us, // if we try to allocate memory for a wrong type). Also if we always use // calloc(), the allocated memory is in a defined state. #define ALLOC_LIST(T, n) (T *)((n) == 0 ? NULL : calloc((n), sizeof(T))) #define ALLOC(T) ALLOC_LIST(T, 1) // Aliases to commonly used functions / macros #define DESTROY APFL_DESTROY // Internal use only functions void apfl_print_indented(unsigned indent, FILE *, const char* fmt, ...); /* Decrease a refererence count. Returns true, if the object should be freed. */ bool apfl_refcount_dec(unsigned *); #ifdef __cplusplus } #endif #endif