GNU Binutils with patches for OS216
Révision | 8de00631b8bd1c328f1916b1fd95bd0d9ff2017e (tree) |
---|---|
l'heure | 2016-11-09 00:26:43 |
Auteur | Pedro Alves <palves@redh...> |
Commiter | Pedro Alves |
Introduce ui_file_as_string
ui_file_as_string is a variant of ui_file_xstrdup that returns a
std::string instead of a xmalloc'ed char *. The idea is using the new
function to eliminate "make_cleanup (xfree, ...)" cleanups
throughout.
Following patches will make use of this.
gdb/ChangeLog:
2016-11-08 Pedro Alves <palves@redhat.com>
* ui-file.c (do_ui_file_as_string, ui_file_as_string): New
functions.
* ui-file.h: Include <string>.
(ui_file_as_string): New declaration.
@@ -1,5 +1,12 @@ | ||
1 | 1 | 2016-11-08 Pedro Alves <palves@redhat.com> |
2 | 2 | |
3 | + * ui-file.c (do_ui_file_as_string, ui_file_as_string): New | |
4 | + functions. | |
5 | + * ui-file.h: Include <string>. | |
6 | + (ui_file_as_string): New declaration. | |
7 | + | |
8 | +2016-11-08 Pedro Alves <palves@redhat.com> | |
9 | + | |
3 | 10 | * ada-lang.c (ada_read_renaming_var_value): Use expression_up. |
4 | 11 | (struct ada_catchpoint_location) <excep_cond_expr>: Now an |
5 | 12 | expression_up. |
@@ -356,6 +356,28 @@ ui_file_xstrdup (struct ui_file *file, long *length) | ||
356 | 356 | return acc.buffer; |
357 | 357 | } |
358 | 358 | |
359 | +/* ui_file utility function for converting a ``struct ui_file'' into a | |
360 | + std:string. */ | |
361 | + | |
362 | +static void | |
363 | +do_ui_file_as_string (void *context, const char *buffer, long length) | |
364 | +{ | |
365 | + std::string *str = (std::string *) context; | |
366 | + | |
367 | + *str = std::string (buffer, length); | |
368 | +} | |
369 | + | |
370 | +/* See ui-file.h. */ | |
371 | + | |
372 | +std::string | |
373 | +ui_file_as_string (struct ui_file *file) | |
374 | +{ | |
375 | + std::string str; | |
376 | + | |
377 | + ui_file_put (file, do_ui_file_as_string, &str); | |
378 | + return str; | |
379 | +} | |
380 | + | |
359 | 381 | static void |
360 | 382 | do_ui_file_obsavestring (void *context, const char *buffer, long length) |
361 | 383 | { |
@@ -22,6 +22,8 @@ | ||
22 | 22 | struct obstack; |
23 | 23 | struct ui_file; |
24 | 24 | |
25 | +#include <string> | |
26 | + | |
25 | 27 | /* Create a generic ui_file object with null methods. */ |
26 | 28 | |
27 | 29 | extern struct ui_file *ui_file_new (void); |
@@ -117,6 +119,10 @@ extern void ui_file_put (struct ui_file *src, | ||
117 | 119 | minus that appended NUL. */ |
118 | 120 | extern char *ui_file_xstrdup (struct ui_file *file, long *length); |
119 | 121 | |
122 | +/* Returns a std::string containing the entire contents of FILE (as | |
123 | + determined by ui_file_put()). */ | |
124 | +extern std::string ui_file_as_string (struct ui_file *file); | |
125 | + | |
120 | 126 | /* Similar to ui_file_xstrdup, but return a new string allocated on |
121 | 127 | OBSTACK. */ |
122 | 128 | extern char *ui_file_obsavestring (struct ui_file *file, |