This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [3.3/mainline;libiberty] Fix vasprintf.c


> If it is an array, isn't passing by value and THEN copying
> it (again) a waste of cpu time?
> 
> It seems that you should leave the 'va_list *args;'
> in the prototype of int_vasprintf.
> 
> For example,
> 
> #ifndef HAVE_VA_COPY
> #include <stdarg.h>
> #ifndef va_copy
> #ifdef VA_LIST_IS_STRUCT
> #define va_copy(dest, src) (dest) = (src)
> #else
> #define va_copy(dest, src) *(dest) = *(src)
> #endif
> #endif /* !va_copy */
> #endif /* !HAVE_VA_COPY */
> 
> static int
> int_vasprintf (result, format, args)
>      char **result;
>      const char *format;
>      va_list *args;
> {
> [...]
>   va_copy (ap, *args);

I'll try that.
The original problem was that it segfaulted on x86-64.

Josef

> The 'VA_LIST_IS_STRUCT' test is needed because on some
> compilers it is possible that va_copy is not a macro or
> function, but still va_list is not a pointer but is a
> structure.
> 
> I used the following as a configure test for that in
> ircu:
> 
> dnl
> dnl Macro: ircu_VA_LIST
> dnl
> dnl Check if va_list is a struct or an array/pointer.
> dnl
> AC_DEFUN(ircu_VA_LIST,
> [dnl Check if va_list is a struct or an array/pointer.
> AC_CACHE_CHECK([if va_list is a struct], ircu_cv_sys_va_list_is_struct,
> [AC_TRY_RUN([#include <stdarg.h>
> void vtest(va_list vl)
> {
>   va_arg(vl, int);
> }
> int test(int ret, ...)
> {
>   va_list vl;
>   va_start(vl, ret);
>   vtest(vl);
>   ret = va_arg(vl, int);
>   va_end(vl);
>   return ret;
> }
> int main(void)
> {
>   exit(test(0, 0, 1));
> }], ircu_cv_sys_va_list_is_struct=yes, ircu_cv_sys_va_list_is_struct=no)])
> if test $ircu_cv_sys_va_list_is_struct = yes; then
>   AC_DEFINE(VA_LIST_IS_STRUCT)
> fi])
> 
> As soon as my future papers are done (should be within one or two
> weeks, they are already being mailed to me), you can use this without
> problems as I am the original author of it.
> 
> Also note that in the above I didn't use memcpy(), it depends
> on the size of va_list if that is efficient or not.  By using
> just #define va_copy(dest, src) (dest) = (src), gcc will make
> that decision by itself.
> 
> Regards,
> 
> Carlo Wood


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]