This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB 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: [RFA 20/23] Avoid some manual memory management in Python


On 05/03/2017 11:46 PM, Tom Tromey wrote:
> This changes a few places in the Python code to avoid manual memory
> management, in favor of letting std::string do the work.

Nice.

> -static char *
> +static std::string
>  compute_python_string (struct command_line *l)
>  {

This hunk in particular really simplifies things.

> -  script = (char *) xmalloc (size + 1);
> -  here = 0;
> -  for (iter = l; iter; iter = iter->next)
>      {
> -      int len = strlen (iter->line);
> -
> -      strcpy (&script[here], iter->line);
> -      here += len;
> -      script[here++] = '\n';
> +      script += iter->line;
> +      script += "\n";

Say:

   script += '\n';

(i.e., call the character overload when append a
character, not the const char * overload.)

Otherwise OK.

Thanks,
Pedro Alves


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