diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/asterisk/astobj2.h | 4 | ||||
-rw-r--r-- | include/asterisk/hashtab.h | 30 | ||||
-rw-r--r-- | include/asterisk/heap.h | 11 | ||||
-rw-r--r-- | include/asterisk/strings.h | 27 |
4 files changed, 72 insertions, 0 deletions
diff --git a/include/asterisk/astobj2.h b/include/asterisk/astobj2.h index c8a464ed7..fc46c2a2f 100644 --- a/include/asterisk/astobj2.h +++ b/include/asterisk/astobj2.h @@ -19,6 +19,10 @@ #include "asterisk/compat.h" +#ifdef MALLOC_DEBUG +#define REF_DEBUG +#endif + /*! \file * \ref AstObj2 * diff --git a/include/asterisk/hashtab.h b/include/asterisk/hashtab.h index 20a85a418..89d293759 100644 --- a/include/asterisk/hashtab.h +++ b/include/asterisk/hashtab.h @@ -291,7 +291,12 @@ 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)) +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 int ast_hashtab_insert_immediate(struct ast_hashtab *tab, const void *obj); +#endif /*! * \brief Insert without checking, hashing or locking @@ -303,7 +308,12 @@ 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)) +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 int ast_hashtab_insert_immediate_bucket(struct ast_hashtab *tab, const void *obj, unsigned int h); +#endif /*! * \brief Check and insert new object only if it is not there. @@ -311,7 +321,12 @@ 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)) +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 int ast_hashtab_insert_safe(struct ast_hashtab *tab, const void *obj); +#endif /*! * \brief Lookup this object in the hash table. @@ -344,10 +359,20 @@ 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)) +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 struct ast_hashtab *ast_hashtab_dup(struct ast_hashtab *tab, void *(*obj_dup_func)(const void *obj)); +#endif /*! \brief Gives an iterator to hastable */ +#if (defined(MALLOC_DEBUG) && !defined(STANDALONE)) +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 struct ast_hashtab_iter *ast_hashtab_start_traversal(struct ast_hashtab *tab); +#endif /*! \brief end the traversal, free the iterator, unlock if necc. */ void ast_hashtab_end_traversal(struct ast_hashtab_iter *it); @@ -367,7 +392,12 @@ void *ast_hashtab_remove_this_object(struct ast_hashtab *tab, void *obj); /* ------------------ */ /*! \brief Gives an iterator to hastable */ +#if (defined(MALLOC_DEBUG) && !defined(STANDALONE)) +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 struct ast_hashtab_iter *ast_hashtab_start_write_traversal(struct ast_hashtab *tab); +#endif /*! \brief Looks up the object, removes the corresponding bucket */ void *ast_hashtab_remove_object_via_lookup_nolock(struct ast_hashtab *tab, void *obj); diff --git a/include/asterisk/heap.h b/include/asterisk/heap.h index 56311ca05..654ec5e1e 100644 --- a/include/asterisk/heap.h +++ b/include/asterisk/heap.h @@ -97,8 +97,14 @@ typedef int (*ast_heap_cmp_fn)(void *elm1, void *elm2); * \return An instance of a max heap * \since 1.6.1 */ +#ifdef MALLOC_DEBUG +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__) +#else struct ast_heap *ast_heap_create(unsigned int init_height, ast_heap_cmp_fn cmp_fn, ssize_t index_offset); +#endif /*! * \brief Destroy a max heap @@ -120,7 +126,12 @@ struct ast_heap *ast_heap_destroy(struct ast_heap *h); * \retval non-zero failure * \since 1.6.1 */ +#ifdef MALLOC_DEBUG +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 int ast_heap_push(struct ast_heap *h, void *elm); +#endif /*! * \brief Pop the max element off of the heap diff --git a/include/asterisk/strings.h b/include/asterisk/strings.h index 65664d930..94ca668a4 100644 --- a/include/asterisk/strings.h +++ b/include/asterisk/strings.h @@ -372,6 +372,26 @@ 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)) +#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, + const char *file, int lineno, const char *func), +{ + struct ast_str *buf; + + buf = (struct ast_str *)__ast_calloc(1, sizeof(*buf) + init_len, file, lineno, func); + if (buf == NULL) + return NULL; + + buf->__AST_STR_LEN = init_len; + buf->__AST_STR_USED = 0; + buf->__AST_STR_TS = DS_MALLOC; + + return buf; +} +) +#else AST_INLINE_API( struct ast_str * attribute_malloc ast_str_create(size_t init_len), { @@ -388,6 +408,7 @@ struct ast_str * attribute_malloc ast_str_create(size_t init_len), return buf; } ) +#endif /*! \brief Reset the content of a dynamic string. * Useful before a series of ast_str_append. @@ -665,8 +686,14 @@ enum { * through calling one of the other functions or macros defined in this * file. */ +#if (defined(MALLOC_DEBUG) && !defined(STANDALONE)) +int __attribute__((format(printf, 4, 0))) __ast_debug_str_helper(struct ast_str **buf, size_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__) +#else int __attribute__((format(printf, 4, 0))) __ast_str_helper(struct ast_str **buf, size_t max_len, int append, const char *fmt, va_list ap); +#endif char *__ast_str_helper2(struct ast_str **buf, size_t max_len, const char *src, size_t maxsrc, int append, int escapecommas); |