Asterisk.org: Developer Documentation (28 Oct 2009)

Wed Oct 28 15:47:49 2009

## Asterisk developer's documentation

# astmm.h

Go to the documentation of this file.

    00001 /*
    00002  * Asterisk -- An open source telephony toolkit.
    00003  *
    00004  * Copyright (C) 1999 - 2005, Digium, Inc.
    00005  *
    00006  * Mark Spencer <markster@digium.com>
    00007  *
    00008  * See http://www.asterisk.org for more information about
    00009  * the Asterisk project. Please do not directly contact
    00010  * any of the maintainers of this project for assistance;
    00011  * the project provides a web site, mailing lists and IRC
    00012  * channels for your use.
    00013  *
    00014  * This program is free software, distributed under the terms of
    00015  * the GNU General Public License Version 2. See the LICENSE file
    00016  * at the top of the source tree.
    00017  */
    00018
    00019 /*! \file
    00020  * \brief Asterisk memory usage debugging
    00021  */
    00022
    00023 #ifndef NO_AST_MM
    00024 #ifndef _ASTERISK_ASTMM_H
    00025 #define _ASTERISK_ASTMM_H
    00026
    00027 #define __AST_DEBUG_MALLOC
    00028
    00029 /* Include these now to prevent them from being needed later */
    00030 #include <sys/types.h>
    00031 #include <stdlib.h>
    00032 #include <string.h>
    00033 #include <stdio.h>
    00034
    00035 /* Undefine any macros */
    00036 #undef malloc
    00037 #undef calloc
    00038 #undef realloc
    00039 #undef strdup
    00040 #undef strndup
    00041 #undef vasprintf
    00042
    00043 void *__ast_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func);
    00044 void *__ast_malloc(size_t size, const char *file, int lineno, const char *func);
    00045 void __ast_free(void *ptr, const char *file, int lineno, const char *func);
    00046 void *__ast_realloc(void *ptr, size_t size, const char *file, int lineno, const char *func);
    00047 char *__ast_strdup(const char *s, const char *file, int lineno, const char *func);
    00048 char *__ast_strndup(const char *s, size_t n, const char *file, int lineno, const char *func);
    00049 int __ast_vasprintf(char **strp, const char *format, va_list ap, const char *file, int lineno, const char *func);
    00050
    00051 void __ast_mm_init(void);
    00052
    00053
    00054 /* Provide our own definitions */
    00055 #define calloc(a,b) \
    00056    __ast_calloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
    00057
    00058 #define malloc(a) \
    00059    __ast_malloc(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
    00060
    00061 #define free(a) \
    00062    __ast_free(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
    00063
    00064 #define realloc(a,b) \
    00065    __ast_realloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
    00066
    00067 #define strdup(a) \
    00068    __ast_strdup(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
    00069
    00070 #define strndup(a,b) \
    00071    __ast_strndup(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
    00072
    00073 #define vasprintf(a,b,c) \
    00074    __ast_vasprintf(a,b,c,__FILE__, __LINE__, __PRETTY_FUNCTION__)
    00075
    00076 #else
    00077 #error "NEVER INCLUDE astmm.h DIRECTLY!!"
    00078 #endif /* _ASTERISK_ASTMM_H */
    00079 #endif