Index: src/natools-references.adb ================================================================== --- src/natools-references.adb +++ src/natools-references.adb @@ -1,7 +1,7 @@ ------------------------------------------------------------------------------ --- Copyright (c) 2013, Natacha Porté -- +-- Copyright (c) 2013-2014, Natacha Porté -- -- -- -- Permission to use, copy, modify, and distribute this software for any -- -- purpose with or without fee is hereby granted, provided that the above -- -- copyright notice and this permission notice appear in all copies. -- -- -- @@ -73,27 +73,32 @@ Ref.Data := new Held_Data'(Constructor.all); Ref.Count := new Counter'(1); end Replace; - function Create - (Constructor : not null access function return Data_Access) - return Immutable_Reference is + function Create (Data : in Data_Access) return Immutable_Reference is begin - return (Ada.Finalization.Controlled with - Data => Constructor.all, - Count => new Counter'(1)); + if Data = null then + return Null_Immutable_Reference; + else + return (Ada.Finalization.Controlled with + Data => Data, + Count => new Counter'(1)); + end if; end Create; procedure Replace (Ref : in out Immutable_Reference; - Constructor : not null access function return Data_Access) is + Data : in Data_Access) is begin Finalize (Ref); - Ref.Data := Constructor.all; - Ref.Count := new Counter'(1); + + if Data /= null then + Ref.Data := Data; + Ref.Count := new Counter'(1); + end if; end Replace; procedure Reset (Ref : in out Immutable_Reference) is begin Index: src/natools-references.ads ================================================================== --- src/natools-references.ads +++ src/natools-references.ads @@ -1,7 +1,7 @@ ------------------------------------------------------------------------------ --- Copyright (c) 2013, Natacha Porté -- +-- Copyright (c) 2013-2014, Natacha Porté -- -- -- -- Permission to use, copy, modify, and distribute this software for any -- -- purpose with or without fee is hereby granted, provided that the above -- -- copyright notice and this permission notice appear in all copies. -- -- -- @@ -52,19 +52,19 @@ procedure Replace (Ref : in out Immutable_Reference; Constructor : not null access function return Held_Data); -- Replace the object held in Ref with a newly created object - function Create - (Constructor : not null access function return Data_Access) - return Immutable_Reference; - -- Create a new held object and return a reference to it - - procedure Replace - (Ref : in out Immutable_Reference; - Constructor : not null access function return Data_Access); - -- Replace the object held in Ref with a newly created object + function Create (Data : in Data_Access) return Immutable_Reference; + -- Create a new reference from Data. + -- From this point the referred object is owned by this + -- package and must NOT be freed or changed or accessed. + + procedure Replace (Ref : in out Immutable_Reference; Data : in Data_Access); + -- Integrate Data into Ref. + -- From this point the referred object is owned by this + -- package and must NOT be freed or changed or accessed. procedure Reset (Ref : in out Immutable_Reference); -- Empty Ref function Is_Empty (Ref : Immutable_Reference) return Boolean;