diff options
Diffstat (limited to 'gdb/common/format.c')
-rw-r--r-- | gdb/common/format.c | 62 |
1 files changed, 5 insertions, 57 deletions
diff --git a/gdb/common/format.c b/gdb/common/format.c index 8cb1551..95cb805 100644 --- a/gdb/common/format.c +++ b/gdb/common/format.c @@ -20,17 +20,13 @@ #include "common-defs.h" #include "format.h" -struct format_piece * -parse_format_string (const char **arg) +format_pieces::format_pieces (const char **arg) { const char *s; char *f, *string; const char *prev_start; const char *percent_loc; char *sub_start, *current_substring; - struct format_piece *pieces; - int next_frag; - int max_pieces; enum argclass this_argclass; s = *arg; @@ -100,12 +96,7 @@ parse_format_string (const char **arg) /* Need extra space for the '\0's. Doubling the size is sufficient. */ current_substring = (char *) xmalloc (strlen (string) * 2 + 1000); - - max_pieces = strlen (string) + 2; - - pieces = XNEWVEC (struct format_piece, max_pieces); - - next_frag = 0; + m_storage.reset (current_substring); /* Now scan the string for %-specs and see what kinds of args they want. argclass classifies the %-specs so we can give printf-type functions @@ -135,9 +126,7 @@ parse_format_string (const char **arg) current_substring += f - 1 - prev_start; *current_substring++ = '\0'; - pieces[next_frag].string = sub_start; - pieces[next_frag].argclass = literal_piece; - next_frag++; + m_pieces.emplace_back (sub_start, literal_piece); percent_loc = f - 1; @@ -343,9 +332,7 @@ parse_format_string (const char **arg) prev_start = f; - pieces[next_frag].string = sub_start; - pieces[next_frag].argclass = this_argclass; - next_frag++; + m_pieces.emplace_back (sub_start, this_argclass); } /* Record the remainder of the string. */ @@ -356,44 +343,5 @@ parse_format_string (const char **arg) current_substring += f - prev_start; *current_substring++ = '\0'; - pieces[next_frag].string = sub_start; - pieces[next_frag].argclass = literal_piece; - next_frag++; - - /* Record an end-of-array marker. */ - - pieces[next_frag].string = NULL; - pieces[next_frag].argclass = literal_piece; - - return pieces; + m_pieces.emplace_back (sub_start, literal_piece); } - -void -free_format_pieces (struct format_piece *pieces) -{ - if (!pieces) - return; - - /* We happen to know that all the string pieces are in the block - pointed to by the first string piece. */ - if (pieces[0].string) - xfree (pieces[0].string); - - xfree (pieces); -} - -void -free_format_pieces_cleanup (void *ptr) -{ - struct format_piece **location = (struct format_piece **) ptr; - - if (location == NULL) - return; - - if (*location != NULL) - { - free_format_pieces (*location); - *location = NULL; - } -} - |