libFirm 1.20
|
00001 /* 00002 * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved. 00003 * 00004 * This file is part of libFirm. 00005 * 00006 * This file may be distributed and/or modified under the terms of the 00007 * GNU General Public License version 2 as published by the Free Software 00008 * Foundation and appearing in the file LICENSE.GPL included in the 00009 * packaging of this file. 00010 * 00011 * Licensees holding valid libFirm Professional Edition licenses may use 00012 * this file in accordance with the libFirm Commercial License. 00013 * Agreement provided with the Software. 00014 * 00015 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00016 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00017 * PURPOSE. 00018 */ 00019 00027 #ifndef FIRM_ADT_XMALLOC_H 00028 #define FIRM_ADT_XMALLOC_H 00029 00030 #include <stddef.h> 00031 #include <stdlib.h> 00032 #include <string.h> 00033 00034 /* Includes for alloca() */ 00035 #ifdef _WIN32 00036 #include <malloc.h> 00037 #endif 00038 00039 #include "../begin.h" 00040 00052 FIRM_API void *xmalloc(size_t size); 00058 FIRM_API void *xrealloc(void *ptr, size_t size); 00064 FIRM_API char *xstrdup(const char *str); 00069 #define xfree(ptr) free(ptr) 00070 00074 #define XMALLOCN(type, n) ((type*)xmalloc(sizeof(type) * (n))) 00075 00079 #define XMALLOCNZ(type, n) ((type*)memset(xmalloc(sizeof(type) * (n)), 0, sizeof(type) * (n))) 00080 00084 #define XMALLOC(type) XMALLOCN(type, 1) 00085 00089 #define XMALLOCZ(type) XMALLOCNZ(type, 1) 00090 00094 #define XREALLOC(ptr, type, n) ((type*)xrealloc(ptr, sizeof(type) * (n))) 00095 00099 #define XMALLOCF(type, member, n) ((type*)xmalloc(offsetof(type, member) + sizeof(*((type*)0)->member) * (n))) 00100 00105 #define XMALLOCFZ(type, member, n) ((type*)memset(XMALLOCF(type, member, (n)), 0, offsetof(type, member) + sizeof(*((type*)0)->member) * (n))) 00106 00110 #define ALLOCAN(type, n) ((type*)alloca(sizeof(type) * (n))) 00111 00115 #define ALLOCANZ(type, n) ((type*)memset((type*)alloca(sizeof(type) * (n)), 0, sizeof(type) * (n))) 00116 00120 #define OALLOCN(obst, type, n) ((type*)obstack_alloc((obst), sizeof(type) * (n))) 00121 00125 #define OALLOCNZ(obst, type, n) ((type*)memset(OALLOCN((obst), type, (n)), 0, sizeof(type) * (n))) 00126 00130 #define OALLOC(obst, type) OALLOCN(obst, type, 1) 00131 00135 #define OALLOCZ(obst, type) OALLOCNZ(obst, type, 1) 00136 00141 #define OALLOCF(obst, type, member, n) ((type*)obstack_alloc((obst), offsetof(type, member) + sizeof(*((type*)0)->member) * (n))) 00142 00147 #define OALLOCFZ(obst, type, member, n) ((type*)memset(OALLOCF((obst), type, member, (n)), 0, offsetof(type, member) + sizeof(*((type*)0)->member) * (n))) 00148 00151 #include "../end.h" 00152 00153 #endif