]> git.ipfire.org Git - thirdparty/gcc.git/commit
Generate a runtime error on recursive I/O, thread-safe
authorThomas Koenig <tkoenig@gcc.gnu.org>
Sun, 4 Jan 2026 19:09:39 +0000 (20:09 +0100)
committerThomas Koenig <tkoenig@gcc.gnu.org>
Tue, 6 Jan 2026 06:32:10 +0000 (07:32 +0100)
commite32c3fb4311bcaf767a87934d6495f05fbae7bc9
tree33ec476e6b5674d522bd08af6cf77fcb5399f548
parent5376cb84aa1eee3670ed5d64443bedbdd2041c55
Generate a runtime error on recursive I/O, thread-safe

This patch is a version of Jerry's patch with one additional feature.
When locking a unit, the thread ID of the locking thread also stored
in the gfc_unit structure. When the unit is found to be locked, it can
be either have been locked by the same thread (bad, recursive I/O) or
by another thread (harmless).

Regression-tested fully (make -j8 check in the gcc build directory) on
Linux, which links in pthreads by default.  Steve checked on FreeBSD,
which does not do so.

Jerry DeLisle  <jvdelisle@gcc.gnu.org>
Thomas Koenig <tkoenig@gcc.gnu.org>

PR libfortran/119136

gcc/fortran/ChangeLog:

* libgfortran.h: Add enum for new LIBERROR_RECURSIVE_IO.

libgfortran/ChangeLog:

* io/async.h (UNLOCK_UNIT): New macro.
(TRYLOCK_UNIT): New macro.
(LOCK_UNIT): New macro.
* io/io.h: Delete prototype for unused stash_internal_unit.
(check_for_recursive): Add prototype for this new function.
* io/transfer.c (data_transfer_init): Add call to new
check_for_recursive.
* io/unit.c (delete_unit): Fix comment.
(check_for_recursive): Add new function.
(init_units): Use new macros.
(close_unit_1): Likewise.
(unlock_unit): Likewise.
* io/unix.c (flush_all_units_1): Likewise.
(flush_all_units): Likewise.
* runtime/error.c (translate_error): : Add translation for
"Recursive I/O not allowed runtime error message.

gcc/testsuite/ChangeLog:

* gfortran.dg/pr119136.f90: New test.
gcc/fortran/libgfortran.h
gcc/testsuite/gfortran.dg/pr119136.f90 [new file with mode: 0644]
libgfortran/io/async.h
libgfortran/io/io.h
libgfortran/io/transfer.c
libgfortran/io/unit.c
libgfortran/io/unix.c
libgfortran/runtime/error.c