aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPiotr Trojanek <trojanek@adacore.com>2024-10-24 10:47:09 +0200
committerMarc Poulhiès <dkm@gcc.gnu.org>2024-11-12 14:00:49 +0100
commit5f230267d241a199a6826c9c61f4e9b0a389c29b (patch)
tree7cf6fb71767abe7a417b36698bf9c67f31141bfa /gcc
parent9bba882f922e69abc72fa71520be649258cfd856 (diff)
downloadgcc-5f230267d241a199a6826c9c61f4e9b0a389c29b.zip
gcc-5f230267d241a199a6826c9c61f4e9b0a389c29b.tar.gz
gcc-5f230267d241a199a6826c9c61f4e9b0a389c29b.tar.bz2
ada: Detect sharing of external file in inconsistent read-write modes
When opening files with "shared=yes", as described in GNAT RM 11.10, Sharing Files, we now prevent sharing a single file in inconsistent read-write modes. gcc/ada/ChangeLog: * doc/gnat_rm/the_implementation_of_standard_i_o.rst (Shared Files): Add trailing period. * libgnat/s-ficobl.ads (AFCB): Reflect new behavior in comment. * libgnat/s-fileio.adb (Open): Detect inconsistent sharing, just like we do in System.File_IO.Reset. * gnat_rm.texi: Regenerate. * gnat_ugn.texi: Regenerate.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ada/doc/gnat_rm/the_implementation_of_standard_i_o.rst2
-rw-r--r--gcc/ada/gnat_rm.texi4
-rw-r--r--gcc/ada/gnat_ugn.texi2
-rw-r--r--gcc/ada/libgnat/s-ficobl.ads4
-rw-r--r--gcc/ada/libgnat/s-fileio.adb5
5 files changed, 11 insertions, 6 deletions
diff --git a/gcc/ada/doc/gnat_rm/the_implementation_of_standard_i_o.rst b/gcc/ada/doc/gnat_rm/the_implementation_of_standard_i_o.rst
index f6d884d..fff9bbf 100644
--- a/gcc/ada/doc/gnat_rm/the_implementation_of_standard_i_o.rst
+++ b/gcc/ada/doc/gnat_rm/the_implementation_of_standard_i_o.rst
@@ -894,7 +894,7 @@ One common use of file sharing in Ada 83 is the use of instantiations of
Sequential_IO on the same file with different types, to achieve
heterogeneous input-output. Although this approach will work in GNAT if
``shared=yes`` is specified, it is preferable in Ada to use Stream_IO
-for this purpose (using the stream attributes)
+for this purpose (using the stream attributes).
.. _Filenames_encoding:
diff --git a/gcc/ada/gnat_rm.texi b/gcc/ada/gnat_rm.texi
index ff55de5..5c3f439 100644
--- a/gcc/ada/gnat_rm.texi
+++ b/gcc/ada/gnat_rm.texi
@@ -19,7 +19,7 @@
@copying
@quotation
-GNAT Reference Manual , Nov 04, 2024
+GNAT Reference Manual , Nov 08, 2024
AdaCore
@@ -22891,7 +22891,7 @@ One common use of file sharing in Ada 83 is the use of instantiations of
Sequential_IO on the same file with different types, to achieve
heterogeneous input-output. Although this approach will work in GNAT if
@code{shared=yes} is specified, it is preferable in Ada to use Stream_IO
-for this purpose (using the stream attributes)
+for this purpose (using the stream attributes).
@node Filenames encoding,File content encoding,Shared Files,The Implementation of Standard I/O
@anchor{gnat_rm/the_implementation_of_standard_i_o filenames-encoding}@anchor{2e2}@anchor{gnat_rm/the_implementation_of_standard_i_o id22}@anchor{2e3}
diff --git a/gcc/ada/gnat_ugn.texi b/gcc/ada/gnat_ugn.texi
index 5eef602..e4f14d2 100644
--- a/gcc/ada/gnat_ugn.texi
+++ b/gcc/ada/gnat_ugn.texi
@@ -29841,8 +29841,8 @@ to permit their use in free software.
@printindex ge
-@anchor{d2}@w{ }
@anchor{gnat_ugn/gnat_utility_programs switches-related-to-project-files}@w{ }
+@anchor{d2}@w{ }
@c %**end of body
@bye
diff --git a/gcc/ada/libgnat/s-ficobl.ads b/gcc/ada/libgnat/s-ficobl.ads
index 29560cb..37dac54 100644
--- a/gcc/ada/libgnat/s-ficobl.ads
+++ b/gcc/ada/libgnat/s-ficobl.ads
@@ -100,8 +100,8 @@ package System.File_Control_Block with SPARK_Mode => Off is
-- defaults at this level). The string is always null-terminated.
Mode : File_Mode;
- -- The file mode. No checks are made that the mode is consistent
- -- with the form used to fopen the file.
+ -- The file mode. When sharing files, we check that the mode is
+ -- consistent with the already opened files.
Is_Regular_File : Boolean;
-- A flag indicating if the file is a regular file
diff --git a/gcc/ada/libgnat/s-fileio.adb b/gcc/ada/libgnat/s-fileio.adb
index 3dea358..69841f0 100644
--- a/gcc/ada/libgnat/s-fileio.adb
+++ b/gcc/ada/libgnat/s-fileio.adb
@@ -1042,6 +1042,11 @@ package body System.File_IO is
elsif Shared = Yes
and then P.Shared_Status = Yes
then
+ if Mode /= P.Mode then
+ raise Use_Error
+ with "sharing file in different modes";
+ end if;
+
Stream := P.Stream;
Record_AFCB;