Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <pedro@codesourcery.com>
To: Tom Tromey <tromey@redhat.com>
Cc: pmuldoon@redhat.com, gdb-patches@sourceware.org
Subject: Re: [rfc] Prompt memory management/cleanups
Date: Wed, 20 Jul 2011 16:04:00 -0000	[thread overview]
Message-ID: <201107201645.14136.pedro@codesourcery.com> (raw)
In-Reply-To: <m3hb6hyo4m.fsf@fleche.redhat.com>

On Wednesday 20 July 2011 16:20:57, Tom Tromey wrote:
> >>>>> "Pedro" == Pedro Alves <pedro@codesourcery.com> writes:
> 
> Pedro> You've asked for comments on the API, and IMO this makes for
> Pedro> a weird API, because the caller of set_prompt needs to know
> Pedro> whether set_prompt will take ownership of the pointer or not
> Pedro> depending on where the pointer came from.  I haven't looked
> Pedro> at the callers -- that's why I asked what would need to
> Pedro> change.  :-)
> 
> The problem case is set_prompt(get_prompt()), but here the prompt code
> already owns the pointer.  

I don't think that would change if you make set_prompt xstrdup
before xfree.

> I guess it is a little weird, but it still
> falls under the general rule of "you have to call get_prompt again to
> get the prompt after set_prompt".

The current code allows:

 p = get_prompt(0);
 set_prompt(p, 0);
 // p is still valid here

whereas:

 p = get_prompt(0);
 set_prompt("foo", 0);
 // p is invalid here

But if we already have that rule, then we can treat the
former as undefined.

I think we should still xstrdup before xfree though as
a general rule in these sort of scenarios.  Otherwise:

 p = get_prompt(0);  (p's len being > 0)
 set_prompt(p + 1, 0);

will end up with garbage.

-- 
Pedro Alves


  reply	other threads:[~2011-07-20 15:45 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-20 13:46 Phil Muldoon
2011-07-20 14:30 ` Pedro Alves
2011-07-20 14:37   ` Phil Muldoon
2011-07-20 15:01     ` Pedro Alves
2011-07-20 15:06       ` Phil Muldoon
2011-07-20 15:15         ` Pedro Alves
2011-07-20 15:45           ` Tom Tromey
2011-07-20 16:04             ` Pedro Alves [this message]
2011-07-20 16:06               ` Tom Tromey
2011-07-20 15:05 ` Tom Tromey
2011-07-20 15:21   ` Phil Muldoon
2011-07-20 15:35     ` Tom Tromey
2011-07-21 17:15   ` Phil Muldoon
2011-07-21 20:42     ` Tom Tromey
2011-07-22 13:26       ` Phil Muldoon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201107201645.14136.pedro@codesourcery.com \
    --to=pedro@codesourcery.com \
    --cc=gdb-patches@sourceware.org \
    --cc=pmuldoon@redhat.com \
    --cc=tromey@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox