From: Jim Ingham <jingham@apple.com>
To: Andrew Cagney <ac131313@cygnus.com>
Cc: <gdb@sources.redhat.com>
Subject: Re: Changing the "enclosing_type" of a value structure
Date: Mon, 14 Aug 2000 11:32:00 -0000 [thread overview]
Message-ID: <B5BD8935.40C8%jingham@apple.com> (raw)
In-Reply-To: <3994BF2A.7B903D3F@cygnus.com>
Also sprach Andrew Cagney:
> Jim Ingham wrote:
>
>> /* If we have the full object, but for some reason the enclosing
>> type is wrong, set it *//* pai: FIXME -- sounds iffy */
>
> I like the comment...
Yeah, this is the sort of thing that really warms your heart after you have
spent a couple of days chasing down memory corruption...
>
>> return (value_ptr) xrealloc (val, sizeof (struct type)
>> + TYPE_LENGTH (new_type));
>
> Should it simply refuse to expand a type? That extra data becomes
> undefined in general?
>
The sketch I sent in the last note was not right. You have to change the
lazy flag - which will take care of your objection (though in all the code
paths I could see the data had not been read when this switch was done) -
and you have to stick the new value back into the value chain, or the old
value will get freed, which is BAD. Here is another - better - version.
This one seems to work pretty well.
value_ptr
value_change_enclosing_type (value_ptr val, struct type *new_encl_type)
{
/* If you follow the code, most of the time that this function
is called, the types are the same... So shortcut this case. */
if (new_encl_type == VALUE_ENCLOSING_TYPE (val))
{
return val;
}
else if (TYPE_LENGTH (new_encl_type)
> TYPE_LENGTH (VALUE_ENCLOSING_TYPE (val)))
{
value_ptr old_val = val;
register value_ptr prev;
val = (value_ptr) xrealloc (old_val, sizeof (struct value)
+ TYPE_LENGTH (new_encl_type));
/* We have to make sure this ends up in the same place in the value
chain as the original copy, so it's clean-up behavior is the same.
If the value has been released, this is a waste of time, but there
is no way to tell that in advance, so... */
if (old_val != all_values)
{
for (prev = all_values; prev != NULL; prev = prev->next)
{
if (prev->next == old_val)
{
prev->next = val;
break;
}
}
}
}
VALUE_ENCLOSING_TYPE (val) = new_encl_type;
/* If we had to change the enclosing type, the data in the value
is no longer good. Setting lazy back to 1 will force it to be
reread. */
VALUE_LAZY (val) = 1;
return val;
}
Jim
--
Jim Ingham jingham@apple.com
Apple Computer
next prev parent reply other threads:[~2000-08-14 11:32 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-08-08 16:21 Jim Ingham
2000-08-11 20:09 ` Andrew Cagney
2000-08-14 11:32 ` Jim Ingham [this message]
2000-08-14 23:33 ` Eli Zaretskii
2000-08-15 16:08 Jim Ingham
2000-08-15 23:20 ` Eli Zaretskii
2000-08-16 11:21 ` Jim Ingham
2000-08-16 15:11 ` Eli Zaretskii
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=B5BD8935.40C8%jingham@apple.com \
--to=jingham@apple.com \
--cc=ac131313@cygnus.com \
--cc=gdb@sources.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).