summaryrefslogtreecommitdiff
path: root/gdb/ada-lang.c
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2016-10-28 23:08:08 +0100
committerPedro Alves <palves@redhat.com>2016-11-17 03:10:00 +0000
commit3d4ed53ca597f71c72ff0db995468578482a0ee0 (patch)
tree23c91cebc43c07ae98f0a494642734aa8abc83f5 /gdb/ada-lang.c
parent05c10af4c15d9501046f6740cdf1173fbd9c3a2e (diff)
downloadbinutils-gdb-users/palves/cxx-eliminate-cleanups.tar.gz
Eliminate make_cleanup_ui_file_deleteusers/palves/cxx-eliminate-cleanups
And now that ui_file_as_string is in, let's eliminate it. :-) Makes ui_file a real C++ hierarchy. mem_fileopen is replaced with a new string_file class that is treated as a value class created on the stack. This alone eliminates most make_cleanup_ui_file_delete calls, and, simplifies code a whole lot (diffstat shows almost 1k loc dropped.) string_file has a string() method that gives you a direct reference to the internal std::string. This is what replaces old (well, new) ui_file_as_string, which used to alway return a new copy of the same data the stream had inside.. With direct access via a writable reference, we can instead move the string out of the string_stream. Note I needed a tweak on scoped_restore. That one should probably be split out to a separate patch. This exposed the need to make use of gnulib namespace support. Otherwise, making use of read/write/printf/puts/etc symbol names will clash on systems where gnulib replaces those functions, due to '#define foo rpl_foo'.
Diffstat (limited to 'gdb/ada-lang.c')
-rw-r--r--gdb/ada-lang.c12
1 files changed, 3 insertions, 9 deletions
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index e364bd85685..f6591199ad3 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -7602,17 +7602,11 @@ ada_value_struct_elt (struct value *arg, char *name, int no_err)
static std::string
type_as_string (struct type *type)
{
- struct ui_file *tmp_stream = mem_fileopen ();
- struct cleanup *old_chain;
-
- tmp_stream = mem_fileopen ();
- old_chain = make_cleanup_ui_file_delete (tmp_stream);
+ string_file tmp_stream;
- type_print (type, "", tmp_stream, -1);
- std::string str = ui_file_as_string (tmp_stream);
+ type_print (type, "", &tmp_stream, -1);
- do_cleanups (old_chain);
- return str;
+ return std::move (tmp_stream.string ());
}
/* Given a type TYPE, look up the type of the component of type named NAME.