13 #ifndef FIRM_ADT_XMALLOC_H
14 #define FIRM_ADT_XMALLOC_H
22 # if defined(__GNUC__)
23 # define alloca(x) __builtin_alloca(x)
24 # elif defined(__WIN32)
27 # error do not know how to get alloca
44 FIRM_API
void *
xmalloc(
size_t size);
50 FIRM_API
void *
xrealloc(
void *ptr,
size_t size);
56 FIRM_API
char *
xstrdup(
const char *str);
61 #define XMALLOCN(type, n) ((type*)xmalloc(sizeof(type) * (n)))
66 #define XMALLOCNZ(type, n) ((type*)memset(xmalloc(sizeof(type) * (n)), 0, sizeof(type) * (n)))
71 #define XMALLOC(type) XMALLOCN(type, 1)
76 #define XMALLOCZ(type) XMALLOCNZ(type, 1)
81 #define XREALLOC(ptr, type, n) ((type*)xrealloc(ptr, sizeof(type) * (n)))
86 #define XMALLOCF(type, member, n) ((type*)xmalloc(offsetof(type, member) + sizeof(*((type*)0)->member) * (n)))
92 #define XMALLOCFZ(type, member, n) ((type*)memset(XMALLOCF(type, member, (n)), 0, offsetof(type, member) + sizeof(*((type*)0)->member) * (n)))
97 #define ALLOCAN(type, n) ((type*)alloca(sizeof(type) * (n)))
102 #define ALLOCANZ(type, n) ((type*)memset((type*)alloca(sizeof(type) * (n)), 0, sizeof(type) * (n)))
107 #define ALLOCAF(type, member, n) ((type*)alloca(offsetof(type, member) + sizeof(*((type*)0)->member) * (n)))
112 #define OALLOCN(obst, type, n) ((type*)obstack_alloc((obst), sizeof(type) * (n)))
117 #define OALLOCNZ(obst, type, n) ((type*)memset(OALLOCN((obst), type, (n)), 0, sizeof(type) * (n)))
122 #define OALLOC(obst, type) OALLOCN(obst, type, 1)
127 #define OALLOCZ(obst, type) OALLOCNZ(obst, type, 1)
133 #define OALLOCF(obst, type, member, n) ((type*)obstack_alloc((obst), offsetof(type, member) + sizeof(*((type*)0)->member) * (n)))
139 #define OALLOCFZ(obst, type, member, n) ((type*)memset(OALLOCF((obst), type, member, (n)), 0, offsetof(type, member) + sizeof(*((type*)0)->member) * (n)))
void * xmalloc(size_t size)
Allocate size bytes on the heap.
void * xrealloc(void *ptr, size_t size)
Chane size of a previously allocated memory block to size bytes.
char * xstrdup(const char *str)
Allocates memory and copies string str into it.