From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.107.183.193 with SMTP id h184mr23414572iof.129.1511800680752; Mon, 27 Nov 2017 08:38:00 -0800 (PST) X-Received: by 10.157.14.137 with SMTP id 9mr309907otj.14.1511800680674; Mon, 27 Nov 2017 08:38:00 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!border1.nntp.ams1.giganews.com!nntp.giganews.com!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.am4!peer.am4.highwinds-media.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!193no1130231itr.0!news-out.google.com!x87ni5406ita.0!nntp.google.com!i6no7538848itb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 27 Nov 2017 08:38:00 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=173.71.208.22; posting-account=QF6XPQoAAABce2NyPxxDAaKdAkN6RgAf NNTP-Posting-Host: 173.71.208.22 References: <4db43571-7f86-4e73-8849-c41160927703@googlegroups.com> <6496a10f-c97e-4e42-b295-2478ad464b2f@googlegroups.com> <6106dfe6-c614-4fc1-aace-74bf8d7435e3@googlegroups.com> <102d4df8-d392-4100-9a37-c49705397e4e@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Extending a third party tagged type while adding finalization From: Jere Injection-Date: Mon, 27 Nov 2017 16:38:00 +0000 Content-Type: text/plain; charset="UTF-8" X-Received-Body-CRC: 3135232884 X-Received-Bytes: 6271 Xref: reader02.eternal-september.org comp.lang.ada:49189 Date: 2017-11-27T08:38:00-08:00 List-Id: On Monday, November 27, 2017 at 10:00:11 AM UTC-5, AdaMagica wrote: > Am Montag, 27. November 2017 13:56:36 UTC+1 schrieb Jere: > > The intent was to be able to provide "overridable" Initialize > > and Finalize to descendants of the mixin which would be called > > automatically, but now I don't think that is possible in a safe way. > > Why do you say this? In my paper, Final is a further derivation, and also derivations from Final will work as expected. well, when I tried your example it didn't call the finalization routing for any derived types. I might have mis-copied it somehow. Here is a compilable example: ************************************************************** with Ada.Text_IO; use Ada.Text_IO; with Ada.Finalization; with Ada.Task_Attributes; procedure Main is generic type Uncontrolled (<>) is abstract tagged private; with procedure Adjust (Object: in out Uncontrolled); with procedure Finalize (Object: in out Uncontrolled); package To_Controlled is type Controlled is new Uncontrolled with private; private type Controlled_Ptr is access all Controlled; type Component is new Ada.Finalization.Controlled with record Parent: Controlled_Ptr; end record; type Controlled is new Uncontrolled with record Controller: Component := (Ada.Finalization.Controlled with Controlled'Unrestricted_Access); -- Gnat only end record; procedure Adjust (Object: in out Component); procedure Finalize (Object: in out Component); end To_Controlled; package body To_Controlled is package Store is new Ada.Task_Attributes (Attribute => Controlled_Ptr, Initial_Value => null); procedure Adjust (Object: in out Component) is begin Object.Parent := Store.Value; Adjust (Uncontrolled (Object.Parent.all)); end Adjust; procedure Finalize (Object: in out Component) is begin Store.Set_Value (Object.Parent); Finalize (Uncontrolled (Object.Parent.all)); end Finalize; end To_Controlled; package Components is type C1 is new Ada.Finalization.Controlled with null record; overriding procedure Adjust (Self : in out C1); overriding procedure Finalize (Self : in out C1); type C2 is new Ada.Finalization.Controlled with null record; overriding procedure Adjust (Self : in out C2); overriding procedure Finalize (Self : in out C2); end Components; package body Components is overriding procedure Adjust (Self : in out C1) is begin Put_Line("Adjust C1"); end Adjust; overriding procedure Finalize (Self : in out C1) is begin Put_Line("Finalize C1"); end Finalize; overriding procedure Adjust (Self : in out C2) is begin Put_Line("Adjust C2"); end Adjust; overriding procedure Finalize (Self : in out C2) is begin Put_Line("Finalize C2"); end Finalize; end Components; package Types is type Base is tagged record c1 : Components.C1; end record; type Derived is new Base with null record; procedure Adjust (Self : in out Derived); procedure Finalize (Self : in out Derived); package To_C is new To_Controlled (Derived, Adjust, Finalize); type Final is new To_C.Controlled with record c2 : Components.C2; end record; overriding procedure Adjust (Self : in out Final); overriding procedure Finalize (Self : in out Final); end Types; package body Types is procedure Adjust (Self : in out Derived) is begin Put_Line("Adjust Derived"); end Adjust; procedure Finalize (Self : in out Derived) is begin Put_Line("Finalize Derived"); end Finalize; procedure Adjust (Self : in out Final) is begin Put_Line("Adjust Final"); end Adjust; procedure Finalize (Self : in out Final) is begin Put_Line("Finalize Final"); end Finalize; end Types; v : Types.Final; begin Put_Line ("Starting"); end Main; ************************************************************** with this the output is: Starting Finalize C2 Finalize Derived Finalize C1 There is no "Finalize Final" as expected from inheritance Did I put something in wrong?