This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [RFA 20/23] Avoid some manual memory management in Python
- From: Pedro Alves <palves at redhat dot com>
- To: Tom Tromey <tom at tromey dot com>, gdb-patches at sourceware dot org
- Date: Mon, 5 Jun 2017 14:55:20 +0100
- Subject: Re: [RFA 20/23] Avoid some manual memory management in Python
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=palves at redhat dot com
- Dkim-filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 608164E4D8
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 608164E4D8
- References: <20170503224626.2818-1-tom@tromey.com> <20170503224626.2818-21-tom@tromey.com>
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