* [RFA] Cleanup in find_method
@ 2010-12-01 22:58 Keith Seitz
2010-12-02 16:14 ` Tom Tromey
0 siblings, 1 reply; 3+ messages in thread
From: Keith Seitz @ 2010-12-01 22:58 UTC (permalink / raw)
To: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 593 bytes --]
Hi,
While bashing my brains against decode_compound today, I noticed that
name canonicalization in find_method is done inside a loop, and it
doesn't need to be.
I've also taken a small liberty, adding a cleanup for it, just in case
something freaky happens inside find_function_start_sal. I don't think
that this function can fail in this specific case, but call me paranoid.
It doesn't hurt.
Comments?
Keith
ChangeLog
2010-12-01 Keith Seitz <keiths@valrhona.uglyboxes.com>
* linespec.c (find_method): Move name canonicalization outside
the loop.
Be paranoid and use a cleanup.
[-- Attachment #2: find_method-canon-cleanup.patch --]
[-- Type: text/plain, Size: 1380 bytes --]
Index: linespec.c
===================================================================
RCS file: /cvs/src/src/gdb/linespec.c,v
retrieving revision 1.104
diff -u -p -r1.104 linespec.c
--- linespec.c 13 Jul 2010 20:07:44 -0000 1.104
+++ linespec.c 1 Dec 2010 22:47:09 -0000
@@ -1589,15 +1589,20 @@ find_method (int funfirstline, char ***c
if (strchr (saved_arg, '(') != NULL)
{
int i;
+ char *name = saved_arg;
+ char *canon = cp_canonicalize_string (name);
+ struct cleanup *cleanup;
- for (i = 0; i < i1; ++i)
+ if (canon != NULL)
{
- char *name = saved_arg;
- char *canon = cp_canonicalize_string (name);
-
- if (canon != NULL)
- name = canon;
+ name = canon;
+ cleanup = make_cleanup (xfree, canon);
+ }
+ else
+ cleanup = make_cleanup (null_cleanup, NULL);
+ for (i = 0; i < i1; ++i)
+ {
if (strcmp_iw (name, SYMBOL_LINKAGE_NAME (sym_arr[i])) == 0)
{
values.sals = (struct symtab_and_line *)
@@ -1605,13 +1610,9 @@ find_method (int funfirstline, char ***c
values.nelts = 1;
values.sals[0] = find_function_start_sal (sym_arr[i],
funfirstline);
- if (canon)
- xfree (canon);
+ do_cleanups (cleanup);
return values;
}
-
- if (canon)
- xfree (canon);
}
error (_("the class `%s' does not have any method instance named %s\n"),
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [RFA] Cleanup in find_method
2010-12-01 22:58 [RFA] Cleanup in find_method Keith Seitz
@ 2010-12-02 16:14 ` Tom Tromey
2010-12-02 20:06 ` Keith Seitz
0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2010-12-02 16:14 UTC (permalink / raw)
To: Keith Seitz; +Cc: gdb-patches
>>>>> "Keith" == Keith Seitz <keiths@redhat.com> writes:
Keith> I've also taken a small liberty, adding a cleanup for it, just in case
Keith> something freaky happens inside find_function_start_sal. I don't think
Keith> that this function can fail in this specific case, but call me
Keith> paranoid. It doesn't hurt.
Keith> Comments?
This is ok.
Tom
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [RFA] Cleanup in find_method
2010-12-02 16:14 ` Tom Tromey
@ 2010-12-02 20:06 ` Keith Seitz
0 siblings, 0 replies; 3+ messages in thread
From: Keith Seitz @ 2010-12-02 20:06 UTC (permalink / raw)
To: gdb-patches
On 12/02/2010 08:14 AM, Tom Tromey wrote:
> This is ok.
Committed. Thank you for reviewing, Tom.
Keith
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-12-02 20:06 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-01 22:58 [RFA] Cleanup in find_method Keith Seitz
2010-12-02 16:14 ` Tom Tromey
2010-12-02 20:06 ` Keith Seitz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox