This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[RFA 5/5] Change psymtab_search_name to return a unique_xmalloc_ptr
- From: Tom Tromey <tom at tromey dot com>
- To: gdb-patches at sourceware dot org
- Cc: Tom Tromey <tom at tromey dot com>
- Date: Fri, 18 Aug 2017 14:00:24 -0600
- Subject: [RFA 5/5] Change psymtab_search_name to return a unique_xmalloc_ptr
- Authentication-results: sourceware.org; auth=none
- References: <20170818200024.4948-1-tom@tromey.com>
This changes psymtab_search_name to return a unique_xmalloc_ptr and
fixes up its one caller. This allows the removal of some cleanups.
ChangeLog
2017-08-18 Tom Tromey <tom@tromey.com>
* psymtab.c (psymtab_search_name): Return a unique_xmalloc_ptr.
(lookup_partial_symbol): Update.
---
gdb/ChangeLog | 5 +++++
gdb/psymtab.c | 32 ++++++++++++--------------------
2 files changed, 17 insertions(+), 20 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index a15df78..4e03f29 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
2017-08-18 Tom Tromey <tom@tromey.com>
+ * psymtab.c (psymtab_search_name): Return a unique_xmalloc_ptr.
+ (lookup_partial_symbol): Update.
+
+2017-08-18 Tom Tromey <tom@tromey.com>
+
* source.h (rewrite_source_path): Return a unique_xmalloc_ptr.
* source.c (rewrite_source_path): Return a unique_xmalloc_ptr.
(find_and_open_source, symtab_to_fullname): Update.
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index 6307d6e..4cbf91c 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -627,7 +627,7 @@ match_partial_symbol (struct objfile *objfile,
The caller is responsible for freeing the return result. */
-static char *
+static gdb::unique_xmalloc_ptr<char>
psymtab_search_name (const char *name)
{
switch (current_language->la_language)
@@ -639,7 +639,7 @@ psymtab_search_name (const char *name)
char *ret = cp_remove_params (name);
if (ret)
- return ret;
+ return gdb::unique_xmalloc_ptr<char> (ret);
}
}
break;
@@ -648,7 +648,7 @@ psymtab_search_name (const char *name)
break;
}
- return xstrdup (name);
+ return gdb::unique_xmalloc_ptr<char> (xstrdup (name));
}
/* Look, in partial_symtab PST, for symbol whose natural name is NAME.
@@ -663,14 +663,11 @@ lookup_partial_symbol (struct objfile *objfile,
struct partial_symbol **top, **real_top, **bottom, **center;
int length = (global ? pst->n_global_syms : pst->n_static_syms);
int do_linear_search = 1;
- char *search_name;
- struct cleanup *cleanup;
if (length == 0)
return NULL;
- search_name = psymtab_search_name (name);
- cleanup = make_cleanup (xfree, search_name);
+ gdb::unique_xmalloc_ptr<char> search_name = psymtab_search_name (name);
start = (global ?
objfile->global_psymbols.list + pst->globals_offset :
objfile->static_psymbols.list + pst->statics_offset);
@@ -695,7 +692,7 @@ lookup_partial_symbol (struct objfile *objfile,
internal_error (__FILE__, __LINE__,
_("failed internal consistency check"));
if (strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*center),
- search_name) >= 0)
+ search_name.get ()) >= 0)
{
top = center;
}
@@ -710,20 +707,19 @@ lookup_partial_symbol (struct objfile *objfile,
/* For `case_sensitivity == case_sensitive_off' strcmp_iw_ordered will
search more exactly than what matches SYMBOL_MATCHES_SEARCH_NAME. */
- while (top >= start && SYMBOL_MATCHES_SEARCH_NAME (*top, search_name))
+ while (top >= start && SYMBOL_MATCHES_SEARCH_NAME (*top,
+ search_name.get ()))
top--;
/* Fixup to have a symbol which matches SYMBOL_MATCHES_SEARCH_NAME. */
top++;
- while (top <= real_top && SYMBOL_MATCHES_SEARCH_NAME (*top, search_name))
+ while (top <= real_top
+ && SYMBOL_MATCHES_SEARCH_NAME (*top, search_name.get ()))
{
if (symbol_matches_domain (SYMBOL_LANGUAGE (*top),
SYMBOL_DOMAIN (*top), domain))
- {
- do_cleanups (cleanup);
- return *top;
- }
+ return *top;
top++;
}
}
@@ -737,15 +733,11 @@ lookup_partial_symbol (struct objfile *objfile,
{
if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym),
SYMBOL_DOMAIN (*psym), domain)
- && SYMBOL_MATCHES_SEARCH_NAME (*psym, search_name))
- {
- do_cleanups (cleanup);
- return *psym;
- }
+ && SYMBOL_MATCHES_SEARCH_NAME (*psym, search_name.get ()))
+ return *psym;
}
}
- do_cleanups (cleanup);
return NULL;
}
--
2.9.4