This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Regression: Re: [PATCH 2/6] Code cleanup: dwarf2read.c: Eliminate ::file_write
- From: Jan Kratochvil <jan dot kratochvil at redhat dot com>
- To: Pedro Alves <palves at redhat dot com>
- Cc: gdb-patches at sourceware dot org
- Date: Sun, 18 Jun 2017 20:36:03 +0200
- Subject: Regression: Re: [PATCH 2/6] Code cleanup: dwarf2read.c: Eliminate ::file_write
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jan dot kratochvil at redhat dot com
- Dkim-filter: OpenDKIM Filter v2.11.0 mx1.redhat.com E36498123A
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E36498123A
- References: <8efc0742-1014-4fe0-6948-f40a9c5c4975@redhat.com> <1497284051-13795-2-git-send-email-palves@redhat.com>
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