diff options
author | Pedro Alves <palves@redhat.com> | 2016-10-28 23:08:08 +0100 |
---|---|---|
committer | Pedro Alves <palves@redhat.com> | 2016-11-17 03:10:00 +0000 |
commit | 3d4ed53ca597f71c72ff0db995468578482a0ee0 (patch) | |
tree | 23c91cebc43c07ae98f0a494642734aa8abc83f5 /gdb/cp-support.c | |
parent | 05c10af4c15d9501046f6740cdf1173fbd9c3a2e (diff) | |
download | binutils-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/cp-support.c')
-rw-r--r-- | gdb/cp-support.c | 38 |
1 files changed, 16 insertions, 22 deletions
diff --git a/gdb/cp-support.c b/gdb/cp-support.c index d409b0b92e7..b0b91fc133f 100644 --- a/gdb/cp-support.c +++ b/gdb/cp-support.c @@ -210,7 +210,6 @@ inspect_type (struct demangle_parse_info *info, int is_anon; struct type *type; struct demangle_parse_info *i; - struct ui_file *buf; /* Get the real type of the typedef. */ type = check_typedef (otype); @@ -246,23 +245,21 @@ inspect_type (struct demangle_parse_info *info, type = last; } - buf = mem_fileopen (); + string_file buf; TRY - { - type_print (type, "", buf, -1); - } - + { + type_print (type, "", &buf, -1); + } /* If type_print threw an exception, there is little point in continuing, so just bow out gracefully. */ CATCH (except, RETURN_MASK_ERROR) { - ui_file_delete (buf); return 0; } END_CATCH - name = ui_file_obsavestring (buf, &info->obstack, &len); - ui_file_delete (buf); + len = buf.size (); + name = (char *) obstack_copy0 (&info->obstack, buf.c_str (), len); /* Turn the result into a new tree. Note that this tree will contain pointers into NAME, so NAME cannot @@ -319,7 +316,7 @@ replace_typedefs_qualified_name (struct demangle_parse_info *info, { long len; char *name; - struct ui_file *buf = mem_fileopen (); + string_file buf; struct demangle_component *comp = ret_comp; /* Walk each node of the qualified name, reconstructing the name of @@ -333,9 +330,9 @@ replace_typedefs_qualified_name (struct demangle_parse_info *info, { struct demangle_component newobj; - ui_file_write (buf, d_left (comp)->u.s_name.s, - d_left (comp)->u.s_name.len); - name = ui_file_obsavestring (buf, &info->obstack, &len); + buf.write (d_left (comp)->u.s_name.s, d_left (comp)->u.s_name.len); + len = buf.size (); + name = (char *) obstack_copy0 (&info->obstack, buf.c_str (), len); newobj.type = DEMANGLE_COMPONENT_NAME; newobj.u.s_name.s = name; newobj.u.s_name.len = len; @@ -348,12 +345,11 @@ replace_typedefs_qualified_name (struct demangle_parse_info *info, string and replace the top DEMANGLE_COMPONENT_QUAL_NAME node. */ - ui_file_rewind (buf); + buf.rewind (); n = cp_comp_to_string (&newobj, 100); if (n == NULL) { /* If something went astray, abort typedef substitutions. */ - ui_file_delete (buf); return; } @@ -378,14 +374,13 @@ replace_typedefs_qualified_name (struct demangle_parse_info *info, if (name == NULL) { /* If something went astray, abort typedef substitutions. */ - ui_file_delete (buf); return; } - fputs_unfiltered (name, buf); + buf.puts (name); xfree (name); } - ui_file_write (buf, "::", 2); + buf.write ("::", 2); comp = d_right (comp); } @@ -395,8 +390,9 @@ replace_typedefs_qualified_name (struct demangle_parse_info *info, if (comp->type == DEMANGLE_COMPONENT_NAME) { - ui_file_write (buf, comp->u.s_name.s, comp->u.s_name.len); - name = ui_file_obsavestring (buf, &info->obstack, &len); + buf.write (comp->u.s_name.s, comp->u.s_name.len); + len = buf.size (); + name = (char *) obstack_copy0 (&info->obstack, buf.c_str (), len); /* Replace the top (DEMANGLE_COMPONENT_QUAL_NAME) node with a DEMANGLE_COMPONENT_NAME node containing the whole @@ -408,8 +404,6 @@ replace_typedefs_qualified_name (struct demangle_parse_info *info, } else replace_typedefs (info, comp, finder, data); - - ui_file_delete (buf); } |