From: Phil Muldoon <pmuldoon@redhat.com>
To: Pedro Alves <pedro@codesourcery.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [rfc] Prompt memory management/cleanups
Date: Wed, 20 Jul 2011 14:37:00 -0000 [thread overview]
Message-ID: <m3oc0puiro.fsf@redhat.com> (raw)
In-Reply-To: <201107201514.46833.pedro@codesourcery.com> (Pedro Alves's message of "Wed, 20 Jul 2011 15:14:46 +0100")
Pedro Alves <pedro@codesourcery.com> writes:
> On Wednesday 20 July 2011 14:05:11, Phil Muldoon wrote:
>> +set_prompt (const char *s, int level)
>> {
>> -/* ??rehrauer: I don't know why this fails, since it looks as though
>> - assignments to prompt are wrapped in calls to xstrdup...
>> - if (prompt != NULL)
>> - xfree (prompt);
>> - */
>> - PROMPT (0) = xstrdup (s);
>> + /* If S is NULL, just free the PROMPT at level LEVEL and set to
>> + NULL. */
>> + if (s == NULL)
>> + {
>> + xfree (PROMPT (level));
>> + PROMPT (level) = NULL;
>> + }
>
>
>> + else
>> + /* If S == PROMPT then do not free it or set it. If we did
>> + that, S (which points to PROMPT), would become garbage. */
>> + if (s != PROMPT (level))
>> + {
>
> This looks strange, and I suppose complicates the callers' life a bit,
> having to know when are they giving up ownership of the string
> or not. What would need to change at the callers if we dropped
> that s != PROMPT() check?
This is a fail-safe for the Python prompt substitution patch. So if they
did (the equivalent in Python):
s = get_prompt (0)
set_prompt (s, 0)
Without that check, 'PROMPT (level)' would be freed, but 's' points to
that. So you set garbage. get_prompt returns a pointer, not a copy.
Internal uses of set_prompt we can just do the checks wherever we want.
Basically checking if your pointer to the prompt is in-fact the current
prompt. I thought about doing this at the callers, but it just
replicated the code everywhere, and in static (IE internal GDB code) that
seemed pointless. We could just xstrdup s, then free the prompt anyway, and
then set it. But then the s they passed to the function, will still be
pointing to xfree'd space; I am not sure if that matters. This seemed
the safest way, and not allow prompts to become corrupted. I am
completely open to changing it if there is a better way.
Cheers,
Phil
next prev parent reply other threads:[~2011-07-20 14:30 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 [this message]
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
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=m3oc0puiro.fsf@redhat.com \
--to=pmuldoon@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=pedro@codesourcery.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