Debian Codegraph @

third-party/pjproject/patches/asterisk_malloc_debug.h

raw symbols SCIP
1 /*
2 * Copyright (C) 2016 George Joseph <[email protected]>
3 *
4 * See http://www.asterisk.org for more information about
5 * the Asterisk project. Please do not directly contact
6 * any of the maintainers of this project for assistance;
7 * the project provides a web site, mailing lists and IRC
8 * channels for your use.
9 *
10 * This program is free software, distributed under the terms of
11 * the GNU General Public License Version 2. See the LICENSE file
12 * at the top of the source tree.
13 */
14
15 #ifndef ASTERISK_MALLOC_DEBUG_H_
16 #define ASTERISK_MALLOC_DEBUG_H_
17
18 /* Include these now to prevent them from messing up MALLOC_DEBUG */
19 #include <sys/types.h>
20 #include <pj/compat/string.h>
21 #include <pj/compat/stdarg.h>
22 #include <pj/compat/malloc.h>
23
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27
28 #ifndef attribute_malloc
29 #ifdef HAVE_ATTRIBUTE_malloc
30 /* HAVE_ATTRIBUTE_malloc is never defined from pjproject. This is here as a placeholder
31 * hopefully we can just use __attribute__((malloc)) unconditionally. */
32 #define attribute_malloc __attribute__((malloc))
33 #else
34 #define attribute_malloc
35 #endif
36 #endif
37
38 int __ast_repl_asprintf(const char *file, int lineno, const char *func, char **strp, const char *format, ...)
39 __attribute__((format(printf, 5, 6)));
40 void *__ast_repl_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func) attribute_malloc;
41 void __ast_free(void *ptr, const char *file, int lineno, const char *func);
42 void *__ast_repl_malloc(size_t size, const char *file, int lineno, const char *func) attribute_malloc;
43 void *__ast_repl_realloc(void *ptr, size_t size, const char *file, int lineno, const char *func);
44 char *__ast_repl_strdup(const char *s, const char *file, int lineno, const char *func) attribute_malloc;
45 char *__ast_repl_strndup(const char *s, size_t n, const char *file, int lineno, const char *func) attribute_malloc;
46 int __ast_repl_vasprintf(char **strp, const char *format, va_list ap, const char *file, int lineno, const char *func)
47 __attribute__((format(printf, 2, 0)));
48
49 /* Undefine any macros */
50 #undef asprintf
51 #undef calloc
52 #undef free
53 #undef malloc
54 #undef realloc
55 #undef strdup
56 #undef strndup
57 #undef vasprintf
58
59 /* Provide our own definitions */
60 #define asprintf(strp, format, args...) \
61 __ast_repl_asprintf(__FILE__, __LINE__, __PRETTY_FUNCTION__, strp, format, args)
62
63 #define calloc(nmemb, size) \
64 __ast_repl_calloc(nmemb, size, __FILE__, __LINE__, __PRETTY_FUNCTION__)
65
66 #define free(ptr) \
67 __ast_free(ptr, __FILE__, __LINE__, __PRETTY_FUNCTION__)
68
69 #define malloc(size) \
70 __ast_repl_malloc(size, __FILE__, __LINE__, __PRETTY_FUNCTION__)
71
72 #define realloc(ptr, size) \
73 __ast_repl_realloc(ptr, size, __FILE__, __LINE__, __PRETTY_FUNCTION__)
74
75 #define strdup(s) \
76 __ast_repl_strdup(s, __FILE__, __LINE__, __PRETTY_FUNCTION__)
77
78 #define strndup(s, n) \
79 __ast_repl_strndup(s, n, __FILE__, __LINE__, __PRETTY_FUNCTION__)
80
81 #define vasprintf(strp, format, ap) \
82 __ast_repl_vasprintf(strp, format, ap, __FILE__, __LINE__, __PRETTY_FUNCTION__)
83
84 #ifdef __cplusplus
85 }
86 #endif
87
88 #endif /* ASTERISK_MALLOC_DEBUG_H_ */