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.
This commit is contained in:
Tom Tromey 2017-10-12 16:48:35 -06:00
parent b80406accc
commit b7b030adc4
12 changed files with 102 additions and 168 deletions

View file

@ -673,24 +673,16 @@ tdesc_parse_xml (const char *document, xml_fetch_another fetcher,
const struct target_desc *
file_read_description_xml (const char *filename)
{
struct target_desc *tdesc;
char *tdesc_str;
struct cleanup *back_to;
tdesc_str = xml_fetch_content_from_file (filename, NULL);
gdb::unique_xmalloc_ptr<char> tdesc_str
= xml_fetch_content_from_file (filename, NULL);
if (tdesc_str == NULL)
{
warning (_("Could not open \"%s\""), filename);
return NULL;
}
back_to = make_cleanup (xfree, tdesc_str);
tdesc = tdesc_parse_xml (tdesc_str, xml_fetch_content_from_file,
(void *) ldirname (filename).c_str ());
do_cleanups (back_to);
return tdesc;
return tdesc_parse_xml (tdesc_str.get (), xml_fetch_content_from_file,
(void *) ldirname (filename).c_str ());
}
/* Read a string representation of available features from the target,
@ -700,7 +692,7 @@ file_read_description_xml (const char *filename)
is "target.xml". Other calls may be performed for the DTD or
for <xi:include>. */
static char *
static gdb::unique_xmalloc_ptr<char>
fetch_available_features_from_target (const char *name, void *baton_)
{
struct target_ops *ops = (struct target_ops *) baton_;
@ -719,21 +711,14 @@ fetch_available_features_from_target (const char *name, void *baton_)
const struct target_desc *
target_read_description_xml (struct target_ops *ops)
{
struct target_desc *tdesc;
char *tdesc_str;
struct cleanup *back_to;
tdesc_str = fetch_available_features_from_target ("target.xml", ops);
gdb::unique_xmalloc_ptr<char> tdesc_str
= fetch_available_features_from_target ("target.xml", ops);
if (tdesc_str == NULL)
return NULL;
back_to = make_cleanup (xfree, tdesc_str);
tdesc = tdesc_parse_xml (tdesc_str,
fetch_available_features_from_target,
ops);
do_cleanups (back_to);
return tdesc;
return tdesc_parse_xml (tdesc_str.get (),
fetch_available_features_from_target,
ops);
}
/* Fetches an XML target description using OPS, processing
@ -758,7 +743,7 @@ target_fetch_description_xml (struct target_ops *ops)
struct target_desc *tdesc;
gdb::unique_xmalloc_ptr<char>
tdesc_str (fetch_available_features_from_target ("target.xml", ops));
tdesc_str = fetch_available_features_from_target ("target.xml", ops);
if (tdesc_str == NULL)
return {};