gcc/libgfortran
Janne Blomqvist c04d4ede17 PR 48587 Newunit allocator
Currently GFortran newer reuses unit numbers allocated with NEWUNIT=,
instead having a simple counter that is decremented each time such a
unit is opened.  For a long running program which repeatedly opens
files with NEWUNIT= and closes them, the counter can wrap around and
cause an abort.  This patch replaces the counter with an allocator
that keeps track of which units numbers are allocated, and can reuse
them once they have been deallocated.  Since operating systems tend to
limit the number of simultaneous open files for a process to a
relatively modest number, a relatively simple approach with a linear
scan through an array suffices.  Though as a small optimization there
is a low water indicator keeping track of the index for which all unit
numbers below are already allocated.  This linear scan also ensures
that we always allocate the smallest available unit number.

2016-10-15  Janne Blomqvist  <jb@gcc.gnu.org>

        PR libfortran/48587
        * io/io.h (get_unique_unit_number): Remove prototype.
        (newunit_alloc): New prototype.
        * io/open.c (st_open): Call newunit_alloc.
        * io/unit.c (newunits,newunit_size,newunit_lwi): New static
        variables.
        (GFC_FIRST_NEWUNIT): Rename to NEWUNIT_START.
        (next_available_newunit): Remove variable.
        (get_unit): Call newunit_alloc, don't try to create negative
        external unit.
        (close_unit_1): Call newunit_free.
        (close_units): Free newunits array.
        (get_unique_number): Remove function.
        (newunit_alloc): New function.
        (newunit_free): New function.
        * io/transfer.c (data_transfer_init): Check for invalid unit
        number.

testsuite ChangeLog:

2016-10-15  Janne Blomqvist  <jb@gcc.gnu.org>

        PR libfortran/48587
        * gfortran.dg/negative_unit2.f90: New testcase.

From-SVN: r241199
2016-10-15 16:14:15 +03:00
..
caf re PR libfortran/77663 (libgfortran/caf/single.c: three minor problems and a lost token) 2016-10-01 16:00:57 +02:00
config
generated
ieee re PR fortran/77507 (gfortran rejects keyworded calls to procedures from intrinsic modules) 2016-09-09 17:57:11 +00:00
intrinsics Use rand_s on MinGW-w64, fix array bound overflow. 2016-09-21 13:07:06 +03:00
io PR 48587 Newunit allocator 2016-10-15 16:14:15 +03:00
m4
runtime Replace KISS PRNG with xorshift1024* using per-thread state. 2016-08-11 11:58:55 +03:00
acinclude.m4
aclocal.m4
c99_protos.h
ChangeLog PR 48587 Newunit allocator 2016-10-15 16:14:15 +03:00
ChangeLog-2002
ChangeLog-2003
ChangeLog-2004
ChangeLog-2005
ChangeLog-2006
ChangeLog-2007
ChangeLog-2008
ChangeLog-2009
ChangeLog-2010
ChangeLog-2011
ChangeLog-2012
ChangeLog-2013
ChangeLog-2014
ChangeLog-2015
config.h.in
configure configure.ac (nvptx-*): Hardwire newlib. 2016-08-29 19:09:57 +00:00
configure.ac configure.ac (nvptx-*): Hardwire newlib. 2016-08-29 19:09:57 +00:00
configure.host
gfortran.map [multiple changes] 2016-08-31 05:36:22 +00:00
kinds-override.h
libgfortran.h
libgfortran.spec.in
libtool-version
Makefile.am
Makefile.in
mk-kinds-h.sh
mk-sik-inc.sh
mk-srk-inc.sh