8
/* Allocate space for typed object. */
9
#define _xmalloc(size, align) memalign(align, size)
10
#define xfree(ptr) free(ptr)
16
#define DEFAULT_ALIGN (sizeof(unsigned long))
17
#define malloc(size) _xmalloc(size, DEFAULT_ALIGN)
18
#define free(ptr) xfree(ptr)
19
#define realloc(ptr, size) _realloc(ptr, size)
21
/* Free any of the above. */
22
extern void xfree(const void *);
24
/* Underlying functions */
25
extern void *_xmalloc(size_t size, size_t align);
26
extern void *_realloc(void *ptr, size_t size);
30
static inline void *_xmalloc_array(size_t size, size_t align, size_t num)
32
/* Check for overflow. */
33
if (size && num > UINT_MAX / size)
35
return _xmalloc(size * num, align);
38
/* Allocate space for typed object. */
39
#define xmalloc(_type) ((_type *)_xmalloc(sizeof(_type), __alignof__(_type)))
41
/* Allocate space for array of typed objects. */
42
#define xmalloc_array(_type, _num) ((_type *)_xmalloc_array(sizeof(_type), __alignof__(_type), _num))
44
#endif /* __XMALLOC_H__ */