diff options
author | Tom Tromey <tom@tromey.com> | 2017-10-12 16:48:35 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2017-10-16 16:10:21 -0600 |
commit | b7b030adc405017f01e996a90f85e40730ef8397 (patch) | |
tree | 5d6fdf82c43f719834633295cbcde80f75d5663d /gdb/xml-support.c | |
parent | b80406accc70791a1789e40f24d64161bc41de34 (diff) | |
download | gdb-b7b030adc405017f01e996a90f85e40730ef8397.zip gdb-b7b030adc405017f01e996a90f85e40730ef8397.tar.gz gdb-b7b030adc405017f01e996a90f85e40730ef8397.tar.bz2 |
Return unique_xmalloc_ptr from target_read_stralloc
This changes target_read_stralloc to return a unique_xmalloc_ptr, and
then fixes all the callers. unique_xmalloc_ptr is used, rather than
std::string, because target_read_stralloc gives a special meaning to a
NULL return.
ChangeLog
2017-10-16 Tom Tromey <tom@tromey.com>
* xml-syscall.c (xml_init_syscalls_info): Update.
* xml-support.c (xinclude_start_include): Update.
(xml_fetch_content_from_file): Return unique_xmalloc_ptr.
* xml-support.h (xml_fetch_another): Return unique_xmalloc_ptr.
(xml_fetch_content_from_file): Likewise.
* osdata.c (get_osdata): Update.
* target.h (target_read_stralloc, target_get_osdata): Return
unique_xmalloc_ptr.
* solib-aix.c (solib_aix_get_library_list): Update.
* solib-target.c (solib_target_current_sos): Update.
* solib-svr4.c (svr4_current_sos_via_xfer_libraries): Update.
* xml-tdesc.c (fetch_available_features_from_target): Update.
(target_fetch_description_xml): Update.
(file_read_description_xml): Update.
* remote.c (remote_get_threads_with_qxfer, remote_memory_map)
(remote_traceframe_info, btrace_read_config, remote_read_btrace)
(remote_pid_to_exec_file): Update.
* target.c (target_read_stralloc): Return unique_xmalloc_ptr.
(target_get_osdata): Likewise.
Diffstat (limited to 'gdb/xml-support.c')
-rw-r--r-- | gdb/xml-support.c | 27 |
1 files changed, 9 insertions, 18 deletions
diff --git a/gdb/xml-support.c b/gdb/xml-support.c index 50a062a..76d03b9 100644 --- a/gdb/xml-support.c +++ b/gdb/xml-support.c @@ -808,8 +808,6 @@ xinclude_start_include (struct gdb_xml_parser *parser, struct xinclude_parsing_data *data = (struct xinclude_parsing_data *) user_data; char *href = (char *) xml_find_attribute (attributes, "href")->value; - struct cleanup *back_to; - char *text, *output; gdb_xml_debug (parser, _("Processing XInclude of \"%s\""), href); @@ -817,19 +815,17 @@ xinclude_start_include (struct gdb_xml_parser *parser, gdb_xml_error (parser, _("Maximum XInclude depth (%d) exceeded"), MAX_XINCLUDE_DEPTH); - text = data->fetcher (href, data->fetcher_baton); + gdb::unique_xmalloc_ptr<char> text = data->fetcher (href, + data->fetcher_baton); if (text == NULL) gdb_xml_error (parser, _("Could not load XML document \"%s\""), href); - back_to = make_cleanup (xfree, text); if (!xml_process_xincludes (data->output, parser->name (), - text, data->fetcher, + text.get (), data->fetcher, data->fetcher_baton, data->include_depth + 1)) gdb_xml_error (parser, _("Parsing \"%s\" failed"), href); - do_cleanups (back_to); - data->skip_depth++; } @@ -997,13 +993,11 @@ show_debug_xml (struct ui_file *file, int from_tty, fprintf_filtered (file, _("XML debugging is %s.\n"), value); } -char * +gdb::unique_xmalloc_ptr<char> xml_fetch_content_from_file (const char *filename, void *baton) { const char *dirname = (const char *) baton; gdb_file_up file; - struct cleanup *back_to; - char *text; size_t len, offset; if (dirname && *dirname) @@ -1024,19 +1018,18 @@ xml_fetch_content_from_file (const char *filename, void *baton) /* Read in the whole file, one chunk at a time. */ len = 4096; offset = 0; - text = (char *) xmalloc (len); - back_to = make_cleanup (free_current_contents, &text); + gdb::unique_xmalloc_ptr<char> text ((char *) xmalloc (len)); while (1) { size_t bytes_read; /* Continue reading where the last read left off. Leave at least one byte so that we can NUL-terminate the result. */ - bytes_read = fread (text + offset, 1, len - offset - 1, file.get ()); + bytes_read = fread (text.get () + offset, 1, len - offset - 1, + file.get ()); if (ferror (file.get ())) { warning (_("Read error from \"%s\""), filename); - do_cleanups (back_to); return NULL; } @@ -1046,12 +1039,10 @@ xml_fetch_content_from_file (const char *filename, void *baton) break; len = len * 2; - text = (char *) xrealloc (text, len); + text.reset ((char *) xrealloc (text.get (), len)); } - discard_cleanups (back_to); - - text[offset] = '\0'; + text.get ()[offset] = '\0'; return text; } |