comp.lang.ada
 help / color / mirror / Atom feed
From: Jeremiah <jeremiah.breeden@gmail.com>
Subject: Re: Trying to understand Ada.Finalization.Controlled assignment mechanics.
Date: Tue, 23 Sep 2014 09:08:37 -0700 (PDT)
Date: 2014-09-23T09:08:37-07:00	[thread overview]
Message-ID: <c00f67d3-3653-43c5-bdf3-c2140f8c5fd9@googlegroups.com> (raw)
In-Reply-To: <lvqhmp$rbc$1@dont-email.me>

On Monday, September 22, 2014 9:17:18 PM UTC-4, Jeffrey Carter wrote:
> On 09/22/2014 05:43 PM, Jeremiah wrote:
> 
> >    tester : test_class2.test := test_class2.Make(new Integer'(45));
> 
> >
> 
> > The output I am seeing doesn't make sense to me:
> 
> > Adjusting
> 
> > Finalizing  (FREED)
> 
> > Adjusting
> 
> > Finalizing
> 
> > Hello World
> 
> > Finalizing
> 
> 
> 
> Your test example is complicated by the use of the function and the aggregate
> 
> inside it.  Someone with a better understanding of GNAT's handling of controlled
> 
> objects should probably comment on this. But it might be a good idea to start
> 
> with a simpler test case, involving no initialization, functions, aggregates, or
> 
> access types, and then complicate it step by step.
> 
> 
> 
> ARM 7.6(17.1/3) says
> 
> 
> 
> 'When a function call or aggregate is used to initialize an object, the result
> 
> of the function call or aggregate is an anonymous object, which is assigned into
> 
> the newly-created object.'
> 
> 
> 
> My guess is that there are both an aggregate object and function return object.
> 
> The aggregate object is copied into the function return object (FRO), the FRO is
> 
> adjusted, and the aggregate object is finalized. The the FRO is copied into
> 
> Tester, Tester is adjusted, and the FRO is finalized. The body of the main
> 
> procedure is then executed, and Tester is finalized. But I could be way off.
> 
> 
> 
> http://www.adaic.org/resources/add_content/standards/12rm/html/RM-7-6.html
> 

It does complicate things, and in the simpler case (using a Set procedure), it does highlight a misunderstanding of mine.  I incorrectly assumed Adjust would occur on B, when based on your response and rereading the RM section a few times, Adjust occurs on A instead.  

Am I understanding that correctly?  If so, then this would explain what I am seeing as I am setting the target to null and not nulling the previous object (which is the reverse of what I previously understood).

TLDR version (barring the actual complexities you noted above):
I previously thought:
A := B
Finalize(A)
copying B into A
Adjust(B)

But in reality it is closer to:
Finalize(A)
copying B into A
Adjust(A)

Again, not taking into account the complexities of FRO's and Anonymous Objects.


  reply	other threads:[~2014-09-23 16:08 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-23  0:43 Trying to understand Ada.Finalization.Controlled assignment mechanics Jeremiah
2014-09-23  1:17 ` Jeffrey Carter
2014-09-23 16:08   ` Jeremiah [this message]
2014-09-23 16:23     ` Adam Beneschan
2014-09-23 17:39       ` Simon Wright
2014-09-23 17:50     ` Jeffrey Carter
2014-09-23 19:19     ` Robert A Duff
2014-09-23 21:59       ` Jeremiah
2014-09-24 10:59         ` AdaMagica
replies disabled

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