c_mem_safety/array.h

16 lines
338 B
C
Raw Normal View History

#include <stdlib.h>
#include "handle.h"
/* Generic array macro */
#define Array(T,AT) struct AT { \
size_t count; \
T *v; \
}; handle(AT) { \
if(state == HANDLE_CREAT) { \
self->count = *(size_t*) data; \
self->v = (T*) calloc(self->count, sizeof(T)); \
} else if (state == HANDLE_DESTR){ \
if(self->v) free(self->v); \
} \
}