libFirm 1.20
libfirm/adt/xmalloc.h File Reference

never failing wrappers for malloc() & friends. More...

#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include "../begin.h"
#include "../end.h"

Go to the source code of this file.

Defines

#define xfree(ptr)   free(ptr)
 Another name for the free function.
#define XMALLOCN(type, n)   ((type*)xmalloc(sizeof(type) * (n)))
 Allocate n objects of a certain type.
#define XMALLOCNZ(type, n)   ((type*)memset(xmalloc(sizeof(type) * (n)), 0, sizeof(type) * (n)))
 Allocate n objects of a certain type and zero them.
#define XMALLOC(type)   XMALLOCN(type, 1)
 Allocate one object of a certain type.
#define XMALLOCZ(type)   XMALLOCNZ(type, 1)
 Allocate one object of a certain type and zero it.
#define XREALLOC(ptr, type, n)   ((type*)xrealloc(ptr, sizeof(type) * (n)))
 Reallocate n objects of a certain type.
#define XMALLOCF(type, member, n)   ((type*)xmalloc(offsetof(type, member) + sizeof(*((type*)0)->member) * (n)))
 Allocate an object with n elements of a flexible array member.
#define XMALLOCFZ(type, member, n)   ((type*)memset(XMALLOCF(type, member, (n)), 0, offsetof(type, member) + sizeof(*((type*)0)->member) * (n)))
 Allocate an object with n elements of a flexible array member and zero the whole object.
#define ALLOCAN(type, n)   ((type*)alloca(sizeof(type) * (n)))
 Allocate n objects of a certain type on the stack.
#define ALLOCANZ(type, n)   ((type*)memset((type*)alloca(sizeof(type) * (n)), 0, sizeof(type) * (n)))
 Allocate n objects of a certain type on the stack and zero them.
#define OALLOCN(obst, type, n)   ((type*)obstack_alloc((obst), sizeof(type) * (n)))
 Allocate n objects of a certain type on the given obstack.
#define OALLOCNZ(obst, type, n)   ((type*)memset(OALLOCN((obst), type, (n)), 0, sizeof(type) * (n)))
 Allocate n objects of a certain type on the given obstack and zero them.
#define OALLOC(obst, type)   OALLOCN(obst, type, 1)
 Allocate one object of a certain type on the given obstack.
#define OALLOCZ(obst, type)   OALLOCNZ(obst, type, 1)
 Allocate one object of a certain type on the given obstack and zero it.
#define OALLOCF(obst, type, member, n)   ((type*)obstack_alloc((obst), offsetof(type, member) + sizeof(*((type*)0)->member) * (n)))
 Allocate an object with n elements of a flexible array member on the given obstck.
#define OALLOCFZ(obst, type, member, n)   ((type*)memset(OALLOCF((obst), type, member, (n)), 0, offsetof(type, member) + sizeof(*((type*)0)->member) * (n)))
 Allocate an object with n elements of a flexible array member on the given obstack and zero the whole object.

Functions

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.

Detailed Description

never failing wrappers for malloc() & friends.

Author:
Markus Armbruster
Note:
The functions here never fail because they simply abort your program in case of an error.

Definition in file xmalloc.h.