summaryrefslogtreecommitdiff
path: root/gdb/auto-load.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2017-04-26 21:49:55 -0600
committerTom Tromey <tom@tromey.com>2017-08-03 07:58:53 -0600
commited1669453be56d71351c77377acee097aefe83b1 (patch)
tree80ee2b988d2bddb6f52fbf3e1fee2bb3376adab5 /gdb/auto-load.c
parentd419f42dd3f3635fc036413258ed530676998191 (diff)
downloadbinutils-gdb-ed1669453be56d71351c77377acee097aefe83b1.tar.gz
Change return type of find_and_open_script
This changes find_and_open_script to return a gdb::optional<open_script>, where open_script is a new type encapsulating the two return values. The new type helps avoid cleanups in the callers. ChangeLog 2017-08-03 Tom Tromey <tom@tromey.com> * cli/cli-cmds.c (find_and_open_script): Change return type. Remove "streamp" and "full_path" parameters. (source_script_with_search): Update. * auto-load.c (source_script_file): Update. * cli/cli-cmds.h (find_and_open_script): Change type. (open_script): New struct.
Diffstat (limited to 'gdb/auto-load.c')
-rw-r--r--gdb/auto-load.c32
1 files changed, 13 insertions, 19 deletions
diff --git a/gdb/auto-load.c b/gdb/auto-load.c
index 292f2ae88e9..9f1f13f926d 100644
--- a/gdb/auto-load.c
+++ b/gdb/auto-load.c
@@ -928,10 +928,7 @@ source_script_file (struct auto_load_pspace_info *pspace_info,
const char *section_name, unsigned int offset,
const char *file)
{
- FILE *stream;
- char *full_path;
- int opened, in_hash_table;
- struct cleanup *cleanups;
+ int in_hash_table;
objfile_script_sourcer_func *sourcer;
/* Skip this script if support is not compiled in. */
@@ -953,27 +950,22 @@ source_script_file (struct auto_load_pspace_info *pspace_info,
return;
}
- opened = find_and_open_script (file, 1 /*search_path*/,
- &stream, &full_path);
+ gdb::optional<open_script> opened = find_and_open_script (file,
+ 1 /*search_path*/);
- cleanups = make_cleanup (null_cleanup, NULL);
if (opened)
{
- make_cleanup_fclose (stream);
- make_cleanup (xfree, full_path);
-
- if (!file_is_auto_load_safe (full_path,
+ if (!file_is_auto_load_safe (opened->full_path.get (),
_("auto-load: Loading %s script "
"\"%s\" from section \"%s\" of "
"objfile \"%s\".\n"),
- ext_lang_name (language), full_path,
+ ext_lang_name (language),
+ opened->full_path.get (),
section_name, objfile_name (objfile)))
- opened = 0;
+ opened.reset ();
}
else
{
- full_path = NULL;
-
/* If one script isn't found it's not uncommon for more to not be
found either. We don't want to print a message for each script,
too much noise. Instead, we print the warning once and tell the
@@ -986,14 +978,16 @@ source_script_file (struct auto_load_pspace_info *pspace_info,
section_name, offset);
}
- in_hash_table = maybe_add_script_file (pspace_info, opened, file, full_path,
+ in_hash_table = maybe_add_script_file (pspace_info, bool (opened), file,
+ (opened
+ ? opened->full_path.get ()
+ : NULL),
language);
/* If this file is not currently loaded, load it. */
if (opened && !in_hash_table)
- sourcer (language, objfile, stream, full_path);
-
- do_cleanups (cleanups);
+ sourcer (language, objfile, opened->stream.get (),
+ opened->full_path.get ());
}
/* Subroutine of source_section_scripts to simplify it.