mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-21 20:56:39 +00:00
Merge "stringfields: Remove MALLOC_DEBUG fields from struct ast_string_field_mgr."
This commit is contained in:
@@ -228,11 +228,6 @@ struct ast_string_field_mgr {
|
|||||||
ast_string_field last_alloc; /*!< the last field allocated */
|
ast_string_field last_alloc; /*!< the last field allocated */
|
||||||
struct ast_string_field_pool *embedded_pool; /*!< pointer to the embedded pool, if any */
|
struct ast_string_field_pool *embedded_pool; /*!< pointer to the embedded pool, if any */
|
||||||
struct ast_string_field_vector string_fields; /*!< field vector for compare and copy */
|
struct ast_string_field_vector string_fields; /*!< field vector for compare and copy */
|
||||||
/* v-- MALLOC_DEBUG information */
|
|
||||||
const char *owner_file; /*!< filename of owner */
|
|
||||||
const char *owner_func; /*!< function name of owner */
|
|
||||||
int owner_line; /*!< line number of owner */
|
|
||||||
/* ^-- MALLOC_DEBUG information */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -266,7 +261,8 @@ int __ast_string_field_ptr_grow(struct ast_string_field_mgr *mgr,
|
|||||||
an additional pool will be allocated.
|
an additional pool will be allocated.
|
||||||
*/
|
*/
|
||||||
ast_string_field __ast_string_field_alloc_space(struct ast_string_field_mgr *mgr,
|
ast_string_field __ast_string_field_alloc_space(struct ast_string_field_mgr *mgr,
|
||||||
struct ast_string_field_pool **pool_head, size_t needed);
|
struct ast_string_field_pool **pool_head, size_t needed,
|
||||||
|
const char *file, int lineno, const char *func);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\internal
|
\internal
|
||||||
@@ -277,9 +273,9 @@ ast_string_field __ast_string_field_alloc_space(struct ast_string_field_mgr *mgr
|
|||||||
\param format printf-style format string
|
\param format printf-style format string
|
||||||
\return nothing
|
\return nothing
|
||||||
*/
|
*/
|
||||||
void __ast_string_field_ptr_build(struct ast_string_field_mgr *mgr,
|
void __ast_string_field_ptr_build(const char *file, int lineno, const char *func,
|
||||||
struct ast_string_field_pool **pool_head,
|
struct ast_string_field_mgr *mgr, struct ast_string_field_pool **pool_head,
|
||||||
ast_string_field *ptr, const char *format, ...) __attribute__((format(printf, 4, 5)));
|
ast_string_field *ptr, const char *format, ...) __attribute__((format(printf, 7, 8)));
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\internal
|
\internal
|
||||||
@@ -293,7 +289,8 @@ void __ast_string_field_ptr_build(struct ast_string_field_mgr *mgr,
|
|||||||
*/
|
*/
|
||||||
void __ast_string_field_ptr_build_va(struct ast_string_field_mgr *mgr,
|
void __ast_string_field_ptr_build_va(struct ast_string_field_mgr *mgr,
|
||||||
struct ast_string_field_pool **pool_head,
|
struct ast_string_field_pool **pool_head,
|
||||||
ast_string_field *ptr, const char *format, va_list ap) __attribute__((format(printf, 4, 0)));
|
ast_string_field *ptr, const char *format, va_list ap,
|
||||||
|
const char *file, int lineno, const char *func) __attribute__((format(printf, 4, 0)));
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Declare a string field
|
\brief Declare a string field
|
||||||
@@ -479,7 +476,7 @@ void __ast_string_field_release_active(struct ast_string_field_pool *pool_head,
|
|||||||
__res__; \
|
__res__; \
|
||||||
})
|
})
|
||||||
|
|
||||||
#define ast_string_field_ptr_set_by_fields(field_mgr_pool, field_mgr, ptr, data) \
|
#define __ast_string_field_ptr_set_by_fields(field_mgr_pool, field_mgr, ptr, data, file, lineno, func) \
|
||||||
({ \
|
({ \
|
||||||
int __res__ = 0; \
|
int __res__ = 0; \
|
||||||
const char *__d__ = (data); \
|
const char *__d__ = (data); \
|
||||||
@@ -491,7 +488,7 @@ void __ast_string_field_release_active(struct ast_string_field_pool *pool_head,
|
|||||||
*__p__ = __ast_string_field_empty; \
|
*__p__ = __ast_string_field_empty; \
|
||||||
} else if ((__dlen__ <= AST_STRING_FIELD_ALLOCATION(*__p__)) || \
|
} else if ((__dlen__ <= AST_STRING_FIELD_ALLOCATION(*__p__)) || \
|
||||||
(!__ast_string_field_ptr_grow(&field_mgr, &field_mgr_pool, __dlen__, __p__)) || \
|
(!__ast_string_field_ptr_grow(&field_mgr, &field_mgr_pool, __dlen__, __p__)) || \
|
||||||
(target = __ast_string_field_alloc_space(&field_mgr, &field_mgr_pool, __dlen__))) { \
|
(target = __ast_string_field_alloc_space(&field_mgr, &field_mgr_pool, __dlen__, file, lineno, func))) { \
|
||||||
if (target != *__p__) { \
|
if (target != *__p__) { \
|
||||||
__ast_string_field_release_active(field_mgr_pool, *__p__); \
|
__ast_string_field_release_active(field_mgr_pool, *__p__); \
|
||||||
*__p__ = target; \
|
*__p__ = target; \
|
||||||
@@ -503,6 +500,9 @@ void __ast_string_field_release_active(struct ast_string_field_pool *pool_head,
|
|||||||
__res__; \
|
__res__; \
|
||||||
})
|
})
|
||||||
|
|
||||||
|
#define ast_string_field_ptr_set_by_fields(field_mgr_pool, field_mgr, ptr, data) \
|
||||||
|
__ast_string_field_ptr_set_by_fields(field_mgr_pool, field_mgr, ptr, data, __FILE__, __LINE__, __PRETTY_FUNCTION__)
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Set a field to a simple string value
|
\brief Set a field to a simple string value
|
||||||
\param x Pointer to a structure containing fields
|
\param x Pointer to a structure containing fields
|
||||||
@@ -532,7 +532,8 @@ void __ast_string_field_release_active(struct ast_string_field_pool *pool_head,
|
|||||||
({ \
|
({ \
|
||||||
int __res__ = -1; \
|
int __res__ = -1; \
|
||||||
if (((void *)(x)) != NULL) { \
|
if (((void *)(x)) != NULL) { \
|
||||||
__ast_string_field_ptr_build(&(x)->__field_mgr, &(x)->__field_mgr_pool, (ast_string_field *) ptr, fmt, args); \
|
__ast_string_field_ptr_build(__FILE__, __LINE__, __PRETTY_FUNCTION__, \
|
||||||
|
&(x)->__field_mgr, &(x)->__field_mgr_pool, (ast_string_field *) ptr, fmt, args); \
|
||||||
__res__ = 0; \
|
__res__ = 0; \
|
||||||
} \
|
} \
|
||||||
__res__; \
|
__res__; \
|
||||||
@@ -550,7 +551,8 @@ void __ast_string_field_release_active(struct ast_string_field_pool *pool_head,
|
|||||||
({ \
|
({ \
|
||||||
int __res__ = -1; \
|
int __res__ = -1; \
|
||||||
if (((void *)(x)) != NULL) { \
|
if (((void *)(x)) != NULL) { \
|
||||||
__ast_string_field_ptr_build(&(x)->__field_mgr, &(x)->__field_mgr_pool, (ast_string_field *) &(x)->field, fmt, args); \
|
__ast_string_field_ptr_build(__FILE__, __LINE__, __PRETTY_FUNCTION__, \
|
||||||
|
&(x)->__field_mgr, &(x)->__field_mgr_pool, (ast_string_field *) &(x)->field, fmt, args); \
|
||||||
__res__ = 0; \
|
__res__ = 0; \
|
||||||
} \
|
} \
|
||||||
__res__; \
|
__res__; \
|
||||||
@@ -568,7 +570,8 @@ void __ast_string_field_release_active(struct ast_string_field_pool *pool_head,
|
|||||||
({ \
|
({ \
|
||||||
int __res__ = -1; \
|
int __res__ = -1; \
|
||||||
if (((void *)(x)) != NULL) { \
|
if (((void *)(x)) != NULL) { \
|
||||||
__ast_string_field_ptr_build_va(&(x)->__field_mgr, &(x)->__field_mgr_pool, (ast_string_field *) ptr, fmt, args); \
|
__ast_string_field_ptr_build_va(&(x)->__field_mgr, &(x)->__field_mgr_pool, (ast_string_field *) ptr, fmt, args, \
|
||||||
|
__FILE__, __LINE__, __PRETTY_FUNCTION__); \
|
||||||
__res__ = 0; \
|
__res__ = 0; \
|
||||||
} \
|
} \
|
||||||
__res__; \
|
__res__; \
|
||||||
@@ -586,7 +589,8 @@ void __ast_string_field_release_active(struct ast_string_field_pool *pool_head,
|
|||||||
({ \
|
({ \
|
||||||
int __res__ = -1; \
|
int __res__ = -1; \
|
||||||
if (((void *)(x)) != NULL) { \
|
if (((void *)(x)) != NULL) { \
|
||||||
__ast_string_field_ptr_build_va(&(x)->__field_mgr, &(x)->__field_mgr_pool, (ast_string_field *) &(x)->field, fmt, args); \
|
__ast_string_field_ptr_build_va(&(x)->__field_mgr, &(x)->__field_mgr_pool, (ast_string_field *) &(x)->field, fmt, args, \
|
||||||
|
__FILE__, __LINE__, __PRETTY_FUNCTION__); \
|
||||||
__res__ = 0; \
|
__res__ = 0; \
|
||||||
} \
|
} \
|
||||||
__res__; \
|
__res__; \
|
||||||
@@ -626,12 +630,14 @@ int __ast_string_fields_cmp(struct ast_string_field_vector *left, struct ast_str
|
|||||||
if (((void *)(copy)) != NULL && ((void *)(orig)) != NULL) { \
|
if (((void *)(copy)) != NULL && ((void *)(orig)) != NULL) { \
|
||||||
__res__ = __ast_string_fields_copy(((copy)->__field_mgr_pool), \
|
__res__ = __ast_string_fields_copy(((copy)->__field_mgr_pool), \
|
||||||
(struct ast_string_field_mgr *)&((copy)->__field_mgr), \
|
(struct ast_string_field_mgr *)&((copy)->__field_mgr), \
|
||||||
(struct ast_string_field_mgr *)&((orig)->__field_mgr)); \
|
(struct ast_string_field_mgr *)&((orig)->__field_mgr), \
|
||||||
|
__FILE__, __LINE__, __PRETTY_FUNCTION__); \
|
||||||
} \
|
} \
|
||||||
__res__; \
|
__res__; \
|
||||||
})
|
})
|
||||||
|
|
||||||
int __ast_string_fields_copy(struct ast_string_field_pool *copy_pool,
|
int __ast_string_fields_copy(struct ast_string_field_pool *copy_pool,
|
||||||
struct ast_string_field_mgr *copy_mgr, struct ast_string_field_mgr *orig_mgr);
|
struct ast_string_field_mgr *copy_mgr, struct ast_string_field_mgr *orig_mgr,
|
||||||
|
const char *file, int lineno, const char *func);
|
||||||
|
|
||||||
#endif /* _ASTERISK_STRINGFIELDS_H */
|
#endif /* _ASTERISK_STRINGFIELDS_H */
|
||||||
|
@@ -179,11 +179,6 @@ int __ast_string_field_init(struct ast_string_field_mgr *mgr, struct ast_string_
|
|||||||
}
|
}
|
||||||
|
|
||||||
mgr->last_alloc = NULL;
|
mgr->last_alloc = NULL;
|
||||||
/* v-- MALLOC_DEBUG information */
|
|
||||||
mgr->owner_file = file;
|
|
||||||
mgr->owner_func = func;
|
|
||||||
mgr->owner_line = lineno;
|
|
||||||
/* ^-- MALLOC_DEBUG information */
|
|
||||||
|
|
||||||
if (AST_VECTOR_INIT(&mgr->string_fields, initial_vector_size)) {
|
if (AST_VECTOR_INIT(&mgr->string_fields, initial_vector_size)) {
|
||||||
return -1;
|
return -1;
|
||||||
@@ -205,7 +200,8 @@ int __ast_string_field_init(struct ast_string_field_mgr *mgr, struct ast_string_
|
|||||||
}
|
}
|
||||||
|
|
||||||
ast_string_field __ast_string_field_alloc_space(struct ast_string_field_mgr *mgr,
|
ast_string_field __ast_string_field_alloc_space(struct ast_string_field_mgr *mgr,
|
||||||
struct ast_string_field_pool **pool_head, size_t needed)
|
struct ast_string_field_pool **pool_head, size_t needed,
|
||||||
|
const char *file, int lineno, const char *func)
|
||||||
{
|
{
|
||||||
char *result = NULL;
|
char *result = NULL;
|
||||||
size_t space = (*pool_head)->size - (*pool_head)->used;
|
size_t space = (*pool_head)->size - (*pool_head)->used;
|
||||||
@@ -222,8 +218,7 @@ ast_string_field __ast_string_field_alloc_space(struct ast_string_field_mgr *mgr
|
|||||||
new_size *= 2;
|
new_size *= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (add_string_pool(mgr, pool_head, new_size,
|
if (add_string_pool(mgr, pool_head, new_size, file, lineno, func)) {
|
||||||
mgr->owner_file, mgr->owner_line, mgr->owner_func)) {
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -290,7 +285,8 @@ void __ast_string_field_release_active(struct ast_string_field_pool *pool_head,
|
|||||||
|
|
||||||
void __ast_string_field_ptr_build_va(struct ast_string_field_mgr *mgr,
|
void __ast_string_field_ptr_build_va(struct ast_string_field_mgr *mgr,
|
||||||
struct ast_string_field_pool **pool_head, ast_string_field *ptr,
|
struct ast_string_field_pool **pool_head, ast_string_field *ptr,
|
||||||
const char *format, va_list ap)
|
const char *format, va_list ap,
|
||||||
|
const char *file, int lineno, const char *func)
|
||||||
{
|
{
|
||||||
size_t needed;
|
size_t needed;
|
||||||
size_t available;
|
size_t available;
|
||||||
@@ -342,7 +338,8 @@ void __ast_string_field_ptr_build_va(struct ast_string_field_mgr *mgr,
|
|||||||
(if it has one), or the space available in the pool (if it does not). allocate
|
(if it has one), or the space available in the pool (if it does not). allocate
|
||||||
space for it, adding a new string pool if necessary.
|
space for it, adding a new string pool if necessary.
|
||||||
*/
|
*/
|
||||||
if (!(target = (char *) __ast_string_field_alloc_space(mgr, pool_head, needed))) {
|
target = (char *) __ast_string_field_alloc_space(mgr, pool_head, needed, file, lineno, func);
|
||||||
|
if (!target) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
vsprintf(target, format, ap);
|
vsprintf(target, format, ap);
|
||||||
@@ -369,13 +366,14 @@ void __ast_string_field_ptr_build_va(struct ast_string_field_mgr *mgr,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void __ast_string_field_ptr_build(struct ast_string_field_mgr *mgr,
|
void __ast_string_field_ptr_build(const char *file, int lineno, const char *func,
|
||||||
|
struct ast_string_field_mgr *mgr,
|
||||||
struct ast_string_field_pool **pool_head, ast_string_field *ptr, const char *format, ...)
|
struct ast_string_field_pool **pool_head, ast_string_field *ptr, const char *format, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
va_start(ap, format);
|
va_start(ap, format);
|
||||||
__ast_string_field_ptr_build_va(mgr, pool_head, ptr, format, ap);
|
__ast_string_field_ptr_build_va(mgr, pool_head, ptr, format, ap, file, lineno, func);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -419,11 +417,6 @@ void *__ast_calloc_with_stringfields(unsigned int num_structs, size_t struct_siz
|
|||||||
mgr->embedded_pool = pool;
|
mgr->embedded_pool = pool;
|
||||||
*pool_head = pool;
|
*pool_head = pool;
|
||||||
pool->size = size_to_alloc - struct_size - sizeof(*pool);
|
pool->size = size_to_alloc - struct_size - sizeof(*pool);
|
||||||
/* v-- MALLOC_DEBUG information */
|
|
||||||
mgr->owner_file = file;
|
|
||||||
mgr->owner_func = func;
|
|
||||||
mgr->owner_line = lineno;
|
|
||||||
/* ^-- MALLOC_DEBUG information */
|
|
||||||
|
|
||||||
return allocation;
|
return allocation;
|
||||||
}
|
}
|
||||||
@@ -446,7 +439,8 @@ int __ast_string_fields_cmp(struct ast_string_field_vector *left,
|
|||||||
}
|
}
|
||||||
|
|
||||||
int __ast_string_fields_copy(struct ast_string_field_pool *copy_pool,
|
int __ast_string_fields_copy(struct ast_string_field_pool *copy_pool,
|
||||||
struct ast_string_field_mgr *copy_mgr, struct ast_string_field_mgr *orig_mgr)
|
struct ast_string_field_mgr *copy_mgr, struct ast_string_field_mgr *orig_mgr,
|
||||||
|
const char *file, int lineno, const char *func)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
struct ast_string_field_vector *dest = &(copy_mgr->string_fields);
|
struct ast_string_field_vector *dest = &(copy_mgr->string_fields);
|
||||||
@@ -460,8 +454,8 @@ int __ast_string_fields_copy(struct ast_string_field_pool *copy_pool,
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < AST_VECTOR_SIZE(dest); i++) {
|
for (i = 0; i < AST_VECTOR_SIZE(dest); i++) {
|
||||||
if (ast_string_field_ptr_set_by_fields(copy_pool, *copy_mgr, AST_VECTOR_GET(dest, i),
|
if (__ast_string_field_ptr_set_by_fields(copy_pool, *copy_mgr, AST_VECTOR_GET(dest, i),
|
||||||
*AST_VECTOR_GET(src, i))) {
|
*AST_VECTOR_GET(src, i), file, lineno, func)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user