Patchwork [Ada] Ada.Streams.Stream_IO is preelaborated

login
register
mail settings
Submitter Arnaud Charlet
Date July 9, 2012, 1:05 p.m.
Message ID <20120709130534.GA16144@adacore.com>
Download mbox | patch
Permalink /patch/169817/
State New
Headers show

Comments

Arnaud Charlet - July 9, 2012, 1:05 p.m.
AI05-0283 requires Ada.Streams.Stream_IO to be declared with a pragma
Preelaborate, so that it can be used by other preelaborated units as
well as by Remote_Types and Remote_Call_Interface units. The pragma
has been added to that package along with several other GNAT library 
units on which it depends. Other minor changes were made to avoid
Preelaborate violations occurring in the body of System.File_IO.

Tested on x86_64-pc-linux-gnu, committed on trunk

2012-07-09  Gary Dismukes  <dismukes@adacore.com>

	* a-ststio.ads: Add pragma Preelaborate, per AI05-0283.
	* i-cstrea.ads (max_path_len): Change from variable to deferred
	constant to allow it to be used as a bound in string component
	in type System.File_IO.Temp_File_Record.
	* s-os_lib.ads, s-commun.ads, s-ficobl.ads, s-fileio.ads: Add pragma
	Preelaborate.
	* s-fileio.adb (Get_Case_Sensitive): Move function inside
	procedure Open.
	(File_Names_Case_Sensitive): Move variable inside
	procedure Open, to avoid violation of Preelaborate restriction
	(due to call to Get_Case_Sensitive).

Patch

Index: i-cstrea.ads
===================================================================
--- i-cstrea.ads	(revision 189366)
+++ i-cstrea.ads	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                 S p e c                                  --
 --                                                                          --
---          Copyright (C) 1995-2010, Free Software Foundation, Inc.         --
+--          Copyright (C) 1995-2012, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -228,9 +228,11 @@ 
    --  pass an actual parameter for buffer that is big enough for any full
    --  path name. Use max_path_len given below as the size of buffer.
 
-   max_path_len : Integer;
-   --  Maximum length of an allowable full path name on the system,
-   --  including a terminating NUL character.
+   max_path_len : constant Integer;
+   --  max_path_len : Integer;
+   --  Maximum length of an allowable full path name on the system,including a
+   --  terminating NUL character. Declared as a constant to allow references
+   --  from other preelaborated GNAT library packages.
 
 private
    --  The following functions are specialized in the body depending on the
Index: a-ststio.ads
===================================================================
--- a-ststio.ads	(revision 189366)
+++ a-ststio.ads	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                 S p e c                                  --
 --                                                                          --
---          Copyright (C) 1992-2011, Free Software Foundation, Inc.         --
+--          Copyright (C) 1992-2012, Free Software Foundation, Inc.         --
 --                                                                          --
 -- This specification is derived from the Ada Reference Manual for use with --
 -- GNAT. The copyright notice above, and the license provisions that follow --
@@ -38,6 +38,8 @@ 
 
 package Ada.Streams.Stream_IO is
 
+   pragma Preelaborate;
+
    type Stream_Access is access all Root_Stream_Type'Class;
 
    type File_Type is limited private;
Index: s-commun.ads
===================================================================
--- s-commun.ads	(revision 189366)
+++ s-commun.ads	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                 S p e c                                  --
 --                                                                          --
---                     Copyright (C) 2001-2009, AdaCore                     --
+--                     Copyright (C) 2001-2012, AdaCore                     --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -36,6 +36,8 @@ 
 
 package System.Communication is
 
+   pragma Preelaborate;
+
    function Last_Index
      (First : Ada.Streams.Stream_Element_Offset;
       Count : CRTL.size_t) return Ada.Streams.Stream_Element_Offset;
Index: s-ficobl.ads
===================================================================
--- s-ficobl.ads	(revision 189366)
+++ s-ficobl.ads	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                 S p e c                                  --
 --                                                                          --
---            Copyright (C) 1992-2011, Free Software Foundation, Inc.       --
+--            Copyright (C) 1992-2012, Free Software Foundation, Inc.       --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -41,6 +41,8 @@ 
 
 package System.File_Control_Block is
 
+   pragma Preelaborate;
+
    ----------------------------
    -- Ada File Control Block --
    ----------------------------
Index: s-os_lib.ads
===================================================================
--- s-os_lib.ads	(revision 189366)
+++ s-os_lib.ads	(working copy)
@@ -56,6 +56,8 @@ 
 package System.OS_Lib is
    pragma Elaborate_Body (OS_Lib);
 
+   pragma Preelaborate;
+
    -----------------------
    -- String Operations --
    -----------------------
Index: s-fileio.adb
===================================================================
--- s-fileio.adb	(revision 189366)
+++ s-fileio.adb	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 1992-2010, Free Software Foundation, Inc.         --
+--          Copyright (C) 1992-2012, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -98,14 +98,6 @@ 
      (C, text_translation_required, "__gnat_text_translation_required");
    --  If true, add appropriate suffix to control string for Open
 
-   function Get_Case_Sensitive return Integer;
-   pragma Import (C, Get_Case_Sensitive,
-                  "__gnat_get_file_names_case_sensitive");
-   File_Names_Case_Sensitive : constant Boolean := Get_Case_Sensitive /= 0;
-   --  Set to indicate whether the operating system convention is for file
-   --  names to be case sensitive (e.g., in Unix, set True), or non case
-   --  sensitive (e.g., in Windows, set False).
-
    -----------------------
    -- Local Subprograms --
    -----------------------
@@ -757,6 +749,17 @@ 
       pragma Import (C, Tmp_Name, "__gnat_tmp_name");
       --  Set buffer (a String address) with a temporary filename
 
+      function Get_Case_Sensitive return Integer;
+      pragma Import (C, Get_Case_Sensitive,
+                     "__gnat_get_file_names_case_sensitive");
+
+      File_Names_Case_Sensitive : constant Boolean := Get_Case_Sensitive /= 0;
+      --  Set to indicate whether the operating system convention is for file
+      --  names to be case sensitive (e.g., in Unix, set True), or not case
+      --  sensitive (e.g., in Windows, set False). Declared locally to avoid
+      --  breaking the Preelaborate rule that disallows function calls at the
+      --  library level.
+
       Stream : FILEs := C_Stream;
       --  Stream which we open in response to this request
 
Index: s-fileio.ads
===================================================================
--- s-fileio.ads	(revision 189366)
+++ s-fileio.ads	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                 S p e c                                  --
 --                                                                          --
---          Copyright (C) 1992-2009, Free Software Foundation, Inc.         --
+--          Copyright (C) 1992-2012, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -38,6 +38,8 @@ 
 
 package System.File_IO is
 
+   pragma Preelaborate;
+
    package FCB renames System.File_Control_Block;
    package ICS renames Interfaces.C_Streams;