Add constructor and destructor to demangle_parse_info
[deliverable/binutils-gdb.git] / gdb / ui-file.c
index 3aa2a7cac8b6bf3114ba1824111dc948d3e6d7d3..3dce51119bdc4331c0bbd2214471d17fdea0f6a8 100644 (file)
@@ -1,6 +1,6 @@
 /* UI_FILE - a generic STDIO like output stream.
 
-   Copyright (C) 1999-2015 Free Software Foundation, Inc.
+   Copyright (C) 1999-2017 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -225,7 +225,7 @@ ui_file_write (struct ui_file *file,
 void
 ui_file_write_for_put (void *data, const char *buffer, long length_buffer)
 {
-  ui_file_write (data, buffer, length_buffer);
+  ui_file_write ((struct ui_file *) data, buffer, length_buffer);
 }
 
 void
@@ -330,12 +330,12 @@ struct accumulated_ui_file
 static void
 do_ui_file_xstrdup (void *context, const char *buffer, long length)
 {
-  struct accumulated_ui_file *acc = context;
+  struct accumulated_ui_file *acc = (struct accumulated_ui_file *) context;
 
   if (acc->buffer == NULL)
-    acc->buffer = xmalloc (length + 1);
+    acc->buffer = (char *) xmalloc (length + 1);
   else
-    acc->buffer = xrealloc (acc->buffer, acc->length + length + 1);
+    acc->buffer = (char *) xrealloc (acc->buffer, acc->length + length + 1);
   memcpy (acc->buffer + acc->length, buffer, length);
   acc->length += length;
   acc->buffer[acc->length] = '\0';
@@ -356,6 +356,28 @@ ui_file_xstrdup (struct ui_file *file, long *length)
   return acc.buffer;
 }
 
+/* ui_file utility function for converting a ``struct ui_file'' into a
+   std:string.  */
+
+static void
+do_ui_file_as_string (void *context, const char *buffer, long length)
+{
+  std::string *str = (std::string *) context;
+
+  *str = std::string (buffer, length);
+}
+
+/* See ui-file.h.  */
+
+std::string
+ui_file_as_string (struct ui_file *file)
+{
+  std::string str;
+
+  ui_file_put (file, do_ui_file_as_string, &str);
+  return str;
+}
+
 static void
 do_ui_file_obsavestring (void *context, const char *buffer, long length)
 {
@@ -371,7 +393,7 @@ ui_file_obsavestring (struct ui_file *file, struct obstack *obstack,
   ui_file_put (file, do_ui_file_obsavestring, obstack);
   *length = obstack_object_size (obstack);
   obstack_1grow (obstack, '\0');
-  return obstack_finish (obstack);
+  return (char *) obstack_finish (obstack);
 }
 \f
 /* A pure memory based ``struct ui_file'' that can be used an output
@@ -413,7 +435,7 @@ mem_file_new (void)
 static void
 mem_file_delete (struct ui_file *file)
 {
-  struct mem_file *stream = ui_file_data (file);
+  struct mem_file *stream = (struct mem_file *) ui_file_data (file);
 
   if (stream->magic != &mem_file_magic)
     internal_error (__FILE__, __LINE__,
@@ -432,7 +454,7 @@ mem_fileopen (void)
 static void
 mem_file_rewind (struct ui_file *file)
 {
-  struct mem_file *stream = ui_file_data (file);
+  struct mem_file *stream = (struct mem_file *) ui_file_data (file);
 
   if (stream->magic != &mem_file_magic)
     internal_error (__FILE__, __LINE__,
@@ -445,7 +467,7 @@ mem_file_put (struct ui_file *file,
              ui_file_put_method_ftype *write,
              void *dest)
 {
-  struct mem_file *stream = ui_file_data (file);
+  struct mem_file *stream = (struct mem_file *) ui_file_data (file);
 
   if (stream->magic != &mem_file_magic)
     internal_error (__FILE__, __LINE__,
@@ -459,7 +481,7 @@ mem_file_write (struct ui_file *file,
                const char *buffer,
                long length_buffer)
 {
-  struct mem_file *stream = ui_file_data (file);
+  struct mem_file *stream = (struct mem_file *) ui_file_data (file);
 
   if (stream->magic != &mem_file_magic)
     internal_error (__FILE__, __LINE__,
@@ -468,7 +490,7 @@ mem_file_write (struct ui_file *file,
     {
       stream->length_buffer = length_buffer;
       stream->sizeof_buffer = length_buffer;
-      stream->buffer = xmalloc (stream->sizeof_buffer);
+      stream->buffer = (char *) xmalloc (stream->sizeof_buffer);
       memcpy (stream->buffer, buffer, length_buffer);
     }
   else
@@ -478,7 +500,8 @@ mem_file_write (struct ui_file *file,
       if (new_length >= stream->sizeof_buffer)
        {
          stream->sizeof_buffer = new_length;
-         stream->buffer = xrealloc (stream->buffer, stream->sizeof_buffer);
+         stream->buffer
+           = (char *) xrealloc (stream->buffer, stream->sizeof_buffer);
        }
       memcpy (stream->buffer + stream->length_buffer, buffer, length_buffer);
       stream->length_buffer = new_length;
@@ -534,7 +557,7 @@ stdio_file_new (FILE *file, int close_p)
 static void
 stdio_file_delete (struct ui_file *file)
 {
-  struct stdio_file *stdio = ui_file_data (file);
+  struct stdio_file *stdio = (struct stdio_file *) ui_file_data (file);
 
   if (stdio->magic != &stdio_file_magic)
     internal_error (__FILE__, __LINE__,
@@ -549,7 +572,7 @@ stdio_file_delete (struct ui_file *file)
 static void
 stdio_file_flush (struct ui_file *file)
 {
-  struct stdio_file *stdio = ui_file_data (file);
+  struct stdio_file *stdio = (struct stdio_file *) ui_file_data (file);
 
   if (stdio->magic != &stdio_file_magic)
     internal_error (__FILE__, __LINE__,
@@ -560,20 +583,20 @@ stdio_file_flush (struct ui_file *file)
 static long
 stdio_file_read (struct ui_file *file, char *buf, long length_buf)
 {
-  struct stdio_file *stdio = ui_file_data (file);
+  struct stdio_file *stdio = (struct stdio_file *) ui_file_data (file);
 
   if (stdio->magic != &stdio_file_magic)
     internal_error (__FILE__, __LINE__,
                    _("stdio_file_read: bad magic number"));
 
-  /* For the benefit of Windows, call gdb_select before reading from
-     the file.  Wait until at least one byte of data is available.
-     Control-C can interrupt gdb_select, but not read.  */
+  /* Wait until at least one byte of data is available, or we get
+     interrupted with Control-C.  */
   {
     fd_set readfds;
+
     FD_ZERO (&readfds);
     FD_SET (stdio->fd, &readfds);
-    if (gdb_select (stdio->fd + 1, &readfds, NULL, NULL, NULL) == -1)
+    if (interruptible_select (stdio->fd + 1, &readfds, NULL, NULL, NULL) == -1)
       return -1;
   }
 
@@ -583,7 +606,7 @@ stdio_file_read (struct ui_file *file, char *buf, long length_buf)
 static void
 stdio_file_write (struct ui_file *file, const char *buf, long length_buf)
 {
-  struct stdio_file *stdio = ui_file_data (file);
+  struct stdio_file *stdio = (struct stdio_file *) ui_file_data (file);
 
   if (stdio->magic != &stdio_file_magic)
     internal_error (__FILE__, __LINE__,
@@ -599,7 +622,7 @@ static void
 stdio_file_write_async_safe (struct ui_file *file,
                             const char *buf, long length_buf)
 {
-  struct stdio_file *stdio = ui_file_data (file);
+  struct stdio_file *stdio = (struct stdio_file *) ui_file_data (file);
 
   if (stdio->magic != &stdio_file_magic)
     {
@@ -622,7 +645,7 @@ stdio_file_write_async_safe (struct ui_file *file,
 static void
 stdio_file_fputs (const char *linebuffer, struct ui_file *file)
 {
-  struct stdio_file *stdio = ui_file_data (file);
+  struct stdio_file *stdio = (struct stdio_file *) ui_file_data (file);
 
   if (stdio->magic != &stdio_file_magic)
     internal_error (__FILE__, __LINE__,
@@ -637,7 +660,7 @@ stdio_file_fputs (const char *linebuffer, struct ui_file *file)
 static int
 stdio_file_isatty (struct ui_file *file)
 {
-  struct stdio_file *stdio = ui_file_data (file);
+  struct stdio_file *stdio = (struct stdio_file *) ui_file_data (file);
 
   if (stdio->magic != &stdio_file_magic)
     internal_error (__FILE__, __LINE__,
@@ -648,7 +671,7 @@ stdio_file_isatty (struct ui_file *file)
 static int
 stdio_file_fseek (struct ui_file *file, long offset, int whence)
 {
-  struct stdio_file *stdio = ui_file_data (file);
+  struct stdio_file *stdio = (struct stdio_file *) ui_file_data (file);
 
   if (stdio->magic != &stdio_file_magic)
     internal_error (__FILE__, __LINE__,
@@ -680,9 +703,9 @@ stderr_file_fputs (const char *linebuffer, struct ui_file *file)
 #endif
 
 struct ui_file *
-stderr_fileopen (void)
+stderr_fileopen (FILE *stream)
 {
-  struct ui_file *ui_file = stdio_fileopen (stderr);
+  struct ui_file *ui_file = stdio_fileopen (stream);
 
 #ifdef __MINGW32__
   /* There is no real line-buffering on Windows, see
@@ -769,7 +792,7 @@ tee_file_new (struct ui_file *one, int close_one,
 static void
 tee_file_delete (struct ui_file *file)
 {
-  struct tee_file *tee = ui_file_data (file);
+  struct tee_file *tee = (struct tee_file *) ui_file_data (file);
 
   if (tee->magic != &tee_file_magic)
     internal_error (__FILE__, __LINE__,
@@ -785,7 +808,7 @@ tee_file_delete (struct ui_file *file)
 static void
 tee_file_flush (struct ui_file *file)
 {
-  struct tee_file *tee = ui_file_data (file);
+  struct tee_file *tee = (struct tee_file *) ui_file_data (file);
 
   if (tee->magic != &tee_file_magic)
     internal_error (__FILE__, __LINE__,
@@ -797,7 +820,7 @@ tee_file_flush (struct ui_file *file)
 static void
 tee_file_write (struct ui_file *file, const char *buf, long length_buf)
 {
-  struct tee_file *tee = ui_file_data (file);
+  struct tee_file *tee = (struct tee_file *) ui_file_data (file);
 
   if (tee->magic != &tee_file_magic)
     internal_error (__FILE__, __LINE__,
@@ -809,7 +832,7 @@ tee_file_write (struct ui_file *file, const char *buf, long length_buf)
 static void
 tee_file_fputs (const char *linebuffer, struct ui_file *file)
 {
-  struct tee_file *tee = ui_file_data (file);
+  struct tee_file *tee = (struct tee_file *) ui_file_data (file);
 
   if (tee->magic != &tee_file_magic)
     internal_error (__FILE__, __LINE__,
@@ -821,7 +844,7 @@ tee_file_fputs (const char *linebuffer, struct ui_file *file)
 static int
 tee_file_isatty (struct ui_file *file)
 {
-  struct tee_file *tee = ui_file_data (file);
+  struct tee_file *tee = (struct tee_file *) ui_file_data (file);
 
   if (tee->magic != &tee_file_magic)
     internal_error (__FILE__, __LINE__,
This page took 0.1 seconds and 4 git commands to generate.