-- --
-- S p e c --
-- --
--- --
--- Copyright (C) 1992-1998 Free Software Foundation, Inc. --
+-- Copyright (C) 1992-2006 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- --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING. If not, write --
--- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
--- MA 02111-1307, USA. --
+-- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
+-- Boston, MA 02110-1301, USA. --
-- --
-- As a special exception, if other files instantiate generics from this --
-- unit, or you link this unit with other files to produce an executable, --
-- --
------------------------------------------------------------------------------
+with Ada.Unchecked_Conversion;
+
+with System.Storage_Elements;
with System.Finalization_Root;
package System.Finalization_Implementation is
-pragma Elaborate_Body (Finalization_Implementation);
+ pragma Elaborate_Body;
- package SFR renames System.Finalization_Root;
+ package SSE renames System.Storage_Elements;
+ package SFR renames System.Finalization_Root;
------------------------------------------------
-- Finalization Management Abstract Interface --
------------------------------------------------
+ function To_Finalizable_Ptr is new Ada.Unchecked_Conversion
+ (Source => System.Address, Target => SFR.Finalizable_Ptr);
+
+ Collection_Finalization_Started : constant SFR.Finalizable_Ptr :=
+ To_Finalizable_Ptr (SSE.To_Address (1));
+ -- This is used to implement the rule in RM-4.8(10.2/2) that requires an
+ -- allocator to raise Program_Error if the collection finalization has
+ -- already started. See also Ada.Finalization.List_Controller. Finalize on
+ -- List_Controller first sets the list to Collection_Finalization_Started,
+ -- to indicate that finalization has started. An allocator will call
+ -- Attach_To_Final_List, which checks for the special value and raises
+ -- Program_Error if appropriate. The value of
+ -- Collection_Finalization_Started must be different from 'Access of any
+ -- finalizable object, and different from null. See AI-280.
+
Global_Final_List : SFR.Finalizable_Ptr;
-- This list stores the controlled objects defined in library-level
-- packages. They will be finalized after the main program completion.
-- attachement, 1 for simple linked lists or 2 for doubly linked lists
-- or even 3 for a simple attachement of a whole array of elements.
-- Attachement to a simply linked list is not protected against
- -- concurrent access and should only be used in context where it
+ -- concurrent access and should only be used in contexts where it
-- doesn't matter, such as for objects allocated on the stack. In the
-- case of an attachment on a doubly linked list, L must not be null
-- and Obj will be inserted AFTER the first element and the attachment
(L : in out SFR.Finalizable_Ptr;
A : System.Address;
B : Short_Short_Integer);
- -- Generic initialize for tagged objects with controlled components. A
- -- is the address of the object, L the finalization list when it needs
- -- to be attached and B the attachement level (see Attach_To_Final_List)
+ -- Generic initialize for tagged objects with controlled components.
+ -- A is the address of the object, L the finalization list when it needs
+ -- to be attached and B the attachement level (see Attach_To_Final_List).
procedure Deep_Tag_Adjust
(L : in out SFR.Finalizable_Ptr;
A : System.Address;
B : Short_Short_Integer);
- -- Generic adjust for tagged objects with controlled components. A
- -- is the address of the object, L the finalization list when it needs
- -- to be attached and B the attachement level (see Attach_To_Final_List)
+ -- Generic adjust for tagged objects with controlled components.
+ -- A is the address of the object, L the finalization list when it needs
+ -- to be attached and B the attachement level (see Attach_To_Final_List).
procedure Deep_Tag_Finalize
(L : in out SFR.Finalizable_Ptr;
A : System.Address;
B : Boolean);
- -- Generic finalize for tagged objects with controlled components. A
- -- is the address of the object, L the finalization list when it needs
- -- to be attached and B the attachement level (see Attach_To_Final_List)
+ -- Generic finalize for tagged objects with controlled components.
+ -- A is the address of the object, L the finalization list when it needs
+ -- to be attached and B the attachement level (see Attach_To_Final_List).
procedure Deep_Tag_Attach
(L : in out SFR.Finalizable_Ptr;
A : System.Address;
B : Short_Short_Integer);
- -- Generic attachement for tagged objects with controlled components. A
- -- is the address of the object, L the finalization list when it needs
- -- to be attached and B the attachement level (see Attach_To_Final_List)
+ -- Generic attachement for tagged objects with controlled components.
+ -- A is the address of the object, L the finalization list when it needs
+ -- to be attached and B the attachement level (see Attach_To_Final_List).
-----------------------------
-- Record Controller Types --
-- Definition of the types of the controller component that is included
-- in records containing controlled components. This controller is
-- attached to the finalization chain of the upper-level and carries
- -- the pointer of the finalization chain for the lower level
+ -- the pointer of the finalization chain for the lower level.
type Limited_Record_Controller is new SFR.Root_Controlled with record
F : SFR.Finalizable_Ptr;
end record;
procedure Initialize (Object : in out Limited_Record_Controller);
- -- Does nothing
+ -- Does nothing.
procedure Finalize (Object : in out Limited_Record_Controller);
-- Finalize the controlled components of the enclosing record by
- -- following the list starting at Object.F
+ -- following the list starting at Object.F.
type Record_Controller is
new Limited_Record_Controller with record
procedure Adjust (Object : in out Record_Controller);
-- Adjust the components and their finalization pointers by subtracting
- -- by the offset of the target and the source addresses of the assignment
+ -- by the offset of the target and the source addresses of the assignment.
-- Inherit Finalize from Limited_Record_Controller
procedure Detach_From_Final_List (Obj : in out SFR.Finalizable);
- -- Remove the specified object from its Final list which must be a
+ -- Remove the specified object from its Final list, which must be a
-- doubly linked list.
end System.Finalization_Implementation;