From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Weird controlled behavior - Gnat 3.15p NT
Date: Thu, 4 Sep 2003 23:04:34 -0500
Date: 2003-09-04T23:04:34-05:00 [thread overview]
Message-ID: <vlg2mqlnqqnm29@corp.supernews.com> (raw)
In-Reply-To: 3F57B071.5030206@attbi.com
"Robert I. Eachus" <rieachus@attbi.com> wrote in message
news:3F57B071.5030206@attbi.com...
> Jano wrote:
>
> > Now, I would assume that no Finalization could happen without a
> > corresponding Initialization, so is this normal? Is something wrong in
> > that read way?
>
> No object can be finalized that has not been initialized (or created as
> part of an assignment with adjust)...
No, that's not right either.
Finalizable objects can be "initialized" three ways:
-- Default initialization followed by a call to Initialize.
-- Explicit initialization followed by a call to Adjust.
-- Aggregate initialization.
Note that the latter doesn't call anything. Also note that an abstraction
can make the last illegal by declaring the type as a private type.
In this case, it looks like GNAT is assigning temporaries, so there is a bit
copy, followed by an Adjust call, and then a Finalize call for the
temporary. That accounts for the "extra" calls. For a non-limited controlled
type, you have to account for all three routines; they can get used
implicitly even if you never wrote any assignments.
Finally, Robert's basic point is correct: Finalize should always be designed
to be called "extra" times on an object. I usually use something like:
procedure Finalize (Obj : in out Object_Type) is
begin
if Obj.Inited then
-- Finalize code.
Obj.Inited := False;
-- else not Initialized or already Finalized.
end if;
end Finalize;
with Initialize setting the Initted flag. (Often, I use some data in the
record for this purpose, rather than a dedicated flag; such as an allocated
block of memory [if the pointer is null, the object is already Finalized].)
Randy.
next prev parent reply other threads:[~2003-09-05 4:04 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-09-04 15:25 Weird controlled behavior - Gnat 3.15p NT Jano
2003-09-04 15:40 ` Martin Krischik
2003-09-04 18:06 ` Patrice Freydiere
2003-09-04 19:03 ` Jano
2003-09-04 20:57 ` Jano
2003-09-05 8:48 ` Preben Randhol
2003-09-05 13:48 ` Jano
2003-09-04 21:36 ` Robert I. Eachus
2003-09-05 4:04 ` Randy Brukardt [this message]
2003-09-05 13:48 ` Jano
2003-09-05 14:33 ` Dmitry A. Kazakov
2003-09-09 2:01 ` Hyman Rosen
2003-09-09 7:02 ` Jean-Pierre Rosen
2003-09-11 3:40 ` Hyman Rosen
2003-09-09 8:22 ` Dmitry A. Kazakov
2003-09-11 3:46 ` Hyman Rosen
2003-09-11 8:23 ` Dmitry A. Kazakov
2003-09-05 7:10 ` Jean-Pierre Rosen
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox