]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
make.adb (Add_Switch): Make Generic_Position a procedure.
authorFlorian Weimer <fw@deneb.enyo.de>
Sat, 22 Dec 2001 11:58:51 +0000 (12:58 +0100)
committerFlorian Weimer <fw@gcc.gnu.org>
Sat, 22 Dec 2001 11:58:51 +0000 (12:58 +0100)
* make.adb (Add_Switch): Make Generic_Position a procedure.  The
function approach did not work well because of a side effect (the
function call could reallocate the table which was being indexed
using its result). Fixes ada/4851.

From-SVN: r48265

gcc/ada/ChangeLog
gcc/ada/make.adb

index 6b0289bbb3e44789e49b3ba89597df55e18dadd3..52841cf49ffc0dd62fb0b5abf70b7ea81e5af0c4 100644 (file)
@@ -1,3 +1,10 @@
+2001-12-22  Florian Weimer  <fw@deneb.enyo.de>
+
+       * make.adb (Add_Switch): Make Generic_Position a procedure.  The
+       function approach did not work well because of a side effect (the
+       function call could reallocate the table which was being indexed
+       using its result). Fixes ada/4851.
+
 2001-12-19  Robert Dewar <dewar@gnat.com>
 
        * bindgen.adb: Minor reformatting
index 6b61456aa3334bb2aae8b6f1074271d2736e3847..500caf8a6e12ba1821e7def568c2d34dcd8e852d 100644 (file)
@@ -6,7 +6,7 @@
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---                            $Revision$
+--                            $Revision: 1.9 $
 --                                                                          --
 --          Copyright (C) 1992-2001 Free Software Foundation, Inc.          --
 --                                                                          --
@@ -554,55 +554,60 @@ package body Make is
    is
       generic
          with package T is new Table.Table (<>);
-      function Generic_Position return Integer;
-      --  Generic procedure that adds S at the end or beginning of T depending
-      --  of the value of the boolean Append_Switch.
+      procedure Generic_Position (New_Position : out Integer);
+      --  Generic procedure that allocates a position for S in T at the
+      --  beginning or the end, depending on the boolean Append_Switch.
 
       ----------------------
       -- Generic_Position --
       ----------------------
 
-      function Generic_Position return Integer is
+      procedure  Generic_Position (New_Position : out Integer) is
       begin
          T.Increment_Last;
 
          if Append_Switch then
-            return Integer (T.Last);
+            New_Position := Integer (T.Last);
          else
             for J in reverse T.Table_Index_Type'Succ (T.First) .. T.Last loop
                T.Table (J) := T.Table (T.Table_Index_Type'Pred (J));
             end loop;
 
-            return Integer (T.First);
+            New_Position := Integer (T.First);
          end if;
       end Generic_Position;
 
-      function Gcc_Switches_Pos    is new Generic_Position (Gcc_Switches);
-      function Binder_Switches_Pos is new Generic_Position (Binder_Switches);
-      function Linker_Switches_Pos is new Generic_Position (Linker_Switches);
+      procedure Gcc_Switches_Pos    is new Generic_Position (Gcc_Switches);
+      procedure Binder_Switches_Pos is new Generic_Position (Binder_Switches);
+      procedure Linker_Switches_Pos is new Generic_Position (Linker_Switches);
 
-      function Saved_Gcc_Switches_Pos is new
+      procedure Saved_Gcc_Switches_Pos is new
         Generic_Position (Saved_Gcc_Switches);
 
-      function Saved_Binder_Switches_Pos is new
+      procedure Saved_Binder_Switches_Pos is new
         Generic_Position (Saved_Binder_Switches);
 
-      function Saved_Linker_Switches_Pos is new
+      procedure Saved_Linker_Switches_Pos is new
         Generic_Position (Saved_Linker_Switches);
 
+      New_Position : Integer;
+
    --  Start of processing for Add_Switch
 
    begin
       if And_Save then
          case Program is
             when Compiler =>
-               Saved_Gcc_Switches.Table (Saved_Gcc_Switches_Pos) := S;
+               Saved_Gcc_Switches_Pos (New_Position);
+               Saved_Gcc_Switches.Table (New_Position) := S;
 
             when Binder   =>
-               Saved_Binder_Switches.Table (Saved_Binder_Switches_Pos) := S;
+               Saved_Binder_Switches_Pos (New_Position);
+               Saved_Binder_Switches.Table (New_Position) := S;
 
             when Linker   =>
-               Saved_Linker_Switches.Table (Saved_Linker_Switches_Pos) := S;
+               Saved_Linker_Switches_Pos (New_Position);
+               Saved_Linker_Switches.Table (New_Position) := S;
 
             when None =>
                raise Program_Error;
@@ -611,13 +616,16 @@ package body Make is
       else
          case Program is
             when Compiler =>
-               Gcc_Switches.Table (Gcc_Switches_Pos) := S;
+               Gcc_Switches_Pos (New_Position);
+               Gcc_Switches.Table (New_Position) := S;
 
             when Binder   =>
-               Binder_Switches.Table (Binder_Switches_Pos) := S;
+               Binder_Switches_Pos (New_Position);
+               Binder_Switches.Table (New_Position) := S;
 
             when Linker   =>
-               Linker_Switches.Table (Linker_Switches_Pos) := S;
+               Linker_Switches_Pos (New_Position);
+               Linker_Switches.Table (New_Position) := S;
 
             when None =>
                raise Program_Error;