This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libfortran/33985] access="stream",form="unformatted" doesn't buffer
- From: "jvdelisle at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 6 Nov 2007 02:41:37 -0000
- Subject: [Bug libfortran/33985] access="stream",form="unformatted" doesn't buffer
- References: <bug-33985-10391@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #5 from jvdelisle at gcc dot gnu dot org 2007-11-06 02:41 -------
Here is a test case that fails with the new patch. (Thanks Dominique)
program streamtest
implicit none
character(1) :: lf = char(10)
character(1) :: tchar
integer :: i,j,k
real(kind=4), dimension(100,100) :: anarray
open(10, file="teststream", access="stream", form="unformatted")
anarray = 3.14159
write(10) anarray
write(10, pos=1) ! This is a way to position an unformatted file
anarray = 0.0
read(10) anarray
anarray = abs(anarray - 3.14159)
if (any(anarray.gt.0.00001)) call abort()
close(10,status="delete")
end program streamtest
Ans a simple patch to fix it:
Index: io/transfer.c
===================================================================
--- io/transfer.c (revision 129871)
+++ io/transfer.c (working copy)
@@ -591,11 +591,14 @@ write_buf (st_parameter_dt *dtp, void *b
size_t have_written, to_write_subrecord;
int short_record;
-
/* Stream I/O. */
if (is_stream_io (dtp))
{
+ if (dtp->u.p.current_unit->strm_pos - 1
+ < file_position (dtp->u.p.current_unit->s))
+ flush(dtp->u.p.current_unit->s);
+
if (sseek (dtp->u.p.current_unit->s,
dtp->u.p.current_unit->strm_pos - 1) == FAILURE)
{
Regression tested on x86-64-linux-gnu
--
jvdelisle at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |REOPENED
Resolution|FIXED |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33985