public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/38122]  New: "file already opened in another unit" error when opening /dev/null or /dev/tty twice
@ 2008-11-14 18:15 steven dot chapel at sbcglobal dot net
  2008-11-14 18:41 ` [Bug fortran/38122] " kargl at gcc dot gnu dot org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: steven dot chapel at sbcglobal dot net @ 2008-11-14 18:15 UTC (permalink / raw)
  To: gcc-bugs

The following program runs without error when compiled with g77 3.4.6 on Redhat
Linux:

       character*72 fnint
       data fnint /'/dev/null'/
       i=index(fnint,' ')
       open(unit=29,file=fnint(1:i-1))
       open(unit=30,file=fnint(1:i-1))
       write(29,100)
       write(30,100)
 100   format('1Hello, world!')
       end

When compiled with gfortran 4.3.2 on Redhat Linux, the following error message
is printed when the program is run:

At line 5 of file bug.f (unit = 30, file = '')
Fortran runtime error: File already opened in another unit

The same error results when I use /dev/tty in place of /dev/null, although this
too works in g77 3.4.6.

This bug is causing me to have to modify a program called NONMEM VI to get it
to run properly.


-- 
           Summary: "file already opened in another unit" error when opening
                    /dev/null or /dev/tty twice
           Product: gcc
           Version: 4.3.2
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: steven dot chapel at sbcglobal dot net
 GCC build triplet: i386-redhat-linux
  GCC host triplet: i386-redhat-linux
GCC target triplet: i386-redhat-linux


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38122


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug fortran/38122] "file already opened in another unit" error when opening /dev/null or /dev/tty twice
  2008-11-14 18:15 [Bug fortran/38122] New: "file already opened in another unit" error when opening /dev/null or /dev/tty twice steven dot chapel at sbcglobal dot net
@ 2008-11-14 18:41 ` kargl at gcc dot gnu dot org
  2008-11-14 20:20 ` steve dot chapel at a2pg dot com
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: kargl at gcc dot gnu dot org @ 2008-11-14 18:41 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from kargl at gcc dot gnu dot org  2008-11-14 18:40 -------
(In reply to comment #0)
> The following program runs without error when compiled with g77 3.4.6 on Redhat
> Linux:
> 
>        character*72 fnint
>        data fnint /'/dev/null'/
>        i=index(fnint,' ')
>        open(unit=29,file=fnint(1:i-1))
>        open(unit=30,file=fnint(1:i-1))
>        write(29,100)
>        write(30,100)
>  100   format('1Hello, world!')
>        end
> 
> When compiled with gfortran 4.3.2 on Redhat Linux, the following error message
> is printed when the program is run:
> 
> At line 5 of file bug.f (unit = 30, file = '')
> Fortran runtime error: File already opened in another unit
> 
> The same error results when I use /dev/tty in place of /dev/null, although this
> too works in g77 3.4.6.
> 
> This bug is causing me to have to modify a program called NONMEM VI to get it
> to run properly.
> 

It's not a bug in gfortran.  It is a bug in your program.
>From the Fortran 95 standard, Section 9.3.4:

   If a file is already connected to a unit, execution of an OPEN
   statement on that file and a different unit is not permitted.

>From the Fortran 77 Standard, Section 12.3.2:

   A unit must not be connected to more than one file at the same time,
   and a file must not be connected to more than one unit at the same time.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38122


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug fortran/38122] "file already opened in another unit" error when opening /dev/null or /dev/tty twice
  2008-11-14 18:15 [Bug fortran/38122] New: "file already opened in another unit" error when opening /dev/null or /dev/tty twice steven dot chapel at sbcglobal dot net
  2008-11-14 18:41 ` [Bug fortran/38122] " kargl at gcc dot gnu dot org
@ 2008-11-14 20:20 ` steve dot chapel at a2pg dot com
  2008-11-14 20:56 ` kargl at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: steve dot chapel at a2pg dot com @ 2008-11-14 20:20 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from steve dot chapel at a2pg dot com  2008-11-14 20:19 -------
It's not a bug in my program. It's a bug in NONMEM VI. That is, assuming that
/dev/tty and /dev/null are files, which they're not. They're devices.
Regardless, it's code that runs in an older version that doesn't run in a new
version. This problem will cause people to use the old version of the compiler.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38122


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug fortran/38122] "file already opened in another unit" error when opening /dev/null or /dev/tty twice
  2008-11-14 18:15 [Bug fortran/38122] New: "file already opened in another unit" error when opening /dev/null or /dev/tty twice steven dot chapel at sbcglobal dot net
  2008-11-14 18:41 ` [Bug fortran/38122] " kargl at gcc dot gnu dot org
  2008-11-14 20:20 ` steve dot chapel at a2pg dot com
@ 2008-11-14 20:56 ` kargl at gcc dot gnu dot org
  2008-11-15 10:43 ` burnus at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: kargl at gcc dot gnu dot org @ 2008-11-14 20:56 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from kargl at gcc dot gnu dot org  2008-11-14 20:54 -------
(In reply to comment #2)
> It's not a bug in my program. It's a bug in NONMEM VI. That is, assuming that
> /dev/tty and /dev/null are files, which they're not. They're devices.

OK, then it's a bug in NONMEM VI.  Submit a bug report to the NONMEM VI
developers.  I cited both the Fortran 77 and Fortran 95 standards, which
show that this is nonconforming code.  Feel free to send my email to them.
You can also tell the NONMEM VI developers that once a unit number is
opened, it is global to entire program.

Under the Unix idiom, /dev/tty and /dev/null are (special) files.
Try 'man 4 null' and 'man 4 tty' on your Redhat box.

> Regardless, it's code that runs in an older version that doesn't run
> in a new version. This problem will cause people to use the old version
> of the compiler.

Well, no.  The code never ran with an older version of gfortran unless
an older version of gfortran had a bug that permitted it.

gfortran and g77 are not the same compiler.  While gfortran tries to
provide backwards compatibility with g77, the author of g77 made several
questionable choices with violating the Fortran 77 Standard.  gfortran
follows the Standards.  Hopefully, "this problem will cause people to"
fix their code.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38122


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug fortran/38122] "file already opened in another unit" error when opening /dev/null or /dev/tty twice
  2008-11-14 18:15 [Bug fortran/38122] New: "file already opened in another unit" error when opening /dev/null or /dev/tty twice steven dot chapel at sbcglobal dot net
                   ` (2 preceding siblings ...)
  2008-11-14 20:56 ` kargl at gcc dot gnu dot org
@ 2008-11-15 10:43 ` burnus at gcc dot gnu dot org
  2008-11-15 15:00 ` jvdelisle at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: burnus at gcc dot gnu dot org @ 2008-11-15 10:43 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from burnus at gcc dot gnu dot org  2008-11-15 10:42 -------
> It's not a bug in my program. It's a bug in NONMEM VI. That is, assuming that
> /dev/tty and /dev/null are files, which they're not. They're devices.
> Regardless, it's code that runs in an older version that doesn't run in a new
> version. This problem will cause people to use the old version of the compiler.

The problem with accessing the same file with different I/O units is that it
quickly leads to race conditions; for /dev/null I don't see any problem, but
for a normal, seekable file like "my_data_file.dat" this is different.

See also:
http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/bd22f289feb99d22/


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38122


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug fortran/38122] "file already opened in another unit" error when opening /dev/null or /dev/tty twice
  2008-11-14 18:15 [Bug fortran/38122] New: "file already opened in another unit" error when opening /dev/null or /dev/tty twice steven dot chapel at sbcglobal dot net
                   ` (3 preceding siblings ...)
  2008-11-15 10:43 ` burnus at gcc dot gnu dot org
@ 2008-11-15 15:00 ` jvdelisle at gcc dot gnu dot org
  2008-11-15 17:30 ` kargl at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jvdelisle at gcc dot gnu dot org @ 2008-11-15 15:00 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from jvdelisle at gcc dot gnu dot org  2008-11-15 14:58 -------
Well I managed to read that thread about 90% through without falling to sleep. 
One point made there is that gfortran should not reposition the file after a
reopen as the default position= specifier should be ASIS.

I will check into this one point.

If anyone sees any other Fortran Standard specifics we may be missing, let me
know so I can fix those.

I do believe that one could write a standard conforming "layer" in Fortran to
handle all of the OPs issues. Obviously one would have to get creative to do
it.

The other thing that was not mentioned is ASYNCHRONOUS I/O which might be the
real solution here.  I/O calls would be queued in and allow the application to
track status with the ID.  


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38122


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug fortran/38122] "file already opened in another unit" error when opening /dev/null or /dev/tty twice
  2008-11-14 18:15 [Bug fortran/38122] New: "file already opened in another unit" error when opening /dev/null or /dev/tty twice steven dot chapel at sbcglobal dot net
                   ` (4 preceding siblings ...)
  2008-11-15 15:00 ` jvdelisle at gcc dot gnu dot org
@ 2008-11-15 17:30 ` kargl at gcc dot gnu dot org
  2008-11-15 19:15 ` jvdelisle at verizon dot net
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: kargl at gcc dot gnu dot org @ 2008-11-15 17:30 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from kargl at gcc dot gnu dot org  2008-11-15 17:28 -------
(In reply to comment #5)
> 
> I do believe that one could write a standard conforming "layer" in Fortran to
> handle all of the OPs issues. Obviously one would have to get creative to do
> it.

Which OP?  The originator of the c.l.f thread or the originator of
this bug report.  I've cited passages from the F77 standard and
F95 standards that explicitly state the issue raised in this 
PR is a non-issue.  gfortran's current behavior correctly conforms
to the standard.  Please, don't unfix that behavior.

As Tobias points out, attaching 2 or more unit numbers to the same
file would open gfortran to race conditions.  Jakub went through
libgfortran to make it thread when he added the OpenMP code. You
would need to paste in a layer of mutexes to properly lock/unlock
access to files.  I for one do not see the benefit of forcing a
performance penalty on everyone to permit nonconforming code to compile.

$0.02

PS: yes, the ASIS issue should be fixed.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38122


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug fortran/38122] "file already opened in another unit" error when opening /dev/null or /dev/tty twice
  2008-11-14 18:15 [Bug fortran/38122] New: "file already opened in another unit" error when opening /dev/null or /dev/tty twice steven dot chapel at sbcglobal dot net
                   ` (5 preceding siblings ...)
  2008-11-15 17:30 ` kargl at gcc dot gnu dot org
@ 2008-11-15 19:15 ` jvdelisle at verizon dot net
  2008-11-15 20:53 ` jvdelisle at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jvdelisle at verizon dot net @ 2008-11-15 19:15 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from jvdelisle at verizon dot net  2008-11-15 19:13 -------
Subject: Re:  "file already opened in another unit" error
 when opening /dev/null or /dev/tty twice

> Which OP?  The originator of the c.l.f thread or the originator of
> this bug report.

Originator of this bug report. And what I am trying to say is that the NONMEM 
folks could write their code so that it does not violate the standard and deals 
with any need for multi-threading.
> 
> As Tobias points out, attaching 2 or more unit numbers to the same
> file would open gfortran to race conditions.

Agree, don't attach 2 or more unit numbers to the same file. I have written 
rudimentary multi-tasking and multi-threading code myself even when not 
supported by the OS. Yes, its extra work and most system programmers would 
cringe at the thought of doing that in Fortran. Respectfully, the NONMEM team 
needs to fix their code.

> $0.02


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38122


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug fortran/38122] "file already opened in another unit" error when opening /dev/null or /dev/tty twice
  2008-11-14 18:15 [Bug fortran/38122] New: "file already opened in another unit" error when opening /dev/null or /dev/tty twice steven dot chapel at sbcglobal dot net
                   ` (6 preceding siblings ...)
  2008-11-15 19:15 ` jvdelisle at verizon dot net
@ 2008-11-15 20:53 ` jvdelisle at gcc dot gnu dot org
  2009-01-05 20:23 ` mikael at gcc dot gnu dot org
  2009-01-18  1:33 ` jvdelisle at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: jvdelisle at gcc dot gnu dot org @ 2008-11-15 20:53 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from jvdelisle at gcc dot gnu dot org  2008-11-15 20:51 -------
As far as I can tell, ASIS is working correctly with gfortran 4.4 and 4.3.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38122


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug fortran/38122] "file already opened in another unit" error when opening /dev/null or /dev/tty twice
  2008-11-14 18:15 [Bug fortran/38122] New: "file already opened in another unit" error when opening /dev/null or /dev/tty twice steven dot chapel at sbcglobal dot net
                   ` (7 preceding siblings ...)
  2008-11-15 20:53 ` jvdelisle at gcc dot gnu dot org
@ 2009-01-05 20:23 ` mikael at gcc dot gnu dot org
  2009-01-18  1:33 ` jvdelisle at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: mikael at gcc dot gnu dot org @ 2009-01-05 20:23 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from mikael at gcc dot gnu dot org  2009-01-05 20:23 -------
(In reply to comment #8)
> As far as I can tell, ASIS is working correctly with gfortran 4.4 and 4.3.
> 
So, we can close?


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38122


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug fortran/38122] "file already opened in another unit" error when opening /dev/null or /dev/tty twice
  2008-11-14 18:15 [Bug fortran/38122] New: "file already opened in another unit" error when opening /dev/null or /dev/tty twice steven dot chapel at sbcglobal dot net
                   ` (8 preceding siblings ...)
  2009-01-05 20:23 ` mikael at gcc dot gnu dot org
@ 2009-01-18  1:33 ` jvdelisle at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: jvdelisle at gcc dot gnu dot org @ 2009-01-18  1:33 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #10 from jvdelisle at gcc dot gnu dot org  2009-01-18 01:33 -------
Closing, the code is invalid Fortran


-- 

jvdelisle at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38122


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2009-01-18  1:33 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-11-14 18:15 [Bug fortran/38122] New: "file already opened in another unit" error when opening /dev/null or /dev/tty twice steven dot chapel at sbcglobal dot net
2008-11-14 18:41 ` [Bug fortran/38122] " kargl at gcc dot gnu dot org
2008-11-14 20:20 ` steve dot chapel at a2pg dot com
2008-11-14 20:56 ` kargl at gcc dot gnu dot org
2008-11-15 10:43 ` burnus at gcc dot gnu dot org
2008-11-15 15:00 ` jvdelisle at gcc dot gnu dot org
2008-11-15 17:30 ` kargl at gcc dot gnu dot org
2008-11-15 19:15 ` jvdelisle at verizon dot net
2008-11-15 20:53 ` jvdelisle at gcc dot gnu dot org
2009-01-05 20:23 ` mikael at gcc dot gnu dot org
2009-01-18  1:33 ` jvdelisle at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).