From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27726 invoked by alias); 13 Apr 2011 10:47:04 -0000 Received: (qmail 27718 invoked by uid 22791); 13 Apr 2011 10:47:04 -0000 X-SWARE-Spam-Status: No, hits=-2.8 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 13 Apr 2011 10:46:55 +0000 From: "jb at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libfortran/48587] Avoid exhausting unit number with NEWUNIT= X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libfortran X-Bugzilla-Keywords: X-Bugzilla-Severity: enhancement X-Bugzilla-Who: jb at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Date: Wed, 13 Apr 2011 10:47:00 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2011-04/txt/msg01326.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48587 --- Comment #2 from Janne Blomqvist 2011-04-13 10:46:42 UTC --- (In reply to comment #1) > There is a problem with reusing numbers - it is probably only a small one - but > it might be larger than the problem of running out of unit IDs: > > The user might reuse NEWUNIT= IDs: > > Open(newunit=id) > ... > close(id) > open(unit=id) ... > > The latter is illegal as one may only pass positive numbers to unit=, but I > would not count on it. I don't see how this would differ from the current behavior vs. my suggested implementation. In any case, we check that the UNIT= number is positive when opening units: program negative_unit implicit none open(-10, file="foo.txt") write(-10, *) "Hello world" close(-10) end program negative_unit $ ./negative_unit At line 3 of file negative_unit.f90 Fortran runtime error: Bad unit number in OPEN statement (this is with 4.4; presumably this restriction hasn't been lifted?) Both the current implementation and my suggested one ensure that any unit number returned in NEWUNIT= is negative. This ensures that the UNIT= and NEWUNIT= number ranges are kept separate from each other, so they shouldn't interact. > Given that the number is huge, we decided that the > current method of just incrementing the value should be sufficient for nearly > all cases and one can think about something clever if a real-space code > encounters the problem. Ah, but what about a k-space code? ;) > However, I don't mind if one solves the problem before. Yeah, well, I don't think this is a big deal; after all it's pretty unlikely that any program will overflow the counter.