comp.lang.ada
 help / color / mirror / Atom feed
From: ytomino <aghia05@gmail.com>
Subject: Re: Question about library-level functions
Date: Sat, 15 Dec 2012 02:50:21 -0800 (PST)
Date: 2012-12-15T02:50:21-08:00	[thread overview]
Message-ID: <565c0f25-e620-4875-9248-2371a874d345@googlegroups.com> (raw)
In-Reply-To: <7ad8ab3a-2a17-44d0-a64f-4cfb1288dc1c@googlegroups.com>

On Saturday, December 15, 2012 6:47:10 PM UTC+9, AdaMagica wrote:

> I guess that, since P is unused, the compiler optimizes the sequence of calls 
> and finalizes P first. 

hurm...So, I tried to change it to do explicit free P.

---- %< ----

with Ada.Text_IO;
with Ada.Unchecked_Deallocation;
with lifetime;
with alloc;
procedure main is
begin
   Ada.Text_IO.Put_Line ("before");
   declare
      type A is access all lifetime.T;
      procedure Free is new Ada.Unchecked_Deallocation (lifetime.T, A);
      P : A := A(alloc);
   begin
      Ada.Text_IO.Put_Line ("lifetime");
      Free (P);
   end;
   Ada.Text_IO.Put_Line ("after");
end main;

---- %> ----

As a result, lifetime.Finalize was called twice.

% ./main
before
Initialize (0000000100100090)
Finalize (0000000100100090)
lifetime
Finalize (0000000100100090)
after

> Finalize may not be called in Alloc,  

Surely, lifetime.Finalize may be called in 'Alloc'.
The backtrace of gdb is:

#0  lifetime__finalize__2 (object=) at lifetime.adb:7
#1  0x0000000100001a9c in lifetime__tFD () at lifetime.adb:4
#2  0x000000010000da39 in system__finalization_masters__finalize (master=) at s-finmas.adb:241
#3  0x00000001000026d8 in _ada_alloc () at alloc.adb:5
#4  0x00000001000028f2 in _ada_main () at main.adb:11

> since the object must be created in place
> (it's limited - there cannot be an intermediate object as in the unlimited 
> case). 

lifetime.T is limited. However, an access value of it is not limited.

Perhaps AARM 7.6.1 says the anonymous access type belongs to innermost master.
The master is usually in the package and lets objects live long time.
I imagine, if a function is library-level, there is no place which it puts the master, so the master is inside of the function...???



  reply	other threads:[~2012-12-15 10:50 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-15  3:38 Question about library-level functions ytomino
2012-12-15  9:47 ` AdaMagica
2012-12-15 10:50   ` ytomino [this message]
2012-12-15 11:38     ` AdaMagica
2012-12-17 19:49       ` Adam Beneschan
2012-12-18  2:26         ` ytomino
2012-12-15 15:23 ` sbelmont700
2012-12-16  6:09   ` ytomino
2012-12-16  9:43 ` Simon Wright
2012-12-16 10:21   ` AdaMagica
2012-12-16 13:07     ` ytomino
2012-12-16 18:31     ` Simon Wright
2012-12-18  3:18       ` ytomino
2012-12-18  0:07     ` Randy Brukardt
2012-12-16 13:34   ` ytomino
2012-12-16 15:54     ` AdaMagica
2012-12-18  0:09       ` Randy Brukardt
replies disabled

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