[patch, libfortran] PR34795 inquire statement , direct= specifier incorrectly returns YES

Tobias Burnus burnus@net-b.de
Sun Jan 20 00:08:00 GMT 2008


Jerry DeLisle wrote:
> This patch modifies gfortran behavior for inquire. The specifiers
> DIRECT=, FORMATTED=, UNFORMATTED=, and SEQUENTIAL answer the question
> whether a given file "may" be opened with the given specifier.
>
> This implies that the given file or unit is not already opened.
I have to admit that I do not see this implication - especially not if
one queries by unit and not by name.

> The patch addresses the case where the files are already opened in
> which case we can query the unit for the actual mode and return
> "YES","NO", "FORMATTED", or "UNFORMATTED" accordingly.
>
> SEQUENTIAL= was already handled this way.

As written in #gfortran I regard it as useful change to return the same
result as the majority of the compilers in this case, i.e. "YES" if the
file has been opened in this mode and "NO" if it has been opened in a
different mode. (NAG f95 has "YES" and "UNKNOWN".)

There are programs relying on the new behavior: The file is opened
somewhere and then the unit number or the filename is passed around and
before the write/read statement the current mode is checked.


The only correct answer would be, by the way, "UNKNOWN" and not "NO" as
one does not rule out the other. (Though using formatted on unformatted,
non-stream files might yield interesting results.)

(Actually, for closed files is the same problem: The library does not
know whether a file is formatted or unformatted - and the operating
system does not know it either. [I think VAX made a distinction.])

> Regression tested on X86-64-Linux.  We have no existing test case that
> is affected by this change.  A new test case is provided.

Can you enhance the test case to check also inquire(file='testfile')
instead of testing only inquite(unit=19) ?


Additionally, your test case fails if the file "testdirect.f" does not
exist. As you call this file "inquire_13.f90" and not "testdirect.f" (as
the original bug report did, the test case will fail for:

open(unit=19,file='testdirect.f',status='OLD',err=170)

which is probably not intended.

Touching the file and calling inquire after that open statement

inquire(file='testfile', direct=drct, opened=opn, access=acc)

gives different results for drct:  "YES" with gfortran and "UNKNOWN"
with ifort, sunf95, openf95, pathscale, PGI and NAG f95. Otherwise
gfortran's output is identical to ifort and sunf95 (using
"inquire(file=...)") while there are some differences to the other
compilers for the other tests. Only g95 and g77 have also "YES".

I think that therefore gfortran should also print "UNKNOWN" for this
test case.

Otherwise the patch is ok.

Tobias

> PS Is the patch tracker working any more?
No. The last time I pinged on #gcc the answer was something like "as
time permits" and about in 2-3 weeks. Someone suggested at gcc@ to put
it on the gcc.gnu.org server, though there might be problems as it uses
Ruby.



More information about the Gcc-patches mailing list