summaryrefslogtreecommitdiff
path: root/gdb/valprint.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2016-09-22 21:16:53 -0600
committerTom Tromey <tom@tromey.com>2016-10-12 19:43:16 -0600
commitcda6c55bd399a8892d62178d4daeb074def909e0 (patch)
treed83fa6dba674729cc8cf978824995f03bbf8ca5e /gdb/valprint.c
parent816d7b53047bca81c226990bc9248d59d80d4b8b (diff)
downloadbinutils-gdb-cda6c55bd399a8892d62178d4daeb074def909e0.tar.gz
Turn wchar iterator into a class
This changes wchar_iterator from charset.c into a real C++ class, then updates the users to use the class. This lets us remove some cleanups in favor of the class' destructor. 2016-10-12 Tom Tromey <tom@tromey.com> * valprint.c (generic_emit_char, count_next_character) (generic_printstr): Update. * charset.c (struct wchar_iterator): Move to charset.h. (wchar_iterator::wchar_iterator): Rename from make_wchar_iterator, turn into a constructor. (wchar_iterator::~wchar_iterator): Rename from do_cleanup_iterator, turn into a destructor. (make_cleanup_wchar_iterator): Remove. (wchar_iterator::iterate): Rename from wchar_iterate. Remove "iter" argument. Update. * charset.h: Include <vector>. (class wchar_iterator): New class, from old struct wchar_iterator. (make_wchar_iterator, make_cleanup_wchar_iterator): Don't declare.
Diffstat (limited to 'gdb/valprint.c')
-rw-r--r--gdb/valprint.c25
1 files changed, 10 insertions, 15 deletions
diff --git a/gdb/valprint.c b/gdb/valprint.c
index 93607e5a1b6..ca30a7f945c 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -2404,19 +2404,16 @@ generic_emit_char (int c, struct type *type, struct ui_file *stream,
struct obstack wchar_buf, output;
struct cleanup *cleanups;
gdb_byte *buf;
- struct wchar_iterator *iter;
int need_escape = 0;
buf = (gdb_byte *) alloca (TYPE_LENGTH (type));
pack_long (buf, type, c);
- iter = make_wchar_iterator (buf, TYPE_LENGTH (type),
- encoding, TYPE_LENGTH (type));
- cleanups = make_cleanup_wchar_iterator (iter);
+ 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);
- make_cleanup_obstack_free (&wchar_buf);
+ cleanups = make_cleanup_obstack_free (&wchar_buf);
while (1)
{
@@ -2427,7 +2424,7 @@ generic_emit_char (int c, struct type *type, struct ui_file *stream,
int print_escape = 1;
enum wchar_iterate_result result;
- num_chars = wchar_iterate (iter, &result, &chars, &buf, &buflen);
+ num_chars = iter.iterate (&result, &chars, &buf, &buflen);
if (num_chars < 0)
break;
if (num_chars > 0)
@@ -2481,7 +2478,7 @@ generic_emit_char (int c, struct type *type, struct ui_file *stream,
storing the result in VEC. */
static int
-count_next_character (struct wchar_iterator *iter,
+count_next_character (wchar_iterator *iter,
VEC (converted_character_d) **vec)
{
struct converted_character *current;
@@ -2492,7 +2489,7 @@ count_next_character (struct wchar_iterator *iter,
gdb_wchar_t *chars;
tmp.num_chars
- = wchar_iterate (iter, &tmp.result, &chars, &tmp.buf, &tmp.buflen);
+ = iter->iterate (&tmp.result, &chars, &tmp.buf, &tmp.buflen);
if (tmp.num_chars > 0)
{
gdb_assert (tmp.num_chars < MAX_WCHARS);
@@ -2521,8 +2518,7 @@ count_next_character (struct wchar_iterator *iter,
while (1)
{
/* Get the next character. */
- d.num_chars
- = wchar_iterate (iter, &d.result, &chars, &d.buf, &d.buflen);
+ d.num_chars = iter->iterate (&d.result, &chars, &d.buf, &d.buflen);
/* If a character was successfully converted, save the character
into the converted character. */
@@ -2736,7 +2732,6 @@ generic_printstr (struct ui_file *stream, struct type *type,
int width = TYPE_LENGTH (type);
struct obstack wchar_buf, output;
struct cleanup *cleanup;
- struct wchar_iterator *iter;
int finished = 0;
struct converted_character *last;
VEC (converted_character_d) *converted_chars;
@@ -2771,10 +2766,10 @@ generic_printstr (struct ui_file *stream, struct type *type,
}
/* Arrange to iterate over the characters, in wchar_t form. */
- iter = make_wchar_iterator (string, length * width, encoding, width);
- cleanup = make_cleanup_wchar_iterator (iter);
+ wchar_iterator iter (string, length * width, encoding, width);
converted_chars = NULL;
- make_cleanup (VEC_cleanup (converted_character_d), &converted_chars);
+ cleanup = make_cleanup (VEC_cleanup (converted_character_d),
+ &converted_chars);
/* Convert characters until the string is over or the maximum
number of printed characters has been reached. */
@@ -2786,7 +2781,7 @@ generic_printstr (struct ui_file *stream, struct type *type,
QUIT;
/* Grab the next character and repeat count. */
- r = count_next_character (iter, &converted_chars);
+ r = count_next_character (&iter, &converted_chars);
/* If less than zero, the end of the input string was reached. */
if (r < 0)