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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,edd7ea1b2d7e9a18 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-02-13 05:47:54 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!peer.news.opaltelecom.net!zen.net.uk!news.cabal.org.uk!news-peer.gradwell.net!not-for-mail Mime-Version: 1.0 X-Newsreader: knews 1.0b.1 References: From: porton@ex-code.com (Victor Porton) Subject: Re: Pitfall: freeing access discriminants Newsgroups: comp.lang.ada Content-Type: text/plain; charset=us-ascii Message-ID: Date: Thu, 13 Feb 2003 18:38:38 +0500 Organization: Extreme Code Software (http://ex-code.com) X-URL: http://www.ex-code.com/ NNTP-Posting-Date: 13 Feb 2003 13:47:54 GMT NNTP-Posting-Host: 195.149.39.13 X-Trace: 1045144074 news.gradwell.net 351 mail2news/195.149.39.13 X-Complaints-To: news-abuse@gradwell.net Xref: archiver1.google.com comp.lang.ada:34053 Date: 2003-02-13T13:47:54+00:00 List-Id: In article , "Grein, Christoph" writes: > This works, but you have to be careful with the allocation pools. > Also access discriminants can never be null, so if you deallocate the object it > is accessing, ... > > Ok, here you are safe since you finalize the whole object. > > with Ada.Finalization; > > package Acc_Dis is > > type T (D: access Integer) is > new Ada.Finalization.Limited_Controlled with null record; > > procedure Finalize (Object: in out T); > > V: T (new Integer'(5)); > > end Acc_Dis; > with Ada.Unchecked_Deallocation; > > package body Acc_Dis is > > procedure Finalize (Object: in out T) is > type Integer_Ptr is access all Integer; > procedure Free is new Ada.Unchecked_Deallocation (Integer, Integer_Ptr); > P: Integer_Ptr := Integer_Ptr (Object.D); > begin > Free (P); > end Finalize; > > end Acc_Dis; Oops, I've found that this in not safe and even may lead to erraneous execution!! Because of storage pools for Integer_Ptr may be different from storage pool used by "new".