Change gdb_abspath to return a unique_xmalloc_ptr

This changes gdb_abspath to return a unique_xmalloc_ptr, and fixes up
the callers.  This allows the removal of a cleanup, and also puts
ownership rules into the API, where they belong.

ChangeLog
2017-08-22  Tom Tromey  <tom@tromey.com>

	* compile/compile.c (compile_file_command): Use
	gdb::unique_xmalloc_ptr, std::string.
	* utils.c (gdb_abspath): Change return type.
	* source.c (openp): Update.
	* objfiles.c (allocate_objfile): Update.
	* main.c (set_gdb_data_directory): Update.
	* utils.h (gdb_abspath): Return a gdb::unique_xmalloc_ptr.
This commit is contained in:
Tom Tromey
2017-08-03 16:32:14 -06:00
parent 0d999a6ef0
commit e3e41d588a
7 changed files with 33 additions and 28 deletions

View File

@@ -90,8 +90,6 @@ static void
compile_file_command (char *arg, int from_tty)
{
enum compile_i_scope_types scope = COMPILE_I_SIMPLE_SCOPE;
char *buffer;
struct cleanup *cleanup;
scoped_restore save_async = make_scoped_restore (&current_ui->async, 0);
@@ -115,12 +113,9 @@ compile_file_command (char *arg, int from_tty)
error (_("Unknown argument specified."));
arg = skip_spaces (arg);
arg = gdb_abspath (arg);
cleanup = make_cleanup (xfree, arg);
buffer = xstrprintf ("#include \"%s\"\n", arg);
make_cleanup (xfree, buffer);
eval_compile_command (NULL, buffer, scope, NULL);
do_cleanups (cleanup);
gdb::unique_xmalloc_ptr<char> abspath = gdb_abspath (arg);
std::string buffer = string_printf ("#include \"%s\"\n", abspath.get ());
eval_compile_command (NULL, buffer.c_str (), scope, NULL);
}
/* Handle the input from the 'compile code' command. The