This is the mail archive of the gdb-patches@sourceware.org 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]
Other format: [Raw text]

Regression: Re: [PATCH 2/6] Code cleanup: dwarf2read.c: Eliminate ::file_write


On Mon, 12 Jun 2017 18:14:07 +0200, Pedro Alves wrote:
> There's no real need for all this indirection.
...
> -/* Write SIZE bytes from the buffer pointed to by DATA to FILE, with
> -   error checking.  */
> -
> -static void
> -file_write (FILE *file, const void *data, size_t size)
> -{
> -  if (fwrite (data, 1, size, file) != size)
> -    error (_("couldn't data write to file"));
> -}
> -
> -/* Write the contents of VEC to FILE, with error checking.  */
> -
> -template<class Elem>
> -static void
> -file_write (FILE *file, const std::vector<Elem> &vec)
> -{
> -  file_write (file, vec.data (), vec.size() * sizeof (vec[0]));
> -}
> -
>  /* In-memory buffer to prepare data to be written later to a file.  */
>  class data_buf
>  {
> @@ -23252,7 +23233,8 @@ public:
>    /* Write the buffer to FILE.  */
>    void file_write (FILE *file) const
>    {
> -    ::file_write (file, m_vec);
> +    if (::fwrite (m_vec.data (), 1, m_vec.size (), file) != m_vec.size ())
> +      error (_("couldn't write data to file"));
>    }

It is a regression as one needs to multiply vector.size() by sizeof(vector[0]).
Which is also why I separated determining the memory block boundaries from
checking the write success.


Jan


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