comp.lang.ada
 help / color / mirror / Atom feed
From: Jere <jhb.chat@gmail.com>
Subject: Re: Extending a third party tagged type while adding finalization
Date: Mon, 27 Nov 2017 11:53:56 -0800 (PST)
Date: 2017-11-27T11:53:56-08:00	[thread overview]
Message-ID: <42736373-423a-42fb-8294-8a22fdb01e41@googlegroups.com> (raw)
In-Reply-To: <2240ea85-c247-4097-9877-24ce32a47123@googlegroups.com>

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


  reply	other threads:[~2017-11-27 19:53 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-22 12:43 Extending a third party tagged type while adding finalization Jere
2017-11-22 16:42 ` AdaMagica
2017-11-26 17:33   ` Jere
2017-11-26 18:15     ` Dmitry A. Kazakov
2017-11-26 19:31       ` Jere
2017-11-27  9:46     ` AdaMagica
2017-11-27 12:56       ` Jere
2017-11-27 15:00         ` AdaMagica
2017-11-27 16:38           ` Jere
2017-11-27 18:37             ` AdaMagica
2017-11-27 19:53               ` Jere [this message]
2017-11-28 11:48                 ` AdaMagica
2017-12-03  2:22                   ` Jere
2017-12-03 21:53               ` Robert Eachus
2017-12-04  7:58                 ` Dmitry A. Kazakov
2017-12-04 14:59                   ` Robert Eachus
2017-12-04 15:39                     ` Dmitry A. Kazakov
2017-11-27 18:10     ` Shark8
2017-11-27 19:56       ` Jere
2017-11-28  1:55       ` Randy Brukardt
2017-12-03  2:47         ` Jere
2017-12-03  9:29           ` Dmitry A. Kazakov
2017-12-03 15:10             ` AdaMagica
2017-12-03 16:39               ` Dmitry A. Kazakov
2017-12-03 19:34             ` AdaMagica
2017-12-03 19:41               ` Dmitry A. Kazakov
2017-12-04 12:38                 ` AdaMagica
2017-12-04 13:19                   ` AdaMagica
2017-12-04 13:55                     ` Dmitry A. Kazakov
2017-12-04 15:44                       ` AdaMagica
2017-12-04 16:19                         ` Dmitry A. Kazakov
2017-12-04 20:54           ` Randy Brukardt
2017-12-04 21:02             ` Dmitry A. Kazakov
2017-12-05 21:09               ` Randy Brukardt
2017-12-05 21:29                 ` Dmitry A. Kazakov
2017-12-07  1:13                   ` Randy Brukardt
2017-12-07  8:36                     ` Dmitry A. Kazakov
2017-12-07 23:22                       ` Randy Brukardt
2017-12-08  9:30                         ` Dmitry A. Kazakov
2017-12-09  0:17                           ` Randy Brukardt
2017-12-11  9:03                             ` Dmitry A. Kazakov
2017-12-11 22:42                               ` Randy Brukardt
2017-12-12 16:11                                 ` AdaMagica
2017-12-12 20:08                               ` G. B.
2017-12-12 20:32                                 ` Dmitry A. Kazakov
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox