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-Thread: a07f3367d7,65b902127ca8a604 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: "Alex R. Mosteo" Newsgroups: comp.lang.ada Subject: Re: Issue with GNAT GPL 2009 and GtkAda Followup-To: comp.lang.ada Date: Mon, 29 Jun 2009 12:04:47 +0200 Message-ID: <7arhv9F20ue9dU1@mid.individual.net> References: <4A414EBB.8060204@free.fr> <1avd65rn49abv$.krcxo2gdzb16$.dlg@40tude.net> <7ajfrgF1vdsnlU1@mid.individual.net> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Trace: individual.net 59ZjXsQs80xOwzsFUctjAguDFWEy4TNHgdiLYpxc912y0NUhY= Cancel-Lock: sha1:nCdMMmZ6ZZ/WAO5XN9OP7eFJOv0= User-Agent: KNode/4.3.0 pre Xref: g2news2.google.com comp.lang.ada:6702 Date: 2009-06-29T12:04:47+02:00 List-Id: Randy Brukardt wrote: > "Alex R. Mosteo" wrote in message > news:7ajfrgF1vdsnlU1@mid.individual.net... > ... >>> 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? >> >> I strongly suspect that Gnat does not behave this way, but I should test >> it. > > Gnat would be wrong if it does *not* behave this way. (Janus/Ada has this > bug currently.) The master of the anonymous access type is the declare > block, and it has to be finalized at the end of the scope. I suppose you > could leave the memory around, but the object has to be finalized (as > Dmitry's example shows). No, indeed GNAT GPL 2009 at least is correct. It was my fault; I was almost sure of having been doing this in such a way that would have caused dangling pointers and immediate crashes. Since this didn't happen, I thought it was the compiler's fault. In reality, my remembrance was wrong and in practice it was a declaration at the library level so it couldn't happen. Not nice though, I was completely unaware and that makes me uneasy.