diff options
author | Tom Tromey <tom@tromey.com> | 2017-08-05 10:40:15 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2017-08-22 09:30:13 -0600 |
commit | 56f37645249752378520a1c2430225c9cee09161 (patch) | |
tree | adb2a2fc529ce4c7763a3811b662a6d8e04f6246 /gdb/psymtab.c | |
parent | 0b581c69fe7186d7d0ea1283c7ecf9839a8827cc (diff) | |
download | gdb-56f37645249752378520a1c2430225c9cee09161.zip gdb-56f37645249752378520a1c2430225c9cee09161.tar.gz gdb-56f37645249752378520a1c2430225c9cee09161.tar.bz2 |
Change psymtab_search_name to return a unique_xmalloc_ptr
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-22 Tom Tromey <tom@tromey.com>
* psymtab.c (psymtab_search_name): Return a unique_xmalloc_ptr.
(lookup_partial_symbol): Update.
Diffstat (limited to 'gdb/psymtab.c')
-rw-r--r-- | gdb/psymtab.c | 32 |
1 files changed, 12 insertions, 20 deletions
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; } |