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

Jan Kratochvil
2017-06-19T09:39:29Z

On Mon, 19 Jun 2017 11:27:46 +0200, Pedro Alves wrote:
> On 06/18/2017 07:36 PM, Jan Kratochvil wrote:
>
> >> @@ -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.
>
> No it's not. The fwrite call is no longer in generic code where
> the element type is unknown. Here m_vec is a vector of gdb_byte, and
> gdb_byte is guaranteed to have sizeof == 1.

Ah, OK. So I would like there some: static_assert (sizeof (m_vec[0]) == 1);

The file_write template+function is used also in a later patch of that series
where sizeof(element) is not 1. I have reimplemented it with ::fwrite in this
"v2" series after this your removal but I do not agree with that, IMO it was
safer+easier with the template+function you just removed.

Jan