This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH 02/40] Eliminate make_cleanup_obstack_free, introduce auto_obstack
- From: Pedro Alves <palves at redhat dot com>
- To: gdb-patches at sourceware dot org
- Date: Fri, 2 Jun 2017 13:22:00 +0100
- Subject: [PATCH 02/40] Eliminate make_cleanup_obstack_free, introduce auto_obstack
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=palves at redhat dot com
- Dkim-filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 147D2232055
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 147D2232055
- References: <1496406158-12663-1-git-send-email-palves@redhat.com>
These changes in the parsers may not be obvious:
- obstack_init (&name_obstack);
- make_cleanup_obstack_free (&name_obstack);
+ name_obstack.clear ();
Here, the 'name_obstack' variable is a global. The change means that
the obstack's contents from a previous parse will stay around until
the next parsing starts. I.e., memory won't be reclaimed until them.
I don't think that's a problem, these objects don't really grow much
at all.
The other option I tried was to add a separate type that is like
auto_obstack but manages an external obstack, just for those cases. I
like the current approach better as that other approach adds more
boilerplate and yet another type to learn.
gdb/ChangeLog:
yyyy-mm-dd Pedro Alves <palves@redhat.com>
* c-exp.y (name_obstack): Now an auto_obstack.
(yylex): Use auto_obstack::clear.
(c_parse): Use auto_obstack::clear instead of reinitializing and
freeing the obstack.
* c-lang.c (evaluate_subexp_c): Use auto_obstack.
* d-exp.y (name_obstack): Now an auto_obstack.
(yylex): Use auto_obstack::clear.
(d_parse): Use auto_obstack::clear instead of reinitializing and
freeing the obstack.
* dwarf2loc.c (fetch_const_value_from_synthetic_pointer): Use
auto_obstack.
* dwarf2read.c (create_addrmap_from_index)
(dwarf2_build_psymtabs_hard)
(update_enumeration_type_from_children, write_psymtabs_to_index):
Likewise.
* gdb_obstack.h (auto_obstack): New type.
* go-exp.y (name_obstack): Now an auto_obstack.
(build_packaged_name): Use auto_obstack::clear.
(go_parse): Use auto_obstack::clear instead of reinitializing and
freeing the obstack.
* linux-tdep.c (linux_make_mappings_corefile_notes): Use
auto_obstack.
* printcmd.c (printf_wide_c_string, ui_printf): Use auto_obstack.
* rust-exp.y (work_obstack): Now an auto_obstack.
(rust_parse, rust_lex_tests): Use auto_obstack::clear instead of
reinitializing and freeing the obstack.
* utils.c (do_obstack_free, make_cleanup_obstack_free): Delete.
(host_char_to_target): Use auto_obstack.
* utils.h (make_cleanup_obstack_free): Delete declaration.
* valprint.c (generic_emit_char, generic_printstr): Use
auto_obstack.
---
gdb/c-exp.y | 10 ++++++----
gdb/c-lang.c | 7 +------
gdb/d-exp.y | 11 ++++++-----
gdb/dwarf2loc.c | 7 +------
gdb/dwarf2read.c | 37 +++++++------------------------------
gdb/gdb_obstack.h | 15 +++++++++++++++
gdb/go-exp.y | 9 +++++----
gdb/linux-tdep.c | 7 +------
gdb/printcmd.c | 12 ++----------
gdb/rust-exp.y | 15 +++++++++------
gdb/utils.c | 24 +-----------------------
gdb/utils.h | 3 ---
gdb/valprint.c | 17 ++++-------------
13 files changed, 58 insertions(+), 116 deletions(-)
diff --git a/gdb/c-exp.y b/gdb/c-exp.y
index 283b737..bdcd51f 100644
--- a/gdb/c-exp.y
+++ b/gdb/c-exp.y
@@ -2806,7 +2806,7 @@ static int popping;
/* Temporary storage for c_lex; this holds symbol names as they are
built up. */
-static struct obstack name_obstack;
+auto_obstack name_obstack;
/* Classify a NAME token. The contents of the token are in `yylval'.
Updates yylval and returns the new token type. BLOCK is the block
@@ -3067,7 +3067,7 @@ yylex (void)
current = *VEC_index (token_and_value, token_fifo, next_to_examine);
++next_to_examine;
- obstack_free (&name_obstack, obstack_base (&name_obstack));
+ name_obstack.clear ();
checkpoint = 0;
if (current.token == FILENAME)
search_block = current.value.bval;
@@ -3169,6 +3169,9 @@ c_parse (struct parser_state *par_state)
gdb_assert (par_state != NULL);
pstate = par_state;
+ /* Note that parsing (within yyparse) freely installs cleanups
+ assuming they'll be run here (below). */
+
back_to = make_cleanup (free_current_contents, &expression_macro_scope);
make_cleanup_clear_parser_state (&pstate);
@@ -3197,8 +3200,7 @@ c_parse (struct parser_state *par_state)
VEC_free (token_and_value, token_fifo);
popping = 0;
- obstack_init (&name_obstack);
- make_cleanup_obstack_free (&name_obstack);
+ name_obstack.clear ();
result = yyparse ();
do_cleanups (back_to);
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index a6d533d..de8868b 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -570,15 +570,12 @@ evaluate_subexp_c (struct type *expect_type, struct expression *exp,
{
int oplen, limit;
struct type *type;
- struct obstack output;
- struct cleanup *cleanup;
struct value *result;
c_string_type dest_type;
const char *dest_charset;
int satisfy_expected = 0;
- obstack_init (&output);
- cleanup = make_cleanup_obstack_free (&output);
+ auto_obstack output;
++*pos;
oplen = longest_to_int (exp->elts[*pos].longconst);
@@ -656,7 +653,6 @@ evaluate_subexp_c (struct type *expect_type, struct expression *exp,
result = allocate_value (type);
else
result = value_cstring ("", 0, type);
- do_cleanups (cleanup);
return result;
}
@@ -702,7 +698,6 @@ evaluate_subexp_c (struct type *expect_type, struct expression *exp,
obstack_object_size (&output),
type);
}
- do_cleanups (cleanup);
return result;
}
break;
diff --git a/gdb/d-exp.y b/gdb/d-exp.y
index 62df737..d392a5c 100644
--- a/gdb/d-exp.y
+++ b/gdb/d-exp.y
@@ -1342,7 +1342,7 @@ static int popping;
/* Temporary storage for yylex; this holds symbol names as they are
built up. */
-static struct obstack name_obstack;
+static auto_obstack name_obstack;
/* Classify an IDENTIFIER token. The contents of the token are in `yylval'.
Updates yylval and returns the new token type. BLOCK is the block
@@ -1480,7 +1480,7 @@ yylex (void)
first try building up a name until we find the qualified module. */
if (current.token == UNKNOWN_NAME)
{
- obstack_free (&name_obstack, obstack_base (&name_obstack));
+ name_obstack.clear ();
obstack_grow (&name_obstack, current.value.sval.ptr,
current.value.sval.length);
@@ -1533,7 +1533,7 @@ yylex (void)
if (current.token != TYPENAME && current.token != '.')
goto do_pop;
- obstack_free (&name_obstack, obstack_base (&name_obstack));
+ name_obstack.clear ();
checkpoint = 0;
if (current.token == '.')
search_block = NULL;
@@ -1627,6 +1627,8 @@ d_parse (struct parser_state *par_state)
gdb_assert (par_state != NULL);
pstate = par_state;
+ /* Note that parsing (within yyparse) freely installs cleanups
+ assuming they're run here (below). */
back_to = make_cleanup (null_cleanup, NULL);
scoped_restore restore_yydebug = make_scoped_restore (&yydebug,
@@ -1639,8 +1641,7 @@ d_parse (struct parser_state *par_state)
VEC_free (token_and_value, token_fifo);
popping = 0;
- obstack_init (&name_obstack);
- make_cleanup_obstack_free (&name_obstack);
+ name_obstack.clear ();
result = yyparse ();
do_cleanups (back_to);
diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c
index 127167d..3f652a2 100644
--- a/gdb/dwarf2loc.c
+++ b/gdb/dwarf2loc.c
@@ -2125,13 +2125,10 @@ fetch_const_value_from_synthetic_pointer (sect_offset die, LONGEST byte_offset,
struct type *type)
{
struct value *result = NULL;
- struct obstack temp_obstack;
- struct cleanup *cleanup;
const gdb_byte *bytes;
LONGEST len;
- obstack_init (&temp_obstack);
- cleanup = make_cleanup_obstack_free (&temp_obstack);
+ auto_obstack temp_obstack;
bytes = dwarf2_fetch_constant_bytes (die, per_cu, &temp_obstack, &len);
if (bytes != NULL)
@@ -2148,8 +2145,6 @@ fetch_const_value_from_synthetic_pointer (sect_offset die, LONGEST byte_offset,
else
result = allocate_optimized_out_value (TYPE_TARGET_TYPE (type));
- do_cleanups (cleanup);
-
return result;
}
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index b58d0fc..cb33fc9 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -3057,13 +3057,11 @@ create_addrmap_from_index (struct objfile *objfile, struct mapped_index *index)
{
struct gdbarch *gdbarch = get_objfile_arch (objfile);
const gdb_byte *iter, *end;
- struct obstack temp_obstack;
struct addrmap *mutable_map;
- struct cleanup *cleanup;
CORE_ADDR baseaddr;
- obstack_init (&temp_obstack);
- cleanup = make_cleanup_obstack_free (&temp_obstack);
+ auto_obstack temp_obstack;
+
mutable_map = addrmap_create_mutable (&temp_obstack);
iter = index->address_table;
@@ -3104,7 +3102,6 @@ create_addrmap_from_index (struct objfile *objfile, struct mapped_index *index)
objfile->psymtabs_addrmap = addrmap_create_fixed (mutable_map,
&objfile->objfile_obstack);
- do_cleanups (cleanup);
}
/* The hash function for strings in the mapped index. This is the same as
@@ -6623,7 +6620,6 @@ static void
dwarf2_build_psymtabs_hard (struct objfile *objfile)
{
struct cleanup *back_to, *addrmap_cleanup;
- struct obstack temp_obstack;
int i;
if (dwarf_read_debug)
@@ -6646,8 +6642,7 @@ dwarf2_build_psymtabs_hard (struct objfile *objfile)
/* Create a temporary address map on a temporary obstack. We later
copy this to the final obstack. */
- obstack_init (&temp_obstack);
- make_cleanup_obstack_free (&temp_obstack);
+ auto_obstack temp_obstack;
objfile->psymtabs_addrmap = addrmap_create_mutable (&temp_obstack);
addrmap_cleanup = make_cleanup (psymtabs_addrmap_cleanup, objfile);
@@ -13793,15 +13788,12 @@ update_enumeration_type_from_children (struct die_info *die,
struct type *type,
struct dwarf2_cu *cu)
{
- struct obstack obstack;
struct die_info *child_die;
int unsigned_enum = 1;
int flag_enum = 1;
ULONGEST mask = 0;
- struct cleanup *old_chain;
- obstack_init (&obstack);
- old_chain = make_cleanup_obstack_free (&obstack);
+ auto_obstack obstack;
for (child_die = die->child;
child_die != NULL && child_die->tag;
@@ -13846,8 +13838,6 @@ update_enumeration_type_from_children (struct die_info *die,
TYPE_UNSIGNED (type) = 1;
if (flag_enum)
TYPE_FLAG_ENUM (type) = 1;
-
- do_cleanups (old_chain);
}
/* Given a DW_AT_enumeration_type die, set its type. We do not
@@ -23870,8 +23860,6 @@ write_psymtabs_to_index (struct objfile *objfile, const char *dir)
{
struct cleanup *cleanup;
char *filename;
- struct obstack contents, addr_obstack, constant_pool, symtab_obstack;
- struct obstack cu_list, types_cu_list;
int i;
FILE *out_file;
struct mapped_symtab *symtab;
@@ -23904,14 +23892,7 @@ write_psymtabs_to_index (struct objfile *objfile, const char *dir)
symtab = create_mapped_symtab ();
make_cleanup (cleanup_mapped_symtab, symtab);
- obstack_init (&addr_obstack);
- make_cleanup_obstack_free (&addr_obstack);
-
- obstack_init (&cu_list);
- make_cleanup_obstack_free (&cu_list);
-
- obstack_init (&types_cu_list);
- make_cleanup_obstack_free (&types_cu_list);
+ auto_obstack addr_obstack, cu_list, types_cu_list;
htab_up psyms_seen (htab_create_alloc (100, htab_hash_pointer,
htab_eq_pointer,
@@ -23987,14 +23968,10 @@ write_psymtabs_to_index (struct objfile *objfile, const char *dir)
lists. */
uniquify_cu_indices (symtab);
- obstack_init (&constant_pool);
- make_cleanup_obstack_free (&constant_pool);
- obstack_init (&symtab_obstack);
- make_cleanup_obstack_free (&symtab_obstack);
+ auto_obstack constant_pool, symtab_obstack;
write_hash_table (symtab, &symtab_obstack, &constant_pool);
- obstack_init (&contents);
- make_cleanup_obstack_free (&contents);
+ auto_obstack contents;
size_of_contents = 6 * sizeof (offset_type);
total_len = size_of_contents;
diff --git a/gdb/gdb_obstack.h b/gdb/gdb_obstack.h
index 3f34d96..b241c82 100644
--- a/gdb/gdb_obstack.h
+++ b/gdb/gdb_obstack.h
@@ -63,4 +63,19 @@ extern char *obconcat (struct obstack *obstackp, ...) ATTRIBUTE_SENTINEL;
extern char *obstack_strdup (struct obstack *obstackp, const char *string);
+/* An obstack that frees itself on scope exit. */
+struct auto_obstack : obstack
+{
+ auto_obstack ()
+ { obstack_init (this); }
+
+ ~auto_obstack ()
+ { obstack_free (this, NULL); }
+
+ /* Free all memory in the obstack but leave it valid for further
+ allocation. */
+ void clear ()
+ { obstack_free (this, obstack_base (this)); }
+};
+
#endif
diff --git a/gdb/go-exp.y b/gdb/go-exp.y
index 057e227..f2f3596 100644
--- a/gdb/go-exp.y
+++ b/gdb/go-exp.y
@@ -1297,7 +1297,7 @@ static int popping;
/* Temporary storage for yylex; this holds symbol names as they are
built up. */
-static struct obstack name_obstack;
+static auto_obstack name_obstack;
/* Build "package.name" in name_obstack.
For convenience of the caller, the name is NUL-terminated,
@@ -1309,7 +1309,7 @@ build_packaged_name (const char *package, int package_len,
{
struct stoken result;
- obstack_free (&name_obstack, obstack_base (&name_obstack));
+ name_obstack.clear ();
obstack_grow (&name_obstack, package, package_len);
obstack_grow_str (&name_obstack, ".");
obstack_grow (&name_obstack, name, name_len);
@@ -1567,6 +1567,8 @@ go_parse (struct parser_state *par_state)
gdb_assert (par_state != NULL);
pstate = par_state;
+ /* Note that parsing (within yyparse) freely installs cleanups
+ assuming they'll be run here (below). */
back_to = make_cleanup (null_cleanup, NULL);
scoped_restore restore_yydebug = make_scoped_restore (&yydebug,
@@ -1579,8 +1581,7 @@ go_parse (struct parser_state *par_state)
VEC_free (token_and_value, token_fifo);
popping = 0;
- obstack_init (&name_obstack);
- make_cleanup_obstack_free (&name_obstack);
+ name_obstack.clear ();
result = yyparse ();
do_cleanups (back_to);
diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c
index 016aadf..db6db35 100644
--- a/gdb/linux-tdep.c
+++ b/gdb/linux-tdep.c
@@ -1503,16 +1503,12 @@ linux_make_mappings_corefile_notes (struct gdbarch *gdbarch, bfd *obfd,
char *note_data, int *note_size)
{
struct cleanup *cleanup;
- struct obstack data_obstack, filename_obstack;
struct linux_make_mappings_data mapping_data;
struct type *long_type
= arch_integer_type (gdbarch, gdbarch_long_bit (gdbarch), 0, "long");
gdb_byte buf[sizeof (ULONGEST)];
- obstack_init (&data_obstack);
- cleanup = make_cleanup_obstack_free (&data_obstack);
- obstack_init (&filename_obstack);
- make_cleanup_obstack_free (&filename_obstack);
+ auto_obstack data_obstack, filename_obstack;
mapping_data.file_count = 0;
mapping_data.data_obstack = &data_obstack;
@@ -1545,7 +1541,6 @@ linux_make_mappings_corefile_notes (struct gdbarch *gdbarch, bfd *obfd,
obstack_object_size (&data_obstack));
}
- do_cleanups (cleanup);
return note_data;
}
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index 02d6e1c..fd6e03c 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -2305,8 +2305,6 @@ printf_wide_c_string (struct ui_file *stream, const char *format,
"wchar_t", NULL, 0);
int wcwidth = TYPE_LENGTH (wctype);
gdb_byte *buf = (gdb_byte *) alloca (wcwidth);
- struct obstack output;
- struct cleanup *inner_cleanup;
tem = value_as_address (value);
@@ -2325,8 +2323,7 @@ printf_wide_c_string (struct ui_file *stream, const char *format,
read_memory (tem, str, j);
memset (&str[j], 0, wcwidth);
- obstack_init (&output);
- inner_cleanup = make_cleanup_obstack_free (&output);
+ auto_obstack output;
convert_between_encodings (target_wide_charset (gdbarch),
host_charset (),
@@ -2335,7 +2332,6 @@ printf_wide_c_string (struct ui_file *stream, const char *format,
obstack_grow_str0 (&output, "");
fprintf_filtered (stream, format, obstack_base (&output));
- do_cleanups (inner_cleanup);
}
/* Subroutine of ui_printf to simplify it.
@@ -2581,8 +2577,6 @@ ui_printf (const char *arg, struct ui_file *stream)
struct type *wctype = lookup_typename (current_language, gdbarch,
"wchar_t", NULL, 0);
struct type *valtype;
- struct obstack output;
- struct cleanup *inner_cleanup;
const gdb_byte *bytes;
valtype = value_type (val_args[i]);
@@ -2592,8 +2586,7 @@ ui_printf (const char *arg, struct ui_file *stream)
bytes = value_contents (val_args[i]);
- obstack_init (&output);
- inner_cleanup = make_cleanup_obstack_free (&output);
+ auto_obstack output;
convert_between_encodings (target_wide_charset (gdbarch),
host_charset (),
@@ -2604,7 +2597,6 @@ ui_printf (const char *arg, struct ui_file *stream)
fprintf_filtered (stream, current_substring,
obstack_base (&output));
- do_cleanups (inner_cleanup);
}
break;
case double_arg:
diff --git a/gdb/rust-exp.y b/gdb/rust-exp.y
index 64b7c55..c7361bc 100644
--- a/gdb/rust-exp.y
+++ b/gdb/rust-exp.y
@@ -185,7 +185,7 @@ static int unit_testing;
/* Obstack for data temporarily allocated during parsing. */
-static struct obstack work_obstack;
+static auto_obstack work_obstack;
/* Result of parsing. Points into work_obstack. */
@@ -2446,13 +2446,17 @@ int
rust_parse (struct parser_state *state)
{
int result;
- struct cleanup *cleanup;
- obstack_init (&work_obstack);
- cleanup = make_cleanup_obstack_free (&work_obstack);
+ work_obstack.clear ();
+
rust_ast = NULL;
pstate = state;
+
+ /* Note that parsing (within rustyyparse) freely installs cleanups
+ assuming they're run here (below). */
+ struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
+
result = rustyyparse ();
if (!result || (parse_completion && rust_ast != NULL))
@@ -2631,7 +2635,7 @@ rust_lex_tests (void)
{
int i;
- obstack_init (&work_obstack);
+ work_obstack.clear ();
unit_testing = 1;
rust_lex_test_one ("", 0);
@@ -2722,7 +2726,6 @@ rust_lex_tests (void)
rust_lex_test_completion ();
rust_lex_test_push_back ();
- obstack_free (&work_obstack, NULL);
unit_testing = 0;
}
diff --git a/gdb/utils.c b/gdb/utils.c
index b4332f8..00b1bbb 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -169,24 +169,6 @@ make_cleanup_fclose (FILE *file)
return make_cleanup (do_fclose_cleanup, file);
}
-/* Helper function which does the work for make_cleanup_obstack_free. */
-
-static void
-do_obstack_free (void *arg)
-{
- struct obstack *ob = (struct obstack *) arg;
-
- obstack_free (ob, NULL);
-}
-
-/* Return a new cleanup that frees OBSTACK. */
-
-struct cleanup *
-make_cleanup_obstack_free (struct obstack *obstack)
-{
- return make_cleanup (do_obstack_free, obstack);
-}
-
/* Helper function for make_cleanup_ui_out_redirect_pop. */
static void
@@ -1332,13 +1314,10 @@ query (const char *ctlstr, ...)
static int
host_char_to_target (struct gdbarch *gdbarch, int c, int *target_c)
{
- struct obstack host_data;
char the_char = c;
- struct cleanup *cleanups;
int result = 0;
- obstack_init (&host_data);
- cleanups = make_cleanup_obstack_free (&host_data);
+ auto_obstack host_data;
convert_between_encodings (target_charset (gdbarch), host_charset (),
(gdb_byte *) &the_char, 1, 1,
@@ -1350,7 +1329,6 @@ host_char_to_target (struct gdbarch *gdbarch, int c, int *target_c)
*target_c = *(char *) obstack_base (&host_data);
}
- do_cleanups (cleanups);
return result;
}
diff --git a/gdb/utils.h b/gdb/utils.h
index f3e8007..3347c23 100644
--- a/gdb/utils.h
+++ b/gdb/utils.h
@@ -78,9 +78,6 @@ extern struct cleanup *(make_cleanup_free_section_addr_info
extern struct cleanup *make_cleanup_fclose (FILE *file);
-struct obstack;
-extern struct cleanup *make_cleanup_obstack_free (struct obstack *obstack);
-
extern struct cleanup *make_cleanup_restore_integer (int *variable);
extern struct cleanup *make_cleanup_restore_uinteger (unsigned int *variable);
diff --git a/gdb/valprint.c b/gdb/valprint.c
index 6937dab..44810b9 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -2432,8 +2432,6 @@ generic_emit_char (int c, struct type *type, struct ui_file *stream,
{
enum bfd_endian byte_order
= gdbarch_byte_order (get_type_arch (type));
- struct obstack wchar_buf, output;
- struct cleanup *cleanups;
gdb_byte *buf;
int need_escape = 0;
@@ -2443,8 +2441,7 @@ generic_emit_char (int c, struct type *type, struct ui_file *stream,
wchar_iterator iter (buf, TYPE_LENGTH (type), encoding, TYPE_LENGTH (type));
/* This holds the printable form of the wchar_t data. */
- obstack_init (&wchar_buf);
- cleanups = make_cleanup_obstack_free (&wchar_buf);
+ auto_obstack wchar_buf;
while (1)
{
@@ -2491,8 +2488,7 @@ generic_emit_char (int c, struct type *type, struct ui_file *stream,
}
/* The output in the host encoding. */
- obstack_init (&output);
- make_cleanup_obstack_free (&output);
+ auto_obstack output;
convert_between_encodings (INTERMEDIATE_ENCODING, host_charset (),
(gdb_byte *) obstack_base (&wchar_buf),
@@ -2501,8 +2497,6 @@ generic_emit_char (int c, struct type *type, struct ui_file *stream,
obstack_1grow (&output, '\0');
fputs_filtered ((const char *) obstack_base (&output), stream);
-
- do_cleanups (cleanups);
}
/* Return the repeat count of the next character/byte in ITER,
@@ -2761,7 +2755,6 @@ generic_printstr (struct ui_file *stream, struct type *type,
enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
unsigned int i;
int width = TYPE_LENGTH (type);
- struct obstack wchar_buf, output;
struct cleanup *cleanup;
int finished = 0;
struct converted_character *last;
@@ -2833,8 +2826,7 @@ generic_printstr (struct ui_file *stream, struct type *type,
/* WCHAR_BUF is the obstack we use to represent the string in
wchar_t form. */
- obstack_init (&wchar_buf);
- make_cleanup_obstack_free (&wchar_buf);
+ auto_obstack wchar_buf;
/* Print the output string to the obstack. */
print_converted_chars_to_obstack (&wchar_buf, converted_chars, quote_char,
@@ -2844,8 +2836,7 @@ generic_printstr (struct ui_file *stream, struct type *type,
obstack_grow_wstr (&wchar_buf, LCST ("..."));
/* OUTPUT is where we collect `char's for printing. */
- obstack_init (&output);
- make_cleanup_obstack_free (&output);
+ auto_obstack output;
convert_between_encodings (INTERMEDIATE_ENCODING, host_charset (),
(gdb_byte *) obstack_base (&wchar_buf),
--
2.5.5