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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,65b902127ca8a604 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!feeder1-2.proxad.net!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Issue with GNAT GPL 2009 and GtkAda Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <4A414EBB.8060204@free.fr> <1avd65rn49abv$.krcxo2gdzb16$.dlg@40tude.net> <7ajfrgF1vdsnlU1@mid.individual.net> Date: Fri, 26 Jun 2009 11:07:11 +0200 Message-ID: <1pjr0mljv2ozo$.1ahm9u9i39pg6.dlg@40tude.net> NNTP-Posting-Date: 26 Jun 2009 11:07:11 CEST NNTP-Posting-Host: 4f218315.newsspool3.arcor-online.net X-Trace: DXC=7i9T?0kYe]kPXlQ;h]GTMdMcF=Q^Z^V3h4Fo<]lROoRa^YC2XCjHcbi1k1BXNbGj`dDNcfSJ;bb[eFCTGGVUmh?dLK[5LiR>kgbYm3`d=XjO[c X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:6631 Date: 2009-06-26T11:07:11+02:00 List-Id: On Fri, 26 Jun 2009 10:39:45 +0200, Alex R. Mosteo wrote: > Dmitry A. Kazakov wrote: > >> On Thu, 25 Jun 2009 05:06:08 -0400, Stephen Leake wrote: >> >>> Another thought: whenever I have trouble with anonymous access types, >>> I replace them with the corresponding named access type, and the >>> problem goes away. That may indicate a conmpiler bug, but I've always >>> had to much to do to find out. >> >> Yes, but that is not necessarily a compiler bug. It is quite simple to >> create a serious problem to oneself: >> >> declare >> Ptr : access T := new T; >> begin >> ... >> External_Ptr := Ptr.all'Uchecked_Access; -- Copy the pointer >> ... >> end; -- Now External_Ptr is dangling, because the object is freed. > > If I understand correctly, this is because the type of Ptr goes out of > scope? Yes > I strongly suspect that Gnat does not behave this way, but I should test it. Here is a test: with Ada.Finalization; with Ada.Text_IO; use Ada.Text_IO; procedure Test_Anonymous_Access is package P is type T is new Ada.Finalization.Controlled with null record; overriding procedure Finalize (X : in out T); end P; package body P is procedure Finalize (X : in out T) is begin Put_Line ("Finalized"); end Finalize; end P; use P; begin declare X : access T := new T; begin Put_Line ("Created"); end; Put_Line ("Left the scope"); end Test_Anonymous_Access; It should print: Created Finalized Left the scope -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de