From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.7 required=5.0 tests=BAYES_00,INVALID_DATE, MSGID_SHORT,REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Path: utzoo!attcan!uunet!lll-winken!lll-tis!ames!ncar!gatech!hubcap!billwolf From: billwolf@hubcap.clemson.edu (William Thomas Wolfe,2847,) Newsgroups: comp.lang.ada Subject: Re: Destroy and Unchecked Deallocation (minor bug) Message-ID: <3892@hubcap.UUCP> Date: 14 Dec 88 19:04:43 GMT References: <8812140455.AA16285@ajpo.sei.cmu.edu> Sender: news@hubcap.UUCP Reply-To: wtwolfe@hubcap.clemson.edu List-Id: >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,