comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Enforcing initialization protocol for protected type
Date: Fri, 11 Sep 2009 18:27:38 +0200
Date: 2009-09-11T18:27:38+02:00	[thread overview]
Message-ID: <1rusjydws2ko.rpfwzoyv4bzj$.dlg@40tude.net> (raw)
In-Reply-To: 61284459-5a02-410a-8ffc-76ad4256f138@a7g2000yqo.googlegroups.com

On Fri, 11 Sep 2009 08:25:56 -0700 (PDT), AdaMagica wrote:

> On 11 Sep., 11:03, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
> wrote:
>> On Thu, 10 Sep 2009 22:01:17 -0700 (PDT), AdaMagica wrote:
>>> On 7 Sep., 22:19, Maciej Sobczak <see.my.homep...@gmail.com> wrote:
>>>> This, however, opens another question: controlled finalization of
>>>> protected types to release the state object, if it was allocated
>>>> dynamically. Oops.
>>
>>> Use an access discriminant of an anonymous type and you will get a
>>> coextension that is reclaimed automatically when the object goes out
>>> of scope, see RM 3.10(14.3/2,14.4/2) [or in the newest draft of the
>>> Amendment 2, (14.1/3,14.4/3), which is a bit clearer].
>>
>>> See also RM 3.7(1.c/2..1.e/2).
>>
>> Hmm, what do you mean by that? When the discriminant's type is an anonymous
>> access it is still declared at the declaration point of the type. It is not
>> the declaration point of an object. So if the discriminant is obtained by
>> the allocator new it will not be destroyed when the object leaves the
>> scope. It will when the type does. If these scopes are different, the
>> compiler will complain that the type in the allocator has a deeper level.
> 
> type Disc is ...
> 
> type Rec (D: access Disc) is record ...
> 
> Obj: Rec (new Disc);
> 
> The discriminant (a coextension of the object) will be deallocated
> when Obj goes out of scope.

OK I see. Anyway I would not use this design pattern because it would be a
source of countless errors very difficult to track down.

P.S. It looks like a language design bug. If allowed then at least it
should have been like:

   Obj: subtype Rec (new Disc);
      -- An anonymous subtype is declared for Obj

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2009-09-11 16:27 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-07 15:15 Enforcing initialization protocol for protected type Maciej Sobczak
2009-09-07 17:01 ` Georg Bauhaus
2009-09-07 20:19   ` Maciej Sobczak
2009-09-10 17:07     ` Georg Bauhaus
2009-09-11  5:01     ` AdaMagica
2009-09-11  9:03       ` Dmitry A. Kazakov
2009-09-11 15:25         ` AdaMagica
2009-09-11 16:27           ` Dmitry A. Kazakov [this message]
2009-09-11 22:24             ` Randy Brukardt
2009-09-12  8:44               ` Dmitry A. Kazakov
2009-09-10 16:39 ` Per Sandberg
2009-09-14 21:15   ` Adam Beneschan
2009-09-15  0:27     ` 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