This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: [RFA] ui-file.[ch]: tell(), mem_filebuf()


Nick Duffek wrote:
> 
> The attached patch:
> 
>   1. Adds a tell method to the ui_file interface.

Um, it might be useful if you expanded a little on what you're trying to
do and why it isn't currently possible.

>   3. Defines a new function, char *mem_filebuf (struct ui_file *file), to
>      return the buffer currently used for storing FILE's contents.

What about ui_file_xstrdup()?

> I made these changes to support some register cache patches I'll be
> posting shortly.

Hmm, er, looking at the code.  Is it a good idea to expose the internal
workings of a specific ui_file implementation?  In particular provide
direct access to an internal dynamic buffer.

	Andrew


> 
> Index: gdb/ui-file.c
> ===================================================================
> diff -up gdb/ui-file.c gdb/ui-file.c
> --- gdb/ui-file.c       Thu Dec 14 08:16:50 2000
> +++ gdb/ui-file.c       Thu Dec 14 08:05:05 2000
> @@ -33,6 +33,7 @@ static ui_file_fputs_ftype null_file_fpu
>  static ui_file_flush_ftype null_file_flush;
>  static ui_file_delete_ftype null_file_delete;
>  static ui_file_rewind_ftype null_file_rewind;
> +static ui_file_tell_ftype null_file_tell;
>  static ui_file_put_ftype null_file_put;
> 
>  struct ui_file
> @@ -44,6 +45,7 @@ struct ui_file
>      ui_file_delete_ftype *to_delete;
>      ui_file_isatty_ftype *to_isatty;
>      ui_file_rewind_ftype *to_rewind;
> +    ui_file_tell_ftype *to_tell;
>      ui_file_put_ftype *to_put;
>      void *to_data;
>    };
> @@ -60,6 +62,7 @@ ui_file_new (void)
>    set_ui_file_fputs (file, null_file_fputs);
>    set_ui_file_isatty (file, null_file_isatty);
>    set_ui_file_rewind (file, null_file_rewind);
> +  set_ui_file_tell (file, null_file_tell);
>    set_ui_file_put (file, null_file_put);
>    return file;
>  }
> @@ -83,6 +86,13 @@ null_file_rewind (struct ui_file *file)
>    return;
>  }
> 
> +static long
> +null_file_tell (file)
> +     struct ui_file *file;
> +{
> +  return 0;
> +}
> +
>  static void
>  null_file_put (struct ui_file *file,
>                ui_file_put_method_ftype *write,
> @@ -171,6 +181,13 @@ ui_file_rewind (struct ui_file *file)
>    file->to_rewind (file);
>  }
> 
> +long
> +ui_file_tell (file)
> +     struct ui_file *file;
> +{
> +  return file->to_tell (file);
> +}
> +
>  void
>  ui_file_put (struct ui_file *file,
>               ui_file_put_method_ftype *write,
> @@ -212,6 +229,12 @@ set_ui_file_rewind (struct ui_file *file
>  }
> 
>  void
> +set_ui_file_tell (struct ui_file *file, ui_file_tell_ftype *tell)
> +{
> +  file->to_tell = tell;
> +}
> +
> +void
>  set_ui_file_put (struct ui_file *file, ui_file_put_ftype *put)
>  {
>    file->to_put = put;
> @@ -287,6 +310,7 @@ struct mem_file
>    };
> 
>  static ui_file_rewind_ftype mem_file_rewind;
> +static ui_file_tell_ftype mem_file_tell;
>  static ui_file_put_ftype mem_file_put;
>  static ui_file_write_ftype mem_file_write;
>  static ui_file_delete_ftype mem_file_delete;
> @@ -300,6 +324,7 @@ mem_file_new (void)
>    struct ui_file *file = ui_file_new ();
>    set_ui_file_data (file, stream, mem_file_delete);
>    set_ui_file_rewind (file, mem_file_rewind);
> +  set_ui_file_tell (file, mem_file_tell);
>    set_ui_file_put (file, mem_file_put);
>    set_ui_file_write (file, mem_file_write);
>    stream->magic = &mem_file_magic;
> @@ -326,6 +351,15 @@ mem_fileopen (void)
>    return mem_file_new ();
>  }
> 
> +char *
> +mem_filebuf (struct ui_file *file)
> +{
> +  struct mem_file *stream = ui_file_data (file);
> +  if (stream->magic != &mem_file_magic)
> +    internal_error ("mem_file_rewind: bad magic number");
> +  return stream->buffer;
> +}
> +
>  static void
>  mem_file_rewind (struct ui_file *file)
>  {
> @@ -335,6 +369,15 @@ mem_file_rewind (struct ui_file *file)
>    stream->length_buffer = 0;
>  }
> 
> +static long
> +mem_file_tell (struct ui_file *file)
> +{
> +  struct mem_file *stream = ui_file_data (file);
> +  if (stream->magic != &mem_file_magic)
> +    internal_error ("mem_file_tell: bad magic number");
> +  return (long) stream->length_buffer;
> +}
> +
>  static void
>  mem_file_put (struct ui_file *file,
>               ui_file_put_method_ftype *write,
> @@ -347,7 +390,7 @@ mem_file_put (struct ui_file *file,
>      write (dest, stream->buffer, stream->length_buffer);
>  }
> 
> -void
> +static void
>  mem_file_write (struct ui_file *file,
>                 const char *buffer,
>                 long length_buffer)
> Index: gdb/ui-file.h
> ===================================================================
> diff -up gdb/ui-file.h gdb/ui-file.h
> --- gdb/ui-file.h       Thu Dec 14 08:16:56 2000
> +++ gdb/ui-file.h       Thu Dec 14 08:15:45 2000
> @@ -47,6 +47,9 @@ extern void set_ui_file_isatty (struct u
>  typedef void (ui_file_rewind_ftype) (struct ui_file * stream);
>  extern void set_ui_file_rewind (struct ui_file *stream, ui_file_rewind_ftype * rewind);
> 
> +typedef long (ui_file_tell_ftype) (struct ui_file * stream);
> +extern void set_ui_file_tell (struct ui_file *stream, ui_file_tell_ftype * tell);
> +
>  typedef void (ui_file_put_method_ftype) (void *object, const char *buffer, long length_buffer);
>  typedef void (ui_file_put_ftype) (struct ui_file *stream, ui_file_put_method_ftype * method, void *context);
>  extern void set_ui_file_put (struct ui_file *stream, ui_file_put_ftype * put);
> @@ -63,6 +66,8 @@ extern void ui_file_delete (struct ui_fi
> 
>  extern void ui_file_rewind (struct ui_file *stream);
> 
> +extern long ui_file_tell (struct ui_file *stream);
> +
>  extern int ui_file_isatty (struct ui_file *);
> 
>  extern void ui_file_write (struct ui_file *file, const char *buf, long length_buf);
> @@ -77,12 +82,13 @@ extern void ui_file_put (struct ui_file
>  extern char *ui_file_xstrdup (struct ui_file *file, long *length);
> 
> 
> -
>  /* Create/open a memory based file. Can be used as a scratch buffer
>     for collecting output. */
>  extern struct ui_file *mem_fileopen (void);
> 
> -
> +/* Return the buffer currently used for storing FILE's contents.  FILE must
> +   have been created by mem_fileopen().  */
> +extern char *mem_filebuf (struct ui_file *file);
> 
>  /* Open/create a an STDIO based UI_FILE using the already open FILE. */
>  extern struct ui_file *stdio_fileopen (FILE *file);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]