Review Board 1.7.16


Use va_copy for stringfields--it's used everywhere else

Review Request #1233 - Created May 26, 2011 and submitted

Terry Wilson
trunk
Reviewers
asterisk-dev
Asterisk
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. It should have been perfectly possible for that case to just define va_copy ourselves as an assignment, as if va_list was implemented in some way incompatible with that (as in an array type), passing two copies of it wouldn't have worked anyway.

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. The only place that used the function was __ast_channel_alloc_ap(). We could simplify things further by just getting rid of __ast_channel_alloc_ap() and doing everything in __ast_channel_alloc() since it is only called by __ast_channel_alloc().

Also, does the ABI compatibility stuff at the end of channel.c still need to be there in trunk?
Made a call under valgrind. Things didn't blow up and the channel had the appropriate name, so things must work.
/trunk/include/asterisk/stringfields.h
Revision 320708 New Change
[20] 202 lines
[+20] [+] void __ast_string_field_ptr_build(struct ast_string_field_mgr *mgr,
203
  \param args_again a copy of the first va_list for the sake of bsd not having a copy routine
203
  \param args_again a copy of the first va_list for the sake of bsd not having a copy routine
204
  \return nothing
204
  \return nothing
205
*/
205
*/
206
void __ast_string_field_ptr_build_va(struct ast_string_field_mgr *mgr,
206
void __ast_string_field_ptr_build_va(struct ast_string_field_mgr *mgr,
207
				     struct ast_string_field_pool **pool_head,
207
				     struct ast_string_field_pool **pool_head,
208
				     ast_string_field *ptr, const char *format, va_list a1, va_list a2) __attribute__((format(printf, 4, 0)));
208
				     ast_string_field *ptr, const char *format, va_list ap) __attribute__((format(printf, 4, 0)));
209

    
   
209

   
210
/*!
210
/*!
211
  \brief Declare a string field
211
  \brief Declare a string field
212
  \param name The field name
212
  \param name The field name
213
*/
213
*/
[+20] [20] 153 lines
[+20] [+] typedef uint16_t ast_string_field_allocation;
367
  \param fmt printf-style format string
367
  \param fmt printf-style format string
368
  \param args1 Arguments for format string in va_list format
368
  \param args1 Arguments for format string in va_list format
369
  \param args2 a second copy of the va_list for the sake of bsd, with no va_list copy operation
369
  \param args2 a second copy of the va_list for the sake of bsd, with no va_list copy operation
370
  \return nothing
370
  \return nothing
371
*/
371
*/
372
#define ast_string_field_ptr_build_va(x, ptr, fmt, args1, args2) \
372
#define ast_string_field_ptr_build_va(x, ptr, fmt, args) \
373
	__ast_string_field_ptr_build_va(&(x)->__field_mgr, &(x)->__field_mgr_pool, (ast_string_field *) ptr, fmt, args1, args2)
373
	__ast_string_field_ptr_build_va(&(x)->__field_mgr, &(x)->__field_mgr_pool, (ast_string_field *) ptr, fmt, args)
374

    
   
374

   
375
/*!
375
/*!
376
  \brief Set a field to a complex (built) value
376
  \brief Set a field to a complex (built) value
377
  \param x Pointer to a structure containing fields
377
  \param x Pointer to a structure containing fields
378
  \param field Name of the field to set
378
  \param field Name of the field to set
379
  \param fmt printf-style format string
379
  \param fmt printf-style format string
380
  \param args1 argument one
380
  \param args1 argument one
381
  \param args2 argument two
381
  \param args2 argument two
382
  \return nothing
382
  \return nothing
383
*/
383
*/
384
#define ast_string_field_build_va(x, field, fmt, args1, args2) \
384
#define ast_string_field_build_va(x, field, fmt, args) \
385
	__ast_string_field_ptr_build_va(&(x)->__field_mgr, &(x)->__field_mgr_pool, (ast_string_field *) &(x)->field, fmt, args1, args2)
385
	__ast_string_field_ptr_build_va(&(x)->__field_mgr, &(x)->__field_mgr_pool, (ast_string_field *) &(x)->field, fmt, args)
386

    
   
386

   
387
#endif /* _ASTERISK_STRINGFIELDS_H */
387
#endif /* _ASTERISK_STRINGFIELDS_H */
/trunk/main/channel.c
Revision 320708 New Change
 
/trunk/main/utils.c
Revision 320708 New Change
 
  1. /trunk/include/asterisk/stringfields.h: Loading...
  2. /trunk/main/channel.c: Loading...
  3. /trunk/main/utils.c: Loading...

https://reviewboard.asterisk.org/ runs on a server provided by Digium, Inc. and uses bandwidth donated to the open source Asterisk community by API Digital Communications in Huntsville, AL USA.
Please report problems with this site to asteriskteam@digium.com.