This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran 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]

Re: GCC 4.7.0 Status Report (2011-10-11)


On Sat, Oct 15, 2011 at 00:12, Tobias Burnus <burnus@net-b.de> wrote:
> Well, I do not worry about INQUIRE - I really do not think that programs use
> it in a loop. Thus, I am happy with either _commit, or an internal file-size
> read, or the current stat without _commit.
>
> In any case, we should remove the _commit from internal/implict buffer
> flushes. Still, for explicit FLUSH statements (or subroutine calls), I think
> gfortran should make sure that the data ends up such that other programs can
> read the file with the current value.
>
> Users should know that FLUSH is relatively expensive - thus, FLUSH should
> only be sparsely used.

Well, within reason. I don't think making FLUSH orders of magnitude
slower and provide very different robustness guarantees on one
platform is conductive to creating portable applications.  There's
also the issue of how to handle unbuffered files; should we _commit()
after every write then, or?

While the standard of course leaves a lot up to the implementation wrt
IO, I think the intention is pretty clear that it's supposed to be the
equivalent of C stdio fflush() and other similar flush mechanisms in
other languages. There's a reason why fsync()/_commit() is kept as a
separate concept.

If it so happens that writing out data to the OS doesn't immediately
update the file metadata on windows, then I suppose that's they way
stuff works on that platform, and programmers are supposed to handle
it themselves in some way just like they have to do for
C/C++/python/whatnot.

> Would be my patch without the inquire.c change be an
> option for you?

I was thinking something along the lines of the attached patch, which
changes gfortran to use the libgfortran info for the file size when
doing a size inquiry on an open file. Also, in order to preserve
existing behavior at least on POSIX platforms, the buffer is flushed;
while this makes it slower (though still being far lighter weight than
fsync/_commit), like you say, I don't think it's a performance
critical thing.


-- 
Janne Blomqvist
diff --git a/gcc/testsuite/gfortran.dg/inquire_size.f90 b/gcc/testsuite/gfortran.dg/inquire_size.f90
index 568c3d6..13876cf 100644
--- a/gcc/testsuite/gfortran.dg/inquire_size.f90
+++ b/gcc/testsuite/gfortran.dg/inquire_size.f90
@@ -8,7 +8,9 @@ open(25, file="testfile", status="replace", access="stream", form="unformatted")
 do i=1,100
   write(25) i, "abcdefghijklmnopqrstuvwxyz"
 enddo
-flush(25)
+! Gfortran implicitly flushes the buffer when doing a file size
+! inquire on an open file.
+! flush(25)
 
 inquire(unit=25, named=is_named, name=aname, size=i)
 if (.not.is_named) call abort
diff --git a/libgfortran/io/inquire.c b/libgfortran/io/inquire.c
index 252f29f..97bd9b6 100644
--- a/libgfortran/io/inquire.c
+++ b/libgfortran/io/inquire.c
@@ -409,7 +409,10 @@ inquire_via_unit (st_parameter_inquire *iqp, gfc_unit * u)
 	  if (u == NULL)
 	    *iqp->size = -1;
 	  else
-	    *iqp->size = file_size (u->file, (gfc_charlen_type) u->file_len);
+	    {
+	      sflush (u->s);
+	      *iqp->size = file_length (u->s);
+	    }
 	}
     }
 
diff --git a/libgfortran/io/unix.c b/libgfortran/io/unix.c
index 25cb559..a209c14 100644
--- a/libgfortran/io/unix.c
+++ b/libgfortran/io/unix.c
@@ -443,10 +443,6 @@ buf_flush (unix_stream * s)
   if (s->ndirty != 0)
     return -1;
 
-#ifdef _WIN32
-  _commit (s->fd);
-#endif
-
   return 0;
 }
 

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