diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/asterisk/astmm.h | 26 | ||||
-rw-r--r-- | include/asterisk/chanvars.h | 2 | ||||
-rw-r--r-- | include/asterisk/config.h | 2 | ||||
-rw-r--r-- | include/asterisk/hashtab.h | 14 | ||||
-rw-r--r-- | include/asterisk/heap.h | 4 | ||||
-rw-r--r-- | include/asterisk/strings.h | 6 | ||||
-rw-r--r-- | include/asterisk/utils.h | 200 |
7 files changed, 115 insertions, 139 deletions
diff --git a/include/asterisk/astmm.h b/include/asterisk/astmm.h index 83c34bed3..e129dc034 100644 --- a/include/asterisk/astmm.h +++ b/include/asterisk/astmm.h @@ -174,35 +174,11 @@ void __ast_mm_init_phase_2(void); #endif -/* Provide our own definitions */ - -#define ast_calloc(a,b) \ - __ast_calloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__) - -#define ast_calloc_cache(a,b) \ - __ast_calloc_cache(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__) - -#define ast_malloc(a) \ - __ast_malloc(a,__FILE__, __LINE__, __PRETTY_FUNCTION__) +/* Provide our own definition for ast_free */ #define ast_free(a) \ __ast_free(a,__FILE__, __LINE__, __PRETTY_FUNCTION__) -#define ast_realloc(a,b) \ - __ast_realloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__) - -#define ast_strdup(a) \ - __ast_strdup(a,__FILE__, __LINE__, __PRETTY_FUNCTION__) - -#define ast_strndup(a,b) \ - __ast_strndup(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__) - -#define ast_asprintf(a, b, c...) \ - __ast_asprintf(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, b, c) - -#define ast_vasprintf(a,b,c) \ - __ast_vasprintf(a,b,c,__FILE__, __LINE__, __PRETTY_FUNCTION__) - #endif /* !STANDALONE */ #else diff --git a/include/asterisk/chanvars.h b/include/asterisk/chanvars.h index 3693e2a3a..2040c7b65 100644 --- a/include/asterisk/chanvars.h +++ b/include/asterisk/chanvars.h @@ -35,7 +35,7 @@ AST_LIST_HEAD_NOLOCK(varshead, ast_var_t); struct varshead *ast_var_list_create(void); void ast_var_list_destroy(struct varshead *head); -#ifdef MALLOC_DEBUG +#ifdef __AST_DEBUG_MALLOC struct ast_var_t *_ast_var_assign(const char *name, const char *value, const char *file, int lineno, const char *function); #define ast_var_assign(a,b) _ast_var_assign(a,b,__FILE__,__LINE__,__PRETTY_FUNCTION__) #else diff --git a/include/asterisk/config.h b/include/asterisk/config.h index 287635a8e..4944a3af2 100644 --- a/include/asterisk/config.h +++ b/include/asterisk/config.h @@ -907,7 +907,7 @@ void ast_category_destroy(struct ast_category *cat); struct ast_variable *ast_category_detach_variables(struct ast_category *cat); void ast_category_rename(struct ast_category *cat, const char *name); -#ifdef MALLOC_DEBUG +#ifdef __AST_DEBUG_MALLOC struct ast_variable *_ast_variable_new(const char *name, const char *value, const char *filename, const char *file, const char *function, int lineno); #define ast_variable_new(name, value, filename) _ast_variable_new(name, value, filename, __FILE__, __PRETTY_FUNCTION__, __LINE__) #else diff --git a/include/asterisk/hashtab.h b/include/asterisk/hashtab.h index 17eff7048..cfe035b28 100644 --- a/include/asterisk/hashtab.h +++ b/include/asterisk/hashtab.h @@ -251,7 +251,7 @@ unsigned int ast_hashtab_hash_short(const short num); * \param hash a func ptr to do the hashing * \param do_locking use locks to guarantee safety of iterators/insertion/deletion -- real simpleminded right now */ -#if (defined(MALLOC_DEBUG) && !defined(STANDALONE)) +#ifdef __AST_DEBUG_MALLOC struct ast_hashtab * _ast_hashtab_create(int initial_buckets, int (*compare)(const void *a, const void *b), int (*resize)(struct ast_hashtab *), @@ -294,7 +294,7 @@ void ast_hashtab_destroy( struct ast_hashtab *tab, void (*objdestroyfunc)(void * * \retval 1 on success * \retval 0 if there's a problem */ -#if (defined(MALLOC_DEBUG) && !defined(STANDALONE)) +#ifdef __AST_DEBUG_MALLOC int _ast_hashtab_insert_immediate(struct ast_hashtab *tab, const void *obj, const char *file, int lineno, const char *func); #define ast_hashtab_insert_immediate(a,b) _ast_hashtab_insert_immediate(a, b, __FILE__, __LINE__, __PRETTY_FUNCTION__) #else @@ -311,7 +311,7 @@ int ast_hashtab_insert_immediate(struct ast_hashtab *tab, const void *obj); * \retval 1 on success * \retval 0 if there's a problem */ -#if (defined(MALLOC_DEBUG) && !defined(STANDALONE)) +#ifdef __AST_DEBUG_MALLOC int _ast_hashtab_insert_immediate_bucket(struct ast_hashtab *tab, const void *obj, unsigned int h, const char *file, int lineno, const char *func); #define ast_hashtab_insert_immediate_bucket(a,b,c) _ast_hashtab_insert_immediate_bucket(a, b, c, __FILE__, __LINE__, __PRETTY_FUNCTION__) #else @@ -324,7 +324,7 @@ int ast_hashtab_insert_immediate_bucket(struct ast_hashtab *tab, const void *obj * \retval 1 on success * \retval 0 if there's a problem, or it's already there. */ -#if (defined(MALLOC_DEBUG) && !defined(STANDALONE)) +#ifdef __AST_DEBUG_MALLOC int _ast_hashtab_insert_safe(struct ast_hashtab *tab, const void *obj, const char *file, int lineno, const char *func); #define ast_hashtab_insert_safe(a,b) _ast_hashtab_insert_safe(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__) #else @@ -362,7 +362,7 @@ int ast_hashtab_size( struct ast_hashtab *tab); int ast_hashtab_capacity( struct ast_hashtab *tab); /*! \brief Return a copy of the hash table */ -#if (defined(MALLOC_DEBUG) && !defined(STANDALONE)) +#ifdef __AST_DEBUG_MALLOC struct ast_hashtab *_ast_hashtab_dup(struct ast_hashtab *tab, void *(*obj_dup_func)(const void *obj), const char *file, int lineno, const char *func); #define ast_hashtab_dup(a,b) _ast_hashtab_dup(a,b,__FILE__,__LINE__,__PRETTY_FUNCTION__) #else @@ -370,7 +370,7 @@ struct ast_hashtab *ast_hashtab_dup(struct ast_hashtab *tab, void *(*obj_dup_fun #endif /*! \brief Gives an iterator to hastable */ -#if (defined(MALLOC_DEBUG) && !defined(STANDALONE)) +#ifdef __AST_DEBUG_MALLOC struct ast_hashtab_iter *_ast_hashtab_start_traversal(struct ast_hashtab *tab, const char *file, int lineno, const char *func); #define ast_hashtab_start_traversal(a) _ast_hashtab_start_traversal(a,__FILE__,__LINE__,__PRETTY_FUNCTION__) #else @@ -395,7 +395,7 @@ void *ast_hashtab_remove_this_object(struct ast_hashtab *tab, void *obj); /* ------------------ */ /*! \brief Gives an iterator to hastable */ -#if (defined(MALLOC_DEBUG) && !defined(STANDALONE)) +#ifdef __AST_DEBUG_MALLOC struct ast_hashtab_iter *_ast_hashtab_start_write_traversal(struct ast_hashtab *tab, const char *file, int lineno, const char *func); #define ast_hashtab_start_write_traversal(a) _ast_hashtab_start_write_traversal(a,__FILE__,__LINE__,__PRETTY_FUNCTION__) #else diff --git a/include/asterisk/heap.h b/include/asterisk/heap.h index a868ac589..728327936 100644 --- a/include/asterisk/heap.h +++ b/include/asterisk/heap.h @@ -97,7 +97,7 @@ typedef int (*ast_heap_cmp_fn)(void *elm1, void *elm2); * \return An instance of a max heap * \since 1.6.1 */ -#ifdef MALLOC_DEBUG +#ifdef __AST_DEBUG_MALLOC struct ast_heap *_ast_heap_create(unsigned int init_height, ast_heap_cmp_fn cmp_fn, ssize_t index_offset, const char *file, int lineno, const char *func); #define ast_heap_create(a,b,c) _ast_heap_create(a,b,c,__FILE__,__LINE__,__PRETTY_FUNCTION__) @@ -126,7 +126,7 @@ struct ast_heap *ast_heap_destroy(struct ast_heap *h); * \retval non-zero failure * \since 1.6.1 */ -#ifdef MALLOC_DEBUG +#ifdef __AST_DEBUG_MALLOC int _ast_heap_push(struct ast_heap *h, void *elm, const char *file, int lineno, const char *func); #define ast_heap_push(a,b) _ast_heap_push(a,b,__FILE__,__LINE__,__PRETTY_FUNCTION__) #else diff --git a/include/asterisk/strings.h b/include/asterisk/strings.h index 2ca75a69c..eb5b4e43c 100644 --- a/include/asterisk/strings.h +++ b/include/asterisk/strings.h @@ -616,7 +616,7 @@ int ast_regex_string_to_regex_pattern(const char *regex_string, struct ast_str * * \note The result of this function is dynamically allocated memory, and must * be free()'d after it is no longer needed. */ -#if (defined(MALLOC_DEBUG) && !defined(STANDALONE)) +#ifdef __AST_DEBUG_MALLOC #define ast_str_create(a) _ast_str_create(a,__FILE__,__LINE__,__PRETTY_FUNCTION__) AST_INLINE_API( struct ast_str * attribute_malloc _ast_str_create(size_t init_len, @@ -771,7 +771,7 @@ char *ast_str_truncate(struct ast_str *buf, ssize_t len), /*! * Make space in a new string (e.g. to read in data from a file) */ -#if (defined(MALLOC_DEBUG) && !defined(STANDALONE)) +#ifdef __AST_DEBUG_MALLOC AST_INLINE_API( int _ast_str_make_space(struct ast_str **buf, size_t new_len, const char *file, int lineno, const char *function), { @@ -964,7 +964,7 @@ enum { * through calling one of the other functions or macros defined in this * file. */ -#if (defined(MALLOC_DEBUG) && !defined(STANDALONE)) +#ifdef __AST_DEBUG_MALLOC int __attribute__((format(printf, 4, 0))) __ast_debug_str_helper(struct ast_str **buf, ssize_t max_len, int append, const char *fmt, va_list ap, const char *file, int lineno, const char *func); #define __ast_str_helper(a,b,c,d,e) __ast_debug_str_helper(a,b,c,d,e,__FILE__,__LINE__,__PRETTY_FUNCTION__) diff --git a/include/asterisk/utils.h b/include/asterisk/utils.h index c3df4779f..9789d34ee 100644 --- a/include/asterisk/utils.h +++ b/include/asterisk/utils.h @@ -533,19 +533,8 @@ long int ast_random(void); ast_log(LOG_ERROR, "Memory Allocation Failure in function %s at line %d of %s\n", func, lineno, file) #endif -/*! - * \brief A wrapper for malloc() - * - * ast_malloc() is a wrapper for malloc() that will generate an Asterisk log - * message in the case that the allocation fails. - * - * The argument and return value are the same as malloc() - */ -#define ast_malloc(len) \ - _ast_malloc((len), __FILE__, __LINE__, __PRETTY_FUNCTION__) - AST_INLINE_API( -void * attribute_malloc _ast_malloc(size_t len, const char *file, int lineno, const char *func), +void * attribute_malloc __ast_malloc(size_t len, const char *file, int lineno, const char *func), { void *p; @@ -559,19 +548,8 @@ void * attribute_malloc _ast_malloc(size_t len, const char *file, int lineno, co } ) -/*! - * \brief A wrapper for calloc() - * - * ast_calloc() is a wrapper for calloc() that will generate an Asterisk log - * message in the case that the allocation fails. - * - * The arguments and return value are the same as calloc() - */ -#define ast_calloc(num, len) \ - _ast_calloc((num), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__) - AST_INLINE_API( -void * attribute_malloc _ast_calloc(size_t num, size_t len, const char *file, int lineno, const char *func), +void * attribute_malloc __ast_calloc(size_t num, size_t len, const char *file, int lineno, const char *func), { void *p; @@ -585,6 +563,98 @@ void * attribute_malloc _ast_calloc(size_t num, size_t len, const char *file, in } ) +AST_INLINE_API( +void * attribute_malloc __ast_realloc(void *p, size_t len, const char *file, int lineno, const char *func), +{ + void *newp; + + DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL); + + if (!(newp = realloc(p, len))) { + MALLOC_FAILURE_MSG; + } + + return newp; +} +) + +AST_INLINE_API( +char * attribute_malloc __ast_strdup(const char *str, const char *file, int lineno, const char *func), +{ + char *newstr = NULL; + + DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL); + + if (str) { + if (!(newstr = strdup(str))) { + MALLOC_FAILURE_MSG; + } + } + + return newstr; +} +) + +AST_INLINE_API( +char * attribute_malloc __ast_strndup(const char *str, size_t len, const char *file, int lineno, const char *func), +{ + char *newstr = NULL; + + DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL); + + if (str) { + if (!(newstr = strndup(str, len))) { + MALLOC_FAILURE_MSG; + } + } + + return newstr; +} +) + +int __attribute__((format(printf, 5, 6))) + __ast_asprintf(const char *file, int lineno, const char *func, char **ret, const char *fmt, ...); + +AST_INLINE_API( +__attribute__((format(printf, 2, 0))) +int __ast_vasprintf(char **ret, const char *fmt, va_list ap, const char *file, int lineno, const char *func), +{ + int res; + + DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, -1); + + if ((res = vasprintf(ret, fmt, ap)) == -1) { + MALLOC_FAILURE_MSG; + } + + return res; +} +) + +#endif /* AST_DEBUG_MALLOC */ + +/*! + * \brief A wrapper for malloc() + * + * ast_malloc() is a wrapper for malloc() that will generate an Asterisk log + * message in the case that the allocation fails. + * + * The argument and return value are the same as malloc() + */ +#define ast_malloc(len) \ + __ast_malloc((len), __FILE__, __LINE__, __PRETTY_FUNCTION__) + +/*! + * \brief A wrapper for calloc() + * + * ast_calloc() is a wrapper for calloc() that will generate an Asterisk log + * message in the case that the allocation fails. + * + * The arguments and return value are the same as calloc() + */ +#define ast_calloc(num, len) \ + __ast_calloc((num), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__) + /*! * \brief A wrapper for calloc() for use in cache pools * @@ -596,7 +666,7 @@ void * attribute_malloc _ast_calloc(size_t num, size_t len, const char *file, in * The arguments and return value are the same as calloc() */ #define ast_calloc_cache(num, len) \ - _ast_calloc((num), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__) + __ast_calloc((num), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__) /*! * \brief A wrapper for realloc() @@ -607,22 +677,7 @@ void * attribute_malloc _ast_calloc(size_t num, size_t len, const char *file, in * The arguments and return value are the same as realloc() */ #define ast_realloc(p, len) \ - _ast_realloc((p), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__) - -AST_INLINE_API( -void * attribute_malloc _ast_realloc(void *p, size_t len, const char *file, int lineno, const char *func), -{ - void *newp; - - DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL); - - if (!(newp = realloc(p, len))) { - MALLOC_FAILURE_MSG; - } - - return newp; -} -) + __ast_realloc((p), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__) /*! * \brief A wrapper for strdup() @@ -637,24 +692,7 @@ void * attribute_malloc _ast_realloc(void *p, size_t len, const char *file, int * The argument and return value are the same as strdup() */ #define ast_strdup(str) \ - _ast_strdup((str), __FILE__, __LINE__, __PRETTY_FUNCTION__) - -AST_INLINE_API( -char * attribute_malloc _ast_strdup(const char *str, const char *file, int lineno, const char *func), -{ - char *newstr = NULL; - - DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL); - - if (str) { - if (!(newstr = strdup(str))) { - MALLOC_FAILURE_MSG; - } - } - - return newstr; -} -) + __ast_strdup((str), __FILE__, __LINE__, __PRETTY_FUNCTION__) /*! * \brief A wrapper for strndup() @@ -669,24 +707,7 @@ char * attribute_malloc _ast_strdup(const char *str, const char *file, int linen * The arguments and return value are the same as strndup() */ #define ast_strndup(str, len) \ - _ast_strndup((str), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__) - -AST_INLINE_API( -char * attribute_malloc _ast_strndup(const char *str, size_t len, const char *file, int lineno, const char *func), -{ - char *newstr = NULL; - - DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL); - - if (str) { - if (!(newstr = strndup(str, len))) { - MALLOC_FAILURE_MSG; - } - } - - return newstr; -} -) + __ast_strndup((str), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__) /*! * \brief A wrapper for asprintf() @@ -697,10 +718,7 @@ char * attribute_malloc _ast_strndup(const char *str, size_t len, const char *fi * The arguments and return value are the same as asprintf() */ #define ast_asprintf(ret, fmt, ...) \ - _ast_asprintf((ret), __FILE__, __LINE__, __PRETTY_FUNCTION__, fmt, __VA_ARGS__) - -int __attribute__((format(printf, 5, 6))) - _ast_asprintf(char **ret, const char *file, int lineno, const char *func, const char *fmt, ...); + __ast_asprintf(__FILE__, __LINE__, __PRETTY_FUNCTION__, (ret), (fmt), __VA_ARGS__) /*! * \brief A wrapper for vasprintf() @@ -711,25 +729,7 @@ int __attribute__((format(printf, 5, 6))) * The arguments and return value are the same as vasprintf() */ #define ast_vasprintf(ret, fmt, ap) \ - _ast_vasprintf((ret), __FILE__, __LINE__, __PRETTY_FUNCTION__, (fmt), (ap)) - -AST_INLINE_API( -__attribute__((format(printf, 5, 0))) -int _ast_vasprintf(char **ret, const char *file, int lineno, const char *func, const char *fmt, va_list ap), -{ - int res; - - DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, -1); - - if ((res = vasprintf(ret, fmt, ap)) == -1) { - MALLOC_FAILURE_MSG; - } - - return res; -} -) - -#endif /* AST_DEBUG_MALLOC */ + __ast_vasprintf((ret), (fmt), (ap), __FILE__, __LINE__, __PRETTY_FUNCTION__) /*! \brief call __builtin_alloca to ensure we get gcc builtin semantics |