30 #ifndef _ASTERISK_ASTMM_H
31 #define _ASTERISK_ASTMM_H
34 void *ast_std_malloc(
size_t size) attribute_malloc;
35 void *ast_std_calloc(
size_t nmemb,
size_t size) attribute_malloc;
36 void *ast_std_realloc(
void *ptr,
size_t size);
37 void ast_std_free(
void *ptr);
47 void *__ast_calloc(
size_t nmemb,
size_t size,
const char *file,
int lineno,
const char *func) attribute_malloc;
48 void *__ast_calloc_cache(
size_t nmemb,
size_t size,
const char *file,
int lineno,
const char *func) attribute_malloc;
49 void *__ast_malloc(
size_t size,
const char *file,
int lineno,
const char *func) attribute_malloc;
50 void __ast_free(
void *ptr,
const char *file,
int lineno,
const char *func);
51 void *__ast_realloc(
void *ptr,
size_t size,
const char *file,
int lineno,
const char *func);
52 char *__ast_strdup(
const char *s,
const char *file,
int lineno,
const char *func) attribute_malloc;
53 char *__ast_strndup(
const char *s,
size_t n,
const char *file,
int lineno,
const char *func) attribute_malloc;
54 int __ast_asprintf(
const char *file,
int lineno,
const char *func,
char **strp,
const char *format, ...)
55 __attribute__((format(printf, 5, 6)));
56 int __ast_vasprintf(
char **strp, const
char *format, va_list ap, const
char *file,
int lineno, const
char *func)
57 __attribute__((format(printf, 2, 0)));
61 void *__ast_repl_calloc(
size_t nmemb,
size_t size, const
char *file,
int lineno, const
char *func) attribute_malloc;
62 void *__ast_repl_malloc(
size_t size, const
char *file,
int lineno, const
char *func) attribute_malloc;
63 void *__ast_repl_realloc(
void *ptr,
size_t size, const
char *file,
int lineno, const
char *func);
64 char *__ast_repl_strdup(const
char *s, const
char *file,
int lineno, const
char *func) attribute_malloc;
65 char *__ast_repl_strndup(const
char *s,
size_t n, const
char *file,
int lineno, const
char *func) attribute_malloc;
66 int __ast_repl_asprintf(const
char *file,
int lineno, const
char *func,
char **strp, const
char *format, ...)
67 __attribute__((format(printf, 5, 6)));
68 int __ast_repl_vasprintf(
char **strp, const
char *format, va_list ap, const
char *file,
int lineno, const
char *func)
69 __attribute__((format(printf, 2, 0)));
99 #define ASTMM_REDIRECT 1
109 #define ASTMM_IGNORE 2
113 #if !defined(ASTMM_LIBC)
115 #define ASTMM_LIBC ASTMM_BLOCK
118 #if ASTMM_LIBC == ASTMM_IGNORE
132 #if ASTMM_LIBC == ASTMM_REDIRECT
135 #define calloc(nmemb, size) \
136 __ast_repl_calloc(nmemb, size, __FILE__, __LINE__, __PRETTY_FUNCTION__)
137 #define malloc(size) \
138 __ast_repl_malloc(size, __FILE__, __LINE__, __PRETTY_FUNCTION__)
140 __ast_free(ptr, __FILE__, __LINE__, __PRETTY_FUNCTION__)
141 #define realloc(ptr, size) \
142 __ast_repl_realloc(ptr, size, __FILE__, __LINE__, __PRETTY_FUNCTION__)
144 __ast_repl_strdup(s, __FILE__, __LINE__, __PRETTY_FUNCTION__)
145 #define strndup(s, n) \
146 __ast_repl_strndup(s, n, __FILE__, __LINE__, __PRETTY_FUNCTION__)
147 #define asprintf(strp, format, args...) \
148 __ast_repl_asprintf(__FILE__, __LINE__, __PRETTY_FUNCTION__, strp, format, args)
149 #define vasprintf(strp, format, ap) \
150 __ast_repl_vasprintf(strp, format, ap, __FILE__, __LINE__, __PRETTY_FUNCTION__)
152 #elif ASTMM_LIBC == ASTMM_BLOCK
155 #define calloc(a, b) \
156 Do_not_use_calloc__use_ast_calloc->fail(a, b)
158 Do_not_use_malloc__use_ast_malloc->fail(a)
160 Do_not_use_free__use_ast_free_or_ast_std_free_for_remotely_allocated_memory->fail(a)
161 #define realloc(a, b) \
162 Do_not_use_realloc__use_ast_realloc->fail(a, b)
164 Do_not_use_strdup__use_ast_strdup->fail(a)
165 #define strndup(a, b) \
166 Do_not_use_strndup__use_ast_strndup->fail(a, b)
167 #define asprintf(a, b, c...) \
168 Do_not_use_asprintf__use_ast_asprintf->fail(a, b, c)
169 #define vasprintf(a, b, c) \
170 Do_not_use_vasprintf__use_ast_vasprintf->fail(a, b, c)
173 #error "Unacceptable value for the macro ASTMM_LIBC"
180 #define ast_free(a) \
181 __ast_free(a, __FILE__, __LINE__, __PRETTY_FUNCTION__)
191 #define ast_malloc(len) \
192 __ast_malloc((len), __FILE__, __LINE__, __PRETTY_FUNCTION__)
202 #define ast_calloc(num, len) \
203 __ast_calloc((num), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)
215 #define ast_calloc_cache(num, len) \
216 __ast_calloc_cache((num), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)
226 #define ast_realloc(p, len) \
227 __ast_realloc((p), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)
241 #define ast_strdup(str) \
242 __ast_strdup((str), __FILE__, __LINE__, __PRETTY_FUNCTION__)
256 #define ast_strndup(str, len) \
257 __ast_strndup((str), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)
267 #define ast_asprintf(ret, fmt, ...) \
268 __ast_asprintf(__FILE__, __LINE__, __PRETTY_FUNCTION__, (ret), (fmt), __VA_ARGS__)
278 #define ast_vasprintf(ret, fmt, ap) \
279 __ast_vasprintf((ret), (fmt), (ap), __FILE__, __LINE__, __PRETTY_FUNCTION__)
288 #define ast_alloca(size) __builtin_alloca(size)
290 #if !defined(ast_strdupa) && defined(__GNUC__)
298 #define ast_strdupa(s) \
301 const char *__old = (s); \
302 size_t __len = strlen(__old) + 1; \
303 char *__new = __builtin_alloca(__len); \
304 memcpy (__new, __old, __len); \
310 #error "NEVER INCLUDE astmm.h DIRECTLY!!"
void ast_free_ptr(void *ptr)
free() wrapper