blob: ef20b8c949d5a60db679ebc4605476fc20c63ea1 [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/* Memory management routine
2 Copyright (C) 1998 Kunihiro Ishiguro
3
4This file is part of GNU Zebra.
5
6GNU Zebra is free software; you can redistribute it and/or modify it
7under the terms of the GNU General Public License as published by the
8Free Software Foundation; either version 2, or (at your option) any
9later version.
10
11GNU Zebra is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Zebra; see the file COPYING. If not, write to the Free
18Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
1902111-1307, USA. */
20
21#ifndef _ZEBRA_MEMORY_H
22#define _ZEBRA_MEMORY_H
23
paul2fd2fd52005-04-15 11:47:15 +000024/* For pretty printing of memory allocate information. */
25struct memory_list
paul718e3742002-12-13 20:15:29 +000026{
paul2fd2fd52005-04-15 11:47:15 +000027 int index;
28 const char *format;
paul718e3742002-12-13 20:15:29 +000029};
30
paul2fd2fd52005-04-15 11:47:15 +000031struct mlist {
32 struct memory_list *list;
33 const char *name;
34};
35
paula7bca0f2005-04-27 12:44:54 +000036#include "lib/memtypes.h"
paule1e53ed2005-04-22 13:44:17 +000037
paul2fd2fd52005-04-15 11:47:15 +000038extern struct mlist mlists[];
39
40/* #define MEMORY_LOG */
paul718e3742002-12-13 20:15:29 +000041#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. */
paul8cc41982005-05-06 21:25:49 +000061extern void *zmalloc (int type, size_t size);
62extern void *zcalloc (int type, size_t size);
63extern void *zrealloc (int type, void *ptr, size_t size);
64extern void zfree (int type, void *ptr);
65extern char *zstrdup (int type, const char *str);
paul718e3742002-12-13 20:15:29 +000066
paul8cc41982005-05-06 21:25:49 +000067extern void *mtype_zmalloc (const char *file, int line, int type, size_t size);
paul718e3742002-12-13 20:15:29 +000068
paul8cc41982005-05-06 21:25:49 +000069extern void *mtype_zcalloc (const char *file, int line, int type,
70 size_t num, size_t size);
paul718e3742002-12-13 20:15:29 +000071
paul8cc41982005-05-06 21:25:49 +000072extern void *mtype_zrealloc (const char *file, int line, int type, void *ptr,
73 size_t size);
paul718e3742002-12-13 20:15:29 +000074
paul8cc41982005-05-06 21:25:49 +000075extern void mtype_zfree (const char *file, int line, int type,
76 void *ptr);
paul718e3742002-12-13 20:15:29 +000077
paul8cc41982005-05-06 21:25:49 +000078extern char *mtype_zstrdup (const char *file, int line, int type,
79 const char *str);
80extern void memory_init (void);
paul718e3742002-12-13 20:15:29 +000081
82#endif /* _ZEBRA_MEMORY_H */