Use va_copy for stringfields
The ast_string_field_build_va functions were written to take to separate va_lists to work around FreeBSD 4 not having va_copy defined. In the end, we don't support anything using gcc < 3 anyway because we use va_copy all over the place anyway. This patch just simplifies things by removing the second va_list function arguments in favor of va_copy. Review: https://reviewboard.asterisk.org/r/1233/ --This line, and those below, will be ignored-- M include/asterisk/stringfields.h M main/utils.c M main/channel.c git-svn-id: http://svn.digium.com/svn/asterisk/trunk@320946 f38db490-d61c-443f-a65b-d21fe96a405b
This commit is contained in:
parent
88e6859a3a
commit
2aeb6694bb
|
@ -205,7 +205,7 @@ 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,
|
||||
struct ast_string_field_pool **pool_head,
|
||||
ast_string_field *ptr, const char *format, va_list a1, va_list a2) __attribute__((format(printf, 4, 0)));
|
||||
ast_string_field *ptr, const char *format, va_list ap) __attribute__((format(printf, 4, 0)));
|
||||
|
||||
/*!
|
||||
\brief Declare a string field
|
||||
|
@ -369,8 +369,8 @@ typedef uint16_t ast_string_field_allocation;
|
|||
\param args2 a second copy of the va_list for the sake of bsd, with no va_list copy operation
|
||||
\return nothing
|
||||
*/
|
||||
#define ast_string_field_ptr_build_va(x, ptr, fmt, args1, args2) \
|
||||
__ast_string_field_ptr_build_va(&(x)->__field_mgr, &(x)->__field_mgr_pool, (ast_string_field *) ptr, fmt, args1, args2)
|
||||
#define ast_string_field_ptr_build_va(x, ptr, fmt, args) \
|
||||
__ast_string_field_ptr_build_va(&(x)->__field_mgr, &(x)->__field_mgr_pool, (ast_string_field *) ptr, fmt, args)
|
||||
|
||||
/*!
|
||||
\brief Set a field to a complex (built) value
|
||||
|
@ -381,7 +381,7 @@ typedef uint16_t ast_string_field_allocation;
|
|||
\param args2 argument two
|
||||
\return nothing
|
||||
*/
|
||||
#define ast_string_field_build_va(x, field, fmt, args1, args2) \
|
||||
__ast_string_field_ptr_build_va(&(x)->__field_mgr, &(x)->__field_mgr_pool, (ast_string_field *) &(x)->field, fmt, args1, args2)
|
||||
#define ast_string_field_build_va(x, field, fmt, args) \
|
||||
__ast_string_field_ptr_build_va(&(x)->__field_mgr, &(x)->__field_mgr_pool, (ast_string_field *) &(x)->field, fmt, args)
|
||||
|
||||
#endif /* _ASTERISK_STRINGFIELDS_H */
|
||||
|
|
|
@ -1118,7 +1118,7 @@ static struct ast_channel * attribute_malloc __attribute__((format(printf, 13, 0
|
|||
__ast_channel_alloc_ap(int needqueue, int state, const char *cid_num, const char *cid_name,
|
||||
const char *acctcode, const char *exten, const char *context,
|
||||
const char *linkedid, const int amaflag, const char *file, int line,
|
||||
const char *function, const char *name_fmt, va_list ap1, va_list ap2)
|
||||
const char *function, const char *name_fmt, va_list ap)
|
||||
{
|
||||
struct ast_channel *tmp;
|
||||
int x;
|
||||
|
@ -1263,7 +1263,7 @@ __ast_channel_alloc_ap(int needqueue, int state, const char *cid_num, const char
|
|||
* uses them to build the string, instead of forming the va_lists internally from the vararg ... list.
|
||||
* This new function was written so this can be accomplished.
|
||||
*/
|
||||
ast_string_field_build_va(tmp, name, name_fmt, ap1, ap2);
|
||||
ast_string_field_build_va(tmp, name, name_fmt, ap);
|
||||
tech = ast_strdupa(tmp->name);
|
||||
if ((slash = strchr(tech, '/'))) {
|
||||
if ((slash2 = strchr(slash + 1, '/'))) {
|
||||
|
@ -1362,15 +1362,13 @@ struct ast_channel *__ast_channel_alloc(int needqueue, int state, const char *ci
|
|||
const char *file, int line, const char *function,
|
||||
const char *name_fmt, ...)
|
||||
{
|
||||
va_list ap1, ap2;
|
||||
va_list ap;
|
||||
struct ast_channel *result;
|
||||
|
||||
va_start(ap1, name_fmt);
|
||||
va_start(ap2, name_fmt);
|
||||
va_start(ap, name_fmt);
|
||||
result = __ast_channel_alloc_ap(needqueue, state, cid_num, cid_name, acctcode, exten, context,
|
||||
linkedid, amaflag, file, line, function, name_fmt, ap1, ap2);
|
||||
va_end(ap1);
|
||||
va_end(ap2);
|
||||
linkedid, amaflag, file, line, function, name_fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -9584,16 +9582,14 @@ struct ast_channel *ast_channel_alloc(int needqueue, int state, const char *cid_
|
|||
const char *linkedid, const int amaflag,
|
||||
const char *name_fmt, ...)
|
||||
{
|
||||
va_list ap1, ap2;
|
||||
va_list ap;
|
||||
struct ast_channel *result;
|
||||
|
||||
|
||||
va_start(ap1, name_fmt);
|
||||
va_start(ap2, name_fmt);
|
||||
va_start(ap, name_fmt);
|
||||
result = __ast_channel_alloc_ap(needqueue, state, cid_num, cid_name, acctcode, exten, context,
|
||||
linkedid, amaflag, __FILE__, __LINE__, __FUNCTION__, name_fmt, ap1, ap2);
|
||||
va_end(ap1);
|
||||
va_end(ap2);
|
||||
linkedid, amaflag, __FILE__, __LINE__, __FUNCTION__, name_fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
24
main/utils.c
24
main/utils.c
|
@ -1733,13 +1733,14 @@ 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,
|
||||
struct ast_string_field_pool **pool_head,
|
||||
ast_string_field *ptr, const char *format, va_list ap1, va_list ap2)
|
||||
ast_string_field *ptr, const char *format, va_list ap)
|
||||
{
|
||||
size_t needed;
|
||||
size_t available;
|
||||
size_t space = (*pool_head)->size - (*pool_head)->used;
|
||||
ssize_t grow;
|
||||
char *target;
|
||||
va_list ap2;
|
||||
|
||||
/* if the field already has space allocated, try to reuse it;
|
||||
otherwise, try to use the empty space at the end of the current
|
||||
|
@ -1762,9 +1763,9 @@ void __ast_string_field_ptr_build_va(struct ast_string_field_mgr *mgr,
|
|||
available = space - sizeof(ast_string_field_allocation);
|
||||
}
|
||||
|
||||
needed = vsnprintf(target, available, format, ap1) + 1;
|
||||
|
||||
va_end(ap1);
|
||||
va_copy(ap2, ap);
|
||||
needed = vsnprintf(target, available, format, ap2) + 1;
|
||||
va_end(ap2);
|
||||
|
||||
if (needed > available) {
|
||||
/* the allocation could not be satisfied using the field's current allocation
|
||||
|
@ -1774,7 +1775,8 @@ void __ast_string_field_ptr_build_va(struct ast_string_field_mgr *mgr,
|
|||
if (!(target = (char *) __ast_string_field_alloc_space(mgr, pool_head, needed))) {
|
||||
return;
|
||||
}
|
||||
vsprintf(target, format, ap2);
|
||||
vsprintf(target, format, ap);
|
||||
va_end(ap);
|
||||
__ast_string_field_release_active(*pool_head, *ptr);
|
||||
*ptr = target;
|
||||
} else if (*ptr != target) {
|
||||
|
@ -1800,15 +1802,11 @@ void __ast_string_field_ptr_build(struct ast_string_field_mgr *mgr,
|
|||
struct ast_string_field_pool **pool_head,
|
||||
ast_string_field *ptr, const char *format, ...)
|
||||
{
|
||||
va_list ap1, ap2;
|
||||
va_list ap;
|
||||
|
||||
va_start(ap1, format);
|
||||
va_start(ap2, format); /* va_copy does not exist on FreeBSD */
|
||||
|
||||
__ast_string_field_ptr_build_va(mgr, pool_head, ptr, format, ap1, ap2);
|
||||
|
||||
va_end(ap1);
|
||||
va_end(ap2);
|
||||
va_start(ap, format);
|
||||
__ast_string_field_ptr_build_va(mgr, pool_head, ptr, format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void *__ast_calloc_with_stringfields(unsigned int num_structs, size_t struct_size, size_t field_mgr_offset,
|
||||
|
|
Reference in New Issue