2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2006, Digium, Inc.
6 * Mark Spencer <markster@digium.com>
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
20 * \brief Asterisk memory usage debugging
28 #ifndef _ASTERISK_ASTMM_H
29 #define _ASTERISK_ASTMM_H
33 #define __AST_DEBUG_MALLOC
37 /* Include these now to prevent them from being needed later */
38 #include <sys/types.h>
44 /* Undefine any macros */
54 void *__ast_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func);
55 void *__ast_calloc_cache(size_t nmemb, size_t size, const char *file, int lineno, const char *func);
56 void *__ast_malloc(size_t size, const char *file, int lineno, const char *func);
57 void __ast_free(void *ptr, const char *file, int lineno, const char *func);
58 void *__ast_realloc(void *ptr, size_t size, const char *file, int lineno, const char *func);
59 char *__ast_strdup(const char *s, const char *file, int lineno, const char *func);
60 char *__ast_strndup(const char *s, size_t n, const char *file, int lineno, const char *func);
61 int __ast_asprintf(const char *file, int lineno, const char *func, char **strp, const char *format, ...)
62 __attribute__((format(printf, 5, 6)));
63 int __ast_vasprintf(char **strp, const char *format, va_list ap, const char *file, int lineno, const char *func)
64 __attribute__((format(printf, 2, 0)));
65 void __ast_mm_init(void);
68 /* Provide our own definitions */
70 __ast_calloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
72 #define ast_calloc(a,b) \
73 __ast_calloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
75 #define ast_calloc_cache(a,b) \
76 __ast_calloc_cache(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
79 __ast_malloc(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
81 #define ast_malloc(a) \
82 __ast_malloc(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
85 __ast_free(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
88 __ast_free(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
90 #define realloc(a,b) \
91 __ast_realloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
93 #define ast_realloc(a,b) \
94 __ast_realloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
97 __ast_strdup(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
99 #define ast_strdup(a) \
100 __ast_strdup(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
102 #define strndup(a,b) \
103 __ast_strndup(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
105 #define ast_strndup(a,b) \
106 __ast_strndup(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
108 #define asprintf(a, b, c...) \
109 __ast_asprintf(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, b, c)
111 #define ast_asprintf(a, b, c...) \
112 __ast_asprintf(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, b, c)
114 #define vasprintf(a,b,c) \
115 __ast_vasprintf(a,b,c,__FILE__, __LINE__, __PRETTY_FUNCTION__)
117 #define ast_vasprintf(a,b,c) \
118 __ast_vasprintf(a,b,c,__FILE__, __LINE__, __PRETTY_FUNCTION__)
120 #endif /* !STANDALONE */
123 #error "NEVER INCLUDE astmm.h DIRECTLY!!"
124 #endif /* _ASTERISK_ASTMM_H */