paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1 | /* Memory management routine |
| 2 | Copyright (C) 1998 Kunihiro Ishiguro |
| 3 | |
| 4 | This file is part of GNU Zebra. |
| 5 | |
| 6 | GNU Zebra is free software; you can redistribute it and/or modify it |
| 7 | under the terms of the GNU General Public License as published by the |
| 8 | Free Software Foundation; either version 2, or (at your option) any |
| 9 | later version. |
| 10 | |
| 11 | GNU Zebra is distributed in the hope that it will be useful, but |
| 12 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License |
| 17 | along with GNU Zebra; see the file COPYING. If not, write to the Free |
| 18 | Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 19 | 02111-1307, USA. */ |
| 20 | |
| 21 | #ifndef _ZEBRA_MEMORY_H |
| 22 | #define _ZEBRA_MEMORY_H |
| 23 | |
paul | 2fd2fd5 | 2005-04-15 11:47:15 +0000 | [diff] [blame^] | 24 | #include "memtypes.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 25 | |
paul | 2fd2fd5 | 2005-04-15 11:47:15 +0000 | [diff] [blame^] | 26 | /* For pretty printing of memory allocate information. */ |
| 27 | struct memory_list |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 28 | { |
paul | 2fd2fd5 | 2005-04-15 11:47:15 +0000 | [diff] [blame^] | 29 | int index; |
| 30 | const char *format; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 31 | }; |
| 32 | |
paul | 2fd2fd5 | 2005-04-15 11:47:15 +0000 | [diff] [blame^] | 33 | struct mlist { |
| 34 | struct memory_list *list; |
| 35 | const char *name; |
| 36 | }; |
| 37 | |
| 38 | extern struct mlist mlists[]; |
| 39 | |
| 40 | /* #define MEMORY_LOG */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 41 | #ifdef MEMORY_LOG |
| 42 | #define XMALLOC(mtype, size) \ |
| 43 | mtype_zmalloc (__FILE__, __LINE__, (mtype), (size)) |
| 44 | #define XCALLOC(mtype, size) \ |
| 45 | mtype_zcalloc (__FILE__, __LINE__, (mtype), (size)) |
| 46 | #define XREALLOC(mtype, ptr, size) \ |
| 47 | mtype_zrealloc (__FILE__, __LINE__, (mtype), (ptr), (size)) |
| 48 | #define XFREE(mtype, ptr) \ |
| 49 | mtype_zfree (__FILE__, __LINE__, (mtype), (ptr)) |
| 50 | #define XSTRDUP(mtype, str) \ |
| 51 | mtype_zstrdup (__FILE__, __LINE__, (mtype), (str)) |
| 52 | #else |
| 53 | #define XMALLOC(mtype, size) zmalloc ((mtype), (size)) |
| 54 | #define XCALLOC(mtype, size) zcalloc ((mtype), (size)) |
| 55 | #define XREALLOC(mtype, ptr, size) zrealloc ((mtype), (ptr), (size)) |
| 56 | #define XFREE(mtype, ptr) zfree ((mtype), (ptr)) |
| 57 | #define XSTRDUP(mtype, str) zstrdup ((mtype), (str)) |
| 58 | #endif /* MEMORY_LOG */ |
| 59 | |
| 60 | /* Prototypes of memory function. */ |
| 61 | void *zmalloc (int type, size_t size); |
| 62 | void *zcalloc (int type, size_t size); |
| 63 | void *zrealloc (int type, void *ptr, size_t size); |
| 64 | void zfree (int type, void *ptr); |
hasso | b04c699 | 2004-10-04 19:10:31 +0000 | [diff] [blame] | 65 | char *zstrdup (int type, const char *str); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 66 | |
| 67 | void *mtype_zmalloc (const char *file, |
| 68 | int line, |
| 69 | int type, |
| 70 | size_t size); |
| 71 | |
| 72 | void *mtype_zcalloc (const char *file, |
| 73 | int line, |
| 74 | int type, |
| 75 | size_t num, |
| 76 | size_t size); |
| 77 | |
| 78 | void *mtype_zrealloc (const char *file, |
| 79 | int line, |
| 80 | int type, |
| 81 | void *ptr, |
| 82 | size_t size); |
| 83 | |
| 84 | void mtype_zfree (const char *file, |
| 85 | int line, |
| 86 | int type, |
| 87 | void *ptr); |
| 88 | |
| 89 | char *mtype_zstrdup (const char *file, |
| 90 | int line, |
| 91 | int type, |
hasso | b04c699 | 2004-10-04 19:10:31 +0000 | [diff] [blame] | 92 | const char *str); |
ajs | f858e49 | 2004-11-16 14:25:30 +0000 | [diff] [blame] | 93 | void memory_init (void); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 94 | |
| 95 | #endif /* _ZEBRA_MEMORY_H */ |