Re: [RFA 20/23] Avoid some manual memory management in Python

Pedro Alves
2017-06-05T13:55:21Z

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