c_mem_safety/array.h
2025-04-25 01:50:15 +02:00

16 lines
338 B
C

#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); \
} \
}