From dbe0163146c0c078d39d586bc3ff14a767904c2d Mon Sep 17 00:00:00 2001 From: Ed Schonberg Date: Wed, 6 Aug 2008 10:32:32 +0200 Subject: [PATCH] g-awk.adb (Finalize): Do not use directly objects of the type in the finalization routine to prevent... 2008-08-06 Ed Schonberg * g-awk.adb (Finalize): Do not use directly objects of the type in the finalization routine to prevent elaboration order anomalies in new finalization scheme. From-SVN: r138772 --- gcc/ada/g-awk.adb | 79 +++++++++++++++++++++++++++++------------------ 1 file changed, 49 insertions(+), 30 deletions(-) diff --git a/gcc/ada/g-awk.adb b/gcc/ada/g-awk.adb index 57045bf5661c..0dee657b140f 100644 --- a/gcc/ada/g-awk.adb +++ b/gcc/ada/g-awk.adb @@ -6,7 +6,7 @@ -- -- -- B o d y -- -- -- --- Copyright (C) 2000-2007, AdaCore -- +-- Copyright (C) 2000-2008, 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,10 +36,6 @@ pragma Ada_95; -- Default_Session (see below) do not work when compiling clients of this -- package that instantiate generic units herein. -pragma Style_Checks (All_Checks); --- Turn off alpha ordering check for subprograms, since we cannot --- Put Finalize and Initialize in alpha order (see comments). - with Ada.Exceptions; with Ada.Text_IO; with Ada.Strings.Unbounded; @@ -56,6 +52,18 @@ package body GNAT.AWK is use Ada; use Ada.Strings.Unbounded; + ----------------------- + -- Local subprograms -- + ----------------------- + + -- The following two subprograms provide a functional interface to the + -- two special session variables, that are manipulated explicitly by + -- Finalize, but must be declared after Finalize to prevent static + -- elaboration warnings. + + function Get_Def return Session_Data_Access; + procedure Set_Cur; + ---------------- -- Split mode -- ---------------- @@ -277,6 +285,24 @@ package body GNAT.AWK is procedure Free is new Unchecked_Deallocation (Session_Data, Session_Data_Access); + -------------- + -- Finalize -- + -------------- + + procedure Finalize (Session : in out Session_Type) is + begin + -- We release the session data only if it is not the default session + + if Session.Data /= Get_Def then + Free (Session.Data); + + -- Since we have closed the current session, set it to point now to + -- the default session. + + Set_Cur; + end if; + end Finalize; + ---------------- -- Initialize -- ---------------- @@ -301,34 +327,9 @@ package body GNAT.AWK is -- Session Variables -- ----------------------- - -- These must come after the body of Initialize, since they make - -- implicit calls to Initialize at elaboration time. - Def_Session : Session_Type; Cur_Session : Session_Type; - -------------- - -- Finalize -- - -------------- - - -- Note: Finalize must come after Initialize and the definition - -- of the Def_Session and Cur_Session variables, since it references - -- the latter. - - procedure Finalize (Session : in out Session_Type) is - begin - -- We release the session data only if it is not the default session - - if Session.Data /= Def_Session.Data then - Free (Session.Data); - - -- Since we have closed the current session, set it to point now to - -- the default session. - - Cur_Session.Data := Def_Session.Data; - end if; - end Finalize; - ---------------------- -- Private Services -- ---------------------- @@ -1480,6 +1481,24 @@ package body GNAT.AWK is Split.Current_Line (Session.Data.Separators.all, Session); end Split_Line; + ------------- + -- Get_Def -- + ------------- + + function Get_Def return Session_Data_Access is + begin + return Def_Session.Data; + end Get_Def; + + ------------- + -- Set_Cur -- + ------------- + + procedure Set_Cur is + begin + Cur_Session.Data := Def_Session.Data; + end Set_Cur; + begin -- We have declared two sessions but both should share the same data. -- The current session must point to the default session as its initial -- 2.47.2