[patch 1/3] Make obconcat use stdarg

Tom Tromey tromey@redhat.com
Fri Apr 30 18:38:00 GMT 2010


>>>>> "Jan" == Jan Kratochvil <jan.kratochvil@redhat.com> writes:

Jan> __attribute__ ((sentinel)) availability for gcc >= 4.0 I have copied from
Jan> <glib-2.0/glib/gmacros.h>.  It roughly matches the GCC ChangeLog dates.

Jan> Still I find this patch as a code cleanup.

I agree.

Jan> +obconcat (struct obstack *obstackp, ...)
Jan> +{
Jan> +  va_list ap;
Jan> +  size_t len = 1;
Jan> +  char *retval, *dest;
Jan> +
Jan> +  va_start (ap, obstackp);
Jan> +  for (;;)
Jan> +    {
Jan> +      const char *s = va_arg (ap, const char *);
Jan> +
Jan> +      if (s == NULL)
Jan> +	break;
Jan> +      len += strlen (s);
Jan> +    }
Jan> +  va_end (ap);

I think it is better to just do the copying in a single loop.
Obstacks already handle growing objects well enough, there's no need to
work around this.

Personally I think this function would be better placed in util.c, but
that isn't a requirement for patch.

Tom



More information about the Gdb-patches mailing list