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.5.137 with SMTP id 131mr23927048iof.117.1511812437089; Mon, 27 Nov 2017 11:53:57 -0800 (PST) X-Received: by 10.157.95.5 with SMTP id f5mr1695173oti.9.1511812437000; Mon, 27 Nov 2017 11:53:57 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!border1.nntp.ams1.giganews.com!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!newspeer1.nac.net!border2.nntp.dca1.giganews.com!nntp.giganews.com!i6no7673520itb.0!news-out.google.com!193ni4838iti.0!nntp.google.com!i6no7673519itb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 27 Nov 2017 11:53:56 -0800 (PST) In-Reply-To: <2240ea85-c247-4097-9877-24ce32a47123@googlegroups.com> 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> <2240ea85-c247-4097-9877-24ce32a47123@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <42736373-423a-42fb-8294-8a22fdb01e41@googlegroups.com> Subject: Re: Extending a third party tagged type while adding finalization From: Jere Injection-Date: Mon, 27 Nov 2017 19:53:57 +0000 Content-Type: text/plain; charset="UTF-8" X-Original-Bytes: 7312 Xref: reader02.eternal-september.org comp.lang.ada:49194 Date: 2017-11-27T11:53:56-08:00 List-Id: On Monday, November 27, 2017 at 1:37:22 PM UTC-5, AdaMagica wrote: > Am Montag, 27. November 2017 17:38:02 UTC+1 schrieb Jere: > > On Monday, November 27, 2017 at 10:00:11 AM UTC-5, AdaMagica wrote: > > 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: > > procedure Main is > > generic > > > > type Uncontrolled (<>) is abstract tagged private; > > > > with procedure Adjust (Object: in out Uncontrolled); > > with procedure Finalize (Object: in out Uncontrolled); > > The problem is in your generic parameter part. See section 3 of my paper and download the full code (see the end of the paper). > > It's really a problem that opens the gates of hell as I've written as an intro. > It can definitly only work for limited types. Sorry about that. I copied it from your paper (and changed some names) but I think I copied from the wrong place. I downloaded code, added controlled components to both Parent and Final. I saw the same results (out of order initialization and finalization). I don't know how you feel about reposting your copyrighted code so here is a handmade main linking to your code to show what I mean: ****************************************** with Ada.Text_IO; use Ada.Text_IO; with Add_Finalization.To_Limited_Uncontrolled; with Ada.Finalization; procedure Main is -- Just some controlled components to add later package Components is type C1 is new Ada.Finalization.Limited_Controlled with null record; overriding procedure Initialize(Self : in out C1); overriding procedure Finalize (Self : in out C1); type C2 is new Ada.Finalization.Limited_Controlled with null record; overriding procedure Initialize(Self : in out C2); overriding procedure Finalize (Self : in out C2); end Components; package body Components is overriding procedure Initialize(Self : in out C1) is begin Put_Line("Initialize C1"); end Initialize; overriding procedure Finalize (Self : in out C1) is begin Put_Line("Finalize C1"); end Finalize; overriding procedure Initialize(Self : in out C2) is begin Put_Line("Initialize C2"); end Initialize; overriding procedure Finalize (Self : in out C2) is begin Put_Line("Finalize C2"); end Finalize; end Components; package Types is type Base is tagged limited record c1 : Components.C1; end record; type Derived is new Base with null record; procedure Initialize(Self : in out Derived); procedure Finalize (Self : in out Derived); procedure Initialize_Redipatch(Self : in out Derived'Class); procedure Finalize_Redipatch(Self : in out Derived'Class); package To_LC is new Add_Finalization.To_Limited_Uncontrolled (Derived, Initialize_Redipatch, Finalize_Redipatch); type Final is new To_LC.Controlled with record c2 : Components.C2; end record; overriding procedure Initialize(Self : in out Final); overriding procedure Finalize (Self : in out Final); end Types; package body Types is procedure Initialize_Redipatch(Self : in out Derived'Class) is begin Self.Initialize; end Initialize_Redipatch; procedure Finalize_Redipatch(Self : in out Derived'Class) is begin Self.Finalize; end Finalize_Redipatch; procedure Initialize(Self : in out Derived) is begin Put_Line("Initialize Derived"); end Initialize; procedure Finalize (Self : in out Derived) is begin Put_Line("Finalize Derived"); end Finalize; procedure Initialize(Self : in out Final) is begin Put_Line("Initialize Final"); end Initialize; 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; ****************************************** The output for this is: Initialize C1 Initialize Final Initialize C2 Starting Finalize C2 Finalize Final Finalize C1 which is the same thing I was seeing with my version. Final is initialized before C2 and C2 is finalized before Final. I can repost the modified version of your code if this isn't sufficient to show the issue. I just wasn't sure if I should. The output from the modified copy of your code: Initialize C1 Final: I am being initialized 4 Derived: I am being initialized 2147483647 Initialize C2 Global Final: I am 100 Derived: I am 2147483647 Parent: I am-2147483648 Initialize C1 Final: I am being initialized 4 Derived: I am being initialized 2147483647 Initialize C2 Local Final: I am 52 Derived: I am 51 Parent: I am 50 Local out of scope Finalize C2 Final: I am being finalized. Final: I am 52 Derived: I am 51 Parent: I am 50 Derived: I am being finalized 51 Derived: I have been finalized 0 Final: I am 0 Derived: I am 0 Parent: I am 0 Final: I have been finalized. Finalize C1 Global Final: I am 100 Derived: I am 2147483647 Parent: I am-2147483648 Global out of scope Finalize C2 Final: I am being finalized. Final: I am 100 Derived: I am 2147483647 Parent: I am-2147483648 Derived: I am being finalized 2147483647 Derived: I have been finalized 0 Final: I am 0 Derived: I am 0 Parent: I am 0 Final: I have been finalized. Finalize C1