comp.lang.ada
 help / color / mirror / Atom feed
From: Jeffrey Carter <spam@spam.com>
Subject: Re: Private area and child packages
Date: Thu, 30 Dec 2004 18:14:06 GMT
Date: 2004-12-30T18:14:06+00:00	[thread overview]
Message-ID: <OzXAd.12742$RH4.8419@newsread1.news.pas.earthlink.net> (raw)
In-Reply-To: <1104420708.559607.11230@z14g2000cwz.googlegroups.com>

danmcleran@hotmail.com wrote:

> What about using Ada's Limited_Controlled type? Then, since no copies
> could be made, I could do something like this:
> 
> with Ada.Finalization;
> 
> package Some_Package is
> type Secret_Type is tagged limited private;
> private
> type Implementation_Type;
> type Implementation_Access_Type is access Implementation_Type;
> type Secret_Type is new Ada.Finalization.Limited_Controlled with
> record
> Implementation_Access : Implementation_Access_Type := null;
> end record;   
> end Some_Package;

Don't forget to override Finalize.

This doesn't really do what you want, since a child can see and copy the 
access component:

package body Some_Package.Child is
    A : Implementation_Access_Type

    procedure Op (L : Secret_Type) is
       -- null;
    begin -- Op
       A := L.Implementation_Access;
    end Op;

    ...
end Some_Package.Child;

It's possible for the actual of L to go out of scope and be finalized, 
deallocating L.Implementation_Access, while A is still around, a 
dangling reference.

-- 
Jeff Carter
"Now look, Col. Batguano, if that really is your name."
Dr. Strangelove
31



  reply	other threads:[~2004-12-30 18:14 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-12-29  4:05 Private area and child packages danmcleran
2004-12-29  4:47 ` tmoran
2004-12-29 15:10   ` danmcleran
2004-12-30 18:51     ` tmoran
2005-01-01  3:45       ` danmcleran
2004-12-29  4:49 ` Jeffrey Carter
2004-12-29 15:27   ` danmcleran
2004-12-29 16:53     ` Samuel Tardieu
2004-12-30  4:07       ` Jeffrey Carter
2004-12-30 15:31   ` danmcleran
2004-12-30 18:14     ` Jeffrey Carter [this message]
2004-12-31 17:55   ` danmcleran
     [not found]   ` <1104515735.052116.248180@c13g2000cwb.googlegroups.com>
2004-12-31 19:02     ` Jeffrey Carter
2004-12-29 19:05 ` Martin Krischik
2004-12-29 21:44 ` Stephen Leake
replies disabled

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