From b02f78f9285728ce2d05ce01e7b14880f70cd6e6 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Tue, 4 Jun 2019 22:40:54 +0100 Subject: Introduce and use make_unique_xstrdup Adds an utility function to make it shorter to write the common case of wrapping an xstrdup with a unique_xmalloc_ptr, and uses it throughout. Note: I tried to put this in common/common-utils.h near skip_spaces, etc. but that is included in common/common-defs.h before common/gdb_unique_ptr.h is included, so it would fail to compile because gdb::unique_xmalloc_ptr isn't defined at that point yet. I tried moving the gdb_unique_ptr.h inclusion before common-utils.h, but that doesn't work because gdb_unique_ptr.h depends on common-utils.h for xfree. gdb/ChangeLog: 2019-06-04 Pedro Alves * common/gdb_unique_ptr.h (make_unique_xstrdup): New. * ada-lang.c (catch_ada_completer): Use make_unique_xstrdup. * breakpoint.c (condition_completer): Likewise. * cli/cli-dump.c (scan_expression): Likewise. * common/filestuff.c (mkdir_recursive): Likewise. * common/gdb_tilde_expand.c (gdb_tilde_expand_up) * common/pathstuff.c (gdb_realpath, gdb_realpath_keepfile) (gdb_abspath): Likewise. * compile/compile-cplus-types.c (compile_cplus_instance::decl_name): Likewise. * completer.c (complete_explicit_location): (signal_completer, reg_or_group_completer_1): Likewise. * cp-support.c (cp_remove_params_if_any): Likewise. * fbsd-tdep.c (fbsd_core_vnode_path): Likewise. * guile/scm-safe-call.c (gdbscm_safe_eval_string): Likewise. * infcmd.c (strip_bg_char): Likewise. * linespec.c (copy_token_string): Likewise. * mi/mi-main.c (output_cores): Likewise. * psymtab.c (psymtab_search_name): * symfile.c (test_set_ext_lang_command): Likewise. * target.c (target_fileio_read_stralloc): Likewise. * tui/tui-regs.c (tui_reggroup_completer): Likewise. * value.c (complete_internalvar): Likewise. gdb/gdbserver/ChangeLog: 2019-06-04 Pedro Alves * server.c (captured_main): Use make_unique_xstrdup. --- gdb/common/pathstuff.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'gdb/common/pathstuff.c') diff --git a/gdb/common/pathstuff.c b/gdb/common/pathstuff.c index 2b1669a..e0e048d 100644 --- a/gdb/common/pathstuff.c +++ b/gdb/common/pathstuff.c @@ -65,7 +65,7 @@ gdb_realpath (const char *filename) we might not be able to display the original casing in a given path. */ if (len > 0 && len < MAX_PATH) - return gdb::unique_xmalloc_ptr (xstrdup (buf)); + return make_unique_xstrdup (buf); } #else { @@ -77,7 +77,7 @@ gdb_realpath (const char *filename) #endif /* This system is a lost cause, just dup the buffer. */ - return gdb::unique_xmalloc_ptr (xstrdup (filename)); + return make_unique_xstrdup (filename); } /* See common/pathstuff.h. */ @@ -92,7 +92,7 @@ gdb_realpath_keepfile (const char *filename) /* Extract the basename of filename, and return immediately a copy of filename if it does not contain any directory prefix. */ if (base_name == filename) - return gdb::unique_xmalloc_ptr (xstrdup (filename)); + return make_unique_xstrdup (filename); dir_name = (char *) alloca ((size_t) (base_name - filename + 2)); /* Allocate enough space to store the dir_name + plus one extra @@ -135,7 +135,7 @@ gdb_abspath (const char *path) return gdb_tilde_expand_up (path); if (IS_ABSOLUTE_PATH (path)) - return gdb::unique_xmalloc_ptr (xstrdup (path)); + return make_unique_xstrdup (path); /* Beware the // my son, the Emacs barfs, the botch that catch... */ return gdb::unique_xmalloc_ptr -- cgit v1.1