[Patch, libfortran, 3/3] Update file position lazily
Janne Blomqvist
blomqvist.janne@gmail.com
Tue Oct 18 15:11:00 GMT 2011
Hi,
libgfortran maintains a position flag which is used by the
INQUIRE(POSITION=...) statement. Currently we update this flag after
every IO statement. For unbuffered IO this is somewhat tedious, as
figuring out whether we're at the beginning of a file or the end
requires at least two syscalls. The attached patch moves this checking
to the inquire implementation, which is certainly less frequently
invoked than READ or WRITE.
Also, I think I've found a small standards conformance bug. From F2008
(N1830) 9.10.2.23 (page 256): "... ASIS if the connection was opened
without changing its position." and "If the file has been repositioned
since the connection, the scalar-default-char-variable
is assigned a processor-dependent value, which shall not be REWIND
unless the file is positioned at its initial
point and shall not be APPEND unless the file is positioned so that its
endfile record is the next record or at its
terminal point if it has no endfile record.
"
If my understanding of the above is correct, returning ASIS is
incorrent unless the position is unchanged since the OPEN statement.
Currently we return ASIS by default if it's neither REWIND nor APPEND.
So the patch changes the implementation to return the
processor-dependent value UNSPECIFIED in this case.
Regtested on x86_64-unknown-linux-gnu, Ok for trunk?
2011-10-18 Janne Blomqvist <jb@gcc.gnu.org>
* io/inquire.c (inquire_via_unit): Check whether we're at the
beginning or end if the position is unspecified. If the position
is not one of the 3 standard ones, return unspecified.
* io/io.h (update_position): Remove prototype.
* io/transfer.c (next_record): Set the position to unspecified,
letting inquire figure it out more exactly when needed.
* io/unit.c (update_position): Remove function.
testsuite ChangeLog:
2011-10-18 Janne Blomqvist <jb@gcc.gnu.org>
* gfortran.dg/inquire_5.f90: Update testcase to match the standard
and current implementation.
--
Janne Blomqvist
-------------- next part --------------
A non-text attachment was scrubbed...
Name: lazypos.diff
Type: text/x-patch
Size: 4755 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20111018/f82844b5/attachment.bin>
More information about the Fortran
mailing list