[PATCH] Replace some uses of xstrprintf with string_printf

Simon Marchi simon.marchi@polymtl.ca
Tue Aug 7 21:46:00 GMT 2018


On 2018-08-07 11:53, Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi <simon.marchi@polymtl.ca> writes:
> 
> Simon> From: Simon Marchi <simon.marchi@ericsson.com>
> Simon> This patch replaces some simple uses of xstrprintf with with
> Simon> string_printf, removing the need to do manual memory freeing.
> 
> Simon> The change in ada-lang.c fixes an apparent memory leak.
> 
> FWIW, I read this patch and I think it is good.

Thanks, I pushed it.

> Simon> +  std::string message
> Simon> +    = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
> Simon> +		     objfile_name (objfile),
> Simon> +		     sect_offset_str (cu->header.sect_off),
> Simon> +		     sect_offset_str (die->sect_off));
> Simon>    saved = (char *) obstack_copy0 (&objfile->objfile_obstack,
> 
> gnulib (and glibc) have an obstack_printf function, which would perhaps
> avoid some allocations here.
> 
> However, I don't know if it is practical to import the gnulib
> obstack_printf, because presumably it would want the gnulib obstack 
> code
> generally, and gdb is using the obstack from libiberty.
> 
> In the long run I tend to think it would be better to promote gnulib to
> the top level and remove some things from libiberty.  But that seems
> like a pretty big project.

Ok, I don't really have an opinion because I don't know the history of 
all the parts.  But it would also be quite simple to do our own 
obstack_printf, like we have string_printf.

Simon



More information about the Gdb-patches mailing list