From: billwolf@hubcap.clemson.edu (William Thomas Wolfe,2847,)
Subject: Re: Destroy and Unchecked Deallocation (minor bug)
Date: 14 Dec 88 19:04:43 GMT [thread overview]
Message-ID: <3892@hubcap.UUCP> (raw)
In-Reply-To: 8812140455.AA16285@ajpo.sei.cmu.edu
From article <8812140455.AA16285@ajpo.sei.cmu.edu>, by TUFFS1@alcoa.com:
> generic
> type Object is limited private;
> type Name is access Object;
> with procedure Destroy(Y: in out Object) is <>;
> procedure Deallocate(X: in out Name);
>
> with Unchecked_Deallocation;
> procedure Deallocate(X: in out Name) is
> procedure Clean_Up is new Unchecked_Deallocation(Object, Name);
> begin
> Destroy(X.all);
> Clean_Up(X);
> end Deallocate;
Deallocate needs to be revised as follows:
begin
if (X /= null) then
Destroy (X.all); -- avoiding a CONSTRAINT_ERROR here...
Clean_Up (X);
end if;
end Deallocate;
Also, it's probably safer to revise the spec of the ADT to read:
type POINTER_TO_ADT is access ADT;
procedure DESTROY (TARGETED_OBJECT : in out POINTER_TO_ADT);
-- This procedure, unlike UNCHECKED_DEALLOCATION, will
-- properly destroy the ADT being pointed to...
and then hide the instantiation in the package body. This will
reduce the length of the user's "with" list, and give the user
less opportunity to screw up the instantiation,
prev parent reply other threads:[~1988-12-14 19:04 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
1988-12-06 13:08 Destroy and Unchecked Deallocation TUFFS1
1988-12-14 19:04 ` William Thomas Wolfe,2847, [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox